diff --git a/app/http/endpoints/manage/blacklist.go b/app/http/endpoints/manage/blacklist.go index c6c36de..1516863 100644 --- a/app/http/endpoints/manage/blacklist.go +++ b/app/http/endpoints/manage/blacklist.go @@ -3,8 +3,8 @@ package manage import ( "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/rpc/cache" "github.com/TicketsBot/GoPanel/utils" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" "strconv" @@ -18,7 +18,6 @@ func BlacklistHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -34,13 +33,7 @@ func BlacklistHandler(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) @@ -79,7 +72,7 @@ func BlacklistHandler(ctx *gin.Context) { exists := targetId != 0 if exists { - if guild.OwnerId == strconv.Itoa(int(targetId)) || table.IsStaff(guildId, targetId) { // Prevent users from blacklisting staff + if guild.OwnerId == targetId || table.IsStaff(guildId, targetId) { // Prevent users from blacklisting staff isStaff = true } else { if !utils.Contains(blacklistedIds, targetId) { // Prevent duplicates diff --git a/app/http/endpoints/manage/blacklistremove.go b/app/http/endpoints/manage/blacklistremove.go index 12aa4df..90cd2e6 100644 --- a/app/http/endpoints/manage/blacklistremove.go +++ b/app/http/endpoints/manage/blacklistremove.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/rpc/cache" "github.com/TicketsBot/GoPanel/utils" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" "strconv" @@ -19,7 +19,6 @@ func BlacklistRemoveHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -35,13 +34,7 @@ func BlacklistRemoveHandler(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) diff --git a/app/http/endpoints/manage/logs.go b/app/http/endpoints/manage/logs.go index 89b4588..2ca9ebc 100644 --- a/app/http/endpoints/manage/logs.go +++ b/app/http/endpoints/manage/logs.go @@ -3,8 +3,8 @@ package manage import ( "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/rpc/cache" "github.com/TicketsBot/GoPanel/utils" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" "strconv" @@ -18,7 +18,6 @@ func LogsHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -43,13 +42,7 @@ func LogsHandler(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) diff --git a/app/http/endpoints/manage/panelcreate.go b/app/http/endpoints/manage/panelcreate.go index e686921..48411ba 100644 --- a/app/http/endpoints/manage/panelcreate.go +++ b/app/http/endpoints/manage/panelcreate.go @@ -2,13 +2,14 @@ package manage import ( "fmt" - "github.com/TicketsBot/GoPanel/cache" "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/messagequeue" + "github.com/TicketsBot/GoPanel/rpc/cache" "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/channel" "strconv" "strings" ) @@ -21,7 +22,6 @@ func PanelCreateHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -37,13 +37,7 @@ func PanelCreateHandler(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) @@ -150,7 +144,7 @@ func PanelCreateHandler(ctx *gin.Context) { ReactionEmote: emoji, } - go cache.Client.PublishPanelCreate(settings) + go messagequeue.Client.PublishPanelCreate(settings) ctx.Redirect(302, fmt.Sprintf("/manage/%d/panels?created=true&validColour=%t", guildId, validColour)) } else { @@ -159,15 +153,10 @@ func PanelCreateHandler(ctx *gin.Context) { } func validateChannel(guildId, channelId uint64, res chan bool) { - // Get channels from DB - channelsChan := make(chan []table.Channel) - go table.GetCachedChannelsByGuild(guildId, channelsChan) - channels := <-channelsChan - // Compare channel IDs validChannel := false - for _, guildChannel := range channels { - if guildChannel.ChannelId == channelId { + for _, guildChannel := range cache.Instance.GetGuildChannels(guildId) { + if guildChannel.Id == channelId { validChannel = true break } @@ -177,15 +166,10 @@ func validateChannel(guildId, channelId uint64, res chan bool) { } func validateCategory(guildId, categoryId uint64, res chan bool) { - // Get channels from DB - categoriesChan := make(chan []table.Channel) - go table.GetCategories(guildId, categoriesChan) - categories := <-categoriesChan - - // Compare channel IDs + // Compare ch IDs validCategory := false - for _, category := range categories { - if category.ChannelId == categoryId { + for _, ch := range cache.Instance.GetGuildChannels(guildId) { + if ch.Type == channel.ChannelTypeGuildCategory && ch.Id == categoryId { validCategory = true break } diff --git a/app/http/endpoints/manage/paneldelete.go b/app/http/endpoints/manage/paneldelete.go index 3bbc0c9..403d752 100644 --- a/app/http/endpoints/manage/paneldelete.go +++ b/app/http/endpoints/manage/paneldelete.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/rpc/cache" "github.com/TicketsBot/GoPanel/utils" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" "strconv" @@ -19,7 +19,6 @@ func PanelDeleteHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -41,13 +40,7 @@ func PanelDeleteHandler(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) diff --git a/app/http/endpoints/manage/panels.go b/app/http/endpoints/manage/panels.go index 44b4ec0..e3d5f69 100644 --- a/app/http/endpoints/manage/panels.go +++ b/app/http/endpoints/manage/panels.go @@ -3,8 +3,8 @@ package manage import ( "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/rpc/cache" "github.com/TicketsBot/GoPanel/utils" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" "strconv" @@ -26,7 +26,6 @@ func PanelHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -42,13 +41,7 @@ func PanelHandler(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) @@ -64,12 +57,7 @@ func PanelHandler(ctx *gin.Context) { panels := <-panelChan // Get channels - channelsChan := make(chan []table.Channel) - go table.GetCachedChannelsByGuild(guildId, channelsChan) - channels := <-channelsChan - - // Get default panel settings - settings := table.GetPanelSettings(guildId) + channels := cache.Instance.GetGuildChannels(guildId) // Convert to wrapped panels wrappedPanels := make([]wrappedPanel, 0) @@ -81,18 +69,11 @@ func PanelHandler(ctx *gin.Context) { CategoryName: "", } - if panel.Title == "" { - wrapper.Title = settings.Title - } - if panel.Content == "" { - wrapper.Content = settings.Content - } - // Get channel name & category name for _, guildChannel := range channels { - if guildChannel.ChannelId == panel.ChannelId { + if guildChannel.Id == panel.ChannelId { wrapper.ChannelName = guildChannel.Name - } else if guildChannel.ChannelId == panel.TargetCategory { + } else if guildChannel.Id == panel.TargetCategory { wrapper.CategoryName = guildChannel.Name } } @@ -100,22 +81,6 @@ func PanelHandler(ctx *gin.Context) { wrappedPanels = append(wrappedPanels, wrapper) } - // Format channels to be text channels only - channelMap := make(map[uint64]string) - for _, channel := range channels { - if channel.Type == 0 { - channelMap[channel.ChannelId] = channel.Name - } - } - - // Get categories & format - categories := make(map[uint64]string) - for _, channel := range channels { - if channel.Type == 4 { - categories[channel.ChannelId] = channel.Name - } - } - // Get is premium isPremiumChan := make(chan bool) go utils.IsPremiumGuild(store, guildId, isPremiumChan) @@ -130,8 +95,7 @@ func PanelHandler(ctx *gin.Context) { "panelcount": len(panels), "premium": isPremium, "panels": wrappedPanels, - "channels": channelMap, - "categories": categories, + "channels": channels, "validTitle": ctx.Query("validTitle") != "true", "validContent": ctx.Query("validContent") != "false", diff --git a/app/http/endpoints/manage/sendmessage.go b/app/http/endpoints/manage/sendmessage.go index 1bd774d..ad24c41 100644 --- a/app/http/endpoints/manage/sendmessage.go +++ b/app/http/endpoints/manage/sendmessage.go @@ -4,12 +4,12 @@ import ( "fmt" "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/rpc/cache" + "github.com/TicketsBot/GoPanel/rpc/ratelimit" "github.com/TicketsBot/GoPanel/utils" - "github.com/TicketsBot/GoPanel/utils/discord" - "github.com/TicketsBot/GoPanel/utils/discord/endpoints/channel" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" + "github.com/rxdn/gdl/rest" "strconv" ) @@ -21,7 +21,6 @@ func SendMessage(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -37,13 +36,7 @@ func SendMessage(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) @@ -65,18 +58,13 @@ func SendMessage(ctx *gin.Context) { return } - contentType := discord.ApplicationJson - if exists { content := fmt.Sprintf("**%s**: %s", store.Get("name").(string), ctx.PostForm("message")) if len(content) > 2000 { content = content[0:1999] } - endpoint := channel.CreateMessage(int(ticket.Channel)) - err, _ = endpoint.Request(store, &contentType, channel.CreateMessageBody{ - Content: content, - }, nil) + _, _ = rest.CreateMessage(config.Conf.Bot.Token, ratelimit.Ratelimiter, ticket.Channel, rest.CreateMessageData{Content: content}) } } else { ctx.Redirect(302, "/login") diff --git a/app/http/endpoints/manage/settings.go b/app/http/endpoints/manage/settings.go index fe83f34..25a0766 100644 --- a/app/http/endpoints/manage/settings.go +++ b/app/http/endpoints/manage/settings.go @@ -2,13 +2,13 @@ package manage import ( "fmt" - "github.com/TicketsBot/GoPanel/cache" "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/rpc/cache" "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/channel" "strconv" ) @@ -20,7 +20,6 @@ func SettingsHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -36,21 +35,14 @@ func SettingsHandler(ctx *gin.Context) { } // Check the bot is in the guild - isInGuild := make(chan bool) - go cache.Client.GuildExists(guildIdStr, isInGuild) - if !<-isInGuild { + _, isInGuild := cache.Instance.GetGuild(guildId, false) + 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) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) @@ -72,21 +64,15 @@ func SettingsHandler(ctx *gin.Context) { go table.GetTicketNamingScheme(guildId, namingSchemeChan) namingScheme := <-namingSchemeChan - // /users/@me/guilds doesn't return channels, so we have to get them for the specific guild - channelsChan := make(chan []table.Channel) - go table.GetCachedChannelsByGuild(guildId, channelsChan) - channels := <-channelsChan + // get guild channels from cache + channels := cache.Instance.GetGuildChannels(guildId) - // Get a list of actual category IDs - categoriesChan := make(chan []table.Channel) - go table.GetCategories(guildId, categoriesChan) - categories := <-categoriesChan - - // Archive channel - // Create a list of IDs - var channelIds []string - for _, c := range channels { - channelIds = append(channelIds, strconv.Itoa(int(c.ChannelId))) + // separate out categories + categories := make([]channel.Channel, 0) + for _, ch := range channels { + if ch.Type == channel.ChannelTypeGuildCategory { + categories = append(categories, ch) + } } panelSettings := table.GetPanelSettings(guildId) @@ -101,26 +87,26 @@ func SettingsHandler(ctx *gin.Context) { invalidTicketLimit := ctx.Query("validTicketLimit") == "false" ctx.HTML(200, "manage/settings", gin.H{ - "name": store.Get("name").(string), - "guildId": guildIdStr, - "avatar": store.Get("avatar").(string), - "prefix": prefix, - "welcomeMessage": welcomeMessage, - "ticketLimit": limit, - "categories": categories, - "activecategory": categoryId, - "channels": channels, - "archivechannel": archiveChannel, - "invalidPrefix": invalidPrefix, + "name": store.Get("name").(string), + "guildId": guildIdStr, + "avatar": store.Get("avatar").(string), + "prefix": prefix, + "welcomeMessage": welcomeMessage, + "ticketLimit": limit, + "categories": categories, + "activecategory": categoryId, + "channels": channels, + "archivechannel": archiveChannel, + "invalidPrefix": invalidPrefix, "invalidWelcomeMessage": invalidWelcomeMessage, - "invalidTicketLimit": invalidTicketLimit, - "csrf": store.Get("csrf").(string), - "pingEveryone": pingEveryone, - "paneltitle": panelSettings.Title, - "panelcontent": panelSettings.Content, - "panelcolour": strconv.FormatInt(int64(panelSettings.Colour), 16), - "usersCanClose": usersCanClose, - "namingScheme": string(namingScheme), + "invalidTicketLimit": invalidTicketLimit, + "csrf": store.Get("csrf").(string), + "pingEveryone": pingEveryone, + "paneltitle": panelSettings.Title, + "panelcontent": panelSettings.Content, + "panelcolour": strconv.FormatInt(int64(panelSettings.Colour), 16), + "usersCanClose": usersCanClose, + "namingScheme": string(namingScheme), }) } else { ctx.Redirect(302, "/login") diff --git a/app/http/endpoints/manage/ticketclose.go b/app/http/endpoints/manage/ticketclose.go index 60df6f6..3aede35 100644 --- a/app/http/endpoints/manage/ticketclose.go +++ b/app/http/endpoints/manage/ticketclose.go @@ -2,11 +2,11 @@ package manage import ( "fmt" - "github.com/TicketsBot/GoPanel/cache" "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/messagequeue" + "github.com/TicketsBot/GoPanel/rpc/cache" "github.com/TicketsBot/GoPanel/utils" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" "strconv" @@ -20,7 +20,6 @@ func TicketCloseHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -36,13 +35,7 @@ func TicketCloseHandler(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) @@ -78,7 +71,7 @@ func TicketCloseHandler(ctx *gin.Context) { reason = reason[:255] } - go cache.Client.PublishTicketClose(ticket.Uuid, userId, reason) + go messagequeue.Client.PublishTicketClose(ticket.Uuid, userId, reason) ctx.Redirect(302, fmt.Sprintf("/manage/%d/tickets", guildId)) } else { diff --git a/app/http/endpoints/manage/ticketlist.go b/app/http/endpoints/manage/ticketlist.go index 86d831a..06b033b 100644 --- a/app/http/endpoints/manage/ticketlist.go +++ b/app/http/endpoints/manage/ticketlist.go @@ -3,8 +3,8 @@ package manage import ( "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/rpc/cache" "github.com/TicketsBot/GoPanel/utils" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" "strconv" @@ -19,7 +19,6 @@ func TicketListHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -35,13 +34,7 @@ func TicketListHandler(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) diff --git a/app/http/endpoints/manage/ticketview.go b/app/http/endpoints/manage/ticketview.go index adf7f95..efa7f23 100644 --- a/app/http/endpoints/manage/ticketview.go +++ b/app/http/endpoints/manage/ticketview.go @@ -4,11 +4,12 @@ import ( "fmt" "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/rpc/cache" + "github.com/TicketsBot/GoPanel/rpc/ratelimit" "github.com/TicketsBot/GoPanel/utils" - "github.com/TicketsBot/GoPanel/utils/discord/endpoints/channel" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" + "github.com/rxdn/gdl/rest" "regexp" "strconv" "strings" @@ -24,7 +25,6 @@ func TicketViewHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -40,13 +40,7 @@ func TicketViewHandler(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) @@ -76,16 +70,7 @@ func TicketViewHandler(ctx *gin.Context) { } // Get messages - var messages []objects.Message - // We want to show users error messages so they can report them - isError := false - var errorMessage string - - endpoint := channel.GetChannelMessages(int(ticket.Channel)) - if err, _ = endpoint.Request(store, nil, nil, &messages); err != nil { - isError = true - errorMessage = err.Error() - } + messages, err := rest.GetChannelMessages(config.Conf.Bot.Token, ratelimit.Ratelimiter, ticket.Channel, rest.GetChannelMessagesData{Limit: 100}) // Format messages, exclude unneeded data var messagesFormatted []map[string]interface{} @@ -96,7 +81,8 @@ func TicketViewHandler(ctx *gin.Context) { match := MentionRegex.FindAllStringSubmatch(content, -1) for _, mention := range match { if len(mention) >= 2 { - mentionedId, err := strconv.ParseUint(mention[1], 10, 64); if err != nil { + mentionedId, err := strconv.ParseUint(mention[1], 10, 64) + if err != nil { continue } @@ -108,7 +94,7 @@ func TicketViewHandler(ctx *gin.Context) { messagesFormatted = append(messagesFormatted, map[string]interface{}{ "username": message.Author.Username, - "content": content, + "content": content, }) } @@ -116,18 +102,18 @@ func TicketViewHandler(ctx *gin.Context) { go utils.IsPremiumGuild(store, guildId, premium) ctx.HTML(200, "manage/ticketview", gin.H{ - "name": store.Get("name").(string), - "guildId": guildIdStr, - "csrf": store.Get("csrf").(string), - "avatar": store.Get("avatar").(string), - "baseUrl": config.Conf.Server.BaseUrl, - "isError": isError, - "error": errorMessage, - "messages": messagesFormatted, - "ticketId": ticket.TicketId, - "uuid": ticket.Uuid, + "name": store.Get("name").(string), + "guildId": guildIdStr, + "csrf": store.Get("csrf").(string), + "avatar": store.Get("avatar").(string), + "baseUrl": config.Conf.Server.BaseUrl, + "isError": err != nil, + "error": err.Error(), + "messages": messagesFormatted, + "ticketId": ticket.TicketId, + "uuid": ticket.Uuid, "include_mock": true, - "premium": <-premium, + "premium": <-premium, }) } else { ctx.Redirect(302, "/login") diff --git a/app/http/endpoints/manage/updatesettings.go b/app/http/endpoints/manage/updatesettings.go index 6c8883d..88c39ce 100644 --- a/app/http/endpoints/manage/updatesettings.go +++ b/app/http/endpoints/manage/updatesettings.go @@ -4,10 +4,11 @@ import ( "fmt" "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/rpc/cache" "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/channel" "strconv" ) @@ -19,7 +20,6 @@ func UpdateSettingsHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -35,13 +35,7 @@ func UpdateSettingsHandler(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) @@ -95,39 +89,30 @@ func UpdateSettingsHandler(ctx *gin.Context) { table.UpdatePingEveryone(guildId, pingEveryone) // Get a list of actual category IDs - categories := make(chan []table.Channel) - go table.GetCategories(guildId, categories) - - // Convert to category IDs - var categoryIds []string - for _, category := range <-categories { - categoryIds = append(categoryIds, strconv.Itoa(int(category.ChannelId))) - } + channels := cache.Instance.GetGuildChannels(guildId) // Update category - categoryStr := ctx.PostForm("category") - if utils.Contains(categoryIds, categoryStr) { - // Error is impossible, as we check it's a valid channel already - category, _ := strconv.ParseUint(categoryStr, 10, 64) - table.UpdateChannelCategory(guildId, category) + if categoryId, err := strconv.ParseUint(ctx.PostForm("category"), 10, 64); err == nil { + for _, ch := range channels { + if ch.Id == categoryId { // compare ID + if ch.Type == channel.ChannelTypeGuildCategory { // verify we're dealing with a category + table.UpdateChannelCategory(guildId, categoryId) + } + break + } + } } // Archive channel - // Create a list of IDs - channelsChan := make(chan []table.Channel) - go table.GetCachedChannelsByGuild(guildId, channelsChan) - channels := <-channelsChan - - var channelIds []uint64 - for _, channel := range channels { - channelIds = append(channelIds, channel.ChannelId) - } - - // Update or archive channel - archiveChannelStr := ctx.PostForm("archivechannel") - archiveChannelId, err := strconv.ParseUint(archiveChannelStr, 10, 64) - if err == nil && utils.Contains(channelIds, archiveChannelId) { - table.UpdateArchiveChannel(guildId, archiveChannelId) + if archiveChannelId, err := strconv.ParseUint(ctx.PostForm("archivechannel"), 10, 64); err == nil { + for _, ch := range channels { + if ch.Id == archiveChannelId { // compare ID + if ch.Type == channel.ChannelTypeGuildText { // verify channel type + table.UpdateArchiveChannel(guildId, archiveChannelId) + } + break + } + } } // Users can close diff --git a/app/http/endpoints/manage/viewlog.go b/app/http/endpoints/manage/viewlog.go index 6187060..ecdb8be 100644 --- a/app/http/endpoints/manage/viewlog.go +++ b/app/http/endpoints/manage/viewlog.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/rpc/cache" "github.com/TicketsBot/GoPanel/utils" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" "io/ioutil" @@ -22,7 +22,6 @@ func LogViewHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) @@ -38,13 +37,7 @@ func LogViewHandler(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildIdStr { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildId, false) // Verify the user has permissions to be here isAdmin := make(chan bool) diff --git a/app/http/endpoints/manage/webchatws.go b/app/http/endpoints/manage/webchatws.go index 0a4f1ed..b66bd73 100644 --- a/app/http/endpoints/manage/webchatws.go +++ b/app/http/endpoints/manage/webchatws.go @@ -4,14 +4,15 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" + "github.com/TicketsBot/GoPanel/rpc/cache" + "github.com/TicketsBot/GoPanel/rpc/ratelimit" "github.com/TicketsBot/GoPanel/utils" - "github.com/TicketsBot/GoPanel/utils/discord" - "github.com/TicketsBot/GoPanel/utils/discord/endpoints/channel" - "github.com/TicketsBot/GoPanel/utils/discord/objects" "github.com/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" "github.com/gorilla/websocket" + "github.com/rxdn/gdl/rest" "net/http" "strconv" "sync" @@ -84,8 +85,6 @@ func WebChatWs(ctx *gin.Context) { SocketsLock.Lock() Sockets = append(Sockets, socket) SocketsLock.Unlock() - - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { conn.Close() @@ -127,13 +126,7 @@ func WebChatWs(ctx *gin.Context) { } // Get object for selected guild - var guild objects.Guild - for _, g := range table.GetGuilds(userIdStr) { - if g.Id == guildId { - guild = g - break - } - } + guild, _ := cache.Instance.GetGuild(guildIdParsed, false) // Verify the user has permissions to be here isAdmin := make(chan bool) @@ -164,8 +157,6 @@ func WebChatWs(ctx *gin.Context) { ticket := <-ticketChan exists := ticket != table.Ticket{} - contentType := discord.ApplicationJson - if exists { content := data if len(content) > 2000 { @@ -188,10 +179,7 @@ func WebChatWs(ctx *gin.Context) { content = content[0:1999] } - endpoint := channel.CreateMessage(int(ticket.Channel)) - err, _ = endpoint.Request(store, &contentType, channel.CreateMessageBody{ - Content: content, - }, nil) + _, _ = rest.CreateMessage(config.Conf.Bot.Token, ratelimit.Ratelimiter, ticket.Channel, rest.CreateMessageData{Content: content}) } } } diff --git a/app/http/endpoints/root/callback.go b/app/http/endpoints/root/callback.go index 5bb3598..d546b0d 100644 --- a/app/http/endpoints/root/callback.go +++ b/app/http/endpoints/root/callback.go @@ -4,17 +4,16 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/TicketsBot/GoPanel/cache" "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database/table" "github.com/TicketsBot/GoPanel/utils" "github.com/TicketsBot/GoPanel/utils/discord" - "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/gin-gonic/contrib/sessions" "github.com/gin-gonic/gin" - "strconv" + "github.com/rxdn/gdl/objects/user" "time" ) @@ -65,8 +64,8 @@ func CallbackHandler(ctx *gin.Context) { store.Set("expiry", (time.Now().UnixNano()/int64(time.Second))+int64(res.ExpiresIn)) // Get ID + name - var currentUser objects.User - err, _ = user.CurrentUser.Request(store, nil, nil, ¤tUser) + var currentUser user.User + err, _ = userEndpoint.CurrentUser.Request(store, nil, nil, ¤tUser) if err != nil { ctx.String(500, err.Error()) return @@ -83,28 +82,14 @@ func CallbackHandler(ctx *gin.Context) { ctx.Redirect(302, config.Conf.Server.BaseUrl) - userId, err := strconv.ParseUint(currentUser.Id, 10, 64); if err != nil { // ??? - return - } - // Cache guilds because Discord takes like 2 whole seconds to return then go func() { var guilds []objects.Guild - err, _ = user.CurrentUserGuilds.Request(store, nil, nil, &guilds) + err, _ = userEndpoint.CurrentUserGuilds.Request(store, nil, nil, &guilds) if err != nil { log.Error(err.Error()) return } - - for _, guild := range guilds { - go cache.Client.StoreGuild(guild) - - // cache roles - guildId, err := strconv.ParseUint(guild.Id, 10, 64); if err != nil { - continue - } - go cacheRoles(store, guildId, userId) - } marshalled, err := json.Marshal(guilds) if err != nil { @@ -112,21 +97,7 @@ func CallbackHandler(ctx *gin.Context) { return } + // TODO: unfuck this table.UpdateGuilds(currentUser.Id, base64.StdEncoding.EncodeToString(marshalled)) }() -} - -func cacheRoles(store sessions.Session, guildId, userId uint64) { - roles := utils.GetRolesRest(store, guildId, userId) - - if roles == nil { - return - } - - // Delete old roles - table.DeleteRoles(guildId, userId) - - for _, role := range *roles { - table.CacheRole(guildId, userId, role) - } -} +} \ No newline at end of file diff --git a/app/http/endpoints/root/index.go b/app/http/endpoints/root/index.go index 0817cdd..1153e45 100644 --- a/app/http/endpoints/root/index.go +++ b/app/http/endpoints/root/index.go @@ -7,6 +7,7 @@ import ( "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" ) @@ -18,25 +19,29 @@ func IndexHandler(ctx *gin.Context) { defer store.Save() if utils.IsLoggedIn(store) { - userIdStr := store.Get("userid").(string) userId, err := utils.GetUserId(store) if err != nil { ctx.String(500, err.Error()) return } - userGuilds := table.GetGuilds(userIdStr) + userGuilds := table.GetGuilds(userId) adminGuilds := make([]objects.Guild, 0) - for _, guild := range userGuilds { - guildId, err := strconv.ParseUint(guild.Id, 10, 64) + 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{ + Owner: g.Owner, + Permissions: g.Permissions, + } + isAdmin := make(chan bool) - go utils.IsAdmin(guild, guildId, userId, isAdmin) + go utils.IsAdmin(fakeGuild, guildId, userId, isAdmin) if <-isAdmin { - adminGuilds = append(adminGuilds, guild) + adminGuilds = append(adminGuilds, g) } } @@ -46,7 +51,7 @@ func IndexHandler(ctx *gin.Context) { "servers": adminGuilds, "empty": len(adminGuilds) == 0, "isIndex": true, - "avatar": store.Get("avatar").(string), + "avatar": store.Get("avatar").(string), }) } else { ctx.Redirect(302, "/login") diff --git a/cache/guildobjectcache.go b/cache/guildobjectcache.go deleted file mode 100644 index 680c127..0000000 --- a/cache/guildobjectcache.go +++ /dev/null @@ -1,49 +0,0 @@ -package cache - -import ( - "fmt" - "github.com/TicketsBot/GoPanel/utils/discord/objects" - "github.com/apex/log" - "github.com/vmihailenco/msgpack" - "time" -) - -func (c *RedisClient) StoreGuild(guild objects.Guild) { - packed, err := msgpack.Marshal(guild) - if err != nil { - log.Error(err.Error()) - return - } - - key := fmt.Sprintf("ticketspanel:guilds:%s", string(packed)) - c.Set(key, string(packed), time.Hour*48) -} - -func (c *RedisClient) GetGuildByID(guildId string, res chan *objects.Guild) { - key := fmt.Sprintf("ticketspanel:guilds:%s", guildId) - packed, err := c.Get(key).Result() - - if err != nil { - res <- nil - } else { - var unpacked objects.Guild - if err = msgpack.Unmarshal([]byte(packed), &unpacked); err != nil { - log.Error(err.Error()) - res <- nil - } else { - 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 -} diff --git a/cache/uriparser.go b/cache/uriparser.go deleted file mode 100644 index 679d08b..0000000 --- a/cache/uriparser.go +++ /dev/null @@ -1,21 +0,0 @@ -package cache - -import "net/url" - -type RedisURI struct { - Addr string - Password string -} - -func ParseURI(raw string) RedisURI { - parsed, err := url.Parse(raw); if err != nil { - panic(err) - } - - passwd, _ := parsed.User.Password() - - return RedisURI{ - Addr: parsed.Host, - Password: passwd, - } -} diff --git a/cmd/panel/main.go b/cmd/panel/main.go index 7f99e21..08155c0 100644 --- a/cmd/panel/main.go +++ b/cmd/panel/main.go @@ -6,9 +6,10 @@ import ( "fmt" "github.com/TicketsBot/GoPanel/app/http" "github.com/TicketsBot/GoPanel/app/http/endpoints/manage" - "github.com/TicketsBot/GoPanel/cache" "github.com/TicketsBot/GoPanel/config" "github.com/TicketsBot/GoPanel/database" + "github.com/TicketsBot/GoPanel/messagequeue" + "github.com/TicketsBot/GoPanel/rpc/cache" "github.com/TicketsBot/GoPanel/utils" "github.com/apex/log" "math/rand" @@ -27,17 +28,18 @@ func main() { config.LoadConfig() database.ConnectToDatabase() + cache.Instance = cache.NewCache() utils.LoadEmoji() - cache.Client = cache.NewRedisClient() - go Listen(cache.Client) + messagequeue.Client = messagequeue.NewRedisClient() + go Listen(messagequeue.Client) http.StartServer() } -func Listen(client cache.RedisClient) { - ch := make(chan cache.TicketMessage) +func Listen(client messagequeue.RedisClient) { + ch := make(chan messagequeue.TicketMessage) go client.ListenForMessages(ch) for decoded := range ch { diff --git a/config.toml.example b/config.toml.example index 997e378..1e273bc 100644 --- a/config.toml.example +++ b/config.toml.example @@ -33,3 +33,6 @@ host="127.0.0.1" port=6379 password="" threads=5 + +[cache] +uri="postgres://pwd:user@localhost:5432/db" diff --git a/config/config.go b/config/config.go index 3aecec0..8972071 100644 --- a/config/config.go +++ b/config/config.go @@ -1,78 +1,83 @@ -package config - -import ( - "github.com/BurntSushi/toml" - "io/ioutil" -) - -type ( - Config struct { - Admins []string - Server Server - Oauth Oauth - MariaDB MariaDB - Bot Bot - Redis Redis - } - - Server struct { - Host string - BaseUrl string - MainSite string - Ratelimit Ratelimit - Session Session - } - - Ratelimit struct { - Window int - Max int - } - - Session struct { - Threads int - Secret string - } - - Oauth struct { - Id int64 - Secret string - RedirectUri string - } - - MariaDB struct { - Host string - Username string - Password string - Database string - Threads int - } - - Bot struct { - Token string - PremiumLookupProxyUrl string `toml:"premium-lookup-proxy-url"` - PremiumLookupProxyKey string `toml:"premium-lookup-proxy-key"` - } - - Redis struct { - Host string - Port int - Password string - Threads int - } -) - -var ( - Conf Config -) - -func LoadConfig() { - raw, err := ioutil.ReadFile("config.toml") - if err != nil { - panic(err) - } - - _, err = toml.Decode(string(raw), &Conf) - if err != nil { - panic(err) - } -} +package config + +import ( + "github.com/BurntSushi/toml" + "io/ioutil" +) + +type ( + Config struct { + Admins []string + Server Server + Oauth Oauth + MariaDB MariaDB + Bot Bot + Redis Redis + Cache Cache + } + + Server struct { + Host string + BaseUrl string + MainSite string + Ratelimit Ratelimit + Session Session + } + + Ratelimit struct { + Window int + Max int + } + + Session struct { + Threads int + Secret string + } + + Oauth struct { + Id int64 + Secret string + RedirectUri string + } + + MariaDB struct { + Host string + Username string + Password string + Database string + Threads int + } + + Bot struct { + Token string + PremiumLookupProxyUrl string `toml:"premium-lookup-proxy-url"` + PremiumLookupProxyKey string `toml:"premium-lookup-proxy-key"` + } + + Redis struct { + Host string + Port int + Password string + Threads int + } + + Cache struct { + Uri string + } +) + +var ( + Conf Config +) + +func LoadConfig() { + raw, err := ioutil.ReadFile("config.toml") + if err != nil { + panic(err) + } + + _, err = toml.Decode(string(raw), &Conf) + if err != nil { + panic(err) + } +} diff --git a/database/table/channels.go b/database/table/channels.go deleted file mode 100644 index b4db35d..0000000 --- a/database/table/channels.go +++ /dev/null @@ -1,56 +0,0 @@ -package table - -import ( - "github.com/TicketsBot/GoPanel/database" -) - -type Channel struct { - ChannelId uint64 `gorm:"column:CHANNELID"` - GuildId uint64 `gorm:"column:GUILDID"` - Name string `gorm:"column:NAME;type:VARCHAR(32)"` - Type int `gorm:"column:CHANNELTYPE;type:TINYINT(1)"` -} - -func (Channel) TableName() string { - return "Channel" -} - -func StoreChannel(channelId, guildId uint64, name string, channelType int) { - channel := Channel{ - ChannelId: channelId, - GuildId: guildId, - Name: name, - Type: channelType, - } - - database.Database.Where(&Channel{ChannelId: channelId}).Assign(&channel).FirstOrCreate(&Channel{}) -} - -func DeleteChannel(channelId uint64) { - var node Channel - database.Database.Where(Channel{ChannelId: channelId}).Take(&node) - database.Database.Delete(&node) -} - -func GetCachedChannelsByGuild(guildId uint64, res chan []Channel) { - var nodes []Channel - database.Database.Where(Channel{GuildId: guildId}).Find(&nodes) - res <- nodes -} - -// Util function ig -func GetCategories(guildId uint64, res chan []Channel) { - channelsChan := make(chan []Channel) - go GetCachedChannelsByGuild(guildId, channelsChan) - channels := <-channelsChan - - var categories []Channel - - for _, channel := range channels { - if channel.Type == 4 { - categories = append(categories, channel) - } - } - - res <- categories -} diff --git a/database/table/guilds.go b/database/table/guilds.go index eb7409b..8156e6b 100644 --- a/database/table/guilds.go +++ b/database/table/guilds.go @@ -1,38 +1,39 @@ -package table - -import ( - "encoding/base64" - "encoding/json" - "github.com/TicketsBot/GoPanel/database" - "github.com/TicketsBot/GoPanel/utils/discord/objects" -) - -type GuildCache struct { - UserId string `gorm:"column:USERID;type:varchar(20)"` // Apparently I made this a VARCHAR in the JS version - Guilds string `gorm:"column:guilds;type:mediumtext"` -} - -func (GuildCache) TableName() string { - return "guildscache" -} - -func UpdateGuilds(userId string, guilds string) { - var cache GuildCache - database.Database.Where(&GuildCache{UserId: userId}).Assign(&GuildCache{Guilds: guilds}).FirstOrCreate(&cache) -} - -func GetGuilds(userId string) []objects.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) - } - - var guilds []objects.Guild - if err := json.Unmarshal(decoded, &guilds); err != nil { - return make([]objects.Guild, 0) - } - - return guilds -} +package table + +import ( + "encoding/base64" + "encoding/json" + "github.com/TicketsBot/GoPanel/database" + "github.com/TicketsBot/GoPanel/utils/discord/objects" +) + +type GuildCache struct { + UserId uint64 `gorm:"column:USERID"` + Guilds string `gorm:"column:guilds;type:mediumtext"` +} + +func (GuildCache) TableName() string { + return "guildscache" +} + +// this is horrible +func UpdateGuilds(userId uint64, guilds string) { + var cache GuildCache + database.Database.Where(&GuildCache{UserId: userId}).Assign(&GuildCache{Guilds: guilds}).FirstOrCreate(&cache) +} + +func GetGuilds(userId uint64) []objects.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) + } + + var guilds []objects.Guild + if err := json.Unmarshal(decoded, &guilds); err != nil { + return make([]objects.Guild, 0) + } + + return guilds +} diff --git a/database/table/rolescache.go b/database/table/rolescache.go deleted file mode 100644 index abad226..0000000 --- a/database/table/rolescache.go +++ /dev/null @@ -1,47 +0,0 @@ -package table - -import ( - "github.com/TicketsBot/GoPanel/database" -) - -type CachedRole struct { - AssociationId int `gorm:"column:ASSOCIATIONID;primary_key;auto_increment"` - GuildId uint64 `gorm:"column:GUILDID"` - UserId uint64 `gorm:"column:USERID"` - RoleId uint64 `gorm:"column:ROLEID"` -} - -func (CachedRole) TableName() string { - return "cache_roles" -} - -func DeleteRoles(guildId, userId uint64) { - database.Database.Where(CachedRole{ - GuildId: guildId, - UserId: userId, - }).Delete(CachedRole{}) -} - -// TODO: Cache invalidation -func CacheRole(guildId, userId, roleId uint64) { - database.Database.Create(&CachedRole{ - GuildId: guildId, - UserId: userId, - RoleId: roleId, - }) -} - -func GetCachedRoles(guildId, userId uint64, res chan []uint64) { - var rows []CachedRole - database.Database.Where(&CachedRole{ - GuildId: guildId, - UserId: userId, - }).Find(&rows) - - roles := make([]uint64, 0) - for _, row := range rows { - roles = append(roles, row.RoleId) - } - - res <- roles -} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b9f0abc --- /dev/null +++ b/go.mod @@ -0,0 +1,24 @@ +module github.com/TicketsBot/GoPanel + +go 1.14 + +require ( + github.com/BurntSushi/toml v0.3.1 + github.com/apex/log v1.1.2 + github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect + github.com/gin-contrib/multitemplate v0.0.0-20200226145339-3e397ee01bc6 + github.com/gin-contrib/static v0.0.0-20191128031702-f81c604d8ac2 + github.com/gin-gonic/contrib v0.0.0-20191209060500-d6e26eeaa607 + github.com/gin-gonic/gin v1.6.2 + github.com/go-redis/redis v6.15.7+incompatible + github.com/go-sql-driver/mysql v1.5.0 + github.com/gorilla/sessions v1.2.0 // indirect + github.com/gorilla/websocket v1.4.2 + github.com/jackc/pgx/v4 v4.6.0 + github.com/jinzhu/gorm v1.9.12 + github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c + github.com/pkg/errors v0.9.1 + github.com/robfig/go-cache v0.0.0-20130306151617-9fc39e0dbf62 + github.com/rxdn/gdl v0.0.0-20200410134146-c1b0871088c5 + github.com/vmihailenco/msgpack v4.0.4+incompatible +) diff --git a/cache/panelcreate.go b/messagequeue/panelcreate.go similarity index 93% rename from cache/panelcreate.go rename to messagequeue/panelcreate.go index dc08137..b079c52 100644 --- a/cache/panelcreate.go +++ b/messagequeue/panelcreate.go @@ -1,4 +1,4 @@ -package cache +package messagequeue import ( "encoding/json" diff --git a/cache/redis.go b/messagequeue/redis.go similarity index 91% rename from cache/redis.go rename to messagequeue/redis.go index a16d623..f33b329 100644 --- a/cache/redis.go +++ b/messagequeue/redis.go @@ -1,25 +1,25 @@ -package cache - -import ( - "fmt" - "github.com/TicketsBot/GoPanel/config" - "github.com/go-redis/redis" -) - -type RedisClient struct { - *redis.Client -} - -var Client RedisClient - -func NewRedisClient() RedisClient { - client := redis.NewClient(&redis.Options{ - Addr: fmt.Sprintf("%s:%d", config.Conf.Redis.Host, config.Conf.Redis.Port), - Password: config.Conf.Redis.Password, - PoolSize: config.Conf.Redis.Threads, - }) - - return RedisClient{ - client, - } -} +package messagequeue + +import ( + "fmt" + "github.com/TicketsBot/GoPanel/config" + "github.com/go-redis/redis" +) + +type RedisClient struct { + *redis.Client +} + +var Client RedisClient + +func NewRedisClient() RedisClient { + client := redis.NewClient(&redis.Options{ + Addr: fmt.Sprintf("%s:%d", config.Conf.Redis.Host, config.Conf.Redis.Port), + Password: config.Conf.Redis.Password, + PoolSize: config.Conf.Redis.Threads, + }) + + return RedisClient{ + client, + } +} diff --git a/cache/ticketclose.go b/messagequeue/ticketclose.go similarity index 95% rename from cache/ticketclose.go rename to messagequeue/ticketclose.go index d04180e..3e2f162 100644 --- a/cache/ticketclose.go +++ b/messagequeue/ticketclose.go @@ -1,4 +1,4 @@ -package cache +package messagequeue import ( "encoding/json" diff --git a/cache/webchat.go b/messagequeue/webchat.go similarity index 96% rename from cache/webchat.go rename to messagequeue/webchat.go index 601eb39..db89c84 100644 --- a/cache/webchat.go +++ b/messagequeue/webchat.go @@ -1,4 +1,4 @@ -package cache +package messagequeue import ( "encoding/json" diff --git a/public/templates/views/panels.tmpl b/public/templates/views/panels.tmpl index 61c6735..b48a50d 100644 --- a/public/templates/views/panels.tmpl +++ b/public/templates/views/panels.tmpl @@ -74,8 +74,10 @@