Browse Source

clearwarns/clearwarnsid: added

main
Ave Ozkal 3 years ago
parent
commit
2c822dc5cb
  1. 5
      README.md
  2. 5
      Robocop.py
  3. 21
      cogs/admin.py
  4. 67
      cogs/mod.py
  5. 2
      data/warnsv2.json

5
README.md

@ -37,7 +37,7 @@ Based on https://gitlab.com/ao/dpybotbase
- [ ] Moderation: restrictions (people who leave with muted role will get muted role on join)
- [x] Warns: warn
- [x] Warns: listwarns-listwarnsid
- [ ] Warns: clearwarns-clearwarnsid
- [x] Warns: clearwarns-clearwarnsid
- [ ] Warns: delwarnid-delwarn
- [x] .serr and .err (thanks tomger!)
@ -54,5 +54,4 @@ Main goal of this project is to get Robocop functionality done, secondary goal i
- [ ] New moderation feature: User notes
- [ ] New moderation feature: watch-unwatch (using log module from akbbot)
- [ ] New moderation feature: timelock (channel lockdown with time)
- [ ] End of development: eval, fetchlog and sh might need to be removed at end of development
- [x] Remove sh, remove risky stuff from eval

5
Robocop.py

@ -15,7 +15,7 @@ log_file_name = f"{script_name}.log"
# Limit of discord (non-nitro) is 8MB (not MiB)
max_file_size = 1000 * 1000 * 8
backup_count = 10000 # random big number
backup_count = 3
file_handler = logging.handlers.RotatingFileHandler(
filename=log_file_name, maxBytes=max_file_size, backupCount=backup_count)
stdout_handler = logging.StreamHandler(sys.stdout)
@ -121,6 +121,9 @@ async def on_command_error(ctx, error):
return await ctx.send(f"{ctx.author.mention}: Check failed. "
"You might not have the right permissions "
"to run this command.")
elif isinstance(error, commands.CommandNotFound):
# Nothing to do when command is not found.
return
help_text = f"Usage of this command is: ```{ctx.prefix}"\
f"{ctx.command.signature}```\nPlease see `{ctx.prefix}help "\

21
cogs/admin.py

@ -131,27 +131,6 @@ class AdminCog:
f'```\n{traceback.format_exc()}\n```')
return
@commands.guild_only()
@commands.check(check_if_bot_manager)
@commands.command(hidden=True)
async def sh(self, ctx, *, command: str):
"""Runs a command on shell, bot manager only."""
command = command.strip('`')
tmp = await ctx.send(f'Running `{command}`...')
self.bot.log.info(f"Running {command}")
shell_output = await self.bot.async_call_shell(command)
shell_output = f"\"{command}\" output:\n\n{shell_output}"
self.bot.log.info(shell_output)
sliced_message = await self.bot.slice_message(shell_output,
prefix="```",
suffix="```")
if len(sliced_message) == 1:
await tmp.edit(content=sliced_message[0])
return
await tmp.delete()
for msg in sliced_message:
await ctx.send(msg)
@commands.guild_only()
@commands.check(check_if_bot_manager)
@commands.command(hidden=True)

67
cogs/mod.py

@ -156,6 +156,31 @@ class ModCog:
", it is recommended to use `.ban <user> [reason]`"\
" as the reason is automatically sent to the user."
@commands.guild_only()
@commands.bot_has_permissions(ban_members=True)
@commands.check(check_if_staff)
@commands.command()
async def hackban(self, ctx, target: int, *, reason: str = ""):
"""Bans a user with their ID, doesn't message them, staff only."""
target = ctx.guild.get_member(target)
if self.check_if_target_is_staff(target):
return await ctx.send("I can't ban this user as "
"they're a member of staff.")
safe_name = self.bot.escape_message(str(target))
await target.ban(reason=f"{ctx.author}, reason: {reason}",
delete_message_days=0)
chan_message = f"โ›” **Hackban**: {ctx.author.mention} banned "\
f"{target.mention} | {safe_name}\n"\
f"๐Ÿท __User ID__: {target.id}\n"
if reason:
chan_message += f"โœ๏ธ __Reason__: \"{reason}\""
else:
chan_message += "Please add an explanation below. In the future"\
", it is recommended to use `.ban <user> [reason]`"\
" as the reason is automatically sent to the user."
log_channel = self.bot.get_channel(config.log_channel)
await log_channel.send(chan_message)
await ctx.send(f"{safe_name} is now b&. ๐Ÿ‘")
@ -390,10 +415,24 @@ class ModCog:
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.description = "ID doesn't exist in saved "\
"warns (there likely aren't any warns)."
embed.color = discord.Color.green()
return embed
def clear_warns_from_id(self, uid: str):
with open("data/warnsv2.json", "r") as f:
warns = json.load(f)
if uid not in warns:
return f"<@{uid}> has no warns!"
warn_count = len(warns[uid]["warns"])
if not warn_count:
return f"<@{uid}> has no warns!"
warns[uid]["warns"] = []
with open("data/warnsv2.json", "w") as f:
json.dump(warns, f)
return f"<@{uid}> no longer has any warns!"
@commands.guild_only()
@commands.check(check_if_staff)
@commands.command()
@ -410,6 +449,32 @@ class ModCog:
embed = self.get_warns_embed_for_id(str(target), str(target))
await ctx.send(embed=embed)
@commands.guild_only()
@commands.check(check_if_staff)
@commands.command()
async def clearwarns(self, ctx, target: discord.Member):
"""Clear all warns for a user. Staff only."""
log_channel = self.bot.get_channel(config.log_channel)
msg = self.clear_warns_from_id(str(target.id))
await ctx.send(msg)
msg = f"๐Ÿ—‘ **Cleared warns**: {ctx.member.mention} cleared"\
f" warns of {target.mention} | "\
f"{self.bot.escape_message(target)}"
await log_channel.send(msg)
@commands.guild_only()
@commands.check(check_if_staff)
@commands.command()
async def clearwarnsid(self, ctx, target: int):
"""Clear all warns for a user from their userid. Staff only."""
log_channel = self.bot.get_channel(config.log_channel)
msg = self.clear_warns_from_id(str(target))
await ctx.send(msg)
msg = f"๐Ÿ—‘ **Cleared warns**: {ctx.member.mention} cleared"\
f" warns of <@{target}> | "\
f"{self.bot.escape_message(target)}"
await log_channel.send(msg)
def setup(bot):
bot.add_cog(ModCog(bot))

2
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"}}
{}
Loadingโ€ฆ
Cancel
Save