/// <summary>
        /// Deletes the custom command.
        /// </summary>
        /// <param name="custCom">The customer COM.</param>
        /// <returns>true if the operation was sucessful </returns>
        /// <exception cref="ArgumentException">
        /// Argument cannot be null
        /// or
        /// Invalid custom command object. Properties were null
        /// </exception>
        public bool DeleteCustomCommand(CustomAudioCommandModel custCom)
        {
            if (custCom == null)
            {
                throw new ArgumentException("Argument cannot be null");
            }
            else if (custCom.CommandName == null || custCom.Filepath == null)
            {
                throw new ArgumentException("Invalid custom command object. Properties were null");
            }

            bool success;

            try
            {
                FileInfo fileInfo = new FileInfo(custCom.Filepath);
                if (fileInfo.Exists)
                {
                    fileInfo.Delete();
                }

                success = customAudioCommands.Remove(custCom);
            }
            catch (SystemException sysEx)
            {
                Program.Client.DebugLogger.Error("Could not delete file: " + sysEx.Message);
                success = false;
            }

            return(success);
        }
        /// <summary>
        /// Renames the custom command.
        /// </summary>
        /// <param name="oldCommandName">Old name of the command.</param>
        /// <param name="newCommandName">New name of the command.</param>
        /// <returns>true if successful</returns>
        /// <exception cref="ArgumentException">Could not find old command in the list</exception>
        public bool RenameCustomCommand(string oldCommandName, string newCommandName)
        {
            CustomAudioCommandModel custCom = GetAudioFileForCommand(oldCommandName);

            if (custCom == null)
            {
                throw new ArgumentException("Could not find old command in the list");
            }

            customAudioCommands.Remove(custCom);
            customAudioCommands.Add(new CustomAudioCommandModel(newCommandName, custCom.Filepath));

            return(true);
        }
Exemple #3
0
        public async Task PlayCustom(CommandContext ctx, [RemainingText, Description("Name of the command")] string customCommandName)
        {
            CustomAudioCommandModel custCom = CustomAudioCommandFile.Instance.GetAudioFileForCommand(customCommandName);

            if (custCom == null)
            {
                // file does not exist
                await ctx.RespondAsync("Could not find a custom command with that name :^(");

                return;
            }

            ctx.Client.DebugLogger.Info(string.Format("{0} executed custom command: {1}", ctx.User.Username, customCommandName));
            await Play(ctx, custCom.Filepath);
        }
Exemple #4
0
        public async Task DeleteCustom(CommandContext ctx, [RemainingText, Description("Name of the command")] string customCommandName)
        {
            CustomAudioCommandModel custCom = CustomAudioCommandFile.Instance.GetAudioFileForCommand(customCommandName);

            if (custCom == null)
            {
                await ctx.RespondAsync(string.Format("Could not find a command with the name `{0}` :^(", customCommandName));

                return;
            }

            if (CustomAudioCommandFile.Instance.DeleteCustomCommand(custCom))
            {
                await ctx.RespondAsync(string.Format("Custom command `{0}` was deleted :^)", customCommandName));
            }
            else
            {
                await ctx.RespondAsync(string.Format("Custom command `{0}` could not be deleted :^(", customCommandName));
            }
        }
Exemple #5
0
        public async Task AddCustom(CommandContext ctx, [RemainingText, Description("Name of the command")] string customCommandName)
        {
            CustomAudioCommandModel custCom = CustomAudioCommandFile.Instance.GetAudioFileForCommand(customCommandName);

            if (custCom != null)
            {
                await ctx.RespondAsync("A command with that name already exists :^(");

                return;
            }

            if (await FileDownloadUtil.DownloadFileFromDiscordMessageAsync(ctx))
            {
                DiscordAttachment attachment      = ctx.Message.Attachments[0];
                string            customAudioPath = string.Format(@"AudioFiles\{0}", attachment.FileName);

                CustomAudioCommandFile.Instance.AddCustomCommand(customCommandName, customAudioPath);
                await ctx.RespondAsync(string.Format("Custom command ```{0}``` was added :^)", customCommandName));
            }
        }
 /// <summary>
 /// Adds the custom command.
 /// </summary>
 /// <param name="commandToAdd">The command to add.</param>
 public void AddCustomCommand(CustomAudioCommandModel commandToAdd)
 {
     customAudioCommands.Add(commandToAdd);
 }