| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- from typing import Optional
- import discord
- from query.user import is_ignored
- from query.channel import get_channel_games, get_channel_interact
- from query.guild import get_guild_games, get_guild_interact
- # Ignore user if on the ignore list.
- async def check_userignore(pg, user_id):
- if await is_ignored(pg, user_id):
- return True # Confirm ignore
- async def check_interact(pg, channel):
- # Respond if interaction is enabled for channel.
- if channel and await get_channel_interact(pg, channel.id):
- return False # Deny ignore
- # Ignore if interactions are disabled for channel or guild.
- if channel and await get_channel_interact(pg, channel.id) == False or interaction.guild and await get_guild_interact(pg, channel.id) == False:
- return True # Confirm ignore
- async def check_ignore_interaction(pg, interaction: discord.Interaction, games: Optional[bool]=False, interact: Optional[bool]=False):
- # Ignore user if they have requested to be ignored:
- if await check_userignore(pg, interaction.user.id):
- return True # Confirm ignore
- # Game setting check
- if games:
- # Respond if games enabled for channel.
- if interaction.channel and await get_channel_games(pg, interaction.channel.id):
- return False # Deny ignore
- # Ignore if games are disabled for channel or guild.
- if interaction.channel and await get_channel_games(pg, interaction.channel.id) == False or interaction.guild and await get_guild_games(pg, interaction.guild.id) == False:
- await interaction.response.send_message(f"An admin of **{interaction.guild}** has disabled games in {interaction.channel.mention}.", ephemeral=True)
- return True # Confirm ignore
- # Respond if channel & faction games are not disabled.
- else:
- return False # Deny ignore
- # Interact settings check:
- if interact:
- return await check_interact(pg, interaction.channel)
- async def check_ignore_message(pg, message: discord.Message, interact: Optional[bool] = False):
- # Check if user has requested to be ignored:
- if await check_userignore(pg, message.author.id):
- True # Confirm ignore
- # Interact settings check:
- if interact:
- return await check_interact(pg, message.channel)
|