Ejemplo n.º 1
0
        public async Task checkWord(Discord.Commands.SocketCommandContext context, string word)
        {
            if (foundWords.Contains(word))
            {
                await context.Message.AddReactionAsync(new Emoji("🔁"));

                return;
            }
            foreach (char item in word)
            {
                if (!letters.Contains(item))
                {
                    await context.Message.AddReactionAsync(new Emoji("❌"));

                    return;
                }
            }
            using (StreamReader sr = new StreamReader("sowpods.txt"))
            {
                string line = "";
                while ((line = sr.ReadLine()) != null)
                {
                    if (line == word)
                    {
                        if (word.Length >= 7)
                        {
                            await context.Channel.SendMessageAsync($"7+ letter word was found, game over!");

                            addPoints(context.Message.Author.Id, word.Length);
                            string scoreboard = "**Scores:**\n";
                            foreach (KeyValuePair <ulong, int> item in Global.wordGameDic[context.Channel.Id].scoreCard)
                            {
                                scoreboard = scoreboard + Commands.DBTransaction.getUserFromID(item.Key) + ": " + item.Value + "\n";
                            }
                            await context.Channel.SendMessageAsync(scoreboard);

                            Global.wordGameDic.Remove(context.Channel.Id);
                            return;
                        }
                        foundWords.Add(word);
                        addPoints(context.Message.Author.Id, word.Length);
                        string newMessage = message.Content + " " + word;
                        await message.ModifyAsync(msg => msg.Content = newMessage);

                        await context.Message.DeleteAsync();

                        return;
                    }
                }
                await context.Message.AddReactionAsync(new Emoji("❌"));
            }
        }
Ejemplo n.º 2
0
        //this file won't be touched for a while

        /// <summary>
        /// Default command handler for DiscordCommands. Is linked to the MessageRecieved handler.
        /// </summary>
        /// <param name="message">Message object recieved from the MessageRecieved handler.</param>
        public async static Task HandleDiscordCommand(SocketMessage message)
        {
            await Task.Yield();

            CheckForTriggers(message as SocketUserMessage);
            if (message.Content.StartsWith(Config.Prefix))
            {
                string commandName = string.Empty;
                try { commandName = message.Content.Substring(Config.Prefix.Length, message.Content.IndexOf(' ') - Config.Prefix.Length); }
                catch (ArgumentOutOfRangeException) { commandName = message.Content.Substring(Config.Prefix.Length); }
                //by this point we definitely know that this is a command

                var context = new Discord.Commands.SocketCommandContext(Program.Client, message as SocketUserMessage);
                try
                {
                    var command = Config.DiscordCommands.FirstOrDefault(x => x.Aliases.Contains(commandName));
                    if (command != null)
                    {
                        if (PermissionsCheck(message.Author as SocketGuildUser, command.Permissions))
                        {
                            await command.Code.Invoke(context, GetArgs(message.Content));
                        }
                        else
                        {
                            await context.Channel.SendMessageAsync("", embed : ErrorEmbedCreator("Not enough permission", "You do not have the permission to execute this command."));
                        }
                    }
                    else
                    {
                        await message.Channel.SendMessageAsync($"A command with the name `{commandName}` does not exist. Please type in `p.help` to display a list of commands.");
                    }
                }
                catch (Exception ex)
                {
                    await context.Channel.SendMessageAsync("", embed : ErrorEmbedCreator(ex));

                    await new Program().Logger(new LogMessage(LogSeverity.Warning, $"Exception during execution of DiscordCommand \"{commandName}\"", ex.Message, ex));
                }
            }
        }