Пример #1
0
 async def setdefaultcanvas_pxlsspace(self, ctx):
     if not ctx.author.permissions_in(ctx.channel).administrator:
         raise NoPermission
     sql.update_guild(ctx.guild.id, default_canvas="pxlsspace")
     await ctx.send(
         getlang(ctx.guild.id,
                 "configuration.default_canvas_set").format("Pxls.space"))
Пример #2
0
 async def alertchannel_set(self, ctx, channel: TextChannel):
     if not ctx.author.permissions_in(ctx.channel).administrator:
         raise NoPermission
     sql.update_guild(ctx.guild.id, alert_channel=channel.id)
     await ctx.send(
         getlang(ctx.guild.id,
                 "configuration.alert_channel_set").format(channel.mention))
Пример #3
0
 async def setprefix(self, ctx, prefix):
     if not ctx.author.permissions_in(ctx.channel).administrator:
         raise NoPermission
     if len(prefix) > 10:
         raise commands.BadArgument
     sql.update_guild(ctx.guild.id, prefix=prefix)
     await ctx.send(
         getlang(ctx.guild.id, "configuration.prefix_set").format(prefix))
Пример #4
0
 async def autoscan(self, ctx):
     if not ctx.author.permissions_in(ctx.channel).administrator:
         raise NoPermission
     if sql.select_guild_by_id(ctx.guild.id)['autoscan'] == 0:
         sql.update_guild(ctx.guild.id, autoscan=1)
         await ctx.send(
             getlang(ctx.guild.id, "configuration.autoscan_enabled"))
     else:
         sql.update_guild(ctx.guild.id, autoscan=0)
         await ctx.send(
             getlang(ctx.guild.id, "configuration.autoscan_disabled"))
Пример #5
0
async def on_ready():
    log.info("Performing guild check...")
    if sql.get_version() is None:
        sql.init_version(VERSION)
        new_ver_alert = False
    else:
        new_ver_alert = sql.get_version() != VERSION and sql.get_version() is not None
        if new_ver_alert:
            sql.update_version(VERSION)
    for g in bot.guilds:
        log.info("Servicing guild '{0.name}' (ID: {0.id})".format(g))
        row = sql.select_guild_by_id(g.id)
        if row is not None:
            prefix = row['prefix'] if row['prefix'] is not None else cfg.prefix
            if g.name != row['name']:
                await channel_logger.log_to_channel("Guild ID `{0.id}` changed name from **{1}** to **{0.name}** since "
                                                    "last bot start".format(g, row['name']))
                sql.update_guild(g.id, name=g.name)
            alert_channel_id = row['alert_channel'] if row['alert_channel'] is not None else 0
            if new_ver_alert and alert_channel_id is not 0:
                alert_channel = next((x for x in g.channels if x.id == alert_channel_id), None)
                if alert_channel is not None:
                    await alert_channel.send(getlang(g.id, "bot.alert_update").format(VERSION, prefix))
                    log.info("Sent update message to guild {0.name} (ID: {0.id})")
                else:
                    log.info("Could not send update message to guild {0.name} (ID: {0.id}): "
                             "Alert channel could not be found.")
        else:
            await channel_logger.log_to_channel("Joined guild **{0.name}** (ID: `{0.id}`) between sessions at `{1}`"
                                                .format(g, g.me.joined_at.isoformat(' ')))
            sql.add_guild(g.id, g.name, int(g.me.joined_at.timestamp()))
            await print_welcome_message(g)

    db_guilds = sql.get_all_guilds()
    if len(bot.guilds) != len(db_guilds):
        for g in db_guilds:
            if not any(x for x in bot.guilds if x.id == g['id']):
                log.info("Kicked from guild '{0}' (ID: {1}) between sessions".format(g['name'], g['id']))
                await channel_logger.log_to_channel("Kicked from guild **{0}** (ID: `{1}`)".format(g['name'], g['id']))
                sql.delete_guild(g['id'])

    for extension in extensions:
        try:
            bot.load_extension(extension)
        except Exception as e:
            log.error("Failed to load extension {}\n{}: {}".format(extension, type(e).__name__, e))

    print("I am ready!")
    log.info('I am ready!')
    await channel_logger.log_to_channel("I am ready!")
Пример #6
0
 async def registerguild(self, ctx):
     if not ctx.author.permissions_in(ctx.channel).manage_emojis:
         raise NoPermission
     if not sql.is_server_emojishare_server(ctx.guild.id):
         sql.update_guild(ctx.guild.id, emojishare=1)
         self.log.info("Guild {0.name} (ID: {0.id}) has opted in to emoji sharing.".format(ctx.guild))
         await self.channel_logger.log_to_channel("Guild **{0.name}** (ID: `{0.id}`) has opted in to emoji sharing."
                                             .format(ctx.guild))
         message = getlang(ctx.guild.id, "animotes.guild_opt_in")
     else:
         sql.update_guild(ctx.guild.id, emojishare=0)
         self.log.info("Guild {0.name} (ID: {0.id}) has opted out of emoji sharing.".format(ctx.guild))
         await self.channel_logger.log_to_channel("Guild **{0.name}** (ID: `{0.id}`) has opted out of emoji sharing."
                                             .format(ctx.guild))
         message = getlang(ctx.guild.id, "animotes.guild_opt_out")
     await ctx.send(message)
Пример #7
0
 async def alertchannel_clear(self, ctx):
     if not ctx.author.permissions_in(ctx.channel).administrator:
         raise NoPermission
     sql.update_guild(ctx.guild.id, alert_channel=0)
     await ctx.send(
         getlang(ctx.guild.id, "configuration.alert_channel_cleared"))
Пример #8
0
async def on_guild_update(before, after):
    if before.name != after.name:
        log.info("Guild {0.name} is now known as {1.name} (ID: {1.id})")
        await channel_logger.log_to_channel("Guild **{0.name}** is now known as **{1.name}** (ID: `{1.id}`)"
                                            .format(before, after))
        sql.update_guild(after.id, name=after.name)