general.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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="Rubbish information.",
  33. # brief="Get info",
  34. # help="Display some crap."
  35. # )
  36. # async def info(self, ctx: commands.Context):
  37. # # Halt on ignore list.
  38. # if await check_ignore(self.bot.pg, ctx.author):
  39. # return
  40. #
  41. # """Displays some rubbish info."""
  42. # embed = discord.Embed(title=f"Guild: {ctx.guild}.")
  43. # await ctx.send(embed=embed)
  44. # #await ctx.send(f"Guild: {ctx.guild}.")
  45. # @commands.command(
  46. # description="Send a message",
  47. # brief="Chat",
  48. # help="Make a chat message",
  49. # aliases= ("say", "pm", "dm", "echo", "print")
  50. # )
  51. # async def msg(self, ctx: commands.Context, channel: Optional[discord.TextChannel], user: Optional[discord.User], *, message: str = None):
  52. # # Halt on ignore list.
  53. # if await check_ignore(self.bot.pg, ctx.author):
  54. # return
  55. #
  56. # #print(ctx.author.permissions_in(self.bot.get_channel(OUTPUT_CHANNEL)).send_messages)
  57. # if not message:
  58. # if channel:
  59. # await ctx.send(f"What would you like me to say in `{channel}`?")
  60. # elif user:
  61. # await ctx.send(f"What would you like me to say to `{user}`?")
  62. # else:
  63. # await ctx.send("What would you like me to say?")
  64. # elif channel:
  65. # if await get_interact(self.bot.pg, channel.id) or ctx.author.permissions_in(self.bot.get_channel(OUTPUT_CHANNEL)).send_messages:
  66. # await channel.send(message)
  67. # await report(self.bot, f"`{ctx.author}` @ {channel.mention}: {message}", ctx.guild)
  68. # else:
  69. # await ctx.send(f"Interactive mode for {channel} is deactivated.")
  70. # elif user and ctx.author.permissions_in(self.bot.get_channel(OUTPUT_CHANNEL)).send_messages:
  71. # await user.send(message)
  72. # await report(self.bot, f"`{ctx.author}` has sent {message} to `{user.name}`")
  73. # else:
  74. # await ctx.send(message)
  75. # await report(self.bot, f"`{ctx.author}` has sent {message} locally.", ctx.guild)
  76. # @commands.command(
  77. # description="Change status.",
  78. # brief="Set status",
  79. # help="Update the bot's status."
  80. # )
  81. # async def status(self, ctx: commands.Context, *, text: str):
  82. # # Halt on ignore list.
  83. # if await check_ignore(self.bot.pg, ctx.author):
  84. # return
  85. #
  86. # await self.bot.change_presence(activity=discord.Game(name=text))
  87. # await report(self.bot, f"`{ctx.author}` has set my status to `{text}`.")
  88. @commands.command(
  89. description="Get ignored.",
  90. brief="Ignore sender",
  91. help="Will have the bot ignore the user from now on."
  92. )
  93. async def ignoreme(self, ctx: commands.Context):
  94. # Halt on ignore list.
  95. if await check_ignore(self.bot.pg, ctx.author):
  96. return
  97. await ignore_user(self.bot.pg, ctx.author.id)
  98. await ctx.send(f"To revert this use the `/unignoreme` command.")
  99. await report(self.bot, f"`{ctx.author}` has requested to be ignored.")
  100. @commands.command(
  101. description="No longer get ingored.",
  102. brief="Un-ignore sender",
  103. help="No longer will the bot ignore the user."
  104. )
  105. async def unignoreme(self, ctx: commands.Context):
  106. await unignore_user(self.bot.pg, ctx.author.id)
  107. await ctx.send(f"I shall now interact with you again where my channel settings allow it.")
  108. await report(self.bot, f"`{ctx.author}` has requested to be un-ignored.")
  109. @commands.command(
  110. description="Ignore status for user.",
  111. brief="Check if user is ingored",
  112. help="Verify if the user is being ignored."
  113. )
  114. async def isignored(self, ctx: commands.Context, user: Optional[discord.User]):
  115. # Halt on ignore list.
  116. if await check_ignore(self.bot.pg, ctx.author):
  117. return
  118. if not user:
  119. user = ctx.author
  120. if await is_ignored(self.bot.pg, user.id):
  121. await ctx.send(f"I am ingoring `{user}`.")
  122. else:
  123. await ctx.send(f"I am not ignoring `{user}`.")