/// <summary>
        /// Handle an executed component
        /// Used for buttons, drop downs, etc.
        /// </summary>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <returns></returns>
        private Task ComponentCommandExecuted(ComponentCommandInfo arg1, Discord.IInteractionContext arg2, Discord.Interactions.IResult arg3)
        {
            if (!arg3.IsSuccess)
            {
                // Defer if not already done:
                try
                {
                    arg2.Interaction.DeferAsync(true).GetAwaiter().GetResult();
                }
                catch
                {
                    // ignore
                }

                switch (arg3.Error)
                {
                case InteractionCommandError.UnmetPrecondition:
                    // Check for userperm error:
                    if (arg3.ErrorReason.Contains("UserPerm"))
                    {
                        arg2.Interaction.FollowupAsync("You do not have permission to execute this command.", ephemeral: true);
                        break;
                    }

                    arg2.Interaction.FollowupAsync("Action Failed\n" + arg3.ErrorReason, ephemeral: true);
                    break;

                case InteractionCommandError.UnknownCommand:
                    arg2.Interaction.FollowupAsync("Unknown action. It may have been recently removed or changed.", ephemeral: true);
                    break;

                case InteractionCommandError.BadArgs:
                    arg2.Interaction.FollowupAsync("The provided values are invalid. (BadArgs)", ephemeral: true);
                    break;

                case InteractionCommandError.Exception:
                    //notify owner if desired:
                    if (arg3.ErrorReason.Contains("Invalid Form Body"))
                    {
                        arg2.Interaction.FollowupAsync("Invalid form body. Please check to ensure that all of your parameters are correct.", ephemeral: true);
                        break;
                    }
                    if (notifyOwnerOnError && !string.IsNullOrEmpty(_config["OwnerID"]))
                    {
                        string error = Format.Bold("Error:") + "\n" + Format.Code(arg3.ErrorReason) + "\n\n" + Format.Bold("Command:") + "\n" + Format.BlockQuote(arg1.Name + " " + DiscordTools.SlashParamToString(arg2));
                        if (error.Length > 2000)
                        {
                            error = error.Substring(0, 2000);
                        }
                        UserExtensions.SendMessageAsync(_client.GetUser(ulong.Parse(_config["OwnerID"])), error);
                    }
                    arg2.Interaction.FollowupAsync("Sorry, Something went wrong...", ephemeral: true);
                    break;

                case InteractionCommandError.Unsuccessful:
                    //notify owner if desired:
                    if (notifyOwnerOnError && !string.IsNullOrEmpty(_config["OwnerID"]))
                    {
                        string error = Format.Bold("Error:") + "\n" + Format.Code(arg3.ErrorReason) + "\n\n" + Format.Bold("Command:") + "\n" + Format.BlockQuote(arg1.Name + " " + DiscordTools.SlashParamToString(arg2));
                        if (error.Length > 2000)
                        {
                            error = error.Substring(0, 2000);
                        }
                        UserExtensions.SendMessageAsync(_client.GetUser(ulong.Parse(_config["OwnerID"])), error);
                    }
                    arg2.Interaction.FollowupAsync("Sorry, Something went wrong...", ephemeral: true);
                    break;

                default:
                    //notify owner if desired:
                    if (notifyOwnerOnError && !string.IsNullOrEmpty(_config["OwnerID"]))
                    {
                        string error = Format.Bold("Error:") + "\n" + Format.Code(arg3.ErrorReason) + "\n\n" + Format.Bold("Command:") + "\n" + Format.BlockQuote(arg1.Name + " " + DiscordTools.SlashParamToString(arg2));
                        if (error.Length > 2000)
                        {
                            error = error.Substring(0, 2000);
                        }
                        UserExtensions.SendMessageAsync(_client.GetUser(ulong.Parse(_config["OwnerID"])), error);
                    }
                    arg2.Interaction.FollowupAsync("Sorry, Something went wrong...");
                    break;
                }
            }

            return(Task.CompletedTask);
        }
Пример #2
0
        public async Task ExecuteAsync([Remainder] string note)
        {
            if (note.Length > 1800)
            {
                await ReplyAsync(embed : SimpleEmbed("Notes can only be 1800 characters maximum.", false));

                return;
            }

            var user = await Context.Database.Users.FirstOrDefaultAsync(x => x.Id == Context.User.Id);

            if (user is null)
            {
                user = new UserProfile(Context.User.Id);
                Context.Database.Users.Add(user);
            }

            user.Notes.Add(new Note(note));

            await ReplyAsync(embed : SimpleEmbed(string.Format("New Self Note Created: {0}", Format.BlockQuote(note))));
        }
        /// <summary>
        /// Handles text command success and failures.
        /// </summary>
        /// <param name="command"></param>
        /// <param name="context"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public async Task CommandExecutedAsync(Optional <CommandInfo> command, ICommandContext context, Discord.Commands.IResult result)
        {
            // if a command isn't found, log that info to console and exit this method
            if (!command.IsSpecified)
            {
                System.Console.WriteLine($"Command not found");
                return;
            }


            // log success to the console and exit this method
            if (result.IsSuccess)
            {
                System.Console.WriteLine($"Command Executed.");
                return;
            }
            else if (result.ErrorReason.Contains("Missing Permissions"))
            {
                await context.Channel.SendMessageAsync($"I do not have permission to carry out this action. I need permission to Send Messages, Embed Links, Attach Files, Add Reactions, Read Message History, and Manage Messages in this channel.");

                return;
            }
            else if (result.ErrorReason.Contains("Cannot reply without permission to read message history"))
            {
                await context.Channel.SendMessageAsync("I need permission to read message history in order to reply to a message and carry out the command.");

                return;
            }
            else if (result.ErrorReason.Contains("timed out"))
            {
                await context.Channel.SendMessageAsync($"Your command timed out. This may be because the bot is overloaded. Please try again later.");

                //report to owner anyway.
            }
            else
            {
                // failure scenario, let's let the user know
                await context.Channel.SendMessageAsync($"Sorry, Something went wrong...");
            }

            //notify owner if desired:
            if (notifyOwnerOnError && !string.IsNullOrEmpty(_config["OwnerID"]))
            {
                string error = Format.Bold("Error:") + "\n" + result.Error + "\n" + Format.Code(result.ErrorReason) + "\n\n" + Format.Bold("Command:") + "\n" + Format.BlockQuote(context.Message.ToString());
                if (error.Length > 2000)
                {
                    error = error.Substring(0, 2000);
                }
                await Discord.UserExtensions.SendMessageAsync(_client.GetUser(ulong.Parse(_config["OwnerID"])), error);
            }
        }
Пример #4
0
        public async Task ExecuteAsync(int id, [Remainder] string edit)
        {
            var user = await Context.Database.Users.FirstOrDefaultAsync(x => x.Id == Context.User.Id);

            if (user is null || user.Notes.Count < 1)
            {
                await ReplyAsync(embed : SimpleEmbed("You have no self notes!", false));

                return;
            }

            var note = user.Notes.FirstOrDefault(x => x.Id == id);

            if (note is null)
            {
                await ReplyAsync(embed : SimpleEmbed("The note Id you specified does not exist! Please double-check & try again.", false));

                return;
            }

            if (edit.Length > 1800)
            {
                await ReplyAsync(embed : SimpleEmbed("Notes can only be 1800 characters maximum.", false));

                return;
            }

            note.Text = edit;

            await ReplyAsync(embed : SimpleEmbed(string.Format("Self Note (ID: {0}) Updated: {1}", Format.Bold(id.ToString()), Format.BlockQuote(edit))));
        }