auto invite
This commit is contained in:
parent
1ceb5dc495
commit
1f843dfb8e
@ -1,6 +1,8 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/TicketsBot/GoPanel/cache"
|
||||
"github.com/TicketsBot/GoPanel/config"
|
||||
"github.com/TicketsBot/GoPanel/database/table"
|
||||
"github.com/TicketsBot/GoPanel/utils"
|
||||
@ -33,6 +35,14 @@ func SettingsHandler(ctx *gin.Context) {
|
||||
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
|
||||
var guild objects.Guild
|
||||
for _, g := range table.GetGuilds(userIdStr) {
|
||||
|
@ -25,8 +25,9 @@ func IndexHandler(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
userGuilds := table.GetGuilds(userIdStr)
|
||||
adminGuilds := make([]objects.Guild, 0)
|
||||
for _, guild := range table.GetGuilds(userIdStr) {
|
||||
for _, guild := range userGuilds {
|
||||
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.
|
||||
continue
|
||||
|
15
cache/guildobjectcache.go
vendored
15
cache/guildobjectcache.go
vendored
@ -9,7 +9,8 @@ import (
|
||||
)
|
||||
|
||||
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())
|
||||
return
|
||||
}
|
||||
@ -34,3 +35,15 @@ func (c *RedisClient) GetGuildByID(guildId string, res chan *objects.Guild) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
//
|
||||
|
||||
func RandStringRunes(length int) string {
|
||||
b := make([]rune, length)
|
||||
for i := range b {
|
||||
|
Loading…
x
Reference in New Issue
Block a user