mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 12:32:03 -04:00
Implemented Discord conversation summaries
This commit is contained in:
@@ -120,9 +120,10 @@ public class BotServices
|
|||||||
_discord.OnPresenceUpdated += DiscordOnPresenceUpdated;
|
_discord.OnPresenceUpdated += DiscordOnPresenceUpdated;
|
||||||
_discord.OnChannelCreated += DiscordOnChannelCreated;
|
_discord.OnChannelCreated += DiscordOnChannelCreated;
|
||||||
_discord.OnChannelDeleted += DiscordOnChannelDeleted;
|
_discord.OnChannelDeleted += DiscordOnChannelDeleted;
|
||||||
|
_discord.OnConversationSummaryUpdate += DiscordOnConversationSummaryUpdate;
|
||||||
await _discord.StartWsClient();
|
await _discord.StartWsClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task BuildRainbet()
|
private async Task BuildRainbet()
|
||||||
{
|
{
|
||||||
var settings = await SettingsProvider.GetMultipleValuesAsync([BuiltIn.Keys.Proxy, BuiltIn.Keys.RainbetEnabled]);
|
var settings = await SettingsProvider.GetMultipleValuesAsync([BuiltIn.Keys.Proxy, BuiltIn.Keys.RainbetEnabled]);
|
||||||
@@ -646,6 +647,13 @@ public class BotServices
|
|||||||
db.SaveChanges();
|
db.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DiscordOnConversationSummaryUpdate(object sender, DiscordConversationSummaryUpdateModel summary, string guildId)
|
||||||
|
{
|
||||||
|
_logger.Info($"Received a conversation summary update for guild {guildId}");
|
||||||
|
var discordIcon = SettingsProvider.GetValueAsync(BuiltIn.Keys.DiscordIcon).Result;
|
||||||
|
_chatBot.SendChatMessage($"[img]{discordIcon.Value}[/img] {summary.Topic}: {summary.SummaryShort} 🤖🤖", true);
|
||||||
|
}
|
||||||
|
|
||||||
private void DiscordOnChannelDeleted(object sender, DiscordChannelDeletionModel channel)
|
private void DiscordOnChannelDeleted(object sender, DiscordChannelDeletionModel channel)
|
||||||
{
|
{
|
||||||
_logger.Info($"Received channel deletion event of type {channel.Type} with name {channel.Name}");
|
_logger.Info($"Received channel deletion event of type {channel.Type} with name {channel.Name}");
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ public class DiscordService : IDisposable
|
|||||||
public delegate void InvalidCredentialsEventHandler(object sender, DiscordPacketReadModel packet);
|
public delegate void InvalidCredentialsEventHandler(object sender, DiscordPacketReadModel packet);
|
||||||
public delegate void ChannelCreatedEventHandler(object sender, DiscordChannelCreationModel channel);
|
public delegate void ChannelCreatedEventHandler(object sender, DiscordChannelCreationModel channel);
|
||||||
public delegate void ChannelDeletedEventHandler(object sender, DiscordChannelDeletionModel channel);
|
public delegate void ChannelDeletedEventHandler(object sender, DiscordChannelDeletionModel channel);
|
||||||
|
public delegate void ConversationSummaryUpdateEventHandler(object sender,
|
||||||
|
DiscordConversationSummaryUpdateModel summary, string guildId);
|
||||||
|
|
||||||
public event MessageReceivedEventHandler OnMessageReceived;
|
public event MessageReceivedEventHandler OnMessageReceived;
|
||||||
public event PresenceUpdateEventHandler OnPresenceUpdated;
|
public event PresenceUpdateEventHandler OnPresenceUpdated;
|
||||||
@@ -33,6 +35,7 @@ public class DiscordService : IDisposable
|
|||||||
public event InvalidCredentialsEventHandler OnInvalidCredentials;
|
public event InvalidCredentialsEventHandler OnInvalidCredentials;
|
||||||
public event ChannelCreatedEventHandler OnChannelCreated;
|
public event ChannelCreatedEventHandler OnChannelCreated;
|
||||||
public event ChannelDeletedEventHandler OnChannelDeleted;
|
public event ChannelDeletedEventHandler OnChannelDeleted;
|
||||||
|
public event ConversationSummaryUpdateEventHandler OnConversationSummaryUpdate;
|
||||||
|
|
||||||
private readonly CancellationToken _cancellationToken = CancellationToken.None;
|
private readonly CancellationToken _cancellationToken = CancellationToken.None;
|
||||||
private readonly CancellationTokenSource _pingCts = new();
|
private readonly CancellationTokenSource _pingCts = new();
|
||||||
@@ -202,6 +205,17 @@ public class DiscordService : IDisposable
|
|||||||
packet.Data.Deserialize<DiscordChannelDeletionModel>() ??
|
packet.Data.Deserialize<DiscordChannelDeletionModel>() ??
|
||||||
throw new InvalidOperationException());
|
throw new InvalidOperationException());
|
||||||
return;
|
return;
|
||||||
|
case "CONVERSATION_SUMMARY_UPDATE":
|
||||||
|
var guildId = packet.Data.GetProperty("guild_id").GetString();
|
||||||
|
var summaries = packet.Data.GetProperty("summaries")
|
||||||
|
.Deserialize<List<DiscordConversationSummaryUpdateModel>>();
|
||||||
|
if (summaries == null) return;
|
||||||
|
if (summaries.Count == 0) return;
|
||||||
|
foreach (var summary in summaries)
|
||||||
|
{
|
||||||
|
OnConversationSummaryUpdate?.Invoke(this, summary, guildId ?? string.Empty);
|
||||||
|
}
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
_logger.Debug($"{packet.DispatchEvent} was unhandled. JSON follows");
|
_logger.Debug($"{packet.DispatchEvent} was unhandled. JSON follows");
|
||||||
_logger.Debug(message.Text);
|
_logger.Debug(message.Text);
|
||||||
@@ -294,6 +308,16 @@ public class DiscordChannelDeletionModel
|
|||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class DiscordConversationSummaryUpdateModel
|
||||||
|
{
|
||||||
|
[JsonPropertyName("unsafe")]
|
||||||
|
public required bool Unsafe { get; set; }
|
||||||
|
[JsonPropertyName("topic")]
|
||||||
|
public required string Topic { get; set; }
|
||||||
|
[JsonPropertyName("summ_short")]
|
||||||
|
public required string SummaryShort { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
|
// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
|
||||||
// Ignored the ones nobody cares about
|
// Ignored the ones nobody cares about
|
||||||
public enum DiscordChannelType
|
public enum DiscordChannelType
|
||||||
|
|||||||
Reference in New Issue
Block a user