dgbot.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "log"
  6. "math/rand"
  7. "os"
  8. "time"
  9. Discord "github.com/bwmarrin/discordgo"
  10. )
  11. // Global Variables
  12. var (
  13. Session Discord.Session
  14. Username string
  15. Password string
  16. )
  17. func main() {
  18. fmt.Printf("\nDiscordgo Bot Starting.\n\n")
  19. // Register all the Event Handlers
  20. RegisterHandlers()
  21. // read in the config file.
  22. ParseFile()
  23. // seed the random number generator
  24. rand.Seed(time.Now().UTC().UnixNano())
  25. // main program loop to keep dgbot running
  26. // will add stuff here to track goroutines
  27. // and monitor for CTRL-C or other things.
  28. for {
  29. time.Sleep(1000 * time.Millisecond)
  30. }
  31. fmt.Println("\nDiscordgo Bot shutting down.\n")
  32. }
  33. // ParseFile will read a file .dgbotrc and run all included
  34. // commands
  35. func ParseFile() {
  36. file, err := os.Open(".dgbotrc")
  37. if err != nil {
  38. return
  39. }
  40. defer file.Close()
  41. scanner := bufio.NewScanner(file)
  42. for scanner.Scan() {
  43. fmt.Println(scanner.Text())
  44. fmt.Println(admin(scanner.Text()))
  45. }
  46. if err := scanner.Err(); err != nil {
  47. log.Fatal(err)
  48. }
  49. }