Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3cc3b373e5 | |||
| f6d5281af8 | |||
| fa63886195 | |||
| 9bd5fe75c9 | |||
| d931da37ec | |||
| 9375fa45b2 | |||
| 0b45aee96d | |||
| 80e346d6b5 | |||
| eff0128d29 |
@@ -6,7 +6,7 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
env:
|
env:
|
||||||
VERSION: 3.0.1
|
VERSION: 3.0.5
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# ЧАСТЬ 1: Собираем образы и кладем в Gitea (чтобы делиться с ребятами)
|
# ЧАСТЬ 1: Собираем образы и кладем в Gitea (чтобы делиться с ребятами)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>3.0.1</Version>
|
<Version>3.0.5</Version>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<LangVersion>preview</LangVersion>
|
<LangVersion>preview</LangVersion>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|||||||
@@ -85,8 +85,10 @@ TELEGRAM_BOT_TOKEN=ваш_токен_здесь
|
|||||||
# Токен Discord application bot
|
# Токен Discord application bot
|
||||||
DISCORD_BOT_TOKEN=ваш_discord_токен_здесь
|
DISCORD_BOT_TOKEN=ваш_discord_токен_здесь
|
||||||
|
|
||||||
# Client ID Discord application (используется для slash-команд)
|
# Discord OAuth (для Web Dashboard)
|
||||||
DISCORD_BOT_CLIENT_ID=ваш_discord_client_id_здесь
|
DISCORD_CLIENT_ID=ваш_discord_client_id_здесь
|
||||||
|
DISCORD_CLIENT_SECRET=ваш_discord_client_secret_здесь
|
||||||
|
DISCORD_REDIRECT_URI=https://your-domain.example/auth/discord/callback
|
||||||
|
|
||||||
# Имя бота без @ (для Telegram Login Widget)
|
# Имя бота без @ (для Telegram Login Widget)
|
||||||
TELEGRAM_BOT_USERNAME=ваше_имя_бота_здесь
|
TELEGRAM_BOT_USERNAME=ваше_имя_бота_здесь
|
||||||
@@ -119,7 +121,7 @@ docker compose up -d
|
|||||||
1. Напишите боту `/start`.
|
1. Напишите боту `/start`.
|
||||||
2. Создайте группу через `/newgroup`.
|
2. Создайте группу через `/newgroup`.
|
||||||
3. Откройте Mini App или Web Dashboard для расширенного управления.
|
3. Откройте Mini App или Web Dashboard для расширенного управления.
|
||||||
4. Для Discord пригласите application bot на сервер с правами `bot` и `applications.commands`. Скопируйте `DISCORD_BOT_TOKEN` и `DISCORD_BOT_CLIENT_ID` в `.env`.
|
4. Для Discord пригласите application bot на сервер с правами `bot` и `applications.commands`. Скопируйте `DISCORD_BOT_TOKEN` в `.env`; `DISCORD_CLIENT_ID`, `DISCORD_CLIENT_SECRET` и `DISCORD_REDIRECT_URI` нужны только для входа в Web Dashboard через Discord.
|
||||||
5. Перезапустите Docker Compose (`docker compose up -d`), а затем в Discord создайте сессию через `/newsession` или опубликуйте расписание через `/listsessions`; игроки записываются и выходят кнопками в опубликованном сообщении.
|
5. Перезапустите Docker Compose (`docker compose up -d`), а затем в Discord создайте сессию через `/newsession` или опубликуйте расписание через `/listsessions`; игроки записываются и выходят кнопками в опубликованном сообщении.
|
||||||
|
|
||||||
## 💾 Backup и восстановление
|
## 💾 Backup и восстановление
|
||||||
|
|||||||
+3
-3
@@ -49,7 +49,7 @@ services:
|
|||||||
crond -f
|
crond -f
|
||||||
|
|
||||||
bot:
|
bot:
|
||||||
image: git.codeanddice.ru/toutsu/gmrelay-bot:3.0.1
|
image: git.codeanddice.ru/toutsu/gmrelay-bot:3.0.5
|
||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
@@ -67,7 +67,7 @@ services:
|
|||||||
retries: 3
|
retries: 3
|
||||||
|
|
||||||
discord:
|
discord:
|
||||||
image: git.codeanddice.ru/toutsu/gmrelay-discord-bot:3.0.1
|
image: git.codeanddice.ru/toutsu/gmrelay-discord-bot:3.0.5
|
||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
@@ -84,7 +84,7 @@ services:
|
|||||||
retries: 3
|
retries: 3
|
||||||
|
|
||||||
web:
|
web:
|
||||||
image: git.codeanddice.ru/toutsu/gmrelay-web:3.0.1
|
image: git.codeanddice.ru/toutsu/gmrelay-web:3.0.5
|
||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using NetCord.Services.ApplicationCommands;
|
|||||||
|
|
||||||
namespace GmRelay.DiscordBot.Features.Sessions;
|
namespace GmRelay.DiscordBot.Features.Sessions;
|
||||||
|
|
||||||
[SlashCommand("listsessions", "Show upcoming game sessions in this server")]
|
|
||||||
public class DiscordListSessionsCommand : ApplicationCommandModule<SlashCommandContext>
|
public class DiscordListSessionsCommand : ApplicationCommandModule<SlashCommandContext>
|
||||||
{
|
{
|
||||||
private readonly DiscordListSessionsHandler _handler;
|
private readonly DiscordListSessionsHandler _handler;
|
||||||
@@ -13,9 +12,10 @@ public class DiscordListSessionsCommand : ApplicationCommandModule<SlashCommandC
|
|||||||
_handler = handler;
|
_handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SlashCommand("listsessions", "Show upcoming game sessions in this server")]
|
||||||
public async Task ExecuteAsync()
|
public async Task ExecuteAsync()
|
||||||
{
|
{
|
||||||
var guildId = Context.Guild?.Id.ToString()
|
var guildId = Context.Interaction.GuildId?.ToString()
|
||||||
?? throw new InvalidOperationException("This command can only be used in a guild.");
|
?? throw new InvalidOperationException("This command can only be used in a guild.");
|
||||||
var channelId = Context.Channel.Id.ToString();
|
var channelId = Context.Channel.Id.ToString();
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using NetCord.Services.ApplicationCommands;
|
|||||||
|
|
||||||
namespace GmRelay.DiscordBot.Features.Sessions;
|
namespace GmRelay.DiscordBot.Features.Sessions;
|
||||||
|
|
||||||
[SlashCommand("newsession", "Create a new game session")]
|
|
||||||
public class DiscordNewSessionCommand : ApplicationCommandModule<SlashCommandContext>
|
public class DiscordNewSessionCommand : ApplicationCommandModule<SlashCommandContext>
|
||||||
{
|
{
|
||||||
private readonly DiscordNewSessionHandler _handler;
|
private readonly DiscordNewSessionHandler _handler;
|
||||||
@@ -16,14 +15,17 @@ public class DiscordNewSessionCommand : ApplicationCommandModule<SlashCommandCon
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SlashCommand("newsession", "Create a new game session")]
|
||||||
public async Task ExecuteAsync(
|
public async Task ExecuteAsync(
|
||||||
[SlashCommandParameter(Name = "title", Description = "Game title")] string title,
|
[SlashCommandParameter(Name = "title", Description = "Game title")] string title,
|
||||||
[SlashCommandParameter(Name = "time", Description = "Session time (YYYY-MM-DD HH:mm or DD.MM.YYYY HH:mm)")] string time,
|
[SlashCommandParameter(Name = "time", Description = "Session time (YYYY-MM-DD HH:mm or DD.MM.YYYY HH:mm)")] string time,
|
||||||
[SlashCommandParameter(Name = "seats", Description = "Maximum number of players")] long? seats = null,
|
[SlashCommandParameter(Name = "seats", Description = "Maximum number of players")] long? seats = null,
|
||||||
[SlashCommandParameter(Name = "link", Description = "Join link")] string? link = null)
|
[SlashCommandParameter(Name = "link", Description = "Join link")] string? link = null)
|
||||||
{
|
{
|
||||||
var guild = Context.Guild
|
var guildId = Context.Interaction.GuildId
|
||||||
?? throw new InvalidOperationException("This command can only be used in a guild.");
|
?? throw new InvalidOperationException("This command can only be used in a guild.");
|
||||||
|
var guild = await Context.Client.Rest.GetGuildAsync(guildId);
|
||||||
|
var member = await Context.Client.Rest.GetGuildUserAsync(guildId, Context.User.Id);
|
||||||
|
|
||||||
var timeResult = DiscordNewSessionHandler.ParseTimeInput(time);
|
var timeResult = DiscordNewSessionHandler.ParseTimeInput(time);
|
||||||
if (!timeResult.IsSuccess)
|
if (!timeResult.IsSuccess)
|
||||||
@@ -33,7 +35,7 @@ public class DiscordNewSessionCommand : ApplicationCommandModule<SlashCommandCon
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var resolvedPermissions = GetResolvedPermissions(guild, Context.User.Id);
|
var resolvedPermissions = GetResolvedPermissions(guild, member);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -70,18 +72,17 @@ public class DiscordNewSessionCommand : ApplicationCommandModule<SlashCommandCon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ulong GetResolvedPermissions(NetCord.Gateway.Guild guild, ulong userId)
|
private static ulong GetResolvedPermissions(NetCord.Rest.RestGuild guild, NetCord.GuildUser member)
|
||||||
{
|
{
|
||||||
if (!guild.Users.TryGetValue(userId, out var guildUser))
|
if (member is null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ulong resolved = 0;
|
ulong resolved = 0;
|
||||||
foreach (var roleId in guildUser.RoleIds)
|
foreach (var roleId in member.RoleIds)
|
||||||
{
|
{
|
||||||
if (guild.Roles.TryGetValue(roleId, out var role))
|
if (guild.Roles.TryGetValue(roleId, out var role))
|
||||||
resolved |= (ulong)role.Permissions;
|
resolved |= (ulong)role.Permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ namespace GmRelay.DiscordBot.Features.Sessions;
|
|||||||
using NetCord.Rest;
|
using NetCord.Rest;
|
||||||
using NetCord.Services.ApplicationCommands;
|
using NetCord.Services.ApplicationCommands;
|
||||||
|
|
||||||
[SlashCommand("reschedule", "Initiate reschedule voting for a session")]
|
|
||||||
public class DiscordRescheduleCommand : ApplicationCommandModule<SlashCommandContext>
|
public class DiscordRescheduleCommand : ApplicationCommandModule<SlashCommandContext>
|
||||||
{
|
{
|
||||||
private readonly DiscordRescheduleHandler _handler;
|
private readonly DiscordRescheduleHandler _handler;
|
||||||
@@ -15,6 +14,7 @@ public class DiscordRescheduleCommand : ApplicationCommandModule<SlashCommandCon
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SlashCommand("reschedule", "Initiate reschedule voting for a session")]
|
||||||
public async Task ExecuteAsync(
|
public async Task ExecuteAsync(
|
||||||
[SlashCommandParameter(Name = "session", Description = "Session ID to reschedule")] string sessionIdText,
|
[SlashCommandParameter(Name = "session", Description = "Session ID to reschedule")] string sessionIdText,
|
||||||
[SlashCommandParameter(Name = "option1", Description = "First time option (YYYY-MM-DD HH:mm)")] string option1,
|
[SlashCommandParameter(Name = "option1", Description = "First time option (YYYY-MM-DD HH:mm)")] string option1,
|
||||||
@@ -22,8 +22,10 @@ public class DiscordRescheduleCommand : ApplicationCommandModule<SlashCommandCon
|
|||||||
[SlashCommandParameter(Name = "option3", Description = "Third time option (optional)")] string? option3 = null,
|
[SlashCommandParameter(Name = "option3", Description = "Third time option (optional)")] string? option3 = null,
|
||||||
[SlashCommandParameter(Name = "deadline", Description = "Voting deadline (YYYY-MM-DD HH:mm)")] string deadline = "")
|
[SlashCommandParameter(Name = "deadline", Description = "Voting deadline (YYYY-MM-DD HH:mm)")] string deadline = "")
|
||||||
{
|
{
|
||||||
var guild = Context.Guild
|
var guildId = Context.Interaction.GuildId
|
||||||
?? throw new InvalidOperationException("This command can only be used in a guild.");
|
?? throw new InvalidOperationException("This command can only be used in a guild.");
|
||||||
|
var guild = await Context.Client.Rest.GetGuildAsync(guildId);
|
||||||
|
var member = await Context.Client.Rest.GetGuildUserAsync(guildId, Context.User.Id);
|
||||||
|
|
||||||
if (!Guid.TryParse(sessionIdText, out var sessionId))
|
if (!Guid.TryParse(sessionIdText, out var sessionId))
|
||||||
{
|
{
|
||||||
@@ -64,7 +66,7 @@ public class DiscordRescheduleCommand : ApplicationCommandModule<SlashCommandCon
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var resolvedPermissions = GetResolvedPermissions(guild, Context.User.Id);
|
var resolvedPermissions = GetResolvedPermissions(guild, member);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -102,12 +104,13 @@ public class DiscordRescheduleCommand : ApplicationCommandModule<SlashCommandCon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ulong GetResolvedPermissions(NetCord.Gateway.Guild guild, ulong userId)
|
private static ulong GetResolvedPermissions(NetCord.Rest.RestGuild guild, NetCord.GuildUser member)
|
||||||
{
|
{
|
||||||
if (!guild.Users.TryGetValue(userId, out var guildUser))
|
if (member is null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ulong resolved = 0;
|
ulong resolved = 0;
|
||||||
foreach (var roleId in guildUser.RoleIds)
|
foreach (var roleId in member.RoleIds)
|
||||||
{
|
{
|
||||||
if (guild.Roles.TryGetValue(roleId, out var role))
|
if (guild.Roles.TryGetValue(roleId, out var role))
|
||||||
resolved |= (ulong)role.Permissions;
|
resolved |= (ulong)role.Permissions;
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ public sealed class DiscordSessionInteractionModule(
|
|||||||
|
|
||||||
private DiscordSessionInteractionInput CreateInput(Guid sessionId)
|
private DiscordSessionInteractionInput CreateInput(Guid sessionId)
|
||||||
{
|
{
|
||||||
var guild = Context.Guild
|
var guildId = Context.Interaction.GuildId?.ToString(CultureInfo.InvariantCulture)
|
||||||
?? throw new InvalidOperationException("Session buttons can only be used in a guild.");
|
?? throw new InvalidOperationException("Session buttons can only be used in a guild.");
|
||||||
var message = Context.Interaction.Message
|
var message = Context.Interaction.Message
|
||||||
?? throw new InvalidOperationException("Session button interaction must include a message.");
|
?? throw new InvalidOperationException("Session button interaction must include a message.");
|
||||||
@@ -176,7 +176,7 @@ public sealed class DiscordSessionInteractionModule(
|
|||||||
return new DiscordSessionInteractionInput(
|
return new DiscordSessionInteractionInput(
|
||||||
SessionId: sessionId,
|
SessionId: sessionId,
|
||||||
InteractionId: Context.Interaction.Id.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
InteractionId: Context.Interaction.Id.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||||
GuildId: guild.Id.ToString(CultureInfo.InvariantCulture),
|
GuildId: guildId,
|
||||||
ChannelId: Context.Channel.Id.ToString(CultureInfo.InvariantCulture),
|
ChannelId: Context.Channel.Id.ToString(CultureInfo.InvariantCulture),
|
||||||
MessageId: message.Id.ToString(CultureInfo.InvariantCulture),
|
MessageId: message.Id.ToString(CultureInfo.InvariantCulture),
|
||||||
UserId: Context.User.Id,
|
UserId: Context.User.Id,
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using NetCord;
|
using NetCord;
|
||||||
using NetCord.Gateway;
|
using NetCord.Gateway;
|
||||||
using NetCord.Hosting.Gateway;
|
using NetCord.Hosting.Gateway;
|
||||||
|
using NetCord.Hosting.Services;
|
||||||
using NetCord.Hosting.Services.ApplicationCommands;
|
using NetCord.Hosting.Services.ApplicationCommands;
|
||||||
using NetCord.Hosting.Services.ComponentInteractions;
|
using NetCord.Hosting.Services.ComponentInteractions;
|
||||||
|
using NetCord.Services.ApplicationCommands;
|
||||||
using NetCord.Services.ComponentInteractions;
|
using NetCord.Services.ComponentInteractions;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
|
|
||||||
@@ -82,12 +84,13 @@ builder.Services
|
|||||||
options.Token = discordOptions.Token;
|
options.Token = discordOptions.Token;
|
||||||
options.Intents = GatewayIntents.Guilds;
|
options.Intents = GatewayIntents.Guilds;
|
||||||
})
|
})
|
||||||
.AddApplicationCommands()
|
.AddApplicationCommands<SlashCommandInteraction, SlashCommandContext>()
|
||||||
.AddComponentInteractions<ButtonInteraction, ButtonInteractionContext>()
|
.AddComponentInteractions<ButtonInteraction, ButtonInteractionContext>()
|
||||||
.AddGatewayHandlers(typeof(Program).Assembly);
|
.AddGatewayHandlers(typeof(Program).Assembly);
|
||||||
|
|
||||||
var host = builder.Build();
|
var host = builder.Build();
|
||||||
|
|
||||||
host.AddSlashCommand("ping", "Checks whether GM-Relay Discord is online.", () => "Pong!");
|
host.AddSlashCommand("ping", "Checks whether GM-Relay Discord is online.", () => "Pong!");
|
||||||
|
host.AddModules(typeof(Program).Assembly);
|
||||||
|
|
||||||
await host.RunAsync();
|
await host.RunAsync();
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="nav-version">v3.0.1</div>
|
<div class="nav-version">v3.0.5</div>
|
||||||
</div>
|
</div>
|
||||||
</Authorized>
|
</Authorized>
|
||||||
<NotAuthorized>
|
<NotAuthorized>
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public sealed class DiscordProjectStructureTests
|
|||||||
var prChecks = File.ReadAllText(Path.Combine(repoRoot, ".gitea", "workflows", "pr-checks.yml"));
|
var prChecks = File.ReadAllText(Path.Combine(repoRoot, ".gitea", "workflows", "pr-checks.yml"));
|
||||||
var deploy = File.ReadAllText(Path.Combine(repoRoot, ".gitea", "workflows", "deploy.yml"));
|
var deploy = File.ReadAllText(Path.Combine(repoRoot, ".gitea", "workflows", "deploy.yml"));
|
||||||
|
|
||||||
Assert.Contains("gmrelay-discord-bot:3.0.1", compose);
|
Assert.Contains("gmrelay-discord-bot:3.0.5", compose);
|
||||||
Assert.Contains("Discord__Token=${DISCORD_BOT_TOKEN:?Set DISCORD_BOT_TOKEN in .env}", compose);
|
Assert.Contains("Discord__Token=${DISCORD_BOT_TOKEN:?Set DISCORD_BOT_TOKEN in .env}", compose);
|
||||||
Assert.Contains("src/GmRelay.DiscordBot/Dockerfile", deploy);
|
Assert.Contains("src/GmRelay.DiscordBot/Dockerfile", deploy);
|
||||||
Assert.Contains("DISCORD_BOT_TOKEN", deploy);
|
Assert.Contains("DISCORD_BOT_TOKEN", deploy);
|
||||||
@@ -75,13 +75,13 @@ public sealed class DiscordProjectStructureTests
|
|||||||
{
|
{
|
||||||
var repoRoot = GetRepoRoot();
|
var repoRoot = GetRepoRoot();
|
||||||
|
|
||||||
Assert.Contains("<Version>3.0.1</Version>", File.ReadAllText(Path.Combine(repoRoot, "Directory.Build.props")));
|
Assert.Contains("<Version>3.0.5</Version>", File.ReadAllText(Path.Combine(repoRoot, "Directory.Build.props")));
|
||||||
Assert.Contains("VERSION: 3.0.1", File.ReadAllText(Path.Combine(repoRoot, ".gitea", "workflows", "deploy.yml")));
|
Assert.Contains("VERSION: 3.0.5", File.ReadAllText(Path.Combine(repoRoot, ".gitea", "workflows", "deploy.yml")));
|
||||||
Assert.Contains("gmrelay-bot:3.0.1", File.ReadAllText(Path.Combine(repoRoot, "compose.yaml")));
|
Assert.Contains("gmrelay-bot:3.0.5", File.ReadAllText(Path.Combine(repoRoot, "compose.yaml")));
|
||||||
Assert.Contains("gmrelay-web:3.0.1", File.ReadAllText(Path.Combine(repoRoot, "compose.yaml")));
|
Assert.Contains("gmrelay-web:3.0.5", File.ReadAllText(Path.Combine(repoRoot, "compose.yaml")));
|
||||||
Assert.Contains("gmrelay-discord-bot:3.0.1", File.ReadAllText(Path.Combine(repoRoot, "compose.yaml")));
|
Assert.Contains("gmrelay-discord-bot:3.0.5", File.ReadAllText(Path.Combine(repoRoot, "compose.yaml")));
|
||||||
Assert.Contains(
|
Assert.Contains(
|
||||||
"v3.0.1",
|
"v3.0.5",
|
||||||
File.ReadAllText(Path.Combine(repoRoot, "src", "GmRelay.Web", "Components", "Layout", "NavMenu.razor")));
|
File.ReadAllText(Path.Combine(repoRoot, "src", "GmRelay.Web", "Components", "Layout", "NavMenu.razor")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +94,16 @@ public sealed class DiscordProjectStructureTests
|
|||||||
Assert.Contains("DISCORD_BOT_TOKEN", envExample);
|
Assert.Contains("DISCORD_BOT_TOKEN", envExample);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Readme_ShouldNotAskForUnusedDiscordBotClientId()
|
||||||
|
{
|
||||||
|
var repoRoot = GetRepoRoot();
|
||||||
|
var readme = File.ReadAllText(Path.Combine(repoRoot, "README.md"));
|
||||||
|
|
||||||
|
Assert.DoesNotContain("DISCORD_BOT_CLIENT_ID", readme);
|
||||||
|
Assert.Contains("DISCORD_CLIENT_ID", readme);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Compose_ShouldIncludeDiscordHealthcheck()
|
public void Compose_ShouldIncludeDiscordHealthcheck()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using GmRelay.DiscordBot.Features.Sessions;
|
||||||
|
using NetCord.Services.ApplicationCommands;
|
||||||
|
|
||||||
namespace GmRelay.Bot.Tests.Discord;
|
namespace GmRelay.Bot.Tests.Discord;
|
||||||
|
|
||||||
@@ -47,6 +50,41 @@ public sealed class DiscordStartupTests
|
|||||||
Assert.Contains(".AddComponentInteractions", program);
|
Assert.Contains(".AddComponentInteractions", program);
|
||||||
Assert.Contains(".AddGatewayHandlers", program);
|
Assert.Contains(".AddGatewayHandlers", program);
|
||||||
Assert.Contains("AddSlashCommand", program);
|
Assert.Contains("AddSlashCommand", program);
|
||||||
|
Assert.Contains("AddModules(typeof(Program).Assembly)", program);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(typeof(DiscordNewSessionCommand), "newsession")]
|
||||||
|
[InlineData(typeof(DiscordListSessionsCommand), "listsessions")]
|
||||||
|
[InlineData(typeof(DiscordRescheduleCommand), "reschedule")]
|
||||||
|
public void DiscordSessionSlashCommands_ShouldBeDeclaredOnModuleMethods(Type moduleType, string commandName)
|
||||||
|
{
|
||||||
|
var executeMethod = moduleType.GetMethod("ExecuteAsync", BindingFlags.Instance | BindingFlags.Public);
|
||||||
|
|
||||||
|
Assert.NotNull(executeMethod);
|
||||||
|
|
||||||
|
var methodAttribute = Assert.Single(executeMethod.GetCustomAttributes<SlashCommandAttribute>(inherit: false));
|
||||||
|
var nameProperty = typeof(SlashCommandAttribute).GetProperty("Name")
|
||||||
|
?? throw new InvalidOperationException("SlashCommandAttribute should expose command name.");
|
||||||
|
|
||||||
|
Assert.Equal(commandName, nameProperty.GetValue(methodAttribute));
|
||||||
|
Assert.Empty(moduleType.GetCustomAttributes<SlashCommandAttribute>(inherit: false));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void DiscordSessionSlashCommands_ShouldBeDiscoverableByNetCordService()
|
||||||
|
{
|
||||||
|
var service = new ApplicationCommandService<SlashCommandContext>();
|
||||||
|
|
||||||
|
service.AddModules(typeof(DiscordNewSessionCommand).Assembly);
|
||||||
|
|
||||||
|
var commandNames = service.GetCommands()
|
||||||
|
.Select(command => command.Name)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
Assert.Contains("newsession", commandNames);
|
||||||
|
Assert.Contains("listsessions", commandNames);
|
||||||
|
Assert.Contains("reschedule", commandNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user