forked from TeamInklings/Octobot
Include bots for storage in MemberData, download users when populating MemberData
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
7f0fd6ffb5
commit
3105229ad4
2 changed files with 8 additions and 8 deletions
|
@ -48,6 +48,7 @@ public record GuildData {
|
|||
[SuppressMessage("Performance", "CA1853:Unnecessary call to \'Dictionary.ContainsKey(key)\'")]
|
||||
// https://github.com/dotnet/roslyn-analyzers/issues/6377
|
||||
private GuildData(SocketGuild guild) {
|
||||
var downloaderTask = guild.DownloadUsersAsync();
|
||||
_id = guild.Id;
|
||||
var idString = $"{_id}";
|
||||
var memberDataDir = $"{_id}/MemberData";
|
||||
|
@ -74,7 +75,8 @@ public record GuildData {
|
|||
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.IsInGuild
|
||||
&& DateTimeOffset.Now.ToUnixTimeSeconds()
|
||||
|
|
|
@ -39,12 +39,13 @@ public static class EventHandler {
|
|||
var i = Random.Shared.Next(3);
|
||||
|
||||
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 config = data.Preferences;
|
||||
var channel = data.PrivateFeedbackChannel;
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
|
||||
if (config["ReceiveStartupMessages"] is not "true" || channel is null) continue;
|
||||
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
_ = channel.SendMessageAsync(string.Format(Messages.Ready, Utils.GetBeep(i)));
|
||||
}
|
||||
|
||||
|
@ -118,7 +119,6 @@ public static class EventHandler {
|
|||
}
|
||||
|
||||
private static async Task UserJoinedEvent(SocketGuildUser user) {
|
||||
if (user.IsBot) return;
|
||||
var guild = user.Guild;
|
||||
var data = GuildData.Get(guild);
|
||||
var config = data.Preferences;
|
||||
|
@ -142,8 +142,7 @@ public static class EventHandler {
|
|||
memberData.JoinedAt.Add(user.JoinedAt!.Value);
|
||||
}
|
||||
|
||||
if (memberData.MutedUntil < DateTimeOffset.Now) {
|
||||
if (data.MuteRole is not null && !user.TimedOutUntil.HasValue)
|
||||
if (DateTimeOffset.Now < memberData.MutedUntil) {
|
||||
await user.AddRoleAsync(data.MuteRole);
|
||||
if (config["RemoveRolesOnMute"] is "false" && config["ReturnRolesOnRejoin"] is "true")
|
||||
await user.AddRolesAsync(memberData.Roles);
|
||||
|
@ -151,7 +150,6 @@ public static class EventHandler {
|
|||
}
|
||||
|
||||
private static Task UserLeftEvent(SocketGuild guild, SocketUser user) {
|
||||
if (user.IsBot) return Task.CompletedTask;
|
||||
var data = GuildData.Get(guild).MemberData[user.Id];
|
||||
data.IsInGuild = false;
|
||||
data.LeftAt.Add(DateTimeOffset.Now);
|
||||
|
|
Reference in a new issue