1
0

general.py 4.2 KB

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