Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mk committed Sep 24, 2024
2 parents b34e64a + fc268f6 commit c19917e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 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
3 changes: 2 additions & 1 deletion src/FMBot.Bot/Services/TimerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,13 @@ public async Task CheckForNewFeatured()

await this._webhookService.PostFeatured(newFeatured, this._client);
await this._featuredService.SetFeatured(newFeatured);
await this._webhookService.SendFeaturedWebhooks(newFeatured);

if (newFeatured.FeaturedMode == FeaturedMode.RecentPlays)
{
await this._featuredService.ScrobbleTrack(this._client.CurrentUser.Id, newFeatured);
}

_ = this._webhookService.SendFeaturedWebhooks(newFeatured);
}

Log.Information($"{nameof(CheckForNewFeatured)}: Setting new featured in bot");
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 c19917e

Please sign in to comment.