1
0

settings.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from typing import Optional
  2. import discord
  3. from query.user import is_ignored
  4. from query.channel import get_channel_games, get_channel_interact
  5. from query.guild import get_guild_games, get_guild_interact
  6. # Ignore user if on the ignore list.
  7. async def check_userignore(pg, user_id):
  8. if await is_ignored(pg, user_id):
  9. return True # Confirm ignore
  10. async def check_interact(pg, channel):
  11. # Respond if interaction is enabled for channel.
  12. if channel and await get_channel_interact(pg, channel.id):
  13. return False # Deny ignore
  14. # Ignore if interactions are disabled for channel or guild.
  15. if channel and await get_channel_interact(pg, channel.id) == False or interaction.guild and await get_guild_interact(pg, channel.id) == False:
  16. return True # Confirm ignore
  17. async def check_ignore_interaction(pg, interaction: discord.Interaction, games: Optional[bool]=False, interact: Optional[bool]=False):
  18. # Ignore user if they have requested to be ignored:
  19. if await check_userignore(pg, interaction.user.id):
  20. return True # Confirm ignore
  21. # Game setting check
  22. if games:
  23. # Respond if games enabled for channel.
  24. if interaction.channel and await get_channel_games(pg, interaction.channel.id):
  25. return False # Deny ignore
  26. # Ignore if games are disabled for channel or guild.
  27. 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:
  28. await interaction.response.send_message(f"An admin of **{interaction.guild}** has disabled games in {interaction.channel.mention}.", ephemeral=True)
  29. return True # Confirm ignore
  30. # Respond if channel & faction games are not disabled.
  31. else:
  32. return False # Deny ignore
  33. # Interact settings check:
  34. if interact:
  35. return await check_interact(pg, interaction.channel)
  36. async def check_ignore_message(pg, message: discord.Message, interact: Optional[bool] = False):
  37. # Check if user has requested to be ignored:
  38. if await check_userignore(pg, message.author.id):
  39. True # Confirm ignore
  40. # Interact settings check:
  41. if interact:
  42. return await check_interact(pg, message.channel)