示例#1
0
func reportIgnored(irc *client.Conn, asker, who string) {
	if asker == who {
		irc.Notice(asker, "You asked to be ignored by last.fm commands")
	} else {
		irc.Notice(asker, fmt.Sprintf("%s asked to be ignored by last.fm commands", who))
	}
}
示例#2
0
func sendHelp(irc *client.Conn, nick string) {
	helpStr := `
	Last.fm commands:
	` + *cmdPrefix + `np ($user)?: Shows your now playing song. If you give $user, queries for that $user.
	` + *cmdPrefix + `compare ($user1) ($user2)?: Runs a tasteometer compare between you and $user1, or between $user1 and $user2 if present.
	` + *cmdPrefix + `top5 ((overall|year|month|week) ($user)?)?: Shows the top5 artists in the chosen period for you or the $user.
	` + *cmdPrefix + `whois ($nick)?: Shows your associated last.fm username, or the username associated with $nick.
	` + *cmdPrefix + `aka ($username): Shows the nicks that have been associated with $username.
	A nick can be used in place of a username if it's associated with a last.fm account.
	`
	if *requireAuth {
		helpStr += `Commands that require that you be authenticated with NickServ:`
	}
	// There's also *cmdPrefix + "wp", but we don't document it to not encourage abuse.
	helpStr += `
	` + *cmdPrefix + `ignore: Makes the bot ignore you for most commands. Use ` +
		*cmdPrefix + `setuser or ` + *cmdPrefix + `deluser to be unignored.
	` + *cmdPrefix + `setuser ($username): Associates your nick with the given last.fm $username.
	` + *cmdPrefix + `deluser: Removes your nick's association, if any.
	` // + *cmdPrefix + `wp: Shows what's playing for everyone in the channel.` // uncomment this at your peril :)
	for _, line := range helpSplit.Split(helpStr, -1) {
		if line != "" {
			irc.Notice(nick, line)
		}
	}
}
示例#3
0
func MessageHandler(conn *irc.Conn, line *irc.Line) {
	var googleRegexp = regexp.MustCompile(`\](.+?)\[`)

	if googleRegexp.MatchString(line.Args[1]) {
		for _, match := range googleRegexp.FindAllStringSubmatch(line.Args[1], -1) {
			conn.Notice(channel, match[1])
		}
	}
}
示例#4
0
func eventJoin(conn *irc.Conn, line *irc.Line) {
	if debug {
		fmt.Printf("Event Join fired: [%s]\n", line)
	}

	if botName != line.Nick {
		conn.Notice(line.Src, line.Nick+", welcome")
	}
}
示例#5
0
文件: handler.go 项目: thevermi/rbot
func say(conn *irc.Conn, target, message string, a ...interface{}) {
	if len(a) > 0 {
		message = fmt.Sprintf(message, a...)
	}
	text := strings.Replace(message, "\n", " ", -1)
	if isChannel(target) {
		conn.Privmsg(target, text)
	} else {
		conn.Notice(target, text)
	}
}
示例#6
0
func plusplus(c *irc.Conn, line *irc.Line, nick string, plus int) {
	score := 0

	incr()
	lock1.Lock()

	defer func() {
		lock1.Unlock()
		<-time.After(1 * time.Second)
		decr()
		if ref == 0 {
			c.Notice(line.Args[0], fmt.Sprintf("%s (%d)", nick, score))
		}
	}()

	tx, err := db.Begin()
	if err != nil {
		fmt.Printf("Database error: %v\n", err)
		return
	}
	defer tx.Rollback()

	row, err := tx.Query(`select score from plusplus where nick = ?`, strings.ToLower(nick))
	if err != nil {
		fmt.Printf("Database error: %v\n", err)
		return
	}

	if row.Next() {
		err = row.Scan(&score)
		if err != nil {
			fmt.Printf("Database error: %v\n", err)
			row.Close()
			return
		}
	}
	score += plus
	row.Close()

	stmt, err := tx.Prepare(`insert or replace into plusplus (nick, score) values (?, ?)`)
	if err != nil {
		fmt.Printf("Database error: %v\n", err)
		return
	}
	defer stmt.Close()

	_, err = stmt.Exec(strings.ToLower(nick), score)
	if err != nil {
		fmt.Printf("Database error: %v\n", err)
		return
	}
	tx.Commit()
}
示例#7
0
func onInvite(irc *client.Conn, line *client.Line) {
	who, channel := line.Args[0], line.Args[1]
	log.Println(line.Nick, "invited bot to", channel)
	if who == irc.Me.Nick {
		// some IRCds only allow operators to INVITE, and on registered channels normally only identified users are operators
		// check anyway, since there are some corner cases where that doesn't happen
		if checkIdentified(irc, line.Nick) {
			log.Println("Accepting invite to", channel)
			irc.Join(channel)
		} else {
			irc.Notice(line.Nick, "you must be identified to invite")
			log.Println("Ignoring invite, user is not identified")
		}
	}
}
示例#8
0
func ranking(c *irc.Conn, line *irc.Line) {
	lock1.Lock()
	defer lock1.Unlock()

	rows, err := db.Query(`select nick, score from plusplus order by score desc`)
	if err != nil {
		fmt.Printf("Database error: %v\n", err)
		return
	}
	defer rows.Close()

	rank, nick, score := 1, "", 0
	for rows.Next() {
		rows.Scan(&nick, &score)
		c.Notice(line.Args[0], fmt.Sprintf("%03d: %s (%d)\n", rank, nick, score))
		rank++
		if rank > 5 {
			break
		}
	}
}
示例#9
0
文件: handlers.go 项目: b33f/sp0rkle
func bot_rebuild(irc *client.Conn, line *client.Line) {
	bot := getState(irc)
	if bot.rbnick == "" || bot.rbnick != line.Nick {
		return
	}
	if !strings.HasPrefix(line.Args[1], "rebuild") {
		return
	}
	if bot.rbpw != "" && line.Args[1] != "rebuild "+bot.rbpw {
		return
	}

	// Ok, we should be good to rebuild now.
	irc.Notice(line.Nick, "Beginning rebuild")
	cmd := exec.Command("go", "get", "-u", "github.com/fluffle/sp0rkle/sp0rkle")
	out, err := cmd.CombinedOutput()
	if err != nil {
		irc.Notice(line.Nick, fmt.Sprintf("Rebuild failed: %s", err))
		for _, l := range strings.Split(string(out), "\n") {
			irc.Notice(line.Nick, l)
		}
		return
	}
	bot.quit = true
	bot.reexec = true
	bot.Conn.Quit("Restarting with new build.")
}
示例#10
0
func reportAllNowPlaying(irc *client.Conn, asker, channel string) {
	if !(strings.HasPrefix(channel, "#") || strings.HasPrefix(channel, "&")) {
		log.Println("User", asker, "asked What's Playing...... via PM")
		irc.Privmsg(channel, fmt.Sprintf("%s: this only works on channels", asker))
		return
	}
	log.Println("User", asker, "requested What's Playing on channel", channel)

	if !checkIdentified(irc, asker) {
		r := fmt.Sprintf("%s: you must be identified with NickServ to use this command", asker)
		log.Println(r)
		irc.Privmsg(channel, r)
		return
	}

	if _, ok := whoChannel[channel]; ok {
		log.Println("Channel", channel, "is already executing a What's Playing request")
		return
	}

	whoChannel[channel] = make(chan bool, 1)

	go irc.Who(channel)
	for _ = range whoChannel[channel] { // wait until channel is closed
	}
	delete(whoChannel, channel)

	reportChan := make(chan bool)
	totalReport := len(whoResult[channel]) - 1
	msg := fmt.Sprintf("Reporting now playing for %d nicks in channel %s", totalReport, channel)
	log.Println(msg)
	irc.Notice(asker, msg)

	for _, nick := range whoResult[channel] {
		if nick != irc.Me().Nick {
			n := nick
			go func() {
				rateLimit <- true
				reportChan <- reportNowPlaying(irc, channel, asker, n, true)
				<-rateLimit
			}()
		}
	}
	delete(whoResult, channel)

	okCount, totalCount := 0, 0
	for r := range reportChan {
		if r {
			okCount++
		}
		if totalCount++; totalCount == totalReport {
			break
		}
	}
	close(reportChan)

	msg = fmt.Sprintf("Reported for %d of %d nicks", okCount, totalCount)
	log.Println(msg)
	irc.Notice(asker, msg)

	return
}