Esempio n. 1
0
async def init_task() -> None:
    async def run_modmail() -> None:
        try:
            await client.start(conf.token, reconnect=True)
        except asyncio.CancelledError:
            pass
        except:
            logger.error("Exception in modmail client task", exc_info=True)
        finally:
            await client.close()

    bot_task: asyncio.Task[None] = util.asyncio.run_async(run_modmail)
    plugins.finalizer(bot_task.cancel)
Esempio n. 2
0
async def init() -> None:
    global conf, cleanup_task
    await util.db.init(util.db.get_ddl(registry.metadata.create_all))
    conf = cast(LoggerConf, await util.db.kv.load(__name__))
    await plugins.message_tracker.subscribe(__name__,
                                            None,
                                            register_messages,
                                            missing=True,
                                            retroactive=False)

    @plugins.finalizer
    async def unsubscribe() -> None:
        await plugins.message_tracker.unsubscribe(__name__, None)

    cleanup_task = asyncio.create_task(clean_old_messages())
    plugins.finalizer(cleanup_task.cancel)
Esempio n. 3
0
async def init() -> None:
    global conf
    conf = cast(RemindersConf, await util.db.kv.load(__name__))

    for user_id, in conf:
        obj = conf[int(user_id)]
        assert obj is not None
        conf[int(user_id)] = FrozenList({
            "guild": int(rem["guild"]),
            "channel": int(rem["channel"]),
            "msg": int(rem["msg"]),
            "time": int(rem["time"]),
            "contents": rem["contents"]
        } for rem in obj)
    await conf

    expiry_task: asyncio.Task[None] = util.asyncio.run_async(expire_reminders)
    plugins.finalizer(expiry_task.cancel)
Esempio n. 4
0
async def init() -> None:
    global conf, session, domains, local_blacklist, local_whitelist, ws_task
    conf = cast(PhishConf, await util.db.kv.load(__name__))
    if conf.local_blacklist is None:
        conf.local_blacklist = []
    if conf.local_whitelist is None:
        conf.local_whitelist = []
    local_blacklist = set(conf.local_blacklist)
    local_whitelist = set(conf.local_whitelist)
    session = aiohttp.ClientSession()
    plugins.finalizer(session.close)
    domains = set(await get_all_domains())
    if domains & local_blacklist:
        local_blacklist -= domains
        conf.local_blacklist = util.frozen_list.FrozenList(local_blacklist)
    await conf
    ws_task = asyncio.create_task(watch_websocket())
    plugins.finalizer(ws_task.cancel)
Esempio n. 5
0
async def init_executor() -> None:
    global executor_task, fetch_task
    executor_task = asyncio.create_task(executor())
    @plugins.finalizer
    async def cancel_executor() -> None:
        async def kill_executor() -> None:
            raise asyncio.CancelledError()
        try:
            await schedule_and_wait(kill_executor())
        except asyncio.CancelledError:
            pass
        finally:
            try:
                await executor_task
            except asyncio.CancelledError:
                pass
    fetch_task = asyncio.create_task(background_fetch())
    plugins.finalizer(fetch_task.cancel)
    if discord_client.client.is_ready():
        chans = [channel for guild in discord_client.client.guilds for channel in guild.text_channels]
        last_msgs, thread_last_msgs = take_snapshot(chans)
        schedule(process_ready(last_msgs, thread_last_msgs))
Esempio n. 6
0

class LoggerConf(Protocol):
    temp_channel: int
    perm_channel: int
    keep: int
    interval: int
    file_path: str


conf: LoggerConf

registry: sqlalchemy.orm.registry = sqlalchemy.orm.registry()

engine = util.db.create_async_engine()
plugins.finalizer(engine.dispose)

sessionmaker = sqlalchemy.orm.sessionmaker(
    engine, class_=sqlalchemy.ext.asyncio.AsyncSession, expire_on_commit=False)


@registry.mapped
class SavedMessage:
    __tablename__ = "saved_messages"

    id: int = sqlalchemy.Column(sqlalchemy.BigInteger,
                                primary_key=True,
                                autoincrement=False)
    channel_id: int = sqlalchemy.Column(sqlalchemy.BigInteger, nullable=False)
    author_id: int = sqlalchemy.Column(sqlalchemy.BigInteger, nullable=False)
    username: str = sqlalchemy.Column(sqlalchemy.TEXT, nullable=False)
Esempio n. 7
0
async def init() -> None:
    global conf, scheduler_task
    conf = cast(ClopenConf, await util.db.kv.load(__name__))
    scheduler_task = asyncio.create_task(scheduler())
    plugins.finalizer(scheduler_task.cancel)