diff --git a/TabletBot.Common/Attributes/Bot/CommandAttribute.cs b/TabletBot.Common/Attributes/Bot/CommandAttribute.cs
index 980985f..fa001bc 100644
--- a/TabletBot.Common/Attributes/Bot/CommandAttribute.cs
+++ b/TabletBot.Common/Attributes/Bot/CommandAttribute.cs
@@ -1,8 +1,10 @@
using System;
+using JetBrains.Annotations;
namespace TabletBot.Common.Attributes.Bot
{
[AttributeUsage(AttributeTargets.Method)]
+ [MeansImplicitUse(ImplicitUseTargetFlags.Members)]
public class CommandAttribute : Attribute
{
public CommandAttribute(params string[] arguments)
diff --git a/TabletBot.Common/LogMessage.cs b/TabletBot.Common/LogMessage.cs
index 31bf826..96b1591 100644
--- a/TabletBot.Common/LogMessage.cs
+++ b/TabletBot.Common/LogMessage.cs
@@ -1,5 +1,4 @@
using System;
-using System.Linq;
namespace TabletBot.Common
{
diff --git a/TabletBot.Common/Reflection/Extensions.cs b/TabletBot.Common/Reflection/Extensions.cs
index 5174869..3e32c7a 100644
--- a/TabletBot.Common/Reflection/Extensions.cs
+++ b/TabletBot.Common/Reflection/Extensions.cs
@@ -1,5 +1,4 @@
using System;
-using System.Linq;
using System.Reflection;
namespace TabletBot.Common.Reflection
diff --git a/TabletBot.Common/Settings.cs b/TabletBot.Common/Settings.cs
index c4d73d4..59c412a 100644
--- a/TabletBot.Common/Settings.cs
+++ b/TabletBot.Common/Settings.cs
@@ -1,4 +1,3 @@
-using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Text.Json;
@@ -15,7 +14,6 @@ public sealed class Settings
private const ulong MODERATOR_ROLE_ID = 644180151755735060;
private const ulong MUTED_ROLE_ID = 715342682293010452;
- public int DeleteDelay { set; get; } = 5000;
public ulong GuildID { set; get; } = MAIN_GUILD_ID;
public ulong LogMessageChannelID { set; get; } = LOG_MESSAGE_CHANNEL_ID;
public ulong ModeratorRoleID { set; get; } = MODERATOR_ROLE_ID;
diff --git a/TabletBot.Common/TabletBot.Common.csproj b/TabletBot.Common/TabletBot.Common.csproj
index f208d30..6367da3 100644
--- a/TabletBot.Common/TabletBot.Common.csproj
+++ b/TabletBot.Common/TabletBot.Common.csproj
@@ -4,4 +4,8 @@
net5.0
+
+
+
+
diff --git a/TabletBot.Discord/Commands/Attributes/ModuleAttribute.cs b/TabletBot.Discord/Commands/Attributes/ModuleAttribute.cs
new file mode 100644
index 0000000..2bbddf2
--- /dev/null
+++ b/TabletBot.Discord/Commands/Attributes/ModuleAttribute.cs
@@ -0,0 +1,10 @@
+using System;
+using JetBrains.Annotations;
+
+namespace TabletBot.Discord.Commands.Attributes
+{
+ [MeansImplicitUse(ImplicitUseTargetFlags.Members)]
+ public class ModuleAttribute : Attribute
+ {
+ }
+}
\ No newline at end of file
diff --git a/TabletBot.Discord/Commands/CommandExtensions.cs b/TabletBot.Discord/Commands/CommandExtensions.cs
index 998d59f..b7a5105 100644
--- a/TabletBot.Discord/Commands/CommandExtensions.cs
+++ b/TabletBot.Discord/Commands/CommandExtensions.cs
@@ -84,5 +84,13 @@ public static EmbedFooterBuilder ToEmbedFooter(this IUser user, string textForma
IconUrl = user.GetAvatarUrl()
};
}
+
+ public static MessageReference ToReference(this IUserMessage message)
+ {
+ if (message.Channel is IGuildChannel guildChannel)
+ return new MessageReference(message.Id, message.Channel.Id, guildChannel.GuildId);
+
+ return new MessageReference(message.Id, message.Channel.Id);
+ }
}
}
\ No newline at end of file
diff --git a/TabletBot.Discord/Commands/CommandModule.cs b/TabletBot.Discord/Commands/CommandModule.cs
index 38b0c2c..d22d418 100644
--- a/TabletBot.Discord/Commands/CommandModule.cs
+++ b/TabletBot.Discord/Commands/CommandModule.cs
@@ -1,8 +1,29 @@
+using System.Threading.Tasks;
+using Discord;
using Discord.Commands;
+using JetBrains.Annotations;
namespace TabletBot.Discord.Commands
{
+ [UsedImplicitly(ImplicitUseTargetFlags.Members)]
public class CommandModule : ModuleBase
{
+ protected override Task ReplyAsync(
+ string message = null,
+ bool isTTS = false,
+ Embed embed = null,
+ RequestOptions options = null,
+ AllowedMentions allowedMentions = null,
+ MessageReference messageReference = null,
+ MessageComponent components = null,
+ ISticker[] stickers = null,
+ Embed[] embeds = null
+ )
+ {
+ messageReference ??= Context.Message.ToReference();
+
+ return base.ReplyAsync(message, isTTS, embed, options, allowedMentions, messageReference, components,
+ stickers, embeds);
+ }
}
}
\ No newline at end of file
diff --git a/TabletBot.Discord/Commands/GitHubCommands.cs b/TabletBot.Discord/Commands/GitHubCommands.cs
index fb5335e..a12506e 100644
--- a/TabletBot.Discord/Commands/GitHubCommands.cs
+++ b/TabletBot.Discord/Commands/GitHubCommands.cs
@@ -8,13 +8,15 @@
using Discord.Commands;
using Discord.WebSocket;
using Octokit;
+using TabletBot.Discord.Commands.Attributes;
using TabletBot.Discord.Embeds;
namespace TabletBot.Discord.Commands
{
+ [Module]
public class GitHubCommands : CommandModule
{
- private GitHubClient _gitHubClient;
+ private readonly GitHubClient _gitHubClient;
private readonly DiscordSocketClient _discordSocketClient;
public GitHubCommands(GitHubClient gitHubClient, DiscordSocketClient discordSocketClient)
@@ -23,16 +25,16 @@ public GitHubCommands(GitHubClient gitHubClient, DiscordSocketClient discordSock
_discordSocketClient = discordSocketClient;
}
- private const string RepositoryOwner = "InfinityGhost";
- private const string RepositoryName = "OpenTabletDriver";
+ private const string REPOSITORY_OWNER = "InfinityGhost";
+ private const string REPOSITORY_NAME = "OpenTabletDriver";
private static readonly Regex ArtifactRegex = new Regex("<.+?href=\"/InfinityGhost/OpenTabletDriver/suites/(?.+?)/artifacts/(?.+?)\">(?.+?)");
private static readonly Regex CommitRegex = new Regex("href=\".+?commit/(?.+?)/.+?/.+?\"");
[Command("overview", RunMode = RunMode.Async), Name("Overview"), Alias("info"), Summary("Shows an overview of the repository.")]
public async Task GetRepositoryOverview()
{
- var message = await ReplyAsync($"Getting overview for {RepositoryOwner}/{RepositoryName}...");
- var repo = await _gitHubClient.Repository.Get(RepositoryOwner, RepositoryName);
+ var message = await ReplyAsync($"Getting overview for {REPOSITORY_OWNER}/{REPOSITORY_NAME}...");
+ var repo = await _gitHubClient.Repository.Get(REPOSITORY_OWNER, REPOSITORY_NAME);
IEnumerable issues =
from issue in await _gitHubClient.Issue.GetAllForRepository(repo.Id)
@@ -46,7 +48,7 @@ from pr in await _gitHubClient.PullRequest.GetAllForRepository(repo.Id)
var embed = new EmbedBuilder
{
- Title = $"{RepositoryOwner}/{RepositoryName}",
+ Title = $"{REPOSITORY_OWNER}/{REPOSITORY_NAME}",
Timestamp = repo.PushedAt,
Url = repo.HtmlUrl,
ThumbnailUrl = _discordSocketClient.CurrentUser.GetAvatarUrl(),
@@ -64,9 +66,8 @@ from pr in await _gitHubClient.PullRequest.GetAllForRepository(repo.Id)
[Command("getpr", RunMode = RunMode.Async), Name("Get Pull Request"), Alias("pr"), Summary("Fetches pull request information.")]
public async Task GetPullRequest([Remainder] int id)
{
- await Context.Message.DeleteAsync();
var message = await ReplyAsync($"Fetching pull request #{id}");
- var pr = await _gitHubClient.PullRequest.Get(RepositoryOwner, RepositoryName, id);
+ var pr = await _gitHubClient.PullRequest.Get(REPOSITORY_OWNER, REPOSITORY_NAME, id);
var embed = GitHubEmbeds.GetPullRequestEmbed(pr);
await message.Update(embed);
}
@@ -74,9 +75,8 @@ public async Task GetPullRequest([Remainder] int id)
[Command("getissue", RunMode = RunMode.Async), Name("Get Issue"), Alias("issue"), Summary("Fetches issue information.")]
public async Task GetIssue([Remainder] int id)
{
- await Context.Message.DeleteAsync();
var message = await ReplyAsync($"Fetching issue #{id}");
- var issue = await _gitHubClient.Issue.Get(RepositoryOwner, RepositoryName, id);
+ var issue = await _gitHubClient.Issue.Get(REPOSITORY_OWNER, REPOSITORY_NAME, id);
var embed = GitHubEmbeds.GetIssueEmbed(issue);
await message.Update(embed);
}
@@ -84,23 +84,22 @@ public async Task GetIssue([Remainder] int id)
[Command("getartifacts", RunMode = RunMode.Async), Name("Get Artifacts"), Alias("artifacts", "artifact"), Summary("Returns all artifacts for a workflow from its URL.")]
public async Task GetArtifacts([Remainder] string url)
{
- await Context.Message.DeleteAsync();
var message = await ReplyAsync("Fetching artifacts...");
string html;
using (var client = new HttpClient())
html = await client.GetStringAsync(url);
- IEnumerable artifacts = await Task.Run(() => ArtifactRegex.Matches(html));
- Match commitMatch = await Task.Run(() => CommitRegex.Match(html));
- string sha = commitMatch.Groups["SHA"].Value;
- string hash = string.Concat(sha.Take(7));
- var commit = await _gitHubClient.Git.Commit.Get(RepositoryOwner, RepositoryName, sha);
+ IEnumerable artifacts = await Task.Run(() => ArtifactRegex.Matches(html));
+ var commitMatch = await Task.Run(() => CommitRegex.Match(html));
+ var sha = commitMatch.Groups["SHA"].Value;
+ var hash = string.Concat(sha.Take(7));
+ var commit = await _gitHubClient.Git.Commit.Get(REPOSITORY_OWNER, REPOSITORY_NAME, sha);
var title = commit.Message.Split(Environment.NewLine).First();
var embed = new EmbedBuilder
{
- Title = string.Format("{0} ({1})", title, hash),
+ Title = $"{title} ({hash})",
Url = url,
Color = Color.Green
};
diff --git a/TabletBot.Discord/Commands/HelpCommands.cs b/TabletBot.Discord/Commands/HelpCommands.cs
index 0e6f6e0..f12964b 100644
--- a/TabletBot.Discord/Commands/HelpCommands.cs
+++ b/TabletBot.Discord/Commands/HelpCommands.cs
@@ -5,9 +5,11 @@
using Discord;
using Discord.Commands;
using TabletBot.Common;
+using TabletBot.Discord.Commands.Attributes;
namespace TabletBot.Discord.Commands
{
+ [Module]
public class HelpCommands : CommandModule
{
private readonly Settings _settings;
@@ -29,7 +31,6 @@ public HelpCommands(Settings settings, CommandService commands, IServiceProvider
[Command("help", RunMode = RunMode.Async), Name("Help"), Summary("Lists all commands available.")]
public async Task ListCommands()
{
- await Context.Message.DeleteAsync();
var message = await ReplyAsync("Fetching help...");
IEnumerable modules =
diff --git a/TabletBot.Discord/Commands/ModerationCommands.cs b/TabletBot.Discord/Commands/ModerationCommands.cs
index 04ad048..55df355 100644
--- a/TabletBot.Discord/Commands/ModerationCommands.cs
+++ b/TabletBot.Discord/Commands/ModerationCommands.cs
@@ -3,10 +3,12 @@
using Discord;
using Discord.Commands;
using TabletBot.Common;
+using TabletBot.Discord.Commands.Attributes;
namespace TabletBot.Discord.Commands
{
- public class ModerationCommands : ModuleBase
+ [Module]
+ public class ModerationCommands : CommandModule
{
private readonly Bot _bot;
private readonly Settings _settings;
@@ -22,14 +24,17 @@ public async Task DeleteMessage(int count = 1)
{
await Context.Message.DeleteAsync();
var messages = await Context.Channel.GetMessagesAsync(count).FlattenAsync();
- await (Context.Channel as ITextChannel).DeleteMessagesAsync(messages);
+ if (Context.Channel is ITextChannel textChannel)
+ await textChannel.DeleteMessagesAsync(messages);
+ else
+ await ReplyAsync("Unable to delete messages as the current channel is not a text channel.");
}
[Command("save", RunMode = RunMode.Async), Name("Force Save"), RequireOwner]
public async Task ForceSaveSettings()
{
- await Context.Message.DeleteAsync();
await _settings.Write(Platform.SettingsFile);
+ await ReplyAsync("Settings force saved.", allowedMentions: AllowedMentions.None);
await Log.WriteAsync("Settings", $"{Context.Message.Author.Username} force-saved the configuration to {Platform.SettingsFile.FullName}");
}
@@ -44,32 +49,8 @@ public async Task ForceKillBot()
[Command("set-prefix", RunMode = RunMode.Async), Name("Set prefix"), RequireOwner]
public async Task SetPrefix([Remainder] string prefix)
{
- await Context.Message.DeleteAsync();
_settings.CommandPrefix = prefix;
- var message = await ReplyAsync(string.Format("Set the command prefix to `{0}`.", _settings.CommandPrefix));
- message.DeleteDelayed(_settings.DeleteDelay);
- }
-
- [Command("set-reply-delete-delay", RunMode = RunMode.Async), Name("Set bot reply delete delay"), RequireOwner]
- public async Task SetReplyDeleteDelay(TimeSpan delay)
- {
- await Context.Message.DeleteAsync();
- _settings.DeleteDelay = (int)delay.TotalMilliseconds;
-
- var embed = new EmbedBuilder
- {
- Title = "Set message delay",
- Fields =
- {
- new EmbedFieldBuilder
- {
- Name = "Delay",
- Value = _settings.DeleteDelay
- }
- }
- };
- var message = await ReplyAsync(embed: embed.Build());
- message.DeleteDelayed(_settings.DeleteDelay);
+ await ReplyAsync($"Set the command prefix to `{_settings.CommandPrefix}`.");
}
}
}
\ No newline at end of file
diff --git a/TabletBot.Discord/Commands/RoleCommands.cs b/TabletBot.Discord/Commands/RoleCommands.cs
index f1ec806..b991697 100644
--- a/TabletBot.Discord/Commands/RoleCommands.cs
+++ b/TabletBot.Discord/Commands/RoleCommands.cs
@@ -5,9 +5,11 @@
using Discord.WebSocket;
using TabletBot.Common;
using TabletBot.Common.Store;
+using TabletBot.Discord.Commands.Attributes;
namespace TabletBot.Discord.Commands
{
+ [Module]
public class RoleCommands : CommandModule
{
private readonly Settings _settings;
@@ -24,7 +26,6 @@ public RoleCommands(Settings settings, DiscordSocketClient discordSocketClient)
public async Task AddReactiveRole(IRole role, string emote)
{
var message = Context.Message.ReferencedMessage!;
- var messageRef = new MessageReference(message.Id, message.Channel.Id);
var emoji = emote.GetEmote();
await message.AddReactionAsync(emoji);
@@ -32,10 +33,7 @@ public async Task AddReactiveRole(IRole role, string emote)
_settings.ReactiveRoles.Add(reactionRole);
await _settings.Overwrite();
- var reply = await ReplyAsync($"Reactive role added: {reactionRole.EmoteName}",
- messageReference: messageRef);
- reply.DeleteDelayed(_settings.DeleteDelay);
- await Context.Message.DeleteAsync();
+ await ReplyAsync($"Reactive role added: {reactionRole.EmoteName}", messageReference: message.ToReference());
}
[Command("remove-react-role", RunMode = RunMode.Async), Name("Remove reactive role")]
@@ -51,15 +49,12 @@ public async Task RemoveReactiveRole(IRole role)
await message.RemoveReactionAsync(emoji, _discordSocketClient.CurrentUser);
await _settings.Overwrite();
- var reply = await ReplyAsync($"Reactive role removed from: {reactiveRole.EmoteName}", messageReference: messageRef);
- reply.DeleteDelayed(_settings.DeleteDelay);
+ await ReplyAsync($"Reactive role removed from: {reactiveRole.EmoteName}", messageReference: messageRef);
}
else
{
- var reply = await ReplyAsync($"{role.Name} is not assigned as reactive to the referenced message.");
- reply.DeleteDelayed(_settings.DeleteDelay);
+ await ReplyAsync($"{role.Name} is not assigned as reactive to the referenced message.");
}
- await Context.Message.DeleteAsync();
}
}
}
\ No newline at end of file
diff --git a/TabletBot.Discord/Commands/SnippetCommands.cs b/TabletBot.Discord/Commands/SnippetCommands.cs
index f81a0bc..2e77c6b 100644
--- a/TabletBot.Discord/Commands/SnippetCommands.cs
+++ b/TabletBot.Discord/Commands/SnippetCommands.cs
@@ -6,12 +6,14 @@
using Discord.Commands;
using TabletBot.Common;
using TabletBot.Common.Store;
+using TabletBot.Discord.Commands.Attributes;
using TabletBot.Discord.Embeds;
using TabletBot.Discord.SlashCommands;
using TabletBot.Discord.Watchers;
namespace TabletBot.Discord.Commands
{
+ [Module]
public class SnippetCommands : CommandModule
{
public SnippetCommands(Settings settings, IEnumerable slashCommands)
@@ -34,28 +36,19 @@ public SnippetCommands(Settings settings, IEnumerable slashC
[Command(SHOW_SNIPPET, RunMode = RunMode.Async), Name("Show snippet")]
public async Task ShowSnippet(string prefix)
{
- await Context.Message!.DeleteAsync();
-
- if (SnippetEmbeds.TryGetSnippetEmbed(_settings, prefix, out var embed))
- {
- await ReplyAsync(embed: embed.Build());
- }
- else
- {
- var message = await ReplyAsync(embed: embed.Build(), messageReference: Context.Message.Reference);
- message.DeleteDelayed(_settings.DeleteDelay);
- }
+ SnippetEmbeds.GetSnippetEmbed(_settings, prefix, out var embed);
+ await ReplyAsync(embed: embed.Build());
}
[Command(LIST_SNIPPETS, RunMode = RunMode.Async), Name("List snippets")]
public async Task ListSnippets()
{
- await Context.Message?.DeleteAsync();
-
+ EmbedBuilder embed;
if (Snippets.Any())
{
- var embed = new EmbedBuilder
+ embed = new EmbedBuilder
{
+ Color = Color.Teal,
Title = "Snippets"
};
@@ -66,28 +59,23 @@ public async Task ListSnippets()
" " + snippet.Title
);
}
-
- await ReplyAsync(embed: embed.Build());
}
else
{
- var embed = new EmbedBuilder
+ embed = new EmbedBuilder
{
Color = Color.Magenta,
Title = "Snippets",
Description = "No snippets have been created."
};
-
- var message = await ReplyAsync(embed: embed.Build());
- message.DeleteDelayed(_settings.DeleteDelay);
}
+
+ await ReplyAsync(embed: embed.Build());
}
[Command(SET_SNIPPET, RunMode = RunMode.Async), Name("Create snippet"), RequireUserPermission(GuildPermission.ManageGuild)]
public async Task SetSnippet(string prefix, string title, [Remainder] string content)
{
- await Context.Message!.DeleteAsync();
-
if (Snippets.FirstOrDefault(s => s.Snippet == prefix) is SnippetStore store)
{
// Update the existing snippet
@@ -100,16 +88,23 @@ public async Task SetSnippet(string prefix, string title, [Remainder] string con
store = new SnippetStore(prefix, title, content);
Snippets.Add(store);
}
+
await _settings.Overwrite();
_snippetSlashCommands.OnUpdate();
- await ReplyAsync(embed: SnippetEmbeds.GetSnippetEmbed(store).Build());
+
+ var embed = new EmbedBuilder
+ {
+ Title = store.Title,
+ Color = Color.Magenta,
+ Description = store.Content
+ };
+
+ await ReplyAsync(embed: embed.Build());
}
[Command(REMOVE_SNIPPET, RunMode = RunMode.Async), Name("Delete snippet"), RequireUserPermission(GuildPermission.ManageGuild)]
public async Task RemoveSnippet(string prefix)
{
- await Context.Message!.DeleteAsync();
-
EmbedBuilder result;
if (Snippets.FirstOrDefault(t => t.Snippet == prefix) is SnippetStore snippet)
@@ -141,8 +136,7 @@ public async Task RemoveSnippet(string prefix)
};
}
- var message = await ReplyAsync(embed: result.Build());
- message.DeleteDelayed(_settings.DeleteDelay);
+ await ReplyAsync(embed: result.Build());
}
[Command(EXPORT_SNIPPET, RunMode = RunMode.Async), Name("Export snippet")]
@@ -161,15 +155,14 @@ public async Task ExportSnippet(string prefix)
}
else
{
- var result = new EmbedBuilder
+ var embed = new EmbedBuilder
{
Color = Color.Red,
Title = "Failed to export snippet",
Description = "The snippet was not found."
};
- var message = await ReplyAsync(embed : result.Build());
- message.DeleteDelayed(_settings.DeleteDelay);
+ await ReplyAsync(embed: embed.Build());
}
}
}
diff --git a/TabletBot.Discord/Commands/UserCommands.cs b/TabletBot.Discord/Commands/UserCommands.cs
index aa13685..0cbd237 100644
--- a/TabletBot.Discord/Commands/UserCommands.cs
+++ b/TabletBot.Discord/Commands/UserCommands.cs
@@ -1,17 +1,22 @@
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
+using TabletBot.Discord.Commands.Attributes;
namespace TabletBot.Discord.Commands
{
+ [Module]
public class UserCommands : CommandModule
{
[Command("tablet", RunMode = RunMode.Async), Name("Tablet"), Summary("Appends your tablet's name to the end of your username.")]
public async Task SetTablet([Remainder]string tablet)
{
await Context.Message.DeleteAsync();
- var nickname = string.Format("{0} | {1}", Context.User.Username, tablet);
- await (Context.User as IGuildUser).ModifyAsync(user => user.Nickname = nickname);
+ var nickname = $"{Context.User.Username} | {tablet}";
+ if (Context.User is IGuildUser guildUser)
+ await guildUser.ModifyAsync(user => user.Nickname = nickname);
+ else
+ await ReplyAsync("Failed to set nickname: User is not in a guild.");
}
}
}
\ No newline at end of file
diff --git a/TabletBot.Discord/DiscordExtensions.cs b/TabletBot.Discord/DiscordExtensions.cs
index 82a9cc2..fdb54d9 100644
--- a/TabletBot.Discord/DiscordExtensions.cs
+++ b/TabletBot.Discord/DiscordExtensions.cs
@@ -1,10 +1,7 @@
using System;
-using System.Linq;
using System.Threading.Tasks;
using Discord;
-using Discord.WebSocket;
using TabletBot.Common;
-using TabletBot.Common.Store;
using TabletBot.Discord.Commands;
using TabletBot.Discord.Embeds;
diff --git a/TabletBot.Discord/Embeds/SnippetEmbeds.cs b/TabletBot.Discord/Embeds/SnippetEmbeds.cs
index 2cd5297..6af2910 100644
--- a/TabletBot.Discord/Embeds/SnippetEmbeds.cs
+++ b/TabletBot.Discord/Embeds/SnippetEmbeds.cs
@@ -8,34 +8,27 @@ namespace TabletBot.Discord.Embeds
{
public static class SnippetEmbeds
{
- public static bool TryGetSnippetEmbed(Settings settings, string prefix, out EmbedBuilder embed)
+ public static bool GetSnippetEmbed(Settings settings, string prefix, out EmbedBuilder embed)
{
if (settings.Snippets.FirstOrDefault(s => s.Snippet == prefix) is SnippetStore snippet)
- {
- embed = GetSnippetEmbed(snippet);
- return true;
- }
- else
{
embed = new EmbedBuilder
{
- Color = Color.Red,
- Title = "Failed to show snippet",
- Description = $"Failed to show the `{prefix}` snippet." + Environment.NewLine
- + "Verify that you have spelled it correctly."
+ Title = snippet.Title,
+ Color = Color.Magenta,
+ Description = snippet.Content
};
- return false;
+ return true;
}
- }
- public static EmbedBuilder GetSnippetEmbed(SnippetStore snippet)
- {
- return new EmbedBuilder
+ embed = new EmbedBuilder
{
- Title = snippet.Title,
- Color = Color.Magenta,
- Description = snippet.Content
+ Color = Color.Red,
+ Title = "Failed to show snippet",
+ Description = $"Failed to show the `{prefix}` snippet." + Environment.NewLine
+ + "Verify that you have spelled it correctly."
};
+ return false;
}
}
}
\ No newline at end of file
diff --git a/TabletBot.Discord/LogExtensions.cs b/TabletBot.Discord/LogExtensions.cs
index 0aeba91..420fa8c 100644
--- a/TabletBot.Discord/LogExtensions.cs
+++ b/TabletBot.Discord/LogExtensions.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Threading.Tasks;
+using System.Threading.Tasks;
using Discord;
using TabletBot.Common;
using LogMessage = Discord.LogMessage;
diff --git a/TabletBot.Discord/SlashCommands/ModerationSlashCommands.cs b/TabletBot.Discord/SlashCommands/ModerationSlashCommands.cs
index 159cd56..29d0d77 100644
--- a/TabletBot.Discord/SlashCommands/ModerationSlashCommands.cs
+++ b/TabletBot.Discord/SlashCommands/ModerationSlashCommands.cs
@@ -3,8 +3,6 @@
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
-using Octokit;
-using TabletBot.Common;
namespace TabletBot.Discord.SlashCommands
{
diff --git a/TabletBot.Discord/SlashCommands/SnippetSlashCommands.cs b/TabletBot.Discord/SlashCommands/SnippetSlashCommands.cs
index 2eaacbc..8d0e67e 100644
--- a/TabletBot.Discord/SlashCommands/SnippetSlashCommands.cs
+++ b/TabletBot.Discord/SlashCommands/SnippetSlashCommands.cs
@@ -39,7 +39,7 @@ protected override IEnumerable GetSlashCommands()
{
Name = SHOW_SNIPPET,
Description = "Shows a snippet",
- Options = new List()
+ Options = new List
{
new SlashCommandOptionBuilder
{
@@ -64,7 +64,7 @@ protected override IEnumerable GetSlashCommands()
{
Name = SET_SNIPPET,
Description = "Sets a snippet",
- Options = new List()
+ Options = new List
{
new SlashCommandOptionBuilder
{
@@ -102,7 +102,7 @@ protected override IEnumerable GetSlashCommands()
{
Name = REMOVE_SNIPPET,
Description = "Removes a snippet",
- Options = new List()
+ Options = new List
{
new SlashCommandOptionBuilder
{
@@ -124,7 +124,7 @@ protected override IEnumerable GetSlashCommands()
{
Name = EXPORT_SNIPPET,
Description = "Exports a snippet",
- Options = new List()
+ Options = new List
{
new SlashCommandOptionBuilder
{
@@ -143,7 +143,7 @@ private async Task ShowSnippet(SocketSlashCommand command)
{
var snippet = command.GetValue("snippet");
- if (SnippetEmbeds.TryGetSnippetEmbed(_settings, snippet, out var embed))
+ if (SnippetEmbeds.GetSnippetEmbed(_settings, snippet, out var embed))
await command.FollowupAsync(embed: embed.Build(), ephemeral: false);
else
await command.FollowupAsync("Could not find snippet");
@@ -170,7 +170,12 @@ private async Task SetSnippet(SocketSlashCommand command)
await _settings.Overwrite();
OnUpdate();
- await command.FollowupAsync(embed: SnippetEmbeds.GetSnippetEmbed(store).Build());
+ await command.FollowupAsync(embed: new EmbedBuilder
+ {
+ Title = store.Title,
+ Color = Color.Magenta,
+ Description = store.Content
+ }.Build());
}
private async Task RemoveSnippet(SocketSlashCommand command)
@@ -226,13 +231,16 @@ private List GetSnippets()
return new List();
}
- return _settings.Snippets.Select(s =>
- new ApplicationCommandOptionChoiceProperties
+ var query = from snippet in _settings.Snippets
+ let option = new ApplicationCommandOptionChoiceProperties
{
- Name = s.Title,
- Value = s.Snippet
+ Name = $"{snippet.Snippet}: {snippet.Title}",
+ Value = snippet.Snippet
}
- ).ToList();
+ orderby option.Name
+ select option;
+
+ return query.ToList();
}
}
}
\ No newline at end of file
diff --git a/TabletBot.Discord/SlashCommands/UserSlashCommands.cs b/TabletBot.Discord/SlashCommands/UserSlashCommands.cs
index 9f713a6..e30c358 100644
--- a/TabletBot.Discord/SlashCommands/UserSlashCommands.cs
+++ b/TabletBot.Discord/SlashCommands/UserSlashCommands.cs
@@ -1,4 +1,3 @@
-using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Discord;
diff --git a/TabletBot.Discord/Watchers/Commands/CommandMessageWatcher.cs b/TabletBot.Discord/Watchers/Commands/CommandMessageWatcher.cs
index 855d0f1..5bf78fe 100644
--- a/TabletBot.Discord/Watchers/Commands/CommandMessageWatcher.cs
+++ b/TabletBot.Discord/Watchers/Commands/CommandMessageWatcher.cs
@@ -5,7 +5,6 @@
using Discord.Commands;
using Discord.WebSocket;
using TabletBot.Common;
-using TabletBot.Discord.Commands;
namespace TabletBot.Discord.Watchers.Commands
{
@@ -88,7 +87,7 @@ private async Task CommandExecuted(Optional cmdInfo, ICommandContex
_ => await context.Channel.SendMessageAsync($"Error: {result.ErrorReason}")
};
- DiscordExtensions.DeleteAllDelayed(_settings.DeleteDelay, context.Message, msg);
+ DiscordExtensions.DeleteAllDelayed(5000, context.Message, msg);
}
}
}
diff --git a/TabletBot.Discord/Watchers/ReactionRoles/RoleReactionWatcher.cs b/TabletBot.Discord/Watchers/ReactionRoles/RoleReactionWatcher.cs
index 08db957..c49af29 100644
--- a/TabletBot.Discord/Watchers/ReactionRoles/RoleReactionWatcher.cs
+++ b/TabletBot.Discord/Watchers/ReactionRoles/RoleReactionWatcher.cs
@@ -5,7 +5,6 @@
using Discord.WebSocket;
using TabletBot.Common;
using TabletBot.Common.Store;
-using TabletBot.Discord.Commands;
using static TabletBot.Discord.DiscordExtensions;
namespace TabletBot.Discord.Watchers.ReactionRoles
@@ -48,8 +47,7 @@ private async Task HandleReactionAdded(ITextChannel channel, SocketReaction reac
catch (Exception ex)
{
var systemChannel = await channel.Guild.GetSystemChannelAsync();
- var reply = await ReplyException(systemChannel ?? channel, ex);
- reply.DeleteDelayed(_settings.DeleteDelay);
+ await ReplyException(systemChannel ?? channel, ex);
Log.Exception(ex);
}
}
@@ -69,8 +67,7 @@ private async Task HandleReactionRemoved(ITextChannel channel, SocketReaction re
catch (Exception ex)
{
var systemChannel = await channel.Guild.GetSystemChannelAsync();
- var reply = await ReplyException(systemChannel ?? channel, ex);
- reply.DeleteDelayed(_settings.DeleteDelay);
+ await ReplyException(systemChannel ?? channel, ex);
Log.Exception(ex);
}
}
diff --git a/TabletBot.Discord/Watchers/Spam/SpamMessageList.cs b/TabletBot.Discord/Watchers/Spam/SpamMessageList.cs
index 48fc1db..384e1c3 100644
--- a/TabletBot.Discord/Watchers/Spam/SpamMessageList.cs
+++ b/TabletBot.Discord/Watchers/Spam/SpamMessageList.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using Discord;
-using TabletBot.Common;
#nullable enable
diff --git a/TabletBot/Box.cs b/TabletBot/Box.cs
index 76705a2..a857979 100644
--- a/TabletBot/Box.cs
+++ b/TabletBot/Box.cs
@@ -1,6 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
namespace TabletBot
{
diff --git a/TabletBot/Tools.cs b/TabletBot/Tools.cs
index 3def1b2..7fce7c1 100644
--- a/TabletBot/Tools.cs
+++ b/TabletBot/Tools.cs
@@ -1,6 +1,4 @@
using System.Linq;
-using TabletBot.Common;
-using TabletBot.Discord;
namespace TabletBot
{
diff --git a/deps.nix b/deps.nix
index cb117d6..eb60228 100644
--- a/deps.nix
+++ b/deps.nix
@@ -6,6 +6,7 @@
(fetchNuGet { pname = "Discord.Net.Labs.Rest"; version = "3.6.1"; sha256 = "1097f3n3pv893lp5v86n90jcig9i5gi24s5z9726xvxqvyasjv2q"; })
(fetchNuGet { pname = "Discord.Net.Labs.Webhook"; version = "3.6.1"; sha256 = "1g5hdx37mfygb9j5m7wwf9d2l52kqilaxvsv8j605yhily56vy8n"; })
(fetchNuGet { pname = "Discord.Net.Labs.WebSocket"; version = "3.6.1"; sha256 = "1igl11l7jp742mqrzlxkamv6x0hzpwclkbn96cwwljx2yqyx2z7k"; })
+ (fetchNuGet { pname = "JetBrains.Annotations"; version = "2021.3.0"; sha256 = "01ssylllbwpana2w3iybi533zlvcsbhzjc8kr0g4kg307kjbfn8v"; })
(fetchNuGet { pname = "Microsoft.AspNetCore.App.Ref"; version = "5.0.0"; sha256 = "0d7sjr89zwq0wxirf8la05hfalv9nhvlczg1c7a508k8aw79jvfg"; })
(fetchNuGet { pname = "Microsoft.CSharp"; version = "4.4.1"; sha256 = "0z6d1i6xcf0c00z6rs75rgw4ncs9q2m8amasf6mmbf40fm02ry7g"; })
(fetchNuGet { pname = "Microsoft.Extensions.DependencyInjection"; version = "6.0.0"; sha256 = "1wlhb2vygzfdjbdzy7waxblmrx0q3pdcqvpapnpmq9fcx5m8r6w1"; })