Compare commits
No commits in common. "8d2694d8b77789e730e46235148acbd5e1cf6a44" and "bf9afd97920d76d80282f63c2642ccc595e67f8c" have entirely different histories.
8d2694d8b7
...
bf9afd9792
2 changed files with 15 additions and 18 deletions
|
@ -3,12 +3,12 @@ from asyncio import TaskGroup
|
||||||
from textwrap import indent
|
from textwrap import indent
|
||||||
from typing import Union
|
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.abc import GuildChannel
|
||||||
from disnake.errors import Forbidden
|
from disnake.errors import Forbidden
|
||||||
from disnake.ext.commands import Cog, Paginator, group, guild_only
|
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 = logging.getLogger("nomen.notifications")
|
||||||
log.setLevel(logging.INFO)
|
log.setLevel(logging.INFO)
|
||||||
|
@ -36,22 +36,6 @@ class KeywordError(Exception):
|
||||||
await ctx.author.send(self.dm_msg)
|
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 def handle_notification(db_updates, ctx, message, keyword, user_id, use_embed):
|
||||||
"""
|
"""
|
||||||
Async task to dispatch a notification
|
Async task to dispatch a notification
|
||||||
|
|
|
@ -3,6 +3,7 @@ from asyncio import TimeoutError
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
import re2 as re
|
import re2 as re
|
||||||
|
from disnake import ChannelType
|
||||||
from disnake.ext.commands import BadArgument
|
from disnake.ext.commands import BadArgument
|
||||||
|
|
||||||
log = logging.getLogger("nomen.utils")
|
log = logging.getLogger("nomen.utils")
|
||||||
|
@ -117,6 +118,18 @@ def unpack(lst_of_tpl):
|
||||||
return list(map(first, 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 =====
|
# ===== Borrowed from https://github.com/avrae/avrae, GPLv3 licensed =====
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue