Added an alias that can be used with the discord command instead of the profile id.

This commit is contained in:
Brett Hewitson 2021-12-16 15:42:42 +10:00
parent 440085f5d3
commit 327103182c
15 changed files with 507 additions and 283 deletions

View file

@ -4,5 +4,5 @@ using System.Threading;
namespace ServerManagerTool.DiscordBot.Delegates
{
public delegate IList<string> HandleCommandDelegate(CommandType commandType, string serverId, string channelId, string profileId, CancellationToken token);
public delegate IList<string> HandleCommandDelegate(CommandType commandType, string serverId, string channelId, string profileIdOrAlias, CancellationToken token);
}

View file

@ -29,16 +29,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("backup", RunMode = RunMode.Async)]
[Summary("Backup the server")]
[Remarks("backup profileId")]
[Remarks("backup profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
public async Task BackupServerAsync(string profileId)
public async Task BackupServerAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
var response = _handleCommandCallback?.Invoke(CommandType.Backup, serverId, channelId, profileId, _serverManagerBot.Token);
var response = _handleCommandCallback?.Invoke(CommandType.Backup, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
@ -60,16 +60,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("restart", RunMode = RunMode.Async)]
[Summary("Restart the server")]
[Remarks("restart profileId")]
[Remarks("restart profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
public async Task RestartServerAsync(string profileId)
public async Task RestartServerAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
var response = _handleCommandCallback?.Invoke(CommandType.Restart, serverId, channelId, profileId, _serverManagerBot.Token);
var response = _handleCommandCallback?.Invoke(CommandType.Restart, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
@ -91,16 +91,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("shutdown", RunMode = RunMode.Async)]
[Summary("Shuts down the server properly")]
[Remarks("shutdown profileId")]
[Remarks("shutdown profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
public async Task ShutdownServerAsync(string profileId)
public async Task ShutdownServerAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
var response = _handleCommandCallback?.Invoke(CommandType.Shutdown, serverId, channelId, profileId, _serverManagerBot.Token);
var response = _handleCommandCallback?.Invoke(CommandType.Shutdown, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
@ -122,16 +122,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("start", RunMode = RunMode.Async)]
[Summary("Starts the server")]
[Remarks("start profileId")]
[Remarks("start profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
public async Task StartServerAsync(string profileId)
public async Task StartServerAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
var response = _handleCommandCallback?.Invoke(CommandType.Start, serverId, channelId, profileId, _serverManagerBot.Token);
var response = _handleCommandCallback?.Invoke(CommandType.Start, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
@ -153,16 +153,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("stop", RunMode = RunMode.Async)]
[Summary("Forcibly stops the server")]
[Remarks("stop profileId")]
[Remarks("stop profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
public async Task StopServerAsync(string profileId)
public async Task StopServerAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
var response = _handleCommandCallback?.Invoke(CommandType.Stop, serverId, channelId, profileId, _serverManagerBot.Token);
var response = _handleCommandCallback?.Invoke(CommandType.Stop, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
@ -184,16 +184,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("update", RunMode = RunMode.Async)]
[Summary("Updates the server")]
[Remarks("update profileId")]
[Remarks("update profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
public async Task UpdateServerAsync(string profileId)
public async Task UpdateServerAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
var response = _handleCommandCallback?.Invoke(CommandType.Update, serverId, channelId, profileId, _serverManagerBot.Token);
var response = _handleCommandCallback?.Invoke(CommandType.Update, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");

View file

@ -38,16 +38,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("info", RunMode = RunMode.Async)]
[Summary("Poll server for information")]
[Remarks("info profileId")]
[Remarks("info profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
public async Task ServerInfoAsync(string profileId)
public async Task ServerInfoAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
var response = _handleCommandCallback?.Invoke(CommandType.Info, serverId, channelId, profileId, _serverManagerBot.Token);
var response = _handleCommandCallback?.Invoke(CommandType.Info, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
@ -109,16 +109,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("status", RunMode = RunMode.Async)]
[Summary("Poll server for status")]
[Remarks("status profileId")]
[Remarks("status profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
public async Task ServerStatusAsync(string profileId)
public async Task ServerStatusAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
var response = _handleCommandCallback?.Invoke(CommandType.Status, serverId, channelId, profileId, _serverManagerBot.Token);
var response = _handleCommandCallback?.Invoke(CommandType.Status, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");