diff --git a/makefile b/makefile deleted file mode 100644 index 83b8195..0000000 --- a/makefile +++ /dev/null @@ -1,17 +0,0 @@ -install: - cd server && dep ensure && go get - cd client && npm install - -build-server: - cd ./server && packr build -o ../bot ./main.go - -build-scripts: - go build -o bot-scripts ./server/scripts - -build-client: - cd client && npm run build - -clean: - rm -rf bot ./dist - -all: install build-client build-server diff --git a/server/bot/bot.go b/server/bot/bot.go index 58bc7a7..e9a98a8 100644 --- a/server/bot/bot.go +++ b/server/bot/bot.go @@ -1,7 +1,6 @@ package bot import ( - "os" "time" "github.com/bwmarrin/discordgo" @@ -13,7 +12,6 @@ import ( // keep reference to discord session var _session *discordgo.Session var _token string -var _sc chan os.Signal // SendEmbeddedNotification - sends notification to default room func SendEmbeddedNotification(title, description string) { diff --git a/server/bothandlers/gif.go b/server/bothandlers/gif.go index ac4951a..7c17f52 100644 --- a/server/bothandlers/gif.go +++ b/server/bothandlers/gif.go @@ -1,73 +1,73 @@ package bothandlers -/** - * DEPRECATED - * this was used to fetch a giphy image - * no longer used - */ +// /** +// * DEPRECATED +// * this was used to fetch a giphy image +// * no longer used +// */ -import ( - "io/ioutil" - "math/rand" - "net/http" - "strings" - "time" +// import ( +// "io/ioutil" +// "math/rand" +// "net/http" +// "strings" +// "time" - "github.com/bwmarrin/discordgo" - "github.com/tidwall/gjson" -) +// "github.com/bwmarrin/discordgo" +// "github.com/tidwall/gjson" +// ) -const ( - gifPrefix string = "!gif " - userAgent string = "go-discord-bot" - giphyURL string = "http://api.giphy.com/v1/gifs/search?&api_key=dc6zaTOxFJmzC&limit=10&q=" -) +// const ( +// gifPrefix string = "!gif " +// userAgent string = "go-discord-bot" +// giphyURL string = "http://api.giphy.com/v1/gifs/search?&api_key=dc6zaTOxFJmzC&limit=10&q=" +// ) -// GifHandler - handler for giphy api -func GifHandler(s *discordgo.Session, m *discordgo.MessageCreate) { +// // GifHandler - handler for giphy api +// func GifHandler(s *discordgo.Session, m *discordgo.MessageCreate) { - // check if valid command - if strings.HasPrefix(m.Content, gifPrefix) { +// // check if valid command +// if strings.HasPrefix(m.Content, gifPrefix) { - searchText := strings.TrimPrefix(m.Content, gifPrefix) +// searchText := strings.TrimPrefix(m.Content, gifPrefix) - gifLink := getGiphy(searchText) +// gifLink := getGiphy(searchText) - if gifLink == "null" { - gifLink = "No gif found." - } +// if gifLink == "null" { +// gifLink = "No gif found." +// } - s.ChannelMessageSend(m.ChannelID, gifLink) +// s.ChannelMessageSend(m.ChannelID, gifLink) - } -} +// } +// } -// send http request to reddit -func getGiphy(searchTerm string) string { +// // send http request to reddit +// func getGiphy(searchTerm string) string { - rand.Seed(time.Now().UnixNano()) +// rand.Seed(time.Now().UnixNano()) - client := &http.Client{} +// client := &http.Client{} - req, err := http.NewRequest("GET", giphyURL+searchTerm, nil) +// req, err := http.NewRequest("GET", giphyURL+searchTerm, nil) - response, err := client.Do(req) - if err != nil { - return err.Error() - } +// response, err := client.Do(req) +// if err != nil { +// return err.Error() +// } - defer response.Body.Close() +// defer response.Body.Close() - body, err := ioutil.ReadAll(response.Body) - if err != nil { - return err.Error() - } +// body, err := ioutil.ReadAll(response.Body) +// if err != nil { +// return err.Error() +// } - data := gjson.Get(string(body), "data").Array() +// data := gjson.Get(string(body), "data").Array() - if len(data) < 1 { - return "null" - } +// if len(data) < 1 { +// return "null" +// } - return data[rand.Intn(len(data))].Get("images.fixed_height.url").String() -} +// return data[rand.Intn(len(data))].Get("images.fixed_height.url").String() +// } diff --git a/server/bothandlers/logger.go b/server/bothandlers/logger.go index 235a0e4..c6f364b 100644 --- a/server/bothandlers/logger.go +++ b/server/bothandlers/logger.go @@ -2,6 +2,7 @@ package bothandlers import ( "strings" + "time" "github.com/bwmarrin/discordgo" "github.com/mgerb/go-discord-bot/server/db" @@ -16,8 +17,11 @@ func LoggerHandler(s *discordgo.Session, m *discordgo.MessageCreate) { model.UserSave(db.GetConn(), user) // create and save message - timestamp, _ := m.Message.Timestamp.Parse() - editedTimestamp, _ := m.Message.EditedTimestamp.Parse() + timestamp := m.Message.Timestamp + var editedTimestamp time.Time + if m.Message.EditedTimestamp != nil { + editedTimestamp = *m.Message.EditedTimestamp + } attachments := getAttachments(m.Message.Attachments) message := &model.Message{ diff --git a/server/bothandlers/sounds.go b/server/bothandlers/sounds.go index 17bee25..743ee29 100644 --- a/server/bothandlers/sounds.go +++ b/server/bothandlers/sounds.go @@ -57,7 +57,8 @@ func VoiceStateHandler(s *discordgo.Session, v *discordgo.VoiceStateUpdate) { voiceConnection := conn.getVoiceConnection() - if voiceConnection != nil && voiceConnection.Ready && voiceConnection.ChannelID == v.VoiceState.ChannelID { + if voiceConnection != nil && voiceConnection.Ready && voiceConnection.ChannelID == v.VoiceState.ChannelID && + (v.BeforeUpdate == nil || v.BeforeUpdate.ChannelID != voiceConnection.ChannelID) { user, err := model.UserGet(db.GetConn(), v.VoiceState.UserID) diff --git a/server/go.mod b/server/go.mod index 2cb0436..07508e7 100644 --- a/server/go.mod +++ b/server/go.mod @@ -3,7 +3,7 @@ module github.com/mgerb/go-discord-bot/server go 1.17 require ( - github.com/bwmarrin/discordgo v0.23.2 + github.com/bwmarrin/discordgo v0.24.0 github.com/gin-gonic/gin v1.7.7 github.com/go-audio/audio v1.0.0 github.com/go-audio/wav v1.0.0 diff --git a/server/go.sum b/server/go.sum index 4dc194c..84cd034 100644 --- a/server/go.sum +++ b/server/go.sum @@ -75,6 +75,8 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4Yn github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/bwmarrin/discordgo v0.23.2 h1:BzrtTktixGHIu9Tt7dEE6diysEF9HWnXeHuoJEt2fH4= github.com/bwmarrin/discordgo v0.23.2/go.mod h1:c1WtWUGN6nREDmzIpyTp/iD3VYt4Fpx+bVyfBG7JE+M= +github.com/bwmarrin/discordgo v0.24.0 h1:Gw4MYxqHdvhO99A3nXnSLy97z5pmIKHZVJ1JY5ZDPqY= +github.com/bwmarrin/discordgo v0.24.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= @@ -243,6 +245,7 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0= github.com/googleapis/gax-go/v2 v2.1.1/go.mod h1:hddJymUZASv3XPyGkUpKj8pPO47Rmb0eJc8R6ouapiM= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= @@ -456,6 +459,7 @@ golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=