added partial userinstall support
This commit is contained in:
10
cmd_ask.go
10
cmd_ask.go
@@ -10,6 +10,15 @@ var cmd_ask = Command{
|
||||
Definition: discord.SlashCommandCreate{
|
||||
Name: "ask",
|
||||
Description: "Ask anything and get a gif as response!",
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel,
|
||||
discord.InteractionContextTypeBotDM,
|
||||
},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall,
|
||||
discord.ApplicationIntegrationTypeUserInstall,
|
||||
},
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
&discord.ApplicationCommandOptionString{
|
||||
Name: "question",
|
||||
@@ -26,5 +35,4 @@ var cmd_ask = Command{
|
||||
logrus.Error(err)
|
||||
}
|
||||
},
|
||||
AllowDM: true,
|
||||
}
|
||||
|
@@ -10,6 +10,11 @@ var cmd_autojoinroles Command = Command{
|
||||
Definition: discord.SlashCommandCreate{
|
||||
Name: "autojoinroles",
|
||||
Description: "Give users a role when they join",
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall},
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
&discord.ApplicationCommandOptionSubCommand{
|
||||
Name: "bot",
|
||||
|
@@ -10,6 +10,11 @@ var cmd_autopublish Command = Command{
|
||||
Definition: discord.SlashCommandCreate{
|
||||
Name: "autopublish",
|
||||
Description: "Toggle automatically publishing every post in a announcement channel",
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall},
|
||||
},
|
||||
Interact: func(e *events.ApplicationCommandInteractionCreate) {
|
||||
channel := e.Channel()
|
||||
|
10
cmd_cat.go
10
cmd_cat.go
@@ -14,6 +14,15 @@ var cmd_cat = Command{
|
||||
Definition: discord.SlashCommandCreate{
|
||||
Name: "cat",
|
||||
Description: "Random cat pictures",
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel,
|
||||
discord.InteractionContextTypeBotDM,
|
||||
},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall,
|
||||
discord.ApplicationIntegrationTypeUserInstall,
|
||||
},
|
||||
},
|
||||
Interact: func(e *events.ApplicationCommandInteractionCreate) {
|
||||
cat, err := GetCatImageURL()
|
||||
@@ -26,7 +35,6 @@ var cmd_cat = Command{
|
||||
}
|
||||
}
|
||||
},
|
||||
AllowDM: true,
|
||||
}
|
||||
|
||||
type CatImage struct {
|
||||
|
@@ -10,6 +10,15 @@ var cmd_dadjoke = Command{
|
||||
Definition: discord.SlashCommandCreate{
|
||||
Name: "dadjoke",
|
||||
Description: "Gives you a random joke that is as bad as your dad would tell them",
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel,
|
||||
discord.InteractionContextTypeBotDM,
|
||||
},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall,
|
||||
discord.ApplicationIntegrationTypeUserInstall,
|
||||
},
|
||||
},
|
||||
Interact: func(e *events.ApplicationCommandInteractionCreate) {
|
||||
joke := simpleGetFromAPI("joke", "https://icanhazdadjoke.com/").(string)
|
||||
@@ -20,5 +29,4 @@ var cmd_dadjoke = Command{
|
||||
logrus.Error(err)
|
||||
}
|
||||
},
|
||||
AllowDM: true,
|
||||
}
|
||||
|
10
cmd_form.go
10
cmd_form.go
@@ -19,6 +19,11 @@ var cmd_form Command = Command{
|
||||
Name: "form",
|
||||
DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageChannels),
|
||||
Description: "Create custom forms right inside Discord",
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall},
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
&discord.ApplicationCommandOptionSubCommand{
|
||||
Name: "help",
|
||||
@@ -250,7 +255,6 @@ var cmd_form Command = Command{
|
||||
Build())
|
||||
}
|
||||
} else {
|
||||
logrus.Debug(result.AcceptChannelID)
|
||||
if result.AcceptChannelID == "" {
|
||||
_, err := e.Client().Rest().CreateMessage(snowflake.MustParse(result.ResultChannelID), discord.NewMessageCreateBuilder().
|
||||
SetEmbeds(discord.NewEmbedBuilder().
|
||||
@@ -270,7 +274,6 @@ var cmd_form Command = Command{
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logrus.Debug("HEERE")
|
||||
var buttons []discord.InteractiveComponent
|
||||
if result.CommentCategoryID != "" {
|
||||
buttons = []discord.InteractiveComponent{discord.
|
||||
@@ -335,6 +338,9 @@ var cmd_ticket_form Command = Command{
|
||||
Name: "ticket",
|
||||
DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageChannels),
|
||||
Description: "A quick command to create Ticketpanels. (/form for more)",
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel},
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
&discord.ApplicationCommandOptionString{
|
||||
Name: "title",
|
||||
|
12
cmd_info.go
12
cmd_info.go
@@ -42,6 +42,15 @@ var cmd_userinfo Command = Command{
|
||||
Definition: discord.SlashCommandCreate{
|
||||
Name: "info",
|
||||
Description: "Gives you information about a user or this bot.",
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel,
|
||||
discord.InteractionContextTypeBotDM,
|
||||
},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall,
|
||||
discord.ApplicationIntegrationTypeUserInstall,
|
||||
},
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
&discord.ApplicationCommandOptionSubCommand{
|
||||
Name: "user",
|
||||
@@ -92,7 +101,7 @@ var cmd_userinfo Command = Command{
|
||||
embedBuilder.AddField("Discriminator", user.Discriminator, false)
|
||||
}
|
||||
if user.AccentColor != nil {
|
||||
embedBuilder.AddField("Accent color", strconv.Itoa(*user.AccentColor), true)
|
||||
embedBuilder.AddField("Accent color", "#"+strconv.FormatInt(int64(*user.AccentColor), 16), true)
|
||||
}
|
||||
if user.AvatarDecorationURL() != nil {
|
||||
value := fmt.Sprintf("[PNG (animated)](%s)\n[PNG](%s)", *user.AvatarDecorationURL(), *user.AvatarDecorationURL()+"?passthrough=false")
|
||||
@@ -119,7 +128,6 @@ var cmd_userinfo Command = Command{
|
||||
}
|
||||
|
||||
},
|
||||
AllowDM: true,
|
||||
}
|
||||
|
||||
func checkDefaultPb(user discord.User) string {
|
||||
|
10
cmd_ping.go
10
cmd_ping.go
@@ -14,6 +14,15 @@ var cmd_ping Command = Command{
|
||||
Definition: discord.SlashCommandCreate{
|
||||
Name: "ping",
|
||||
Description: "Returns the ping of the bot",
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel,
|
||||
discord.InteractionContextTypeBotDM,
|
||||
},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall,
|
||||
discord.ApplicationIntegrationTypeUserInstall,
|
||||
},
|
||||
},
|
||||
Interact: func(e *events.ApplicationCommandInteractionCreate) {
|
||||
start := time.Now()
|
||||
@@ -51,5 +60,4 @@ var cmd_ping Command = Command{
|
||||
logrus.Error(err)
|
||||
}
|
||||
},
|
||||
AllowDM: true,
|
||||
}
|
||||
|
@@ -13,6 +13,11 @@ var cmd_sticky Command = Command{
|
||||
Name: "sticky",
|
||||
Description: "Stick or unstick messages to the bottom of the current channel",
|
||||
DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageMessages),
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall},
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
&discord.ApplicationCommandOptionString{
|
||||
Name: "message",
|
||||
@@ -53,6 +58,11 @@ var context_sticky Command = Command{
|
||||
Definition: discord.MessageCommandCreate{
|
||||
Name: "Stick to channel",
|
||||
DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageMessages),
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall},
|
||||
},
|
||||
Interact: func(e *events.ApplicationCommandInteractionCreate) {
|
||||
inputStickyMessage(e)
|
||||
|
16
cmd_tag.go
16
cmd_tag.go
@@ -7,11 +7,17 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// TODO: make user installable tag command using userIDs instead of guildIDs
|
||||
var cmd_tag Command = Command{
|
||||
Definition: discord.SlashCommandCreate{
|
||||
Name: "tag",
|
||||
DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageGuild),
|
||||
Description: "A command to show and edit saved presaved messages.",
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall},
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
discord.ApplicationCommandOptionSubCommand{
|
||||
Name: "get",
|
||||
@@ -80,6 +86,11 @@ var cmd_tag_short Command = Command{
|
||||
Definition: discord.SlashCommandCreate{
|
||||
Name: "g",
|
||||
Description: "A short command to get presaved messages.",
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall},
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
discord.ApplicationCommandOptionString{
|
||||
Name: "tag",
|
||||
@@ -101,6 +112,11 @@ var context_tag Command = Command{
|
||||
Definition: discord.MessageCommandCreate{
|
||||
Name: "Save as tag",
|
||||
DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageGuild),
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall},
|
||||
},
|
||||
Interact: func(e *events.ApplicationCommandInteractionCreate) {
|
||||
AddTagCommand(e)
|
||||
|
32
handlers.go
32
handlers.go
@@ -23,7 +23,6 @@ type Command struct {
|
||||
ModalIDs []string
|
||||
DynamicModalIDs func() []string
|
||||
DynamicComponentIDs func() []string
|
||||
AllowDM bool
|
||||
}
|
||||
|
||||
var commands []Command = []Command{cmd_tag, cmd_tag_short, context_tag, cmd_sticky, context_sticky, cmd_ping, cmd_userinfo, cmd_form, cmd_ask, cmd_cat, cmd_dadjoke, cmd_ticket_form, cmd_autopublish, cmd_autojoinroles}
|
||||
@@ -63,44 +62,22 @@ func ready(e *events.Ready) {
|
||||
func applicationCommandInteractionCreate(e *events.ApplicationCommandInteractionCreate) {
|
||||
for _, command := range commands {
|
||||
if command.Interact != nil && e.Data.CommandName() == command.Definition.CommandName() {
|
||||
if !command.AllowDM && e.ApplicationCommandInteraction.GuildID().String() == "" {
|
||||
err := e.CreateMessage(discord.NewMessageCreateBuilder().
|
||||
SetContent("This command is not available in DMs.").SetEphemeral(true).
|
||||
Build())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
} else {
|
||||
command.Interact(e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func autocompleteInteractionCreate(e *events.AutocompleteInteractionCreate) {
|
||||
for _, command := range commands {
|
||||
if command.Autocomplete != nil && e.Data.CommandName == command.Definition.CommandName() {
|
||||
if !command.AllowDM && e.AutocompleteInteraction.GuildID().String() == "" {
|
||||
err := e.AutocompleteResult(nil)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
} else {
|
||||
command.Autocomplete(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func componentInteractionCreate(e *events.ComponentInteractionCreate) {
|
||||
for _, command := range commands {
|
||||
if !command.AllowDM && e.ComponentInteraction.GuildID().String() == "" {
|
||||
e.CreateMessage(discord.NewMessageCreateBuilder().
|
||||
SetContent("This component is not available in DMs.").SetEphemeral(true).
|
||||
Build())
|
||||
} else {
|
||||
if command.ComponentInteract != nil {
|
||||
if slices.Contains(command.ComponentIDs, e.Data.CustomID()) || slices.ContainsFunc(command.DynamicComponentIDs(), func(id string) bool {
|
||||
var customID string
|
||||
@@ -115,16 +92,10 @@ func componentInteractionCreate(e *events.ComponentInteractionCreate) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func modalSubmitInteractionCreate(e *events.ModalSubmitInteractionCreate) {
|
||||
for _, command := range commands {
|
||||
if !command.AllowDM && e.ModalSubmitInteraction.GuildID().String() == "" {
|
||||
e.CreateMessage(discord.NewMessageCreateBuilder().
|
||||
SetContent("This modal is not available in DMs.").SetEphemeral(true).
|
||||
Build())
|
||||
} else {
|
||||
if command.ModalSubmit != nil {
|
||||
var hasID bool = false
|
||||
var modalIDs []string
|
||||
@@ -146,7 +117,6 @@ func modalSubmitInteractionCreate(e *events.ModalSubmitInteractionCreate) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func removeOldCommandFromAllGuilds(c bot.Client) {
|
||||
@@ -201,7 +171,6 @@ func messageCreate(e *events.MessageCreate) {
|
||||
logrus.Error(err)
|
||||
}
|
||||
if channel != nil && channel.Type() == discord.ChannelTypeGuildNews {
|
||||
logrus.Debug("HERE")
|
||||
if isAutopublishEnabled(e.GuildID.String(), e.ChannelID.String()) {
|
||||
_, err := e.Client().Rest().CrosspostMessage(e.ChannelID, e.MessageID)
|
||||
if err != nil {
|
||||
@@ -217,7 +186,6 @@ func messageDelete(e *events.MessageDelete) { //TODO: also clear on bot start wh
|
||||
}
|
||||
|
||||
func guildMemberJoin(e *events.GuildMemberJoin) {
|
||||
logrus.Debug("TESSST")
|
||||
role := getAutoJoinRole(e.GuildID.String(), e.Member.User.Bot)
|
||||
if role != "" {
|
||||
err := e.Client().Rest().AddMemberRole(e.GuildID, e.Member.User.ID, snowflake.MustParse(role))
|
||||
|
Reference in New Issue
Block a user