mirror of
https://github.com/RPCS3/discord-bot.git
synced 2026-01-31 01:25:22 +01:00
Merge branch 'vnext'
This commit is contained in:
@@ -202,7 +202,7 @@ internal static class Fortune
|
||||
do
|
||||
{
|
||||
var totalFortunes = await db.Fortune.CountAsync().ConfigureAwait(false);
|
||||
if (totalFortunes == 0)
|
||||
if (totalFortunes is 0)
|
||||
return null;
|
||||
|
||||
var selectedId = rng.Next(totalFortunes);
|
||||
@@ -214,7 +214,7 @@ internal static class Fortune
|
||||
foreach (var l in fortune.Content.FixTypography().Split('\n'))
|
||||
{
|
||||
var fixedLine = l.Replace("\t", " ");
|
||||
quote &= !fixedLine.StartsWith(" ");
|
||||
//quote &= !fixedLine.StartsWith(" ");
|
||||
var trimmed = fixedLine.TrimStart(' ');
|
||||
quote &= trimmed is { Length: 0 } || trimmed[0] is not '-' and not '–' and not '—';
|
||||
if (quote)
|
||||
@@ -222,8 +222,8 @@ internal static class Fortune
|
||||
tmp.Append(l).Append('\n');
|
||||
}
|
||||
return $"""
|
||||
{user.Mention}, your fortune for today:
|
||||
{tmp.ToString().TrimEnd().FixSpaces()}
|
||||
""";
|
||||
{user.Mention}, your fortune for today:
|
||||
{tmp.ToString().TrimEnd().FixSpaces()}
|
||||
""";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,10 +249,10 @@ internal static class ContentFilter
|
||||
|
||||
if (trigger.Actions.HasFlag(FilterAction.ShowExplain)
|
||||
&& !ignoreFlags.HasFlag(FilterAction.ShowExplain)
|
||||
&& !string.IsNullOrEmpty(trigger.ExplainTerm))
|
||||
&& trigger.ExplainTerm is { Length: >0 } term)
|
||||
{
|
||||
var result = await Explain.LookupTerm(trigger.ExplainTerm).ConfigureAwait(false);
|
||||
await Explain.SendExplanationAsync(result, trigger.ExplainTerm, message, true).ConfigureAwait(false);
|
||||
var result = await Explain.LookupTerm(term).ConfigureAwait(false);
|
||||
await Explain.SendExplanationAsync(result, term, message, true).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (trigger.Actions.HasFlag(FilterAction.Kick)
|
||||
|
||||
@@ -118,27 +118,7 @@ public static class DiscordClientExtensions
|
||||
if (!string.IsNullOrEmpty(context))
|
||||
reportText += $"Triggered in: ```{context.Sanitize()}```{Environment.NewLine}";
|
||||
embedBuilder.Description = reportText + embedBuilder.Description;
|
||||
var (contents, _) = await message.DownloadAttachmentsAsync().ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
if (contents?.Count > 0)
|
||||
return await logChannel.SendMessageAsync(
|
||||
new DiscordMessageBuilder()
|
||||
.AddEmbed(embedBuilder.Build())
|
||||
.AddFiles(contents)
|
||||
).ConfigureAwait(false);
|
||||
else
|
||||
return await logChannel.SendMessageAsync(
|
||||
new DiscordMessageBuilder()
|
||||
.AddEmbed(embedBuilder.Build())
|
||||
).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (contents?.Count > 0)
|
||||
foreach (var f in contents.Values)
|
||||
await f.DisposeAsync();
|
||||
}
|
||||
return await logChannel.SendMessageAsync(new DiscordMessageBuilder().AddEmbed(embedBuilder.Build())).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static async ValueTask<DiscordMessage> ReportAsync(this DiscordClient client, string infraction, DiscordMessage message, IEnumerable<DiscordMember?> reporters, string? comment, ReportSeverity severity)
|
||||
|
||||
@@ -64,37 +64,4 @@ public static class DiscordMessageExtensions
|
||||
msgBuilder.WithReply(refMsg.Id);
|
||||
return botMsg.UpdateOrCreateMessageAsync(channel, msgBuilder);
|
||||
}
|
||||
|
||||
public static async Task<(Dictionary<string, Stream>? attachmentContent, List<string>? failedFilenames)> DownloadAttachmentsAsync(this DiscordMessage msg)
|
||||
{
|
||||
if (msg.Attachments.Count == 0)
|
||||
return (null, null);
|
||||
|
||||
var attachmentContent = new Dictionary<string, Stream>(msg.Attachments.Count);
|
||||
var attachmentFilenames = new List<string>();
|
||||
using var httpClient = HttpClientFactory.Create(new CompressionMessageHandler());
|
||||
foreach (var att in msg.Attachments)
|
||||
{
|
||||
if (att.FileSize > msg.Channel.Guild.GetAttachmentSizeLimit())
|
||||
{
|
||||
attachmentFilenames.Add(att.FileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await using var sourceStream = await httpClient.GetStreamAsync(att.Url).ConfigureAwait(false);
|
||||
var fileStream = new FileStream(Path.GetTempFileName(), FileMode.Create, FileAccess.ReadWrite, FileShare.Read, 16384, FileOptions.Asynchronous | FileOptions.RandomAccess | FileOptions.DeleteOnClose);
|
||||
await sourceStream.CopyToAsync(fileStream, 16384, Config.Cts.Token).ConfigureAwait(false);
|
||||
fileStream.Seek(0, SeekOrigin.Begin);
|
||||
attachmentContent[att.FileName] = fileStream;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Config.Log.Warn(ex, $"Failed to download attachment {att.FileName} from deleted message {msg.JumpLink}");
|
||||
attachmentFilenames.Add(att.FileName);
|
||||
}
|
||||
}
|
||||
return (attachmentContent: attachmentContent, failedFilenames: attachmentFilenames);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user