91 lines
3.4 KiB
Python
91 lines
3.4 KiB
Python
from discord.ext import commands
|
|
import discord
|
|
import core.common as common
|
|
import sys
|
|
import subprocess
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class System(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
self.commit = subprocess.run(["git", "show", "-s", "--format=%h"],
|
|
capture_output=True,
|
|
encoding="utf-8").stdout.strip()
|
|
|
|
@commands.group()
|
|
async def bot(self, ctx):
|
|
if ctx.invoked_subcommand is None:
|
|
await ctx.send('No subcommand invoked.')
|
|
|
|
@bot.command()
|
|
async def ping(self, ctx):
|
|
await ctx.message.delete()
|
|
embed = discord.Embed(title="Pong!",
|
|
description=str(round(self.bot.latency * 1000, 1)) + "ms",
|
|
colour=common.random_rgb())
|
|
embed.set_footer(text=f"requested by {ctx.author}",
|
|
icon_url=ctx.author.avatar_url)
|
|
await ctx.send(embed=embed)
|
|
|
|
@bot.command()
|
|
@commands.is_owner()
|
|
async def stop(self, ctx):
|
|
await ctx.message.delete()
|
|
embed = discord.Embed(title="Stopping Bot!",
|
|
color=common.random_rgb())
|
|
embed.set_footer(text=f"requested by {ctx.author}",
|
|
icon_url=ctx.author.avatar_url)
|
|
await ctx.send(embed=embed)
|
|
sys.exit()
|
|
|
|
@bot.command()
|
|
@commands.is_owner()
|
|
async def restart(self, ctx):
|
|
await ctx.message.delete()
|
|
embed = discord.Embed(title="Restarting Bot!",
|
|
color=common.random_rgb())
|
|
embed.set_footer(text=f"requested by {ctx.author}",
|
|
icon_url=ctx.author.avatar_url)
|
|
await ctx.send(embed=embed)
|
|
sys.exit(26)
|
|
|
|
@commands.group()
|
|
async def git(self, ctx):
|
|
if ctx.invoked_subcommand is None:
|
|
await ctx.send('No subcommand invoked.')
|
|
|
|
@git.command()
|
|
async def version(self, ctx):
|
|
await ctx.message.delete()
|
|
d = subprocess.run(["git", "show", "-s", "--format=%ci", self.commit],
|
|
capture_output=True,
|
|
encoding="utf-8")
|
|
m = subprocess.run(['git', 'show', '-s', '--format=%B', self.commit],
|
|
capture_output=True,
|
|
encoding="utf-8")
|
|
embed = discord.Embed(title="Bot Version",
|
|
description="Current Bot Version",
|
|
color=common.random_rgb(self.commit))
|
|
embed.set_footer(text=f"requested by {ctx.author}", icon_url=ctx.author.avatar_url)
|
|
embed.add_field(name="ID", value=self.commit, inline=False)
|
|
embed.add_field(name="Date", value=d.stdout, inline=False)
|
|
embed.add_field(name="Changelog", value=m.stdout, inline=False)
|
|
await ctx.send(embed=embed)
|
|
|
|
@git.command()
|
|
async def repo(self, ctx):
|
|
await ctx.message.delete()
|
|
embed = discord.Embed(title="Code Repository",
|
|
description="You can find my source code on [GitDab]("
|
|
f"{common.load_config('config.json')[0]['repo_link']}).",
|
|
color=common.random_rgb())
|
|
embed.set_footer(text=f"requested by {ctx.author}", icon_url=ctx.author.avatar_url)
|
|
await ctx.send(embed=embed)
|
|
|
|
|
|
def setup(bot):
|
|
bot.add_cog(System(bot))
|