Include bots for storage in MemberData, download users when populating MemberData

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2023-02-02 23:05:28 +05:00
parent 7f0fd6ffb5
commit 3105229ad4
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
2 changed files with 8 additions and 8 deletions

View file

@ -48,6 +48,7 @@ public record GuildData {
[SuppressMessage("Performance", "CA1853:Unnecessary call to \'Dictionary.ContainsKey(key)\'")] [SuppressMessage("Performance", "CA1853:Unnecessary call to \'Dictionary.ContainsKey(key)\'")]
// https://github.com/dotnet/roslyn-analyzers/issues/6377 // https://github.com/dotnet/roslyn-analyzers/issues/6377
private GuildData(SocketGuild guild) { private GuildData(SocketGuild guild) {
var downloaderTask = guild.DownloadUsersAsync();
_id = guild.Id; _id = guild.Id;
var idString = $"{_id}"; var idString = $"{_id}";
var memberDataDir = $"{_id}/MemberData"; var memberDataDir = $"{_id}/MemberData";
@ -74,7 +75,8 @@ public record GuildData {
MemberData.Add(deserialised!.Id, deserialised); MemberData.Add(deserialised!.Id, deserialised);
} }
foreach (var member in guild.Users.Where(user => !user.IsBot)) { downloaderTask.Wait();
foreach (var member in guild.Users) {
if (MemberData.TryGetValue(member.Id, out var memberData)) { if (MemberData.TryGetValue(member.Id, out var memberData)) {
if (!memberData.IsInGuild if (!memberData.IsInGuild
&& DateTimeOffset.Now.ToUnixTimeSeconds() && DateTimeOffset.Now.ToUnixTimeSeconds()

View file

@ -39,12 +39,13 @@ public static class EventHandler {
var i = Random.Shared.Next(3); var i = Random.Shared.Next(3);
foreach (var guild in Client.Guilds) { foreach (var guild in Client.Guilds) {
Boyfriend.Log(new LogMessage(LogSeverity.Info, nameof(EventHandler), $"Guild \"{guild.Name}\" is READY"));
var data = GuildData.Get(guild); var data = GuildData.Get(guild);
var config = data.Preferences; var config = data.Preferences;
var channel = data.PrivateFeedbackChannel; var channel = data.PrivateFeedbackChannel;
Utils.SetCurrentLanguage(guild);
if (config["ReceiveStartupMessages"] is not "true" || channel is null) continue; if (config["ReceiveStartupMessages"] is not "true" || channel is null) continue;
Utils.SetCurrentLanguage(guild);
_ = channel.SendMessageAsync(string.Format(Messages.Ready, Utils.GetBeep(i))); _ = channel.SendMessageAsync(string.Format(Messages.Ready, Utils.GetBeep(i)));
} }
@ -118,7 +119,6 @@ public static class EventHandler {
} }
private static async Task UserJoinedEvent(SocketGuildUser user) { private static async Task UserJoinedEvent(SocketGuildUser user) {
if (user.IsBot) return;
var guild = user.Guild; var guild = user.Guild;
var data = GuildData.Get(guild); var data = GuildData.Get(guild);
var config = data.Preferences; var config = data.Preferences;
@ -142,8 +142,7 @@ public static class EventHandler {
memberData.JoinedAt.Add(user.JoinedAt!.Value); memberData.JoinedAt.Add(user.JoinedAt!.Value);
} }
if (memberData.MutedUntil < DateTimeOffset.Now) { if (DateTimeOffset.Now < memberData.MutedUntil) {
if (data.MuteRole is not null && !user.TimedOutUntil.HasValue)
await user.AddRoleAsync(data.MuteRole); await user.AddRoleAsync(data.MuteRole);
if (config["RemoveRolesOnMute"] is "false" && config["ReturnRolesOnRejoin"] is "true") if (config["RemoveRolesOnMute"] is "false" && config["ReturnRolesOnRejoin"] is "true")
await user.AddRolesAsync(memberData.Roles); await user.AddRolesAsync(memberData.Roles);
@ -151,7 +150,6 @@ public static class EventHandler {
} }
private static Task UserLeftEvent(SocketGuild guild, SocketUser user) { private static Task UserLeftEvent(SocketGuild guild, SocketUser user) {
if (user.IsBot) return Task.CompletedTask;
var data = GuildData.Get(guild).MemberData[user.Id]; var data = GuildData.Get(guild).MemberData[user.Id];
data.IsInGuild = false; data.IsInGuild = false;
data.LeftAt.Add(DateTimeOffset.Now); data.LeftAt.Add(DateTimeOffset.Now);