From 8022dec4d40e5660f1729fccc70a6ad0a65bf77f Mon Sep 17 00:00:00 2001 From: Ave Ozkal Date: Mon, 24 Dec 2018 01:36:36 +0300 Subject: [PATCH] listwarns/listwarnsid: add --- README.md | 4 ++-- cogs/logs.py | 4 ++-- cogs/mod.py | 35 +++++++++++++++++++++++++++++++++++ data/warnsv2.json | 2 +- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 022f8ae..a7325ea 100755 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ Based on https://gitlab.com/ao/dpybotbase - [x] Moderation: clear/purge - [ ] Moderation: restrictions (people who leave with muted role will get muted role on join) - [x] Warns: warn -- [ ] Warns: delwarnid-delwarn -- [ ] Warns: listwarns-listwarnsid +- [x] Warns: listwarns-listwarnsid - [ ] Warns: clearwarns-clearwarnsid +- [ ] Warns: delwarnid-delwarn - [x] .serr and .err (thanks tomger!) --- diff --git a/cogs/logs.py b/cogs/logs.py index 8a1f78f..b22fe57 100644 --- a/cogs/logs.py +++ b/cogs/logs.py @@ -50,13 +50,13 @@ class Logs: with open("data/warnsv2.json", "r") as f: warns = json.load(f) try: - if len(warns[member.id]["warns"]) == 0: + if len(warns[str(member.id)]["warns"]) == 0: await log_channel.send(msg) else: embed = discord.Embed(color=discord.Color.dark_red(), title=f"Warns for {escaped_name}") embed.set_thumbnail(url=member.avatar_url) - for idx, warn in enumerate(warns[member.id]["warns"]): + for idx, warn in enumerate(warns[str(member.id)]["warns"]): embed.add_field(name=f"{idx + 1}: {warn['timestamp']}", value=f"Issuer: {warn['issuer_name']}" f"\nReason: {warn['reason']}") diff --git a/cogs/mod.py b/cogs/mod.py index f17ee09..4545ba8 100644 --- a/cogs/mod.py +++ b/cogs/mod.py @@ -375,6 +375,41 @@ class ModCog: " as the reason is automatically sent to the user." await log_channel.send(msg) + def get_warns_embed_for_id(self, uid: str, name: str): + embed = discord.Embed(color=discord.Color.dark_red()) + embed.set_author(name=f"Warns for {name}") + with open("data/warnsv2.json", "r") as f: + warns = json.load(f) + try: + if len(warns[uid]["warns"]): + for idx, warn in enumerate(warns[uid]["warns"]): + embed.add_field(name=f"{idx + 1}: {warn['timestamp']}", + value=f"Issuer: {warn['issuer_name']}\n" + f"Reason: {warn['reason']}") + else: + embed.description = "There are none!" + embed.color = discord.Color.green() + except KeyError: # if the user is not in the file + embed.description = "There are none!" + embed.color = discord.Color.green() + return embed + + @commands.guild_only() + @commands.check(check_if_staff) + @commands.command() + async def listwarns(self, ctx, target: discord.Member): + """List warns for a user. Staff only.""" + embed = self.get_warns_embed_for_id(str(target.id), str(target)) + await ctx.send(embed=embed) + + @commands.guild_only() + @commands.check(check_if_staff) + @commands.command() + async def listwarnsid(self, ctx, target: int): + """List warns for a user by ID. Staff only.""" + embed = self.get_warns_embed_for_id(str(target), str(target)) + await ctx.send(embed=embed) + def setup(bot): bot.add_cog(ModCog(bot)) diff --git a/data/warnsv2.json b/data/warnsv2.json index 0967ef4..abb1540 100644 --- a/data/warnsv2.json +++ b/data/warnsv2.json @@ -1 +1 @@ -{} +{"420332322307571713": {"warns": [{"issuer_id": 137584770145058817, "issuer_name": "ao", "reason": "rule", "timestamp": "2018-12-24 01:23:14"}], "name": "Weed#9481"}} \ No newline at end of file