Example #1
0
func context(conn *client.Conn, line *client.Line) *Context {
	ctx := &Context{conn: conn, Line: line.Copy(), rws: bot.rewriters}
	// This is a bit of a dirty hack; context() returns nil to ignore a line.
	// TODO(fluffle): Ignores based on masks (or more likely regex).
	if ctx.Nick != "" && conf.Ns(ignoreNs).String(strings.ToLower(ctx.Nick)) != "" {
		return nil
	}
	if ctx.Cmd != client.PRIVMSG {
		return ctx
	}
	ctx.Args[1], ctx.Addressed = util.RemovePrefixedNick(
		strings.TrimSpace(ctx.Args[1]), ctx.Me())
	// If we're being talked to in private, line.Args[0] will contain our Nick.
	// We should consider this as "addressing" us, and set Addressed = true
	if ctx.Args[0] == ctx.Me() {
		ctx.Addressed = true
	}
	return ctx
}
Example #2
0
File: bot.go Project: pzsz/sp0rkle
func transformLine(line *client.Line) *base.Line {
	// We want line.Args[1] to contain the (possibly) stripped version of itself
	// but modifying the pointer will result in other goroutines seeing the
	// change, so we need to copy line for our own edification.
	nl := &base.Line{Line: line.Copy()}
	if nl.Cmd != "PRIVMSG" {
		return nl
	}
	nl.Args[1], nl.Addressed = util.RemovePrefixedNick(
		strings.TrimSpace(line.Args[1]), irc.Me.Nick)
	// If we're being talked to in private, line.Args[0] will contain our Nick.
	// To ensure the replies go to the right place (without performing this
	// check everywhere) test for this and set line.Args[0] == line.Nick.
	// We should consider this as "addressing" us too, and set Addressed = true
	if nl.Args[0] == irc.Me.Nick {
		nl.Args[0] = nl.Nick
		nl.Addressed = true
	}
	return nl
}