def get_botadmin_role(ctx): role_id = sql.guild_get_by_id(ctx.guild.id).bot_admin r = dget(ctx.guild.roles, id=role_id) if role_id and not r: sql.guild_update(ctx.guild.id, bot_admin=None) return None return r
def get_templateadder_role(ctx): role_id = sql.guild_get_by_id(ctx.guild.id).template_adder r = dget(ctx.guild.roles, id=role_id) if role_id and not r: sql.guild_update(ctx.guild.id, template_adder=None) return None return r
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 ch_log.log( "Guild **{0.name}** is now known as **{1.name}** (ID: `{1.id}`)". format(before, after)) sql.guild_update(after.id, name=after.name)
async def prefix(self, ctx, prefix): if len(prefix) > 5: raise commands.BadArgument sql.guild_update(ctx.guild.id, prefix=prefix) log.info("Prefix for {0.name} set to {1} (GID: {0.id})".format( ctx.guild, prefix)) await ctx.send(ctx.s("configuration.prefix_set").format(prefix))
async def alertchannel_set(self, ctx, channel: TextChannel): sql.guild_update(ctx.guild.id, alert_channel=channel.id) log.info( "Alert channel for {0.name} set to {1.name} (GID:{0.id} CID:{1.name})" .format(ctx.guild, channel)) await ctx.send( ctx.s("configuration.alert_channel_set").format(channel.mention))
async def canvas_pixelzone(self, ctx): sql.guild_update(ctx.guild.id, canvas="pixelzone") log.info( "Default canvas for {0.name} set to pixelzone (GID:{0.id})".format( ctx.guild)) await ctx.send( ctx.s("configuration.canvas_set").format("Pixelzone.io"))
async def role_templateadmin_set(self, ctx, role=None): m = re.match('<@&(\d+)>', role) r = dget(ctx.guild.roles, id=int(m.group(1))) if m else dget(ctx.guild.roles, name=role) if r: sql.guild_update(ctx.guild.id, template_admin=r.id) await ctx.send(ctx.s("configuration.role_template_admin_set").format(r.name)) else: await ctx.send(ctx.s("configuration.role_not_found"))
async def autoscan(self, ctx): if sql.guild_is_autoscan(ctx.guild.id): sql.guild_update(ctx.guild.id, autoscan=1) self.log.info("Autoscan enabled for {0.name} (GID: {0.id})".format(ctx.guild)) await ctx.send(ctx.s("configuration.autoscan_enabled")) else: sql.guild_update(ctx.guild.id, autoscan=0) self.log.info("Autoscan disabled for {0.name} (GID: {0.id})".format(ctx.guild)) await ctx.send(ctx.s("configuration.autoscan_disabled"))
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})") if config.CHANNEL_LOG_GUILD_RENAMES: await utils.channel_log( bot, "Guild **{0.name}** is now known as **{1.name}** (ID: `{1.id}`)" .format(before, after)) sql.guild_update(after.id, name=after.name)
async def autoscan(self, ctx): # Guild does not have autoscan enabled, enable it if sql.guild_is_autoscan(ctx.guild.id) == False: sql.guild_update(ctx.guild.id, autoscan=1) log.info("Autoscan enabled for {0.name} (GID: {0.id})".format( ctx.guild)) await ctx.send(ctx.s("configuration.autoscan_enabled")) # Guild has autoscan enabled, disable it else: # for autoscan 2==False, cause 0 was converting to null and f*****g up sql.guild_update(ctx.guild.id, autoscan=2) log.info("Autoscan disabled for {0.name} (GID: {0.id})".format( ctx.guild)) await ctx.send(ctx.s("configuration.autoscan_disabled"))
async def language(self, ctx, option=None): if not option: out = [ ctx.s("configuration.language_check_1").format(ctx.langs[ctx.lang]), ctx.s("configuration.language_check_2"), "```" ] for code, name in ctx.langs.items(): out.append("{0} - {1}".format(code, name)) out.append("```") await ctx.send('\n'.join(out)) return if option.lower() not in ctx.langs: return sql.guild_update(ctx.guild.id, language=option.lower()) self.log.info("Language for {0.name} set to {1} (GID:{0.id})".format(ctx.guild, option.lower())) await ctx.send(ctx.s("configuration.language_set").format(ctx.langs[option.lower()]))
async def canvas_pxlsspace(self, ctx): sql.guild_update(ctx.guild.id, canvas="pxlsspace") self.log.info("Default canvas for {0.name} set to pxlsspace (GID:{0.id})".format(ctx.guild)) await ctx.send(ctx.s("configuration.canvas_set").format("Pxls.space"))
async def alertchannel_clear(self, ctx): sql.guild_update(ctx.guild.id, alert_channel=0) self.log.info("Alert channel for {0.name} cleared (GID:{0.id})".format(ctx.guild)) await ctx.send(ctx.s("configuration.alert_channel_cleared"))
async def role_templateadmin_clear(self, ctx): sql.guild_update(ctx.guild.id, template_admin=None) await ctx.send(ctx.s("configuration.role_template_admin_cleared"))
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!")