aboutsummaryrefslogtreecommitdiff
path: root/Handlers/DiscordHandler.cs
diff options
context:
space:
mode:
authorJake Mannens <jake@asger.xyz>2024-10-18 14:51:26 +1100
committerJake Mannens <jake@asger.xyz>2024-10-29 11:42:54 +1100
commit09ade38700ae3795c47826cf4c80c65f9c3338f3 (patch)
tree2bc877d130f70a89cc891fb18e034e00a337478a /Handlers/DiscordHandler.cs
parente8e3c4cba8ffa0056e984c113cfbb75319e00022 (diff)
Diffstat (limited to 'Handlers/DiscordHandler.cs')
-rw-r--r--Handlers/DiscordHandler.cs91
1 files changed, 55 insertions, 36 deletions
diff --git a/Handlers/DiscordHandler.cs b/Handlers/DiscordHandler.cs
index ae948c5..461aac4 100644
--- a/Handlers/DiscordHandler.cs
+++ b/Handlers/DiscordHandler.cs
@@ -15,7 +15,7 @@ namespace PagerParser {
namespace PagerParser.Handlers {
[PagerHandler]
- public class DiscordHandler : IPagerHandler {
+ internal class DiscordHandler : IPagerHandler {
// TODO: consolidate this with the map used by TTS
private readonly Dictionary<string, string> IncidentTypes = new() {
{ "ALAR", "FIRE ALARM" },
@@ -86,7 +86,7 @@ namespace PagerParser.Handlers {
},
new() {
Name = "brigade",
- Description = "Paged brigade/appliance to match (e.g. CBERW, P88, etc)",
+ Description = "Paged brigade/appliance to match (e.g. BERW, FS88, etc)",
Type = ApplicationCommandOptionType.String,
IsRequired = true
}
@@ -106,7 +106,7 @@ namespace PagerParser.Handlers {
},
new() {
Name = "brigade",
- Description = "Paged brigade/appliance to match (e.g. CBERW, P88, etc)",
+ Description = "Paged brigade/appliance to match (e.g. BERW, FS88, etc)",
Type = ApplicationCommandOptionType.String,
IsRequired = true
}
@@ -197,6 +197,7 @@ namespace PagerParser.Handlers {
// Get a list of alert groups matching the page we've just received
var subscriptions = db.DiscordAlertSubscriptions
+ .Where(s => s.GuildId == guild.Id)
.Where(s => pagedServices.Contains(s.PageDestination))
.ToArray();
@@ -263,12 +264,14 @@ namespace PagerParser.Handlers {
if(alertChannel is null) {
await command.RespondAsync(
- "No alert channel has been configured for this server!");
+ ephemeral: true,
+ text: "No alert channel has been configured for this server!");
return;
}
await command.RespondAsync(
- string.Join(' ', [
+ ephemeral: true,
+ text: string.Join(' ', [
$"The configured alert channel for this server is",
$"<#{alertChannel.ChannelId}>",
alertChannel.RequireMention ? null : "(all messages will be sent)"
@@ -290,7 +293,8 @@ namespace PagerParser.Handlers {
// text channel and not a channel category.
if(command.Data.Options.First().Value is not SocketTextChannel) {
await command.RespondAsync(
- "Error: Pager message notifications can only be posted to text channels");
+ ephemeral: true,
+ text: "Error: Pager message notifications can only be posted to text channels");
return;
}
@@ -316,7 +320,8 @@ namespace PagerParser.Handlers {
await db.Database.CommitTransactionAsync();
await command.RespondAsync(
- string.Join(' ', [
+ ephemeral: true,
+ text: string.Join(' ', [
"The alert channel for this server has been set to",
$"<#{channel.Id}>",
requireMention ? null : "(all messages will be sent)"
@@ -333,7 +338,9 @@ namespace PagerParser.Handlers {
.FirstOrDefaultAsync(c => c.GuildId == command.GuildId);
if(alertChannel is null) {
- await command.RespondAsync("No alert channel was configured for this server!");
+ await command.RespondAsync(
+ ephemeral: true,
+ text: "No alert channel was configured for this server!");
return;
}
@@ -343,7 +350,8 @@ namespace PagerParser.Handlers {
await db.Database.CommitTransactionAsync();
await command.RespondAsync(
- $"Removed the configured alert channel for this server");
+ ephemeral: true,
+ text: $"Removed the configured alert channel for this server");
}
private async Task OnSubscribeChannelCommand(SocketSlashCommand command) {
@@ -380,12 +388,14 @@ namespace PagerParser.Handlers {
.Any();
if(exists) {
- await command.RespondAsync(string.Join(' ', [
- mention,
- subscription.PrincipalType == DiscordPrincipalType.User ? "is" : "are",
- "already subscribed to pager messages for",
- $"`{subscription.PageDestination}`"
- ]));
+ await command.RespondAsync(
+ ephemeral: true,
+ text: string.Join(' ', [
+ mention,
+ subscription.PrincipalType == DiscordPrincipalType.User ? "is" : "are",
+ "already subscribed to pager messages for",
+ $"`{subscription.PageDestination}`"
+ ]));
return;
}
@@ -393,12 +403,14 @@ namespace PagerParser.Handlers {
await db.SaveChangesAsync();
await db.Database.CommitTransactionAsync();
- await command.RespondAsync(string.Join(' ', [
- "Subscribed",
- $"<@{subscription.PrincipalId}>",
- "to pager messages for",
- $"`{subscription.PageDestination}`"
- ]));
+ await command.RespondAsync(
+ ephemeral: true,
+ text: string.Join(' ', [
+ "Subscribed",
+ $"<@{subscription.PrincipalId}>",
+ "to pager messages for",
+ $"`{subscription.PageDestination}`"
+ ]));
}
private async Task OnUnsubscribeChannelCommand(SocketSlashCommand command) {
@@ -434,12 +446,14 @@ namespace PagerParser.Handlers {
.Where(s => s.PageDestination == subscription.PageDestination);
if(!existing.Any()) {
- await command.RespondAsync(string.Join(' ', [
- mention,
- subscription.PrincipalType == DiscordPrincipalType.User ? "was" : "are",
- "not subscribed to pager messages for",
- $"`{subscription.PageDestination}`"
- ]));
+ await command.RespondAsync(
+ ephemeral: true,
+ text: string.Join(' ', [
+ mention,
+ subscription.PrincipalType == DiscordPrincipalType.User ? "was" : "are",
+ "not subscribed to pager messages for",
+ $"`{subscription.PageDestination}`"
+ ]));
return;
}
@@ -447,12 +461,14 @@ namespace PagerParser.Handlers {
await db.SaveChangesAsync();
await db.Database.CommitTransactionAsync();
- await command.RespondAsync(string.Join(' ', [
- "Unsubscribed",
- $"<@{subscription.PrincipalId}>",
- "from pager messages for",
- $"`{subscription.PageDestination}`"
- ]));
+ await command.RespondAsync(
+ ephemeral: true,
+ text: string.Join(' ', [
+ "Unsubscribed",
+ $"<@{subscription.PrincipalId}>",
+ "from pager messages for",
+ $"`{subscription.PageDestination}`"
+ ]));
}
private async Task OnListSubscriptionsCommand(SocketSlashCommand command) {
@@ -492,12 +508,14 @@ namespace PagerParser.Handlers {
if(subscriptions.Count() == 0) {
await command.RespondAsync(
- $"{mention} not subscribed to any pager messages");
+ ephemeral: true,
+ text: $"{mention} not subscribed to any pager messages");
return;
}
await command.RespondAsync(
- string.Join(
+ ephemeral: true,
+ text: string.Join(
"\n - ",
Enumerable.Concat(
[ $"{mention} subscribed to pager messages for the following brigades/appliances:" ],
@@ -527,7 +545,8 @@ namespace PagerParser.Handlers {
]));
try {
await command.RespondAsync(
- string.Join(' ', [
+ ephemeral: true,
+ text: string.Join(' ', [
"An unknown error occurred whilst attempting to execute the command.",
"Error reference:",
$"`{reference}`"