async def channels(self, ctx): # TODO: allow guild admins to use this, restricted to single guild embed = Embed( timestamp=ctx.message.created_at, color=0x50f3d7, title='Bug Reporting Channels') guild_row = Guild.get_or_none(serverid=ctx.guild.id) guild_channels = [] non_guild_channels = dict() for row in BugReportingPlatform.select(): for channel_row in row.bug_channels: channel = self.bot.get_channel(channel_row.channelid) if not channel: channel_row.delete_instance() continue description = f"{row.platform}/{row.branch}: {channel.mention}" if channel_row.guild == guild_row: guild_channels.append(description) else: # TODO: get guild names and add to description if channel_row.guild.serverid not in non_guild_channels: non_guild_channels[channel_row.guild.serverid] = [] non_guild_channels[channel_row.guild.serverid].append(description) if guild_channels: embed.add_field(name=f'`{ctx.guild.name}` server', value="\n".join(guild_channels)) for guild_id, channel_list in non_guild_channels.items(): guild = self.bot.get_guild(guild_id) server_name = self.bot.get_guild(guild_id).name or f"[{guild_id}][MISSING GUILD]" embed.add_field(name=f'`{server_name}` server', value="\n".join(channel_list)) if not guild_channels and not non_guild_channels: await ctx.send("There are no configured bug reporting channels") else: await ctx.send(embed=embed)
def get_defaulted_locale(ctx): locale = 'en_US' if isinstance(ctx, Context): # TODO: move guild/channel checks to LangConfig, store in dict, update there on guild events and config changes cid = ctx.channel.id if ctx.guild is None: # DM - default the language locale = Configuration.get_var('broadcast_locale', 'en_US') if locale == ALL_LOCALES: return locales return [locale] # TODO: create lookup table so we don't hit database every time # github issue #91 gid = ctx.guild.id guild_row = Guild.get_or_none(serverid=gid) chan_locale = Localization.get_or_none(channelid=cid) # Bot default is English if guild_row is not None and guild_row.defaultlocale in locales: # server locale overrides bot default locale = guild_row.defaultlocale if chan_locale is not None and chan_locale.locale in locales: # channel locale overrides server locale = chan_locale.locale elif isinstance(ctx, str): # String assumes caller knows better and is overriding all else if ctx == ALL_LOCALES: return locales if ctx not in locales: if ctx != '': Logging.info( f"Locale string override '{ctx}' not found. Defaulting.") else: locale = ctx else: Logging.info(f"Cannot derive locale from context: {ctx}") locale = False if locale not in locales: Logging.info(f"Missing locale {locale} - defaulting to English") locale = 'en_US' return [locale]
async def lang(self, ctx): """Show language settings for this server""" channels = [] embed = discord.Embed( timestamp=ctx.message.created_at, color=0x663399, title=Lang.get_locale_string('lang/lang_settings_title', ctx, server_name=ctx.guild.name)) guild_row = Guild.get_or_none(serverid=ctx.guild.id) if guild_row: embed.add_field(name="Server default", value=guild_row.defaultlocale or "none") localization_rows = Localization.select().join(Guild).where(Guild.serverid == ctx.guild.id) for row in localization_rows: channels.append(self.bot.get_channel(row.channelid).mention) embed.add_field(name=f"#{self.bot.get_channel(row.channelid).name}", value=row.locale, inline=True) await ctx.send(embed=embed)