Ejemplo n.º 1
0
func (m *NotifyMod) NotifyIfQueued(conn *irc.Conn, line irc.Line) {
	to := line.Src.String()

	if notes, ok := m.notes[to]; ok {

		ctx := getContext(line)

		for _, note := range notes {
			conn.Privmsg(ctx, fmt.Sprintf("%s: %s", to, note))
		}

		delete(m.notes, to)
	}
}
Ejemplo n.º 2
0
func Conn(conn *irc.Conn) IrcConn {
	return IrcConn{conn.SafeConn()}
}
Ejemplo n.º 3
0
func handleCommand(conn *irc.Conn, db *sql.DB, line irc.Line, arg, dst string, isPrivate bool) {
	if !isPrivate {
		conn.Notice(dst, "urls: URL querying must be done over private messages")
		return
	}

	arg = strings.TrimSpace(arg)

	if arg == "help" {
		conn.Notice(dst, fmt.Sprintf("urls: usage: %surls", command.CommandPrefix))
		conn.Notice(dst, "urls: Prints the last 5 URLs seen in all channels")
		return
	}

	sqlstr := "SELECT nick, src, timestamp, dst, url FROM seen GROUP BY url ORDER BY id DESC LIMIT ?"
	n := 5
	rows, err := db.Query(sqlstr, n)

	if err != nil {
		fmt.Println("error in !urls:", err)
		conn.Notice(dst, "urls: Internal error occurred")
		return
	}

	for rows.Next() {
		reply := dst
		var nick, src, dst, url string
		var timestamp time.Time
		if err = rows.Scan(&nick, &src, &timestamp, &dst, &url); err != nil {
			fmt.Println("error in !urls:", err)
			conn.Notice(dst, "urls: Internal error occurred")
			rows.Close()
			return
		}
		if nick == "" {
			nick = src
		}
		timestr := timestamp.Format("01-02 15:04:05")
		conn.Notice(reply, fmt.Sprintf("%s: %s: %s by %s", timestr, dst, url, nick))
		n -= 1
	}

	if n > 0 {
		conn.Notice(dst, "(no more URLs)")
	}
}
Ejemplo n.º 4
0
func processMatches(conn *irc.Conn, line irc.Line, dst string, matches []string) {
	if lines := channels[dst]; lines != nil {
		nick := line.Src.Nick
		src := matches[4]
		isSelf := false
		if src == "" {
			src = nick
			isSelf = true
		}
		if line, ok := lines[src]; ok {
			pat := matches[1]
			ignorecase, global := false, false
			if matches[3] != "" {
				for _, c := range matches[3] {
					switch c {
					case 'i':
						ignorecase = true
					case 'g':
						global = true
					}
				}
			}
			if ignorecase {
				pat = "(?i)" + pat
			}
			re, err := regexp.Compile(pat)
			if err != nil {
				fmt.Printf("sed: bad regexp %s: %v\n", pat, err)
				return
			}
			var result string
			if global {
				result = re.ReplaceAllString(line.Msg, matches[2])
			} else {
				indices := re.FindStringSubmatchIndex(line.Msg)
				if indices == nil {
					return
				}
				bresult := []byte(line.Msg[0:indices[0]])
				bresult = re.ExpandString(bresult, matches[2], line.Msg, indices)
				bresult = append(bresult, line.Msg[indices[1]:]...)
				result = string(bresult)
			}
			if result != line.Msg {
				if isSelf {
					line.Msg = result
					lines[src] = line
				}
				if line.Action {
					result = src + " " + result
				}
				infix := "meant"
				if !isSelf {
					infix = fmt.Sprintf("thinks %s meant", src)
				}
				conn.Notice(dst, fmt.Sprintf("%s %s: %s", nick, infix, result))
			} else {
				fmt.Printf("sed: non-matching regexp %s against nick %s\n", pat, src)
			}
		} else {
			fmt.Printf("sed: no history known for nick %s\n", src)
		}
	}
}
Ejemplo n.º 5
0
func h_PRIVMSG(conn *irc.Conn, line irc.Line) {
	fmt.Printf("[%s] %s> %s\n", line.Args[0], line.Src, line.Args[1])
	if line.Args[1] == "!quit" {
		conn.Quit("")
	}
}