Example #1
0
    def cmd_earthquake(self):
        output_channel = self.input_channel
        output_broadcast = False

        if self.lp.my_date:
            for merb in self.merbs.merbs:
                merb.update_pop(self.lp.my_date, str(self.input_author))

            self.merbs.save_timers()

            output_date = timeh.change_tz(
                timeh.naive_to_tz(self.lp.my_date, "UTC"), self.lp.timezone)
            output_content = "Earthquake! All pop times updated [%s] %s, signed by %s" % \
                             (output_date.strftime(config.DATE_FORMAT_PRINT),
                              self.lp.timezone,
                              self.input_author
                              )
            output_broadcast = self.get_broadcast_channels()

        else:
            output_content = errors.error_param(self.lp.cmd,
                                                "Time Syntax Error. ")
            output_channel = self.input_author

        return {
            "destination": output_channel,
            "content": messagecomposer.prettify(output_content, "CSS"),
            'broadcast': output_broadcast
        }
Example #2
0
    def cmd_target(self):
        output_channel = self.input_channel
        output_broadcast = False

        if self.lp.merb_found:
            if "off" in self.lp.key_words:
                self.lp.merb_found.target = False
                output_content = "Target OFF for [%s] " % self.lp.merb_found.name
            else:
                self.lp.merb_found.target = True
                output_content = "Target ON for [%s]" % self.lp.merb_found.name
            output_content += "- signed by %s" % self.input_author.name
            self.merbs.save_targets()
            output_broadcast = self.get_broadcast_channels()
        # If there is a guessed merb
        elif self.lp.merb_guessed:
            output_content = "Merb not found. Did you mean %s?" % self.lp.merb_guessed.name
            output_channel = self.input_author
        else:
            output_content = errors.error_param(self.lp.cmd,
                                                "Missing Parameter. ")
            output_channel = self.input_author

        return {
            "destination": output_channel,
            "content": messagecomposer.prettify(output_content, "CSS"),
            "broadcast": output_broadcast
        }
Example #3
0
    def update_merb(self, mode="tod"):
        output_channel = self.input_channel
        output_broadcast = False

        # Check for approx, exact for default
        approx = 1
        approx_output = ""
        if "approx" in self.lp.key_words:
            approx = 0
            approx_output = "~"

        # If there is a Merb
        if self.lp.merb_found:
            # Check if we have a date
            if self.lp.my_date:
                # UPDATE THE TOD
                if mode == "tod":
                    self.lp.merb_found.update_tod(self.lp.my_date,
                                                  str(self.input_author),
                                                  approx)
                if mode == "pop":
                    self.lp.merb_found.update_pop(self.lp.my_date,
                                                  str(self.input_author))
                # save merbs
                self.merbs.save_timers()
                output_date = timeh.change_tz(
                    timeh.naive_to_tz(self.lp.my_date, "UTC"),
                    self.lp.timezone)
                output_content = "[%s] updated! New %s: {%s %s} - %ssigned by %s" % \
                                 (self.lp.merb_found.name,
                                  mode,
                                  output_date.strftime(config.DATE_FORMAT_PRINT),
                                  self.lp.timezone,
                                  approx_output,
                                  self.input_author.name)

                output_broadcast = self.get_broadcast_channels()

            else:
                output_content = errors.error_param(self.lp.cmd,
                                                    "Time Syntax Error. ")
                output_channel = self.input_author

        # If there is a guessed merb
        elif self.lp.merb_guessed:
            output_content = "Merb not found. Did you mean %s?" % self.lp.merb_guessed.name
            output_channel = self.input_author
        # If no merb
        else:
            output_channel = self.input_author
            output_content = errors.error_merb_not_found()

        return {
            "destination": output_channel,
            "content": messagecomposer.prettify(output_content, "CSS"),
            'broadcast': output_broadcast
        }
Example #4
0
    def cmd_get(self):
        output_channel = self.input_channel
        output_broadcast = False

        # print merbs in target
        if "target" in self.lp.key_words:
            output_content = "NEXT TARGETS\n"
            output_content += "=" * (len(output_content) - 1) + "\n\n"
            output_content += messagecomposer.output_list(
                self.merbs.get_all_targets())
        # print merbs by tag
        elif self.lp.tag:
            output_content = "#%s\n" % self.lp.tag.upper()
            output_content += "=" * len(self.lp.tag) + "\n\n"
            output_content += messagecomposer.output_list(
                self.merbs.get_all_by_tag(self.lp.tag))

        # print only merbs in windows
        elif "window" in self.lp.key_words:
            output_content = "MERBS IN WINDOW\n"
            output_content += "=" * len(output_content) + "\n\n"
            output_content += messagecomposer.output_list(
                self.merbs.get_all_window())

        # print a list of all merbs
        elif "all" in self.lp.key_words:
            output_content = messagecomposer.output_list(
                self.merbs.get_all(self.lp.timezone, 'countdown'))

        # print single merb
        elif self.lp.merb_found:
            if "info" in self.lp.key_words:
                output_content = self.lp.merb_found.print_long_info(
                    self.lp.timezone)
            else:
                output_content = self.lp.merb_found.print_short_info()

        # no parameter recognized but a guessed merb
        elif self.lp.merb_guessed:
            output_content = "Merb not found. Did you mean %s?" % self.lp.merb_guessed.name
            output_channel = self.input_author

        # no parameter recognized
        else:
            output_content = errors.error_param(self.lp.cmd,
                                                "Missing Parameter. ")
            output_channel = self.input_author

        return {
            "destination": output_channel,
            "content": messagecomposer.prettify(output_content, "CSS"),
            'broadcast': output_broadcast
        }
Example #5
0
    def cmd_target(self):
        output_channel = self.input_channel
        output_messages = list()

        # Merb not found
        if not self.lp.merb_found:
            if self.lp.merb_guessed:
                output_content = "Merb not found. Did you mean %s?" % self.lp.merb_guessed.name
            else:
                output_content = "Merb not found"
            return [{
                'destination': self.input_author,
                'content': output_content,
                'decoration': 'BLOCK'
            }]

        if self.lp.merb_found:
            if "off" in self.lp.key_words:
                self.lp.merb_found.switch_target(False)
                output_content = "- %s is no more a target " % self.lp.merb_found.name
            else:
                if "sticky" in self.lp.key_words:
                    self.lp.merb_found.switch_target("auto")
                    output_content = "+ %s is a sticky target! " % self.lp.merb_found.name
                else:
                    self.lp.merb_found.switch_target("manual")
                    output_content = "+ %s is a new target! " % self.lp.merb_found.name

            output_content += "- signed by %s" % self.input_author.name
            self.merbs.save_targets()
        else:
            output_content = errors.error_param(self.lp.cmd,
                                                "Missing Parameter. ")
            output_channel = self.input_author

        output_messages.append({
            'destination': output_channel,
            'content': output_content,
            'decoration': 'CSS'
        })
        output_messages.append({
            'destination':
            self.d_client.get_channel(config.BROADCAST_CHANNEL),
            'content':
            output_content,
            'decoration':
            'MD'
        })

        return output_messages
Example #6
0
    def cmd_set_role(self):
        output_channel = self.input_author
        output_broadcast = False
        output_content = ""

        b_role = d_role = False
        if self.lp.param:

            # Find the discord_role_id
            reg = re.search(r"\b(\d+)\b", self.lp.param)
            if reg:
                d_role = self.authenticator.roles.check_discord_role(
                    reg.group(0))

            # Find the Bot_Roles
            bot_roles_list = self.authenticator.roles.get_bot_roles_list()
            regex = ""
            for role in bot_roles_list:
                regex += "%s|" % role
            regex = r"\b(" + regex[:-1] + r")\b"
            reg = re.search(regex, self.lp.param)
            if reg:
                b_role = reg.group(0)

            if not isinstance(d_role, auth.DiscordRole):
                output_content = "Discord Role ID not found! Type !roles to list them"
            elif not b_role:
                output_content = "Bot Role not found! Type !roles to list them"
            else:
                self.authenticator.roles.assign_discord_role_to_bot_role(
                    str(d_role.id), b_role)
                output_content += "Discord Role [%s] {%s} assigned to Bot Role [%s]\n\n" %\
                                  (d_role.name, d_role.id, b_role)
                output_content += "Commands for this new role:\n%s" %\
                                  self.authenticator.acl.which_permissions_any([b_role], "command")
                self.authenticator.reload_discord_roles()
                self.authenticator.reload_discord_users()

        else:
            output_content = errors.error_param(self.lp.cmd,
                                                "Missing Parameter. ")

        return {
            "destination": output_channel,
            "content": messagecomposer.prettify(output_content, "CSS"),
            'broadcast': output_broadcast
        }
Example #7
0
    def cmd_get(self):
        output_channel = self.input_channel

        # print merbs in target
        if "target" in self.lp.key_words:
            output_content = "NEXT TARGETS\n"
            output_content += "=" * (len(output_content) - 1) + "\n\n"
            output_content += messagecomposer.output_list(
                self.merbs.print_all_targets())
        # print merbs by tag
        elif self.lp.tag:
            output_content = "#%s\n" % self.lp.tag.upper()
            output_content += "=" * len(self.lp.tag) + "\n\n"
            output_content += messagecomposer.output_list(
                self.merbs.print_all_by_tag(self.lp.tag))

        # print only merbs in windows
        elif "window" in self.lp.key_words:
            output_content = "MERBS IN WINDOW\n"
            output_content += "=" * len(output_content) + "\n\n"
            output_content += messagecomposer.output_list(
                self.merbs.print_all_in_window())

        # print a list of all merbs
        elif "all" in self.lp.key_words:
            output_content = messagecomposer.output_list(
                self.merbs.print_all())

        elif "today" in self.lp.key_words:
            output_content = messagecomposer.output_list(
                self.merbs.print_all(limit_hours=24))

        # print single merb
        elif self.lp.merb_found:
            if "info" in self.lp.key_words:
                output_content = self.lp.merb_found.print_long_info(
                    self.lp.timezone, v_single=True)

            else:
                output_content = self.lp.merb_found.print_short_info(
                    self.lp.timezone,
                    v_trackers=True,
                    v_only_active_trackers=True,
                    v_single=True)

        # no parameter recognized but a guessed merb
        elif self.lp.merb_guessed:
            output_content = "Merb not found. Did you mean %s?" % self.lp.merb_guessed.name
            output_channel = self.input_author

        # no parameter recognized
        else:
            output_content = errors.error_param(self.lp.cmd,
                                                "Missing Parameter. ")
            output_channel = self.input_author

        return [{
            'destination': output_channel,
            'content': output_content,
            'decoration': "CSS"
        }]