general.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from discord.ext import commands
  2. import discord
  3. import time
  4. from typing import Optional
  5. def setup(bot: commands.Bot):
  6. bot.add_cog(General(bot))
  7. class General(commands.Cog):
  8. """General functionality."""
  9. def __init__(self, bot: commands.Bot):
  10. self.bot = bot
  11. @commands.command(
  12. description="Get the bot's current websocket and API latency.",
  13. brief="Test latency",
  14. help="Test latency by polling the gateway and API."
  15. )
  16. async def ping(self, ctx: commands.Context):
  17. start_time = time.time()
  18. message = await ctx.send(f"Pong!\nGateway heartbeat in {round(self.bot.latency * 1000)}ms.")
  19. end_time = time.time()
  20. await ctx.send(f"API roundtrip latency {round((end_time - start_time) * 1000)}ms.")
  21. @commands.command(
  22. description="Rubbish information.",
  23. brief="Get info",
  24. help="Display some crap."
  25. )
  26. async def info(self, ctx: commands.Context):
  27. """Displays some rubbish info."""
  28. embed = discord.Embed(title=f"Guild: {ctx.guild}.")
  29. await ctx.send(embed=embed)
  30. #await ctx.send(f"Guild: {ctx.guild}.")
  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. 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. await channel.send(message)
  47. elif user:
  48. await user.send(message)
  49. else:
  50. await ctx.send(message)
  51. @commands.command(
  52. description="Change status.",
  53. brief="Set status",
  54. help="Update the bot's status."
  55. )
  56. async def status(self, ctx: commands.Context, *, text: str):
  57. await self.bot.change_presence(activity=discord.Game(name=text))