コード例 #1
0
        public async Task HandleInteraction(DiscordClient discord, ComponentInteractionCreateEventArgs e)
        {
            Logger.Log(Logging.EventsHandled);
            if (Settings.Test && e.Message.Channel.GuildId != Settings.TestGuild)
            {
                return;
            }

            Response response = null;

            if (CachedMisses.Contains(e.Message.Id))
            {
                response = CachedMisses[e.Message.Id];
            }
            if (e.Message.Interaction != null && CachedMisses.Contains(e.Message.Interaction.Id))
            {
                response = CachedMisses[e.Message.Interaction.Id];
            }

            if (response != null && !e.User.IsCurrent && !e.User.IsBot)
            {
                int index = int.Parse(e.Id) - 1;
                Logger.Log(Logging.ReactionCalls);
                _ = Task.Run(() => UpdateResponse(e, response, index));
                await Task.CompletedTask;
            }
        }
コード例 #2
0
        private async Task HandleTvRequestAsync(ComponentInteractionCreateEventArgs e)
        {
            if (e.Id.ToLower().StartsWith("trs"))
            {
                if (e.Values != null && e.Values.Any())
                {
                    await CreateTvShowRequestWorkFlow(e, int.Parse(e.Values.Single().Split("/").First()))
                    .HandleTvShowSelectionAsync(int.Parse(e.Values.Single().Split("/").Last()));
                }
            }
            else if (e.Id.ToLower().StartsWith("tss"))
            {
                if (e.Values != null && e.Values.Any())
                {
                    var splitValues  = e.Values.Single().Split("/");
                    var categoryId   = int.Parse(splitValues[0]);
                    var tvDbId       = int.Parse(splitValues[1]);
                    var seasonNumber = int.Parse(splitValues[2]);

                    await CreateTvShowRequestWorkFlow(e, categoryId)
                    .HandleSeasonSelectionAsync(tvDbId, seasonNumber);
                }
            }
            else if (e.Id.ToLower().StartsWith("trc"))
            {
                var splitValues  = e.Id.Split("/").Skip(2).ToArray();
                var categoryId   = int.Parse(splitValues[0]);
                var tvDbId       = int.Parse(splitValues[1]);
                var seasonNumber = int.Parse(splitValues[2]);

                await CreateTvShowRequestWorkFlow(e, categoryId)
                .RequestSeasonSelectionAsync(tvDbId, seasonNumber);
            }
        }
コード例 #3
0
 public static async Task OnComponentInteraction(DiscordClient sender, ComponentInteractionCreateEventArgs e)
 {
     if (e.Interaction.Type != InteractionType.Component ||
         e.Interaction.Data.ComponentType != ComponentType.Button ||
         e.Interaction.Data.CustomId is not {
         Length : > 0
     })
コード例 #4
0
        public override async Task <ulong?> UpdateResponse(object e, int index)
        {
            Miss.CurrentMiss = index;
            ComponentInteractionCreateEventArgs args = (ComponentInteractionCreateEventArgs)e;
            await args.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage,
                                                       new DiscordInteractionResponseBuilder(BuildMessage(await GetContent())));

            return(null);
        }
コード例 #5
0
        private async Task Handle(DiscordClient sender, ComponentInteractionCreateEventArgs e)
        {
            if (e.Id != "a")
            {
                return;
            }
            var pages = sender.GetInteractivity().GeneratePagesInContent(_lorem);

            _ = sender.GetInteractivity().SendPaginatedResponseAsync(e.Interaction, true, e.User, pages);
            sender.ComponentInteractionCreated -= this.Handle;
        }
コード例 #6
0
ファイル: TestBot.cs プロジェクト: DSharpPlus/DSharpPlus
 private async Task Discord_ModalCheck(DiscordClient sender, ComponentInteractionCreateEventArgs e)
 {
     if (e.Id == "modal")
     {
         await e.Interaction.CreateResponseAsync(InteractionResponseType.Modal, new DiscordInteractionResponseBuilder()
                                                 .WithTitle("Test!")
                                                 .WithCustomId("owo")
                                                 .AddComponents(new TextInputComponent("Short, optional", "short_opt", "Placeholder!"))
                                                 .AddComponents(new TextInputComponent("Long, optional", "long_opt", "Placeholder 2!", style: TextInputStyle.Paragraph))
                                                 .AddComponents(new TextInputComponent("Short, required", "short_req", "Placeholder 3!", style:  TextInputStyle.Short, min_length: 10, max_length: 20))
                                                 .AddComponents(new TextInputComponent("Long, required", "long_req", "Placeholder 4!", "Lorem Ipsum", true, TextInputStyle.Paragraph, 100, 300))
                                                 );
     }
 }
コード例 #7
0
        private async Task HandleMovieRequestAsync(ComponentInteractionCreateEventArgs e)
        {
            if (e.Id.ToLower().StartsWith("mrs"))
            {
                if (e.Values != null && e.Values.Any())
                {
                    await CreateMovieRequestWorkFlow(e, int.Parse(e.Values.Single().Split("/").First()))
                    .HandleMovieSelectionAsync(int.Parse(e.Values.Single().Split("/").Last()));
                }
            }
            else if (e.Id.ToLower().StartsWith("mrc"))
            {
                var categoryId = int.Parse(e.Id.Split("/").Skip(2).First());

                await CreateMovieRequestWorkFlow(e, categoryId)
                .RequestMovieAsync(int.Parse(e.Id.Split("/").Last()));
            }
        }
コード例 #8
0
ファイル: Events.cs プロジェクト: JulianusIV/LathBot
 internal static Task ComponentTriggered(DiscordClient _1, ComponentInteractionCreateEventArgs e)
 {
     _ = Task.Run(async() =>
     {
         if (e.Id == "lb_server_verification")
         {
             DiscordMember member = await e.Guild.GetMemberAsync(e.User.Id);
             await member.GrantRoleAsync(e.Guild.GetRole(767050052257447936));
             await member.GrantRoleAsync(e.Guild.GetRole(699562710144385095));
             await e.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource,
                                                     new DiscordInteractionResponseBuilder
             {
                 Content = "You are now verified and can access the rest of the channels.\n\n" +
                           "Make sure to visit <#767098427225145365> to unlock some more channels that you like.",
                 IsEphemeral = true
             });
         }
     });
     return(Task.CompletedTask);
 }
コード例 #9
0
        private async Task HandleComponentInteractionCreated(DiscordClient sender, ComponentInteractionCreateEventArgs e)
        {
            if (e.Id != _button.CustomId)
            {
                return;
            }

            if (_response != null)
            {
                var responseBuilder = _response();
                await e.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage, responseBuilder);
            }
            else if (_followup != null)
            {
                var followupMessageBuilder = _followup();
                await e.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate);

                await e.Interaction.CreateFollowupMessageAsync(followupMessageBuilder);
            }
        }
コード例 #10
0
 private ITvShowNotificationWorkflow CreateTvShowNotificationWorkflow(ComponentInteractionCreateEventArgs e)
 {
     return(_tvShowWorkflowFactory
            .CreateNotificationWorkflow(e.Interaction));
 }
コード例 #11
0
 private TvShowRequestingWorkflow CreateTvShowRequestWorkFlow(ComponentInteractionCreateEventArgs e, int categoryId)
 {
     return(_tvShowWorkflowFactory
            .CreateRequestingWorkflow(e.Interaction, categoryId));
 }
コード例 #12
0
 private IMovieNotificationWorkflow CreateMovieNotificationWorkflow(ComponentInteractionCreateEventArgs e)
 {
     return(_movieWorkflowFactory
            .CreateNotificationWorkflow(e.Interaction));
 }
コード例 #13
0
        private async Task DiscordComponentInteractionCreatedHandler(DiscordClient client, ComponentInteractionCreateEventArgs e)
        {
            try
            {
                await e.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage);

                var authorId = ulong.Parse(e.Id.Split("/").Skip(1).First());

                if (e.User.Id == authorId)
                {
                    if (e.Id.ToLower().StartsWith("mr"))
                    {
                        await HandleMovieRequestAsync(e);
                    }
                    else if (e.Id.ToLower().StartsWith("mnr"))
                    {
                        await CreateMovieNotificationWorkflow(e)
                        .AddNotificationAsync(e.Id.Split("/").Skip(1).First(), int.Parse(e.Id.Split("/").Last()));
                    }
                    if (e.Id.ToLower().StartsWith("tr") || e.Id.ToLower().StartsWith("ts"))
                    {
                        await HandleTvRequestAsync(e);
                    }
                    else if (e.Id.ToLower().StartsWith("tnr"))
                    {
                        var splitValues  = e.Id.Split("/").Skip(1).ToArray();
                        var userId       = splitValues[0];
                        var tvDbId       = int.Parse(splitValues[1]);
                        var seasonType   = splitValues[2];
                        var seasonNumber = splitValues[3];

                        await CreateTvShowNotificationWorkflow(e)
                        .AddNotificationAsync(userId, tvDbId, seasonType, int.Parse(seasonNumber));
                    }
                }
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex, "Error while handling interaction: " + ex.Message);
                await e.Interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().WithContent(Language.Current.Error));
            }
        }
コード例 #14
0
 public static async Task XpGraphs(ComponentInteractionCreateEventArgs e)
 {
     string userId = e.Id[28..];
コード例 #15
0
ファイル: Functions.cs プロジェクト: Katzerolli/DiscordBot
 public static async void Buttonpressed(DiscordClient client, ComponentInteractionCreateEventArgs eventArgs)
 {
 }
コード例 #16
0
 public Task OnComponentInteractionCreatedAsync(DiscordClient sender, ComponentInteractionCreateEventArgs e) => e.Id switch
 {
     "sg-joinlog-select" => HandleJoinlogConfigurationAsync(e),