Skip to content

Commit

Permalink
possibly fix webhook stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mk committed Sep 23, 2024
1 parent aa784a8 commit 02ab0b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/FMBot.Bot/Services/Guild/WebhookService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Diagnostics.Eventing.Reader;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
Expand Down Expand Up @@ -97,10 +97,10 @@ public async Task<Webhook> CreateWebhook(ICommandContext context, int guildId)

public async Task<bool> TestWebhook(Webhook webhook, string text)
{
var webhookClient = new DiscordWebhookClient(webhook.DiscordWebhookId, webhook.Token);

try
{
var webhookClient = new DiscordWebhookClient(webhook.DiscordWebhookId, webhook.Token);

await webhookClient.SendMessageAsync(text, threadId: webhook.DiscordThreadId);

return true;
Expand All @@ -123,6 +123,10 @@ public async Task<bool> TestWebhook(Webhook webhook, string text)

return false;
}
finally
{
webhookClient.Dispose();
}
}

public async Task SendFeaturedWebhooks(FeaturedLog featured)
Expand All @@ -136,10 +140,14 @@ public async Task SendFeaturedWebhooks(FeaturedLog featured)
.AsQueryable()
.ToListAsync();

var tasks = new List<Task>();
foreach (var webhook in webhooks)
{
await SendWebhookEmbed(webhook, embed, featured.UserId);
tasks.Add(SendWebhookEmbed(webhook, embed, featured.UserId));
}

Log.Information("SendFeaturedWebhooks: Sending {webhookCount} featured webhooks", webhooks.Count);
await Task.WhenAll(tasks);
}

public async Task SendFeaturedPreview(FeaturedLog featured, string webhook)
Expand Down
2 changes: 0 additions & 2 deletions src/FMBot.Bot/TextCommands/Guild/WebhookCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ await ReplyAsync(
return;
}

var type = socketCommandContext.Channel.GetChannelType();

var createdWebhook = await this._webhookService.CreateWebhook(this.Context, guild.GuildId);

await this._webhookService.TestWebhook(createdWebhook, "If you see this message the webhook has been successfully added!\n\n" +
Expand Down

0 comments on commit 02ab0b5

Please sign in to comment.