WIP Cleaning up the code base + impl slash commands

This commit is contained in:
2021-10-30 22:05:40 +02:00
parent 425d3a3a92
commit bcf3d957a8
16 changed files with 973 additions and 541 deletions
+48 -49
View File
@@ -2,12 +2,12 @@ import discord
from discord.ext import tasks, commands
import time
from discord.ext.commands import Context
import humanize
import datetime
import lavalink
from utils import metadata
from utils.EmbedGenerator import EmbedGenerator
from utils.paginator import HelpPaginator
from discord import Status
class InformationCog(commands.Cog, name="Information"):
@@ -21,49 +21,49 @@ class InformationCog(commands.Cog, name="Information"):
await self.bot.wait_until_ready()
title = "ck!connect | ck!help"
if self.is_help_msg:
title = (await metadata.fetch_metadata())["name"]
title = "Tfoe broer"
self.is_help_msg = not self.is_help_msg
await self.bot.change_presence(activity=discord.Game(title))
@commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
@commands.command(description='PONG!', aliases=['pong'])
async def ping(self, ctx):
@commands.command(description="PONG!", aliases=["pong"])
async def ping(self, ctx: Context):
"""Test the latency"""
avatar = ctx.author.avatar_url_as(static_format='jpeg')
emoji = discord.utils.get(ctx.bot.emojis, name='loading')
avatar = ctx.author.avatar.with_static_format("jpeg")
emoji = discord.utils.get(ctx.bot.emojis, name="loading")
start = time.monotonic()
msg = await ctx.send(embed=discord.Embed(
description=f'{emoji} Calculating ping'))
msg = await ctx.send(
embed=discord.Embed(description=f"{emoji} Calculating ping")
)
millis = (time.monotonic() - start) * 1000
heartbeat = ctx.bot.latency * 1000
embed = discord.Embed(color=discord.Color.blue())
embed.add_field(name=':heartbeat: Heartbeat',
value=f'`{heartbeat:,.2f}ms`',
inline=True)
embed.add_field(name=':file_cabinet: ACK',
value=f'`{millis:,.2f}ms`',
inline=True)
embed.set_footer(text=f"Requested by: {ctx.author}",
icon_url=f"{avatar}")
embed.add_field(
name=":heartbeat: Heartbeat", value=f"`{heartbeat:,.2f}ms`", inline=True
)
embed.add_field(
name=":file_cabinet: ACK", value=f"`{millis:,.2f}ms`", inline=True
)
embed.set_footer(text=f"Requested by: {ctx.author}", icon_url=f"{avatar}")
await msg.edit(embed=embed)
@commands.command(name='invite')
@commands.command(
name="invite", description="Gets the invite link!", slash_commands=True
)
@commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
async def invite(self, ctx):
async def invite(self, ctx: Context):
"""Gets the invite link!"""
color = self.bot.colors["embed"]
avatar = ctx.author.avatar_url_as(static_format='jpeg')
client_id = ctx.bot.user.id
link = f"https://discord.com/oauth2/authorize?scope=bot&client_id={client_id}&permissions=70642768"
embed = discord.Embed(color=color)
embed.add_field(name='Add our bot to your server:', value=link)
embed.set_footer(text=f"Requested by: {ctx.author}",
icon_url=f"{avatar}")
link = f"https://discord.com/oauth2/authorize?client_id=643555373814382593&permissions=3230720&scope=bot%20applications.commands"
embed = await EmbedGenerator.Message(ctx, "Add our bot to your server:", link)
await ctx.send(embed=embed)
@commands.command(
name="wlinfo",
description="Retrieve various Node/Server/Player information.",
slash_commands=True,
)
@commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
@commands.command()
async def wlinfo(self, ctx):
async def wlinfo(self, ctx: Context):
"""Retrieve various Node/Server/Player information."""
player = self.bot.lavalink.player_manager.get(ctx.guild.id)
node = player.node
@@ -73,28 +73,29 @@ class InformationCog(commands.Cog, name="Information"):
free = humanize.naturalsize(node.stats.memory_free)
cpu = node.stats.cpu_cores
fmt = f'**WaveLink:** `{lavalink.__version__}`\n\n' \
f'Connected to `{len(self.bot.lavalink.nodes)}` nodes.\n' \
f'Best available Node `{self.bot.lavalink.get_best_node().__repr__()}`\n' \
f'`{len(self.bot.lavalink.players)}` players are distributed on nodes.\n' \
f'`{node.stats.players}` players are distributed on server.\n' \
f'`{node.stats.playing_players}` players are playing on server.\n\n' \
f'Server Memory: `{used}/{total}` | `({free} free)`\n' \
f'Server CPU: `{cpu}`\n\n' \
f'Server Uptime: `{datetime.timedelta(milliseconds=node.stats.uptime)}`'
fmt = (
f"**WaveLink:** `{lavalink.__version__}`\n\n"
f"Connected to `{len(self.bot.lavalink.nodes)}` nodes.\n"
f"Best available Node `{self.bot.lavalink.get_best_node().__repr__()}`\n"
f"`{len(self.bot.lavalink.players)}` players are distributed on nodes.\n"
f"`{node.stats.players}` players are distributed on server.\n"
f"`{node.stats.playing_players}` players are playing on server.\n\n"
f"Server Memory: `{used}/{total}` | `({free} free)`\n"
f"Server CPU: `{cpu}`\n\n"
f"Server Uptime: `{datetime.timedelta(milliseconds=node.stats.uptime)}`"
)
await ctx.send(fmt)
@commands.command(name="help", aliases=["about", "info"])
@commands.command(name="help", aliases=["about", "info"], slash_command=True)
@commands.cooldown(1, 1, commands.BucketType.user)
async def about(self, ctx, command: str = None):
async def about(self, ctx: Context):
"""Exobot command list"""
if command:
if None:
entity = self.bot.get_cog(command) or self.bot.get_command(command)
if entity is None:
clean = command.replace('@', '@\u200b')
return await ctx.send(
f'Command or category "{clean}" not found.')
clean = command.replace("@", "@\u200b")
return await ctx.send(f'Command or category "{clean}" not found.')
elif isinstance(entity, discord.ext.commands.Command):
p = await HelpPaginator.from_command(ctx, entity)
else:
@@ -111,7 +112,7 @@ class InformationCog(commands.Cog, name="Information"):
display_cogs = {
"Information": ":information_source:",
"Music": ":musical_note:",
"Settings": ":gear:"
"Settings": ":gear:",
}
for cog_name, cog_icon in display_cogs.items():
@@ -119,13 +120,11 @@ class InformationCog(commands.Cog, name="Information"):
if not cog:
continue
cogname_str = f"{cog_icon} {cog_name}"
commands = [
f"`{cmd.name}`" for cmd in cog.get_commands() if not cmd.hidden
]
commands = [f"`{cmd.name}`" for cmd in cog.get_commands() if not cmd.hidden]
commands_str = ", ".join(commands)
embed.add_field(name=cogname_str, value=commands_str, inline=False)
avatar = ctx.author.avatar_url_as(static_format='jpeg')
avatar = ctx.author.avatar.with_static_format("jpeg")
embed.set_footer(text=f"Requested by: {ctx.author}", icon_url=avatar)
await ctx.send(embed=embed)