예제 #1
0
 private string GetDailyStr(ScoreData scoreData, int amount, int bonus)
 {
     var bonusStr = bonus == 0 ? "" : $" (+3 streak bonus)";
     var streakStr = scoreData.DailyStreakCount == 0 ? "" : $" Streak days: {scoreData.DailyStreakCount}";
     return $"{MentionUtils.MentionUser(Context.User.Id)} collected their {amount}{bonusStr} daily gems. " +
         $"They now have {scoreData.Gems} in total.{streakStr}";
 }
예제 #2
0
        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));
                });
            }
        }
예제 #3
0
 private static async Task OnScoreChangeAsync(DiscordSocketClient client, ulong userId, ScoreData scoreData)
 {
     foreach (var guild in client.Guilds)
     {
         var user = guild.GetUser(userId);
         if (user != null)
         {
             await UpdateUserAsync(client, user, scoreData);
         }
     }
 }
예제 #4
0
 private static async void Score_OnUpdate(DiscordSocketClient client, ulong userId, ScoreData scoreData)
 {
     await OnScoreChangeAsync(client, userId, scoreData);
 }