mirror of
https://github.com/RPCS3/discord-bot.git
synced 2024-11-23 10:19:39 +00:00
move credits to slash commands and update the code slightly
This commit is contained in:
parent
4eb701290a
commit
625f1e3166
@ -6,7 +6,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
|
||||
<PackageReference Include="Octokit" Version="4.0.1" />
|
||||
<PackageReference Include="Octokit" Version="4.0.3" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CompatApiClient\CompatApiClient.csproj" />
|
||||
|
49
CompatBot/Commands/BaseApplicationCommandModuleCustom.cs
Normal file
49
CompatBot/Commands/BaseApplicationCommandModuleCustom.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using CompatBot.Database.Providers;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.SlashCommands;
|
||||
|
||||
namespace CompatBot.Commands;
|
||||
|
||||
internal class BaseApplicationCommandModuleCustom : ApplicationCommandModule
|
||||
{
|
||||
private DateTimeOffset executionStart;
|
||||
|
||||
public override async Task<bool> BeforeSlashExecutionAsync(InteractionContext ctx)
|
||||
{
|
||||
executionStart = DateTimeOffset.UtcNow;
|
||||
|
||||
if (ctx.Channel.Name == "media" && ctx.Interaction is { Type: InteractionType.ApplicationCommand, Data.Name: not ("warn" or "report") })
|
||||
{
|
||||
//todo: look what's available in data
|
||||
Config.Log.Info($"Ignoring slash command from {ctx.User.Username} (<@{ctx.User.Id}>) in #media: {ctx.Interaction.Data}");
|
||||
await ctx.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource,
|
||||
new DiscordInteractionResponseBuilder().WithContent($"Only `warn` and `report` are allowed in {ctx.Channel.Mention}").AsEphemeral()
|
||||
).ConfigureAwait(false);
|
||||
Config.TelemetryClient?.TrackRequest(ctx.Interaction.Data.Name, executionStart, DateTimeOffset.UtcNow - executionStart, HttpStatusCode.Forbidden.ToString(), true);
|
||||
return false;
|
||||
}
|
||||
|
||||
var disabledCmds = DisabledCommandsProvider.Get();
|
||||
if (disabledCmds.Contains(ctx.Interaction.Data.Name) && !disabledCmds.Contains("*"))
|
||||
{
|
||||
await ctx.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource,
|
||||
new DiscordInteractionResponseBuilder().WithContent($"Command `{ctx.Interaction.Data.Name}` is currently disabled").AsEphemeral()
|
||||
).ConfigureAwait(false);
|
||||
Config.TelemetryClient?.TrackRequest(ctx.Interaction.Data.Name, executionStart, DateTimeOffset.UtcNow - executionStart, HttpStatusCode.Locked.ToString(), true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return await base.BeforeSlashExecutionAsync(ctx).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public override Task AfterSlashExecutionAsync(InteractionContext ctx)
|
||||
{
|
||||
StatsStorage.IncCmdStat(ctx.Interaction.Data.Name);
|
||||
Config.TelemetryClient?.TrackRequest(ctx.Interaction.Data.Name, executionStart, DateTimeOffset.UtcNow - executionStart, HttpStatusCode.OK.ToString(), true);
|
||||
return base.AfterSlashExecutionAsync(ctx);
|
||||
}
|
||||
}
|
@ -130,31 +130,6 @@ internal sealed class Misc: BaseCommandModuleCustom
|
||||
|
||||
private static readonly Regex Instead = new("rate (?<instead>.+) instead", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline);
|
||||
|
||||
[Command("credits"), Aliases("about")]
|
||||
[Description("Author Credit")]
|
||||
public async Task About(CommandContext ctx)
|
||||
{
|
||||
var hcorion = ctx.Client.GetEmoji(":hcorion:", DiscordEmoji.FromUnicode("🍁"));
|
||||
var clienthax = ctx.Client.GetEmoji(":gooseknife:", DiscordEmoji.FromUnicode("🐱"));
|
||||
var embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Title = "RPCS3 Compatibility Bot",
|
||||
Url = "https://github.com/RPCS3/discord-bot",
|
||||
Color = DiscordColor.Purple,
|
||||
}.AddField("Made by",
|
||||
"💮 13xforever\n" +
|
||||
"🇭🇷 Roberto Anić Banić aka nicba1010\n" +
|
||||
$"{clienthax} clienthax\n"
|
||||
)
|
||||
.AddField("People who ~~broke~~ helped test the bot",
|
||||
"🐱 Juhn\n" +
|
||||
$"{hcorion} hcorion\n" +
|
||||
"🙃 TGE\n" +
|
||||
"🍒 Maru\n" +
|
||||
"♋ Tourghool");
|
||||
await ctx.Channel.SendMessageAsync(embed: embed.Build());
|
||||
}
|
||||
|
||||
[Command("roll")]
|
||||
[Description("Generates a random number between 1 and maxValue. Can also roll dices like `2d6`. Default is 1d6")]
|
||||
public Task Roll(CommandContext ctx, [Description("Some positive natural number")] int maxValue = 6, [RemainingText, Description("Optional text")] string? comment = null)
|
||||
|
@ -6,10 +6,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CompatBot.Commands;
|
||||
|
||||
internal sealed class SlashTest: ApplicationCommandModule
|
||||
internal sealed class SlashMisc: BaseApplicationCommandModuleCustom
|
||||
{
|
||||
[SlashCommand("credits", "Author Credit")]
|
||||
// TODO [Aliases("about")]
|
||||
[SlashCommand("about", "Bot information")]
|
||||
public async Task About(InteractionContext ctx)
|
||||
{
|
||||
var hcorion = ctx.Client.GetEmoji(":hcorion:", DiscordEmoji.FromUnicode("🍁"));
|
||||
@ -20,17 +19,21 @@ internal sealed class SlashTest: ApplicationCommandModule
|
||||
Url = "https://github.com/RPCS3/discord-bot",
|
||||
Color = DiscordColor.Purple,
|
||||
}.AddField("Made by",
|
||||
"💮 13xforever\n" +
|
||||
"🇭🇷 Roberto Anić Banić aka nicba1010\n" +
|
||||
$"{clienthax} clienthax\n"
|
||||
$"""
|
||||
💮 13xforever
|
||||
🇭🇷 Roberto Anić Banić aka nicba1010
|
||||
{clienthax} clienthax
|
||||
"""
|
||||
)
|
||||
.AddField("People who ~~broke~~ helped test the bot",
|
||||
"🐱 Juhn\n" +
|
||||
$"{hcorion} hcorion\n" +
|
||||
"🙃 TGE\n" +
|
||||
"🍒 Maru\n" +
|
||||
"♋ Tourghool");
|
||||
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().AddEmbed(embed.Build()));
|
||||
$"""
|
||||
🐱 Juhn
|
||||
{hcorion} hcorion
|
||||
🙃 TGE
|
||||
🍒 Maru
|
||||
♋ Tourghool
|
||||
"""
|
||||
);
|
||||
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().AddEmbed(embed.Build()).AsEphemeral());
|
||||
}
|
||||
|
||||
}
|
@ -142,10 +142,6 @@ internal static class Program
|
||||
Intents = DiscordIntents.All,
|
||||
};
|
||||
using var client = new DiscordClient(config);
|
||||
var slashCommands = client.UseSlashCommands();
|
||||
// Only register to rpcs3 guild for now.
|
||||
slashCommands.RegisterCommands<SlashTest>(Config.BotGuildId);
|
||||
|
||||
var commands = client.UseCommandsNext(new()
|
||||
{
|
||||
StringPrefixes = new[] {Config.CommandPrefix, Config.AutoRemoveCommandPrefix},
|
||||
@ -176,10 +172,13 @@ internal static class Program
|
||||
commands.RegisterCommands<ForcedNicknames>();
|
||||
commands.RegisterCommands<Minesweeper>();
|
||||
commands.RegisterCommands<Fortune>();
|
||||
|
||||
if (!string.IsNullOrEmpty(Config.AzureComputerVisionKey))
|
||||
commands.RegisterCommands<Vision>();
|
||||
|
||||
var slashCommands = client.UseSlashCommands();
|
||||
// Only register to rpcs3 guild for now.
|
||||
slashCommands.RegisterCommands<SlashMisc>(Config.BotGuildId);
|
||||
|
||||
commands.CommandErrored += UnknownCommandHandler.OnError;
|
||||
|
||||
client.UseInteractivity(new());
|
||||
|
@ -30,6 +30,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
README.md = README.md
|
||||
SECURITY.md = SECURITY.md
|
||||
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
|
||||
get-names_anidb.ps1 = get-names_anidb.ps1
|
||||
get-names_anilist.ps1 = get-names_anilist.ps1
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneDriveClient", "Clients\OneDriveClient\OneDriveClient.csproj", "{5C4BCF33-2EC6-455F-B026-8A0001B7B7AD}"
|
||||
|
Loading…
Reference in New Issue
Block a user