-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt to auto jail mention bombers. #351
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,8 @@ def setup(self): | |
pass | ||
|
||
@staticmethod | ||
def build_reason(ctx, action, minutes, reason, past=False): | ||
full_reason = StringBuilder(f"{action} by {user_discrim(ctx.author)}") | ||
def build_reason_internal(message, action, minutes, reason, past=False): | ||
full_reason = StringBuilder(f"{action} by {user_discrim(message.author)}") | ||
if minutes: | ||
full_reason.write( | ||
f" {'for' if past else 'in'} {minutes} minute{plural(minutes)}" | ||
|
@@ -56,7 +56,11 @@ def build_reason(ctx, action, minutes, reason, past=False): | |
full_reason.write(f" with reason: {reason}") | ||
return str(full_reason) | ||
|
||
async def remove_roles(self, ctx, member, minutes, action, reason): | ||
@staticmethod | ||
def build_reason(ctx, action, minutes, reason, past=False): | ||
return Moderation.build_reason_internal(ctx.message, action, minutes, reason, past) | ||
|
||
async def remove_roles_internal(self, message, member, minutes, action, reason): | ||
assert minutes | ||
|
||
logger.info( | ||
|
@@ -71,7 +75,7 @@ async def remove_roles(self, ctx, member, minutes, action, reason): | |
task = PunishTask( | ||
self.bot, | ||
None, | ||
ctx.author, | ||
message.author, | ||
timestamp, | ||
None, | ||
member=member, | ||
|
@@ -80,6 +84,9 @@ async def remove_roles(self, ctx, member, minutes, action, reason): | |
) | ||
self.bot.add_tasks(task) | ||
|
||
async def remove_roles(self, ctx, member, minutes, action, reason): | ||
await self.remove_roles_internal(ctx.message, member, minutes, action, reason) | ||
|
||
@commands.command(name="nick", aliases=["nickname", "renick"]) | ||
@commands.guild_only() | ||
@permissions.check_perm("manage_nicknames") | ||
|
@@ -169,25 +176,28 @@ async def unmute( | |
else: | ||
await self.bot.punish.unjail(ctx.guild, member, reason) | ||
|
||
async def perform_jail(self, ctx, member, minutes, reason): | ||
roles = self.bot.sql.settings.get_special_roles(ctx.guild) | ||
async def perform_jail_internal(self, message, member, minutes, reason): | ||
roles = self.bot.sql.settings.get_special_roles(message.guild) | ||
if roles.jail is None: | ||
raise CommandFailed(content="No configured jail role") | ||
|
||
if member.top_role >= ctx.me.top_role: | ||
if member.top_role >= self.bot.user.top_role: | ||
raise ManualCheckFailure("I don't have permission to jail this user") | ||
|
||
minutes = max(minutes, 0) | ||
reason = self.build_reason(ctx, "Jailed", minutes, reason) | ||
reason = self.build_reason_internal(message, "Jailed", minutes, reason) | ||
|
||
await self.bot.punish.jail(ctx.guild, member, reason) | ||
await self.bot.punish.jail(message.guild, member, reason) | ||
|
||
# If a delayed event, schedule a Navi task | ||
if minutes: | ||
await self.remove_roles( | ||
ctx, member, minutes, PunishAction.RELIEVE_JAIL, reason | ||
await self.remove_roles_internal( | ||
message, member, minutes, PunishAction.RELIEVE_JAIL, reason | ||
) | ||
|
||
async def perform_jail(self, ctx, member, minutes, reason): | ||
await self.perform_jail_internal(ctx.message, member, minutes, reason) | ||
|
||
@commands.command(name="jail", aliases=["dunce"]) | ||
@commands.guild_only() | ||
@permissions.check_perm("manage_roles") | ||
|
@@ -201,6 +211,17 @@ async def jail(self, ctx, member: MemberConv, *, reason: str = None): | |
|
||
await self.perform_jail(ctx, member, 0, reason) | ||
|
||
async def on_message(self, message): | ||
""" | ||
Bot Event. | ||
:param message: Messages. | ||
:return: Nothing. | ||
""" | ||
if len(message.mentions) > 5: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On another thought I probably should ensure that this line does not count the same mention more than once like for example if they did But then again it could be considered annoying too so probably should dunce them too in that case as well. Edit: Or even the case where they mention themselves multiple times too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is too simplistic. In addition to the self-mentioning problem above, this also doesn't account for multiple messages in quick succession with multiple mentions. Finally, if we have a threshold like this it should be configurable per-guild. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright I might need to look further into what you do to store the configuration, also might need to somehow store a datetime of the user's last mention like this as well so that way it can pick up any and all history on that action they done? |
||
await self.perform_jail_internal( | ||
message, message.author, 0, "Mention Bombing." | ||
) | ||
|
||
@commands.command(name="djail", aliases=["ddunce", "timejail", "timedunce"]) | ||
@commands.guild_only() | ||
@permissions.check_perm("manage_roles") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User
s do not have roles.ctx.me
is theMember
version of the bot, which is associated with a guild and does have rules.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to get the
Member
version of the bot without usingctx
since it would be impossible to usectx
inon_message
?