mirror of
https://github.com/mgerb/go-discord-bot
synced 2026-01-09 16:42:48 +00:00
UI done for video archiving
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var session *discordgo.Session
|
||||
|
||||
// Start the bot
|
||||
func Start(token string) *discordgo.Session {
|
||||
// initialize connection
|
||||
@@ -25,13 +27,34 @@ func Start(token string) *discordgo.Session {
|
||||
return session
|
||||
}
|
||||
|
||||
// GetSession - get current discord session
|
||||
func GetSession() *discordgo.Session {
|
||||
return session
|
||||
}
|
||||
|
||||
// SendEmbeddedNotification - sends notification to default room
|
||||
func SendEmbeddedNotification(title, description string) {
|
||||
if session == nil || config.Config.DefaultRoomID == "" {
|
||||
return
|
||||
}
|
||||
|
||||
embed := &discordgo.MessageEmbed{
|
||||
Color: 0x42adf4,
|
||||
Title: title,
|
||||
Description: description,
|
||||
}
|
||||
|
||||
session.ChannelMessageSendEmbed(config.Config.DefaultRoomID, embed)
|
||||
}
|
||||
|
||||
func addHandler(session *discordgo.Session, handler interface{}) {
|
||||
session.AddHandler(handler)
|
||||
}
|
||||
|
||||
func connect(token string) *discordgo.Session {
|
||||
// Create a new Discord session using the provided bot token.
|
||||
session, err := discordgo.New("Bot " + token)
|
||||
var err error
|
||||
session, err = discordgo.New("Bot " + token)
|
||||
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
|
||||
@@ -13,16 +13,17 @@ var (
|
||||
)
|
||||
|
||||
type configType struct {
|
||||
Token string `json:"token"`
|
||||
ClientID string `json:"client_id"`
|
||||
ClientSecret string `json:"client_secret"`
|
||||
RedirectURI string `json:"redirect_uri"`
|
||||
BotPrefix string `json:"bot_prefix"` //prefix to use for bot commands
|
||||
AdminEmails []string `json:"admin_emails"`
|
||||
ModEmails []string `json:"mod_emails"`
|
||||
ServerAddr string `json:"server_addr"`
|
||||
JWTSecret string `json:"jwt_secret"`
|
||||
Logger bool `json:"logger"`
|
||||
Token string `json:"token"`
|
||||
ClientID string `json:"client_id"`
|
||||
ClientSecret string `json:"client_secret"`
|
||||
RedirectURI string `json:"redirect_uri"`
|
||||
BotPrefix string `json:"bot_prefix"` //prefix to use for bot commands
|
||||
AdminEmails []string `json:"admin_emails"`
|
||||
ModEmails []string `json:"mod_emails"`
|
||||
ServerAddr string `json:"server_addr"`
|
||||
JWTSecret string `json:"jwt_secret"`
|
||||
Logger bool `json:"logger"`
|
||||
DefaultRoomID string `json:"default_room_id"`
|
||||
|
||||
// hard coded folder paths
|
||||
SoundsPath string
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mgerb/go-discord-bot/server/bot"
|
||||
"github.com/mgerb/go-discord-bot/server/db"
|
||||
"github.com/mgerb/go-discord-bot/server/webserver/middleware"
|
||||
"github.com/mgerb/go-discord-bot/server/webserver/model"
|
||||
@@ -13,11 +14,11 @@ import (
|
||||
|
||||
// AddVideoArchiveRoutes -
|
||||
func AddVideoArchiveRoutes(group *gin.RouterGroup) {
|
||||
group.GET("/video-archives", listVideoArchivesHandler)
|
||||
group.GET("/video-archive", listVideoArchivesHandler)
|
||||
|
||||
authGroup := group.Group("", middleware.AuthorizedJWT())
|
||||
authGroup.POST("/video-archives", middleware.AuthPermissions(middleware.PermMod), postVideoArchivesHandler)
|
||||
authGroup.DELETE("/video-archives/:id", middleware.AuthPermissions(middleware.PermAdmin), deleteVideoArchivesHandler)
|
||||
authGroup.POST("/video-archive", middleware.AuthPermissions(middleware.PermMod), postVideoArchivesHandler)
|
||||
authGroup.DELETE("/video-archive/:id", middleware.AuthPermissions(middleware.PermAdmin), deleteVideoArchivesHandler)
|
||||
}
|
||||
|
||||
func listVideoArchivesHandler(c *gin.Context) {
|
||||
@@ -100,5 +101,9 @@ func postVideoArchivesHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
hostURL := "[Click here to see the full archive!](http://" + c.Request.Host + "/video-archive)"
|
||||
youtubeURL := "https://youtu.be/" + videoArchive.YoutubeID
|
||||
bot.SendEmbeddedNotification(videoArchive.Title, "**"+videoArchive.UploadedBy+"** archived a new video:\n"+youtubeURL+"\n\n"+hostURL)
|
||||
|
||||
response.Success(c, "saved")
|
||||
}
|
||||
Reference in New Issue
Block a user