示例#1
0
        public async Task GiveReputationAsync(MiunieUser invoker, MiunieUser target, MiunieChannel c)
        {
            if (invoker.UserId == target.UserId)
            {
                await _discordMessages.SendMessageAsync(c, PhraseKey.CANNOT_SELF_REP, invoker.Name);

                return;
            }

            if (_reputationProvider.CanAddReputation(invoker, target))
            {
                _logger.Log($"User '{invoker.Name}' has a reputation timeout for User '{target.Name}', ignoring...");
                return;
            }

            _reputationProvider.AddReputation(invoker, target);

            if (_miunieDiscord.UserIsMiunie(target))
            {
                await _discordMessages.SendMessageAsync(c, PhraseKey.REPUTATION_GIVEN_BOT, invoker.Name);

                return;
            }

            await _discordMessages.SendMessageAsync(c, PhraseKey.REPUTATION_GIVEN, target.Name, invoker.Name);
        }
示例#2
0
        public async Task RemoveReputationAsync(MiunieUser invoker, MiunieUser target, MiunieChannel c)
        {
            if (invoker.UserId == target.UserId)
            {
                await _discordMessages.SendMessageAsync(c, PhraseKey.CANNOT_SELF_REP, invoker.Name);

                return;
            }

            if (_reputationProvider.CanRemoveReputation(invoker, target))
            {
                return;
            }

            _reputationProvider.RemoveReputation(invoker, target);

            if (_miunieDiscord.UserIsMiunie(target))
            {
                await _discordMessages.SendMessageAsync(c, PhraseKey.REPUTATION_TAKEN_BOT, invoker.Name);

                return;
            }

            await _discordMessages.SendMessageAsync(c, PhraseKey.REPUTATION_TAKEN, invoker.Name, target.Name);
        }
示例#3
0
        public async Task ShowReputationLogAsync(MiunieUser user, int page, MiunieChannel c)
        {
            page -= 1;
            var repGiven = _reputationProvider.GetReputation(user);

            await _discordMessages.SendMessageAsync(c, repGiven, page);
        }
示例#4
0
        public async Task SetUtcOffsetForUserAsync(DateTime userTime, MiunieUser user, MiunieChannel channel)
        {
            var offset = TimeSpan.FromHours(userTime.Hour - _dateTime.UtcNow.Hour);

            user.UtcTimeOffset = offset;
            _users.StoreUser(user);
            await _messages.SendMessageAsync(channel, PhraseKey.TIME_NEW_OFFSET_SET);
        }
示例#5
0
        public async Task OutputCurrentTimeForUserAsync(MiunieUser user, MiunieChannel channel)
        {
            if (!user.UtcTimeOffset.HasValue)
            {
                await _messages.SendMessageAsync(channel, PhraseKey.TIME_NO_TIMEZONE_INFO, user.Name);

                return;
            }

            var targetDateTime = _dateTime.UtcNow + user.UtcTimeOffset.Value;
            await _messages.SendMessageAsync(channel, PhraseKey.TIME_TIMEZONE_INFO, user.Name, targetDateTime);
        }
示例#6
0
        public async Task OutputCurrentTimeComparedToInputForUserAsync(MiunieUser requestUser, DateTime requestTime, MiunieUser user, MiunieChannel channel)
        {
            var requesterOffset = requestUser.UtcTimeOffset ?? new TimeSpan();
            var otherUserOffSet = user.UtcTimeOffset ?? new TimeSpan();

            var requestUtcTime = requestTime - requesterOffset;
            var otherUserTime  = requestUtcTime + otherUserOffSet;

            var formattedRequestTime   = requestTime.ToShortTimeString();
            var formattedOtherUserTime = otherUserTime.ToShortTimeString();

            await _messages.SendMessageAsync(channel, PhraseKey.TIME_USERTIME_FROM_LOCAL, formattedRequestTime, user.Name, formattedOtherUserTime);
        }
示例#7
0
        public async Task OutputCurrentTimeComparedToInputForUserAsync(MiunieUser requestUser, DateTime requestTime, string verb, MiunieUser user, MiunieChannel channel)
        {
            if (verb.Trim().ToLower() != "for")
            {
                await _messages.SendMessageAsync(channel, PhraseKey.INCORRECT_VERB, verb);

                return;
            }

            var requesterOffset = requestUser.UtcTimeOffset ?? default;
            var otherUserOffSet = user.UtcTimeOffset ?? default;

            var requestUtcTime = requestTime - requesterOffset;
            var otherUserTime  = requestUtcTime + otherUserOffSet;

            await _messages.SendMessageAsync(channel, PhraseKey.TIME_USERTIME_FROM_LOCAL, requestTime, user.Name, otherUserTime);
        }
示例#8
0
        private MiunieUser EnsureExistence(
            MiunieUser user,
            ulong userId,
            ulong guildId)
        {
            if (user is null)
            {
                user = new MiunieUser
                {
                    GuildId = guildId,
                    Id      = userId
                };
                StoreUser(user);
            }

            return(user);
        }
示例#9
0
        public async Task RemoveReputation(MiunieUser invoker, MiunieUser target, MiunieChannel c)
        {
            if (invoker.Id == target.Id)
            {
                await _discordMessages.SendMessage(c, PhraseKey.CANNOT_SELF_REP, invoker.Name);

                return;
            }

            if (_reputationProvider.RemoveReputationHasTimeout(invoker, target))
            {
                return;
            }

            _reputationProvider.RemoveReputation(invoker, target);
            await _discordMessages.SendMessage(c, PhraseKey.REPUTATION_TAKEN, invoker.Name, target.Name);
        }
示例#10
0
        public async Task OutputFutureTimeForUserAsync(MiunieUser user, string verb, int units, string timeframe, MiunieChannel channel)
        {
            if (verb.Trim().ToLower() != "in")
            {
                await _messages.SendMessageAsync(channel, PhraseKey.INCORRECT_VERB, verb);

                return;
            }

            var timeFromLocal = _timeManipulator.GetTimeSpanFromString(timeframe, units);

            if (timeFromLocal is null)
            {
                await _messages.SendMessageAsync(channel, PhraseKey.TIME_USERTIME_IN_FUTURE_UNPARSABLE, units.ToString(), timeframe);

                return;
            }

            var usersOffset     = user.UtcTimeOffset ?? default;
            var usersLocalTime  = _dateTime.UtcNow + usersOffset;
            var usersFutureTime = usersLocalTime + timeFromLocal;

            await _messages.SendMessageAsync(channel, PhraseKey.TIME_USERTIME_IN_FUTURE, user.Name, usersFutureTime, units.ToString(), timeframe);
        }
示例#11
0
        public async Task OutputMessageTimeAsLocalAsync(ulong messageId, DateTimeOffset?createdTimeOffset, DateTimeOffset?editTimeOffset, MiunieUser user, MiunieChannel channel)
        {
            if (createdTimeOffset is null)
            {
                await _messages.SendMessageAsync(channel, PhraseKey.TIME_NO_MESSAGE, messageId.ToString());

                return;
            }

            var createdTime = createdTimeOffset.Value.UtcDateTime;
            var editTime    = editTimeOffset?.UtcDateTime;

            if (user.UtcTimeOffset.HasValue)
            {
                createdTime += user.UtcTimeOffset.Value;

                if (editTime.HasValue)
                {
                    editTime += user.UtcTimeOffset.Value;
                }
            }

            if (editTime.HasValue)
            {
                await _messages.SendMessageAsync(channel, PhraseKey.TIME_MESSAGE_INFO_EDIT, messageId.ToString(), createdTime, editTime);

                return;
            }

            await _messages.SendMessageAsync(channel, PhraseKey.TIME_MESSAGE_INFO_NO_EDIT, messageId.ToString(), createdTime);
        }
示例#12
0
        public async Task OutputMessageTimeAsLocalAsync(ulong messageId, DateTimeOffset?createdTimeOffset, DateTimeOffset?editTimeOffset, MiunieUser user, MiunieChannel channel)
        {
            if (createdTimeOffset is null)
            {
                await _messages.SendMessageAsync(channel, PhraseKey.TIME_NO_MESSAGE, messageId.ToString());

                return;
            }

            var messageCreated = _timeManipulator.GetDateTimeLocalToUser(createdTimeOffset?.UtcDateTime, user);
            var messageEdited  = _timeManipulator.GetDateTimeLocalToUser(editTimeOffset?.UtcDateTime, user);

            if (messageEdited.HasValue)
            {
                await _messages.SendMessageAsync(channel, PhraseKey.TIME_MESSAGE_INFO_EDIT, messageId.ToString(), messageCreated, messageEdited);

                return;
            }

            await _messages.SendMessageAsync(channel, PhraseKey.TIME_MESSAGE_INFO_NO_EDIT, messageId.ToString(), messageCreated);
        }
示例#13
0
 public async Task RemoveUserData(MiunieUser user, MiunieChannel channel)
 {
     _users.RemoveUser(user);
     await _messages.SendMessageAsync(channel, PhraseKey.USER_PRIVACY_DATA_REMOVED, user.Name);
 }
示例#14
0
 public async Task ShowProfile(MiunieUser user, MiunieChannel c)
 => await _discordMessages.SendMessage(c, user);
示例#15
0
 private void StoreUser(MiunieUser u)
 => _dataStorage.StoreObject(u,
                             GetCollectionById(u.GuildId),
                             GetKeyById(u.Id));
示例#16
0
 public async Task ShowProfile(MiunieUser u, MiunieChannel c)
 {
     var response = _lang.GetPhrase("SHOW_PROFILE", u.Reputation);
     await _discordMessages.SendMessage(response, c);
 }
示例#17
0
 public async Task OutputUserJsonDataAsync(MiunieUser user)
 {
     var userJson = _jsonParser.Serialize(user);
     await _messages.SendDirectFileMessageAsync(user, userJson);
 }