async def factionlist(self, ctx, page: int = 1): fs = [ x for x in sql.guild_get_all_factions() if x.id not in sql.faction_hides_get_all(ctx.guild.id) ] if len(fs) > 0: pages = 1 + len(fs) // 10 page = min(max(page, 1), pages) g = sql.guild_get_prefix_by_id(ctx.guild.id) msg = [ "**{}** - {} {}/{}".format(ctx.s("faction.list_header"), ctx.s("bot.page"), page, pages), "```xl", "{0:<34} {1:<5}".format(ctx.s("bot.name"), ctx.s("bot.alias")) ] for f in fs[(page - 1) * 10:page * 10]: alias = '"{}"'.format( f.faction_alias) if f.faction_alias else "" msg.append("{0:<34} {1:<5}".format( '"{}"'.format(f.faction_name), alias)) msg.append("") msg.append("// " + ctx.s("faction.faction_list_footer_1").format(g)) msg.append("// " + ctx.s("faction.faction_list_footer_2").format(g)) msg.append("```") await ctx.send('\n'.join(msg)) else: await ctx.send(ctx.s("faction.no_factions"))
async def template_all(self, ctx, page: int = 1): gs = [ x for x in sql.guild_get_all_factions() if x.id not in sql.faction_hides_get_all(ctx.guild.id) ] ts = [x for x in sql.template_get_all() if x.gid in [y.id for y in gs]] def by_faction_name(template): for g in gs: if template.gid == g.id: return g.faction_name ts = sorted(ts, key=by_faction_name) ts_with_f = [] for faction, ts2 in itertools.groupby(ts, key=by_faction_name): for t in ts2: ts_with_f.append((t, faction)) if len(ts) > 0: pages = 1 + len(ts) // 10 page = min(max(page, 1), pages) w1 = max( max(map(lambda tx: len(tx.name), ts)) + 2, len(ctx.s("bot.name"))) msg = [ "**{}** - {} {}/{}".format(ctx.s("template.list_header"), ctx.s("bot.page"), page, pages), "```xl", "{0:<{w1}} {1:<34} {2:<14} {3}".format( ctx.s("bot.name"), ctx.s("bot.faction"), ctx.s("bot.canvas"), ctx.s("bot.coordinates"), w1=w1) ] for t, f in ts_with_f[(page - 1) * 10:page * 10]: coords = "({}, {})".format(t.x, t.y) faction = '"{}"'.format(f) name = '"{}"'.format(t.name) canvas_name = canvases.pretty_print[t.canvas] msg.append("{0:<{w1}} {1:<34} {2:<14} {3}".format( name, faction, canvas_name, coords, w1=w1)) msg.append("") msg.append("// " + ctx.s("template.list_all_footer_1").format(ctx.gprefix)) msg.append("// " + ctx.s("template.list_all_footer_2").format(ctx.gprefix)) msg.append("```") await ctx.send('\n'.join(msg)) else: await ctx.send(ctx.s("template.err.no_public_templates"))
async def hide(self, ctx): # try to find faction by guild id faction = [ x for x in sql.guild_get_all_factions() if x.id == ctx.guild.id ] if len(faction) == 0: await ctx.send(ctx.s("faction.not_a_faction_yet")) return faction = faction[0] # see if faction is currently hidden hidden = sql.faction_hides_get_all(ctx.guild.id) if hidden == []: sql.faction_hides_add(ctx.guild.id, faction.id) await ctx.send( ctx.s("faction.set_hide").format(faction.faction_name)) elif hidden[0] == ctx.guild.id: sql.faction_hides_remove(ctx.guild.id, faction.id) await ctx.send( ctx.s("faction.clear_hide").format(faction.faction_name))
async def unhide(self, ctx, other=None): if other is None: fs = [x for x in sql.guild_get_all_factions() if x.id not in sql.faction_hides_get_all(ctx.guild.id)] if len(fs) == 0: await ctx.send(ctx.s("faction.no_factions_hidden")) return out = [ ctx.s("faction.currently_hidden"), "```xl", "{0:<34} {1:<5}".format(ctx.s("bot.name"), ctx.s("bot.alias")) ] for f in fs: alias = '"{}"'.format(f.faction_alias) if f.faction_alias else "" out.append("{0:<34} {1:<5}".format('"{}"'.format(f.faction_name), alias)) out.append('```') await ctx.send('\n'.join(out)) return other_fac = sql.guild_get_by_faction_name_or_alias(other) if not other_fac: await ctx.send(ctx.s("error.faction_not_found")) return sql.faction_hides_remove(ctx.guild.id, other_fac.id) await ctx.send(ctx.s("faction.clear_hide").format(other_fac.faction_name))