You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.1 KiB

  1. import time
  2. import config
  3. import discord
  4. from discord.ext import commands
  5. class Basic:
  6. def __init__(self, bot):
  7. self.bot = bot
  8. @commands.command()
  9. async def hello(self, ctx):
  10. """Says hello. Duh."""
  11. await ctx.send(f"Hello {ctx.author.mention}!")
  12. @commands.command()
  13. async def rules(self, ctx, *, targetuser: discord.Member = None):
  14. """Post a link to the Rules"""
  15. if not targetuser:
  16. targetuser = ctx.author
  17. await ctx.send(f"{targetuser.mention}: A link to the rules "
  18. f"can be found here: {config.rules_url}")
  19. @commands.guild_only()
  20. @commands.command()
  21. async def membercount(self, ctx):
  22. """Prints the member count of the server."""
  23. await ctx.send(f"{ctx.guild.name} has "
  24. f"{ctx.guild.member_count} members!")
  25. @commands.command()
  26. async def source(self, ctx):
  27. """Gives link to source code."""
  28. await ctx.send("You can find my source at " +
  29. config.source_url +
  30. ". Serious PRs and issues welcome!")
  31. @commands.command(aliases=["robocopng", "robocop-ng"])
  32. async def robocop(self, ctx):
  33. """Shows a quick embed with bot info."""
  34. embed = discord.Embed(title="Komet",
  35. url=config.source_url,
  36. description=config.embed_desc)
  37. embed.set_thumbnail(url=self.bot.user.avatar_url)
  38. await ctx.send(embed=embed)
  39. @commands.command(aliases=['p'])
  40. async def ping(self, ctx):
  41. """Shows ping values to discord.
  42. RTT = Round-trip time, time taken to send a message to discord
  43. GW = Gateway Ping"""
  44. before = time.monotonic()
  45. tmp = await ctx.send('Calculating ping...')
  46. after = time.monotonic()
  47. rtt_ms = (after - before) * 1000
  48. gw_ms = self.bot.latency * 1000
  49. message_text = f":ping_pong: rtt: `{rtt_ms:.1f}ms`, `gw: {gw_ms:.1f}ms`"
  50. self.bot.log.info(message_text)
  51. await tmp.edit(content=message_text)
  52. def setup(bot):
  53. bot.add_cog(Basic(bot))