diff --git a/nomen/notifications.py b/nomen/notifications.py index eaeb8fb..170967d 100644 --- a/nomen/notifications.py +++ b/nomen/notifications.py @@ -3,12 +3,12 @@ from asyncio import TaskGroup from textwrap import indent from typing import Union -from disnake import Embed, Member, Thread, User +from disnake import ChannelType, Embed, Member, Thread, User from disnake.abc import GuildChannel from disnake.errors import Forbidden from disnake.ext.commands import Cog, Paginator, group, guild_only -from .utils import can_view, confirm, test_keyword +from .utils import confirm, test_keyword log = logging.getLogger("nomen.notifications") log.setLevel(logging.INFO) @@ -36,6 +36,18 @@ class KeywordError(Exception): await ctx.author.send(self.dm_msg) +async def in_thread(member, thread): + # FIXME: Currently overlooks the situation where a moderator isn't in a thread but has manage threads + return any(member.id == thread_member.id for thread_member in await thread.fetch_members()) + + +async def can_view(ctx, member) -> bool: + if ctx.channel.type == ChannelType.private_thread and not await in_thread(member, ctx.channel): + return False + + return ctx.channel.permissions_for(member).view_channel + + async def handle_notification(db_updates, ctx, message, keyword, user_id, use_embed): """ Async task to dispatch a notification diff --git a/nomen/utils.py b/nomen/utils.py index 1782d56..f4b49bc 100644 --- a/nomen/utils.py +++ b/nomen/utils.py @@ -3,7 +3,6 @@ from asyncio import TimeoutError from itertools import chain import re2 as re -from disnake import ChannelType from disnake.ext.commands import BadArgument log = logging.getLogger("nomen.utils") @@ -118,18 +117,6 @@ def unpack(lst_of_tpl): return list(map(first, lst_of_tpl)) -async def in_thread(member, thread): - # FIXME: Currently overlooks the situation where a moderator isn't in a thread but has manage threads - return any(member.id == thread_member.id for thread_member in await thread.fetch_members()) - - -async def can_view(ctx, member) -> bool: - if ctx.channel.type == ChannelType.private_thread and not await in_thread(member, ctx.channel): - return False - - return ctx.channel.permissions_for(member).view_channel - - # ===== Borrowed from https://github.com/avrae/avrae, GPLv3 licensed =====