func (s *t) seen(conn *irc.Connection, msg *irc.Message) { if msg.Command != "PRIVMSG" { return } fs := flag.NewFlagSet("seen", flag.ContinueOnError) fs.Usage = func() { conn.Privmsg(*msg.Target(), "usage: seen <nick>") } parts := msg.Split() if fs.Parse(parts[1:]) != nil { return } if fs.NArg() == 0 { fs.Usage() return } target := fs.Arg(0) stmt, err := s.db.Prepare( fmt.Sprintf("SELECT datetime, message FROM %s WHERE nick LIKE ? ORDER BY datetime desc LIMIT 1", tableName)) defer stmt.Finalize() if err != nil { log.Printf("seen.seen(): sql error: %s", err) return } stmt.Exec(target) found := stmt.Next() if found { var datetime int64 var rawmessage string stmt.Scan(&datetime, &rawmessage) t := time.SecondsToLocalTime(datetime) str := t.Format(time.UnixDate) conn.Privmsg(*msg.Target(), str+": "+rawmessage) } else { conn.Privmsg(*msg.Target(), "I haven't seen "+target) } }
func (s *t) lastUrl(conn *irc.Connection, msg *irc.Message) { if msg.Command != "PRIVMSG" { return } var nFlag int var contextFlag string var fromFlag string var contains string = "" fs := flag.NewFlagSet("urls", flag.ContinueOnError) fs.IntVar(&nFlag, "n", 1, "number of results") fs.StringVar(&fromFlag, "from", "", "sender's nick contains string") fs.StringVar(&contextFlag, "context", "", "context of the message") fs.Usage = func() { conn.Privmsg(*msg.Target(), "usage: url [-from=<nick>] [-n=<number to display>] [-context=<string>] [<substring>]") } parts := msg.Split() if fs.Parse(parts[1:]) != nil { return } if fs.NArg() > 0 { contains = fs.Arg(0) } query := fmt.Sprintf( "SELECT url FROM %s WHERE nick LIKE ? AND url LIKE ? AND rawmessage LIKE ? ORDER BY datetime DESC LIMIT ?", tableName) stmt, err := s.db.Prepare(query) defer stmt.Finalize() if err != nil { conn.Privmsg(*msg.Target(), "sql error") return } stmt.Exec("%"+fromFlag+"%", "%"+contains+"%", "%"+contextFlag+"%", nFlag) more := stmt.Next() var output string if !more { output = "no URL matches those criterias" } left := maxResponses for more && left > 0 { var url string stmt.Scan(&url) output += url + " " more = stmt.Next() left-- } conn.Privmsg(*msg.Target(), output) }
func snarf(conn *irc.Connection, msg *irc.Message) { if msg.Command == "PING" { conn.Pong(*msg.LastParameter()) } }
func snarf(conn *irc.Connection, msg *irc.Message) { if msg.Command == "376" && config.Password != "" { conn.Privmsg("nickserv", "identify "+config.Password) } }