-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathMessageMenuCommands.cs
178 lines (159 loc) · 7.98 KB
/
MessageMenuCommands.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using CompatApiClient.Utils;
using CompatBot.Database;
using CompatBot.Database.Providers;
using CompatBot.EventHandlers;
using CompatBot.Utils.Extensions;
using DSharpPlus.Commands.Processors.MessageCommands;
using DSharpPlus.Interactivity;
using Microsoft.Extensions.DependencyInjection;
namespace CompatBot.Commands;
internal static class MessageMenuCommands
{
/*
[Command("🗨️ message command with very long name")]
[Description("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901")]
public async ValueTask AnalyzerTest(){}
*/
// limited to 5 commands per menu
// anyone can use this
[Command("💬 Explain"), SlashCommandTypes(DiscordApplicationCommandType.MessageContextMenu)]
public static async ValueTask ShowToUser(MessageCommandContext ctx, DiscordMessage replyTo)
{
if (ctx.Extension.ServiceProvider.GetService<InteractivityExtension>() is not {} interactivity)
{
await ctx.RespondAsync($"{Config.Reactions.Failure} Couldn't get interactivity extension").ConfigureAwait(false);
return;
}
var placeholder = StatsStorage.GetExplainStats().FirstOrDefault().name ?? "rule 1";
var modal = new DiscordInteractionResponseBuilder()
.WithTitle("Explain Prompt")
.AddComponents(new DiscordTextInputComponent("Term to explain", "term", placeholder, min_length: 1))
.WithCustomId($"modal:explain:{Guid.NewGuid():n}");
await ctx.RespondWithModalAsync(modal).ConfigureAwait(false);
InteractivityResult<ModalSubmittedEventArgs> modalResult;
string? term = null;
(Explanation? explanation, string? fuzzyMatch, double score) result;
do
{
modalResult = await interactivity.WaitForModalAsync(modal.CustomId, ctx.User).ConfigureAwait(false);
if (modalResult.TimedOut)
return;
} while (!modalResult.Result.Values.TryGetValue("term", out term)
|| (result = await Explain.LookupTerm(term).ConfigureAwait(false)) is not { score: >0.5 } );
await modalResult.Result.Interaction.CreateResponseAsync(
DiscordInteractionResponseType.ChannelMessageWithSource,
new DiscordInteractionResponseBuilder()
.WithContent($" {Config.Reactions.Success} Found term `{result.explanation?.Keyword ?? result.fuzzyMatch}` to send")
.AsEphemeral()
).ConfigureAwait(false);
var canPing = ModProvider.IsMod(ctx.User.Id);
await Explain.SendExplanationAsync(result, term, replyTo, true, canPing).ConfigureAwait(false);
}
// non-whitenames can use these
[Command("👮 Report to mods"), RequiresSupporterRole, SlashCommandTypes(DiscordApplicationCommandType.MessageContextMenu)]
public static async ValueTask Report(MessageCommandContext ctx, DiscordMessage message)
{
try
{
if (message.Reactions.Any(r => r.IsMe && r.Emoji == Config.Reactions.Moderated))
{
await ctx.RespondAsync($"{Config.Reactions.Failure} Message was already reported", ephemeral: true).ConfigureAwait(false);
return;
}
if (ctx.Extension.ServiceProvider.GetService<InteractivityExtension>() is not {} interactivity)
{
await ctx.RespondAsync($"{Config.Reactions.Failure} Couldn't get interactivity extension").ConfigureAwait(false);
return;
}
var modal = new DiscordInteractionResponseBuilder()
.AsEphemeral()
.WithCustomId($"modal:report:{Guid.NewGuid():n}")
.WithTitle("Message Report")
.AddComponents(
new DiscordTextInputComponent(
"Comment",
"comment",
"Describe why you report this message",
required: false,
style: DiscordTextInputStyle.Paragraph,
max_length: EmbedPager.MaxFieldLength
)
);
await ctx.RespondWithModalAsync(modal).ConfigureAwait(false);
var modalResult = await interactivity.WaitForModalAsync(modal.CustomId, ctx.User).ConfigureAwait(false);
if (modalResult.TimedOut)
return;
modalResult.Result.Values.TryGetValue("comment", out var comment);
await ctx.Client.ReportAsync("👀 Message report", message, [ctx.Member], comment, ReportSeverity.Medium).ConfigureAwait(false);
await message.ReactWithAsync(Config.Reactions.Moderated).ConfigureAwait(false);
await modalResult.Result.Interaction.CreateResponseAsync(
DiscordInteractionResponseType.ChannelMessageWithSource,
new DiscordInteractionResponseBuilder()
.WithContent($"{Config.Reactions.Success} Message was reported")
.AsEphemeral()
).ConfigureAwait(false);
}
catch (Exception)
{
await ctx.RespondAsync($"{Config.Reactions.Failure} Failed to report the message", ephemeral: true).ConfigureAwait(false);
}
}
[Command("🔍 Analyze log"), RequiresSupporterRole, SlashCommandTypes(DiscordApplicationCommandType.MessageContextMenu)]
public static async ValueTask Reanalyze(MessageCommandContext ctx, DiscordMessage message)
{
try
{
LogParsingHandler.EnqueueLogProcessing(ctx.Client, ctx.Channel, message, ctx.Member, true, true);
}
catch
{
await ctx.RespondAsync($"{Config.Reactions.Failure} Failed to enqueue log analysis", ephemeral: true).ConfigureAwait(false);
return;
}
await ctx.RespondAsync($"{Config.Reactions.Success} Message was enqueued for analysis", ephemeral: true).ConfigureAwait(false);
}
/*
[Command("🔇 Shut up bot"), RequiresWhitelistedRole, SlashCommandTypes(DiscordApplicationCommandType.MessageContextMenu)]
public static async ValueTask Shutup(MessageCommandContext ctx, DiscordMessage message)
{
if (!message.Author.IsBotSafeCheck()
|| message.Author != ctx.Client.CurrentUser)
{
await ctx.RespondAsync($"{Config.Reactions.Failure} You can only remove bot messages", ephemeral: true).ConfigureAwait(false);
return;
}
/*
if (message.CreationTimestamp.Add(Config.ShutupTimeLimitInMin) < DateTime.UtcNow)
{
await ctx.RespondAsync($"{Config.Reactions.Failure} Message is too old to remove", ephemeral: true).ConfigureAwait(false);
return;
}
#1#
try
{
await message.DeleteAsync().ConfigureAwait(false);
await ctx.RespondAsync($"{Config.Reactions.Success} Message removed", ephemeral: true).ConfigureAwait(false);
}
catch (Exception e)
{
Config.Log.Warn(e, "Failed to remove bot message");
await ctx.RespondAsync($"{Config.Reactions.Failure} Failed to remove bot message: {e.Message}".Trim(EmbedPager.MaxMessageLength), ephemeral: true).ConfigureAwait(false);
}
}
*/
// only bot mods can use this
/*
[Command("👎 Toggle bad update"), RequiresSmartlistedRole, SlashCommandTypes(DiscordApplicationCommandType.MessageContextMenu)]
public static async ValueTask BadUpdate(MessageCommandContext ctx, DiscordMessage message)
{
if (message.Embeds is not [DiscordEmbed embed]
|| message.Channel?.Id != Config.BotChannelId)
{
await ctx.RespondAsync($"{Config.Reactions.Failure} Invalid update announcement message", ephemeral: true).ConfigureAwait(false);
return;
}
await Starbucks.ToggleBadUpdateAnnouncementAsync(message).ConfigureAwait(false);
await ctx.RespondAsync($"{Config.Reactions.Success} Done", ephemeral: true).ConfigureAwait(false);
}
*/
}