Пример #1
0
        public async Task Weed([Remainder] string filename = "dir")
        {
            string path = Path.Combine("data\\media\\" + filename);

            if (filename.ToLower() == "dir")
            {
                string filenames = "";
                IEnumerable <string> mediaFolderContents = Directory.EnumerateFiles("data\\media\\");
                ulong numFiles = (ulong)mediaFolderContents.Count();

                if (numFiles == 0)
                {
                    await Nitori.Say(Context.Channel, ResponseManager.GetLine("MediaFolderEmpty"));

                    return;
                }
                foreach (string file in mediaFolderContents)
                {
                    filenames = filenames + file + "\n";
                }
                await Nitori.Say(Context.Channel, ResponseManager.GetLine("MediaFolderDisplay") +
                                 ResponseManager.GetLine("MediaFolderCodeblock"), filenames, numFiles);

                return;
            }
            else if (File.Exists(path))
            {
                await Context.Channel.SendFileAsync(Path.Combine("data\\media\\" + filename));

                return;
            }
            await Nitori.Say(Context.Channel, ResponseManager.GetLine("FileNotFound"), filename);
        }
Пример #2
0
        /// <summary>
        /// Parses command errors from the given CommandError
        /// </summary>
        /// <param name="context">The message behind the command</param>
        /// <param name="error">The type of error</param>
        /// <param name="reason">The message if and error arises</param>
        /// <returns></returns>
        private async Task ParseCommandErrors(ICommandContext context, string command, CommandError?error, string reason)
        {
            string author = context.Message.Author.Username;
            string prefix = Nitori.Config.separatePrefix ? Nitori.Config.prefix + " " : Nitori.Config.prefix;  // {3} argument is prefix, compensate for having a spearated prefix

            switch (error)
            {
            case (CommandError.Exception | CommandError.Unsuccessful):
                await CommandFailed(context, command, reason);

                break;

            case (CommandError.UnknownCommand):
                await Nitori.Say(context.Channel, ResponseManager.GetLine("UnknownCommandError"), command, reason, author, prefix);

                break;

            case (CommandError.UnmetPrecondition):
                if (reason == "")
                {
                    await Nitori.Say(context.Channel, ResponseManager.GetLine("CommandPermissionsError"), command, reason, author);
                }
                break;

            default:
                await CommandFailed(context, command, reason);

                break;
            }
        }
Пример #3
0
        /// <summary>
        /// Fire when a command fails to execute due to an exception
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="command"></param>
        /// <param name="reason"></param>
        /// <returns></returns>
        private async Task CommandFailed(ICommandContext context, string command = "", string reason = "")
        {
            IMessageChannel channel = context.Channel;
            string          author  = context.Message.Author.Username;

            if (!string.IsNullOrEmpty(command))
            {
                command = "'" + command + "' ";
            }
            string reasonSentence = ResponseManager.GetLine("NoReasonGiven");

            if (!string.IsNullOrEmpty(reason))
            {
                reasonSentence = ResponseManager.GetLine("ReasonGiven");
            }
            await Nitori.Say(channel, ResponseManager.GetLine("CommandExecutionError") + reasonSentence, command, reason, author);
        }
Пример #4
0
        public async Task Reload()
        {
            await ReplyAsync(ResponseManager.GetLine("BotReload"));

            Nitori.ReloadConfig();
        }