Store the ID of the trigger message in the database

This commit is contained in:
Ske 2019-07-24 13:38:54 +02:00
parent 11eabe2e3d
commit b14666aa4f
3 changed files with 12 additions and 9 deletions

View File

@ -114,7 +114,7 @@ namespace PluralKit.Bot
var hookMessageId = await ExecuteWebhook(webhook, match.InnerText, match.ProxyName, match.Member.AvatarUrl, message.Attachments.FirstOrDefault()); var hookMessageId = await ExecuteWebhook(webhook, match.InnerText, match.ProxyName, match.Member.AvatarUrl, message.Attachments.FirstOrDefault());
// Store the message in the database, and log it in the log channel (if applicable) // Store the message in the database, and log it in the log channel (if applicable)
await _messageStorage.Store(message.Author.Id, hookMessageId, message.Channel.Id, match.Member); await _messageStorage.Store(message.Author.Id, hookMessageId, message.Channel.Id, message.Id, match.Member);
await _logChannel.LogMessage(match.System, match.Member, hookMessageId, message.Channel as IGuildChannel, message.Author, match.InnerText); await _logChannel.LogMessage(match.System, match.Member, hookMessageId, message.Channel as IGuildChannel, message.Author, match.InnerText);
// Wait a second or so before deleting the original message // Wait a second or so before deleting the original message

View File

@ -181,6 +181,7 @@ namespace PluralKit {
public ulong Mid; public ulong Mid;
public ulong Channel; public ulong Channel;
public ulong Sender; public ulong Sender;
public ulong? OriginalMid;
} }
public class StoredMessage public class StoredMessage
{ {
@ -198,13 +199,14 @@ namespace PluralKit {
_logger = logger.ForContext<MessageStore>(); _logger = logger.ForContext<MessageStore>();
} }
public async Task Store(ulong senderId, ulong messageId, ulong channelId, PKMember member) { public async Task Store(ulong senderId, ulong messageId, ulong channelId, ulong originalMessage, PKMember member) {
using (var conn = await _conn.Obtain()) using (var conn = await _conn.Obtain())
await conn.ExecuteAsync("insert into messages(mid, channel, member, sender) values(@MessageId, @ChannelId, @MemberId, @SenderId)", new { await conn.ExecuteAsync("insert into messages(mid, channel, member, sender, original_mid) values(@MessageId, @ChannelId, @MemberId, @SenderId, @OriginalMid)", new {
MessageId = messageId, MessageId = messageId,
ChannelId = channelId, ChannelId = channelId,
MemberId = member.Id, MemberId = member.Id,
SenderId = senderId SenderId = senderId,
OriginalMid = originalMessage
}); });
_logger.Information("Stored message {Message} in channel {Channel}", messageId, channelId); _logger.Information("Stored message {Message} in channel {Channel}", messageId, channelId);
@ -213,7 +215,7 @@ namespace PluralKit {
public async Task<StoredMessage> Get(ulong id) public async Task<StoredMessage> Get(ulong id)
{ {
using (var conn = await _conn.Obtain()) using (var conn = await _conn.Obtain())
return (await conn.QueryAsync<PKMessage, PKMember, PKSystem, StoredMessage>("select messages.*, members.*, systems.* from messages, members, systems where mid = @Id and messages.member = members.id and systems.id = members.system", (msg, member, system) => new StoredMessage return (await conn.QueryAsync<PKMessage, PKMember, PKSystem, StoredMessage>("select messages.*, members.*, systems.* from messages, members, systems where (mid = @Id or original_mid = @Id) and messages.member = members.id and systems.id = members.system", (msg, member, system) => new StoredMessage
{ {
Message = msg, Message = msg,
System = system, System = system,

View File

@ -38,7 +38,8 @@ create table if not exists messages
mid bigint primary key, mid bigint primary key,
channel bigint not null, channel bigint not null,
member serial not null references members (id) on delete cascade, member serial not null references members (id) on delete cascade,
sender bigint not null sender bigint not null,
original_mid bigint
); );
create table if not exists switches create table if not exists switches