mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-13 09:10:14 +00:00
Add basic switch model and migrate fronter command
This commit is contained in:
parent
31322f3fea
commit
4a48e43d13
4 changed files with 49 additions and 16 deletions
|
|
@ -109,21 +109,7 @@ async def system_fronter(ctx: CommandContext):
|
|||
else:
|
||||
system = await ctx.ensure_system()
|
||||
|
||||
fronters, timestamp = await pluralkit.utils.get_fronters(ctx.conn, system_id=system.id)
|
||||
fronter_names = [member.name for member in fronters]
|
||||
|
||||
embed = embeds.status("")
|
||||
|
||||
if len(fronter_names) == 0:
|
||||
embed.add_field(name="Current fronter", value="(no fronter)")
|
||||
elif len(fronter_names) == 1:
|
||||
embed.add_field(name="Current fronter", value=fronter_names[0])
|
||||
else:
|
||||
embed.add_field(name="Current fronters", value=", ".join(fronter_names))
|
||||
|
||||
if timestamp:
|
||||
embed.add_field(name="Since", value="{} ({})".format(timestamp.isoformat(sep=" ", timespec="seconds"),
|
||||
humanize.naturaltime(pluralkit.utils.fix_time(timestamp))))
|
||||
embed = await embeds.front_status(await system.get_latest_switch(ctx.conn), ctx.conn)
|
||||
await ctx.reply(embed=embed)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@ from typing import Tuple
|
|||
|
||||
import discord
|
||||
|
||||
import pluralkit
|
||||
from pluralkit import db
|
||||
from pluralkit.bot.utils import escape
|
||||
from pluralkit.member import Member
|
||||
from pluralkit.switch import Switch
|
||||
from pluralkit.system import System
|
||||
from pluralkit.utils import get_fronters
|
||||
|
||||
|
|
@ -149,4 +151,25 @@ async def member_card(conn, member: Member) -> discord.Embed:
|
|||
value=member.description, inline=False)
|
||||
|
||||
card.set_footer(text="System ID: {} | Member ID: {}".format(system.hid, member.hid))
|
||||
return card
|
||||
return card
|
||||
|
||||
|
||||
async def front_status(switch: Switch, conn) -> discord.Embed:
|
||||
if switch:
|
||||
embed = status("")
|
||||
fronter_names = [member.name for member in await switch.fetch_members(conn)]
|
||||
|
||||
if len(fronter_names) == 0:
|
||||
embed.add_field(name="Current fronter", value="(no fronter)")
|
||||
elif len(fronter_names) == 1:
|
||||
embed.add_field(name="Current fronter", value=fronter_names[0])
|
||||
else:
|
||||
embed.add_field(name="Current fronters", value=", ".join(fronter_names))
|
||||
|
||||
if switch.timestamp:
|
||||
embed.add_field(name="Since",
|
||||
value="{} ({})".format(switch.timestamp.isoformat(sep=" ", timespec="seconds"),
|
||||
humanize.naturaltime(pluralkit.utils.fix_time(switch.timestamp))))
|
||||
else:
|
||||
embed = error("No switches logged.")
|
||||
return embed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue