Use gdl object
This commit is contained in:
parent
97d3dacd95
commit
5ab238cc1c
@ -9,10 +9,10 @@ import (
|
|||||||
"github.com/TicketsBot/GoPanel/utils"
|
"github.com/TicketsBot/GoPanel/utils"
|
||||||
"github.com/TicketsBot/GoPanel/utils/discord"
|
"github.com/TicketsBot/GoPanel/utils/discord"
|
||||||
userEndpoint "github.com/TicketsBot/GoPanel/utils/discord/endpoints/user"
|
userEndpoint "github.com/TicketsBot/GoPanel/utils/discord/endpoints/user"
|
||||||
"github.com/TicketsBot/GoPanel/utils/discord/objects"
|
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/gin-gonic/contrib/sessions"
|
"github.com/gin-gonic/contrib/sessions"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/rxdn/gdl/objects/guild"
|
||||||
"github.com/rxdn/gdl/objects/user"
|
"github.com/rxdn/gdl/objects/user"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -84,7 +84,7 @@ func CallbackHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
// Cache guilds because Discord takes like 2 whole seconds to return then
|
// Cache guilds because Discord takes like 2 whole seconds to return then
|
||||||
go func() {
|
go func() {
|
||||||
var guilds []objects.Guild
|
var guilds []guild.Guild
|
||||||
err, _ = userEndpoint.CurrentUserGuilds.Request(store, nil, nil, &guilds)
|
err, _ = userEndpoint.CurrentUserGuilds.Request(store, nil, nil, &guilds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
|
@ -4,11 +4,9 @@ import (
|
|||||||
"github.com/TicketsBot/GoPanel/config"
|
"github.com/TicketsBot/GoPanel/config"
|
||||||
"github.com/TicketsBot/GoPanel/database/table"
|
"github.com/TicketsBot/GoPanel/database/table"
|
||||||
"github.com/TicketsBot/GoPanel/utils"
|
"github.com/TicketsBot/GoPanel/utils"
|
||||||
"github.com/TicketsBot/GoPanel/utils/discord/objects"
|
|
||||||
"github.com/gin-gonic/contrib/sessions"
|
"github.com/gin-gonic/contrib/sessions"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/rxdn/gdl/objects/guild"
|
"github.com/rxdn/gdl/objects/guild"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func IndexHandler(ctx *gin.Context) {
|
func IndexHandler(ctx *gin.Context) {
|
||||||
@ -22,15 +20,10 @@ func IndexHandler(ctx *gin.Context) {
|
|||||||
userId := utils.GetUserId(store)
|
userId := utils.GetUserId(store)
|
||||||
|
|
||||||
userGuilds := table.GetGuilds(userId)
|
userGuilds := table.GetGuilds(userId)
|
||||||
adminGuilds := make([]objects.Guild, 0)
|
adminGuilds := make([]guild.Guild, 0)
|
||||||
for _, g := range userGuilds {
|
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{
|
fakeGuild := guild.Guild{
|
||||||
Id: guildId,
|
Id: g.Id,
|
||||||
OwnerId: g.OwnerId,
|
OwnerId: g.OwnerId,
|
||||||
Permissions: g.Permissions,
|
Permissions: g.Permissions,
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TicketsBot/GoPanel/database"
|
"github.com/TicketsBot/GoPanel/database"
|
||||||
"github.com/TicketsBot/GoPanel/utils/discord/objects"
|
"github.com/rxdn/gdl/objects/guild"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GuildCache struct {
|
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)
|
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
|
var cache GuildCache
|
||||||
database.Database.Where(&GuildCache{UserId: userId}).First(&cache)
|
database.Database.Where(&GuildCache{UserId: userId}).First(&cache)
|
||||||
decoded, err := base64.StdEncoding.DecodeString(cache.Guilds)
|
decoded, err := base64.StdEncoding.DecodeString(cache.Guilds)
|
||||||
if err != nil {
|
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 {
|
if err := json.Unmarshal(decoded, &guilds); err != nil {
|
||||||
return make([]objects.Guild, 0)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return guilds
|
return guilds
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package objects
|
|
||||||
|
|
||||||
type Guild struct {
|
|
||||||
Id string
|
|
||||||
Name string
|
|
||||||
Icon string
|
|
||||||
Owner bool
|
|
||||||
OwnerId uint64 `json:"id,string"`
|
|
||||||
Permissions int
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
@ -1,7 +1,6 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TicketsBot/GoPanel/utils/discord/objects"
|
|
||||||
"github.com/rxdn/gdl/objects/channel/message"
|
"github.com/rxdn/gdl/objects/channel/message"
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
@ -23,17 +22,6 @@ func Contains(s interface{}, elem interface{}) bool {
|
|||||||
return false
|
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 {
|
func Reverse(slice []message.Message) []message.Message {
|
||||||
for i := len(slice)/2-1; i >= 0; i-- {
|
for i := len(slice)/2-1; i >= 0; i-- {
|
||||||
opp := len(slice)-1-i
|
opp := len(slice)-1-i
|
||||||
|
Loading…
x
Reference in New Issue
Block a user