Add handling command ❌ reactions
and, uhh, rename invoker_id to author_id
This commit is contained in:
parent
05cc30279a
commit
56bb5e975f
@ -48,12 +48,15 @@ namespace PluralKit.Bot
|
|||||||
_db.Execute(c => _repo.GetMessage(c, evt.Message.Id));
|
_db.Execute(c => _repo.GetMessage(c, evt.Message.Id));
|
||||||
|
|
||||||
FullMessage msg;
|
FullMessage msg;
|
||||||
|
CommandMessage cmdmsg;
|
||||||
switch (evt.Emoji.Name)
|
switch (evt.Emoji.Name)
|
||||||
{
|
{
|
||||||
// Message deletion
|
// Message deletion
|
||||||
case "\u274C": // Red X
|
case "\u274C": // Red X
|
||||||
if ((msg = await GetMessage()) != null)
|
if ((msg = await GetMessage()) != null)
|
||||||
await HandleDeleteReaction(evt, msg);
|
await HandleDeleteReaction(evt, msg);
|
||||||
|
else if ((cmdmsg = await _db.Execute(conn => _repo.GetCommandMessage(conn, evt.Message.Id))) != null)
|
||||||
|
await HandleCommandDeleteReaction(evt, cmdmsg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "\u2753": // Red question mark
|
case "\u2753": // Red question mark
|
||||||
@ -92,6 +95,25 @@ namespace PluralKit.Bot
|
|||||||
await _db.Execute(c => _repo.DeleteMessage(c, evt.Message.Id));
|
await _db.Execute(c => _repo.DeleteMessage(c, evt.Message.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async ValueTask HandleCommandDeleteReaction(MessageReactionAddEventArgs evt, CommandMessage msg)
|
||||||
|
{
|
||||||
|
if (!evt.Channel.BotHasAllPermissions(Permissions.ManageMessages)) return;
|
||||||
|
|
||||||
|
// Can only delete your own message
|
||||||
|
if (msg.author_id != evt.User.Id) return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await evt.Message.DeleteAsync();
|
||||||
|
}
|
||||||
|
catch (NotFoundException)
|
||||||
|
{
|
||||||
|
// Message was deleted by something/someone else before we got to it
|
||||||
|
}
|
||||||
|
|
||||||
|
// No need to delete database row here, it'll get deleted by the once-per-minute scheduled task.
|
||||||
|
}
|
||||||
|
|
||||||
private async ValueTask HandleQueryReaction(MessageReactionAddEventArgs evt, FullMessage msg)
|
private async ValueTask HandleQueryReaction(MessageReactionAddEventArgs evt, FullMessage msg)
|
||||||
{
|
{
|
||||||
// Try to DM the user info about the message
|
// Try to DM the user info about the message
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
create table command_message
|
create table command_message
|
||||||
(
|
(
|
||||||
message_id bigint primary key,
|
message_id bigint primary key,
|
||||||
invoker_id bigint not null,
|
author_id bigint not null,
|
||||||
timestamp timestamp not null default now()
|
timestamp timestamp not null default now()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -9,7 +9,16 @@ namespace PluralKit.Core
|
|||||||
public partial class ModelRepository
|
public partial class ModelRepository
|
||||||
{
|
{
|
||||||
public Task SaveCommandMessage(IPKConnection conn, ulong message_id, ulong author_id) =>
|
public Task SaveCommandMessage(IPKConnection conn, ulong message_id, ulong author_id) =>
|
||||||
conn.QueryAsync("insert into command_message (message_id, invoker_id) values (@Message, @Author)",
|
conn.QueryAsync("insert into command_message (message_id, author_id) values (@Message, @Author)",
|
||||||
new {Message = message_id, Author = author_id });
|
new {Message = message_id, Author = author_id });
|
||||||
|
|
||||||
|
public Task<CommandMessage> GetCommandMessage(IPKConnection conn, ulong message_id) =>
|
||||||
|
conn.QuerySingleOrDefaultAsync<CommandMessage>("select message_id, author_id from command_message where message_id = @Message",
|
||||||
|
new {Message = message_id});
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CommandMessage
|
||||||
|
{
|
||||||
|
public ulong author_id { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user