listwarns/listwarnsid: add
This commit is contained in:
parent
9fba7b3075
commit
8022dec4d4
4 changed files with 40 additions and 5 deletions
|
@ -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!)
|
||||
|
||||
---
|
||||
|
|
|
@ -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']}")
|
||||
|
|
35
cogs/mod.py
35
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))
|
||||
|
|
|
@ -1 +1 @@
|
|||
{}
|
||||
{"420332322307571713": {"warns": [{"issuer_id": 137584770145058817, "issuer_name": "ao", "reason": "rule", "timestamp": "2018-12-24 01:23:14"}], "name": "Weed#9481"}}
|
Loading…
Reference in a new issue