Exemple #1
0
    def message_listener(self, event):
        # Because we don't have Bug-bot access, we have to do it like this :(
        try:
            content = event.message.content
            if event.message.author.id != self.config.bug_bot_user_id:
                return
            long_repro_msg = "your repro has been successfully added to the Trello Ticket!"

            # handles approve/deny reports
            if "you've successfully approved report" in content or "you've successfully denied report" in content:
                if len(event.message.mentions) != 1:
                    return
                for k in event.message.mentions.keys():
                    self.handle_action(k, "approve_deny", True)
            # handles canrepro/cantrepro
            elif "your reproduction has been added to the ticket" in content or long_repro_msg in content:
                if len(event.message.mentions) != 1:
                    return
                for k, v in event.message.mentions.items():
                    self.handle_action(k, "canrepro_cantrepro", True)

            elif content.startswith(":incoming_envelope:"):
                if len(event.message.mentions) != 1:
                    return
                for uid in event.message.mentions.keys():
                    self.handle_action(uid, "submit", True)
            elif "your attachment has been added." in content:
                if len(event.message.mentions) != 1:
                    return
                for uid in event.message.mentions.keys():
                    self.handle_action(uid, "attach", True)
        except Exception as exception:
            handle_exception(event, self.bot, exception)
Exemple #2
0
 def _slowmode(self, event, channel, time):
     if time > 120:
         return event.msg.reply("You can only have slowmode up to 120 seconds.")
     try:
         if channel != int:
             self.client.api.channels_modify(channel.id, rate_limit_per_user=time)
             event.msg.reply(f"Successfully set `{time}` seconds of slowmode in <#{channel.id}>.")
         else:
             self.client.api.channels_modify(channel, rate_limit_per_user=time)
             event.msg.reply(f"Successfully set `{time}` seconds of slowmode in <#{channel}>.")
     except APIException as e:
         event.msg.reply(f"Failed to apply slowmode in <#{channel.id}>.")
         handle_exception(event, self.bot, e)
Exemple #3
0
 def change_verification_level(self, event, level, reason = None):
     vl = VerificationLevel.get(level.lower())
     if vl is not None:
         if event.guild.verification_level != vl:
             try:
                 self.bot.client.api.guilds_modify(event.guild.id, reason, verification_level=vl.value)
             except APIException as e:
                 event.msg.reply("Failed to change the server verification level")
                 handle_exception(event, self.bot, e)
             else:
                 if reason is None:
                     reason = ""
                 else:
                     reason = " with reason `{}`".format(reason)
                 log_to_bot_log(self.bot,
                                ":vertical_traffic_light: {} changed the server verification level to {}{}".format(
                                    event.msg.author, level, reason))
                 event.msg.reply("Server verification level changed successfully")
         else:
             event.msg.reply("The server verification level is already set to {}".format(level))
     else:
         event.msg.reply("That level name doesn't seem to be valid")
Exemple #4
0
 def on_message_create(self, event):
     if event.author.id != self.config.bug_bot_user_id:
         return
     action = None
     # Bot Log - covers almost all events
     if event.channel.id == self.config.channels['bot-log']:
         # Try to find an event/action match for the message
         for act in self.exp:
             if act == 'denied':
                 continue
             match = self.exp[act].match(event.message.content)
             if match:
                 if act == 'approved':
                     link = match.group(1)
                     report_id = int(match.group(2))
                 else:
                     report_id = int(match.group(1))
                 action = act
                 break
     # Denied Bugs - only denied tickets
     elif event.channel.id == self.config.channels['denied-bugs']:
         try:
             report_id = int(self.exp['denied'].search(event.message.content).group(0))
         except AttributeError as e:
             # Couldn't extract the report ID from the message
             handle_exception(event, self.bot, e)
         else:
             action = 'denied'
     # Approval Queue - to track new tickets
     elif event.channel.id == self.config.channels['bug-approval-queue']:
         search = re.findall(r'(?<=Report\sID:\s\*{2})[0-9]+', event.message.content)
         if search:
             # Get the last ID in case the report includes the format above
             report_id = int(search[-1])
             self.reports.insert_one({'report_id': report_id, 'subs': {}, 'queue_msg': event.message.id})
     # Check if we need to send a DM update
     if action is not None:
         report = self.reports.find_one({'report_id': report_id})
         if report is not None:
             if len(report['subs']) > 0:
                 action_scope = Scope[action.upper()]
                 # Linkify the report ID
                 if action == 'approved':
                     report_str = f'report [**#{report_id}**]({link})'
                 elif action == 'denied':
                     report_str = f'report **#{report_id}**'
                 else:
                     link = self._build_jump_link(event.guild.id, self.config.channels['bug-approval-queue'],
                                                  report['queue_msg'])
                     report_str = f'report [**#{report_id}**]({link})'
                 em = MessageEmbed()
                 em.title = f'{SCOPE_DATA[action][0]} (#{report_id})'
                 desc = SCOPE_DATA[action][1].format(report=report_str)
                 em.description = desc[0].upper() + desc[1:]
                 em.color = '7506394'
                 uc = 0
                 for k, v in report['subs'].items():
                     if action_scope & Scope(v):
                         dm = self.bot.client.api.users_me_dms_create(int(k))
                         try:
                             dm.send_message(embed=em)
                         except APIException:
                             # Closed DMs
                             pass
                         else:
                             uc += 1
                 if uc > 0:
                     log_to_bot_log(self.bot,
                                    f':pager: `{action.upper()}` notification for **#{report_id}** sent to {uc} user(s)')
             if action in ['approved', 'denied']:
                 self.reports.delete_one({'report_id': report_id})