From b70f57f0a34d7f335f8ae0c78ade54d04b7fece7 Mon Sep 17 00:00:00 2001 From: Noikoio Date: Fri, 22 Dec 2017 22:28:58 -0800 Subject: [PATCH] Added another handler --- EntityCache/Module.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/EntityCache/Module.cs b/EntityCache/Module.cs index 2726237..f976632 100644 --- a/EntityCache/Module.cs +++ b/EntityCache/Module.cs @@ -29,6 +29,7 @@ namespace Noikoio.RegexBot.EntityCache client.GuildUpdated += Client_GuildUpdated; client.GuildMemberUpdated += Client_GuildMemberUpdated; client.UserJoined += Client_UserJoined; + client.UserLeft += Client_UserLeft; } else { @@ -37,8 +38,7 @@ namespace Noikoio.RegexBot.EntityCache } public override Task ProcessConfiguration(JToken configSection) => Task.FromResult(null); - - #region Event handling + // Guild and guild member information has become available. // This is a very expensive operation, especially when joining larger guilds. private async Task Client_GuildAvailable(SocketGuild arg) @@ -104,7 +104,21 @@ namespace Noikoio.RegexBot.EntityCache } }); } - #endregion - + + // User left the guild. No new data, but gives an excuse to update the cache date. + private async Task Client_UserLeft(SocketGuildUser arg) + { + await Task.Run(async () => + { + try + { + await SqlHelper.UpdateGuildMemberAsync(arg); + } + catch (NpgsqlException ex) + { + await Log($"SQL error in {nameof(Client_UserLeft)}: {ex.Message}"); + } + }); + } } }