Compare commits

..

No commits in common. "8d2694d8b77789e730e46235148acbd5e1cf6a44" and "bf9afd97920d76d80282f63c2642ccc595e67f8c" have entirely different histories.

2 changed files with 15 additions and 18 deletions

View file

@ -3,12 +3,12 @@ from asyncio import TaskGroup
from textwrap import indent
from typing import Union
from disnake import ChannelType, Embed, Member, Thread, User
from disnake import 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 confirm, test_keyword
from .utils import can_view, confirm, test_keyword
log = logging.getLogger("nomen.notifications")
log.setLevel(logging.INFO)
@ -36,22 +36,6 @@ 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:
# Nonexistent members cannot view
if member is None:
return False
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

View file

@ -3,6 +3,7 @@ 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")
@ -117,6 +118,18 @@ 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 =====