Esempio n. 1
0
        public async Task OnMinutePassed(DateTime time)
        {
            SocketRole activeRole    = Utility.GetServer().GetRole(UserActivityMonitor.activeUserRole);
            SocketRole younglingRole = Utility.GetServer().GetRole(younglingRoleID);

            List <ulong> toRemove = new List <ulong> ();

            foreach (var pair in joinDate)   // A bit of optimization, so it doesn't test any unneccesary users.
            {
                SocketGuildUser user = Utility.GetServer().GetUser(pair.Key);

                if (user != null)
                {
                    if (user.Roles.Contains(younglingRole) && !user.Roles.Contains(activeRole))
                    {
                        try {
                            Program.SetKickReason(user.Id, "Kicked due to youngling-stage inactivity.");
                            RestInviteMetadata metadata = await Utility.GetMainChannel().CreateInviteAsync(null, 1, false, true);

                            await Program.messageControl.SendMessage(user, onKickedDM.Replace("{INVITELINK}", metadata.Url));

                            await user.KickAsync();
                        } catch (Exception e) {
                            Logging.DebugLog(Logging.LogType.EXCEPTION, e.Message);
                        }
                    }



                    if (user.Roles.Contains(younglingRole))
                    {
                        bool pastYounglingStage = UserActivityMonitor.GetLastActivity(user.Id) > pair.Value.joinDate.AddDays(daysActiveRequired);
                        bool remindAboutKick    = UserActivityMonitor.GetLastActivity(user.Id) < DateTime.Now.AddDays(-(UserActivityMonitor.activeThresholdDays - capraPopFlySprawlsYeekYoungin));

                        if (pastYounglingStage)
                        {
                            await Utility.SecureRemoveRole(user, younglingRole);

                            await Program.messageControl.SendMessage(user, onAcceptedDM);

                            Program.messageControl.SendMessage(Utility.GetMainChannel() as SocketTextChannel, onAcceptedPublicAnnouncement.Replace("{USERNAME}", Utility.GetUserName(user)), true);
                            toRemove.Add(user.Id);
                        }
                        if (remindAboutKick && pair.Value.reminded == false)
                        {
                            pair.Value.reminded = true;
                            await Program.messageControl.SendMessage(user, onRemindDM);
                        }
                    }
                    else
                    {
                        toRemove.Add(user.Id);
                        Logging.Log(Logging.LogType.BOT, "Purged manually removed user from younglings joinDate dictionary.");
                    }
                }
                else
                {
                    toRemove.Add(pair.Key);
                    Logging.Log(Logging.LogType.BOT, "Purge user who has left the server from joinDate dictionary.");
                }
            }

            foreach (ulong id in toRemove)
            {
                joinDate.Remove(id);
            }
            if (toRemove.Count > 0)
            {
                SaveData();
            }
        }
 public Task <Result> Execute(SocketUserMessage e, SocketGuildUser user, DateTime time)
 {
     UserActivityMonitor.RecordActivity(user.Id, time, true);
     return(TaskResult(null, "Succesfully set activity of user!"));
 }