2020-02-16 15:26:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
|
|
|
|
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/irc"
|
2020-02-16 16:53:31 +00:00
|
|
|
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/xmpp"
|
2020-02-16 15:26:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type TmpHandler struct{
|
|
|
|
exit chan bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *TmpHandler) Joined(roomId connector.RoomID) {
|
|
|
|
fmt.Printf("C Joined: %s\n", roomId)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *TmpHandler) Left(roomId connector.RoomID) {
|
|
|
|
fmt.Printf("C Joined: %s\n", roomId)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *TmpHandler) UserInfoUpdated(u connector.UserID, i *connector.UserInfo) {
|
|
|
|
fmt.Printf("C User info: %s => %#v\n", u, i)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *TmpHandler) RoomInfoUpdated(r connector.RoomID, i *connector.RoomInfo) {
|
|
|
|
fmt.Printf("C Room info: %s => %#v\n", r, i)
|
|
|
|
}
|
|
|
|
func (h *TmpHandler) Event(e *connector.Event) {
|
|
|
|
if e.Type == connector.EVENT_JOIN {
|
|
|
|
fmt.Printf("C E Join %s %s\n", e.Author, e.Room)
|
|
|
|
} else if e.Type == connector.EVENT_LEAVE {
|
|
|
|
fmt.Printf("C E Leave %s %s\n", e.Author, e.Room)
|
|
|
|
} else if e.Type == connector.EVENT_MESSAGE {
|
2020-02-16 16:53:31 +00:00
|
|
|
fmt.Printf("C E Message %s %s %s\n", e.Author, e.Room, e.Text)
|
|
|
|
if strings.Contains(e.Text, "ezbrexit") {
|
|
|
|
fmt.Printf("we have to exit\n")
|
2020-02-16 15:26:55 +00:00
|
|
|
h.exit <- true
|
|
|
|
}
|
|
|
|
} else if e.Type == connector.EVENT_ACTION {
|
2020-02-16 16:53:31 +00:00
|
|
|
fmt.Printf("C E Action %s %s %s\n", e.Author, e.Room, e.Text)
|
2020-02-16 15:26:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-16 16:53:31 +00:00
|
|
|
func testIrc() {
|
2020-02-16 15:26:55 +00:00
|
|
|
irc := &irc.IRC{}
|
|
|
|
h := TmpHandler{
|
|
|
|
exit: make(chan bool),
|
|
|
|
}
|
|
|
|
irc.SetHandler(&h)
|
|
|
|
|
|
|
|
err := irc.Configure(connector.Configuration{
|
|
|
|
"server": "irc.ulminfo.fr",
|
|
|
|
"port": "6666",
|
|
|
|
"nick": "ezbr",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Connect: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = irc.Join(connector.RoomID("#ezbrtest@irc.ulminfo.fr"))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Join: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Duration(1)*time.Second)
|
|
|
|
err = irc.Send(&connector.Event{
|
|
|
|
Room: connector.RoomID("#ezbrtest@irc.ulminfo.fr"),
|
|
|
|
Type: connector.EVENT_MESSAGE,
|
2020-02-16 16:53:31 +00:00
|
|
|
Text: "EZBR TEST",
|
2020-02-16 15:26:55 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Send: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Duration(1)*time.Second)
|
|
|
|
err = irc.Send(&connector.Event{
|
|
|
|
Recipient: connector.UserID("lx@irc.ulminfo.fr"),
|
|
|
|
Type: connector.EVENT_MESSAGE,
|
2020-02-16 16:53:31 +00:00
|
|
|
Text: "EZBR TEST direct message lol",
|
2020-02-16 15:26:55 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Send: %s", err)
|
|
|
|
}
|
|
|
|
|
2020-02-16 15:41:13 +00:00
|
|
|
fmt.Printf("waiting exit signal\n")
|
2020-02-16 15:26:55 +00:00
|
|
|
<-h.exit
|
2020-02-16 15:41:13 +00:00
|
|
|
fmt.Printf("got exit signal\n")
|
2020-02-16 15:26:55 +00:00
|
|
|
irc.Close()
|
|
|
|
}
|
2020-02-16 16:53:31 +00:00
|
|
|
|
|
|
|
func testXmpp() {
|
|
|
|
xmpp := &xmpp.XMPP{}
|
|
|
|
h := TmpHandler{
|
|
|
|
exit: make(chan bool),
|
|
|
|
}
|
|
|
|
xmpp.SetHandler(&h)
|
|
|
|
|
|
|
|
err := xmpp.Configure(connector.Configuration{
|
|
|
|
"server": "jabber.fr",
|
|
|
|
"jid": "ezbr@jabber.fr",
|
|
|
|
"password": "azerty1234",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Connect: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = xmpp.Join(connector.RoomID("ezbrtest@muc.linkmauve.fr"))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Join: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Duration(1)*time.Second)
|
|
|
|
err = xmpp.Send(&connector.Event{
|
|
|
|
Room: connector.RoomID("ezbrtest@muc.linkmauve.fr"),
|
|
|
|
Type: connector.EVENT_MESSAGE,
|
|
|
|
Text: "EZBR TEST",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Send: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Duration(1)*time.Second)
|
|
|
|
err = xmpp.Send(&connector.Event{
|
|
|
|
Recipient: connector.UserID("alexis211@jabber.fr"),
|
|
|
|
Type: connector.EVENT_MESSAGE,
|
|
|
|
Text: "EZBR TEST direct message lol",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Send: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("waiting exit signal\n")
|
|
|
|
<-h.exit
|
|
|
|
fmt.Printf("got exit signal\n")
|
|
|
|
xmpp.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
testXmpp()
|
|
|
|
}
|