Exemple #1
0
func loopCli(l *log.Logger, ircmgr *irc.IrcConnectionManager, evm event.EventManager) {
	help := func() {
		fmt.Println(`Commands:

exit		Quits IRC, if connected, and exits the program
debug		Toggles debug on or off`)
		if ircmgr.Status() != irc.Disconnected {
			fmt.Println("disconnect	Disconnect from IRC\n")
		} else {
			fmt.Println("connect		Connect to IRC\n")
		}
	}

	help()

	bin := bufio.NewReader(os.Stdin)
	for {
		str, _ := bin.ReadString('\n')
		evm.Trigger(InputEvent, map[string]interface{}{
			"Message": str,
		})
		switch {
		case str == "exit\n" || str == "quit\n":
			go ircmgr.Quit()
			time.Sleep(2 * time.Second)
			l.Println("Exiting")
			return

		case str == "debug\n":
			if ircmgr.Status() == irc.Disconnected {
				fmt.Println("Not connected")
			} else {
				conn := ircmgr.Connection()
				debugging := !conn.Debug
				conn.Debug = debugging
				conn.VerboseCallbackHandler = debugging
				if debugging {
					l.Println("Debug ENABLED")
				} else {
					l.Println("Debug DISABLED")
				}
			}

		case str == "connect\n" || str == "disconnect\n":
			if ircmgr.Status() != irc.Disconnected {
				fmt.Println("Disconnecting...")
				ircmgr.Quit()
			} else {
				fmt.Println("Connecting...")
				ircmgr.Connect()
			}

		default:
			fmt.Print("Unknown input. ")
			help()
		}
	}
}
Exemple #2
0
func newEventSource(evm event.EventManager) eventsource.EventSource {
	es := eventsource.New(nil, nil)

	var id int = -1
	evm.Bind(event.AllEvents, func(es eventsource.EventSource, ev event.Event) {
		id++
		data, _ := json.Marshal(ev.Data)
		go es.SendEventMessage(string(data), string(ev.Type), strconv.Itoa(id))
	})

	return es
}
Exemple #3
0
func newEventTracer(evm event.EventManager) *eventTracer {
	t := &eventTracer{25, make(map[event.EventType][]map[string]interface{}, 0)}
	evm.Bind(event.AllEvents, func(ev event.Event) {
		history, ok := t.data[ev.Type]
		if !ok {
			history = make([]map[string]interface{}, 0)
		}

		if len(history) >= t.limit {
			history = history[1:]
		}

		history = append(history, ev.Data)

		t.data[ev.Type] = history
	})

	return t
}
Exemple #4
0
func bindEvents(mgr *IrcConnectionManager, e event.EventManager) {
	mgr.conn.AddCallback("*", func(ev *ircevent.Event) {
		e.Trigger(IrcEvent, newEventData(ev))
		e.Trigger(event.EventType("irc."+ev.Code), newEventData(ev))
	})

	mgr.conn.AddCallback("001", func(ev *ircevent.Event) {
		fmt.Println("Connected")
		mgr.status = Connected
		e.Trigger(ConnectEvent, newEventData(ev))
	})

	mgr.conn.AddCallback("ERROR", func(ev *ircevent.Event) {
		if mgr.status != Disconnected {
			mgr.Quit()
		}
		e.Trigger(DisconnectEvent, newEventData(ev))
	})
}
Exemple #5
0
func triggerConnecting(e event.EventManager) {
	e.Trigger(ConnectingEvent, nil)
}