mirror of
https://github.com/WCBROW01/zblock.git
synced 2025-12-12 04:28:07 -05:00
[main.c] Test buttons in list message
This commit is contained in:
42
main.c
42
main.c
@ -37,6 +37,9 @@ struct bot_command {
|
|||||||
#define _CREATE_EMBEDS(embeds) &(struct discord_embeds) { .size = sizeof((struct discord_embed[]) embeds) / sizeof(struct discord_embed), .array = (struct discord_embed[]) embeds }
|
#define _CREATE_EMBEDS(embeds) &(struct discord_embeds) { .size = sizeof((struct discord_embed[]) embeds) / sizeof(struct discord_embed), .array = (struct discord_embed[]) embeds }
|
||||||
#define CREATE_EMBEDS(...) _CREATE_EMBEDS(P99_PROTECT(__VA_ARGS__))
|
#define CREATE_EMBEDS(...) _CREATE_EMBEDS(P99_PROTECT(__VA_ARGS__))
|
||||||
|
|
||||||
|
#define _CREATE_COMPONENTS(components) &(struct discord_components) { .size = sizeof((struct discord_component[]) components) / sizeof(struct discord_component), .array = (struct discord_component[]) components }
|
||||||
|
#define CREATE_COMPONENTS(...) _CREATE_COMPONENTS(P99_PROTECT(__VA_ARGS__))
|
||||||
|
|
||||||
#define BOT_COMMAND_NOT_IMPLEMENTED() do { \
|
#define BOT_COMMAND_NOT_IMPLEMENTED() do { \
|
||||||
struct discord_interaction_response res = { \
|
struct discord_interaction_response res = { \
|
||||||
.type = DISCORD_INTERACTION_CHANNEL_MESSAGE_WITH_SOURCE, \
|
.type = DISCORD_INTERACTION_CHANNEL_MESSAGE_WITH_SOURCE, \
|
||||||
@ -264,6 +267,33 @@ static void bot_command_list(struct discord *client, const struct discord_intera
|
|||||||
struct discord_interaction_response res = {
|
struct discord_interaction_response res = {
|
||||||
.type = DISCORD_INTERACTION_CHANNEL_MESSAGE_WITH_SOURCE,
|
.type = DISCORD_INTERACTION_CHANNEL_MESSAGE_WITH_SOURCE,
|
||||||
.data = &(struct discord_interaction_callback_data) {
|
.data = &(struct discord_interaction_callback_data) {
|
||||||
|
.components = CREATE_COMPONENTS({
|
||||||
|
{
|
||||||
|
.type = DISCORD_COMPONENT_ACTION_ROW,
|
||||||
|
.components = CREATE_COMPONENTS({
|
||||||
|
{
|
||||||
|
.type = DISCORD_COMPONENT_BUTTON,
|
||||||
|
.disabled = false,
|
||||||
|
.style = DISCORD_BUTTON_SECONDARY,
|
||||||
|
.custom_id = "page_back",
|
||||||
|
.label = "Back",
|
||||||
|
.emoji = &(struct discord_emoji) {
|
||||||
|
.name = "◀️"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.type = DISCORD_COMPONENT_BUTTON,
|
||||||
|
.disabled = false,
|
||||||
|
.style = DISCORD_BUTTON_SECONDARY,
|
||||||
|
.custom_id = "page_next",
|
||||||
|
.label = "Next",
|
||||||
|
.emoji = &(struct discord_emoji) {
|
||||||
|
.name = "▶️"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}),
|
||||||
.embeds = CREATE_EMBEDS({
|
.embeds = CREATE_EMBEDS({
|
||||||
{
|
{
|
||||||
.title = "Feed List",
|
.title = "Feed List",
|
||||||
@ -360,9 +390,8 @@ static void on_ready(struct discord *client, const struct discord_ready *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void on_interaction(struct discord *client, const struct discord_interaction *event) {
|
static void on_interaction(struct discord *client, const struct discord_interaction *event) {
|
||||||
if (event->type != DISCORD_INTERACTION_APPLICATION_COMMAND)
|
switch (event->type) {
|
||||||
return; // not a slash command
|
case DISCORD_INTERACTION_APPLICATION_COMMAND: {
|
||||||
|
|
||||||
// invoke the command
|
// invoke the command
|
||||||
for (struct bot_command *i = commands; i < commands + sizeof(commands) / sizeof(*commands); ++i) {
|
for (struct bot_command *i = commands; i < commands + sizeof(commands) / sizeof(*commands); ++i) {
|
||||||
if (!strcmp(event->data->name, i->cmd.name)) {
|
if (!strcmp(event->data->name, i->cmd.name)) {
|
||||||
@ -379,6 +408,13 @@ static void on_interaction(struct discord *client, const struct discord_interact
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
discord_create_interaction_response(client, event->id, event->token, &res, NULL);
|
discord_create_interaction_response(client, event->id, event->token, &res, NULL);
|
||||||
|
} break;
|
||||||
|
case DISCORD_INTERACTION_MESSAGE_COMPONENT: {
|
||||||
|
// nothing yet
|
||||||
|
} break;
|
||||||
|
default: // nothing
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// delay before the first feed retrieval (in ms)
|
// delay before the first feed retrieval (in ms)
|
||||||
|
|||||||
Reference in New Issue
Block a user