diff options
| author | 2021-06-12 21:23:31 +0100 | |
|---|---|---|
| committer | 2021-06-12 21:23:31 +0100 | |
| commit | 093f67338688a2533fe44f11f598e532bbb8a070 (patch) | |
| tree | d1e74a7acbee9ce2fa79ce8cf8748981c6999feb | |
| parent | Edit indentation (diff) | |
| parent | Merge #1637 - add an optional loop kwarg to scheduling.create_task (diff) | |
Merge branch 'main' into jake/helpdm
Diffstat (limited to '')
| -rw-r--r-- | bot/constants.py | 2 | ||||
| -rw-r--r-- | bot/utils/messages.py | 2 | ||||
| -rw-r--r-- | bot/utils/scheduling.py | 19 | ||||
| -rw-r--r-- | config-default.yml | 4 | 
4 files changed, 23 insertions, 4 deletions
diff --git a/bot/constants.py b/bot/constants.py index ab55da482..3d960f22b 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -433,6 +433,8 @@ class Channels(metaclass=YAMLGetter):      off_topic_1: int      off_topic_2: int +    black_formatter: int +      bot_commands: int      discord_py: int      esoteric: int diff --git a/bot/utils/messages.py b/bot/utils/messages.py index b6f6c1f66..d4a921161 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -54,7 +54,7 @@ def reaction_check(          log.trace(f"Removing reaction {reaction} by {user} on {reaction.message.id}: disallowed user.")          scheduling.create_task(              reaction.message.remove_reaction(reaction.emoji, user), -            HTTPException,  # Suppress the HTTPException if adding the reaction fails +            suppressed_exceptions=(HTTPException,),              name=f"remove_reaction-{reaction}-{reaction.message.id}-{user}"          )          return False diff --git a/bot/utils/scheduling.py b/bot/utils/scheduling.py index 2dc485f24..bb83b5c0d 100644 --- a/bot/utils/scheduling.py +++ b/bot/utils/scheduling.py @@ -161,9 +161,22 @@ class Scheduler:                  self._log.error(f"Error in task #{task_id} {id(done_task)}!", exc_info=exception) -def create_task(coro: t.Awaitable, *suppressed_exceptions: t.Type[Exception], **kwargs) -> asyncio.Task: -    """Wrapper for `asyncio.create_task` which logs exceptions raised in the task.""" -    task = asyncio.create_task(coro, **kwargs) +def create_task( +    coro: t.Awaitable, +    *, +    suppressed_exceptions: tuple[t.Type[Exception]] = (), +    event_loop: t.Optional[asyncio.AbstractEventLoop] = None, +    **kwargs, +) -> asyncio.Task: +    """ +    Wrapper for creating asyncio `Task`s which logs exceptions raised in the task. + +    If the loop kwarg is provided, the task is created from that event loop, otherwise the running loop is used. +    """ +    if event_loop is not None: +        task = event_loop.create_task(coro, **kwargs) +    else: +        task = asyncio.create_task(coro, **kwargs)      task.add_done_callback(partial(_log_task_exception, suppressed_exceptions=suppressed_exceptions))      return task diff --git a/config-default.yml b/config-default.yml index 55388247c..48fd7c47e 100644 --- a/config-default.yml +++ b/config-default.yml @@ -176,6 +176,9 @@ guild:          user_log:                           528976905546760203          voice_log:                          640292421988646961 +        # Open Source Projects +        black_formatter:    &BLACK_FORMATTER 846434317021741086 +          # Off-topic          off_topic_0:    291284109232308226          off_topic_1:    463035241142026251 @@ -244,6 +247,7 @@ guild:      reminder_whitelist:          - *BOT_CMD          - *DEV_CONTRIB +        - *BLACK_FORMATTER      roles:          announcements:                          463658397560995840  |