Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
Update dependencies and add various admin commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartdebever committed Oct 19, 2020
1 parent af578c5 commit a6ba546
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
12 changes: 6 additions & 6 deletions FightCore.Bot/FightCore.Bot/FightCore.Bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

<ItemGroup>
<PackageReference Include="Discord.Net" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.9" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="GraphQL.Client" Version="3.1.9" />
<PackageReference Include="GraphQL.Client" Version="3.2.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
</ItemGroup>

Expand Down
32 changes: 32 additions & 0 deletions FightCore.Bot/FightCore.Bot/Modules/AdminModule.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,12 +15,15 @@ public class AdminModule : ModuleBase<SocketCommandContext>
{
private readonly FrameDataService _frameDataService;
private readonly UsersConfiguration _usersConfiguration;
private readonly DiscordSocketClient _client;
public AdminModule(
FrameDataService frameDataService,
DiscordSocketClient client,
IOptions<UsersConfiguration> usersConfiguration)
{
_frameDataService = frameDataService;
_usersConfiguration = usersConfiguration.Value;
_client = client;
}

[Command("refresh")]
Expand All @@ -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.");
}
}
}
}

}
21 changes: 21 additions & 0 deletions FightCore.Bot/FightCore.Bot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -31,6 +33,12 @@ public async Task MainAsync()
_config = BuildConfig();

var services = ConfigureServices();
var admins = services.GetService<IOptions<UsersConfiguration>>().Value.Admins;
if (admins.Count > 0)
{
_ownerId = admins[0];
}

services.GetRequiredService<LogService>();
await services.GetRequiredService<CommandHandlingService>().InitializeAsync(services);

Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion FightCore.Bot/FightCore.FrameData/MoveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Character>> GetCharacters()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.9" />
</ItemGroup>

</Project>

0 comments on commit a6ba546

Please sign in to comment.