aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.mdbin2764 -> 3462 bytes
-rw-r--r--Handlers/DiscordHandler.cs91
-rw-r--r--Handlers/HomeAssistantHandler.cs4
-rw-r--r--PagerFetchService.cs18
-rw-r--r--PagerHandler.cs14
-rw-r--r--PagerMessage.cs2
-rw-r--r--PagerParser.csproj2
-rw-r--r--PositionCalculator.cs4
-rw-r--r--Sites/PagerMon.cs4
-rw-r--r--appsettings.json18
10 files changed, 81 insertions, 76 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dc92823..d143062 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
Binary files differ
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}`"
diff --git a/Handlers/HomeAssistantHandler.cs b/Handlers/HomeAssistantHandler.cs
index bf914c3..8a56292 100644
--- a/Handlers/HomeAssistantHandler.cs
+++ b/Handlers/HomeAssistantHandler.cs
@@ -3,7 +3,7 @@
namespace PagerParser.Handlers;
[PagerHandler]
-public class HomeAssistantHandler : IPagerHandler {
+internal class HomeAssistantHandler : IPagerHandler {
private List<HomeAssistantConfig> haConfigs = new();
private ILogger logger;
@@ -46,7 +46,7 @@ public class HomeAssistantHandler : IPagerHandler {
return Task.CompletedTask;
}
- public class HomeAssistantConfig {
+ private class HomeAssistantConfig {
public string Host { get; set; }
public string ApiKey { get; set; }
public string EventType { get; set; } = "cfa_pager_message";
diff --git a/PagerFetchService.cs b/PagerFetchService.cs
index aa014a3..f823ffd 100644
--- a/PagerFetchService.cs
+++ b/PagerFetchService.cs
@@ -3,13 +3,13 @@ using System.Text.RegularExpressions;
namespace PagerParser;
-public class PagerMessageEventArgs : EventArgs {
- public PagerMessage Message { get; init; }
+internal class PagerMessageEventArgs : EventArgs {
+ internal PagerMessage Message { get; init; }
}
-public delegate void PagerMessageHandler(object sender, PagerMessageEventArgs e);
+internal delegate void PagerMessageHandler(object sender, PagerMessageEventArgs e);
-public interface IPagerProvider {
+internal interface IPagerProvider {
public event EventHandler OnConnect;
public event EventHandler<string> OnDisconnect;
public event PagerMessageHandler OnPagerMessage;
@@ -21,7 +21,7 @@ public interface IPagerProvider {
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
-public class PagerProviderAttribute : Attribute {}
+internal class PagerProviderAttribute : Attribute {}
public class PagerFetchService : IHostedService {
private readonly TimeSpan FetchInterval = TimeSpan.FromMinutes(1);
@@ -138,7 +138,7 @@ public class PagerFetchService : IHostedService {
db.SaveChanges();
}
- public async Task FetchAsync() {
+ private async Task FetchAsync() {
await lastFetchLock.WaitAsync(cts.Token);
try {
var fetchUntil = lastFetch ?? LastPageTimestamp ?? DateTime.MinValue;
@@ -163,7 +163,7 @@ public class PagerFetchService : IHostedService {
}
}
- public void OnConnect(object? sender, EventArgs e) {
+ private void OnConnect(object? sender, EventArgs e) {
logger.LogInformation(
$"Connected to pager message provider {pagerProvider.GetType().Name}");
@@ -172,7 +172,7 @@ public class PagerFetchService : IHostedService {
fetchTimer.AutoReset = false;
}
- public async void OnDisconnect(object? sender, string e) {
+ private async void OnDisconnect(object? sender, string e) {
logger.LogInformation(
$"Disconnected from pager message provider {pagerProvider.GetType().Name}");
@@ -188,7 +188,7 @@ public class PagerFetchService : IHostedService {
fetchTimer.Start();
}
- public async void PagerMessageReceived(object sender, PagerMessageEventArgs e) {
+ private async void PagerMessageReceived(object sender, PagerMessageEventArgs e) {
logger.LogInformation($"PagerMessage: {e.Message.Message}");
AddMessages([ e.Message ]);
diff --git a/PagerHandler.cs b/PagerHandler.cs
index 8520064..19e92c5 100644
--- a/PagerHandler.cs
+++ b/PagerHandler.cs
@@ -3,18 +3,18 @@
namespace PagerParser;
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
-public class PagerHandlerAttribute : Attribute {}
+internal class PagerHandlerAttribute : Attribute {}
-public interface IPagerHandler {
- public void OnConfiguring(
+internal interface IPagerHandler {
+ internal void OnConfiguring(
ILogger logger,
IConfiguration config,
IServiceProvider serviceProvider);
- public Task StartAsync(CancellationToken ct);
- public Task StopAsync(CancellationToken ct);
+ internal Task StartAsync(CancellationToken ct);
+ internal Task StopAsync(CancellationToken ct);
- public Task HandleMessageAsync(
+ internal Task HandleMessageAsync(
PagerMessage message,
ParsedPagerMessage? parsedMessage);
}
@@ -35,7 +35,7 @@ public class RootPagerHandler : IRootPagerHandler, IHostedService {
.Where(t => t.IsClass)
.Where(t => t.IsAssignableTo(typeof(IPagerHandler)))
.Where(t => t.GetCustomAttributes<PagerHandlerAttribute>().Any())
- .Select(t => Activator.CreateInstance(t))
+ .Select(Activator.CreateInstance)
.Cast<IPagerHandler>()
.Select(h => new HandlerEntry(h))
.ToArray();
diff --git a/PagerMessage.cs b/PagerMessage.cs
index 765636c..23fdf66 100644
--- a/PagerMessage.cs
+++ b/PagerMessage.cs
@@ -82,7 +82,7 @@ public interface IPagerMessageParserService {
// Running a single instance of the service isn't an issue, as this
// service is only used by the fetch service for parsing new messages.
public class PagerMessageParserService : IPagerMessageParserService {
- public static readonly Dictionary<string, MapType> MapTypeMap = new() {
+ internal static readonly Dictionary<string, MapType> MapTypeMap = new() {
{ "M", MapType.Melways },
{ "SVC", MapType.SpacialVisionCentral },
{ "SVNE", MapType.SpacialVisionNorthEast },
diff --git a/PagerParser.csproj b/PagerParser.csproj
index 7a72caa..088f82e 100644
--- a/PagerParser.csproj
+++ b/PagerParser.csproj
@@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
- <Version>0.4-rc1</Version>
+ <Version>0.4-rc2</Version>
<UserSecretsId>77f0c394-8b38-418c-a13e-2dc7c57ff7b9</UserSecretsId>
</PropertyGroup>
diff --git a/PositionCalculator.cs b/PositionCalculator.cs
index 2140a88..f6fdbff 100644
--- a/PositionCalculator.cs
+++ b/PositionCalculator.cs
@@ -40,7 +40,7 @@ public record MelwaysPage {
// and grid number (e.g: 131 D7) by looking up the origin coordinates
// of the Melways page from a pre-defined table, then interpolating
// the grid number across the page to get a (very) rough position.
-public class PositionCalculator {
+internal class PositionCalculator {
private const float PageWidth = 0.0583403752108005f;
private const float PageHeight = 0.0444074086328539f;
@@ -72,7 +72,7 @@ public class PositionCalculator {
new MelwaysPage { PageNo = 317, Latitude = -38.0493097638301, Longitude = 145.464666307851 }
};
- public static GpsPosition? GetGpsPosition(ParsedPagerMessage message) {
+ internal static GpsPosition? GetGpsPosition(ParsedPagerMessage message) {
if(message.MapType != MapType.Melways)
return null;
if(message.MapNo is null || message.MapGrid is null)
diff --git a/Sites/PagerMon.cs b/Sites/PagerMon.cs
index 9dfd7df..dd8cb22 100644
--- a/Sites/PagerMon.cs
+++ b/Sites/PagerMon.cs
@@ -6,7 +6,7 @@ namespace PagerParser.PagerProviders;
// Interface class for fetching pager messages from PagerMon
// sites such as Jobyyy over HTTP.
[PagerProvider]
-public class PagerMon : IPagerProvider {
+internal class PagerMon : IPagerProvider {
private record PagerMonMessage {
public long Timestamp { get; set; }
public string Message { get; set; }
@@ -32,7 +32,7 @@ public class PagerMon : IPagerProvider {
private SocketIO socketIOClient;
- public PagerMon() {
+ internal PagerMon() {
socketIOClient = new SocketIO("https://jobyyy.net/", new SocketIOOptions() {
AutoUpgrade = false,
ConnectionTimeout = TimeSpan.FromMinutes(15),
diff --git a/appsettings.json b/appsettings.json
index e50ae14..00b7c95 100644
--- a/appsettings.json
+++ b/appsettings.json
@@ -8,22 +8,8 @@
"MessageExclude": [
// Regex patterns to exclude globally
]
- //"Discord": {
- // "Webhooks": [
- // {
- // "Url": "<webhook url>",
- // "AlertGroups": [
- // {
- // "PageDestinations": [
- // // List of destination brigades
- // ],
- // "Roles": [
- // // List of Discord role IDs
- // ]
- // }
- // ]
- // }
- // ]
+ //"DiscordBot": {
+ // "Token": "<bot token>"
//}
//"HomeAssistant": {
// "Servers": [