Beispiel #1
0
        public static ActionRunFactory Find(IServiceProvider services, RequestContext context,
                                            SocketInteraction interaction)
        {
            if (interaction is SocketSlashCommand slashCommand)
            {
                return(new ActionSlashRunFactory(services, context, slashCommand));
            }

            if (interaction is SocketMessageCommand msgCommand)
            {
                return(new ActionMessageRunFactory(services, context, msgCommand));
            }

            if (interaction is SocketUserCommand userCommand)
            {
                return(new ActionUserRunFactory(services, context, userCommand));
            }

            if (interaction is SocketMessageComponent component)
            {
                if (component.Data.CustomId.StartsWith('#') ||
                    component.Data.CustomId.StartsWith('^')) //# = refresh component, ^ = refresh into new component
                {
                    return(new ActionRefreshRunFactory(services, context, component));
                }
                return(new ActionComponentRunFactory(services, context, component));
            }

            if (interaction is SocketAutocompleteInteraction autoComplete)
            {
                return(new ActionAutoCompleteRunFactory(services, context, autoComplete));
            }

            return(null);
        }
Beispiel #2
0
        private async Task RestartBot(SocketInteraction interaction, ulong botId)
        {
            if (interaction.User.Id != Config.ReversesId)
            {
                await interaction.PrintError();

                return;
            }

            else if (!Bots.List.Contains(botId))
            {
                await interaction.PrintError("That can't be restarted");

                return;
            }

            Bots.RestartBot(botId);
            var botAccount = _reversesGuild.GetUser(botId);
            await interaction.RespondAsync(embed : new EmbedBuilder()
                                           .WithAuthor(new EmbedAuthorBuilder()
                                                       .WithName($"Restarted {botAccount.Username}")
                                                       .WithIconUrl(botAccount.GetAvatarUrl()))
                                           .WithColor(Embeds.Green)
                                           .Build());
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    SocketInteraction socketInteraction = new SocketInteraction();

                    socketInteraction.Connect();

                    socketInteraction.Login();

                    Thread acceptMessageManager = new Thread(new ThreadStart(() =>
                    {
                        while (true)
                        {
                            socketInteraction.getAnswer();
                        }
                    }));

                    acceptMessageManager.Start();

                    while (true)
                    {
                        socketInteraction.sendMessage();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Beispiel #4
0
        private async Task HandleInteraction(SocketInteraction interaction)
        {
            try
            {
                // Create an execution context that matches the generic type parameter of your InteractionModuleBase<T> modules.
                var context = new SocketInteractionContext(_client, interaction);

                // Execute the incoming command.
                var result = await _handler.ExecuteCommandAsync(context, _services);

                if (!result.IsSuccess)
                {
                    switch (result.Error)
                    {
                    case InteractionCommandError.UnmetPrecondition:
                        // implement
                        break;

                    default:
                        break;
                    }
                }
            }
            catch
            {
                // If Slash Command execution fails it is most likely that the original interaction acknowledgement will persist. It is a good idea to delete the original
                // response, or at least let the user know that something went wrong during the command execution.
                if (interaction.Type is InteractionType.ApplicationCommand)
                {
                    await interaction.GetOriginalResponseAsync().ContinueWith(async(msg) => await msg.Result.DeleteAsync());
                }
            }
        }
Beispiel #5
0
 private async Task InteractionCreatedAsync(SocketInteraction arg)
 {
     if (arg is SocketSlashCommand command)
     {
         await SlashCommands.ExecuteCommandAsync(_services, command);
     }
 }
Beispiel #6
0
 private async Task InteractionHandler(SocketInteraction arg)
 {
     if (arg.Type == InteractionType.ApplicationCommand)
     {
         await _commands.ExecuteAsync(arg);
     }
 }
Beispiel #7
0
 public DiscordBotContext(DiscordSocketClient client, SocketInteraction interaction, IUserMessage message)
 {
     this.Client      = client;
     this.Interaction = interaction;
     this.MessageData = BotMessageData.Create(interaction, message, this.Settings);
     this.Message     = message;
 }
Beispiel #8
0
 private async Task OnInteractionAsync(SocketInteraction interaction)
 {
     _ = Task.Run(async() =>
     {
         var context = new ShardedInteractionContext(_client, interaction);
         await _service.ExecuteCommandAsync(context, _provider);
     });
     await Task.CompletedTask;
 }
Beispiel #9
0
 /// <summary>
 /// Creates an embed with a red background and a message
 /// </summary>
 public static async Task PrintError(this SocketInteraction interaction, string message = null)
 {
     await interaction.RespondAsync(embed : new EmbedBuilder()
                                    .WithColor(Red)
                                    .WithAuthor(new EmbedAuthorBuilder()
                                                .WithName("Error"))
                                    .WithDescription(message == null ? "I'm sorry. I'm afraid I can't let you do that." : message)
                                    .Build(), ephemeral : true);
 }
        private async Task InteractionCreated(SocketInteraction interaction)
        {
            // I am not sure if bot's can trigger interactions/slash commands, but if they can we want to ignore them
            if (interaction.User.IsBot)
            {
                return;
            }

            var context = new SocketInteractionContext(_client, interaction);
            await _commands.ExecuteCommandAsync(context, _services);
        }
Beispiel #11
0
        private async Task Client_InteractionCreated(SocketInteraction interaction)
        {
            // Checking the type of this interaction
            switch (interaction)
            {
            // Slash commands
            case SocketSlashCommand commandInteraction:
                await BotSlashCommandHandler(commandInteraction);

                break;
            }
        }
        private async Task OnInteractionAsync(SocketInteraction interaction)
        {
            switch (interaction)
            {
            // Slash Command
            case SocketSlashCommand commandInteraction:
                // /rt
                if (commandInteraction.CommandName == "rt")
                {
                    if (commandInteraction.Data.Options == null)
                    {
                        await commandInteraction.RespondAsync(embed : new EmbedBuilder()
                                                              .WithColor(EmbedUtils.Red)
                                                              .WithTitle("Rotten Tomatoes")
                                                              .WithImageUrl("https://cdn.discordapp.com/attachments/735282082963652749/891459194820100116/ezgif.com-gif-maker.gif")
                                                              .WithDescription("To search for a movie...\n`/rt <name of movie>`\nThen click on the movie\n\nTo view the top box office...\n`/boxoffice`\n\nIf you need help, join the support server (link below)")
                                                              .WithThumbnailUrl(EmbedUtils.Logo)
                                                              .Build(),
                                                              component : new ComponentBuilder()
                                                              .WithButton("Support Server", style : ButtonStyle.Link, url : "https://discord.gg/AM2SvZKZgR")
                                                              .WithButton("Bot Invite Link", style : ButtonStyle.Link, url : "https://discord.com/api/oauth2/authorize?client_id=477287091798278145&permissions=67584&scope=bot%20applications.commands")
                                                              .WithButton("GitHub", style : ButtonStyle.Link, url : "https://github.com/WilliamWelsh/RottenTomatoes")
                                                              .Build());
                    }
                    else
                    {
                        await commandInteraction.DeferAsync();

                        await SearchHandler.SearchRottenTomatoes(commandInteraction);
                    }
                }

                // /boxoffice
                else if (commandInteraction.CommandName == "boxoffice")
                {
                    await commandInteraction.DeferAsync();

                    await BoxOffice.Print(commandInteraction);
                }
                break;

            // Button Click
            case SocketMessageComponent componentInteraction:
                await SearchHandler.PrintToInteraction(componentInteraction);

                break;

            default:
                break;
            }
        }
Beispiel #13
0
        public static BotMessageData Create(SocketInteraction interaction, IUserMessage message, Settings serverSettings)
        {
            var preferEmbeds = ((interaction.Channel as SocketTextChannel)?.GetCurrentUserPermissions().EmbedLinks ?? false) && serverSettings.PreferEmbeds;

            var messageData = new BotMessageData(BotType.Discord)
            {
                DiscordInteraction = interaction,
                UserName           = interaction.User.Username,
                UserId             = interaction.User.Id.ToString(),
                UserHost           = interaction.User.Id.ToString(),
                Channel            = interaction.Channel.Id.ToString(),
                Server             = (interaction.Channel as IGuildChannel)?.GuildId.ToString() ?? "private",
                MessageId          = message?.Id.ToString(),
                Format             = preferEmbeds ? "embed" : string.Empty,
                Sasshat            = serverSettings.SasshatEnabled,
                Content            = message?.Content ?? serverSettings.Prefix + ((interaction as SocketCommandBase)?.CommandName ?? (interaction as SocketMessageComponent)?.Data.CustomId),
                Prefix             = serverSettings.Prefix,
                TargetUserName     = (interaction as SocketUserCommand)?.Data.Member.UserOrNickname(),
                TargetUserId       = (interaction as SocketUserCommand)?.Data.Member.Id.ToString(),
            };

            if (interaction is SocketMessageCommand messageCommand)
            {
                messageData.Content = messageCommand.Data.Message.Content;
            }
            else if (interaction is SocketSlashCommand slashCommand)
            {
                messageData.RequestOptions = new Dictionary <string, string>();
                foreach (var option in slashCommand.Data.Options)
                {
                    if (option.Type == ApplicationCommandOptionType.SubCommand)
                    {
                        messageData.Content += $" {option.Name}";
                        messageData.RequestOptions.Add(option.Name, option.Name);
                    }
                    else
                    {
                        messageData.Content += $" {option.Value}";
                        messageData.RequestOptions.Add(option.Name, option.Value.ToString());
                    }
                }
            }

            // if the user does not have @everyone permissions, block its use
            if (!(interaction.User as SocketGuildUser)?.GetPermissions(interaction.Channel as SocketGuildChannel).MentionEveryone ?? false)
            {
                messageData.Content = messageData.Content.Replace("@everyone", "@every\x200Bone").Replace("@here", "@he\x200Bre");
            }

            return(messageData);
        }
Beispiel #14
0
        protected override async Task HandleInteractionAsync(SocketInteraction interaction)
        {
            if (interaction.User.Id == Discord.CurrentUser.Id)
            {
                return;
            }

            ulong messageId;

            switch (interaction)
            {
            case SocketMessageComponent componentMsg:
                messageId = componentMsg.Message.Id;
                break;

            default:
                return;
            }

            if (!_interactionCallbacks.TryGetValue(messageId, out var callback))
            {
                return;
            }

            if (!await callback.Criterion.JudgeAsync(callback.Context, interaction))
            {
                return;
            }

            async Task RemoveCallbackWrapper()
            {
                if (await callback.HandleCallbackAsync(interaction).ConfigureAwait(false))
                {
                    RemoveInteractionCallback(messageId);
                }
            }

            switch (callback.RunMode)
            {
            case Commands.RunMode.Async:
                _ = RemoveCallbackWrapper();
                break;

            default:
                await RemoveCallbackWrapper();

                break;
            }
        }
Beispiel #15
0
        public async Task HandleInteractionAsync(SocketInteraction interaction)
        {
            switch (interaction)
            {
            case SocketSlashCommand slashCommand:
                await HandleSlashCommand(slashCommand);

                break;

            case SocketAutocompleteInteraction autocomplete:
                await HandleAutocomplete(autocomplete);

                break;
            }
        }
Beispiel #16
0
        // For better functionality & a more developer-friendly approach to handling any kind of interaction, refer to:
        // https://discordnet.dev/guides/int_framework/intro.html
        private async Task InteractionCreatedAsync(SocketInteraction interaction)
        {
            // safety-casting is the best way to prevent something being cast from being null.
            // If this check does not pass, it could not be cast to said type.
            if (interaction is SocketMessageComponent component)
            {
                // Check for the ID created in the button mentioned above.
                if (component.Data.CustomId == "unique-id")
                {
                    await interaction.RespondAsync("Thank you for clicking my button!");
                }

                else
                {
                    Console.WriteLine("An ID has been received that has no handler!");
                }
            }
        }
Beispiel #17
0
        private async Task Client_InteractionCreated(SocketInteraction interaction)
        {
            switch (interaction)
            {
            case SocketSlashCommand commandInteraction:
                await HandleSlash(commandInteraction).ConfigureAwait(false);

                break;

            case SocketMessageComponent componentInteraction:
                await HandleComponent(componentInteraction).ConfigureAwait(false);

                break;

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #18
0
        private async Task OnInteractionCreated(SocketInteraction interaction)
        {
            switch (interaction)
            {
            // Slash Commands
            case SocketSlashCommand slashCommand:

                // /restart
                if (slashCommand.CommandName == "restart")
                {
                    await RestartBot(interaction, ((SocketGuildUser)slashCommand.Data.Options.ElementAt(0).Value).Id);
                }

                // /avatar
                else if (slashCommand.CommandName == "avatar")
                {
                    var target = ((SocketGuildUser)slashCommand.Data.Options.ElementAt(0).Value);
                    await slashCommand.RespondAsync(target.GetAvatarUrl() ?? target.GetDefaultAvatarUrl());
                }

                break;

            // User Commands (context menut)
            case SocketUserCommand userCommand:

                // Restart command
                if (userCommand.CommandName == "Restart")
                {
                    await RestartBot(interaction, userCommand.Data.Member.Id);
                }

                // Avatar command
                else if (userCommand.CommandName == "Avatar")
                {
                    await userCommand.RespondAsync(userCommand.Data.Member.GetAvatarUrl());
                }

                break;

            default:
                break;
            }
        }
        private async Task HandleInteraction(SocketInteraction arg)
        {
            try
            {
                // Create an execution context that matches the generic type parameter of your InteractionModuleBase<T> modules
                var ctx = new SocketInteractionContext(_client, arg);
                await _interactionService.ExecuteCommandAsync(ctx, _serviceProvider);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error trying to handle interaction (e.g., from a slash command).");

                // If a Slash Command execution fails it is most likely that the original interaction acknowledgement will persist. It is a good idea to delete the original
                // response, or at least let the user know that something went wrong during the command execution.
                if (arg.Type == InteractionType.ApplicationCommand)
                {
                    await arg.GetOriginalResponseAsync().ContinueWith(async(msg) => await msg.Result.DeleteAsync());
                }
            }
        }
    private async Task HandleInteraction(SocketInteraction arg)
    {
        try
        {
            // Create an execution context that matches the generic type parameter of your InteractionModuleBase<T> modules
            var ctx = new ShardedInteractionContext(Client, arg);
            await _interactionService.ExecuteCommandAsync(ctx, _provider);
        }
        catch (Exception ex)
        {
            Logger.LogError(ex, "Exception occurred whilst attempting to handle interaction.");

            if (arg.Type == InteractionType.ApplicationCommand)
            {
                var msg = await arg.GetOriginalResponseAsync();

                await msg.DeleteAsync();
            }
        }
    }
Beispiel #21
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    SocketInteraction socketInteraction = new SocketInteraction();

                    // connecting to remote host
                    socketInteraction.Connect();

                    socketInteraction.Login();

                    Thread acceptMessageManager = new Thread(new ThreadStart(() =>
                    {
                        try
                        {
                            while (true)
                            {
                                socketInteraction.getAnswer();
                            }
                        } catch (Exception exc)
                        {
                            Console.WriteLine("Server error: " + exc);
                            Environment.Exit(0);
                        }
                    }));

                    acceptMessageManager.Start();

                    while (true)
                    {
                        socketInteraction.sendMessage();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        private async Task HandleInteraction(SocketInteraction arg)
        {
            Console.WriteLine("Slash Command Executed");
            try
            {
                // Create an execution context that matches the generic type parameter of your InteractionModuleBase<T> modules
                var ctx = new ShardedInteractionContext(_client, arg);
                await _interact.ExecuteCommandAsync(ctx, _services);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                // If a Slash Command execution fails it is most likely that the original interaction acknowledgement will persist. It is a good idea to delete the original
                // response, or at least let the user know that something went wrong during the command execution.
                if (arg.Type == InteractionType.ApplicationCommand)
                {
                    await arg.GetOriginalResponseAsync().ContinueWith(async(msg) => await msg.Result.DeleteAsync());
                }
            }
        }
        private async Task OnInteraction(SocketInteraction interaction)
        {
            if (interaction is SocketMessageComponent component)
            {
                /* Message hasnt been interacted with in over half a minute */
                if (_activeMessages.FirstOrDefault(x => x.DiscordMessageId == component.Message.Id) == null)
                {
                    await component.ModifyOriginalResponseAsync(x => x.Content = "This message is no longer interactable.");

                    return;
                }

                switch (component.Data.CustomId)
                {
                case "first":
                    await GoToFirstPageAsync(component.Message.Id);

                    break;

                case "previous":
                    await GoToPreviousPageAsync(component.Message.Id);

                    break;

                case "next":
                    await GoToNextPageAsync(component.Message.Id);

                    break;

                case "last":
                    await GoToLastPageAsync(component.Message.Id);

                    break;
                }

                ResetTimer(component.Message.Id);
            }
        }
Beispiel #24
0
        // interaction handler
        public async Task InteractionRecieved(SocketInteraction arg)
        {
            // checking interaction type
            switch (arg.Type)
            {
            // slashcommand passing through
            case InteractionType.ApplicationCommand:
                await Commands.MySlashCommandHandler(arg);

                break;

            // button passing through
            case InteractionType.MessageComponent:
                await ButtonParser.OnButtonPress(arg);

                break;

            // other bullshit (unhandled)
            default:
                Console.WriteLine("Unsupported interaction type: " + arg.Type);
                break;
            }
        }
Beispiel #25
0
        /// <summary>
        /// Processes and executes the interaction command.
        /// </summary>
        /// <param name="socketInteraction">The <see cref="SocketInteraction"/> object.</param>
        /// <returns>A task that represents the asynchronous execution operation. The task contains the result of the command execution.</returns>
        public async Task HandleInteractionAsync(SocketInteraction socketInteraction)
        {
            try
            {
                bool isInteractiveServiceCallback = socketInteraction is SocketMessageComponent messageComponent && InteractiveService.Callbacks.ContainsKey(messageComponent.Message.Id);
                if (!isInteractiveServiceCallback)
                {
                    SocketInteractionContext context = new(Client, socketInteraction);
                    await InteractionCommands.ExecuteCommandAsync(context, Services);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Logger.Error(ex);

                // If a Slash Command execution fails it is most likely that the original interaction acknowledgement will persist.
                // It is a good idea to delete the original response, or at least let the user know that something went wrong during the command execution.
                if (socketInteraction.Type == InteractionType.ApplicationCommand)
                {
                    await socketInteraction.GetOriginalResponseAsync().ContinueWith(async(msg) => await msg.Result.DeleteAsync());
                }
            }
        }
Beispiel #26
0
        public async Task <bool> HandleCallbackAsync(SocketInteraction interaction)
        {
            var msgComponent = interaction as SocketMessageComponent;

            switch (msgComponent.Data.CustomId)
            {
            case FirstId:
                _page = 1;
                break;

            case NextId:
            {
                if (_page >= _pages)
                {
                    return(false);
                }

                ++_page;
                break;
            }

            case PreviousId:
            {
                if (_page <= 1)
                {
                    return(false);
                }

                --_page;
                break;
            }

            case LastId:
                _page = _pages;
                break;

            case StopId:
                await Message.DeleteAsync().ConfigureAwait(false);

                return(true);

            case JumpId:
            {
                _ = Task.Run(async() =>
                    {
                        var criteria = new Criteria <SocketMessage>()
                                       .AddCriterion(new EnsureSourceChannelCriterion())
                                       .AddCriterion(new EnsureFromUserCriterion(interaction.User.Id))
                                       .AddCriterion(new EnsureIsIntegerCriterion());

                        var response = await Interactive.NextMessageAsync(Context, criteria, TimeSpan.FromSeconds(15));
                        var request  = int.Parse(response.Content);
                        if (request < 1 || request > _pages)
                        {
                            _ = response.DeleteAsync().ConfigureAwait(false);
                            await Interactive.ReplyAndDeleteAsync(Context, Options.Stop.Name);
                            return;
                        }
                        _page = request;
                        _     = response.DeleteAsync().ConfigureAwait(false);
                        await RenderAsync(msgComponent).ConfigureAwait(false);
                    });

                break;
            }

            case InfoId:
                await Interactive.ReplyAndDeleteAsync(Context, Options.InformationText, timeout : Options.InfoTimeout);

                return(false);
            }

            await RenderAsync(msgComponent).ConfigureAwait(false);

            return(false);
        }
Beispiel #27
0
        public async static Task MySlashCommandHandler(SocketInteraction arg)
        {
            InteractionResponseType param = InteractionResponseType.ChannelMessageWithSource;

            switch ((arg as SocketSlashCommand).Data.Name)
            {
            case "help":
            {
                try
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Previous page", $"id.0|{(arg as SocketSlashCommand).User.Id}", ButtonStyle.Danger, null, null, true)
                             .WithButton("Next page", $"id.1|{(arg as SocketSlashCommand).User.Id}", ButtonStyle.Success)
                             .WithButton("Our website", null, ButtonStyle.Link, null, "https://terrariabuilders.com/")
                             .WithButton("Become a voter!", $"id.voter|{(arg as SocketSlashCommand).User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Title        = "Development & Source",
                        Color        = Color.Blue,
                        Description  = $"The Grand Design has been developed by the Terraria Builders Community to bring utility in Terraria and Discord to new heights!",
                        ThumbnailUrl = "https://cdn.discordapp.com/attachments/694988142616379432/849374178343518238/sbcdetailed.gif",
                        Author       = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "TGD Help | Scroll through pages with the buttons below.",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"Page 1 • The Grand Design!",
                        },
                        Fields =
                        {
                            new EmbedFieldBuilder()
                            {
                                Name  = "Commands",
                                Value = "All commands are featured in `!commands`.  Check it out! \nTGD also introduces slashcommands for easy access. \nType `'/'` to get a preview of all commands!"
                            },
                            new EmbedFieldBuilder()
                            {
                                Name  = "DM Support",
                                Value = "To get into contact with the staff of this server in an easy way, \nsend a DM to the Grand Design!"
                            },
                            new EmbedFieldBuilder()
                            {
                                Name  = "About TBC",
                                Value = "All information about the Terraria Builders Community is provided on other pages. \nUse the buttons to navigate them!"
                            }
                        }
                    };
                    await arg.RespondAsync("", false, eb.Build(), param, false, null, null, ct.Build());
                }
                catch { Console.WriteLine("Error executing slash command"); }
            }
            break;

            case "vote":
            {
                try
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Click here to vote", null, ButtonStyle.Link, null, "https://terrariabuilders.com/vote")
                             .WithButton("Become a voter!", $"id.voter|{(arg as SocketSlashCommand).User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color       = Color.Blue,
                        Description = $"Thank you for your contribution! You can get the voter role through the buttons below to be reminded to vote every day.",
                        Author      = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "Vote for TBC!",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"{DateTime.Now}",
                        },
                    };
                    await arg.RespondAsync("", false, eb.Build(), param, false, null, null, ct.Build());
                }
                catch { Console.WriteLine("Error executing slash command"); }
            }
            break;

            case "notifications":
            {
                try
                {
                    IEmote eEvent    = new Emoji("🗓");
                    IEmote eAnnounce = new Emoji("📣");
                    IEmote eVoter    = new Emoji("🎫");
                    var    ct        = new ComponentBuilder()
                                       .WithButton("Events", $"id.event|{(arg as SocketSlashCommand).User.Id}", ButtonStyle.Primary, eEvent)
                                       .WithButton("Announcements", $"id.announce|{(arg as SocketSlashCommand).User.Id}", ButtonStyle.Primary, eAnnounce)
                                       .WithButton("Voting", $"id.voter|{(arg as SocketSlashCommand).User.Id}", ButtonStyle.Primary, eVoter);
                    var eb = new EmbedBuilder()
                    {
                        Color       = Color.Blue,
                        Description = $"You can assign any of the below roles to be mentioned when updates/reminders are sent in respective channels!",
                        Author      = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "Notification Roles & Reminders",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"{DateTime.Now}",
                        },
                    };
                    await arg.RespondAsync("", false, eb.Build(), param, false, null, null, ct.Build());
                }
                catch { Console.WriteLine("Error executing slash command"); }
            }
            break;

            case "ping":
            {
                try
                {
                    var eb = new EmbedBuilder()
                    {
                        Description = $"The Grand Design's latency is about: `{Handler._Client.Latency}` milliseconds.",
                        Author      = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "Ping/Latency",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"{DateTime.Now}",
                        },
                    };
                    await arg.RespondAsync("", false, eb.Build(), param, true);
                }
                catch { Console.WriteLine("Error executing slash command"); }
            }
            break;

            case "8ball":
            {
                try
                {
                    var      input     = (arg as SocketSlashCommand).Data.Options.First(x => x.Name == "question");
                    string[] mystrings = ("No.|Yes.|Not at all, degenerate scum.|Your mother might agree.|Bistol says no.|I muster with all my strength, a fart in your face.|Lick my balls and call it a day.|A Discord moderator disagrees.|The kids in my basement.|Former president obama might know the answer, I am just an 8ball|S******g in your mouth and saying 'Yeehaw!'.|F**k no.|F*****g hell, weirdo.|I tried to think, didn't work out.|Yes daddy!").Split('|');
                    Random   randomInt = new Random();
                    var      eb        = new EmbedBuilder()
                    {
                        Author = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = $"{input.Value}",
                        },
                        Description = new string(mystrings[randomInt.Next(mystrings.Length)]),
                        Footer      = new EmbedFooterBuilder()
                        {
                            Text = $"{DateTime.Now}"
                        }
                    };
                    await arg.RespondAsync("", false, eb.Build(), param, true);
                }
                catch { Console.WriteLine("Error executing slash command"); }
            }
            break;

            case "avatar":
            {
                try
                {
                    SocketUser user;
                    var        options = arg as SocketSlashCommand;
                    if (options.Data.Options != null && options.Data.Options.Count > 0)
                    {
                        string userdata = options.Data?.Options?.FirstOrDefault()?.Value?.ToString();
                        ulong  userid   = Convert.ToUInt64(userdata);
                        user = Utils.Guild.GetUser(userid);
                        var eb = new EmbedBuilder()
                        {
                            ImageUrl = $"{user.GetAvatarUrl(ImageFormat.Auto, 256)}",
                            Author   = new EmbedAuthorBuilder()
                            {
                                IconUrl = $"{user.GetAvatarUrl()}",
                                Name    = $"{user.Username}#{user.Discriminator}",
                            },
                            Footer = new EmbedFooterBuilder()
                            {
                                Text = $"{DateTime.Now}",
                            }
                        };
                        await arg.RespondAsync("", false, eb.Build());
                    }
                    else
                    {
                        user = options.User;
                        var eb = new EmbedBuilder()
                        {
                            ImageUrl = $"{user.GetAvatarUrl(ImageFormat.Auto, 256)}",
                            Author   = new EmbedAuthorBuilder()
                            {
                                IconUrl = $"{user.GetAvatarUrl()}",
                                Name    = $"{user.Username}#{user.Discriminator}",
                            },
                            Footer = new EmbedFooterBuilder()
                            {
                                Text = $"{DateTime.Now}",
                            }
                        };
                        await arg.RespondAsync("", false, eb.Build(), param, true);
                    }
                }
                catch { Console.WriteLine("Error executing slash command"); }
            }
            break;
            }
        }
        /// <summary>
        /// Execute the function based on the interaction data we get.
        /// </summary>
        /// <param name="data">Interaction data from interaction</param>
        /// <param name="interaction">SocketInteraction</param>
        public async Task <IResult> ExecuteAsync(IReadOnlyCollection <SocketInteractionDataOption> data, SocketInteraction interaction)
        {
            // Array of arguments to be passed to the Delegate
            var args = new object[Parameters.Count];

            try
            {
                // For each parameter to try find its coresponding DataOption based on the name.
                // !!! names from `data` will always be lowercase regardless if we defined the command with any
                // number of upercase letters !!!
                for (var i = 0; i < Parameters.Count; i++)
                {
                    var parameter = Parameters[i];

                    if (TryGetInteractionDataOption(data, parameter.Name, out var dataOption))
                    {
                        args[i] = parameter.Parse(dataOption);
                    }
                }
            }
            catch (Exception e)
            {
                return(ExecuteResult.FromError(e));
            }

            var instance = ReflectionUtils.CreateObject <ISlashCommandModule>(Module.ModuleType, Module.Service, Module.ServiceProvider);

            instance.SetContext(interaction);

            var delegateMethod = SlashCommandServiceHelper.CreateDelegate(MethodInfo, instance);

            var callback = new Func <object[], Task <IResult> >(async callbackArgs =>
            {
                // Try-catch it and see what we get - error or success
                try
                {
                    await Task.Run(() => { delegateMethod.DynamicInvoke(callbackArgs); }).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    return(ExecuteResult.FromError(e));
                }

                return(ExecuteResult.FromSuccess());
            });

            return(await callback.Invoke(args).ConfigureAwait(false));
        }
        public static async Task OnButtonPress(SocketInteraction arg)
        {
            var button = arg as SocketMessageComponent;
            await arg.AcknowledgeAsync();

            string[] buttonId = button.Data.CustomId.Split('|');
            switch (buttonId[0])
            {
            case "id.0":
            {
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Previous page", $"id.0|{button.User.Id}", ButtonStyle.Danger, null, null, true)
                             .WithButton("Next page", $"id.1|{button.User.Id}", ButtonStyle.Success)
                             .WithButton("Our website", null, ButtonStyle.Link, null, "https://terrariabuilders.com/")
                             .WithButton("Become a voter!", $"id.voter|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color       = Color.Blue,
                        Description = $"The Grand Design has been developed by the Terraria Builders Community to bring utility in Terraria and Discord to new heights!",
                        Author      = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "TGD Help | Scroll through pages with the buttons below.",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"Page 1 • The Grand Design!",
                        },
                        Fields =
                        {
                            new EmbedFieldBuilder()
                            {
                                Name  = "Commands",
                                Value = "All commands are featured in the `!commands` command. Check it out! \nTGD also introduces slashcommands for a more fleshed out experience. \nType '/' to get a preview of all commands!"
                            },
                            new EmbedFieldBuilder()
                            {
                                Name  = "DM Support",
                                Value = "To get into contact with the staff of this server in an easy way, DM this bot and recieve answer!"
                            },
                            new EmbedFieldBuilder()
                            {
                                Name  = "About TBC",
                                Value = "A large amount of information about the Terraria Builders Community is provided in pages beyond where you currently are. Use the buttons to navigate them!"
                            }
                        }
                    };
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.1":
            {
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Previous page", $"id.0|{button.User.Id}", ButtonStyle.Danger)
                             .WithButton("Next page", $"id.2|{button.User.Id}", ButtonStyle.Success)
                             .WithButton("Our website", null, ButtonStyle.Link, null, "https://terrariabuilders.com/")
                             .WithButton("Become a voter!", $"id.voter|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color       = Color.Green,
                        Description = $"Designed by artists, for artists. This is the best place to be for showing off, asking advice & feedback or anything else regarding your creations. The focus on community gives us the ability to bond with members, have fun and enjoy art & Terraria in a fun and enjoyable way.",
                        Author      = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "TGD Help | Scroll through pages with the buttons below.",
                        },
                        ThumbnailUrl = "https://cdn.discordapp.com/attachments/694988142616379432/849374178343518238/sbcdetailed.gif",
                        Title        = "About the Terraria Builders Community",
                        Footer       = new EmbedFooterBuilder()
                        {
                            Text = $"Page 2 • About us!",
                        },
                        Fields =
                        {
                            new EmbedFieldBuilder()
                            {
                                Name  = "What do we offer?",
                                Value = $"A great set of features is provided to all members of this community. All commonly used features are listed on several pages after this one, many of them being available on different platforms!"
                            },
                        }
                    };
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.2":
            {
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Previous page", $"id.1|{button.User.Id}", ButtonStyle.Danger)
                             .WithButton("Next page", $"id.3|{button.User.Id}", ButtonStyle.Success)
                             .WithButton("Our website", null, ButtonStyle.Link, null, "https://terrariabuilders.com/")
                             .WithButton("Become a voter!", $"id.voter|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color  = Color.Purple,
                        Author = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "TGD Help | Scroll through pages with the buttons below.",
                        },
                        ThumbnailUrl = "https://cdn.discordapp.com/attachments/694988142616379432/849374178343518238/sbcdetailed.gif",
                        Title        = $"Features on the Discord server",
                        Footer       = new EmbedFooterBuilder()
                        {
                            Text = $"Page 3 • Discord features!",
                        },
                        Description = $"• **Contests**: Monthly build events to keep yourself busy, themes are provided.\n" +
                                      "• **Dueling**: Battle your foes in 1v1 build-off's!\n" +
                                      "• **Challenges**: A building tournament, 5 players head to head!\n" +
                                      "• **Ranking & Rewards**: All building events grant role rewards.\n" +
                                      "• **Custom roles**: All boosters get a custom role!\n" +
                                      "• **Ingame chat connection**: A chat with members playing ingame.",
                        Fields =
                        {
                            new EmbedFieldBuilder()
                            {
                                Name  = "A quick channel guide",
                                Value = $"Every channel has a main purpose and a set of requirements to use it. All channels have this written down in their descriptions. If you have any questions, you can ask the staff or the community in <#801941584517791815>"
                            }
                        }
                    };
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.3":
            {
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Previous page", $"id.2|{button.User.Id}", ButtonStyle.Danger)
                             .WithButton("Next page", $"id.4|{button.User.Id}", ButtonStyle.Success)
                             .WithButton("Our website", null, ButtonStyle.Link, null, "https://terrariabuilders.com/")
                             .WithButton("Become a voter!", $"id.voter|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color  = Color.Red,
                        Author = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "TGD Help | Scroll through pages with the buttons below.",
                        },
                        ThumbnailUrl = "https://cdn.discordapp.com/attachments/694988142616379432/849374178343518238/sbcdetailed.gif",
                        Title        = $"Features on the website!",
                        Footer       = new EmbedFooterBuilder()
                        {
                            Text = $"Page 4 • Website features!",
                        },
                        Description = $"• **Gallery**: This page shows off the builds our builders have made. Make sure to show off yours as well!\n" +
                                      "• **Applications**: Here you can apply for roles on our server.Make sure to read the general requirements!\n" +
                                      "• **Map archive**: All ingame maps are posted to this thread.\n" +
                                      "• **Staff support**: Our staff is always available on the forums.If you have a question, make sure to message them!\n" +
                                      "• **FAQ**: Frequently asked questions, in case you have certain questions about our servers."
                    };
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.4":
            {
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Previous page", $"id.3|{button.User.Id}", ButtonStyle.Danger)
                             .WithButton("Next page", $"id.5|{button.User.Id}", ButtonStyle.Success)
                             .WithButton("Our website", null, ButtonStyle.Link, null, "https://terrariabuilders.com/")
                             .WithButton("Become a voter!", $"id.voter|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color  = Color.Orange,
                        Author = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "TGD Help | Scroll through pages with the buttons below.",
                        },
                        ThumbnailUrl = "https://cdn.discordapp.com/attachments/694988142616379432/849374178343518238/sbcdetailed.gif",
                        Title        = $"Features on our Terraria server!",
                        Footer       = new EmbedFooterBuilder()
                        {
                            Text = $"Page 5 • Terraria server features!",
                        },
                        Description = $"• **Freebuild**: Here you can roam and build freely, with many creative features.\n" +
                                      "• **Free Items**: Any item in the game is available here!\n" +
                                      "• **PvP**: Player versus player, an arena to challenge your foes!\n" +
                                      "• **PvE**: Player versus enemy, the place to challenge many creatures!\n" +
                                      "• **Parkour**: Jumping over obstacles to get to the finish line.\n" +
                                      "• **Community events**: Where the community gathers to build unique and theme driven creations!\n" +
                                      "• **More to come!** stay tuned for any major announcements.",
                        Fields =
                        {
                            new EmbedFieldBuilder()
                            {
                                Name  = "Connecting your account to Discord",
                                Value = $":one: Create an ingame account: `/register 'password'`\n:two: Send a DM to any server bot: `login 'Username'' 'Password'`"
                            },
                            new EmbedFieldBuilder()
                            {
                                Name  = "Join us now!",
                                Value = "PC & Android 1.4 • IP: `terrariabuilders.com` | PORT: `7777`"
                            }
                        }
                    };
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.5":
            {
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Previous page", $"id.4|{button.User.Id}", ButtonStyle.Danger)
                             .WithButton("Next page", $"id.6|{button.User.Id}", ButtonStyle.Success)
                             .WithButton("Our website", null, ButtonStyle.Link, null, "https://terrariabuilders.com/")
                             .WithButton("Become a voter!", $"id.voter|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color       = Color.Blue,
                        Description = $"Page 6",
                        Author      = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "Help menu for The Grand Design!",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"Page 6 • Commands & IP!",
                        },
                    };
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.6":
            {
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Previous page", $"id.5|{button.User.Id}", ButtonStyle.Danger)
                             .WithButton("Next page", $"id.7|{button.User.Id}", ButtonStyle.Success, null, null, true)
                             .WithButton("Our website", null, ButtonStyle.Link, null, "https://terrariabuilders.com/")
                             .WithButton("Become a voter!", $"id.voter|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color       = Color.Blue,
                        Description = $"Page 7",
                        Author      = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "Help menu for The Grand Design!",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"Page 7",
                        },
                    };
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.rolebase":
            {
                if (buttonId[1] == button.User.Id.ToString())
                {
                    IEmote eEvent    = new Emoji("🗓");
                    IEmote eAnnounce = new Emoji("📣");
                    IEmote eVoter    = new Emoji("🎫");
                    var    ct        = new ComponentBuilder()
                                       .WithButton("Events", $"id.event|{button.User.Id}", ButtonStyle.Primary, eEvent)
                                       .WithButton("Announcements", $"id.announce|{button.User.Id}", ButtonStyle.Primary, eAnnounce)
                                       .WithButton("Voting", $"id.voter|{button.User.Id}", ButtonStyle.Primary, eVoter);
                    var eb = new EmbedBuilder()
                    {
                        Color       = Color.Blue,
                        Description = $"You can assign any of the below roles to be mentioned when updates/reminders are sent in respective channels!",
                        Author      = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "Notification Roles & Reminders",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"{DateTime.Now}",
                        },
                    };
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.voter":
            {
                IRole role = Utils.Guild.GetRole(820994140040724486);
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Click here to vote", null, ButtonStyle.Link, null, "https://terrariabuilders.com/vote")
                             .WithButton("Remove the role", $"id.nullvoter|{button.User.Id}", ButtonStyle.Danger)
                             .WithButton("Assign/Remove other roles!", $"id.rolebase|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color  = Color.Purple,
                        Author = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "Thank you for becoming a voter!",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"{DateTime.Now}",
                        },
                    };
                    if (!(button.User as SocketGuildUser).Roles.Any(x => x.Name == role.Name))
                    {
                        await(button.User as SocketGuildUser).AddRoleAsync(role);
                        eb.WithDescription($"Thank you for assigning the {role.Mention} role! You will be reminded to vote daily.");
                    }
                    if ((button.User as SocketGuildUser).Roles.Any(x => x.Name == role.Name))
                    {
                        eb.WithDescription($"You already have the {role.Mention} role! You can vote through the button below.");
                    }
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.nullvoter":
            {
                IRole role = Utils.Guild.GetRole(820994140040724486);
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Become a voter!", $"id.voter|{button.User.Id}", ButtonStyle.Success)
                             .WithButton("Assign/Remove other roles!", $"id.rolebase|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color       = Color.Red,
                        Description = $"The {role.Mention} role has successfully been removed.",
                        Author      = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "Thank you for your contribution!",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"{DateTime.Now}",
                        },
                    };
                    if ((button.User as SocketGuildUser).Roles.Any(x => x.Name == "Voter"))
                    {
                        await(button.User as SocketGuildUser).RemoveRoleAsync(role);
                        eb.WithDescription($"The {role.Mention} role has successfully been removed.");
                    }
                    if (!(button.User as SocketGuildUser).Roles.Any(x => x.Name == "Voter"))
                    {
                        return;
                    }
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.event":
            {
                IRole role = Utils.Guild.GetRole(607907671299063809);
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Remove the role", $"id.nullevent|{button.User.Id}", ButtonStyle.Danger)
                             .WithButton("Assign/Remove other roles!", $"id.rolebase|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color  = Color.Purple,
                        Author = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "Thank you for becoming a voter!",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"{DateTime.Now}",
                        },
                    };
                    if (!(button.User as SocketGuildUser).Roles.Any(x => x.Name == role.Name))
                    {
                        await(button.User as SocketGuildUser).AddRoleAsync(role);
                        eb.WithDescription($"Thank you for assigning the {role.Mention} role! You will be notified for all event updates.");
                    }
                    if ((button.User as SocketGuildUser).Roles.Any(x => x.Name == role.Name))
                    {
                        eb.WithDescription($"You already have the {role.Mention} role! You will be notified for all event updates.");
                    }
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.nullevent":
            {
                IRole role = Utils.Guild.GetRole(607907671299063809);
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Add the event role!", $"id.voter|{button.User.Id}", ButtonStyle.Success)
                             .WithButton("Assign/Remove other roles!", $"id.rolebase|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color       = Color.Red,
                        Description = $"The {role.Mention} role has successfully been removed.",
                        Author      = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "Thank you for your contribution!",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"{DateTime.Now}",
                        },
                    };
                    if ((button.User as SocketGuildUser).Roles.Any(x => x.Name == role.Name))
                    {
                        await(button.User as SocketGuildUser).RemoveRoleAsync(role);
                        eb.WithDescription($"The {role.Mention} role has successfully been removed.");
                    }
                    if (!(button.User as SocketGuildUser).Roles.Any(x => x.Name == role.Name))
                    {
                        return;
                    }
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.announce":
            {
                IRole role = Utils.Guild.GetRole(714461391351840893);
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Remove the role", $"id.nullevent|{button.User.Id}", ButtonStyle.Danger)
                             .WithButton("Assign/Remove other roles!", $"id.rolebase|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color  = Color.Purple,
                        Author = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "Thank you for becoming a voter!",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"{DateTime.Now}",
                        },
                    };
                    if (!(button.User as SocketGuildUser).Roles.Any(x => x.Name == role.Name))
                    {
                        await(button.User as SocketGuildUser).AddRoleAsync(role);
                        eb.WithDescription($"Thank you for assigning the {role.Mention} role! You will be notified for all new announcements.");
                    }
                    if ((button.User as SocketGuildUser).Roles.Any(x => x.Name == role.Name))
                    {
                        eb.WithDescription($"You already have the {role.Mention} role! You will be notified for all new announcements.");
                    }
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;

            case "id.nullannounce":
            {
                IRole role = Utils.Guild.GetRole(714461391351840893);
                if (buttonId[1] == button.User.Id.ToString())
                {
                    var ct = new ComponentBuilder()
                             .WithButton("Add the announcement role!", $"id.voter|{button.User.Id}", ButtonStyle.Success)
                             .WithButton("Assign/Remove other roles!", $"id.rolebase|{button.User.Id}", ButtonStyle.Primary);
                    var eb = new EmbedBuilder()
                    {
                        Color       = Color.Red,
                        Description = $"The {role.Mention} role has successfully been removed.",
                        Author      = new EmbedAuthorBuilder()
                        {
                            IconUrl = $"{Utils.BotUser.GetAvatarUrl()}",
                            Name    = "Thank you for your contribution!",
                        },
                        Footer = new EmbedFooterBuilder()
                        {
                            Text = $"{DateTime.Now}",
                        },
                    };
                    if ((button.User as SocketGuildUser).Roles.Any(x => x.Name == role.Name))
                    {
                        await(button.User as SocketGuildUser).RemoveRoleAsync(role);
                        eb.WithDescription($"The {role.Mention} role has successfully been removed.");
                    }
                    if (!(button.User as SocketGuildUser).Roles.Any(x => x.Name == role.Name))
                    {
                        return;
                    }
                    var message = button.Message;
                    await message.ModifyAsync(x => x.Embed = eb.Build());

                    await message.ModifyAsync(x => x.Components = ct.Build());
                }
                else
                {
                    return;
                }
            }
            break;
            }
        }
Beispiel #30
0
        private async Task Client_InteractionCreated(SocketInteraction arg)
        {
            if (arg.Data.Name == "whitelist")
            {
                if (!Program.UserHasPerm(arg.Member))
                {
                    await arg.FollowupAsync("Invalid permission f****r, go sit on a pinecone dickhead");

                    return;
                }

                if (arg.Data.Options.Count == 1)
                {
                    var opt = arg.Data.Options.First();

                    switch (opt.Name)
                    {
                    case "add":
                    {
                        var word = (string)opt.Options.First().Value;

                        if (WhiteList.Contains(word))
                        {
                            await arg.FollowupAsync("", false, new EmbedBuilder()
                                {
                                    Title       = "No.. sex",
                                    Color       = Color.Red,
                                    Description = $"The word `{word}` is already in the whitelist!"
                                }.WithCurrentTimestamp().Build());

                            return;
                        }

                        AddWhitelist(word);
                        await arg.FollowupAsync("", false, new EmbedBuilder()
                            {
                                Title       = "Success!",
                                Color       = Color.Green,
                                Description = $"Added `{word}` to the whitelist!"
                            }.WithCurrentTimestamp().Build());

                        return;
                    }

                    case "remove":
                    {
                        var word = (string)opt.Options.First().Value;

                        if (!WhiteList.Contains(word))
                        {
                            await arg.FollowupAsync("", false, new EmbedBuilder()
                                {
                                    Title       = "No.. sex",
                                    Color       = Color.Red,
                                    Description = $"The word `{word}` is not in the whitelist!"
                                }.WithCurrentTimestamp().Build());

                            return;
                        }

                        RemoveWhitelist(word);
                        await arg.FollowupAsync("", false, new EmbedBuilder()
                            {
                                Title       = "Success!",
                                Color       = Color.Green,
                                Description = $"Removed `{word}` from the whitelist!"
                            }.WithCurrentTimestamp().Build());

                        return;
                    }

                    case "list":

                        await arg.FollowupAsync("", false, new EmbedBuilder()
                        {
                            Title       = "Whitelist",
                            Color       = Color.Green,
                            Description = $"Heres the current whitelist:\n```\n{string.Join("\n", WhiteList)}```"
                        }.WithCurrentTimestamp().Build());

                        return;
                    }
                }
            }
        }