move can_view into notifications

This commit is contained in:
Infinidoge 2025-02-21 16:20:10 -05:00
parent bf9afd9792
commit b3b7f69788
Signed by: Infinidoge
SSH key fingerprint: SHA256:EMoPe5e2dO0gEvtBb2xkZTz5dkyL0rBmuiGTKG5s96E
2 changed files with 14 additions and 15 deletions

View file

@ -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 Embed, Member, Thread, User from disnake import ChannelType, 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 can_view, confirm, test_keyword from .utils import confirm, test_keyword
log = logging.getLogger("nomen.notifications") log = logging.getLogger("nomen.notifications")
log.setLevel(logging.INFO) log.setLevel(logging.INFO)
@ -36,6 +36,18 @@ 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:
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

View file

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