Exemple #1
0
func Auth(conn *irc.Conn, channel, secret string) {
	conn.AddHandler("353", func(c *irc.Conn, l *irc.Line) { // NAMES
		if l.Args[2] != channel {
			return
		}
		for _, nick := range strings.Split(l.Args[3], " ", -1) {
			if !strings.HasPrefix(nick, "@") {
				continue
			}
			nick = nick[1:]
			hash := makeHash(channel, c.Me.Nick, nick, secret)
			c.Privmsg(nick, ".authop "+channel+" "+hash)
		}
	})
	conn.AddHandler("PRIVMSG", func(c *irc.Conn, l *irc.Line) {
		if strings.HasPrefix(l.Args[0], "#") {
			return
		}
		p := strings.Split(l.Args[1], " ", -1)
		if len(p) != 3 || p[0] != ".authop" || p[1] != channel {
			return
		}
		if p[2] != makeHash(channel, l.Nick, c.Me.Nick, secret) {
			return
		}
		c.Mode(channel, l.Nick+" +o")
	})
}
Exemple #2
0
func PlusOne(conn *irc.Conn, channel string) {
	AutoJoin(conn, channel)
	conn.AddHandler("PRIVMSG", func(c *irc.Conn, l *irc.Line) {
		if l.Args[0] != channel {
			return
		}
		m := l.Args[1]
		if m == ".scores" {
			plusOneScores(c, channel)
			return
		}
		if !plusOneRe.MatchString(m) {
			return
		}
		nick := strings.Split(m, ":", 2)[0]
		if c.GetNick(nick) == nil {
			return
		}
		nick = Canonical(nick)
		if len(nick) == 0 {
			return
		}
		n := 1
		if m[len(m)-2] == '-' {
			n = -1
		}
		plusOneCount(nick, n)
	})
}
Exemple #3
0
func addWhoHandlers(irc *client.Conn) {
	if !flag.Parsed() {
		flag.Parse()
	}

	irc.AddHandler("352", whoHandler)
	irc.AddHandler("315", whoHandler)
	return
}
Exemple #4
0
func AutoJoin(conn *irc.Conn, channel string) {
	autoJoinLock.Lock()
	defer autoJoinLock.Unlock()
	if autoJoinChannels[channel] {
		return
	}
	autoJoinChannels[channel] = true
	conn.AddHandler("CONNECTED", func(c *irc.Conn, l *irc.Line) {
		conn.Join(channel)
	})
}
Exemple #5
0
func (s InBandSource) Connect(c *irc.Conn) (err error) {
	if c.Connected {
		return nil
	}

	c.AddHandler(irc.CONNECTED, func(c *irc.Conn, line *irc.Line) {
		c.Join(s.Host().Channel)
	})

	if err := c.Connect(s.Host().Server); err != nil {
		return err
	}

	return nil
}
Exemple #6
0
func YouTuber(conn *irc.Conn, channel string) {
	AutoJoin(conn, channel)
	conn.AddHandler("PRIVMSG", func(c *irc.Conn, l *irc.Line) {
		if l.Args[0] != channel {
			return
		}
		m := l.Args[1]
		url := youtubeRe.FindStringSubmatch(m)
		if url == nil {
			return
		}
		q, _ := http.ParseQuery(url[1])
		key, found := q["v"]
		if !found {
			return
		}
		printMetadataForKey(c, channel, key[0])
	})
}
Exemple #7
0
func addNickHandlers(irc *client.Conn) {
	if !flag.Parsed() {
		flag.Parse()
	}

	irc.AddHandler("QUIT", dropIdentifiedCache)
	irc.AddHandler("307", isIdentified)
	irc.AddHandler("330", isIdentified)
	irc.AddHandler("318", isIdentified)
}
Exemple #8
0
func setupClient(c *irc.Conn, chConnected chan bool) {
	c.AddHandler(irc.CONNECTED, func(conn *irc.Conn, line *irc.Line) {
		chConnected <- true
	})
	c.AddHandler(irc.DISCONNECTED, func(conn *irc.Conn, line *irc.Line) {
		chConnected <- false
	})
	c.AddHandler("PRIVMSG", func(conn *irc.Conn, line *irc.Line) {
		if len(line.Args) < 2 || !strings.HasPrefix(line.Args[1], "!") {
			return
		}
		to := line.Args[0]
		sender := to
		if to == c.Me.Nick {
			// TODO: check if sender is in main chan, else return
			log.Println("Got ! via PM from " + line.Src)
			sender = line.Src // replies go via PM too.
		} else {
			log.Println("Got ! via chan: " + line.Args[0] + " from " + line.Src)
		}
		log.Println(line.Args)
		switch line.Args[0] {
		case "!join":
			if len(line.Args) == 2 {
				c.Join(line.Args[1])
			} else if len(line.Args) == 3 {
				c.Join(line.Args[1] + " " + line.Args[2])
			} else {
				c.Privmsg(sender, "Usage: !join #chan  or  !join #chan key")
			}
		case "!part":
			if len(line.Args) == 2 {
				c.Part(line.Args[1])
			} else {
				c.Privmsg(sender, "Usage: !part #chan")
			}
		default:
			c.Privmsg(sender, "Invalid command: "+strings.Join(line.Args[1:], " "))
			return
		}
	})

}
Exemple #9
0
func (plugin *Plugin) Register(conn *irc.Conn) {
	conn.AddHandler("PRIVMSG", respond)
}