Пример #1
0
        /// <summary>
        /// Handles a message sent by a player in the appropriate channel.
        /// </summary>
        /// <param name="message">The message context from which the author and content can be obtained.</param>
        /// <param name="gamesDB">The games database in case any player data has to be modified.</param>
        /// <param name="client">The Discord client used to parse users.</param>
        /// <param name="funConfiguration">The configuration file containing relevant game information.</param>
        /// <returns>A <c>Task</c> object, which can be awaited until the method completes successfully.</returns>

        public async Task HandleMessage(IMessage message, GamesDB gamesDB, DiscordSocketClient client, FunConfiguration funConfiguration)
        {
            if (message.Channel is IDMChannel)
            {
                return;
            }
            Player player = gamesDB.GetOrCreatePlayer(message.Author.Id);

            string msg = message.Content.Replace("@", "@-");

            if (msg.ToLower() == "pass")
            {
                if (game.LastUserInteracted == message.Author.Id)
                {
                    await message.Channel.SendMessageAsync($"It's not your turn, {message.Author.Mention}!");

                    return;
                }

                game.LastUserInteracted = message.Author.Id;
                await message.Channel.SendMessageAsync($"{message.Author.Mention} passed their turn!");

                await message.DeleteAsync();

                return;
            }

            if (msg.ToLower() == "mistakes")
            {
                await message.Channel.SendMessageAsync($"Mistakes: {MistakesExpression()}");

                return;
            }
            if (msg.ToLower() == "lives")
            {
                await message.Channel.SendMessageAsync($"Lives: {LivesExpression()}");

                return;
            }

            if (msg.ToLower().StartsWith("guess"))
            {
                string[] args = msg.Split(" ");
                if (args.Length == 1)
                {
                    await message.Channel.SendMessageAsync(DiscordifyGuess());

                    return;
                }
                if (message.Author.Id == game.Master)
                {
                    await message.Channel.SendMessageAsync("The game master isn't allowed to guess their own word.");

                    return;
                }
                if (game.LastUserInteracted == message.Author.Id)
                {
                    await message.Channel.SendMessageAsync("You've already guessed! Let someone else play, if it's only you, have the master pass their turn.");

                    return;
                }
                if (!Guess.Contains('_'))
                {
                    await message.Channel.SendMessageAsync($"The term was already guessed! You're late to the party. Waiting for the Game Master to change it.");

                    return;
                }
                if (Lives < 1)
                {
                    await message.Channel.SendMessageAsync($"You're out of lives! Choose a new term before continuing.");

                    return;
                }
                string newGuess = string.Join(' ', args[1..]);