Pylint Compliance

- Modifies codebase to match conventions set by Pylint.
- Added update command to template.
This commit is contained in:
InValidFire 2021-03-30 18:42:07 -04:00
parent f928c6df20
commit 58ca231454
5 changed files with 54 additions and 30 deletions

View file

@ -1,27 +1,33 @@
from discord.ext import commands
import discord
import core.common as common
"""System Module from Bot Template"""
import sys
import subprocess
import logging
from discord.ext import commands
import discord
import core.common as common
logger = logging.getLogger(__name__)
class System(commands.Cog):
"""System Cog from Bot Template"""
def __init__(self, bot):
self.bot = bot
self.commit = subprocess.run(["git", "show", "-s", "--format=%h"],
capture_output=True,
encoding="utf-8").stdout.strip()
encoding="utf-8", check=True).stdout.strip()
@commands.group()
async def bot(self, ctx):
async def bot_group(self, ctx):
"""Command group for core bot commands"""
if ctx.invoked_subcommand is None:
await ctx.send('No subcommand invoked.')
@bot.command()
@bot_group.command()
async def ping(self, ctx):
"""Ping the bot"""
await ctx.message.delete()
embed = discord.Embed(title="Pong!",
description=str(round(self.bot.latency * 1000, 1)) + "ms",
@ -30,9 +36,10 @@ class System(commands.Cog):
icon_url=ctx.author.avatar_url)
await ctx.send(embed=embed)
@bot.command()
@bot_group.command()
@commands.is_owner()
async def stop(self, ctx):
"""Stop the bot"""
await ctx.message.delete()
embed = discord.Embed(title="Stopping Bot!",
color=common.random_rgb())
@ -41,9 +48,10 @@ class System(commands.Cog):
await ctx.send(embed=embed)
sys.exit()
@bot.command()
@bot_group.command()
@commands.is_owner()
async def restart(self, ctx):
"""Restart the bot"""
await ctx.message.delete()
embed = discord.Embed(title="Restarting Bot!",
color=common.random_rgb())
@ -52,31 +60,28 @@ class System(commands.Cog):
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()
@bot_group.command()
async def version(self, ctx):
"""Get bot version"""
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")
commit_date = subprocess.run(["git", "show", "-s", "--format=%ci", self.commit],
capture_output=True, check=True,
encoding="utf-8").stdout.strip()
commit_msg = subprocess.run(['git', 'show', '-s', '--format=%B', self.commit],
capture_output=True, check=True,
encoding="utf-8").stdout.strip()
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)
embed.add_field(name="Date", value=commit_date, inline=False)
embed.add_field(name="Changelog", value=commit_msg, inline=False)
await ctx.send(embed=embed)
@git.command()
@bot_group.command()
async def repo(self, ctx):
"""Display the bot repository"""
await ctx.message.delete()
embed = discord.Embed(title="Code Repository",
description="You can find my source code on [GitDab]("
@ -85,6 +90,19 @@ class System(commands.Cog):
embed.set_footer(text=f"requested by {ctx.author}", icon_url=ctx.author.avatar_url)
await ctx.send(embed=embed)
@bot_group.command()
@commands.is_owner()
async def update(self, ctx):
"""Update the bot"""
ctx: commands.Context
await ctx.message.delete()
response = subprocess.run(["git", "pull"], capture_output=True, check=True,
encoding="utf-8").stdout.strip()
embed=discord.Embed(title="Update Report", description=response, 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):
"""Initialize the cog"""
bot.add_cog(System(bot))