예제 #1
0
func loadConfig() {
	conf, _ := spicerack.GofigFromEnv("ME_CONF")
	salty, _ := conf.Map("salty")
	dbUser = salty["db_user"].(string)
	dbName = salty["db_name"].(string)
	dbPass = salty["db_pass"].(string)
	illumEmail = salty["illum_email"].(string)
	illumPass = salty["illum_pword"].(string)
	theShiznit = salty["the_shiznit"].(string)
	statsUrl = salty["ajax_stats"].(string)
}
예제 #2
0
func main() {
	// thread-safe message logging
	go listenForLogs()

	// catching interrupt and terminate signals
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)
	go catchSignals(sigs)

	// loading from global config
	log("PID: %d\n", os.Getpid())
	log("Loading Configuration")
	conf, err := spicerack.GofigFromEnv("ME_CONF")
	if err != nil {
		log("%v -  Quitting.", err)
		os.Exit(1)
	}

	// reading from config & initialzing IRC client
	conf.Struct("salty", settings)
	settings.Pushover, _ = conf.Map("pushover")
	client = irc.NewClient(settings.Server, settings.Nick, false)

	// If the bot crashes, send a notification
	defer func() {
		if r := recover(); r != nil {
			log("Panic! Sending notification: %v", r)
			msg := fmt.Sprintf("%s is down! (%v)", settings.Nick, r)
			notify(msg)
		}
	}()

	// hookup irc command handling functions
	client.HandleCommand(irc.RPL_WELCOME, registerAndJoin)
	client.HandleCommand(irc.CMD_PRIVMSG, manualFightCard)
	client.HandleCommand(irc.CMD_PRIVMSG, getSpecificFighters)
	client.HandleCommand(irc.CMD_PRIVMSG, showWLInfo)
	client.HandleCommand(irc.CMD_PRIVMSG, getUntieredCount)
	client.HandleCommand(irc.CMD_PRIVMSG, nickServ)

	// connect to IRC & wait indefinitely, and listen for HTTP posts
	// to relay to the channel
	log("Connecting to IRC...")
	client.Connect()
	listenForRelays()
	client.Wait()

	if shouldNotify {
		notify(fmt.Sprintf("%s has unexpectedly stopped!", settings.Nick))
	}
}
예제 #3
0
func main() {
	// load the config file
	flag.Parse()
	conf, err := spicerack.GofigFromEnv("ME_CONF")
	if err != nil {
		fmt.Printf("%v\nQuitting.\n", err)
		os.Exit(1)
	}

	// inflate settings struct & open db connection
	settings := &Settings{}
	conf.Struct("salty", settings)
	repo, err = spicerack.OpenDb(settings.DbUser, settings.DbPass, settings.DbName)
	if err != nil {
		fmt.Printf("Failed to connect to postgres: %v\n", err)
		os.Exit(1)
	}
	defer repo.Close()

	// reset ELO values if options are present
	if *resetElo {
		repo.ResetElo(*eloBase)
	}

	// log into saltybet
	client, err := spicerack.LogIntoSaltyBet(settings.IllumEmail, settings.IllumPword)
	if err != nil {
		fmt.Printf("Error logging into saltybet: %v\n", err)
		os.Exit(1)
	}

	// compile a number regex, we'll be using it a lot in parsing
	numRx, _ = regexp.Compile(`[0-9]+`)

	// scrape the compendium for updated/new characters
	fmt.Println("Scraping Roster")
	if err := getRoster(client); err != nil {
		fmt.Printf("Failed to scrape roster: %v\n", err)
		os.Exit(1)
	}

	// Get the last n number of tournaments & scrape 'em
	count := settings.RecentTournamentCount
	fmt.Printf("Grabbing last %d tournament Ids\n", count)
	var tourneys []int
	if *saltTheEarth {
		tourneys, _ = getAllTournamentIds()
	} else {
		tourneys, err = getLatestTournamentIds(client, count)
		if err != nil {
			fmt.Printf("Failed to grab tournament IDs: %v\n", err)
			os.Exit(1)
		}
	}

	for _, tournyId := range tourneys {
		pageNum := 1
		for {
			fmt.Printf("Processing Tournament #%d, Page #%d\n", tournyId, pageNum)
			hasNextPage, err := processTournament(client, tournyId, pageNum)
			if err != nil {
				fmt.Printf("Failed to parse tournament page: %v\n", err)
				break
			}
			if !hasNextPage {
				break
			}
			fmt.Println()
			pageNum++
		}
		fmt.Println()
	}
	relayToBot(fmt.Sprintf("Scheduled scrape complete, bot information is up to date."))
}