Пример #1
0
        public async Task <Message> Respond(Message message)
        {
            var createUser = CreateUser(message.Sender);
            var fullText   = message.MessageParts.Skip(1).Select(x => x.Text);

            var mentionedUsers = message.MessageParts.Skip(1)
                                 .Where(x => x.MessageType == MessageType.PersonMention)
                                 .Select(x => x.UserId)
                                 .ToArray();

            var commands = string.Join("", fullText)
                           .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (commands.Length < 2)
            {
                return(new Message
                {
                    Text = "Please specify a command. Possible values are get, set, and delete."
                });
            }

            var meId        = message.Sender.UserId;
            var userIsAdmin = UserIsAdmin(meId);
            var command     = commands[1];

            commands = commands.Skip(2).ToArray();

            await createUser.ConfigureAwait(false);

            return(new Message
            {
                Text = command.ToLowerInvariant() switch
                {
                    Actions.Get => _userLocationGetter.GetUserLocation(commands, mentionedUsers, meId),
                    Actions.Set => await _userLocationSetter.SetUserLocation(commands, mentionedUsers, userIsAdmin, meId),
                    Actions.Delete => await _userLocationDeleter.DeleteUserLocation(commands, mentionedUsers, userIsAdmin,
                                                                                    meId),
                    _ => "Unknown command. Possible values are get, set, and delete."
                }
            });
Пример #2
0
 private async Task WhenSetUserLocationIsCalled()
 {
     _result = await _subject.SetUserLocation(_commands, _mentionedUsers, _userIsAdmin, _meId);
 }