コード例 #1
0
ファイル: factdriver.go プロジェクト: gundalow/sp0rkle
func Init() {
	fc = factoids.Init()

	bot.Handle(insert, client.PRIVMSG)
	bot.Handle(lookup, client.PRIVMSG, client.ACTION)

	bot.Rewrite(replaceIdentifiers)

	bot.Command(chance, "chance of that is",
		"chance  -- Sets trigger chance of the last displayed factoid value.")
	bot.Command(edit, "that =~",
		"=~ s/regex/replacement/ -- Edits the last factoid value using regex.")
	bot.Command(forget, "delete that",
		"delete  -- Forgets the last displayed factoid value.")
	bot.Command(forget, "forget that",
		"forget  -- Forgets the last displayed factoid value.")
	bot.Command(info, "fact info",
		"fact info <key>  -- Displays some stats about factoid <key>.")
	bot.Command(literal, "literal",
		"literal <key>  -- Displays the factoid values stored for <key>.")
	bot.Command(replace, "replace that with",
		"replace  -- Replaces the last displayed factoid value.")
	bot.Command(search, "fact search",
		"fact search <regexp>  -- Searches for factoids matching <regexp>.")
}
コード例 #2
0
ファイル: factdriver.go プロジェクト: pzsz/sp0rkle
func Init() {
	fc = factoids.Init()

	bot.HandleFunc(insert, "privmsg")
	bot.HandleFunc(lookup, "privmsg", "action")

	bot.PluginFunc(replaceIdentifiers)

	bot.CommandFunc(chance, "chance of that is",
		"chance  -- Sets trigger chance of the last displayed factoid value.")
	bot.CommandFunc(forget, "delete that",
		"delete  -- Forgets the last displayed factoid value.")
	bot.CommandFunc(forget, "forget that",
		"forget  -- Forgets the last displayed factoid value.")
	bot.CommandFunc(info, "fact info",
		"fact info <key>  -- Displays some stats about factoid <key>.")
	bot.CommandFunc(literal, "literal",
		"literal <key>  -- Displays the factoid values stored for <key>.")
	bot.CommandFunc(replace, "replace that with",
		"replace  -- Replaces the last displayed factoid value.")
	bot.CommandFunc(search, "fact search",
		"fact search <regexp>  -- Searches for factoids matching <regexp>.")
}
コード例 #3
0
ファイル: factimporter.go プロジェクト: pzsz/sp0rkle
func main() {
	flag.Parse()
	logging.InitFromFlags()

	// Let's go find some mongo.
	db.Init()
	defer db.Close()
	fc := factoids.Init()

	// A communication channel of Factoids.
	facts := make(chan *factoids.Factoid)
	ptrs := make(chan []interface{})
	rows := make(chan []interface{})

	// Function to execute some queries on the SQLite db and shove the results
	// into the ptrs and rows channels created above.
	db_query := func(dbh *sqlite3.Database) {
		_, err := dbh.Execute("SELECT * FROM Factoids WHERE Value LIKE '%*%';", feeder(ptrs))
		close(ptrs)
		if err != nil {
			logging.Error("DB error: %s", err)
		}
		n, err := dbh.Execute("SELECT * FROM Factoids;", feeder(rows))
		close(rows)
		if err == nil {
			logging.Info("Read %d rows from database.", n)
		} else {
			logging.Error("DB error: %s", err)
		}
	}

	go func() {
		sqlite3.Session(*file, db_query)
	}()

	// First, synchronously read all the stuff from the ptrs channel
	// and build a set of all the factoid keys that are used as pointers
	for row := range ptrs {
		for _, val := range parseMultipleValues(toString(row[cValue])) {
			if key, _, _ := util.FactPointer(val); key != "" {
				ptrkeys[key] = true
			}
		}
	}

	// Now run another goroutine to munge the rows into factoids.
	// This was originally done inside the SQLite callbacks, but
	// cgo or sqlite3 obscures runtime panics and makes fail happen.
	go func() {
		for row := range rows {
			parseFactoid(row, facts)
		}
		close(facts)
	}()

	// And finally...
	count := 0
	var err error
	for fact := range facts {
		// ... push each fact into mongo
		err = fc.Insert(fact)
		if err != nil {
			logging.Error("Awww: %v\n", err)
		} else {
			if count%1000 == 0 {
				fmt.Printf("%d...", count)
			}
			count++
		}
	}
	fmt.Println("done.")
	logging.Info("Inserted %d factoids.\n", count)
}