continued porting to disgo...

This commit is contained in:
2024-04-09 23:21:08 +02:00
parent 01ac1ec363
commit b7f126efba
10 changed files with 284 additions and 379 deletions

View File

@@ -1,35 +1,30 @@
package main
/*
import (
"github.com/bwmarrin/discordgo"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus"
)
var cmd_ask Command = Command{
Definition: discordgo.ApplicationCommand{
var cmd_ask = Command{
Definition: discord.SlashCommandCreate{
Name: "ask",
Description: "Ask anything and get a gif as response!",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Options: []discord.ApplicationCommandOption{
&discord.ApplicationCommandOptionString{
Name: "question",
Description: "The question you want to ask",
Required: true,
},
},
},
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
err := respondEmbed(i.Interaction, discordgo.MessageEmbed{
Type: discordgo.EmbedTypeImage,
Color: hexToDecimal(color["primary"]),
Image: &discordgo.MessageEmbedImage{
URL: simpleGetFromAPI("image", "https://yesno.wtf/api").(string),
}}, false)
Interact: func(e *events.ApplicationCommandInteractionCreate) {
err := e.CreateMessage(discord.NewMessageCreateBuilder().
AddEmbeds(discord.NewEmbedBuilder().SetImage(simpleGetFromAPI("image", "https://yesno.wtf/api").(string)).SetColor(hexToDecimal(color["primary"])).Build()).
Build())
if err != nil {
logrus.Error("Failed to respond with embed: ", err)
logrus.Error(err)
}
},
AllowDM: true,
}
*/

View File

@@ -1,25 +1,29 @@
package main
/*
var cmd_cat Command = Command{
Definition: discordgo.ApplicationCommand{
import (
"encoding/json"
"io"
"net/http"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus"
)
var cmd_cat = Command{
Definition: discord.SlashCommandCreate{
Name: "cat",
Description: "Random cat pictures",
},
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
Interact: func(e *events.ApplicationCommandInteractionCreate) {
cat, err := GetCatImageURL()
if err == nil {
err := respondEmbed(i.Interaction, discordgo.MessageEmbed{
Type: discordgo.EmbedTypeImage,
Color: hexToDecimal(color["primary"]),
Image: &discordgo.MessageEmbedImage{
URL: cat,
}}, false)
err = e.CreateMessage(discord.NewMessageCreateBuilder().
AddEmbeds(discord.NewEmbedBuilder().SetImage(cat).SetColor(hexToDecimal(color["primary"])).Build()).
Build())
if err != nil {
logrus.Error(err)
}
} else {
logrus.Error(err)
}
},
AllowDM: true,
@@ -44,4 +48,3 @@ func GetCatImageURL() (string, error) {
return "https://cataas.com/cat/" + images.ID, err
}
*/

View File

@@ -1,22 +1,24 @@
package main
/*
import (
"github.com/bwmarrin/discordgo"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus"
)
var cmd_dadjoke Command = Command{
Definition: discordgo.ApplicationCommand{
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",
},
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
err := respond(i.Interaction, simpleGetFromAPI("joke", "https://icanhazdadjoke.com/").(string), false)
Interact: func(e *events.ApplicationCommandInteractionCreate) {
joke := simpleGetFromAPI("joke", "https://icanhazdadjoke.com/").(string)
err := e.CreateMessage(discord.NewMessageCreateBuilder().
SetContent(joke).
Build())
if err != nil {
logrus.Error(err)
}
},
AllowDM: true,
}
*/

View File

@@ -1,65 +1,68 @@
package main
/*
import (
"bytes"
"fmt"
"strings"
"github.com/bwmarrin/discordgo"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/json"
"github.com/disgoorg/snowflake/v2"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
)
var cmd_form Command = Command{
Definition: discordgo.ApplicationCommand{
Definition: discord.SlashCommandCreate{
Name: "form",
DefaultMemberPermissions: int64Ptr(discordgo.PermissionManageChannels),
DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageChannels),
Description: "Create custom forms right inside Discord",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionSubCommand,
Options: []discord.ApplicationCommandOption{
&discord.ApplicationCommandOptionSubCommand{
Name: "help",
Description: "Gives you a example file and demo for creating custom forms",
Description: "Gives you an example file and demo for creating custom forms",
},
{
Type: discordgo.ApplicationCommandOptionSubCommand,
&discord.ApplicationCommandOptionSubCommand{
Name: "custom",
Description: "Create a new custom form right inside Discord",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionAttachment,
Options: []discord.ApplicationCommandOption{
&discord.ApplicationCommandOptionAttachment{
Name: "json",
Description: "Your edited form file",
Required: true,
},
},
},
{
Type: discordgo.ApplicationCommandOptionSubCommand,
&discord.ApplicationCommandOptionSubCommand{
Name: "add",
Description: "Adds existing forms to this channel",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionChannel,
Options: []discord.ApplicationCommandOption{
&discord.ApplicationCommandOptionChannel{
Name: "result_channel",
Description: "Where the form results should appear",
ChannelTypes: []discordgo.ChannelType{discordgo.ChannelTypeGuildText},
ChannelTypes: []discord.ChannelType{discord.ChannelTypeGuildText},
},
{
Type: discordgo.ApplicationCommandOptionMentionable,
&discord.ApplicationCommandOptionMentionable{
Name: "moderator",
Description: "Who can interact with moderating buttons.",
},
{
Type: discordgo.ApplicationCommandOptionString,
&discord.ApplicationCommandOptionString{
Name: "type",
Description: "Which type of form you want to add",
Autocomplete: true,
},
{
Type: discordgo.ApplicationCommandOptionString,
&discord.ApplicationCommandOptionString{
Name: "title",
Description: "The title the form should have",
},
{
Type: discordgo.ApplicationCommandOptionChannel,
&discord.ApplicationCommandOptionChannel{
Name: "approve_channel",
Description: "Channel for results that need to be accepted by a moderator before sending it to the result channel",
ChannelTypes: []discordgo.ChannelType{discordgo.ChannelTypeGuildText},
ChannelTypes: []discord.ChannelType{discord.ChannelTypeGuildText},
},
{
Type: discordgo.ApplicationCommandOptionBoolean,
&discord.ApplicationCommandOptionBool{
Name: "mods_can_answer",
Description: "Moderators can open a new channel on the form result, which then pings the user who submitted it",
},
@@ -67,8 +70,8 @@ var cmd_form Command = Command{
},
},
},
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
switch i.ApplicationCommandData().Options[0].Name {
Interact: func(e *events.ApplicationCommandInteractionCreate) {
switch *e.SlashCommandInteractionData().SubCommandName {
case "help":
fileData, err := formTemplates.ReadFile("form_templates/form_demo.json")
if err != nil {
@@ -76,39 +79,18 @@ var cmd_form Command = Command{
return
}
fileReader := bytes.NewReader(fileData)
err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "NOT SUPPORTED YET!(use `/form add` instead)\n\nGet the example file edit it (make sure to have a unique \"form_type\") and submit it via `/form create`.\nOr use the demo button to get an idea of how the example would look like.",
Flags: discordgo.MessageFlagsEphemeral,
Files: []*discordgo.File{
{
Name: "example.json",
ContentType: "json",
Reader: fileReader,
},
},
Components: []discordgo.MessageComponent{
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
discordgo.Button{
Emoji: discordgo.ComponentEmoji{
Name: "📑",
},
CustomID: "form_demo",
Label: "Demo",
Style: discordgo.PrimaryButton,
},
},
},
},
},
})
err = e.CreateMessage(discord.NewMessageCreateBuilder().
SetContent("NOT SUPPORTED YET!(use `/form add` instead)\n\nGet the example file edit it (make sure to have a unique \"form_type\") and submit it via `/form create`.\nOr use the demo button to get an idea of how the example would look like.").
SetFiles(discord.NewFile("example.json", "json", fileReader)).
SetContainerComponents(discord.ActionRowComponent{discord.NewPrimaryButton("Demo", "form_demo").WithEmoji(discord.ComponentEmoji{Name: "📑"})}).SetEphemeral(true).
Build())
if err != nil {
logrus.Error(err)
}
case "custom":
err := respond(i.Interaction, "Feature not available yet use `/form add` instead", true)
err := e.CreateMessage(discord.NewMessageCreateBuilder().
SetContent("Feature not available yet use `/form add` instead").SetEphemeral(true).
Build())
if err != nil {
logrus.Error(err)
}
@@ -116,30 +98,21 @@ var cmd_form Command = Command{
var title, formID, overwriteTitle, acceptChannelID string
var modsCanAnswer bool
var resultChannelID string
moderator := i.Member.User.ID
if i.ApplicationCommandData().Options != nil {
options := i.ApplicationCommandData().Options[0]
for _, opt := range options.Options {
switch opt.Name {
case "result_channel":
resultChannelID = opt.ChannelValue(s).ID
case "type":
formID = opt.StringValue()
case "title":
overwriteTitle = opt.StringValue()
title = overwriteTitle
case "approve_channel":
acceptChannelID = opt.ChannelValue(s).ID
case "mods_can_answer":
modsCanAnswer = opt.BoolValue()
case "moderator":
moderator = opt.RoleValue(s, i.GuildID).ID
moderator := e.Member().User.ID.String()
data := e.SlashCommandInteractionData()
resultChannelID = data.Channel("result_channel").ID.String()
moderator = data.Role("moderator").ID.String()
if moderator == "" {
moderator = opt.UserValue(s).ID
}
}
moderator = data.User("moderator").ID.String()
}
formID = data.String("type")
overwriteTitle = data.String("title")
if overwriteTitle != "" {
title = overwriteTitle
}
acceptChannelID = data.Channel("accept_channel").ID.String()
modsCanAnswer = data.Bool("mods_can_answer")
if formID == "" {
formID = "template_general"
}
@@ -159,44 +132,29 @@ var cmd_form Command = Command{
formManageID = uuid.New()
exists = getFormManageIdExists(formManageID)
}
message, err := s.ChannelMessageSendComplex(i.ChannelID, &discordgo.MessageSend{
Embed: &discordgo.MessageEmbed{
Color: hexToDecimal(color["primary"]),
Title: title,
Description: "Press the bottom button to open a form popup.",
},
Components: []discordgo.MessageComponent{
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
discordgo.Button{
CustomID: "form:" + formManageID.String(),
Style: discordgo.SuccessButton,
Label: "Submit",
Emoji: discordgo.ComponentEmoji{
messagebuild := discord.NewMessageCreateBuilder().SetEmbeds(discord.NewEmbedBuilder().
SetTitle(title).SetDescription("Press the bottom button to open a form popup.").SetColor(hexToDecimal(color["primary"])).
Build()).SetContainerComponents(discord.ActionRowComponent{
discord.NewSuccessButton("Submit", "form:"+formManageID.String()).WithEmoji(discord.ComponentEmoji{
Name: "anim_rocket",
ID: "1215740398706757743",
ID: snowflake.MustParse("1215740398706757743"),
Animated: true,
},
},
},
},
},
})
})}).
Build()
message, err := e.Client().Rest().CreateMessage(e.Channel().ID(), messagebuild)
if err != nil {
logrus.Error(err)
return
}
var category string
if modsCanAnswer {
c, err := s.GuildChannelCreate(i.GuildID, title+" mod answers", discordgo.ChannelTypeGuildCategory)
c, err := e.Client().Rest().CreateGuildChannel(*e.GuildID(), discord.GuildCategoryChannelCreate{Name: title + " mod answers"})
if err != nil {
logrus.Error(err)
}
category = c.ID
category = c.ID().String()
}
addFormButton(i.GuildID, i.ChannelID, message.ID, formManageID.String(), formID, resultChannelID, overwriteTitle, acceptChannelID, category, moderator)
err = respond(i.Interaction, "Successfully added form button!", true)
addFormButton(e.GuildID().String(), e.Channel().ID().String(), message.ID.String(), formManageID.String(), formID, resultChannelID, overwriteTitle, acceptChannelID, category, moderator)
err = e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Successfully added form button!").SetEphemeral(true).Build())
if err != nil {
logrus.Error(err)
}
@@ -204,36 +162,36 @@ var cmd_form Command = Command{
},
DynamicComponentIDs: func() []string { return getFormButtonIDs() },
DynamicModalIDs: func() []string { return getFormButtonIDs() },
ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
if strings.ContainsAny(i.MessageComponentData().CustomID, ";") {
var form_manage_id string = strings.TrimPrefix(strings.Split(i.MessageComponentData().CustomID, ";")[0], "form:")
switch strings.Split(i.MessageComponentData().CustomID, ";")[1] {
ComponentInteract: func(e *events.ComponentInteractionCreate) {
if e.Data.Type() == discord.ComponentTypeButton {
if strings.ContainsAny(e.ButtonInteractionData().CustomID(), ";") {
var form_manage_id string = strings.TrimPrefix(strings.Split(e.ButtonInteractionData().CustomID(), ";")[0], "form:")
switch strings.Split(e.ButtonInteractionData().CustomID(), ";")[1] {
case "decline":
err := s.ChannelMessageDelete(i.ChannelID, i.Message.ID)
err := e.Client().Rest().DeleteMessage(e.Channel().ID(), e.Message.ID)
if err != nil {
logrus.Error(err)
}
respond(i.Interaction, "Submission declined!", true)
e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Submission declined!").SetEphemeral(true).Build())
case "approve":
embed := i.Message.Embeds[0]
embed.Description = fmt.Sprintf("This submission was approved by <@%s>.", i.Member.User.ID)
_, err := s.ChannelMessageSendComplex(getFormResultValues(form_manage_id).ResultChannelID, &discordgo.MessageSend{
Embed: embed,
})
embed := e.Message.Embeds[0]
embed.Description = fmt.Sprintf("This submission was approved by <@%s>.", e.Member().User.ID)
_, err := e.Client().Rest().CreateMessage(snowflake.MustParse(getFormResultValues(form_manage_id).ResultChannelID), discord.NewMessageCreateBuilder().
SetEmbeds(embed).
Build())
if err != nil {
logrus.Error(err)
}
respond(i.Interaction, "Submission accepted!", true)
err = s.ChannelMessageDelete(i.ChannelID, i.Message.ID)
e.CreateMessage(discord.NewMessageCreateBuilder().SetContent("Submission accepted!").SetEphemeral(true).Build())
err = e.Client().Rest().DeleteMessage(e.Channel().ID(), e.Message.ID)
if err != nil {
logrus.Error(err)
}
case "comment":
author := strings.TrimSuffix(strings.Split(i.Message.Embeds[0].Fields[len(i.Message.Embeds[0].Fields)-1].Value, "<@")[1], ">")
embed := i.Message.Embeds[0]
moderator := i.Member.User.ID
createFormComment(form_manage_id, author, moderator, "answer", embed, i)
author := strings.TrimSuffix(strings.Split(e.Message.Embeds[0].Fields[len(e.Message.Embeds[0].Fields)-1].Value, "<@")[1], ">")
embed := e.Message.Embeds[0]
moderator := e.Member().User.ID
createFormComment(form_manage_id, author, moderator, "answer", embed, e)
}
} else {
if strings.HasPrefix(i.Interaction.MessageComponentData().CustomID, "form:") {
@@ -243,6 +201,7 @@ var cmd_form Command = Command{
jsonStringShowModal(i.Interaction, "form_demo", "form_demo")
}
}
}
},
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
if !strings.HasPrefix(i.ModalSubmitData().CustomID, "form_demo") {
@@ -507,18 +466,18 @@ var cmd_ticket_form Command = Command{
}
// moderator can be userID as well as roleID
func createFormComment(form_manage_id string, author string, moderator string, commentName string, embed *discordgo.MessageEmbed, i *discordgo.InteractionCreate) {
category := getFormResultValues(form_manage_id).CommentCategoryID
_, err := bot.Channel(category)
func createFormComment(form_manage_id string, author string, moderator snowflake.ID, commentName string, embed discord.Embed, e *events.ComponentInteractionCreate) {
var category snowflake.ID
_, err := e.Client().Rest().GetChannel(snowflake.MustParse(getFormResultValues(form_manage_id).CommentCategoryID))
if err != nil {
c, err := bot.GuildChannelCreate(i.GuildID, strings.Trim(embed.Title, "\"")+" mod "+commentName+"s", discordgo.ChannelTypeGuildCategory)
c, err := e.Client().Rest().CreateGuildChannel(*e.GuildID(), discord.GuildCategoryChannelCreate{Name: strings.Trim(embed.Title, "\"") + " mod " + commentName + "s"})
if err != nil {
logrus.Error(err)
}
category = c.ID
updateFormCommentCategory(form_manage_id, c.ID)
category = c.ID()
updateFormCommentCategory(form_manage_id, category.String())
}
ch, err := bot.GuildChannelCreateComplex(i.GuildID, discordgo.GuildChannelCreateData{
ch, err := e.Client().Rest().CreateGuildChannel(*e.GuildID(), discord.GuildTextChannelCreate{
ParentID: category,
Name: strings.ToLower(embed.Author.Name) + "-" + commentName,
})
@@ -526,6 +485,7 @@ func createFormComment(form_manage_id string, author string, moderator string, c
logrus.Error(err)
}
err = bot.ChannelPermissionSet(ch.ID, i.GuildID, discordgo.PermissionOverwriteTypeRole, 0, discordgo.PermissionViewChannel)
_, err = e.Client().Rest().UpdateChannel(ch.ID(), discord.GuildTextChannelUpdate{PermissionOverwrites: &[]discord.PermissionOverwrite{}})
if err != nil {
logrus.Error(err)
}
@@ -563,4 +523,3 @@ func getFormButtonIDs() []string {
}
return IDs
}
*/

View File

@@ -1,17 +1,12 @@
package main
/*
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/bwmarrin/discordgo"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus"
)
@@ -25,128 +20,98 @@ type AvatarDecoration struct {
URL string
}
var userFlagsString map[discordgo.UserFlags]string = map[discordgo.UserFlags]string{
discordgo.UserFlagDiscordEmployee: "<:Discord_Employee:1224708831419043942>[`Discord Employee`](https://discord.com/company)",
discordgo.UserFlagDiscordPartner: "<:Discord_Partner:1224708689190060092>[`Discord Partner`](https://discord.com/partners)",
discordgo.UserFlagHypeSquadEvents: "<:Hypesquad_Events:1224708685494747237>[`HypeSquad Events`](https://discord.com/hypesquad)",
discordgo.UserFlagBugHunterLevel1: "<:Bug_Hunter_Level_1:1224708828415918231>[`Bug Hunter Level 1`](https://support.discord.com/hc/en-us/articles/360046057772-Discord-Bugs)",
discordgo.UserFlagHouseBravery: "<:Hypesquad_Bravery:1224708678905630801>[`HypeSquad Bravery`](https://discord.com/settings/hypesquad-online)",
discordgo.UserFlagHouseBrilliance: "<:Hypesquad_Brilliance:1224708677584424961>[`HypeSquad Brilliance`](https://discord.com/settings/hypesquad-online)",
discordgo.UserFlagHouseBalance: "<:Hypequad_Balance:1224708826901516309>[`HypeSquad Balance`](https://discord.com/settings/hypesquad-online)",
discordgo.UserFlagEarlySupporter: "<:Early_Supporter:1224708674065272873>[`Early Supporter`](https://discord.com/settings/premium)",
discordgo.UserFlagTeamUser: "`TeamUser`",
discordgo.UserFlagSystem: "",
discordgo.UserFlagBugHunterLevel2: "<:Bug_Hunter_Level_2:1224708682378383461>[`Bug Hunter Level 2`](https://support.discord.com/hc/en-us/articles/360046057772-Discord-Bugs)",
discordgo.UserFlagVerifiedBot: "",
discordgo.UserFlagVerifiedBotDeveloper: "<:Early_Verified_Bot_Developer:1224708675294203934>`Early Verified Bot Developer`",
discordgo.UserFlagDiscordCertifiedModerator: "<:Discord_Certified_Moderator:1224708830223532124>[`Discord Certified Moderator`](https://discord.com/safety)",
1 << 19: "`BotHTTPInteractions`",
1 << 22: "<:Active_Developer:1224708676611215380>[`Active Developer`](https://support-dev.discord.com/hc/en-us/articles/10113997751447?ref=badge)",
var userFlagsString map[discord.UserFlags]string = map[discord.UserFlags]string{
discord.UserFlagDiscordEmployee: "<:Discord_Employee:1224708831419043942>[`Discord Employee`](https://discord.com/company)",
discord.UserFlagPartneredServerOwner: "<:Discord_Partner:1224708689190060092>[`Discord Partner`](https://discord.com/partners)",
discord.UserFlagHypeSquadEvents: "<:Hypesquad_Events:1224708685494747237>[`HypeSquad Events`](https://discord.com/hypesquad)",
discord.UserFlagBugHunterLevel1: "<:Bug_Hunter_Level_1:1224708828415918231>[`Bug Hunter Level 1`](https://support.discord.com/hc/en-us/articles/360046057772-Discord-Bugs)",
discord.UserFlagHouseBravery: "<:Hypesquad_Bravery:1224708678905630801>[`HypeSquad Bravery`](https://discord.com/settings/hypesquad-online)",
discord.UserFlagHouseBrilliance: "<:Hypesquad_Brilliance:1224708677584424961>[`HypeSquad Brilliance`](https://discord.com/settings/hypesquad-online)",
discord.UserFlagHouseBalance: "<:Hypequad_Balance:1224708826901516309>[`HypeSquad Balance`](https://discord.com/settings/hypesquad-online)",
discord.UserFlagEarlySupporter: "<:Early_Supporter:1224708674065272873>[`Early Supporter`](https://discord.com/settings/premium)",
discord.UserFlagTeamUser: "`TeamUser`",
discord.UserFlagBugHunterLevel2: "<:Bug_Hunter_Level_2:1224708682378383461>[`Bug Hunter Level 2`](https://support.discord.com/hc/en-us/articles/360046057772-Discord-Bugs)",
discord.UserFlagVerifiedBot: "",
discord.UserFlagEarlyVerifiedBotDeveloper: "<:Early_Verified_Bot_Developer:1224708675294203934>`Early Verified Bot Developer`",
discord.UserFlagDiscordCertifiedModerator: "<:Discord_Certified_Moderator:1224708830223532124>[`Discord Certified Moderator`](https://discord.com/safety)",
discord.UserFlagBotHTTPInteractions: "`BotHTTPInteractions`",
discord.UserFlagActiveDeveloper: "<:Active_Developer:1224708676611215380>[`Active Developer`](https://support-dev.discord.com/hc/en-us/articles/10113997751447?ref=badge)",
}
var cmd_userinfo Command = Command{
Definition: discordgo.ApplicationCommand{
Definition: discord.SlashCommandCreate{
Name: "info",
Description: "Gives you information about a user or this bot.",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionSubCommand,
Options: []discord.ApplicationCommandOption{
&discord.ApplicationCommandOptionSubCommand{
Name: "user",
Description: "Gives you information about a user and its profile images.",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionUser,
Options: []discord.ApplicationCommandOption{
&discord.ApplicationCommandOptionUser{
Name: "user",
Description: "The user you need information about.",
Required: true,
},
},
},
{
Type: discordgo.ApplicationCommandOptionSubCommand,
&discord.ApplicationCommandOptionSubCommand{
Name: "bot-service",
Description: "Gives you information about this bot's server service.",
},
},
},
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
switch i.ApplicationCommandData().Options[0].Name {
Interact: func(e *events.ApplicationCommandInteractionCreate) {
switch *e.SlashCommandInteractionData().SubCommandName {
case "user":
var user *discordgo.User = i.ApplicationCommandData().Options[0].Options[0].UserValue(s)
var extendedUser UserExtend = extendedUserFromAPI(user.ID)
var userHasFlags string = fetchFlagStrings(user, extendedUser.AvatarDecorationData.Asset)
var user discord.User = e.SlashCommandInteractionData().User("user")
var userHasFlags string = fetchFlagStrings(user)
var userType string = "User"
if user.Bot {
userType = "Unverified Bot"
if user.PublicFlags&discordgo.UserFlagVerifiedBot != 0 {
if user.PublicFlags&discord.UserFlagVerifiedBot != 0 {
userType = "Verified Bot"
}
} else if user.System {
userType = "System"
}
createdate, err := discordgo.SnowflakeTimestamp(user.ID)
if err != nil {
logrus.Error(err)
}
err = respondEmbed(i.Interaction, discordgo.MessageEmbed{
Title: extendedUser.GlobalName + " user info",
Thumbnail: &discordgo.MessageEmbedThumbnail{URL: user.AvatarURL("512")},
Description: user.Mention(),
Type: discordgo.EmbedTypeArticle,
Fields: []*discordgo.MessageEmbedField{
{
Name: "test",
Value: fmt.Sprint(s.State.Application.BotPublic),
},
{
Name: "ID",
Value: user.ID,
},
{
Name: "Type",
Value: userType,
Inline: true,
},
{
Name: "Global name",
Value: extendedUser.GlobalName,
Inline: true,
},
{
Name: "Username",
Value: user.Username,
Inline: true,
},
{
Name: "Badges",
Value: userHasFlags,
},
{
Name: "Discriminator",
Value: user.Discriminator,
Inline: true,
},
{
Name: "Accent color",
Value: "#" + decimalToHex(user.AccentColor),
Inline: true,
},
{
Name: "Avatar Decoration",
Value: "[PNG (animated)](" + extendedUser.AvatarDecorationData.URL + ")\n[PNG](" + extendedUser.AvatarDecorationData.URL + "?size=4096&passthrough=false)\nSKU ID: `" + extendedUser.AvatarDecorationData.SkuID + "`",
Inline: true,
},
{
Name: "Created at",
Value: "<:discord_member:1224717530078253166> <t:" + fmt.Sprint(createdate.Unix()) + ":f> - <t:" + fmt.Sprint(createdate.Unix()) + ":R>",
},
},
Color: hexToDecimal(color["primary"]),
Image: &discordgo.MessageEmbedImage{URL: user.BannerURL("512")},
}, false)
embedBuilder := discord.NewEmbedBuilder()
embedBuilder.SetThumbnail(checkDefaultPb(user))
embedBuilder.AddField("ID", user.ID.String(), false)
embedBuilder.AddField("Type", userType, true)
if user.GlobalName != nil {
embedBuilder.AddField("Global name", *user.GlobalName, true)
}
embedBuilder.AddField("Username", user.Username, true)
if userHasFlags != "" {
embedBuilder.AddField("Badges", userHasFlags, false)
}
if user.Discriminator != "0" {
embedBuilder.AddField("Discriminator", user.Discriminator, false)
}
if user.AccentColor != nil {
embedBuilder.AddField("Accent color", strconv.Itoa(*user.AccentColor), true)
}
if user.AvatarDecorationURL() != nil {
decoration := strings.TrimSuffix(*user.AvatarDecorationURL(), ".gif")
value := fmt.Sprintf("[PNG (animated)](%s)\n[PNG](%s)", decoration, decoration+"?passthrough=false")
embedBuilder.AddField("Avatar decoration", value, true)
}
creation := "<:discord_member:1224717530078253166> " + discord.TimestampStyleLongDateTime.FormatTime(user.CreatedAt()) + "-" + discord.TimestampStyleRelative.FormatTime(user.CreatedAt())
embedBuilder.AddField("Created at", creation, false)
if user.BannerURL() != nil {
embedBuilder.SetImage(*user.BannerURL())
}
embedBuilder.SetTitle("User info")
embedBuilder.SetDescription(user.Mention())
embedBuilder.SetColor(hexToDecimal(color["primary"]))
embedBuilder.SetFooterText("Currently a bit broken because of Discord's constant user API changes")
err := e.CreateMessage(discord.NewMessageCreateBuilder().
SetEmbeds(embedBuilder.Build()).
Build())
if err != nil {
logrus.Error(err)
}
case "bot-service":
}
@@ -155,19 +120,27 @@ var cmd_userinfo Command = Command{
AllowDM: true,
}
func fetchFlagStrings(user *discordgo.User, decorationAsset string) string {
func checkDefaultPb(user discord.User) string {
if user.AvatarURL() == nil {
return "https://discord.com/assets/ac6f8cf36394c66e7651.png"
}
return *user.AvatarURL()
}
func fetchFlagStrings(user discord.User) string {
var userHasFlagsString string
for flag, flagName := range userFlagsString {
if user.PublicFlags&flag != 0 {
if flag&user.PublicFlags != 0 {
userHasFlagsString += flagName + ", "
}
}
if noNullString(user.AvatarDecorationData.Asset) == "a_5e1210779d99ece1c0b4f438a5bc6e72" {
userHasFlagsString += "<:Limited_Lootbox_Clown:1224714172705804300>[`Lootbox Clown`](https://discord.com/settings/Lootboxes)"
}
/*
if user.PremiumType > 0 {
userHasFlagsString += "<:Nitro:1224708672492666943>[`Nitro`](https://discord.com/settings/premium), "
}
if decorationAsset == "a_5e1210779d99ece1c0b4f438a5bc6e72" {
userHasFlagsString += "<:Limited_Lootbox_Clown:1224714172705804300>[`Lootbox Clown`](https://discord.com/settings/Lootboxes)"
}
if user.Bot {
appuser := bot.State.Application
if appuser.Flags&1<<23 != 0 {
@@ -177,60 +150,7 @@ func fetchFlagStrings(user *discordgo.User, decorationAsset string) string {
userHasFlagsString += "<:Uses_Automod:1224862880982106202>`Uses Automod`"
}
}
*/
returnString := strings.TrimSuffix(userHasFlagsString, ", ")
return returnString
}
func extendedUserFromAPI(userID string) UserExtend {
client := &http.Client{}
var userExtend UserExtend
req, err := http.NewRequest("GET", "https://discord.com/api/v10/users/"+userID, nil)
if err != nil {
logrus.Error(err)
return userExtend
}
req.Header.Add("Authorization", "Bot "+os.Getenv("BOT_TOKEN"))
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
logrus.Error(err)
return userExtend
}
defer res.Body.Close()
if res.StatusCode == http.StatusTooManyRequests {
retryAfter := parseRetryAfterHeader(res.Header)
if retryAfter > 0 {
time.Sleep(retryAfter)
}
}
body, err := io.ReadAll(res.Body)
if err != nil {
logrus.Error(err)
return userExtend
}
json.Unmarshal(body, &userExtend)
if userExtend.AvatarDecorationData.Asset != "" {
userExtend.AvatarDecorationData.URL = "https://cdn.discordapp.com/avatar-decoration-presets/" + userExtend.AvatarDecorationData.Asset + ".png"
}
return userExtend
}
func parseRetryAfterHeader(headers http.Header) time.Duration {
retryAfterStr := headers.Get("Retry-After")
if retryAfterStr == "" {
return 0
}
retryAfter, err := strconv.Atoi(retryAfterStr)
if err != nil {
return 0
}
return time.Duration(retryAfter) * time.Millisecond
}
*/

View File

@@ -1,28 +1,28 @@
package main
/*
import (
"fmt"
"net/http"
"time"
"github.com/bwmarrin/discordgo"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus"
)
var cmd_ping Command = Command{
Definition: discordgo.ApplicationCommand{
Definition: discord.SlashCommandCreate{
Name: "ping",
Description: "Returns the ping of the bot",
},
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
Interact: func(e *events.ApplicationCommandInteractionCreate) {
start := time.Now()
client := http.Client{
Timeout: 5 * time.Second,
}
resp, err := client.Get("https://discord.com/api/" + discordgo.APIVersion + "/gateway/bot")
resp, err := client.Get("https://discord.com/api/v9/gateway/bot")
if err != nil {
logrus.Error(err)
return
@@ -30,23 +30,26 @@ var cmd_ping Command = Command{
defer resp.Body.Close()
ping := time.Since(start)
var ping_color string
var pingColor string
if ping.Milliseconds() < 200 {
ping_color = "green"
pingColor = "green"
} else if ping.Milliseconds() < 400 {
ping_color = "yellow"
pingColor = "yellow"
} else {
ping_color = "red"
pingColor = "red"
}
err = respondEmbed(i.Interaction, discordgo.MessageEmbed{
Title: s.State.User.Username + " ping",
Description: fmt.Sprintf("# %.2fms", ping.Seconds()*1000),
Type: discordgo.EmbedTypeArticle,
Color: hexToDecimal(color[ping_color])}, true)
app, err := e.Client().Rest().GetCurrentApplication()
if err != nil {
logrus.Error(err)
}
err = e.CreateMessage(discord.NewMessageCreateBuilder().
SetEmbeds(discord.NewEmbedBuilder().
SetTitle(app.Bot.Username + " ping").
SetDescription(fmt.Sprintf("# %.2fms", ping.Seconds()*1000)).
SetColor(hexToDecimal(color[pingColor])).Build()).SetEphemeral(true).Build())
if err != nil {
logrus.Error(err)
}
},
AllowDM: true,
}
*/

8
go.mod
View File

@@ -3,7 +3,7 @@ module github.com/vaporvee/acecore
go 1.21.6
require (
github.com/disgoorg/disgo v0.17.2
github.com/disgoorg/disgo v0.18.0
github.com/disgoorg/json v1.1.0
github.com/disgoorg/snowflake/v2 v2.0.1
github.com/google/uuid v1.6.0
@@ -15,9 +15,9 @@ require (
require (
github.com/gorilla/websocket v1.5.1 // indirect
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
)
replace github.com/vaporvee/acecore/custom => ./custom

8
go.sum
View File

@@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/disgoorg/disgo v0.17.2 h1:RxiLq8guMtk+9tArFwve02iya2APQ9yZVtV30ySKNtw=
github.com/disgoorg/disgo v0.17.2/go.mod h1:8r3h9fXSz7BbACxLPsPbtB6LX8gaQFUETgPKV/0gAKQ=
github.com/disgoorg/disgo v0.18.0 h1:EviKy/OiGofYW2X4kLjgxAUYrqjmBEMpVp/MMXHP1pY=
github.com/disgoorg/disgo v0.18.0/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o=
github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys=
github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
github.com/disgoorg/snowflake/v2 v2.0.1 h1:CuUxGLwggUxEswZOmZ+mZ5i0xSumQdXW9tXW7uGqe+0=
@@ -27,11 +29,17 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

View File

@@ -26,7 +26,7 @@ type Command struct {
AllowDM bool
}
var commands []Command = []Command{cmd_tag, cmd_tag_short, context_tag, cmd_sticky, context_sticky /*, cmd_form, cmd_ticket_form, cmd_dadjoke, cmd_ping, cmd_ask, cmd_cat, cmd_autojoinroles, cmd_autopublish, cmd_userinfo*/}
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_autojoinroles, cmd_autopublish*/}
func ready(e *events.Ready) {
logrus.Info("Starting up...")

15
tool.go
View File

@@ -36,6 +36,21 @@ type MessageIDs struct {
ChannelID string
}
func noNullString(in interface{}) string {
var s string = ""
var is_str bool
switch in.(type) {
case string:
is_str = true
case *string:
is_str = true
}
if in != nil && is_str {
s = fmt.Sprint(in)
}
return s
}
func jsonStringShowModal(userID string, manageID string, formID string, overwrite ...string) discord.InteractionResponse {
var modal ModalJson = getModalByFormID(formID)
var components []discord.ContainerComponent