private static async Task Client_RoleUpdated(SocketRole arg1, SocketRole arg2) { if (arg1.Name != arg2.Name) { await ScoreRoleManager.OrderRolesAsync(arg2.Guild); } }
private static async void OnHour(DiscordSocketClient client) { await Score.UpdateDecays(client); foreach (var guild in client.Guilds) { var cache = CacheProvider.Get(guild); await ScoreRoleManager.DeleteRolesAsync(cache); } }
public static async Task UpdateUserAsync(DiscordSocketClient client, SocketGuildUser user, ScoreData scoreData, bool force = false) { if (user.IsBot) { return; } if (user.Guild.CurrentUser.Hierarchy <= user.Hierarchy) { return; } if (!force && user.Roles.Count <= 1) { return; } var cache = CacheProvider.Get(user.Guild); var muted = await Database.UNSAFE_GetMute(user.Id) != null; // TODO: looking up mutes on everyone every hour is not a good idea var inSchool = user.Roles.Any(r => r.Id == 775812620108169298l); var roles = new List <IRole> { await ScoreRoleManager.GetScoreRoleForUserAsync(client, cache, user.Id, scoreData) }; if (!muted && !inSchool) { roles.Add(await ScoreRoleManager.GetClassRole(cache, scoreData)); } var toDelete = user.Roles.GetBotRoles().Where(r => roles.All(r2 => r.Id != r2.Id)).ToList(); var toAdd = roles.Where(r => user.Roles.All(r2 => r.Id != r2.Id)).ToList(); if (toAdd.Any() || toDelete.Any()) { await user.ModifyAsync(x => { x.Roles = Optional.Create(user.Roles .Concat(toAdd) .Except(toDelete) .Where(r => r != r.Guild.EveryoneRole)); }); } }