async def on_guild_remove(guild): log.info("Kicked from guild '{0.name}' (ID: {0.id})".format(guild)) await ch_log.log( "Kicked from guild **{0.name}** (ID: `{0.id}`)".format(guild)) sql.guild_delete(guild.id)
async def on_ready(): log.info("Starting Starlight Glimmer v{}!".format(VERSION)) if sql.version_get() is None: sql.version_init(VERSION) is_new_version = False else: old_version = sql.version_get() is_new_version = old_version != VERSION and old_version is not None if is_new_version: log.info("Database is a previous version. Updating...") sql.version_update(VERSION) if old_version < 1.6 <= VERSION: # Fix legacy templates not having a size for t in sql.template_get_all(): try: t.size = await render.calculate_size( await http.get_template(t.url)) sql.template_update(t) except errors.TemplateHttpError: log.error( "Error retrieving template {0.name}. Skipping...". format(t)) log.info("Loading extensions...") 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)) log.info("Performing guilds check...") for g in bot.guilds: log.info("'{0.name}' (ID: {0.id})".format(g)) db_g = sql.guild_get_by_id(g.id) if db_g: prefix = db_g.prefix if db_g.prefix else cfg.prefix if g.name != db_g.name: await ch_log.log( "Guild **{1}** is now known as **{0.name}** `(ID:{0.id})`". format(g, db_g.name)) sql.guild_update(g.id, name=g.name) if is_new_version: ch = next( (x for x in g.channels if x.id == db_g.alert_channel), None) if ch: data = await http.get_changelog(VERSION) if data: e = discord.Embed(title=data['name'], url=data['url'], color=13594340, description=data['body']) \ .set_author(name=data['author']['login']) \ .set_thumbnail(url=data['author']['avatar_url']) \ .set_footer(text="Released " + data['published_at']) await ch.send(GlimContext.get_from_guild( g, "bot.update").format(VERSION, prefix), embed=e) else: await ch.send( GlimContext.get_from_guild( g, "bot.update_no_changelog").format( VERSION, prefix)) log.info("- Sent update message") else: log.info( "- Could not send update message: alert channel not found." ) else: j = g.me.joined_at await ch_log.log("Joined guild **{0.name}** (ID: `{0.id}`)".format( g, j.isoformat(' '))) log.info( "Joined guild '{0.name}' (ID: {0.id}) between sessions at {1}". format(g, j.timestamp())) sql.guild_add(g.id, g.name, int(j.timestamp())) await print_welcome_message(g) db_guilds = sql.guild_get_all() 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 ch_log.log( "Kicked from guild **{0}** (ID: `{1}`)".format( g.name, g.id)) sql.guild_delete(g.id) log.info('I am ready!') await ch_log.log("I am ready!") print("I am ready!")
async def on_guild_remove(guild): log.info("Kicked from guild '{0.name}' (ID: {0.id})".format(guild)) if config.CHANNEL_LOG_GUILD_KICKS: await utils.channel_log( bot, "Kicked from guild **{0.name}** (ID: `{0.id}`)".format(guild)) sql.guild_delete(guild.id)