added error command
This commit is contained in:
parent
a1a1886e17
commit
4fa1892578
1 changed files with 30 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ class Admin(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.admin_ids = [242018983241318410]
|
self.admin_ids = [242018983241318410]
|
||||||
|
self.log_file = "logs/info.log"
|
||||||
|
|
||||||
@commands.command(
|
@commands.command(
|
||||||
description="Kill",
|
description="Kill",
|
||||||
|
|
@ -59,5 +60,34 @@ class Admin(commands.Cog):
|
||||||
await ctx.send("You don't have permission to do this.")
|
await ctx.send("You don't have permission to do this.")
|
||||||
self.bot.logger.info(f"Update command attempted by {ctx.author.id}")
|
self.bot.logger.info(f"Update command attempted by {ctx.author.id}")
|
||||||
|
|
||||||
|
def is_error(self, log_line):
|
||||||
|
if "ERROR" in log_line:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@commands.command(
|
||||||
|
description="Errors",
|
||||||
|
help="This will display the last X errors",
|
||||||
|
brief="Displays errors",
|
||||||
|
hidden=True
|
||||||
|
)
|
||||||
|
async def errors(self, ctx, amount=5):
|
||||||
|
if ctx.author.id in self.admin_ids:
|
||||||
|
self.bot.logger.info(f"Errors command ran by {ctx.author.id}")
|
||||||
|
with open(self.log_file, 'r', encoding="utf-8") as log:
|
||||||
|
data = log.readlines()
|
||||||
|
log.close()
|
||||||
|
errors = []
|
||||||
|
for line in data[::-1]:
|
||||||
|
if self.is_error(line):
|
||||||
|
errors.append(line)
|
||||||
|
if len(errors) >= amount:
|
||||||
|
break
|
||||||
|
await ctx.send("```\n" + "\n".join(errors[::-1]) + "```")
|
||||||
|
else:
|
||||||
|
await ctx.send("You don't have permission to do this.")
|
||||||
|
self.bot.logger.info(f"Update command attempted by {ctx.author.id}")
|
||||||
|
|
||||||
async def setup(bot):
|
async def setup(bot):
|
||||||
await bot.add_cog(Admin(bot))
|
await bot.add_cog(Admin(bot))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue