def warn_user(self, event, member, reason: str = None): """ ***The Warn Command*** This command will warn target member, and serve out the according punishment. (For minor infractions) ***Required Values*** > __member__ **The user's full discord name, mention, or ID** **Optional Values** > __reason__ **The reason for the user's warning** """ if reason is not None: Infraction.create(user=member.id, type="warn", reason=reason, moderator=event.author.id, date=int(time())) else: Infraction.create(user=member.id, type="warn", moderator=event.author.id, date=int(time())) event.msg.add_reaction("👍") dm = member.user.open_dm() if reason is not None: dm.send_message(self.config['msgs']['warn'].format( reason=reason, length=self.config['auto_actions']['warn']['mute'] // 60)) self.log_action("Warn", "{t.mention} was warned for '{r}' by {m.mention}", member, r=reason, m=event.author) else: dm.send_message(self.config['msgs']['warn_no_reason'].format( length=self.config['auto_actions']['warn']['mute'] // 60)) self.log_action( "Warn", "{t.mention} was warned, no reason was provided, by {m.mention}", member, e=event.author) if not len( Infraction.find(Infraction.user == member.id, Infraction.type == 'warn')) % self.config['warns_to_strike']: dm.send_message(self.config['msgs']['strike_auto'].format( length=self.config['auto_actions']['strike']['mute'] // 60)) self.execute_action(member, self.config['auto_actions']['strike']) else: self.execute_action(member, self.config['auto_actions']['warn'])
def strike_user(self, event, member, reason: str = None): """ ***The Strike Command*** This command will strike a member, and serve out the according punishment. (For serious infractions) ***Required Values*** > __member__ **The user's full discord name, mention, or ID** **Optional Values** > __reason__ **The reason for the strike** """ if reason is not None: Infraction.create(user=member.id, type="strike", reason=reason, moderator=event.author.id, date=int(time())) else: Infraction.create(user=member.id, type="strike", moderator=event.author.id, date=int(time())) event.msg.add_reaction("👍") dm = member.user.open_dm() if reason is not None: dm.send_message(self.config['msgs']['strike_manual'].format( reason=reason, length=self.config['auto_actions']['strike']['mute'] // 60)) self.log_action("Strike", "{t.mention} was striked for '{r}' by {m.mention}", member, r=reason, m=event.author) else: dm.send_message( self.config['msgs']['strike_manual_no_reason'].format( length=self.config['auto_actions']['strike']['mute'] // 60)) self.log_action( "Strike", "{t.mention} was striked, no reason was provided, by {m.mention}", member, e=event.author) if len( Infraction.find(Infraction.user == member.id, Infraction.type == "strike")) == self.config['strike_to_ban']: member.ban() else: self.execute_action(member, self.config['auto_actions']['strike'])
def expire_infractions(self): for infraction in Infraction.find_all(): if infraction.type == "warn" and time( ) - infraction.date > 7.884e+6: infraction.delete_self() elif infraction.type == "strike" and time( ) - infraction.date > 1.577e+7: infraction.delete_self()
def strike_user(self, event, member, reason: str = None): if reason is not None: Infraction.create(user=member.id, type="strike", reason=reason, moderator=event.author.id, date=int(time())) else: Infraction.create(user=member.id, type="strike", moderator=event.author.id, date=int(time())) event.msg.add_reaction("👍") dm = member.user.open_dm() if reason is not None: dm.send_message( self.config['msgs']['strike_manual'].format(reason=reason)) self.log_action("Strike", "{t.mention} was striked for '{r}' by {m.mention}", member, r=reason, m=event.author) else: dm.send_message(self.config['msgs']['strike_manual_no_reason']) self.log_action( "Strike", "{t.mention} was striked, no reason was provided, by {m.mention}", member, e=event.author) if len( Infraction.find(Infraction.user == member.id, Infraction.type == "strike")) == self.config['strike_to_ban']: member.ban() else: self.execute_action(member, self.config['auto_actions']['strike'])
def warn_user(self, event, member, reason: str = None): if reason is not None: Infraction.create(user=member.id, type="warn", reason=reason, moderator=event.author.id, date=int(time())) else: Infraction.create(user=member.id, type="warn", moderator=event.author.id, date=int(time())) event.msg.add_reaction("👍") dm = member.user.open_dm() if reason is not None: dm.send_message(self.config['msgs']['warn'].format(reason=reason)) self.log_action("Warn", "{t.mention} was warned for '{r}' by {m.mention}", member, r=reason, m=event.author) else: dm.send_message(self.config['msgs']['warn_no_reason']) self.log_action( "Warn", "{t.mention} was warned, no reason was provided, by {m.mention}", member, e=event.author) if not len( Infraction.find(Infraction.user == member.id, Infraction.type == 'warn')) % self.config['warns_to_strike']: dm.send_message(self.config['msgs']['strike_auto']) self.execute_action(member, self.config['auto_actions']['strike']) else: self.execute_action(member, self.config['auto_actions']['warn'])
def get_history(self, member, show_mods: bool): infractions = Infraction.find(Infraction.user == member.id) total_warns = len([i for i in infractions if i.type == "warn"]) active_warns = total_warns % self.config['warns_to_strike'] active_strikes = len([i for i in infractions if i.type == "strike"]) \ + total_warns // self.config['warns_to_strike'] embed = MessageEmbed() embed.title = member.name + "'s History" embed.description = f"""__**Details:**__ Total Warnings: **{active_warns} / {self.config['warns_to_strike']}** Total Strikes: **{active_strikes} / {self.config['strike_to_ban']}** Strikes from Warnings: **{total_warns // self.config['warns_to_strike']}** Account Creation date: **{to_datetime(member.id)}** """ embed.set_thumbnail(url=member.user.get_avatar_url()) embed.color = 0x6832E3 embeds = [embed] if infractions: embed.description += """ __**Infractions**__ """ infraction_base = """ ICIN: **{}** Type: **{}** Reason: ***{}*** Date: **{}** {}""" for i, infraction in enumerate(infractions): new_infraction = infraction_base.format( i, infraction.type, infraction.reason or "", datetime.utcfromtimestamp(infraction.date), f"Moderator: <@{infraction.moderator}>" if show_mods else "") if len(embeds[-1].description + new_infraction) >= 2048: next_embed = MessageEmbed() next_embed.color = 0x6832E3 next_embed.description = new_infraction embeds.append(next_embed) else: embeds[-1].description += new_infraction return embeds
def repeal_infraction(self, event, member, ICIN: int): """ ***The Repeal Command*** This command will remove an infraction from a user, either a warn or a strike. Keep in mind, infractions will expire naturally so only remove if it was a mistake. ***Required Values*** > __member__ **The user's full discord name, mention, or ID** > __ICIN__ **The infraction's ID, check history if unsure** """ for i, infraction in enumerate( Infraction.find(Infraction.user == member.id)): if i == ICIN: infraction.delete_self() event.msg.add_reaction("👍") break else: event.msg.reply("ICIN does not exist for that user, sorry.")