Exemple #1
0
async def ex(args, message, client, invoke):
    if len(args) > 0:
        out = " ".join(args)
        await message.channel.send(
            embed=discord.Embed(color=discord.Color.green(), description=out))
        out = out.replace("\n", " / ")
        if out.startswith("`") and out.endswith("`"):
            if out.startswith("```") and out.endswith("```"):
                out = out[3:-3]
                await Logger.info("Successfully said: '%s'" %
                                  paint.color(out, "code"))
            else:
                out = out[1:-1]
                await Logger.info("Successfully said: '%s'" %
                                  paint.color(out, "code"))
        else:
            await Logger.info("Successfully said: '%s'" % out)
    else:
        await Logger.error("Doesn't accept empty messages.")
Exemple #2
0
async def on_member_join(member):
    role_ids = db.fetch_autoroles(member.guild.id)
    not_found = False
    msg = "==> %s%s (%s) joined %s." % (
        paint.color("BOT ", "green") if member.bot else "",
        paint.color(member.name, "white"), member.id,
        paint.color(member.guild.name, "blue"))
    if len(role_ids) > 0:
        if not member.bot:
            auto_roles = []
            for r in role_ids:
                result = member.guild.get_role(r)
                if result is not None:
                    auto_roles.append(result)
            if len(auto_roles) > 0:
                try:
                    for r in auto_roles:
                        await member.add_roles(r)
                except discord.Forbidden:
                    await Logger.error(
                        "No Permission to add autoroles on `%s`. Please make sure the bot's role is placed above the roles you want to add in the Discord guild settings."
                        % member.guild.name,
                        chan=member.guild.owner,
                        delete=False)
                else:
                    role_names = []
                    for r in auto_roles:
                        role_names.append(r.name)
                    msg += " Automatically assigned the role(s): %s" % ", ".join(
                        role_names)
            else:
                not_found = True
        else:
            await Logger.warn(
                "A new bot (%s) joined your guild. Autorole does not automatically assign roles to bots since they can have their own roles."
                % member.name,
                chan=member.guild.owner,
                delete=False)
    await Logger.info(msg)
    if not_found:
        await Logger.warn(
            "Could not find any of the entered Role IDs for Autorole.")
Exemple #3
0
async def on_message(message):
    if message.guild is not None and not message.author.bot:  # if guild is None it's a DM, don't react to bot messages
        if message.content.startswith(db.fetch_prefix(message.guild.id)):
            invoke = message.content[len(db.fetch_prefix(message.guild.id)
                                         ):].split(" ")[0]
            args = message.content.split(" ")[1:]
            if invoke in commands:
                if invoke != "clear":
                    await message.delete()
                await Logger.info(
                    "%s: %s is executing command %s" %
                    (paint.color(message.guild.name, "yellow"),
                     paint.color(
                         message.author.name + " (%s)" % message.author.id,
                         "white"), paint.color(invoke, "blue")))
                await commands.get(invoke).ex(args, message, client, invoke)
                config.update()
            else:
                await message.delete()
                await Logger.error("Command not found: %s" % invoke,
                                   chan=message.channel)
Exemple #4
0
# Load config and data

if len(sys.argv) > 1 and sys.argv[1] == "dev":
    dev = True
else:
    dev = False


# Load config
def load():
    with open("CONFIG.json" if not dev else "devCONFIG.json",
              "r",
              encoding="utf-8") as f:
        config = json.load(f)
    return config


# Update config
def update():
    with open("CONFIG.json" if not dev else "devCONFIG.json",
              "w",
              encoding="utf-8") as f:
        json.dump(CONFIG, f, ensure_ascii=False, indent=4)


CONFIG = load()

print("Successfully loaded %s%s!" % (paint.color("dev", "blue") if dev else "",
                                     paint.color("CONFIG.json", "blue")))
Exemple #5
0
sql_create_guilds_table = """CREATE TABLE IF NOT EXISTS guilds (
                                sid int PRIMARY KEY,
                                name text NOT NULL,
                                owner_id int NOT NULL,
                                prefix text NOT NULL
); """

sql_create_colors_table = """CREATE TABLE IF NOT EXISTS colors (
                                uid text PRIMARY KEY,
                                sid int NOT NULL,
                                name text NOT NULL,
                                role_id int NOT NULL
);"""

sql_create_autoroles_table = """CREATE TABLE IF NOT EXISTS autoroles (
                                uid text PRIMARY KEY,
                                sid int NOT NULL,
                                role_id int NOT NULL
);"""

conn = create_connection(database)
if conn is not None:
    create_table(conn, sql_create_guilds_table)
    create_table(conn, sql_create_colors_table)
    create_table(conn, sql_create_autoroles_table)
else:
    print(paint.color("Cannot create database connection!", "red"))
    exit()

conn.close()
Exemple #6
0
async def on_guild_remove(guild):
    db.delete_guild(guild.id)
    await Logger.info("%s left a guild: %s" %
                      (client.user.name,
                       paint.color(guild.name + " (%s)" % guild.id, "white")))
Exemple #7
0
async def on_guild_join(guild):
    db.create_guild(guild.id, guild.name, guild.owner.id)
    await Logger.info("%s joined a new guild: %s" %
                      (client.user.name,
                       paint.color(guild.name + " (%s)" % guild.id, "white")))
Exemple #8
0
async def on_guild_join(guild):
    db.create_guild(guild.id, guild.name, guild.owner.id)
    await Logger.info("%s joined a new guild: %s" %
                      (client.user.name,
                       paint.color(guild.name + " (%s)" % guild.id, "white")))


@client.event
async def on_guild_remove(guild):
    db.delete_guild(guild.id)
    await Logger.info("%s left a guild: %s" %
                      (client.user.name,
                       paint.color(guild.name + " (%s)" % guild.id, "white")))


try:
    client.loop.run_until_complete(client.start(config.CONFIG["TOKEN"]))
except ConnectionResetError:
    Logger.warn("Connection reset by peer... Everything should still be fine")
except discord.LoginFailure:
    print(
        "It seems like no %s was given or it was incorrect. Please check the %s!"
        % (paint.color("Discord Bot Token",
                       "red"), paint.color("CONFIG.json", "blue")))
    client.loop.run_until_complete(client.logout())
except KeyboardInterrupt:
    client.loop.run_until_complete(client.logout())
finally:
    client.loop.close()
    print("\nShutting down...")