Add ban and kick

Also, message escaping stuffs were added to common and meme was updated
accordingly
This commit is contained in:
Ave Ozkal 2018-12-23 18:33:59 +03:00
parent b787589ef7
commit 0c9352fe33
No known key found for this signature in database
GPG key ID: 09356ABAA42C842B
4 changed files with 87 additions and 3 deletions

View file

@ -19,8 +19,8 @@ Based on https://gitlab.com/ao/dpybotbase
- [ ] Logging: message deletes
- [ ] Logging: bans
- [ ] Logging: kicks
- [ ] Moderation: ban
- [ ] Moderation: kick
- [x] Moderation: ban
- [x] Moderation: kick
- [x] Moderation: userinfo
- [ ] Moderation: approve-revoke (community)
- [ ] Moderation: addhacker-removehacker

View file

@ -17,6 +17,7 @@ class Common:
self.bot.aioget = self.aioget
self.bot.aiogetbytes = self.aiogetbytes
self.bot.get_relative_timestamp = self.get_relative_timestamp
self.bot.escape_message = self.escape_message
def get_relative_timestamp(self, time_from=None, time_to=None,
humanized=False, include_from=False,
@ -98,6 +99,10 @@ class Common:
"""Turns a given hex color into an integer"""
return int("0x" + color_hex.strip('#'), 16)
def escape_message(self, text: str):
"""Escapes unfun stuff from messages"""
return text.replace("@", "@ ").replace("#", "# ")
# This function is based on https://stackoverflow.com/a/35435419/3286892
# by link2110 (https://stackoverflow.com/users/5890923/link2110)
# modified by Ave (https://github.com/aveao), licensed CC-BY-SA 3.0

View file

@ -21,7 +21,7 @@ class Meme:
@commands.command(hidden=True, name="bam")
async def bam_member(self, ctx, user: discord.Member):
"""Bams a user owo"""
await ctx.send(f"{self.bot.escape_name(user)} is ̶n͢ow b̕&̡.̷ 👍̡")
await ctx.send(f"{self.bot.escape_message(user)} is ̶n͢ow b̕&̡.̷ 👍̡")
@commands.check(check_if_staff_or_ot)
@commands.command(hidden=True, name="warm")

View file

@ -6,10 +6,89 @@ import config
class AdminCog:
def __init__(self, bot):
self.bot = bot
self.modlog_channel = bot.get_channel(config.modlog_channel)
def check_if_staff(ctx):
return any(r.id in config.staff_role_ids for r in ctx.author.roles)
def check_if_target_is_staff(self, target):
return any(r.id in config.staff_role_ids for r in target.roles)
@commands.bot_has_permissions(kick_members=True)
@commands.check(check_if_staff)
@commands.command()
async def kick(self, ctx, target: discord.Member, *, reason: str = ""):
"""Kicks a user, staff only."""
if self.check_if_target_is_staff(target):
return await ctx.send("I can't kick this user as "
"they're a member of staff.")
safe_name = self.bot.escape_message(str(target))
dm_message = f"You were kicked from {ctx.guild.name}."
if reason:
dm_message += f" The given reason is: \"{reason}\"."
dm_message += "\n\nYou are able to rejoin the server,"\
" but please be sure to behave when participating again."
try:
await target.send(dm_message)
except discord.errors.Forbidden:
# Prevents kick issues in cases where user blocked bot
# or has DMs disabled
pass
await target.kick(reason=f"{ctx.author}, reason: {reason}")
chan_message = f"👢 **Kick**: {ctx.author.mention} kicked "\
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."
await self.modlog_channel.send(chan_message)
@commands.bot_has_permissions(ban_members=True)
@commands.check(check_if_staff)
@commands.command()
async def ban(self, ctx, target: discord.Member, *, reason: str = ""):
"""Bans a user, staff only."""
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))
dm_message = f"You were banned from {ctx.guild.name}."
if reason:
dm_message += f" The given reason is: \"{reason}\"."
dm_message += "\n\nThis ban does not expire."
try:
await target.send(dm_message)
except discord.errors.Forbidden:
# Prevents kick issues in cases where user blocked bot
# or has DMs disabled
pass
await target.ban(reason=f"{ctx.author}, reason: {reason}",
delete_message_days=0)
chan_message = f"👢 **Ban**: {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."
await self.modlog_channel.send(chan_message)
await ctx.send(f"{safe_name} is now b&. 👍")
@commands.check(check_if_staff)
@commands.command()
async def userinfo(self, ctx, *, user: discord.Member):