예제 #1
0
        private async Task UserLeft(SocketGuildUser user)
        {
            DateTime joinDate;

            DateTime.TryParse(_databaseService.GetUserJoinDate(user.Id), out joinDate);
            TimeSpan timeStayed = DateTime.Now - joinDate;
            await _loggingService.LogAction(
                $"User Left - After {(timeStayed.Days > 1 ? Math.Floor((double)timeStayed.Days).ToString() + " days" : " ")}" +
                $" {Math.Floor((double)timeStayed.Hours).ToString()} hours {user.Mention} - `{user.Username}#{user.DiscriminatorValue}` - ID : `{user.Id}`");

            _databaseService.DeleteUser(user.Id);
        }
예제 #2
0
        public async Task Thanks(SocketMessage messageParam)
        {
            if (messageParam.Author.IsBot)
            {
                return;
            }

            Match match = Regex.Match(messageParam.Content, _thanksRegex);

            if (!match.Success)
            {
                return;
            }

            IReadOnlyCollection <SocketUser> mentions = messageParam.MentionedUsers;

            mentions = mentions.Distinct().ToList();
            ulong     userId         = messageParam.Author.Id;
            const int defaultDelTime = 120;

            if (mentions.Count > 0)
            {
                if (_thanksCooldown.HasUser(userId))
                {
                    await messageParam.Channel.SendMessageAsync(
                        $"{messageParam.Author.Mention} you must wait " +
                        $"{DateTime.Now - _thanksCooldown[userId]:ss} " +
                        "seconds before giving another karma point").DeleteAfterTime(seconds: defaultDelTime);

                    return;
                }

                DateTime.TryParse(_databaseService.GetUserJoinDate(userId), out DateTime joinDate);
                var j = joinDate + TimeSpan.FromSeconds(_thanksMinJoinTime);

                if (j > DateTime.Now)
                {
                    await messageParam.Channel.SendMessageAsync(
                        $"{messageParam.Author.Mention} you must have been a member for at least 10 minutes to give karma points.")
                    .DeleteAfterTime(seconds: 140);

                    return;
                }

                bool          mentionedSelf = false;
                bool          mentionedBot  = false;
                StringBuilder sb            = new StringBuilder();

                sb.Append("**").Append(messageParam.Author.Username).Append("** gave karma to **");
                foreach (SocketUser user in mentions)
                {
                    if (user.IsBot)
                    {
                        mentionedBot = true;
                        continue;
                    }

                    if (user.Id == userId)
                    {
                        mentionedSelf = true;
                        continue;
                    }

                    _databaseService.AddUserKarma(user.Id, 1);
                    _databaseService.AddUserUdc(user.Id, 350);
                    sb.Append(user.Username).Append(" , ");
                }

                sb.Length -= 2; //Removes last instance of appended comma without convoluted tracking
                sb.Append("**");

                if (mentionedSelf)
                {
                    await messageParam.Channel.SendMessageAsync(
                        $"{messageParam.Author.Mention} you can't give karma to yourself.").DeleteAfterTime(seconds: defaultDelTime);
                }

                if (mentionedBot)
                {
                    await messageParam.Channel.SendMessageAsync(
                        $"Very cute of you {messageParam.Author.Mention} but I don't need karma :blush:{Environment.NewLine}" +
                        "If you'd like to know what Karma is about, type !karma").DeleteAfterTime(seconds: defaultDelTime);
                }

                _canEditThanks.Remove(messageParam.Id);

                //Don't give karma cooldown if user only mentioned himself or the bot or both
                if (((mentionedSelf || mentionedBot) && mentions.Count == 1) || (mentionedBot && mentionedSelf && mentions.Count == 2))
                {
                    return;
                }

                _thanksCooldown.AddCooldown(userId, _thanksCooldownTime);
                //Add thanks reminder cooldown after thanking to avoid casual thanks triggering remind afterwards
                ThanksReminderCooldown.AddCooldown(userId, _thanksReminderCooldownTime);
                await messageParam.Channel.SendMessageAsync(sb.ToString());

                await _loggingService.LogAction(sb + " in channel " + messageParam.Channel.Name);
            }
            else if (messageParam.Channel.Name != "general-chat" && !ThanksReminderCooldown.IsPermanent(userId) &&
                     !ThanksReminderCooldown.HasUser(userId) && !_thanksCooldown.HasUser(userId))
            {
                ThanksReminderCooldown.AddCooldown(userId, _thanksReminderCooldownTime);
                await messageParam.Channel.SendMessageAsync(
                    $"{messageParam.Author.Mention} , if you are thanking someone, please @mention them when you say \"thanks\" so they may receive karma for their help." +
                    Environment.NewLine +
                    "If you want me to stop reminding you about this, please type \"!disablethanksreminder\".")
                .DeleteAfterTime(seconds: defaultDelTime);
            }
            if (mentions.Count == 0 && _canEditThanks.Add(messageParam.Id))
            {
                _canEditThanks.RemoveAfterSeconds(messageParam.Id, 240);
            }
        }