Skip to content
Snippets Groups Projects
Commit 8d2e506a authored by Levatax's avatar Levatax
Browse files

add message handler

parent ae0d2a26
Branches dev
No related tags found
No related merge requests found
package events
import (
"fmt"
"github.com/bwmarrin/discordgo"
)
type MessageHandler struct{}
func NewMessageHandler() *MessageHandler {
return &MessageHandler{}
}
func (h *MessageHandler) Handler(session *discordgo.Session, e *discordgo.MessageCreate) {
channel, err := session.Channel(e.ChannelID)
if err != nil {
fmt.Println("Failed getting channel: ", err)
return
}
fmt.Printf("%s said in channel %s: %s\n", e.Author.String(), channel.Name, e.Content)
}
......@@ -3,7 +3,6 @@ module git.randomchars.net/Leva/ticket-bot
go 1.16
require (
git.randomchars.net/FreeNitori/EmbedUtil v1.0.1
git.randomchars.net/FreeNitori/Log v1.0.0
git.randomchars.net/FreeNitori/Multiplexer v1.0.8
github.com/bwmarrin/discordgo v0.23.2
......
......@@ -6,14 +6,17 @@ git.randomchars.net/FreeNitori/Multiplexer v1.0.8 h1:T8psSgXzZ9P7LC0LxUsVrYU/itr
git.randomchars.net/FreeNitori/Multiplexer v1.0.8/go.mod h1:wXHDJdlKFC15Bh+f0FsFuQKTXyTxVIfkTt749oDcSk0=
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/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g=
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.0 h1:nfhvjKcUMhBMVqbKHJlk5RPrrfYr/NMo3692g0dwfWU=
github.com/sirupsen/logrus v1.8.0/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
......
......@@ -3,13 +3,15 @@ package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
log "git.randomchars.net/FreeNitori/Log"
multiplexer "git.randomchars.net/FreeNitori/Multiplexer"
"github.com/bwmarrin/discordgo"
"github.com/sirupsen/logrus"
"os"
"os/signal"
"syscall"
"https://git.randomchars.net/Leva/ticket-bot/events"
)
var session *discordgo.Session
......@@ -72,6 +74,9 @@ func main() {
log.Infof("Invite URL: https://discord.com/oauth2/authorize?client_id=%s&scope=bot&permissions=8", application.ID)
}
// Message handling
session.AddHandler(events.NewMessageHandler().Handler)
// Signal handling
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, os.Interrupt, os.Kill)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment