mirror of
https://github.com/RPCS3/discord-bot.git
synced 2026-01-31 01:25:22 +01:00
ability to mark update announcement as a bad update
This commit is contained in:
@@ -205,19 +205,6 @@ Example usage:
|
||||
}
|
||||
}
|
||||
|
||||
private static string DicToDesc(Dictionary<char, string[]> dictionary)
|
||||
{
|
||||
var result = new StringBuilder();
|
||||
foreach (var lst in dictionary.Values)
|
||||
result.AppendLine(string.Join(", ", lst.Reverse()));
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
private static string DicToDesc(Dictionary<string, int> dictionary)
|
||||
{
|
||||
return string.Join(", ", dictionary.Keys);
|
||||
}
|
||||
|
||||
private async Task DoRequestAndRespond(CommandContext ctx, RequestBuilder requestBuilder)
|
||||
{
|
||||
Config.Log.Info(requestBuilder.Build());
|
||||
|
||||
@@ -78,6 +78,60 @@ namespace CompatBot.Commands
|
||||
}
|
||||
}
|
||||
|
||||
[Command("badupdate"), Aliases("bad", "recall"), RequiresBotModRole]
|
||||
[Description("Toggles new update announcement as being bad")]
|
||||
public async Task BadUpdate(CommandContext ctx, [Description("Link to the update announcement")] string updateMessageLink)
|
||||
{
|
||||
var msg = await ctx.GetMessageAsync(updateMessageLink).ConfigureAwait(false);
|
||||
var embed = msg?.Embeds?.FirstOrDefault();
|
||||
if (embed == null)
|
||||
{
|
||||
await ctx.ReactWithAsync(Config.Reactions.Failure, "Invalid update announcement link").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await ToggleBadUpdateAnnouncementAsync(msg).ConfigureAwait(false);
|
||||
await ctx.ReactWithAsync(Config.Reactions.Success).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static async Task ToggleBadUpdateAnnouncementAsync(DiscordMessage message)
|
||||
{
|
||||
var embed = message?.Embeds?.FirstOrDefault();
|
||||
if (embed == null)
|
||||
return;
|
||||
|
||||
var result = new DiscordEmbedBuilder(embed);
|
||||
const string warningTitle = "Warning!";
|
||||
if (embed.Color.Value.Value == Config.Colors.DownloadLinks.Value)
|
||||
{
|
||||
result = result.WithColor(Config.Colors.UpdateStatusBad);
|
||||
result.ClearFields();
|
||||
var warned = false;
|
||||
foreach (var f in embed.Fields)
|
||||
{
|
||||
if (!warned && f.Name.EndsWith("download"))
|
||||
{
|
||||
result.AddField(warningTitle, "This build is known to have severe problems, please avoid downloading.");
|
||||
warned = true;
|
||||
}
|
||||
result.AddField(f.Name, f.Value, f.Inline);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = result.WithColor(Config.Colors.DownloadLinks);
|
||||
result.ClearFields();
|
||||
foreach (var f in embed.Fields)
|
||||
{
|
||||
if (f.Name == warningTitle)
|
||||
continue;
|
||||
|
||||
result.AddField(f.Name, f.Value, f.Inline);
|
||||
}
|
||||
}
|
||||
await message.UpdateOrCreateMessageAsync(message.Channel, embed: result).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static async Task ReportMessage(CommandContext ctx, string comment, DiscordMessage msg)
|
||||
{
|
||||
if (msg.Reactions.Any(r => r.IsMe && r.Emoji == Config.Reactions.Moderated))
|
||||
|
||||
@@ -95,6 +95,9 @@ namespace CompatBot
|
||||
public static readonly DiscordColor PrOpen = new DiscordColor(0x2cbe4e);
|
||||
public static readonly DiscordColor PrMerged = new DiscordColor(0x6f42c1);
|
||||
public static readonly DiscordColor PrClosed = new DiscordColor(0xcb2431);
|
||||
|
||||
public static readonly DiscordColor UpdateStatusGood = DiscordColor.Green;
|
||||
public static readonly DiscordColor UpdateStatusBad = DiscordColor.Yellow;
|
||||
}
|
||||
|
||||
public static class Reactions
|
||||
@@ -108,6 +111,7 @@ namespace CompatBot
|
||||
public static readonly DiscordEmoji PleaseWait = DiscordEmoji.FromUnicode("👀");
|
||||
public static readonly DiscordEmoji PiracyCheck = DiscordEmoji.FromUnicode("🔨");
|
||||
public static readonly DiscordEmoji Shutup = DiscordEmoji.FromUnicode("🔇");
|
||||
public static readonly DiscordEmoji BadUpdate = DiscordEmoji.FromUnicode("⚠");
|
||||
}
|
||||
|
||||
public static class Moderation
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CompatBot.Commands;
|
||||
using CompatBot.Utils;
|
||||
using CompatBot.Utils.Extensions;
|
||||
using DSharpPlus;
|
||||
@@ -85,7 +86,7 @@ namespace CompatBot.EventHandlers
|
||||
|
||||
public static Task Handler(MessageReactionAddEventArgs args)
|
||||
{
|
||||
return CheckMessageAsync(args.Client, args.Channel, args.User, args.Message, args.Emoji);
|
||||
return CheckMessageAsync(args.Client, args.Channel, args.User, args.Message, args.Emoji, false);
|
||||
}
|
||||
|
||||
public static async Task CheckBacklogAsync(DiscordClient client, DiscordGuild guild)
|
||||
@@ -104,7 +105,7 @@ namespace CompatBot.EventHandlers
|
||||
{
|
||||
var reactionUsers = await message.GetReactionsAsync(Config.Reactions.Starbucks).ConfigureAwait(false);
|
||||
if (reactionUsers.Count > 0)
|
||||
checkTasks.Add(CheckMessageAsync(client, channel, reactionUsers[0], message, Config.Reactions.Starbucks));
|
||||
checkTasks.Add(CheckMessageAsync(client, channel, reactionUsers[0], message, Config.Reactions.Starbucks, true));
|
||||
}
|
||||
}
|
||||
await Task.WhenAll(checkTasks).ConfigureAwait(false);
|
||||
@@ -115,7 +116,7 @@ namespace CompatBot.EventHandlers
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task CheckMessageAsync(DiscordClient client, DiscordChannel channel, DiscordUser user, DiscordMessage message, DiscordEmoji emoji)
|
||||
private static async Task CheckMessageAsync(DiscordClient client, DiscordChannel channel, DiscordUser user, DiscordMessage message, DiscordEmoji emoji, bool isBacklog)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -126,8 +127,10 @@ namespace CompatBot.EventHandlers
|
||||
message = await channel.GetMessageAsync(message.Id).ConfigureAwait(false);
|
||||
if (emoji == Config.Reactions.Starbucks)
|
||||
await CheckMediaTalkAsync(client, channel, message, emoji).ConfigureAwait(false);
|
||||
if (emoji == Config.Reactions.Shutup)
|
||||
if (emoji == Config.Reactions.Shutup && !isBacklog)
|
||||
await ShutupAsync(client, user, message).ConfigureAwait(false);
|
||||
if (emoji == Config.Reactions.BadUpdate && !isBacklog)
|
||||
await BadUpdateAsync(client, user, message, emoji).ConfigureAwait(false);
|
||||
|
||||
await CheckGameFansAsync(client, channel, message).ConfigureAwait(false);
|
||||
}
|
||||
@@ -192,6 +195,18 @@ namespace CompatBot.EventHandlers
|
||||
return message.DeleteAsync();
|
||||
}
|
||||
|
||||
private static async Task BadUpdateAsync(DiscordClient client, DiscordUser user, DiscordMessage message, DiscordEmoji emoji)
|
||||
{
|
||||
if (message?.Channel.Id != Config.BotChannelId)
|
||||
return;
|
||||
|
||||
if (!user.IsSmartlisted(client, message.Channel.Guild))
|
||||
return;
|
||||
|
||||
await Moderation.ToggleBadUpdateAnnouncementAsync(message).ConfigureAwait(false);
|
||||
await message.DeleteReactionAsync(emoji, user).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
private static Task CheckGameFansAsync(DiscordClient client, DiscordChannel channel, DiscordMessage message)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user