Skip to content

Commit

Permalink
begin moving to disgo
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Sep 2, 2024
1 parent 446af73 commit 3c7384f
Show file tree
Hide file tree
Showing 24 changed files with 485 additions and 365 deletions.
4 changes: 1 addition & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
[submodule "submodules/discordgo"]
path = submodules/discordgo
url = https://github.com/infinitybotlist/discordgo

3 changes: 2 additions & 1 deletion apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"popplio/types"
"popplio/validators/timex"

"github.com/disgoorg/snowflake/v2"
"github.com/infinitybotlist/eureka/uapi"
)

Expand Down Expand Up @@ -234,7 +235,7 @@ You can only have up to one ban appeal at any given point of time. Abusing the s
Hidden: true, // We don't want it to be prominently shown
ReviewLogic: reviewLogicBanAppeal,
Tags: []string{"Ban Appeal"},
Channel: func() string {
Channel: func() snowflake.ID {
return state.Config.Channels.BanAppeals
},
PositionDescription: func(d uapi.RouteData, p types.Position) string {
Expand Down
71 changes: 46 additions & 25 deletions apps/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (
"popplio/state"
"popplio/teams"
"popplio/types"
"popplio/validators"
"strings"

"github.com/bwmarrin/discordgo"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/rest"
"github.com/disgoorg/snowflake/v2"
"github.com/infinitybotlist/eureka/dovewing"
"github.com/infinitybotlist/eureka/uapi"
kittycat "github.com/infinitybotlist/kittycat/go"
Expand Down Expand Up @@ -65,15 +68,15 @@ func extraLogicResubmit(d uapi.RouteData, p types.Position, answers map[string]s
}

// Send an embed to the bot logs channel
_, err = state.Discord.ChannelMessageSendComplex(state.Config.Channels.BotLogs, &discordgo.MessageSend{
_, err = state.Discord.Rest().CreateMessage(state.Config.Channels.BotLogs, discord.MessageCreate{
Content: state.Config.Meta.UrgentMentions,
Embeds: []*discordgo.MessageEmbed{
Embeds: []discord.Embed{
{
Title: "Bot Resubmitted!",
URL: state.Config.Sites.Frontend.Parse() + "/bots/" + botID,
Description: "User <@" + d.Auth.ID + "> has resubmitted their bot",
Color: 0x00ff00,
Fields: []*discordgo.MessageEmbedField{
Fields: []discord.EmbedField{
{
Name: "Bot ID",
Value: botID,
Expand All @@ -85,7 +88,7 @@ func extraLogicResubmit(d uapi.RouteData, p types.Position, answers map[string]s
{
Name: "Reason",
Value: answers["reason"],
Inline: true,
Inline: validators.Pointer(true),
},
},
},
Expand Down Expand Up @@ -158,10 +161,16 @@ func reviewLogicBanAppeal(d uapi.RouteData, resp types.AppResponse, reason strin
return errors.New("reason must be less than 384 characters")
}

err := state.Discord.GuildBanDelete(
userId, err := snowflake.Parse(resp.UserID)

if err != nil {
return fmt.Errorf("error parsing user ID: %w", err)
}

err = state.Discord.Rest().DeleteBan(
state.Config.Servers.Main,
resp.UserID,
discordgo.WithAuditLogReason("Ban appeal accepted by "+d.Auth.ID+" | "+reason),
userId,
rest.WithReason("Ban appeal accepted by "+d.Auth.ID+" | "+reason),
)

if err != nil {
Expand All @@ -184,9 +193,15 @@ func reviewLogicCert(d uapi.RouteData, resp types.AppResponse, reason string, ap
return errors.New("bot ID not found")
}

botIdSnow, err := snowflake.Parse(botID)

if err != nil {
return fmt.Errorf("error parsing bot ID: %w", err)
}

// Get the bot
var botType string
err := state.Pool.QueryRow(d.Context, "SELECT type FROM bots WHERE bot_id = $1", botID).Scan(&botType)
err = state.Pool.QueryRow(d.Context, "SELECT type FROM bots WHERE bot_id = $1", botID).Scan(&botType)

if err != nil {
return fmt.Errorf("error getting bot type, does the bot exist?: %w", err)
Expand All @@ -208,21 +223,21 @@ func reviewLogicCert(d uapi.RouteData, resp types.AppResponse, reason string, ap
}

// Give roles
err = state.Discord.GuildMemberRoleAdd(state.Config.Servers.Main, botID, state.Config.Roles.CertBot)
err = state.Discord.Rest().AddMemberRole(state.Config.Servers.Main, botIdSnow, state.Config.Roles.CertBot)

if err != nil {
return fmt.Errorf("error giving certified bot role to bot, but successfully certified bot: %v", err)
}

// Send an embed to the bot logs channel
_, err = state.Discord.ChannelMessageSendComplex(state.Config.Channels.BotLogs, &discordgo.MessageSend{
Embeds: []*discordgo.MessageEmbed{
_, err = state.Discord.Rest().CreateMessage(state.Config.Channels.BotLogs, discord.MessageCreate{
Embeds: []discord.Embed{
{
Title: "Bot Certified!",
URL: state.Config.Sites.Frontend.Parse() + "/bots/" + botID,
Description: "<@" + d.Auth.ID + "> has certified bot <@" + botID + ">",
Color: 0x00ff00,
Fields: []*discordgo.MessageEmbedField{
Fields: []discord.EmbedField{
{
Name: "Bot ID",
Value: botID,
Expand All @@ -232,7 +247,7 @@ func reviewLogicCert(d uapi.RouteData, resp types.AppResponse, reason string, ap
Value: reason,
},
},
Footer: &discordgo.MessageEmbedFooter{
Footer: &discord.EmbedFooter{
Text: "If you are the owner of this bot, use ibb!getbotroles to get your dev roles",
},
},
Expand All @@ -251,15 +266,21 @@ func reviewLogicCert(d uapi.RouteData, resp types.AppResponse, reason string, ap
}

func reviewLogicStaff(d uapi.RouteData, resp types.AppResponse, reason string, approve bool) error {
userId, err := snowflake.Parse(resp.UserID)

if err != nil {
return fmt.Errorf("error parsing user ID: %w", err)
}

if approve {
err := state.Discord.GuildMemberRoleAdd(state.Config.Servers.Main, resp.UserID, state.Config.Roles.AwaitingStaff)
err := state.Discord.Rest().AddMemberRole(state.Config.Servers.Main, userId, state.Config.Roles.AwaitingStaff)

if err != nil {
return err
}

// DM the user
dmchan, err := state.Discord.UserChannelCreate(resp.UserID)
dmchan, err := state.Discord.Rest().CreateDMChannel(userId)

if err != nil {
return errors.New("could not send DM, please ask the user to accept DMs from server members")
Expand All @@ -269,19 +290,19 @@ func reviewLogicStaff(d uapi.RouteData, resp types.AppResponse, reason string, a
return errors.New("reason must be 1024 characters or less")
}

_, err = state.Discord.ChannelMessageSendComplex(dmchan.ID, &discordgo.MessageSend{
Embeds: []*discordgo.MessageEmbed{
_, err = state.Discord.Rest().CreateMessage(dmchan.ID(), discord.MessageCreate{
Embeds: []discord.Embed{
{
Title: "Staff Application Whitelisted",
Description: "Your staff application has been whitelisted for onboarding! Please ping any manager at #staff-only in our discord server to get started.",
Color: 0x00ff00,
Fields: []*discordgo.MessageEmbedField{
Fields: []discord.EmbedField{
{
Name: "Feedback",
Value: reason,
},
},
Footer: &discordgo.MessageEmbedFooter{
Footer: &discord.EmbedFooter{
Text: "Congratulations!",
},
},
Expand All @@ -300,25 +321,25 @@ func reviewLogicStaff(d uapi.RouteData, resp types.AppResponse, reason string, a
}

// Attempt to DM the user on denial
dmchan, err := state.Discord.UserChannelCreate(resp.UserID)
dmchan, err := state.Discord.Rest().CreateDMChannel(userId)

if err != nil {
return fmt.Errorf("could not create DM channel with user, please inform them manually, then deny with reason of 'MANUALLYNOTIFIED <your reason here>': %w", err)
}

_, err = state.Discord.ChannelMessageSendComplex(dmchan.ID, &discordgo.MessageSend{
Embeds: []*discordgo.MessageEmbed{
_, err = state.Discord.Rest().CreateMessage(dmchan.ID(), discord.MessageCreate{
Embeds: []discord.Embed{
{
Title: "Staff Application Denied",
Description: "Unfortunately, we have denied your staff application for Infinity Bot List. You may reapply later if you wish to",
Color: 0x00ff00,
Fields: []*discordgo.MessageEmbedField{
Fields: []discord.EmbedField{
{
Name: "Reason",
Value: reason,
},
},
Footer: &discordgo.MessageEmbedFooter{
Footer: &discord.EmbedFooter{
Text: "Better luck next time?",
},
},
Expand Down
24 changes: 13 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package config
import (
_ "embed"
"strings"

"github.com/disgoorg/snowflake/v2"
)

const (
Expand Down Expand Up @@ -69,19 +71,19 @@ type Sites struct {
}

type Roles struct {
AwaitingStaff string `yaml:"awaiting_staff" default:"1029058929361174678" comment:"Awaiting Staff Role" validate:"required"`
Apps string `yaml:"apps" default:"907729844605968454" comment:"Apps Role" validate:"required"`
CertBot string `yaml:"cert_bot" default:"759468236999491594" comment:"Certified Bot Role" validate:"required"`
PremiumRoles Differs[[]string] `yaml:"premium_roles" default:"759468236999491594" comment:"Premium Roles" validate:"required"`
AwaitingStaff snowflake.ID `yaml:"awaiting_staff" default:"1029058929361174678" comment:"Awaiting Staff Role" validate:"required"`
Apps snowflake.ID `yaml:"apps" default:"907729844605968454" comment:"Apps Role" validate:"required"`
CertBot snowflake.ID `yaml:"cert_bot" default:"759468236999491594" comment:"Certified Bot Role" validate:"required"`
PremiumRoles Differs[[]snowflake.ID] `yaml:"premium_roles" default:"759468236999491594" comment:"Premium Roles" validate:"required"`
}

type Channels struct {
BotLogs string `yaml:"bot_logs" default:"762077915499593738" comment:"Bot Logs Channel" validate:"required"`
ModLogs string `yaml:"mod_logs" default:"911907978926493716" comment:"Mod Logs Channel" validate:"required"`
Apps string `yaml:"apps" default:"1034075132030894100" comment:"Apps Channel, should be a staff only channel" validate:"required"`
VoteLogs string `yaml:"vote_logs" default:"762077981811146752" comment:"Vote Logs Channel" validate:"required"`
BanAppeals string `yaml:"ban_appeals" default:"870950610692878337" comment:"Ban Appeals Channel" validate:"required"`
AuthLogs string `yaml:"auth_logs" default:"1075091440117498007" comment:"Auth Logs Channel" validate:"required"`
BotLogs snowflake.ID `yaml:"bot_logs" default:"762077915499593738" comment:"Bot Logs Channel" validate:"required"`
ModLogs snowflake.ID `yaml:"mod_logs" default:"911907978926493716" comment:"Mod Logs Channel" validate:"required"`
Apps snowflake.ID `yaml:"apps" default:"1034075132030894100" comment:"Apps Channel, should be a staff only channel" validate:"required"`
VoteLogs snowflake.ID `yaml:"vote_logs" default:"762077981811146752" comment:"Vote Logs Channel" validate:"required"`
BanAppeals snowflake.ID `yaml:"ban_appeals" default:"870950610692878337" comment:"Ban Appeals Channel" validate:"required"`
AuthLogs snowflake.ID `yaml:"auth_logs" default:"1075091440117498007" comment:"Auth Logs Channel" validate:"required"`
}

type JAPI struct {
Expand All @@ -94,7 +96,7 @@ type Notifications struct {
}

type Servers struct {
Main string `yaml:"main" default:"758641373074423808" comment:"Main Server ID" validate:"required"`
Main snowflake.ID `yaml:"main" default:"758641373074423808" comment:"Main Server ID" validate:"required"`
}

type Meta struct {
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ require (
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/disgoorg/disgo v0.18.11 // indirect
github.com/disgoorg/json v1.2.0 // indirect
github.com/disgoorg/snowflake/v2 v2.0.3 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
golang.org/x/arch v0.9.0 // indirect
)
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80N
github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/disgoorg/disgo v0.18.11 h1:hvWpU43PtThNeKOeP6ghx3nyjpgP0oaQz2WL3yizCIA=
github.com/disgoorg/disgo v0.18.11/go.mod h1:mkNGTSWCxIgTXCIg8GqRJedAqNw4T++xOgBOTEk9d7U=
github.com/disgoorg/json v1.2.0 h1:6e/j4BCfSHIvucG1cd7tJPAOp1RgnnMFSqkvZUtEd1Y=
github.com/disgoorg/json v1.2.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
github.com/disgoorg/snowflake/v2 v2.0.3 h1:3B+PpFjr7j4ad7oeJu4RlQ+nYOTadsKapJIzgvSI2Ro=
github.com/disgoorg/snowflake/v2 v2.0.3/go.mod h1:W6r7NUA7DwfZLwr00km6G4UnZ0zcoLBRufhkFWgAc4c=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
Expand Down Expand Up @@ -230,6 +236,8 @@ github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJ
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad h1:qIQkSlF5vAUHxEmTbaqt1hkJ/t6skqEGYiMag343ucI=
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
23 changes: 12 additions & 11 deletions routes/apps/endpoints/create_app/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (
"popplio/apps"
"popplio/state"
"popplio/types"
"popplio/validators"
"strconv"
"time"

"github.com/disgoorg/disgo/discord"
docs "github.com/infinitybotlist/eureka/doclib"
"github.com/infinitybotlist/eureka/uapi"
"github.com/jackc/pgx/v5"
"go.uber.org/zap"

"github.com/bwmarrin/discordgo"
"github.com/go-playground/validator/v10"
"github.com/infinitybotlist/eureka/crypto"
)
Expand Down Expand Up @@ -101,14 +102,14 @@ func Route(d uapi.RouteData, r *http.Request) uapi.HttpResponse {
}

var appBanned bool
err = state.Pool.QueryRow(d.Context, "SELECT app_banned FROM users WHERE user_id = $1", d.Auth.ID).Scan(&appBanned)
err = state.Pool.QueryRow(d.Context, "SELECT app_banned FROM users WHERE user_id = $1", d.Auth.ID).Scan(&appBanned)

if err != nil {
state.Logger.Error("Error gettingstate.Pop banned state", zap.Error(err), zap.String("user_id", d.Auth.ID))
state.Logger.Error("Error gettingstate.Pop banned state", zap.Error(err), zap.String("user_id", d.Auth.ID))
return uapi.DefaultResponse(http.StatusInternalServerError)
}

if appBanned {
if appBanned {
return uapi.HttpResponse{
Json: types.ApiError{
Message: "You are currently banned from making applications on the site",
Expand Down Expand Up @@ -277,29 +278,29 @@ func Route(d uapi.RouteData, r *http.Request) uapi.HttpResponse {
channel = position.Channel()
}

_, err = state.Discord.ChannelMessageSendComplex(channel, &discordgo.MessageSend{
Content: "<@&" + state.Config.Roles.Apps + ">",
Embeds: []*discordgo.MessageEmbed{
_, err = state.Discord.Rest().CreateMessage(channel, discord.MessageCreate{
Content: "<@&" + state.Config.Roles.Apps.String() + ">",
Embeds: []discord.Embed{
{
Title: "New " + position.Name + " Application!",
URL: state.Config.Sites.Panel.Production() + "/panel/apps",
Description: desc,
Color: 0x00ff00,
Fields: []*discordgo.MessageEmbedField{
Fields: []discord.EmbedField{
{
Name: "App ID",
Value: appId,
Inline: true,
Inline: validators.Pointer(true),
},
{
Name: "User ID",
Value: d.Auth.ID,
Inline: true,
Inline: validators.Pointer(true),
},
{
Name: "Position",
Value: payload.Position,
Inline: true,
Inline: validators.Pointer(true),
},
},
},
Expand Down
Loading

0 comments on commit 3c7384f

Please sign in to comment.