general.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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
  11. class GeneralCommands(commands.Cog):
  12. """General functionality."""
  13. def __init__(self, bot: commands.Bot):
  14. self.bot = bot
  15. # @commands.command(
  16. # description="Get the bot's current websocket and API latency.",
  17. # brief="Test latency",
  18. # help="Test latency by polling the gateway and API."
  19. # )
  20. # async def ping(self, ctx: commands.Context):
  21. # # Halt on ignore list.
  22. # if await check_ignore(self.bot.pg, ctx.author):
  23. # return
  24. #
  25. # start_time = time.time()
  26. # message = await ctx.send(f"Pong!\nGateway heartbeat in {round(self.bot.latency * 1000)}ms.")
  27. # end_time = time.time()
  28. #
  29. # await ctx.send(f"API roundtrip latency {round((end_time - start_time) * 1000)}ms.")
  30. # @commands.command(
  31. # description="Send a message",
  32. # brief="Chat",
  33. # help="Make a chat message",
  34. # aliases= ("say", "pm", "dm", "echo", "print")
  35. # )
  36. # async def msg(self, ctx: commands.Context, channel: Optional[discord.TextChannel], user: Optional[discord.User], *, message: str = None):
  37. # # Halt on ignore list.
  38. # if await check_ignore(self.bot.pg, ctx.author):
  39. # return
  40. #
  41. # #print(ctx.author.permissions_in(self.bot.get_channel(OUTPUT_CHANNEL)).send_messages)
  42. # if not message:
  43. # if channel:
  44. # await ctx.send(f"What would you like me to say in `{channel}`?")
  45. # elif user:
  46. # await ctx.send(f"What would you like me to say to `{user}`?")
  47. # else:
  48. # await ctx.send("What would you like me to say?")
  49. # elif channel:
  50. # if await get_interact(self.bot.pg, channel.id) or ctx.author.permissions_in(self.bot.get_channel(OUTPUT_CHANNEL)).send_messages:
  51. # await channel.send(message)
  52. # await report(self.bot, f"`{ctx.author}` @ {channel.mention}: {message}", ctx.guild)
  53. # else:
  54. # await ctx.send(f"Interactive mode for {channel} is deactivated.")
  55. # elif user and ctx.author.permissions_in(self.bot.get_channel(OUTPUT_CHANNEL)).send_messages:
  56. # await user.send(message)
  57. # await report(self.bot, f"`{ctx.author}` has sent {message} to `{user.name}`")
  58. # else:
  59. # await ctx.send(message)
  60. # await report(self.bot, f"`{ctx.author}` has sent {message} locally.", ctx.guild)
  61. # @commands.command(
  62. # description="Change status.",
  63. # brief="Set status",
  64. # help="Update the bot's status."
  65. # )
  66. # async def status(self, ctx: commands.Context, *, text: str):
  67. # # Halt on ignore list.
  68. # if await check_ignore(self.bot.pg, ctx.author):
  69. # return
  70. #
  71. # await self.bot.change_presence(activity=discord.Game(name=text))
  72. # await report(self.bot, f"`{ctx.author}` has set my status to `{text}`.")
  73. @commands.command(
  74. description="Get ignored.",
  75. brief="Ignore sender",
  76. help="Will have the bot ignore the user from now on."
  77. )
  78. async def ignoreme(self, ctx: commands.Context):
  79. # Halt on ignore list.
  80. if await check_ignore(self.bot.pg, ctx.author):
  81. return
  82. await ignore_user(self.bot.pg, ctx.author.id)
  83. await ctx.send(f"To revert this use the `/unignoreme` command.")
  84. await report(self.bot, f"`{ctx.author}` has requested to be ignored.")
  85. @commands.command(
  86. description="No longer get ingored.",
  87. brief="Un-ignore sender",
  88. help="No longer will the bot ignore the user."
  89. )
  90. async def unignoreme(self, ctx: commands.Context):
  91. await unignore_user(self.bot.pg, ctx.author.id)
  92. await ctx.send(f"I shall now interact with you again where my channel settings allow it.")
  93. await report(self.bot, f"`{ctx.author}` has requested to be un-ignored.")
  94. @app_commands.command(
  95. name="isignored1",
  96. description="Echoes a message."
  97. )
  98. # @commands.command(
  99. # description="Ignore status for user.",
  100. # brief="Check if user is ingored",
  101. # help="Verify if the user is being ignored."
  102. # )
  103. async def isignored1(self, interaction: discord.Interaction, user: Optional[discord.User]):
  104. print(0)
  105. # Halt on ignore list.
  106. if await check_ignore(self.bot.pg, interaction.author):
  107. print("Ignoring")
  108. return
  109. if not user:
  110. user = interaction.author
  111. if await is_ignored(self.bot.pg, user.id):
  112. await interaction.response.send_message(f"I am ignoring `{user}`.")
  113. print(1)
  114. else:
  115. await interaction.response.send_message(f"I am not ignoring `{user}`.")
  116. print(2)
  117. @app_commands.command(name="echo1", description="Echo a message")
  118. async def echo1(self, inter: discord.Interaction, message: str) -> None:
  119. await inter.response.send_message(message)
  120. async def setup(bot: commands.Bot):
  121. await bot.add_cog(GeneralCommands(bot))