Exemplo n.º 1
0
func connectToDiscord() {
	log.Println("Connecting to discord")

	var err error

	c := config.Get()

	dg, err := discordgo.New(c.Email, c.Password, "Bot "+c.Token)
	if err != nil {
		log.Println(err.Error())
		return
	}

	// Register messageCreate as a callback for the OnMessageCreate event.
	dg.AddHandler(messageCreate)

	// Retry after broken websocket
	dg.ShouldReconnectOnError = true

	// Verify the Token is valid and grab user information
	dg.State.User, err = dg.User("@me")
	if err != nil {
		log.Printf("error fetching user information, %s\n", err)
	}

	// Open websocket connection
	err = dg.Open()
	if err != nil {
		log.Printf("error opening connection to Discord, %s\n", err)
		return
	}

	log.Println("Connected")
}
Exemplo n.º 2
0
func shouldIgnore(user *discordgo.User) bool {
	c := config.Get()

	if user.Bot {
		return true
	}

	for _, id := range c.Blacklist {
		if id == user.ID {
			return true
		}
	}

	return false
}
Exemplo n.º 3
0
func main() {
	os.Mkdir("./data", 0744)

	config.Init()
	brain.Init()

	c := config.Get()

	go func() {
		start := time.Now()

		log.Println("Starting to fill brain")

		for _, b := range c.Brain {
			log.Println("Parsing", b.File)

			err := brain.LearnFileLines(b.File, b.Simple)

			if err != nil {
				log.Println(err)
				return
			}
		}

		log.Println("Parsing ./data/chatlog.txt")
		err := brain.LearnFileLines("./data/chatlog.txt", false)
		if err != nil {
			log.Println(err)
		}

		log.Println("Brain filled in", time.Since(start))
	}()

	connectToDiscord()

	// Simple way to keep program running until any key press.
	var input string
	fmt.Scanln(&input)
}