ryuko-ng/robocop_ng/cogs/basic.py

68 lines
2.1 KiB
Python
Raw Normal View History

2018-03-08 22:47:53 +00:00
import time
2018-12-23 13:13:39 +00:00
import config
import discord
2018-03-08 22:47:53 +00:00
from discord.ext import commands
from discord.ext.commands import Cog
2018-03-08 22:47:53 +00:00
2019-06-17 16:10:01 +00:00
class Basic(Cog):
2018-03-08 22:47:53 +00:00
def __init__(self, bot):
self.bot = bot
@commands.command()
async def hello(self, ctx):
"""Says hello. Duh."""
await ctx.send(f"Hello {ctx.author.mention}!")
2019-06-17 16:17:13 +00:00
@commands.cooldown(1, 10, type=commands.BucketType.user)
2019-06-17 16:10:01 +00:00
@commands.command(name="hex")
async def _hex(self, ctx, num: int):
"""Converts base 10 to 16 (for emummc sector calculation)"""
2019-06-17 16:11:08 +00:00
hex_val = hex(num).upper().replace("0X", "0x")
await ctx.send(f"{ctx.author.mention}: {hex_val}")
2019-06-17 16:10:01 +00:00
2019-06-17 16:17:13 +00:00
@commands.cooldown(1, 10, type=commands.BucketType.user)
@commands.command(name="dec")
async def _dec(self, ctx, num):
"""Converts base 10 to 16"""
2019-06-17 16:18:33 +00:00
await ctx.send(f"{ctx.author.mention}: {int(num, 16)}")
2019-06-17 16:17:13 +00:00
@commands.guild_only()
@commands.command()
async def membercount(self, ctx):
"""Prints the member count of the server."""
await ctx.send(f"{ctx.guild.name} has {ctx.guild.member_count} members!")
2018-12-23 17:27:51 +00:00
@commands.command(aliases=["robocopng", "robocop-ng"])
async def robocop(self, ctx):
"""Shows a quick embed with bot info."""
embed = discord.Embed(
title="Robocop-NG", url=config.source_url, description=config.embed_desc
)
2018-12-23 17:27:51 +00:00
embed.set_thumbnail(url=self.bot.user.avatar_url)
await ctx.send(embed=embed)
@commands.command(aliases=["p"])
2018-03-08 22:47:53 +00:00
async def ping(self, ctx):
"""Shows ping values to discord.
RTT = Round-trip time, time taken to send a message to discord
GW = Gateway Ping"""
before = time.monotonic()
tmp = await ctx.send("Calculating ping...")
2018-03-08 22:47:53 +00:00
after = time.monotonic()
rtt_ms = (after - before) * 1000
gw_ms = self.bot.latency * 1000
message_text = (
f":ping_pong:\nrtt: `{rtt_ms:.1f}ms`\ngw: `{gw_ms:.1f}ms`"
)
2018-03-08 22:47:53 +00:00
self.bot.log.info(message_text)
await tmp.edit(content=message_text)
def setup(bot):
bot.add_cog(Basic(bot))