func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface{}) {
events := ps.Sub("presence","door","buttons")
+
+ defer func() {
+ if x := recover(); x != nil {
+ fmt.Printf("handleIncomingXMPPStanzas: run time panic: %v", x)
+ ps.Unsub(events, "presence","door","buttons")
+ close(xmpp_presence_events_chan_)
+ }
+ }()
+
var present, locked, shut bool = false, true, true
var who string
button_msg := "The button has been pressed ! Propably someone is bored and in need of company ! ;-)"
}
func main() {
- var err error
+ var xmpperr error
var bot *r3xmppbot.XmppBot
- bot, xmpp_presence_events_chan_, err = r3xmppbot.NewStartedBot(xmpp_login_.jid, xmpp_login_.pass, xmpp_bot_authstring_, xmpp_state_save_dir_, true)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer bot.StopBot()
+ bot, xmpp_presence_events_chan_, xmpperr = r3xmppbot.NewStartedBot(xmpp_login_.jid, xmpp_login_.pass, xmpp_bot_authstring_, xmpp_state_save_dir_, true)
newlinequeue := make(chan string, 1)
ps := pubsub.New(1)
defer ps.Shutdown()
//~ defer brn.Shutdown()
- ticker := time.NewTicker(time.Duration(7) * time.Minute)
go EventToWeb(ps)
- go EventToXMPP(ps, xmpp_presence_events_chan_)
- go ReadFromUSocket(presence_socket_path_, newlinequeue)
- for {
- select {
- case e := <-newlinequeue:
- ParseSocketInputLine(e, ps) //, brn)
- case <-ticker.C:
- ps.Pub(TimeTick{time.Now().Unix()}, "publishjson")
- }
- }
+ if xmpperr == nil {
+ defer bot.StopBot()
+ go EventToXMPP(ps, xmpp_presence_events_chan_)
+ } else {
+ fmt.Println(xmpperr)
+ fmt.Println("XMPP Bot disabled")
+ }
+ go ReadFromUSocket(presence_socket_path_, newlinequeue)
+ ticker := time.NewTicker(time.Duration(7) * time.Minute)
+
+ for {
+ select {
+ case e := <-newlinequeue:
+ ParseSocketInputLine(e, ps) //, brn)
+ case <-ticker.C:
+ ps.Pub(TimeTick{time.Now().Unix()}, "publishjson")
+ }
+ }
}
func (botdata *XmppBot) handleEventsforXMPP(xmppout chan <- xmpp.Stanza, presence_events <- chan interface{}, jabber_events <- chan JabberEvent) {
var last_status_msg *string
+ defer func() {
+ if x := recover(); x != nil {
+ log.Printf("handleEventsforXMPP: run time panic: %v", x)
+ }
+ }()
+
for {
select {
case pe := <-presence_events:
}
func (botdata *XmppBot) handleIncomingXMPPStanzas(xmppin <- chan xmpp.Stanza, xmppout chan<- xmpp.Stanza, jabber_events chan JabberEvent) {
+
+ defer func() {
+ if x := recover(); x != nil {
+ log.Printf("handleIncomingXMPPStanzas: run time panic: %v", x)
+ close(jabber_events)
+ }
+ }()
+
var incoming_stanza interface{}
for incoming_stanza = range xmppin {
switch stanza := incoming_stanza.(type) {