コード例 #1
0
        public async Task HandleUserMessage(SocketUserMessage message)
        {
            var user = await _userRepository.GetById(message.Author.Id);

            if (user == null)
            {
                user          = new User();
                user.Id       = message.Author.Id;
                user.Username = message.Author.Username;

                Console.WriteLine("adding user");
                await _userRepository.Insert(user);
            }
            else
            {
                Console.WriteLine("User already exists");
            }

            var uniqueWords = GetWordsFromMessage(message);
            var wordColl    = await _wordRepository.GetByWords(uniqueWords);

            await SetUserWordMappings(user, wordColl);

            var chnl = _client.GetChannel(message.Channel.Id) as IMessageChannel;
            await chnl.SendMessageAsync("That message was worth " + wordColl.Sum(x => x.Value) + " points!");
        }