bot: add member creation command

This commit is contained in:
Ske 2019-04-27 16:30:34 +02:00
parent 876dcc0145
commit 8359df09e9
6 changed files with 95 additions and 35 deletions

View file

@ -11,17 +11,16 @@ namespace PluralKit.Bot.Commands
public class SystemCommands : ContextParameterModuleBase<PKSystem>
{
public override string Prefix => "system";
public override string ContextNoun => "system";
public SystemStore Systems {get; set;}
public MemberStore Members {get; set;}
public EmbedService EmbedService {get; set;}
private PKError NO_SYSTEM_ERROR => new PKError($"You do not have a system registered with PluralKit. To create one, type `pk;system new`. If you already have a system registered on another account, type `pk;link {Context.User.Mention}` from that account to link it here.");
private PKError OTHER_SYSTEM_CONTEXT_ERROR => new PKError("You can only run this command on your own system.");
[Command]
public async Task Query(PKSystem system = null) {
if (system == null) system = Context.SenderSystem;
if (system == null) throw NO_SYSTEM_ERROR;
if (system == null) Context.RaiseNoSystemError();
await Context.Channel.SendMessageAsync(embed: await EmbedService.CreateSystemEmbed(system));
}
@ -29,19 +28,19 @@ namespace PluralKit.Bot.Commands
[Command("new")]
public async Task New([Remainder] string systemName = null)
{
if (ContextEntity != null) throw OTHER_SYSTEM_CONTEXT_ERROR;
if (ContextEntity != null) RaiseNoContextError();
if (Context.SenderSystem != null) throw new PKError("You already have a system registered with PluralKit. To view it, type `pk;system`. If you'd like to delete your system and start anew, type `pk;system delete`, or if you'd like to unlink this account from it, type `pk;unlink`.");
var system = await Systems.Create(systemName);
await Systems.Link(system, Context.User.Id);
await ReplyAsync("Your system has been created. Type `pk;system` to view it, and type `pk;help` for more information about commands you can use now.");
await Context.Channel.SendMessageAsync($"{Emojis.Success} Your system has been created. Type `pk;system` to view it, and type `pk;help` for more information about commands you can use now.");
}
[Command("name")]
public async Task Name([Remainder] string newSystemName = null) {
if (ContextEntity != null) throw OTHER_SYSTEM_CONTEXT_ERROR;
if (Context.SenderSystem == null) throw NO_SYSTEM_ERROR;
if (ContextEntity != null) RaiseNoContextError();
if (Context.SenderSystem == null) Context.RaiseNoSystemError();
if (newSystemName != null && newSystemName.Length > 250) throw new PKError($"Your chosen system name is too long. ({newSystemName.Length} > 250 characters)");
Context.SenderSystem.Name = newSystemName;
@ -51,8 +50,8 @@ namespace PluralKit.Bot.Commands
[Command("description")]
public async Task Description([Remainder] string newDescription = null) {
if (ContextEntity != null) throw OTHER_SYSTEM_CONTEXT_ERROR;
if (Context.SenderSystem == null) throw NO_SYSTEM_ERROR;
if (ContextEntity != null) RaiseNoContextError();
if (Context.SenderSystem == null) Context.RaiseNoSystemError();
if (newDescription != null && newDescription.Length > 1000) throw new PKError($"Your chosen description is too long. ({newDescription.Length} > 250 characters)");
Context.SenderSystem.Description = newDescription;
@ -62,8 +61,8 @@ namespace PluralKit.Bot.Commands
[Command("tag")]
public async Task Tag([Remainder] string newTag = null) {
if (ContextEntity != null) throw OTHER_SYSTEM_CONTEXT_ERROR;
if (Context.SenderSystem == null) throw NO_SYSTEM_ERROR;
if (ContextEntity != null) RaiseNoContextError();
if (Context.SenderSystem == null) Context.RaiseNoSystemError();
if (newTag.Length > 30) throw new PKError($"Your chosen description is too long. ({newTag.Length} > 30 characters)");
Context.SenderSystem.Tag = newTag;
@ -72,7 +71,7 @@ namespace PluralKit.Bot.Commands
var unproxyableMembers = await Members.GetUnproxyableMembers(Context.SenderSystem);
if (unproxyableMembers.Count > 0) {
var msg = await Context.Channel.SendMessageAsync($"{Emojis.Warn} Changing your system tag to '{newTag}' will result in the following members being unproxyable, since the tag would bring their name over 32 characters:\n**{string.Join(", ", unproxyableMembers.Select((m) => m.Name))}**\nDo you want to continue anyway?");
if (!await Context.PromptYesNo(msg, TimeSpan.FromMinutes(5))) throw new PKError("Tag change cancelled.");
if (!await Context.PromptYesNo(msg)) throw new PKError("Tag change cancelled.");
}
await Systems.Save(Context.SenderSystem);
@ -81,8 +80,8 @@ namespace PluralKit.Bot.Commands
[Command("delete")]
public async Task Delete() {
if (ContextEntity != null) throw OTHER_SYSTEM_CONTEXT_ERROR;
if (Context.SenderSystem == null) throw NO_SYSTEM_ERROR;
if (ContextEntity != null) RaiseNoContextError();
if (Context.SenderSystem == null) Context.RaiseNoSystemError();
var msg = await Context.Channel.SendMessageAsync($"{Emojis.Warn} Are you sure you want to delete your system? If so, reply to this message with your system's ID (`{Context.SenderSystem.Hid}`).\n**Note: this action is permanent.**");
var reply = await Context.AwaitMessage(Context.Channel, Context.User, timeout: TimeSpan.FromMinutes(1));