Beispiel #1
0
func (m *NotifyMod) Init(b *Bot, conn irc.SafeConn) error {
	m.notes = make(map[string][]Note)

	conn.AddHandler("PRIVMSG", func(con *irc.Conn, line irc.Line) {
		args := strings.SplitN(line.Args[1], " ", 3)

		if len(args) == 3 && args[0] == ".notify" {

			note := Note{
				from:    line.Src.String(),
				message: args[2],
				sent:    time.Now(),
			}

			m.notes[args[1]] = append(m.notes[args[1]], note)

			conn.Privmsg(getContext(line), fmt.Sprintf("added note to %q: %q", args[1], note))
		}
	})

	notify := func(conn *irc.Conn, line irc.Line) {
		m.NotifyIfQueued(conn, line)
	}

	conn.AddHandler("PRIVMSG", notify)
	conn.AddHandler("JOIN", notify)

	return nil
}
Beispiel #2
0
func (w *WtmpMod) Init(b *Bot, conn irc.SafeConn) error {
	conf := b.Config.Search("mod", "wtmp")
	w.file = conf.Search("file")
	w.last = time.Now()
	w.cron = cron.New()
	w.on = make(map[string]string)

	channel := conf.Search("channel")

	w.cron.AddFunc("@every 1m", func() {
		//log.Printf("checking wtmp %s...", w.file)

		wtmps, err := wtmp(w.file)
		if err != nil {
			log.Printf("error checking wtmp: %s", err)
			return
		}

		for _, wtr := range wtmps {
			if wtr.name != "" {
				w.on[wtr.line] = wtr.name
			}

			if w.last.Before(wtr.date) {
				log.Printf("wtmp: %q %q %q %q", wtr.line, wtr.name, wtr.host, wtr.date)

				in := "in "
				if wtr.name == "" {
					in = "out"
					wtr.name = w.on[wtr.line]
				}
				conn.Privmsg(channel, fmt.Sprintf("log%s: %s on %s", in, wtr.name, wtr.line))
			}
		}

		w.last = time.Now()
	})

	go func() {
		time.Sleep(10 * time.Second)
		w.cron.Start()
	}()

	log.Printf("wtmp module initialized with file %s", w.file)

	return nil
}
Beispiel #3
0
func (m *MailwatchMod) Init(b *Bot, conn irc.SafeConn) error {
	conf := b.Config.Search("mod", "mailwatch")
	dir := conf.Search("dir")
	channel := conf.Search("channel")

	if dir != "" {
		m.dir = maildir.Dir(dir)
		m.cronjob = cron.New()

		m.cronjob.AddFunc("@every 1m", func() {
			//log.Printf("checking mail %s...", m.dir)

			if newmail, err := m.dir.Unseen(); err != nil {
				conn.Privmsg(channel, fmt.Sprintf("maildir error: %s, err"))
			} else {
				l := len(newmail)

				if l > 0 {
					conn.Privmsg(channel, fmt.Sprintf("%d new mail:", l))

					for _, k := range newmail {
						hdr, err := m.dir.Header(k)
						if err != nil {
							conn.Privmsg(channel, fmt.Sprintf("maildir header error: %s", err))
						} else {
							conn.Privmsg(channel, fmt.Sprintf("from   : %s", hdr.Get("From")))
							conn.Privmsg(channel, fmt.Sprintf("subject: %s", hdr.Get("Subject")))
						}
					}
				}
			}
		})

		go func() {
			time.Sleep(10 * time.Second)
			m.cronjob.Start()
		}()

		log.Printf("mailwatch module initialized with dir: %s", dir)
	}

	return nil
}
Beispiel #4
0
func (g *AdventureMod) Init(b *Bot, conn irc.SafeConn) error {
	conf := b.Config.Search("mod", "adventure")
	channel := conf.Search("channel")

	go func() {
		var err error

		time.Sleep(5 * time.Second)

		for err == nil {
			if err = g.spawn(); err != nil {
				log.Printf("adventure spawn error: %s", err)
				break
			}

			for g.out.Scan() {
				line := g.out.Text()
				log.Printf("adventure: %s", line)
				conn.Privmsg(channel, line)
			}

			if err := g.out.Err(); err != nil {
				log.Printf("adventure read error: %s", err)
			}
		}
	}()

	conn.AddHandler("PRIVMSG", func(c *irc.Conn, l irc.Line) {
		args := strings.Split(l.Args[1], " ")
		if args[0] == ".a" {
			line := strings.Join(args[1:], " ")
			log.Printf("adventure: writing %q", line)
			if _, err := fmt.Fprintf(g.in, "%s\n", line); err != nil {
				log.Printf("adventure: error writing to subprocess: %s", err)
			}
		}
	})

	log.Printf("adventure module initialized with channel %s", channel)

	return nil
}