From a6ba546e91132f369d8f1bb47e6dabfdbfd8f61b Mon Sep 17 00:00:00 2001 From: Bart de Bever Date: Mon, 19 Oct 2020 18:10:16 +0200 Subject: [PATCH] Update dependencies and add various admin commands. --- .../FightCore.Bot/FightCore.Bot.csproj | 12 +++---- .../FightCore.Bot/Modules/AdminModule.cs | 32 +++++++++++++++++++ FightCore.Bot/FightCore.Bot/Program.cs | 21 ++++++++++++ .../FightCore.FrameData/MoveService.cs | 2 +- .../FightCore.MeleeFrameData.csproj | 4 +-- 5 files changed, 62 insertions(+), 9 deletions(-) diff --git a/FightCore.Bot/FightCore.Bot/FightCore.Bot.csproj b/FightCore.Bot/FightCore.Bot/FightCore.Bot.csproj index 6030d0b..712d7df 100644 --- a/FightCore.Bot/FightCore.Bot/FightCore.Bot.csproj +++ b/FightCore.Bot/FightCore.Bot/FightCore.Bot.csproj @@ -8,16 +8,16 @@ - - - - - + + + + + - + diff --git a/FightCore.Bot/FightCore.Bot/Modules/AdminModule.cs b/FightCore.Bot/FightCore.Bot/Modules/AdminModule.cs index 03e7a5d..04be3be 100644 --- a/FightCore.Bot/FightCore.Bot/Modules/AdminModule.cs +++ b/FightCore.Bot/FightCore.Bot/Modules/AdminModule.cs @@ -1,6 +1,8 @@ using System.Linq; using System.Threading.Tasks; +using Discord; using Discord.Commands; +using Discord.WebSocket; using FightCore.Bot.Configuration; using FightCore.Bot.Services; using Microsoft.Extensions.Options; @@ -13,12 +15,15 @@ public class AdminModule : ModuleBase { private readonly FrameDataService _frameDataService; private readonly UsersConfiguration _usersConfiguration; + private readonly DiscordSocketClient _client; public AdminModule( FrameDataService frameDataService, + DiscordSocketClient client, IOptions usersConfiguration) { _frameDataService = frameDataService; _usersConfiguration = usersConfiguration.Value; + _client = client; } [Command("refresh")] @@ -31,6 +36,33 @@ public async Task Refresh() await ReplyAsync(":white_check_mark: Refreshed and all services are back online."); } } + + [Command("servers")] + public async Task Servers() + { + if (_usersConfiguration.Admins.Contains(Context.User.Id)) + { + await ReplyAsync($"Active on {_client.Guilds.Count} servers"); + } + } + + [Command("game")] + public async Task SetGame([Remainder] string gameText) + { + if (_usersConfiguration.Admins.Contains(Context.User.Id)) + { + if (gameText == "clear") + { + await _client.SetGameAsync(null, null, ActivityType.Playing); + await ReplyAsync(":white_check_mark: Cleared the custom game."); + } + else + { + await _client.SetGameAsync(gameText); + await ReplyAsync(":white_check_mark: Set the custom game."); + } + } + } } } diff --git a/FightCore.Bot/FightCore.Bot/Program.cs b/FightCore.Bot/FightCore.Bot/Program.cs index 1fd6a83..1b7e97e 100644 --- a/FightCore.Bot/FightCore.Bot/Program.cs +++ b/FightCore.Bot/FightCore.Bot/Program.cs @@ -13,6 +13,7 @@ using FightCore.SlippiStatsOnline; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder; namespace FightCore.Bot @@ -22,6 +23,7 @@ public class Program static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult(); + private ulong _ownerId = 0; private DiscordSocketClient _client; private IConfiguration _config; @@ -31,6 +33,12 @@ public async Task MainAsync() _config = BuildConfig(); var services = ConfigureServices(); + var admins = services.GetService>().Value.Admins; + if (admins.Count > 0) + { + _ownerId = admins[0]; + } + services.GetRequiredService(); await services.GetRequiredService().InitializeAsync(services); @@ -40,12 +48,25 @@ public async Task MainAsync() // return Task.CompletedTask; //}; + _client.JoinedGuild += ClientOnJoinedGuild; + await _client.LoginAsync(TokenType.Bot, _config["token"]); await _client.StartAsync(); await Task.Delay(-1); } + private async Task ClientOnJoinedGuild(SocketGuild arg) + { + if (_ownerId <= 0) + { + return; + } + + var dmChannel = await _client.GetDMChannelAsync(_ownerId); + await dmChannel.SendMessageAsync($"Joined {arg.Name}, Members: {arg.MemberCount}"); + } + private IServiceProvider ConfigureServices() { return new ServiceCollection() diff --git a/FightCore.Bot/FightCore.FrameData/MoveService.cs b/FightCore.Bot/FightCore.FrameData/MoveService.cs index 50d5650..7c5aa92 100644 --- a/FightCore.Bot/FightCore.FrameData/MoveService.cs +++ b/FightCore.Bot/FightCore.FrameData/MoveService.cs @@ -17,7 +17,7 @@ public class MoveService : IMoveService public MoveService() { - _client = new RestClient("https://localhost:5001"); + _client = new RestClient("https://api.fightcore.gg"); } public async Task> GetCharacters() diff --git a/FightCore.Bot/FightCore.MeleeFrameData/FightCore.MeleeFrameData.csproj b/FightCore.Bot/FightCore.MeleeFrameData/FightCore.MeleeFrameData.csproj index a98cf51..a7f20a9 100644 --- a/FightCore.Bot/FightCore.MeleeFrameData/FightCore.MeleeFrameData.csproj +++ b/FightCore.Bot/FightCore.MeleeFrameData/FightCore.MeleeFrameData.csproj @@ -5,8 +5,8 @@ - - + +