Skip to content

Commit

Permalink
Fix voice alert timoute
Browse files Browse the repository at this point in the history
  • Loading branch information
Plerx2493 committed Feb 23, 2024
1 parent 9a4c75d commit ec724ae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ModularAssistentForDiscordServer/Commands/Slash/Purge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public async Task PurgeMessages

await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource,
new DiscordInteractionResponseBuilder());
var response = await ctx.GetOriginalResponseAsync();
DiscordMessage response = await ctx.GetOriginalResponseAsync();

List<DiscordMessage> messages = [];
await foreach (var msg in ctx.Channel.GetMessagesAsync((int) amount))
await foreach (DiscordMessage msg in ctx.Channel.GetMessagesAsync((int) amount))
{
messages.Add(msg);
}
Expand Down
22 changes: 13 additions & 9 deletions ModularAssistentForDiscordServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ public static async Task Main()
.CreateLogger();

//Create cancellationToken and hook the cancelKey
var cancellationSource = new CancellationTokenSource();
CancellationTokenSource cancellationSource = new CancellationTokenSource();
Console.CancelKeyPress += async (_, args) =>
{
args.Cancel = true;
await cancellationSource.CancelAsync();
};

//retrieves the config.json
var config = DataProvider.GetConfig();
MadsConfig config = DataProvider.GetConfig();

//Create a discordWebhookClient and add the debug webhook from the config.json
WebhookClient = new DiscordWebhookClient();
var webhookUrl = new Uri(config.DiscordWebhook);
Uri webhookUrl = new Uri(config.DiscordWebhook);
await WebhookClient.AddWebhookAsync(webhookUrl);

//Create a new instance of the bot
Expand All @@ -62,9 +62,13 @@ public static async Task Main()
}
catch (Exception e)
{
if (e is TaskCanceledException) return;
if (e is TaskCanceledException)
{
return;
}

Log.Error(e, "An uncaught exception occurred");
var _ = LogToWebhookAsync(e);
Task _ = LogToWebhookAsync(e);
Environment.Exit(69);
}

Expand All @@ -73,14 +77,14 @@ public static async Task Main()

public static async Task LogToWebhookAsync(Exception e)
{
var exceptionEmbed = new DiscordEmbedBuilder()
DiscordEmbedBuilder exceptionEmbed = new DiscordEmbedBuilder()
.WithAuthor("Mads-Debug")
.WithColor(DiscordColor.Red)
.WithTimestamp(DateTime.UtcNow)
.WithTitle($"Ooopsie... {e.GetType()}")
.WithDescription(e.Message);

var webhookBuilder = new DiscordWebhookBuilder()
DiscordWebhookBuilder webhookBuilder = new DiscordWebhookBuilder()
.WithUsername("Mads-Debug")
.AddEmbed(exceptionEmbed);

Expand All @@ -90,8 +94,8 @@ public static async Task LogToWebhookAsync(Exception e)
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = "EFCore CLI tools rely on reflection.")]
public static IHostBuilder CreateHostBuilder(string[] args)
{
var builder = Host.CreateDefaultBuilder(args);
var config = DataProvider.GetConfig();
IHostBuilder builder = Host.CreateDefaultBuilder(args);
MadsConfig config = DataProvider.GetConfig();

builder.ConfigureServices((_, services) => services.AddDbContextFactory<MadsContext>(
options => options.UseMySql(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class VoiceAlertService : IHostedService
private readonly IDbContextFactory<MadsContext> _contextFactory;
private readonly DiscordClient _discordClient;

private static ILogger _logger = Log.ForContext<VoiceAlertService>();
private static readonly ILogger _logger = Log.ForContext<VoiceAlertService>();

public VoiceAlertService(IDbContextFactory<MadsContext> contextFactory, DiscordClientService discordClientService)
{
Expand Down Expand Up @@ -90,7 +90,7 @@ public async Task HandleEvent(DiscordClient client, VoiceStateUpdateEventArgs e)
continue;
}

if (alert.MinTimeBetweenAlerts is null)
if (alert.MinTimeBetweenAlerts is not null)
{
if (alert.LastAlert is not null && alert.LastAlert + alert.MinTimeBetweenAlerts > DateTimeOffset.UtcNow)
{
Expand Down

0 comments on commit ec724ae

Please sign in to comment.