Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement user-installed integration #1625

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from

Conversation

User9684
Copy link
Contributor

In order for this to actually be used on a bot, the setting must be enabled in the installation panel.

image

Implements the new integration context/types system

Adds `Integration_Types` and `Contexts` to `lib\discordgo\structs.go`'s `Integration` struct
Adds `IntegrationOwners` to `lib\discordgo\interactions.go`'s `Interaction` struct
Adds `UserInstalledGuild` to `lib\dcmd\data.go`'s `Data` struct
Implements the new `Integration_Types` and `Contexts` into `commands\slashcommands.go`'s `yagCommandToSlashCommand` function
Replaces integration with the proper word interaction according to documentation
@@ -186,6 +186,8 @@ type Interaction struct {
Data InteractionData `json:"data"`
GuildID int64 `json:"guild_id,string"`
ChannelID int64 `json:"channel_id,string"`
// https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-authorizing-integration-owners-object
IntegrationOwners map[string]interface{} `json:"authorizing_integration_owners"` // Left as interface due to discord being inconsistent, with the value being an int at some times and a string at others.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bwmarrin's dgo also struggles with this bug, their workaround currently is > bwmarrin/discordgo#1511

regarding that bug, maybe it would be a good thing to wait a little until discord/discord-api-docs#6730 is fixed

@mrbentarikau
Copy link
Contributor

One thing I'd add is if interaction context is of type 2 PRIVATE_CHANNEL, the response should be ephemeral - no need to spam user DMs with bot interactions.

@User9684
Copy link
Contributor Author

One thing I'd add is if interaction context is of type 2 PRIVATE_CHANNEL, the response should be ephemeral - no need to spam user DMs with bot interactions.

While I do agree that there's no need to flood dms with interactions, I also think it would ruin the fun of users who want to use the bot in a GDM, as the type is PRIVATE_CHANNEL in there aswell.

@User9684
Copy link
Contributor Author

There might be some way to check if the channel is a GDM, but I'd have to look further into the API, and I feel as though that would be out of scope for this PR anyways.

@mrbentarikau
Copy link
Contributor

mrbentarikau commented Mar 26, 2024

I think Context field for type Interaction is in the scope of this PR.
I agree in group DMs it should be open response, so is running application commands in random people's DMs necessary, I guess is for the maintainer to decide, RunInDM is currently enabled for few commands.

@mrbentarikau
Copy link
Contributor

mrbentarikau commented Mar 26, 2024

ok, got it working on my end, so that it goes Ephemeral for regular DMs and not for Group ones
I added Channel (really don't know why bwmarrin does not have it, docs has it) and Context fields to type Interaction
and in commands/plugin_bot.go >

func YAGCommandMiddleware(inner dcmd.RunFunc) dcmd.RunFunc {
...
// this follows bwmarrin PR#1511 and not your interface, logic is the same
    isUserInstalledGuild := data.SlashCommandTriggerData.Interaction.AuthorizingIntegrationOwners[discordgo.ApplicationIntegrationGuildInstall] == "" && data.SlashCommandTriggerData.Interaction.AuthorizingIntegrationOwners[discordgo.ApplicationIntegrationUserInstall] != ""

    if yc.IsResponseEphemeral || (isUserInstalledGuild && data.SlashCommandTriggerData.Interaction.Context == discordgo.InteractionContextPrivateChannel && data.SlashCommandTriggerData.Interaction.Channel.Type != discordgo.ChannelTypeGroupDM) {
				response.Data = &discordgo.InteractionResponseData{Flags: 64}
}
...

Removes underscores from variables
Fixes a mistake made by blindly replacing all text
@User9684
Copy link
Contributor Author

Pagination will probably need some degree of changes if a command with RunInDM enabled uses it anywhere (i.e. forex)

@User9684 User9684 marked this pull request as draft March 27, 2024 03:49
@mrbentarikau
Copy link
Contributor

Pagination will probably need some degree of changes if a command with RunInDM enabled uses it anywhere (i.e. forex)

yeah, even if you enable forex for DMs by setting guilID 0 for pagination function, problem is still that bot does not have access to that channel.

Modifies `bot\paginatedmessages\paginatedinteractions.go`'s `CreatePaginatedMessage` function to accept `dcmd.Data` and respond to original interaction accordingly
@mrbentarikau
Copy link
Contributor

mrbentarikau commented Mar 27, 2024

What I did...
I created a separate pagination function for interactions, this one sends CreateFollowupMessage and HandlePageButtonClick method handles non-guild related messages separately via EditOriginalInteractionResponse

it works , ok buttons don't get deleted... yet

I still don't see bigger reason for YAGPDB having it, for self-hosts it could be fun, but changing this much code for no good reason, I really don't know.

@User9684 User9684 marked this pull request as ready for review March 28, 2024 07:37
@User9684
Copy link
Contributor Author

User9684 commented May 6, 2024

Discord fixed discord/discord-api-docs#6730

commands/slashcommands.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants