[Groups] Add role setup
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -684,5 +684,3 @@ fabric.properties
|
||||
# Additional files built by Visual Studio
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/visualstudio,visualstudiocode,rider,csharp,dotnetcore
|
||||
|
||||
Cocotte/discord.json
|
||||
@@ -11,8 +11,4 @@
|
||||
<PackageReference Include="Discord.Net" Version="3.8.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Modules" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
42
Cocotte/Modules/Groups/GroupModule.cs
Normal file
42
Cocotte/Modules/Groups/GroupModule.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Cocotte.Options;
|
||||
using Cocotte.Utils;
|
||||
using Discord;
|
||||
using Discord.Interactions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Cocotte.Modules.Groups;
|
||||
|
||||
/// <summary>
|
||||
/// Module to ask and propose groups for different activities: Abyss, OOW, FC, ...
|
||||
/// </summary>
|
||||
[Group("group", "Group related commands")]
|
||||
public class GroupModule : InteractionModuleBase<SocketInteractionContext>
|
||||
{
|
||||
private readonly ILogger<GroupModule> _logger;
|
||||
private readonly GroupsOptions _options;
|
||||
|
||||
public GroupModule(ILogger<GroupModule> logger, IOptions<GroupsOptions> options)
|
||||
{
|
||||
_logger = logger;
|
||||
_options = options.Value;
|
||||
}
|
||||
|
||||
[RequireOwner]
|
||||
[SlashCommand("test", "Test group module")]
|
||||
public async Task Test()
|
||||
{
|
||||
await RespondAsync("Module is active!!");
|
||||
}
|
||||
|
||||
[RequireOwner]
|
||||
[SlashCommand("setup-info", "Display group setup info")]
|
||||
public async Task SetupInfo()
|
||||
{
|
||||
await RespondAsync($"""
|
||||
- Helper: {MentionUtils.MentionRole(_options.HelperRoleId)} {_options.HelperEmote.ToEmote()}
|
||||
- Dps: {MentionUtils.MentionRole(_options.DpsRoleId)} {_options.DpsEmote.ToEmote()}
|
||||
- Tank: {MentionUtils.MentionRole(_options.TankRoleId)} {_options.TankEmote.ToEmote()}
|
||||
- Healer: {MentionUtils.MentionRole(_options.HealerRoleId)} {_options.HealerEmote.ToEmote()}
|
||||
""");
|
||||
}
|
||||
}
|
||||
18
Cocotte/Options/GroupsOptions.cs
Normal file
18
Cocotte/Options/GroupsOptions.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace Cocotte.Options;
|
||||
|
||||
public class GroupsOptions
|
||||
{
|
||||
public const string SectionName = "GroupsOptions";
|
||||
|
||||
public ulong HelperRoleId { get; init; }
|
||||
public string HelperEmote { get; init; }
|
||||
|
||||
public ulong DpsRoleId { get; init; }
|
||||
public string DpsEmote { get; init; }
|
||||
|
||||
public ulong TankRoleId { get; init; }
|
||||
public string TankEmote { get; init; }
|
||||
|
||||
public ulong HealerRoleId { get; init; }
|
||||
public string HealerEmote { get; init; }
|
||||
}
|
||||
@@ -9,18 +9,21 @@ using Discord.WebSocket;
|
||||
DiscordSocketConfig discordSocketConfig = new()
|
||||
{
|
||||
LogLevel = LogSeverity.Debug,
|
||||
MessageCacheSize = 200
|
||||
MessageCacheSize = 200,
|
||||
GatewayIntents = GatewayIntents.None
|
||||
};
|
||||
|
||||
IHost host = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureAppConfiguration((_, configuration) =>
|
||||
{
|
||||
configuration.AddJsonFile("discord.json", false, false);
|
||||
configuration.AddJsonFile("groups.json", false, false);
|
||||
})
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
// Options
|
||||
services.Configure<DiscordOptions>(context.Configuration.GetSection(DiscordOptions.SectionName));
|
||||
services.Configure<GroupsOptions>(context.Configuration.GetSection(GroupsOptions.SectionName));
|
||||
|
||||
// Discord.Net
|
||||
services.AddHostedService<DiscordLoggingService>();
|
||||
@@ -37,6 +40,8 @@ IHost host = Host.CreateDefaultBuilder(args)
|
||||
services.AddSingleton<IPlayerInfosRepository, MemoryPlayerInfosRepository>();
|
||||
services.AddSingleton<RolesOptions>();
|
||||
|
||||
// Groups
|
||||
|
||||
// Raids
|
||||
services.AddTransient<RaidFormatter>();
|
||||
services.AddSingleton<RaidRegisterManager>();
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
"dotnetRunMessages": true,
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"workingDirectory": "bin/Debug/net7.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,18 +15,20 @@ public class CocotteService : BackgroundService
|
||||
private readonly IHostApplicationLifetime _hostApplicationLifetime;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly DiscordOptions _options;
|
||||
private readonly GroupsOptions _groupOptions;
|
||||
private readonly InteractionService _interactionService;
|
||||
|
||||
public CocotteService(ILogger<CocotteService> logger, IServiceProvider serviceProvider,
|
||||
IHostEnvironment hostEnvironment,
|
||||
IHostApplicationLifetime hostApplicationLifetime, DiscordSocketClient client,
|
||||
IOptions<DiscordOptions> options, InteractionService interactionService)
|
||||
IOptions<DiscordOptions> options, IOptions<GroupsOptions> groupOptions, InteractionService interactionService)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceProvider = serviceProvider;
|
||||
_hostApplicationLifetime = hostApplicationLifetime;
|
||||
_client = client;
|
||||
_options = options.Value;
|
||||
_groupOptions = groupOptions.Value;
|
||||
_interactionService = interactionService;
|
||||
_hostEnvironment = hostEnvironment;
|
||||
}
|
||||
@@ -34,7 +36,7 @@ public class CocotteService : BackgroundService
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
// Check token first
|
||||
if (_options.Token is null)
|
||||
if (string.IsNullOrWhiteSpace(_options.Token))
|
||||
{
|
||||
_logger.LogError("Couldn't find any discord bot token, exiting...");
|
||||
|
||||
@@ -43,6 +45,11 @@ public class CocotteService : BackgroundService
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ValidateOptions())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize modules and commands
|
||||
await _interactionService.AddModulesAsync(Assembly.GetEntryAssembly(), _serviceProvider);
|
||||
|
||||
@@ -56,6 +63,22 @@ public class CocotteService : BackgroundService
|
||||
await Task.Delay(Timeout.Infinite, stoppingToken);
|
||||
}
|
||||
|
||||
private bool ValidateOptions()
|
||||
{
|
||||
// Validate group options
|
||||
if ((_groupOptions.HelperRoleId
|
||||
| _groupOptions.DpsRoleId
|
||||
| _groupOptions.TankRoleId
|
||||
| _groupOptions.HealerRoleId) == 0)
|
||||
{
|
||||
_logger.LogError("One of the group options id is invalid, it cannot be 0");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task ClientOnReady()
|
||||
{
|
||||
// Context & Slash commands can be automatically registered, but this process needs to happen after the client enters the READY state.
|
||||
@@ -63,7 +86,7 @@ public class CocotteService : BackgroundService
|
||||
if (_hostEnvironment.IsDevelopment())
|
||||
{
|
||||
// Check that a dev guild is set
|
||||
if (!_options.DevGuildId.HasValue)
|
||||
if (!_options.DevGuildId.HasValue && _options.DevGuildId!.Value != 0)
|
||||
{
|
||||
_logger.LogError("Couldn't find any dev guild while application is run in dev mode, exiting...");
|
||||
|
||||
|
||||
6
Cocotte/discord.json
Normal file
6
Cocotte/discord.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"DiscordOptions": {
|
||||
"Token": "",
|
||||
"DevGuildId": 0
|
||||
}
|
||||
}
|
||||
15
Cocotte/groups.json
Normal file
15
Cocotte/groups.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"GroupsOptions": {
|
||||
"HelperRoleId": 0,
|
||||
"HelperEmote": "",
|
||||
|
||||
"DpsRoleId": 0,
|
||||
"DpsEmote": "",
|
||||
|
||||
"TankRoleId": 0,
|
||||
"TankEmote": "",
|
||||
|
||||
"HealerRoleId": 0,
|
||||
"HealerEmote": ""
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user