1
0

general.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. from discord.ext import commands
  2. import discord
  3. from discord import app_commands
  4. import time
  5. from typing import Optional
  6. #from query.channel import get_interact
  7. from query.user import ignore_user, unignore_user, is_ignored
  8. from common.logging import report
  9. #from local_settings import OUTPUT_CHANNEL
  10. from common.settings import check_ignore_interaction
  11. async def setup(bot: commands.Bot) -> None:
  12. await bot.add_cog(GeneralCommands(bot))
  13. class GeneralCommands(commands.Cog):
  14. """General functionality."""
  15. def __init__(self, bot: commands.Bot) -> None:
  16. self.bot = bot
  17. @app_commands.command(
  18. name="ping",
  19. description="Get the bot's current websocket and API latency.",
  20. )
  21. async def ping(self, interaction: discord.Interaction) -> None:
  22. start_time = time.time()
  23. # message = await ctx.send(f"Pong!\nGateway heartbeat in {round(self.bot.latency * 1000)}ms.")
  24. end_time = time.time()
  25. await interaction.response.send_message(f"API roundtrip latency {round((end_time - start_time) * 1000)}ms.", ephemeral=True)
  26. # @commands.command(
  27. # description="Send a message",
  28. # brief="Chat",
  29. # help="Make a chat message",
  30. # aliases= ("say", "pm", "dm", "echo", "print")
  31. # )
  32. # async def msg(self, ctx: commands.Context, channel: Optional[discord.TextChannel], user: Optional[discord.User], *, message: str = None):
  33. # # Halt on ignore list.
  34. # if await check_ignore_interaction(self.bot.pg, interaction):
  35. # return
  36. #
  37. # #print(ctx.author.permissions_in(self.bot.get_channel(OUTPUT_CHANNEL)).send_messages)
  38. # if not message:
  39. # if channel:
  40. # await ctx.send(f"What would you like me to say in `{channel}`?")
  41. # elif user:
  42. # await ctx.send(f"What would you like me to say to `{user}`?")
  43. # else:
  44. # await ctx.send("What would you like me to say?")
  45. # elif channel:
  46. # if await get_interact(self.bot.pg, channel.id) or ctx.author.permissions_in(self.bot.get_channel(OUTPUT_CHANNEL)).send_messages:
  47. # await channel.send(message)
  48. # await report(self.bot, f"`{ctx.author}` @ {channel.mention}: {message}", ctx.guild)
  49. # else:
  50. # await ctx.send(f"Interactive mode for {channel} is deactivated.")
  51. # elif user and ctx.author.permissions_in(self.bot.get_channel(OUTPUT_CHANNEL)).send_messages:
  52. # await user.send(message)
  53. # await report(self.bot, f"`{ctx.author}` has sent {message} to `{user.name}`")
  54. # else:
  55. # await ctx.send(message)
  56. # await report(self.bot, f"`{ctx.author}` has sent {message} locally.", ctx.guild)
  57. @app_commands.command(
  58. name="ignoreme",
  59. description="Get ignored.",
  60. )
  61. async def ignoreme(self, interaction: discord.Interaction) -> None:
  62. # Halt on ignore list.
  63. if await check_ignore_interaction(self.bot.pg, interaction):
  64. return
  65. await ignore_user(self.bot.pg, interaction.user.id)
  66. await interaction.response.send_message(f"To revert this use the `/unignoreme` command.")
  67. await report(self.bot, " has requested to be ignored.", user=interaction.user)
  68. @app_commands.command(
  69. name="unignoreme",
  70. description="No longer get ingored.",
  71. )
  72. async def unignoreme(self, interaction: discord.Interaction) -> None:
  73. await unignore_user(self.bot.pg, interaction.user.id)
  74. await interaction.response.send_message(f"I shall now interact with you again where my channel settings allow it.")
  75. await report(self.bot, " has requested to be un-ignored.", user=interaction.user)
  76. @app_commands.command(
  77. name="isignored",
  78. description="Ignore status for user.",
  79. )
  80. async def isignored(self, interaction: discord.Interaction, user: Optional[discord.User]) -> None:
  81. # Halt on ignore list.
  82. if await check_ignore_interaction(self.bot.pg, interaction.user):
  83. return
  84. if not user:
  85. user = interaction.user
  86. if await is_ignored(self.bot.pg, user.id):
  87. await interaction.response.send_message(f"I am ignoring `{user}`.")
  88. else:
  89. await interaction.response.send_message(f"I am not ignoring `{user}`.")