Add message querying by ? reaction
This commit is contained in:
parent
93fff14053
commit
53037f7d52
@ -32,7 +32,7 @@ namespace PluralKit.Bot.Commands
|
||||
var message = await Messages.Get(messageId);
|
||||
if (message == null) throw Errors.MessageNotFound(messageId);
|
||||
|
||||
await Context.Channel.SendMessageAsync(embed: await Embeds.CreateMessageInfoEmbed(messageId));
|
||||
await Context.Channel.SendMessageAsync(embed: await Embeds.CreateMessageInfoEmbed(message));
|
||||
}
|
||||
|
||||
[Command("message")]
|
||||
|
@ -120,9 +120,8 @@ namespace PluralKit.Bot {
|
||||
.Build();
|
||||
}
|
||||
|
||||
public async Task<Embed> CreateMessageInfoEmbed(ulong messageId)
|
||||
public async Task<Embed> CreateMessageInfoEmbed(MessageStore.StoredMessage msg)
|
||||
{
|
||||
var msg = await _messages.Get(messageId);
|
||||
var channel = (ITextChannel) await _client.GetChannelAsync(msg.Message.Channel);
|
||||
var serverMsg = await channel.GetMessageAsync(msg.Message.Mid);
|
||||
|
||||
@ -131,7 +130,7 @@ namespace PluralKit.Bot {
|
||||
|
||||
return new EmbedBuilder()
|
||||
.WithAuthor(msg.Member.Name, msg.Member.AvatarUrl)
|
||||
.WithDescription(serverMsg.Content)
|
||||
.WithDescription(serverMsg?.Content ?? "*(message contents deleted or inaccessible)*")
|
||||
.AddField("System", msg.System.Name != null ? $"{msg.System.Name} (`{msg.System.Hid}`)" : $"`{msg.System.Hid}`", true)
|
||||
.AddField("Member", memberStr, true)
|
||||
.WithTimestamp(SnowflakeUtils.FromSnowflake(msg.Message.Mid))
|
||||
|
@ -33,15 +33,16 @@ namespace PluralKit.Bot
|
||||
private LogChannelService _logger;
|
||||
private WebhookCacheService _webhookCache;
|
||||
private MessageStore _messageStorage;
|
||||
private EmbedService _embeds;
|
||||
|
||||
|
||||
public ProxyService(IDiscordClient client, WebhookCacheService webhookCache, IDbConnection connection, LogChannelService logger, MessageStore messageStorage)
|
||||
public ProxyService(IDiscordClient client, WebhookCacheService webhookCache, IDbConnection connection, LogChannelService logger, MessageStore messageStorage, EmbedService embeds)
|
||||
{
|
||||
this._client = client;
|
||||
this._webhookCache = webhookCache;
|
||||
this._connection = connection;
|
||||
this._logger = logger;
|
||||
this._messageStorage = messageStorage;
|
||||
_client = client;
|
||||
_webhookCache = webhookCache;
|
||||
_connection = connection;
|
||||
_logger = logger;
|
||||
_messageStorage = messageStorage;
|
||||
_embeds = embeds;
|
||||
}
|
||||
|
||||
private ProxyMatch GetProxyTagMatch(string message, IEnumerable<ProxyDatabaseResult> potentials) {
|
||||
@ -98,17 +99,40 @@ namespace PluralKit.Bot
|
||||
return await webhook.Channel.GetMessageAsync(messageId);
|
||||
}
|
||||
|
||||
public async Task HandleReactionAddedAsync(Cacheable<IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
|
||||
public Task HandleReactionAddedAsync(Cacheable<IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
|
||||
{
|
||||
// Make sure it's the right emoji (red X)
|
||||
if (reaction.Emote.Name != "\u274C") return;
|
||||
// Dispatch on emoji
|
||||
switch (reaction.Emote.Name)
|
||||
{
|
||||
case "\u274C": // Red X
|
||||
return HandleMessageDeletionByReaction(message, reaction.UserId);
|
||||
case "\u2753": // Red question mark
|
||||
case "\u2754": // White question mark
|
||||
return HandleMessageQueryByReaction(message, reaction.UserId);
|
||||
default:
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleMessageQueryByReaction(Cacheable<IUserMessage, ulong> message, ulong userWhoReacted)
|
||||
{
|
||||
var user = await _client.GetUserAsync(userWhoReacted);
|
||||
if (user == null) return;
|
||||
|
||||
var msg = await _messageStorage.Get(message.Id);
|
||||
if (msg == null) return;
|
||||
|
||||
await user.SendMessageAsync(embed: await _embeds.CreateMessageInfoEmbed(msg));
|
||||
}
|
||||
|
||||
public async Task HandleMessageDeletionByReaction(Cacheable<IUserMessage, ulong> message, ulong userWhoReacted)
|
||||
{
|
||||
// Find the message in the database
|
||||
var storedMessage = await _messageStorage.Get(message.Id);
|
||||
if (storedMessage == null) return; // (if we can't, that's ok, no worries)
|
||||
|
||||
// Make sure it's the actual sender of that message deleting the message
|
||||
if (storedMessage.Message.Sender != reaction.UserId) return;
|
||||
if (storedMessage.Message.Sender != userWhoReacted) return;
|
||||
|
||||
try {
|
||||
// Then, fetch the Discord message and delete that
|
||||
|
Loading…
Reference in New Issue
Block a user