auto invite
This commit is contained in:
parent
1ceb5dc495
commit
1f843dfb8e
@ -1,6 +1,8 @@
|
|||||||
package manage
|
package manage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/TicketsBot/GoPanel/cache"
|
||||||
"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"
|
||||||
@ -33,6 +35,14 @@ func SettingsHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check the bot is in the guild
|
||||||
|
isInGuild := make(chan bool)
|
||||||
|
go cache.Client.GuildExists(guildIdStr, isInGuild)
|
||||||
|
if !<-isInGuild {
|
||||||
|
ctx.Redirect(302, fmt.Sprintf("https://invite.ticketsbot.net/?guild_id=%s&disable_guild_select=true&response_type=code&scope=bot%%20identify&redirect_uri=%s", guildIdStr, config.Conf.Server.BaseUrl))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Get object for selected guild
|
// Get object for selected guild
|
||||||
var guild objects.Guild
|
var guild objects.Guild
|
||||||
for _, g := range table.GetGuilds(userIdStr) {
|
for _, g := range table.GetGuilds(userIdStr) {
|
||||||
|
@ -25,8 +25,9 @@ func IndexHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userGuilds := table.GetGuilds(userIdStr)
|
||||||
adminGuilds := make([]objects.Guild, 0)
|
adminGuilds := make([]objects.Guild, 0)
|
||||||
for _, guild := range table.GetGuilds(userIdStr) {
|
for _, guild := range userGuilds {
|
||||||
guildId, err := strconv.ParseInt(guild.Id, 10, 64)
|
guildId, err := strconv.ParseInt(guild.Id, 10, 64)
|
||||||
if err != nil { // I think this happens when a server was deleted? We should just skip though.
|
if err != nil { // I think this happens when a server was deleted? We should just skip though.
|
||||||
continue
|
continue
|
||||||
|
23
cache/guildobjectcache.go
vendored
23
cache/guildobjectcache.go
vendored
@ -9,13 +9,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *RedisClient) StoreGuild(guild objects.Guild) {
|
func (c *RedisClient) StoreGuild(guild objects.Guild) {
|
||||||
packed, err := msgpack.Marshal(guild); if err != nil {
|
packed, err := msgpack.Marshal(guild)
|
||||||
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
key := fmt.Sprintf("ticketspanel:guilds:%s", string(packed))
|
key := fmt.Sprintf("ticketspanel:guilds:%s", string(packed))
|
||||||
c.Set(key, string(packed), time.Hour * 48)
|
c.Set(key, string(packed), time.Hour*48)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RedisClient) GetGuildByID(guildId string, res chan *objects.Guild) {
|
func (c *RedisClient) GetGuildByID(guildId string, res chan *objects.Guild) {
|
||||||
@ -23,14 +24,26 @@ func (c *RedisClient) GetGuildByID(guildId string, res chan *objects.Guild) {
|
|||||||
packed, err := c.Get(key).Result()
|
packed, err := c.Get(key).Result()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res<-nil
|
res <- nil
|
||||||
} else {
|
} else {
|
||||||
var unpacked objects.Guild
|
var unpacked objects.Guild
|
||||||
if err = msgpack.Unmarshal([]byte(packed), &unpacked); err != nil {
|
if err = msgpack.Unmarshal([]byte(packed), &unpacked); err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
res<-nil
|
res <- nil
|
||||||
} else {
|
} else {
|
||||||
res<-&unpacked
|
res <- &unpacked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *RedisClient) GuildExists(guildId string, res chan bool) {
|
||||||
|
key := fmt.Sprintf("tickets:guilds:%s", guildId)
|
||||||
|
|
||||||
|
intResult, err := c.Exists(key).Result()
|
||||||
|
if err != nil {
|
||||||
|
res <- false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res <- intResult == 1
|
||||||
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||||
//
|
|
||||||
func RandStringRunes(length int) string {
|
func RandStringRunes(length int) string {
|
||||||
b := make([]rune, length)
|
b := make([]rune, length)
|
||||||
for i := range b {
|
for i := range b {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user