From 5ab238cc1ccd64cc636f95a8c5d367be5fb3161f Mon Sep 17 00:00:00 2001 From: Dot-Rar Date: Wed, 15 Apr 2020 16:31:12 +0100 Subject: [PATCH] Use gdl object --- app/http/endpoints/root/callback.go | 4 ++-- app/http/endpoints/root/index.go | 11 ++--------- database/table/guilds.go | 10 +++++----- utils/discord/objects/guild.go | 10 ---------- utils/discord/objects/user.go | 12 ------------ utils/sliceutils.go | 12 ------------ 6 files changed, 9 insertions(+), 50 deletions(-) delete mode 100644 utils/discord/objects/guild.go delete mode 100644 utils/discord/objects/user.go diff --git a/app/http/endpoints/root/callback.go b/app/http/endpoints/root/callback.go index d546b0d..e04e8ed 100644 --- a/app/http/endpoints/root/callback.go +++ b/app/http/endpoints/root/callback.go @@ -9,10 +9,10 @@ import ( "github.com/TicketsBot/GoPanel/utils" "github.com/TicketsBot/GoPanel/utils/discord" userEndpoint "github.com/TicketsBot/GoPanel/utils/discord/endpoints/user" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/apex/log" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" + "github.com/rxdn/gdl/objects/guild" "github.com/rxdn/gdl/objects/user" "time" ) @@ -84,7 +84,7 @@ func CallbackHandler(ctx *gin.Context) { // Cache guilds because Discord takes like 2 whole seconds to return then go func() { - var guilds []objects.Guild + var guilds []guild.Guild err, _ = userEndpoint.CurrentUserGuilds.Request(store, nil, nil, &guilds) if err != nil { log.Error(err.Error()) diff --git a/app/http/endpoints/root/index.go b/app/http/endpoints/root/index.go index ea8ce27..f91cac3 100644 --- a/app/http/endpoints/root/index.go +++ b/app/http/endpoints/root/index.go @@ -4,11 +4,9 @@ import ( "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" "github.com/TicketsBot/GoPanel/utils" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" "github.com/rxdn/gdl/objects/guild" - "strconv" ) func IndexHandler(ctx *gin.Context) { @@ -22,15 +20,10 @@ func IndexHandler(ctx *gin.Context) { userId := utils.GetUserId(store) userGuilds := table.GetGuilds(userId) - adminGuilds := make([]objects.Guild, 0) + adminGuilds := make([]guild.Guild, 0) for _, g := range userGuilds { - guildId, err := strconv.ParseUint(g.Id, 10, 64) - if err != nil { // I think this happens when a server was deleted? We should just skip though. - continue - } - fakeGuild := guild.Guild{ - Id: guildId, + Id: g.Id, OwnerId: g.OwnerId, Permissions: g.Permissions, } diff --git a/database/table/guilds.go b/database/table/guilds.go index 8156e6b..8819d99 100644 --- a/database/table/guilds.go +++ b/database/table/guilds.go @@ -4,7 +4,7 @@ import ( "encoding/base64" "encoding/json" "github.com/TicketsBot/GoPanel/database" - "github.com/TicketsBot/GoPanel/utils/discord/objects" + "github.com/rxdn/gdl/objects/guild" ) type GuildCache struct { @@ -22,17 +22,17 @@ func UpdateGuilds(userId uint64, guilds string) { database.Database.Where(&GuildCache{UserId: userId}).Assign(&GuildCache{Guilds: guilds}).FirstOrCreate(&cache) } -func GetGuilds(userId uint64) []objects.Guild { +func GetGuilds(userId uint64) []guild.Guild { var cache GuildCache database.Database.Where(&GuildCache{UserId: userId}).First(&cache) decoded, err := base64.StdEncoding.DecodeString(cache.Guilds) if err != nil { - return make([]objects.Guild, 0) + return nil } - var guilds []objects.Guild + var guilds []guild.Guild if err := json.Unmarshal(decoded, &guilds); err != nil { - return make([]objects.Guild, 0) + return nil } return guilds diff --git a/utils/discord/objects/guild.go b/utils/discord/objects/guild.go deleted file mode 100644 index ae33125..0000000 --- a/utils/discord/objects/guild.go +++ /dev/null @@ -1,10 +0,0 @@ -package objects - -type Guild struct { - Id string - Name string - Icon string - Owner bool - OwnerId uint64 `json:"id,string"` - Permissions int -} diff --git a/utils/discord/objects/user.go b/utils/discord/objects/user.go deleted file mode 100644 index 202fd15..0000000 --- a/utils/discord/objects/user.go +++ /dev/null @@ -1,12 +0,0 @@ -package objects - -type User struct { - Id string - Username string - Discriminator string - Avatar string - Verified bool - Email string - Flags int - PremiumType int -} diff --git a/utils/sliceutils.go b/utils/sliceutils.go index 8dcab91..c7e403b 100644 --- a/utils/sliceutils.go +++ b/utils/sliceutils.go @@ -1,7 +1,6 @@ package utils import ( - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/rxdn/gdl/objects/channel/message" "reflect" ) @@ -23,17 +22,6 @@ func Contains(s interface{}, elem interface{}) bool { return false } -func Insert(slice []objects.Guild, index int, value objects.Guild) []objects.Guild { - // Grow the slice by one element. - slice = slice[0 : len(slice)+1] - // Use copy to move the upper part of the slice out of the way and open a hole. - copy(slice[index+1:], slice[index:]) - // Store the new value. - slice[index] = value - // Return the result. - return slice -} - func Reverse(slice []message.Message) []message.Message { for i := len(slice)/2-1; i >= 0; i-- { opp := len(slice)-1-i