-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Discord; | ||
using Discord.WebSocket; | ||
using DiscordLab.Bot.API.Interfaces; | ||
using DiscordLab.Bot.API.Modules; | ||
|
||
namespace DiscordLab.Bot.Commands | ||
{ | ||
public class Discord : ISlashCommand | ||
{ | ||
public SlashCommandBuilder Data { get; } = new() | ||
{ | ||
Name = "discordlab", | ||
Description = "DiscordLab related commands", | ||
DefaultMemberPermissions = GuildPermission.Administrator, | ||
Options = new() | ||
{ | ||
new() | ||
{ | ||
Type = ApplicationCommandOptionType.SubCommand, | ||
Name = "list", | ||
Description = "List all available DiscordLab modules", | ||
}, | ||
new() | ||
{ | ||
Type = ApplicationCommandOptionType.SubCommand, | ||
Name = "install", | ||
Description = "Install a DiscordLab module", | ||
Options = new () | ||
{ | ||
new () | ||
{ | ||
Type = ApplicationCommandOptionType.String, | ||
Name = "module", | ||
Description = "The module to install", | ||
IsRequired = true, | ||
IsAutocomplete = true | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
public ulong GuildId { get; set; } = Plugin.Instance.Config.GuildId; | ||
|
||
public async Task Run(SocketSlashCommand command) | ||
{ | ||
string subcommand = command.Data.Options.First().Name; | ||
if (subcommand == "list") | ||
{ | ||
string modules = string.Join("\n", UpdateStatus.Statuses.Where(s => s.ModuleName != "DiscordLab.Bot").Select(s => s.ModuleName)); | ||
await command.RespondAsync("List of available DiscordLab modules:\n\n" + modules, ephemeral:true); | ||
} | ||
else if (subcommand == "install") | ||
{ | ||
string module = command.Data.Options.First().Options.First().Value.ToString(); | ||
if(string.IsNullOrWhiteSpace(module)) | ||
{ | ||
await command.RespondAsync("Please provide a module name.", ephemeral: true); | ||
return; | ||
} | ||
API.Features.UpdateStatus status = UpdateStatus.Statuses.FirstOrDefault(s => s.ModuleName == module); | ||
if (status == null) | ||
{ | ||
await command.RespondAsync("Module not found.", ephemeral: true); | ||
return; | ||
} | ||
|
||
await UpdateStatus.DownloadPlugin(status); | ||
ServerStatic.StopNextRound = ServerStatic.NextRoundAction.Restart; | ||
await command.RespondAsync("Downloaded module. Server will restart next round.", ephemeral:true); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using CommandSystem; | ||
using DiscordLab.Bot.API.Modules; | ||
using PluginAPI.Core; | ||
|
||
namespace DiscordLab.Bot.Commands | ||
{ | ||
[CommandHandler(typeof(GameConsoleCommandHandler))] | ||
public class LocalAdmin : ICommand | ||
{ | ||
public string Command { get; } = "discordlab"; | ||
|
||
public string[] Aliases { get; } = new [] { "dl", "lab" }; | ||
|
||
public string Description { get; } = "Do things directly with DiscordLab."; | ||
|
||
public bool Execute( | ||
ArraySegment<string> arguments, | ||
ICommandSender sender, | ||
out string response | ||
) | ||
{ | ||
switch (arguments.FirstOrDefault()) | ||
{ | ||
case "list": | ||
string modules = string.Join("\n", UpdateStatus.Statuses.Where(s => s.ModuleName != "DiscordLab.Bot").Select(s => s.ModuleName)); | ||
response = | ||
$"Available modules:\n{modules}"; | ||
return true; | ||
case "install": | ||
string module = arguments.ElementAtOrDefault(1); | ||
if(string.IsNullOrWhiteSpace(module)) | ||
{ | ||
response = "Please provide a module name."; | ||
return false; | ||
} | ||
API.Features.UpdateStatus status = UpdateStatus.Statuses.FirstOrDefault(s => s.ModuleName == module); | ||
if (status == null) | ||
{ | ||
response = "Module not found."; | ||
return false; | ||
} | ||
|
||
Task.Run(async () => await UpdateStatus.DownloadPlugin(status)); | ||
ServerStatic.StopNextRound = ServerStatic.NextRoundAction.Restart; | ||
response = "Downloaded module. Server will restart next round."; | ||
return true; | ||
default: | ||
response = "Invalid subcommand. Available subcommands: list, install"; | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters