def load_guild(self, guild): guild_row = Guild.get_or_create(serverid=guild.id)[0] for row in guild_row.admin_roles: role = guild.get_role(row.roleid) if role: self.admin_roles[guild.id].add(role.id) else: row.delete_instance() for row in guild_row.mod_roles: role = guild.get_role(row.roleid) if role: self.mod_roles[guild.id].add(role.id) else: row.delete_instance() for row in guild_row.trusted_roles: role = guild.get_role(row.roleid) if role: self.trusted_roles[guild.id].add(role.id) else: row.delete_instance() for row in guild_row.command_permissions: member = guild.get_member(row.userid) if member: self.command_permissions[guild.id][member.id] = row else: row.delete_instance()
def get_guild_db_config(self, guild_id): try: if guild_id in Utils.GUILD_CONFIGS: return Utils.GUILD_CONFIGS[guild_id] row = Guild.get_or_create(serverid=guild_id)[0] Utils.GUILD_CONFIGS[guild_id] = row return row except Exception as e: Utils.get_embed_and_log_exception("--------Failed to get config--------", self, e) return None
async def set_channel_locale(self, ctx, locale: str, channel_id: int = 0): """ Set Locale for a specific channel locale: Locale string, or one of ["*", "x", "none", "unset", "off"] to unset channel_id: ID for channel to set, or do not provide ID and invocation channel will be used. """ # TODO: add ALL_LOCALES as channel option if locale not in Lang.locales and locale not in self.unset_str: await ctx.send(Lang.get_locale_string('lang/unknown_locale', ctx, locale=locale, locale_lsit=Lang.locales)) return # use input channel, or if input is 0, use channel from command context channel_id = ctx.channel.id if channel_id == 0 else channel_id guild_row = Guild.get_or_create(serverid=ctx.guild.id)[0] old_value = None localization_row = Localization.select().join(Guild).where( (Guild.serverid == ctx.guild.id) & (Localization.channelid == channel_id)) if len(localization_row) == 1: localization_row = localization_row[0] old_value = localization_row.locale else: localization_row = None if locale in self.unset_str: if not localization_row: await ctx.send(Lang.get_locale_string('lang/channel_not_unset', ctx, channelid=channel_id)) else: localization_row.delete_instance() await ctx.send(Lang.get_locale_string('lang/channel_unset', ctx, old_value=old_value)) return if not localization_row: localization_row = Localization.create(guild=guild_row, channelid=channel_id) if localization_row.locale == locale: await ctx.send(Lang.get_locale_string('lang/channel_already_set', ctx, channelid=channel_id, locale=locale)) return localization_row.locale = locale localization_row.save() await ctx.send(Lang.get_locale_string('lang/channel_set', ctx, channelid=channel_id, locale=locale))
async def set_server_locale(self, ctx, locale: str): """Set default locale for this server""" if locale not in Lang.locales and locale not in self.unset_str: await ctx.send(Lang.get_locale_string('lang/unknown_locale', ctx, locale=locale, locale_lsit=Lang.locales)) return if locale in self.unset_str: locale = "" guild_row = Guild.get_or_create(serverid=ctx.guild.id)[0] # Don't set/save if input arg is already default if locale == guild_row.defaultlocale: await ctx.send( Lang.get_locale_string('lang/default_not_changed', ctx, locale=locale, server_name=ctx.guild.name)) return guild_row.defaultlocale = locale guild_row.save() await ctx.send(Lang.get_locale_string('lang/default_set', ctx, locale=locale, server_name=ctx.guild.name))
def init_guild(self, guild_id): watch = ReactWatch.get_or_create(serverid=guild_id)[0] self.mutes[guild_id] = Configuration.get_persistent_var(f"react_mutes_{guild_id}", dict()) self.min_react_lifespan[guild_id] = Configuration.get_persistent_var(f"min_react_lifespan_{guild_id}", 0.5) self.mute_duration[guild_id] = watch.muteduration # track react add/remove per guild self.recent_reactions[guild_id] = dict() self.react_removers[guild_id] = dict() self.react_adds[guild_id] = dict() # list of emoji to watch self.emoji[guild_id] = dict() for e in watch.emoji: self.emoji[guild_id][e.emoji] = e # enable listening if set in db if watch.watchremoves: self.activate_react_watch(guild_id) self.guilds[guild_id] = Guild.get_or_create(serverid=guild_id)[0]
def init_guild(self, guild): row = Guild.get_or_create(serverid=guild.id)[0] Utils.GUILD_CONFIGS[guild.id] = row return row