listwarns/listwarnsid: add

This commit is contained in:
Ave Ozkal 2018-12-24 01:36:36 +03:00
parent 9fba7b3075
commit 8022dec4d4
No known key found for this signature in database
GPG key ID: 09356ABAA42C842B
4 changed files with 40 additions and 5 deletions

View file

@ -36,9 +36,9 @@ Based on https://gitlab.com/ao/dpybotbase
- [x] Moderation: clear/purge - [x] Moderation: clear/purge
- [ ] Moderation: restrictions (people who leave with muted role will get muted role on join) - [ ] Moderation: restrictions (people who leave with muted role will get muted role on join)
- [x] Warns: warn - [x] Warns: warn
- [ ] Warns: delwarnid-delwarn - [x] Warns: listwarns-listwarnsid
- [ ] Warns: listwarns-listwarnsid
- [ ] Warns: clearwarns-clearwarnsid - [ ] Warns: clearwarns-clearwarnsid
- [ ] Warns: delwarnid-delwarn
- [x] .serr and .err (thanks tomger!) - [x] .serr and .err (thanks tomger!)
--- ---

View file

@ -50,13 +50,13 @@ class Logs:
with open("data/warnsv2.json", "r") as f: with open("data/warnsv2.json", "r") as f:
warns = json.load(f) warns = json.load(f)
try: try:
if len(warns[member.id]["warns"]) == 0: if len(warns[str(member.id)]["warns"]) == 0:
await log_channel.send(msg) await log_channel.send(msg)
else: else:
embed = discord.Embed(color=discord.Color.dark_red(), embed = discord.Embed(color=discord.Color.dark_red(),
title=f"Warns for {escaped_name}") title=f"Warns for {escaped_name}")
embed.set_thumbnail(url=member.avatar_url) 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']}", embed.add_field(name=f"{idx + 1}: {warn['timestamp']}",
value=f"Issuer: {warn['issuer_name']}" value=f"Issuer: {warn['issuer_name']}"
f"\nReason: {warn['reason']}") f"\nReason: {warn['reason']}")

View file

@ -375,6 +375,41 @@ class ModCog:
" as the reason is automatically sent to the user." " as the reason is automatically sent to the user."
await log_channel.send(msg) 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): def setup(bot):
bot.add_cog(ModCog(bot)) bot.add_cog(ModCog(bot))

View file

@ -1 +1 @@
{} {"420332322307571713": {"warns": [{"issuer_id": 137584770145058817, "issuer_name": "ao", "reason": "rule", "timestamp": "2018-12-24 01:23:14"}], "name": "Weed#9481"}}