Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: buffer message sends #66

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Plogon/DiscordWebhook.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using Discord;
Expand Down Expand Up @@ -65,4 +66,26 @@

return await this.Client.SendMessageAsync(embeds: new[] { embed }, username: username, avatarUrl: avatarUrl);
}

public async Task SendSplitting(Color color, string message, string title, string footer)

Check warning on line 70 in Plogon/DiscordWebhook.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DiscordWebhook.SendSplitting(Color, string, string, string)'

Check warning on line 70 in Plogon/DiscordWebhook.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DiscordWebhook.SendSplitting(Color, string, string, string)'
{
var messages = new List<string>();

var buffer = "";
foreach (var part in message.Split("\n"))
{
if (buffer.Length + part.Length > 2000)
{
messages.Add(buffer);
buffer = "";
}

buffer += part + "\n";
}

foreach (var body in messages)
{
await this.Send(color, body, title, footer);
}
}
}
4 changes: 2 additions & 2 deletions Plogon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ string ReplaceDiscordEmotes(string text)
$"{ReplaceDiscordEmotes(buildsMd.GetText(true, true))}\n\n[Show log](https://github.com/goatcorp/DalamudPluginsD17/actions/runs/{actionRunId})";
var committedColor = !anyFailed ? Color.Green : Color.Red;
var committedTitle = "Builds committed";
await publicChannelWebhook.Send(committedColor, committedText, committedTitle, string.Empty);
await pacChannelWebhook.Send(committedColor, committedText, committedTitle, string.Empty);
await publicChannelWebhook.SendSplitting(committedColor, committedText, committedTitle, string.Empty);
await pacChannelWebhook.SendSplitting(committedColor, committedText, committedTitle, string.Empty);

// TODO: We don't support this for removals for now
foreach (var buildResult in statuses.Where(x => x.Task.Type == BuildTask.TaskType.Build))
Expand Down
Loading