Add system fronter command
This commit is contained in:
parent
5d15a973f1
commit
fa5a616716
@ -20,7 +20,10 @@ namespace PluralKit.Bot.Commands
|
||||
|
||||
public SystemStore Systems {get; set;}
|
||||
public MemberStore Members {get; set;}
|
||||
|
||||
public SwitchStore Switches {get; set;}
|
||||
public EmbedService EmbedService {get; set;}
|
||||
|
||||
|
||||
[Command]
|
||||
public async Task Query(PKSystem system = null) {
|
||||
@ -145,8 +148,22 @@ namespace PluralKit.Bot.Commands
|
||||
}
|
||||
}
|
||||
|
||||
[Command("fronter")]
|
||||
public async Task SystemFronter()
|
||||
{
|
||||
var system = ContextEntity ?? Context.SenderSystem;
|
||||
if (system == null) throw Errors.NoSystemError;
|
||||
|
||||
var sw = await Switches.GetLatestSwitch(system);
|
||||
if (sw == null) throw Errors.NoRegisteredSwitches;
|
||||
|
||||
var members = await Switches.GetSwitchMembers(sw);
|
||||
await Context.Channel.SendMessageAsync(embed: EmbedService.CreateFronterEmbed(sw, members.ToList()));
|
||||
}
|
||||
|
||||
[Command("timezone")]
|
||||
[Remarks("system timezone [timezone]")]
|
||||
[MustHaveSystem]
|
||||
public async Task SystemTimezone([Remainder] string zoneStr = null)
|
||||
{
|
||||
if (zoneStr == null)
|
||||
|
@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using NodaTime;
|
||||
|
||||
namespace PluralKit.Bot {
|
||||
public class EmbedService {
|
||||
@ -50,8 +52,7 @@ namespace PluralKit.Bot {
|
||||
var name = member.Name;
|
||||
if (system.Name != null) name = $"{member.Name} ({system.Name})";
|
||||
|
||||
var color = Color.Default;
|
||||
if (member.Color != null) color = new Color(uint.Parse(member.Color, NumberStyles.HexNumber));
|
||||
var color = member.Color?.ToDiscordColor() ?? Color.Default;
|
||||
|
||||
var messageCount = await _members.MessageCount(member);
|
||||
|
||||
@ -69,5 +70,15 @@ namespace PluralKit.Bot {
|
||||
|
||||
return eb.Build();
|
||||
}
|
||||
|
||||
public Embed CreateFronterEmbed(PKSwitch sw, ICollection<PKMember> members)
|
||||
{
|
||||
var timeSinceSwitch = SystemClock.Instance.GetCurrentInstant() - sw.Timestamp;
|
||||
return new EmbedBuilder()
|
||||
.WithColor(members.FirstOrDefault()?.Color?.ToDiscordColor() ?? Color.Blue)
|
||||
.AddField("Current fronter", members.Count > 0 ? string.Join(", ", members.Select(m => m.Name)) : "*(no fronter)*", true)
|
||||
.AddField("Since", $"{sw.Timestamp.ToString(Formats.DateTimeFormat, null)} ({timeSinceSwitch.ToString(Formats.DurationFormat, null)} ago)", true)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
@ -20,6 +21,13 @@ namespace PluralKit.Bot
|
||||
return $"{user.Username}#{user.Discriminator} ({user.Mention})";
|
||||
}
|
||||
|
||||
public static Color? ToDiscordColor(this string color)
|
||||
{
|
||||
if (uint.TryParse(color, NumberStyles.HexNumber, null, out var colorInt))
|
||||
return new Color(colorInt);
|
||||
throw new ArgumentException($"Invalid color string '{color}'.");
|
||||
}
|
||||
|
||||
public static async Task VerifyAvatarOrThrow(string url)
|
||||
{
|
||||
// List of MIME types we consider acceptable
|
||||
|
Loading…
Reference in New Issue
Block a user