Gregory Rudolph
3 years ago
1 changed files with 46 additions and 0 deletions
@ -0,0 +1,46 @@
@@ -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)) |
||||
} |
Loading…
Reference in new issue