コード例 #1
0
    def orgmember_remove_cmd(self, request, _, char):
        if not char.char_id:
            return StandardMessage.char_not_found(char.name)

        org_member = self.get_org_member(char.char_id)
        if not org_member or org_member.mode == self.MODE_REM_MANUAL:
            return f"<highlight>{char.name}</highlight> is not on the org roster."

        if not request.conn.org_id:
            return "This bot connection does not have an associated org."

        self.process_update(char.char_id,
                            org_member.mode if org_member else None,
                            self.MODE_REM_MANUAL, request.conn)

        # fire org_member logoff event
        self.event_service.fire_event(
            self.ORG_MEMBER_LOGOFF_EVENT,
            DictObject({
                "char_id": org_member.char_id,
                "name": char.name,
                "conn": request.conn
            }))

        return f"<highlight>{char.name}</highlight> has been manually removed from the org roster."
コード例 #2
0
    def discord_link_cmd(self, ctx, reply, args):
        char = args[1]
        if not char.char_id:
            reply(StandardMessage.char_not_found(char.name))
            return

        main = self.alts_service.get_main(char.char_id)
        if main.char_id != char.char_id:
            reply(
                "You cannot link an alt, you must link with a main character.")
            return

        author = ctx.message.author
        discord_user = "******" % (author.name, author.discriminator,
                                       author.id)
        confirm_link = self.text.make_tellcmd("Confirm",
                                              "discord confirm %d" % author.id)

        blob = f"Discord user {discord_user} would like to link to this character.\n\n"
        blob += "This discord user will inherit your access level on the bot so be sure that this is what you want to do.\n\n"
        blob += "If you are currently linked to another Discord user, this will replace that link.\n\n"
        blob += f"To confirm, click here: {confirm_link}"

        self.bot.send_private_message(char.char_id,
                                      ChatBlob("Discord Confirm Link", blob))

        reply(
            f"A confirmation has been sent to {char.name}. You must confirm the link from that character."
        )
コード例 #3
0
ファイル: alts_controller.py プロジェクト: Budabot/Tyrbot
    def altadmin_remove_cmd(self, request, _, main, alt):
        if not main.char_id:
            return StandardMessage.char_not_found(main.name)
        if not alt.char_id:
            return StandardMessage.char_not_found(alt.name)

        msg, result = self.alts_service.remove_alt(main.char_id, alt.char_id)

        if result:
            return f"Character <highlight>{alt.name}</highlight> was added as an alt of <highlight>{main.name}</highlight> successfully."
        elif msg == "not_alt":
            return f"Error! Character <highlight>{alt.name}</highlight> is not an alt of <highlight>{main.name}</highlight>."
        elif msg == "remove_main":
            return "Error! Main characters may not be removed from their alt list."
        else:
            raise Exception("Unknown msg: " + msg)
コード例 #4
0
ファイル: alts_controller.py プロジェクト: Budabot/Tyrbot
    def altadmin_add_cmd(self, request, _, main, alt):
        if not main.char_id:
            return StandardMessage.char_not_found(main.name)
        if not alt.char_id:
            return StandardMessage.char_not_found(alt.name)

        elif main.char_id == alt.char_id:
            return "Error! Alt and main are identical."

        msg, result = self.alts_service.add_alt(main.char_id, alt.char_id)
        if result:
            return f"Character <highlight>{alt.name}</highlight> was added as an alt of <highlight>{main.name}</highlight> successfully."
        elif msg == "another_main":
            return f"Error! Character <highlight>{alt.name}</highlight> already has alts."
        else:
            raise Exception("Unknown msg: " + msg)
コード例 #5
0
ファイル: alts_controller.py プロジェクト: Budabot/Tyrbot
    def alts_add_cmd(self, request, _, alt_chars):
        responses = []
        for alt_char in alt_chars:
            if not alt_char.char_id:
                responses.append(StandardMessage.char_not_found(alt_char.name))
            elif alt_char.char_id == request.sender.char_id:
                responses.append(
                    "Error! You cannot register yourself as an alt.")
            else:
                msg, result = self.alts_service.add_alt(
                    request.sender.char_id, alt_char.char_id)
                if result:
                    self.bot.send_private_message(
                        alt_char.char_id,
                        f"Character <highlight>{request.sender.name}</highlight> has added you as an alt.",
                        conn=request.conn)
                    responses.append(
                        f"Character <highlight>{alt_char.name}</highlight> has been added as your alt."
                    )
                elif msg == "another_main":
                    responses.append(
                        f"Error! Character <highlight>{alt_char.name}</highlight> already has alts."
                    )
                else:
                    raise Exception("Unknown msg: " + msg)

        return "\n".join(responses)
コード例 #6
0
    def orgmember_add_cmd(self, request, _, char):
        if not char.char_id:
            return StandardMessage.char_not_found(char.name)

        org_member = self.get_org_member(char.char_id)
        if org_member and (org_member.mode == self.MODE_ADD_AUTO
                           or org_member.mode == self.MODE_ADD_MANUAL):
            return f"<highlight>{char.name}</highlight> is already on the org roster."

        if not request.conn.org_id:
            return "This bot connection does not have an associated org."

        self.process_update(char.char_id,
                            org_member.mode if org_member else None,
                            self.MODE_ADD_MANUAL, request.conn)

        # fire org_member logon event
        if self.buddy_service.is_online(char.char_id):
            org_member = self.get_org_member(char.char_id)
            self.event_service.fire_event(
                self.ORG_MEMBER_LOGON_EVENT,
                DictObject({
                    "char_id": org_member.char_id,
                    "name": char.name,
                    "conn": request.conn
                }))

        return f"<highlight>{char.name}</highlight> has been manually added to the org roster."
コード例 #7
0
    def buddylist_remove_cmd(self, request, _, char, buddy_type):
        buddy_type = buddy_type.lower()

        if char.char_id:
            self.buddy_service.remove_buddy(char.char_id, buddy_type)
            return f"Character <highlight>{char.name}</highlight> has been removed from the buddy list for type <highlight>{buddy_type}</highlight>."
        else:
            return StandardMessage.char_not_found(char.name)
コード例 #8
0
    def moderator_remove_cmd(self, request, _, char):
        if not char.char_id:
            return StandardMessage.char_not_found(char.name)

        if self.admin_service.remove(char.char_id):
            return f"Character <highlight>{char.name}</highlight> removed as <highlight>{AdminService.MODERATOR}</highlight> successfully."
        else:
            return f"Could not remove character <highlight>{char.name}</highlight> as <highlight>{AdminService.MODERATOR}</highlight>."
コード例 #9
0
    def admin_add_cmd(self, request, _, char):
        if not char.char_id:
            return StandardMessage.char_not_found(char.name)

        if self.admin_service.add(char.char_id, AdminService.ADMIN):
            return f"Character <highlight>{char.name}</highlight> added as <highlight>{AdminService.ADMIN}</highlight> successfully."
        else:
            return f"Could not add character <highlight>{char.name}</highlight> as <highlight>{AdminService.ADMIN}</highlight>."
コード例 #10
0
    def orgactivity_cmd(self, request, char, named_params):
        page_size = 20
        page_number = int(named_params.page or "1")

        params = []
        filter_sql = "WHERE 1=1"
        if char:
            if not char.char_id:
                return StandardMessage.char_not_found(char.name)
            else:
                filter_sql += " AND (o.actor_char_id = ? OR o.actee_char_id = ?)"
                params.append(char.char_id)
                params.append(char.char_id)

        if named_params.action:
            named_params.action = named_params.action.lower()
            filter_sql += " AND o.action LIKE ?"
            params.append(named_params.action)

        offset, limit = self.util.get_offset_limit(page_size, page_number)
        params.append(offset)
        params.append(limit)

        sql = f"""
            SELECT
                p1.name AS actor,
                p2.name AS actee, o.action,
                o.created_at,
                o.org_id
            FROM
                org_activity o
                LEFT JOIN player p1 ON o.actor_char_id = p1.char_id
                LEFT JOIN player p2 ON o.actee_char_id = p2.char_id
            {filter_sql}
            ORDER BY
                o.created_at DESC
            LIMIT ?, ?
        """
        data = self.db.query(sql, params)

        command_str = "orgactivity"
        if char:
            command_str += " " + char.name
        if named_params.action:
            command_str += " --action=" + named_params.action

        blob = self.text.get_paging_links(command_str, page_number, len(data) == page_size) + "\n\n"
        for row in data:
            blob += self.format_org_action(row) + "\n"

        title = "Org Activity"
        if char:
            title += " for " + char.name
        if named_params.action:
            title += " [" + named_params.action + "]"

        return ChatBlob(title, blob)
コード例 #11
0
 def send_tell_cmd(self, request, _, char, message):
     if char.char_id:
         self.bot.send_private_message(char.char_id,
                                       message,
                                       add_color=False,
                                       conn=request.conn)
         return "Your message has been sent."
     else:
         return StandardMessage.char_not_found(char.name)
コード例 #12
0
    def ban_remove_cmd(self, request, _, char):
        if not char.char_id:
            return StandardMessage.char_not_found(char.name)

        if not self.ban_service.get_ban(char.char_id):
            return f"<highlight>{char.name}</highlight> is not banned."

        self.ban_service.remove_ban(char.char_id, request.sender.char_id)
        return f"<highlight>{char.name}</highlight> has been removed from the ban list."
コード例 #13
0
ファイル: member_controller.py プロジェクト: Budabot/Tyrbot
 def member_remove_cmd(self, request, _, char):
     if char.char_id:
         if self.get_member(char.char_id):
             self.remove_member(char.char_id)
             return f"<highlight>{char.name}</highlight> has been removed as a member."
         else:
             return f"<highlight>{char.name}</highlight> is not a member."
     else:
         return StandardMessage.char_not_found(char.name)
コード例 #14
0
ファイル: member_controller.py プロジェクト: Budabot/Tyrbot
 def member_add_cmd(self, request, _, char):
     if char.char_id:
         if self.get_member(char.char_id):
             return f"<highlight>{char.name}</highlight> is already a member."
         else:
             self.add_member(char.char_id)
             return f"<highlight>{char.name}</highlight> has been added as a member."
     else:
         return StandardMessage.char_not_found(char.name)
コード例 #15
0
 def runas_cmd(self, request, char, command_str):
     if not char.char_id:
         return StandardMessage.char_not_found(char.name)
     elif not self.access_service.has_sufficient_access_level(
             request.sender.char_id, char.char_id):
         return f"Error! You must have a higher access level than <highlight>{char.name}</highlight>."
     else:
         command_str = self.command_service.trim_command_symbol(command_str)
         self.command_service.process_command(command_str, request.channel,
                                              char.char_id, request.reply,
                                              request.conn)
コード例 #16
0
    def raid_instance_leader_cmd(self, request, _, char):
        if not char.char_id:
            return StandardMessage.char_not_found(char.name)

        raid_instance = self.get_raid_instance_by_char(char.char_id)
        if not raid_instance:
            return f"Character <highlight>{char.name}</highlight> does not belong to a raid instance."

        self.set_leader(char.char_id, raid_instance.id)

        return f"Character <highlight>{char.name}</highlight> has been set as the leader for raid instance <highlight>{raid_instance.name}</highlight>."
コード例 #17
0
    def broadcast_remove_cmd(self, request, _, char):
        if char.char_id is None:
            return StandardMessage.char_not_found(char.name)

        row = self.db.query_single("SELECT 1 FROM broadcast WHERE char_id = ?",
                                   [char.char_id])

        if not row:
            return f"Error! <highlight>{char.name}</highlight> does not exist on the broadcast list."
        else:
            self.db.exec("DELETE FROM broadcast WHERE char_id = ?",
                         [char.char_id])
            return f"<highlight>{char.name}</highlight> has been removed from the broadcast list."
コード例 #18
0
ファイル: alts_controller.py プロジェクト: Budabot/Tyrbot
    def alts_remove_cmd(self, request, _, alt_char):
        if not alt_char.char_id:
            return StandardMessage.char_not_found(alt_char.name)

        msg, result = self.alts_service.remove_alt(request.sender.char_id,
                                                   alt_char.char_id)
        if result:
            return f"Character <highlight>{alt_char.name}</highlight> has been removed as your alt."
        elif msg == "not_alt":
            return f"Error! Character <highlight>{alt_char.name}</highlight> is not your alt."
        elif msg == "remove_main":
            return "Error! You cannot remove your main."
        else:
            raise Exception("Unknown msg: " + msg)
コード例 #19
0
 def invite_cmd(self, request, char):
     if char.char_id:
         conn = self.get_conn(request.conn)
         if char.char_id in conn.private_channel:
             return f"<highlight>{char.name}</highlight> is already in the private channel."
         else:
             self.bot.send_private_message(
                 char.char_id,
                 f"You have been invited to the private channel by <highlight>{request.sender.name}</highlight>.",
                 conn=conn)
             self.private_channel_service.invite(char.char_id, conn)
             return f"You have invited <highlight>{char.name}</highlight> to the private channel."
     else:
         return StandardMessage.char_not_found(char.name)
コード例 #20
0
    def raid_instance_unassign_cmd(self, request, _, char):
        if not char.char_id:
            return StandardMessage.char_not_found(char.name)

        self.refresh_raid_instance_chars()

        row = self.db.query_single(
            "SELECT r2.name FROM raid_instance_char r1 JOIN raid_instance r2 ON r1.raid_instance_id = r2.id WHERE r1.char_id = ?",
            [char.char_id])
        if row:
            self.update_char_raid_instance(char.char_id,
                                           self.UNASSIGNED_RAID_INSTANCE_ID)
            return f"Character <highlight>{char.name}</highlight> has been removed from raid instance <highlight>{row.name}</highlight>."
        else:
            return f"Character <highlight>{char.name}</highlight> is not assigned to any raid instances."
コード例 #21
0
ファイル: alts_controller.py プロジェクト: Budabot/Tyrbot
    def alts_list_other_cmd(self, request, char, named_params):
        if not char.char_id:
            return StandardMessage.char_not_found(char.name)

        if named_params.sort_by:
            if named_params.sort_by not in self.SORT_OPTIONS:
                return "Sort_by parameter must be one of: " + ", ".join(
                    self.SORT_OPTIONS)
        else:
            named_params.sort_by = "level"

        alts = self.alts_service.get_alts(char.char_id, named_params.sort_by)
        blob = self.format_alt_list(alts)

        return ChatBlob(f"Alts of {alts[0].name} ({len(alts)})", blob)
コード例 #22
0
ファイル: usage_controller.py プロジェクト: Budabot/Tyrbot
    def usage_history_command(self, request, _, named_params):
        page_size = 20
        page_number = int(named_params.page or "1")

        params = []
        sql = "SELECT channel, command, created_at, handler, p.name, c.char_id FROM command_usage c " \
              "LEFT JOIN player p ON c.char_id = p.char_id " \
              "WHERE 1=1"

        if named_params.cmd:
            sql += " AND (command LIKE ? OR handler LIKE ?)"
            params.append(named_params.cmd)
            params.append(named_params.cmd)

        if named_params.char:
            char_id = self.character_service.resolve_char_to_id(named_params.char)
            if not char_id:
                return StandardMessage.char_not_found(named_params.char)

            sql += " AND c.char_id = ?"
            params.append(char_id)

        sql += " ORDER BY created_at DESC LIMIT ?, ?"
        offset, limit = self.util.get_offset_limit(page_size, page_number)
        params.append(offset)
        params.append(limit)
        data = self.db.query(sql, params)

        rows = []
        for row in data:
            rows.append([row.command, row.channel, row.handler, (row.name or "Unknown(%s)" % row.char_id), self.util.format_datetime(row.created_at)])

        display_table = self.text.pad_table(rows, " ", pad_right=False)

        blob = ""
        cmd_string = "usage history"
        if named_params.cmd:
            cmd_string += f" --cmd={named_params.cmd}"
        if named_params.char:
            cmd_string += f" --char={named_params.char}"

        blob += self.text.get_paging_links(cmd_string, page_number, len(data) == page_size) + "\n\n"
        for cols in display_table:
            blob += "  ".join(cols) + "\n"

        title = "Command History"

        return ChatBlob(title, blob)
コード例 #23
0
ファイル: util_controller.py プロジェクト: Budabot/Tyrbot
    def showcommand_cmd(self, request, char, command_str):
        if not char.char_id:
            return StandardMessage.char_not_found(char.name)

        self.bot.send_private_message(
            char.char_id,
            f"<highlight>{request.sender.name}</highlight> is showing you output for command <highlight>{command_str}</highlight>:",
            conn=request.conn)

        self.command_service.process_command(
            self.command_service.trim_command_symbol(command_str),
            request.channel, request.sender.char_id,
            lambda msg: self.bot.send_private_message(
                char.char_id, msg, conn=request.conn), request.conn)

        return f"Command <highlight>{command_str}</highlight> output has been sent to <highlight>{char.name}</highlight>."
コード例 #24
0
 def kick_cmd(self, request, char):
     if char.char_id:
         conn = self.get_conn(request.conn)
         if char.char_id not in conn.private_channel:
             return f"<highlight>{char.name}</highlight> is not in the private channel."
         else:
             # TODO use request.sender.access_level and char.access_level
             if self.access_service.has_sufficient_access_level(
                     request.sender.char_id, char.char_id):
                 self.bot.send_private_message(
                     char.char_id,
                     f"You have been kicked from the private channel by <highlight>{request.sender.name}</highlight>.",
                     conn=conn)
                 self.private_channel_service.kick(char.char_id, conn)
                 return f"You have kicked <highlight>{char.name}</highlight> from the private channel."
             else:
                 return f"You do not have the required access level to kick <highlight>{char.name}</highlight>."
     else:
         return StandardMessage.char_not_found(char.name)
コード例 #25
0
    def raid_instance_assign_cmd(self, request, _, raid_instance_name, char):
        if not char.char_id:
            return StandardMessage.char_not_found(char.name)

        raid_instance = self.get_raid_instance(raid_instance_name)
        if not raid_instance:
            return f"Raid instance <highlight>{raid_instance_name}</highlight> does not exist."

        self.refresh_raid_instance_chars()

        row = self.db.query_single(
            "SELECT raid_instance_id FROM raid_instance_char WHERE char_id = ?",
            [char.char_id])
        if row:
            if raid_instance.id == row.raid_instance_id:
                return f"Character <highlight>{char.name}</highlight> is already assigned to raid instance <highlight>{raid_instance.name}</highlight>."
            else:
                self.update_char_raid_instance(char.char_id, raid_instance.id)
                return f"Character <highlight>{char.name}</highlight> has been assigned to raid instance <highlight>{raid_instance.name}</highlight>."
        else:
            return f"Character <highlight>{char.name}</highlight> is not in the private channel."
コード例 #26
0
    def ban_add_cmd(self, request, _, char, duration, reason):
        if not char.char_id:
            return StandardMessage.char_not_found(char.name)

        if self.ban_service.get_ban(char.char_id):
            return f"<highlight>{char.name}</highlight> is already banned."

        if reason and len(reason) > 255:
            return "Ban reason cannot be more than 255 characters."

        self.ban_service.add_ban(char.char_id, request.sender.char_id,
                                 duration, reason)
        msg = f"<highlight>{char.name}</highlight> has been added to the ban list"
        if duration:
            msg += " for "
            msg += self.util.time_to_readable(duration)
        if reason:
            msg += " with reason: "
            msg += reason
        msg += "."
        return msg
コード例 #27
0
    def broadcast_add_cmd(self, request, _, char, alias):
        if char.char_id is None:
            return StandardMessage.char_not_found(char.name)

        if char.char_id == request.sender.char_id:
            return "You cannot add yourself to the broadcast list."

        if self.access_service.check_access(char.char_id,
                                            AdminService.MODERATOR):
            return "You cannot add a moderator or admin to the broadcast list."

        row = self.db.query_single("SELECT 1 FROM broadcast WHERE char_id = ?",
                                   [char.char_id])

        if row:
            return f"Error! <highlight>{char.name}</highlight> already exists on the broadcast list."
        else:
            self.db.exec(
                "INSERT INTO broadcast (char_id, alias, created_at) VALUES (?, ?, ?)",
                [char.char_id, alias, int(time.time())])
            return f"<highlight>{char.name}</highlight> has been added to the broadcast list."
コード例 #28
0
 def buddylist_remove_force_cmd(self, request, _, char):
     if char.char_id:
         self.buddy_service.remove_buddy(char.char_id, None, force_remove=True)
         return f"Character <highlight>{char.name}</highlight> has been removed from the buddy list forcefully."
     else:
         return StandardMessage.char_not_found(char.name)
コード例 #29
0
ファイル: util_controller.py プロジェクト: Budabot/Tyrbot
    def checkaccess_other_cmd(self, request, char):
        if not char.char_id:
            return StandardMessage.char_not_found(char.name)

        return "Access level for <highlight>%s</highlight> is <highlight>%s</highlight> (%s)." % \
               (char.name, char.access_level["label"], self.access_service.get_single_access_level(char.char_id)["label"])