Add utility to listen to DiscordGo for debugging
This commit is contained in:
46
tools/listen.go
Normal file
46
tools/listen.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
token string
|
||||||
|
dg *discordgo.Session
|
||||||
|
guild string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.StringVar(&token, "t", "", "Bot Token")
|
||||||
|
flag.StringVar(&guild, "g", "", "Guild ID")
|
||||||
|
flag.Parse()
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if token == "" {
|
||||||
|
fmt.Printf("No token provided. Please run: disgord-thanos -t <bot token>")
|
||||||
|
}
|
||||||
|
dg, _ = discordgo.New("Bot " + token)
|
||||||
|
dg.AddHandler(messageCreate)
|
||||||
|
_ = dg.Open()
|
||||||
|
sc := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||||
|
<-sc
|
||||||
|
dg.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
|
jsonMsg, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg = append(jsonMsg, '0')
|
||||||
|
}
|
||||||
|
log.Printf("----------\n%+v: %+v\n\n%+v\n------------------------------\n\n", m.Author.Username, m.Content, string(jsonMsg))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user