示例#1
0
 async def handle_unstuck(client, txt_channel, author, msg, message) \
         -> "Unstucks a player":
     args = msg.split()
     if len(args) < 2:
         await txt_channel.send("Usage: !unstuck <character>")
         return False
     player = args[1]
     API.dc_player(player)
     old_map = DatabaseHandler.get_map(player)
     if not old_map:
         await txt_channel.send("User not found")
         return False
     henesys = 100000000
     new_map_response = DatabaseHandler.set_map(player, henesys, old_map)
     await txt_channel.send(new_map_response)
示例#2
0
 async def handle_unban(client, txt_channel, author, msg, message) \
         -> "Unbans a player":
     args = msg.split(" ")
     if len(args) < 2:
         # spirit_logger.warn(f"{author} has made and invalid !unban command attempt: {msg}")
         await txt_channel.send("Usage: !unban <player>")
         return False
     player = args[1]
     m = DatabaseHandler.unban_account(player)
     await txt_channel.send(m)
     return True
示例#3
0
 async def handle_ban(client, txt_channel, author, msg, message) \
         -> "Ban a player":
     args = msg.split()
     if len(args) < 3:
         await txt_channel.send("Usage: !ban <character> <reason>")
         return False
     player = args[1]
     reason_list = args[2:]
     reason = " ".join(reason_list)
     API.dc_player(player)
     s = DatabaseHandler.ban_account(player, reason)
     await txt_channel.send(s)
     return True
示例#4
0
    async def handle_ranking(client, txt_channel, author, msg, message) \
            -> "Shows the rankings":
        args = msg.split(" ")
        if len(args) < 2:
            await txt_channel.send("Usage: !rankings <category>")
            # TODO: Add category list
            return False
        category = args[1]

        # Optional ASCII-check for rank type (comment out if undesired)
        if not utils.is_ascii(category):
            await txt_channel.send(
                "Invalid characters detected in rank category!")
            spirit_logger.warn(
                f"{author} used a command with non-ASCII characters: {msg}")
            return False
        elif category[
                1] == ":" or ":" in category:  # checks for Discord emoji in message
            await txt_channel.send(
                "Are you trying to send a Discord emoji? :liar:")
            spirit_logger.warn(
                f"{author} may have tried to send a Discord emoji: {msg}")
            return False

        table, result = DatabaseHandler.get_rankings(category)
        if "column" in str(
                table
        ):  # checks if the word "column" is in the table this means the column was not found
            await txt_channel.send("Can't find the category")
            return False
        elif not result:
            await txt_channel.send(config.DATABASE_OFFLINE_MESSAGE)
            return False
        e = discord.Embed(title=f"Rankings by {category}",
                          colour=config.EMBED_COLOR)
        e.set_thumbnail(url=config.ICON_URL)
        for x in range(5):
            name = table[x]["name"]
            rank_type = table[x][category]
            job = utils.get_job_by_id(table[x]["job"])

            e.add_field(
                name=f"{utils.get_ordinal_number(x + 1)}.  {name} ({job})",
                value=f"{category}: {rank_type}",
                inline=False)
        await txt_channel.send(embed=e)
        return True
示例#5
0
    async def handle_give_vp(client, txt_channel, author, msg, message) \
            -> "Gives a player votepoints":

        args = msg.split(" ")
        if len(args) < 3:
            # await txt_channel.send("Usage: !givevp <name> <amount>")
            spirit_logger.warn(
                f"{author} has made and invalid !givevp command attempt: {msg}"
            )
            return False
        player = args[1]
        vp = int(args[2])
        r = API.give_vp(player, vp)
        if "Server is" or "found" in r:
            r = DatabaseHandler.give_vp(player, vp)
        await txt_channel.send(r)
        return True
示例#6
0
    async def handle_setgmlevel(client, txt_channel, author, msg, message) \
            -> "Makes a player a gm":

        args = msg.split(" ")
        if len(args) < 3:
            # spirit_logger.warn(f"{author} has made and invalid !getgmlevel command attempt: {msg}")
            await txt_channel.send("Usage: !setgmlevel <player> <level>")
            return False
        player = args[1]
        level = int(args[2])
        r = API.set_gm_level(player, level)
        if "Successfully" in r:
            await txt_channel.send(r)
            return True
        else:
            e = DatabaseHandler.set_gm_level(player, level)
            await txt_channel.send(e)
            return True
示例#7
0
    async def handle_guild(client, txt_channel, author, msg, message) \
            -> "Shows guild info":
        args = msg.split(" ")
        if len(args) <= 1:
            await txt_channel.send("Usage: !guild <name>")
            return False
        guild_name = args[1]

        # Optional ASCII-check for guild name (comment out if undesired)
        # Since GMS should only have ASCII names
        if not utils.is_ascii(guild_name):
            await txt_channel.send("Invalid characters detected in guild name!"
                                   )
            spirit_logger.warn(
                f"{author} used a command with non-ASCII characters: {msg}")
            return False
        elif guild_name[
                1] == ":" or ":" in guild_name:  # checks for Discord emoji in message
            await txt_channel.send(
                "Are you trying to send a Discord emoji? :liar:")
            spirit_logger.warn(
                f"{author} may have tried to send a Discord emoji: {msg}")
            return False

        rows, result = DatabaseHandler.get_guild_info(guild_name)
        if not result:  # If the result is false the database is offline
            await txt_channel.send(config.DATABASE_OFFLINE_MESSAGE)
            return False
        elif len(rows) == 0:
            await txt_channel.send("Guild not found")
            return False

        # rows[0] because no two guilds will have the same name
        guild_info = rows[0]

        guild = guild_info["name"]
        guild_leader = guild_info["leader"]
        logo = guild_info["logo"]
        logo_color = guild_info["logoColor"]
        logo_bg = guild_info["logoBG"]
        logo_bg_color = guild_info["logoBGColor"]
        notice = guild_info["notice"]
        gp = guild_info["GP"]
        alliance_id = guild_info["allianceId"]

        guild_img = utils.get_guild_logo(
            guild_mark_id=logo,
            guild_mark_color_id=logo_color,
            guild_background_id=logo_bg,
            guild_background_color_id=logo_bg_color)
        e = discord.Embed(title="Guild info", colour=config.EMBED_COLOR)
        e.set_footer(text=config.SERVER_NAME, icon_url=config.ICON_URL)
        e.set_thumbnail(url=guild_img)
        e.add_field(name="Name", value=guild, inline=True)
        e.add_field(name="Leader",
                    value=DatabaseHandler.get_character_name(guild_leader),
                    inline=True)
        e.add_field(name="Alliance",
                    value=DatabaseHandler.get_alliance_name(alliance_id),
                    inline=True)
        e.add_field(name="Notice", value=notice, inline=True)
        await txt_channel.send(embed=e)
        return True
示例#8
0
    async def handle_character(client, txt_channel, author, msg, message) \
            -> "Shows character info":
        args = msg.split(" ")
        if len(args) <= 1:
            await txt_channel.send("Usage: !character <name>")
            return False
        character_name = args[1]

        # Optional ASCII-check for char name (comment out if undesired)
        # Since GMS should only have ASCII names
        if not utils.is_ascii(character_name):
            await txt_channel.send(
                "Invalid characters detected in character name!")
            spirit_logger.warn(
                f"{author} used a command with non-ASCII characters: {msg}")
            return False
        elif character_name[
                1] == ":" or ":" in character_name:  # checks for Discord emoji in message
            await txt_channel.send(
                "Are you trying to send a Discord emoji? :liar:")
            spirit_logger.warn(
                f"{author} may have tried to send a Discord emoji: {msg}")
            return False

        rows, result = DatabaseHandler.get_character_stats(character_name)
        # A tuple is returned, result being false means the database is off and vice versa

        if not result:
            await txt_channel.send(config.DATABASE_OFFLINE_MESSAGE)
            return False
        elif len(rows) == 0:
            await txt_channel.send("Character not found")
            return False

        # It is always 0, cause no two characters should have the same name.
        char = rows[0]

        id = char["id"]
        name = char["name"]
        level = char["level"]
        job = char["job"]
        meso = char["meso"]
        rank = char["rank"]
        face = char["face"]
        hair = char["hair"]
        skin = char[
            "skincolor"]  # Other Databases may have this column named "skin", rename accordingly
        guildid = char["guildid"]
        fame = char["fame"]
        # rebirths = char["reborns"]  # Other Databases may have this column named "rebirths", rename accordingly

        character_img = DatabaseHandler.get_character_look(
            id, hair, face, skin)  # sends the hair, face and skin id's
        # character_img is a link from maplestory.io API that lets us draw any character given the correct params

        guild_name = DatabaseHandler.get_guild_name(guildid)
        e = discord.Embed(title="Character stats", colour=config.EMBED_COLOR)
        e.set_thumbnail(url=character_img)
        e.set_footer(text=config.SERVER_NAME, icon_url=config.ICON_URL)
        e.add_field(name="Name", value=name, inline=True)
        e.add_field(name="Level", value=level, inline=True)
        e.add_field(name="Job", value=utils.get_job_by_id(job), inline=True)
        e.add_field(name="Guild", value=guild_name, inline=True)
        e.add_field(name="Rank", value=rank, inline=True)
        e.add_field(name="Meso", value=meso, inline=True)
        e.add_field(name="Fame", value=fame, inline=True)
        # e.add_field(name="Rebirths", value=rebirths, inline=True)

        await txt_channel.send(embed=e)
        return True