rewrite: New Pomodoro Timer system.
This commit is contained in:
@@ -2,6 +2,7 @@ from enum import Enum
|
||||
from itertools import chain
|
||||
from psycopg import sql
|
||||
from cachetools import TTLCache
|
||||
import discord
|
||||
|
||||
from data import Table, Registry, Column, RowModel, RegisterEnum
|
||||
from data.models import WeakCache
|
||||
@@ -346,3 +347,23 @@ class CoreData(Registry, name="core"):
|
||||
(guildid, tuple(untracked), userid)
|
||||
)
|
||||
return (await curs.fetchone()) or (None, None)
|
||||
|
||||
class LionHook(RowModel):
|
||||
"""
|
||||
Schema
|
||||
------
|
||||
CREATE TABLE channel_webhooks(
|
||||
channelid BIGINT NOT NULL PRIMARY KEY,
|
||||
webhookid BIGINT NOT NULL,
|
||||
token TEXT NOT NULL
|
||||
);
|
||||
"""
|
||||
_tablename_ = 'channel_webhooks'
|
||||
_cache_ = {}
|
||||
|
||||
channelid = Integer(primary=True)
|
||||
webhookid = Integer()
|
||||
token = String()
|
||||
|
||||
def as_webhook(self, **kwargs):
|
||||
return discord.Webhook.partial(self.webhookid, self.token, **kwargs)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
from enum import Enum
|
||||
import asyncio
|
||||
import pytz
|
||||
import discord
|
||||
|
||||
@@ -48,7 +49,7 @@ class LionGuild(Timezoned):
|
||||
No guarantee is made that the client is in the corresponding Guild,
|
||||
or that the corresponding Guild even exists.
|
||||
"""
|
||||
__slots__ = ('bot', 'data', 'guildid', 'config', '_guild', '__weakref__')
|
||||
__slots__ = ('bot', 'data', 'guildid', 'config', '_guild', 'voice_lock', '__weakref__')
|
||||
|
||||
Config = GuildConfig
|
||||
settings = Config.settings
|
||||
@@ -62,6 +63,11 @@ class LionGuild(Timezoned):
|
||||
|
||||
self.config = self.Config(self.guildid, data)
|
||||
|
||||
# Guild-specific voice lock
|
||||
# Every module which uses voice alerts should hold this lock throughout the alert.
|
||||
# Avoids voice race-states
|
||||
self.voice_lock = asyncio.Lock()
|
||||
|
||||
@property
|
||||
def guild(self):
|
||||
if self._guild is None:
|
||||
@@ -77,6 +83,10 @@ class LionGuild(Timezoned):
|
||||
def timezone(self) -> pytz.timezone:
|
||||
return self.config.timezone.value
|
||||
|
||||
@property
|
||||
def locale(self) -> str:
|
||||
return self.config.get('guild_locale').value
|
||||
|
||||
async def touch_discord_model(self, guild: discord.Guild):
|
||||
"""
|
||||
Update saved Discord model attributes for this guild.
|
||||
|
||||
Reference in New Issue
Block a user