Exemple #1
0
async def get_user_invites(guild_id: int, user_id: int) -> list:
    sql = "SELECT * FROM INVITES WHERE SERVER_ID=(SELECT ID FROM CONFIG WHERE GUILD_ID=%s) AND FROM_USER_ID=%s"
    val = (guild_id, user_id)

    cur_main.execute(sql, val)
    invites = cur_main.fetchall()
    return invites
Exemple #2
0
async def get_welcome_channel(ctx) -> discord.TextChannel:
    try:
        guild = ctx.guild
    except AttributeError:
        guild = ctx

    cur_main.execute("SELECT WELCOME_CHANNEL_ID FROM CONFIG WHERE GUILD_ID=%s",
                     (guild.id, ))
    channel_db = cur_main.fetchall()

    overwrites_main = {
        guild.default_role:
        discord.PermissionOverwrite(read_messages=True,
                                    read_message_history=True,
                                    send_messages=False)
    }

    if channel_db:
        channel = discord.utils.get(guild.channels, id=int(channel_db[0][0]))
        if not channel:
            welcome_channel = await guild.create_text_channel(
                name="willkommen", overwrites=overwrites_main)
            change_msg_welcome_channel(guild.id, welcome_channel.id,
                                       welcome_channel.id)
            return welcome_channel
        else:
            return channel
    else:
        welcome_channel = await guild.create_text_channel(
            name="willkommen", overwrites=overwrites_main)
        change_msg_welcome_channel(guild.id, welcome_channel.id,
                                   welcome_channel.id)
        return welcome_channel
Exemple #3
0
def get_invites_to_user(guild_id: int, invite_to_user_id: int) -> list:
    sql = "SELECT * FROM INVITES WHERE SERVER_ID=(SELECT ID FROM CONFIG WHERE GUILD_ID=%s) AND TO_USER_ID=%s"
    val = (guild_id, invite_to_user_id)

    cur_main.execute(sql, val)
    data = cur_main.fetchall()
    return decode_data(data)
Exemple #4
0
def get_user_trashtalk(guild_id: int, user_id: int) -> list:
    sql = "SELECT * FROM TRASHTALK_LOG WHERE SERVER_ID=(SELECT ID FROM CONFIG WHERE GUILD_ID=%s) AND FROM_USER_ID=%s"
    val = (guild_id, user_id)

    cur_main.execute(sql, val)
    data = cur_main.fetchall()
    return decode_data(data)
Exemple #5
0
def get_trashtalk(guild_id: int) -> list:
    sql = "SELECT MESSAGE FROM TRASHTALK WHERE SERVER_ID=(SELECT ID FROM CONFIG WHERE GUILD_ID=%s)"
    val = (guild_id, )

    cur_main.execute(sql, val)
    data = cur_main.fetchall()

    return [x[0] for x in decode_data(data) if x[0]]
Exemple #6
0
def get_top_user_ranking():
    cur_main.execute(
        "SELECT (SELECT GUILD_ID FROM CONFIG WHERE ID=SERVER_ID), USER_ID, XP FROM LEVEL ORDER BY XP DESC LIMIT 4;"
    )
    data = cur_main.fetchall()
    data = [(count + 1, get_username_by_id(x[1]), get_guild_name_by_id(x[0]),
             xp_lvl(x[2]), x[2]) for count, x in enumerate(data)]

    return data
Exemple #7
0
def get_categories_with_command_count():
    cur_main.execute("SELECT CATEGORY_ID, COMMAND FROM COMMANDS;")
    data = cur_main.fetchall()
    dict_data = {}

    for entry in data:
        cur_main.execute(
            "SELECT CATEGORY FROM COMMAND_CATEGORIES WHERE ID=%s;",
            (entry[0], ))
        category = cur_main.fetchone()

        if category[0] + "_category" not in dict_data:
            dict_data[category[0] + "_category"] = 1
        else:
            dict_data[category[0] +
                      "_category"] = dict_data[category[0] + "_category"] + 1

    cur_main.execute("SELECT COMMAND FROM ADMIN_COMMANDS;")
    dict_data["admin_commands"] = len(cur_main.fetchall())

    return dict_data
Exemple #8
0
def get_all_disabled_commands_from_guild(guild_id: int) -> list:
    cur_main.execute(
        "SELECT COMMAND_ID FROM DISABLED_COMMANDS WHERE SERVER_ID=(SELECT ID FROM CONFIG WHERE GUILD_ID=%s)",
        (guild_id, ))
    command_ids = cur_main.fetchall()
    data = []

    for command_id in command_ids:
        cur_main.execute("SELECT COMMAND FROM COMMANDS WHERE ID=%s",
                         command_id)
        data.append(cur_main.fetchone()[0])

    return data
Exemple #9
0
def get_all_guild_commands_and_category(guild_id: int):
    cur_main.execute(
        "SELECT CATEGORY_ID, COMMAND FROM COMMANDS WHERE ID NOT IN (SELECT COMMAND_ID FROM DISABLED_COMMANDS WHERE SERVER_ID=(SELECT ID FROM CONFIG WHERE GUILD_ID=%s))",
        (guild_id, ))
    commands = {
        command: category
        for (category, command) in cur_main.fetchall()
    }

    for command in commands:
        cur_main.execute("SELECT CATEGORY FROM COMMAND_CATEGORIES WHERE ID=%s",
                         (commands[command], ))
        commands[command] = cur_main.fetchone()[0]

    return commands
Exemple #10
0
def get_server_ranks(guild_id: int) -> list:
    sql = "SELECT * FROM LEVEL WHERE SERVER_ID=(SELECT ID FROM CONFIG WHERE GUILD_ID=%s) ORDER BY XP ASC"
    val = (guild_id,)

    cur_main.execute(sql, val)
    data = cur_main.fetchall()

    new = {}
    done_users = []

    for entry in decode_data(data):
        if entry[1] in done_users:
            continue

        for second in decode_data(data):
            if second[0] == entry[0] and second[1] == entry[1]:
                if second[1] in new:
                    new[second[1]] += second[2]
                else:
                    new[second[1]] = second[2]

        done_users.append(entry[1])

    return [(k, v) for k, v in new.items()]
Exemple #11
0
def get_all_admin_commands():
    cur_main.execute("SELECT COMMAND FROM ADMIN_COMMANDS")
    return [commands[0] for commands in cur_main.fetchall()]
Exemple #12
0
def get_all_twitch_data() -> list:
    cur_main.execute('SELECT GUILD_ID, TWITCH_USERNAME FROM CONFIG')
    data = cur_main.fetchall()
    return [entry for entry in decode_data(data) if entry[1]]
Exemple #13
0
def get_active_guild_ids():
    cur_main.execute("SELECT GUILD_ID FROM CONFIG WHERE ACTIVE=1")

    return cur_main.fetchall()
Exemple #14
0
def get_all_guild_ids():
    cur_main.execute("SELECT GUILD_ID FROM CONFIG")

    return cur_main.fetchall()
Exemple #15
0
def get_all_commands():
    cur_main.execute("SELECT COMMAND FROM COMMANDS;")

    return cur_main.fetchall()
Exemple #16
0
def get_user_messages(user_id: int) -> list:
    cur_main.execute("SELECT * from MESSAGE WHERE USER_ID=%s", (user_id, ))
    data = cur_main.fetchall()
    return decode_data(data)
Exemple #17
0
def get_all_commands_with_id():
    cur_main.execute("SELECT ID, COMMAND FROM COMMANDS;")
    try:
        return tuple([(x[0], x[1].capitalize()) for x in cur_main.fetchall()])
    except IndexError:
        return ()
Exemple #18
0
def get_all_guild_commands_from_category(guild_id: int, category: str):
    cur_main.execute(
        "SELECT COMMAND, PARAMETERS, DESCRIPTION FROM COMMANDS WHERE ID NOT IN (SELECT COMMAND_ID FROM DISABLED_COMMANDS WHERE ID=(SELECT ID FROM CONFIG WHERE GUILD_ID=%s)) AND CATEGORY_ID=(SELECT ID FROM COMMAND_CATEGORIES WHERE CATEGORY=%s)",
        (guild_id, category))
    return cur_main.fetchall()