mirror of
https://github.com/RPCS3/discord-bot.git
synced 2026-01-31 01:25:22 +01:00
fix channel mention on adding a new warning
This commit is contained in:
committed by
Roberto Anić Banić
parent
14462d7bed
commit
a1ecb592dc
@@ -40,7 +40,7 @@ namespace CompatBot.Commands
|
||||
}
|
||||
}
|
||||
await BotDb.Instance.SaveChangesAsync().ConfigureAwait(false);
|
||||
ctx.RespondAsync($"Fixed {@fixed} records").ConfigureAwait(false);
|
||||
await ctx.RespondAsync($"Fixed {@fixed} records").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -58,33 +58,16 @@ namespace CompatBot.Commands
|
||||
{
|
||||
var @fixed = 0;
|
||||
foreach (var warning in BotDb.Instance.Warning)
|
||||
if (!string.IsNullOrEmpty(warning.Reason) && warning.Reason.Contains('#'))
|
||||
{
|
||||
var newReason = await FixChannelMentionAsync(ctx, warning.Reason).ConfigureAwait(false);
|
||||
if (newReason != warning.Reason)
|
||||
{
|
||||
var reasonParts = warning.Reason.Split(' ');
|
||||
var rebuiltMsg = new List<string>(reasonParts.Length);
|
||||
var changed = false;
|
||||
foreach (var p in reasonParts)
|
||||
{
|
||||
if (p.Contains('#'))
|
||||
{
|
||||
var ch = await new CustomDiscordChannelConverter().ConvertAsync(p, ctx).ConfigureAwait(false);
|
||||
if (ch.HasValue)
|
||||
{
|
||||
rebuiltMsg.Add("#" + ch.Value.Name);
|
||||
changed = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
rebuiltMsg.Add(p);
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
warning.Reason = string.Join(' ', rebuiltMsg);
|
||||
@fixed++;
|
||||
}
|
||||
warning.Reason = newReason;
|
||||
@fixed++;
|
||||
}
|
||||
}
|
||||
await BotDb.Instance.SaveChangesAsync().ConfigureAwait(false);
|
||||
ctx.RespondAsync($"Fixed {@fixed} records").ConfigureAwait(false);
|
||||
await ctx.RespondAsync($"Fixed {@fixed} records").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -92,6 +75,33 @@ namespace CompatBot.Commands
|
||||
await ctx.RespondAsync("Failed to fix warning timestamps").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<string> FixChannelMentionAsync(CommandContext ctx, string msg)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(msg) && msg.Contains('#'))
|
||||
{
|
||||
var reasonParts = msg.Split(' ');
|
||||
var rebuiltMsg = new List<string>(reasonParts.Length);
|
||||
var changed = false;
|
||||
foreach (var p in reasonParts)
|
||||
{
|
||||
if (p.Contains('#'))
|
||||
{
|
||||
var ch = await new CustomDiscordChannelConverter().ConvertAsync(p, ctx).ConfigureAwait(false);
|
||||
if (ch.HasValue)
|
||||
{
|
||||
rebuiltMsg.Add("#" + ch.Value.Name);
|
||||
changed = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
rebuiltMsg.Add(p);
|
||||
}
|
||||
if (changed)
|
||||
return string.Join(' ', rebuiltMsg);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace CompatBot.Commands
|
||||
return;
|
||||
|
||||
var typingTask = ctx.TriggerTypingAsync();
|
||||
if (await AddAsync(ctx.Client, ctx.Message, user.Id, user.Username.Sanitize(), ctx.Message.Author, reason).ConfigureAwait(false))
|
||||
if (await AddAsync(ctx, user.Id, user.Username.Sanitize(), ctx.Message.Author, reason).ConfigureAwait(false))
|
||||
await ctx.Message.CreateReactionAsync(Config.Reactions.Success).ConfigureAwait(false);
|
||||
else
|
||||
await ctx.Message.CreateReactionAsync(Config.Reactions.Failure).ConfigureAwait(false);
|
||||
@@ -41,7 +41,7 @@ namespace CompatBot.Commands
|
||||
return;
|
||||
|
||||
var typingTask = ctx.TriggerTypingAsync();
|
||||
if (await AddAsync(ctx.Client, ctx.Message, userId, $"<@{userId}>", ctx.Message.Author, reason).ConfigureAwait(false))
|
||||
if (await AddAsync(ctx, userId, $"<@{userId}>", ctx.Message.Author, reason).ConfigureAwait(false))
|
||||
await ctx.Message.CreateReactionAsync(Config.Reactions.Success).ConfigureAwait(false);
|
||||
else
|
||||
await ctx.Message.CreateReactionAsync(Config.Reactions.Failure).ConfigureAwait(false);
|
||||
@@ -96,6 +96,12 @@ namespace CompatBot.Commands
|
||||
|
||||
}
|
||||
|
||||
internal static async Task<bool> AddAsync(CommandContext ctx, ulong userId, string userName, DiscordUser issuer, string reason, string fullReason = null)
|
||||
{
|
||||
reason = await Sudo.Fix.FixChannelMentionAsync(ctx, reason).ConfigureAwait(false);
|
||||
return await AddAsync(ctx.Client, ctx.Message, userId, userName, issuer, reason, fullReason);
|
||||
}
|
||||
|
||||
internal static async Task<bool> AddAsync(DiscordClient client, DiscordMessage message, ulong userId, string userName, DiscordUser issuer, string reason, string fullReason = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(reason))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CompatApiClient;
|
||||
using CompatBot.Commands;
|
||||
using CompatBot.Providers;
|
||||
using CompatBot.Utils;
|
||||
@@ -50,7 +51,7 @@ namespace CompatBot.EventHandlers
|
||||
await Task.WhenAll(
|
||||
message.Channel.SendMessageAsync($"{message.Author.Mention} Please follow the {rules.Mention} and do not discuss piracy on this server. Repeated offence may result in a ban."),
|
||||
client.ReportAsync("Mention of piracy", message, trigger, message.Content, needsAttention),
|
||||
Warnings.AddAsync(client, message, message.Author.Id, message.Author.Username, client.CurrentUser, "Mention of piracy", message.Content)
|
||||
Warnings.AddAsync(client, message, message.Author.Id, message.Author.Username, client.CurrentUser, "Mention of piracy", message.Content.Sanitize())
|
||||
).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.IO.Pipelines;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CompatApiClient;
|
||||
using CompatBot.Commands;
|
||||
using CompatBot.LogParsing;
|
||||
using CompatBot.LogParsing.SourceHandlers;
|
||||
@@ -69,7 +70,7 @@ namespace CompatBot.EventHandlers
|
||||
await Task.WhenAll(
|
||||
args.Client.ReportAsync("Pirated Release", args.Message, result.PiracyTrigger, result.PiracyContext, needsAttention),
|
||||
Warnings.AddAsync(args.Client, args.Message, args.Message.Author.Id, args.Message.Author.Username, args.Client.CurrentUser,
|
||||
"Pirated Release", $"{message.CreationTimestamp:O} - {message.Content} - {result.PiracyTrigger}")
|
||||
"Pirated Release", $"{message.Content.Sanitize()} - {result.PiracyTrigger}")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user