aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-16 17:53:31 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-16 17:53:31 +0100
commit225fc84f097aa615239df6deece647a19794234a (patch)
tree14ce2ea0a61993c56da21f8f0c3f157177717bbb /main.go
parentb7f0776784b6e5fe0f0a028c2913f58e995afa73 (diff)
downloadeasybridge-225fc84f097aa615239df6deece647a19794234a.tar.gz
easybridge-225fc84f097aa615239df6deece647a19794234a.zip
Basic XMPP
Diffstat (limited to 'main.go')
-rw-r--r--main.go66
1 files changed, 59 insertions, 7 deletions
diff --git a/main.go b/main.go
index f2b5b31..9c5c015 100644
--- a/main.go
+++ b/main.go
@@ -8,6 +8,7 @@ import (
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/irc"
+ "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/xmpp"
)
type TmpHandler struct{
@@ -35,17 +36,17 @@ func (h *TmpHandler) Event(e *connector.Event) {
} 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 {
- fmt.Printf("C E Message %s %s %s\n", e.Author, e.Room, e.Message)
- if strings.Contains(e.Message, "ezbrexit") {
- fmt.Printf("we have to exit")
+ 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")
h.exit <- true
}
} else if e.Type == connector.EVENT_ACTION {
- fmt.Printf("C E Action %s %s %s\n", e.Author, e.Room, e.Message)
+ fmt.Printf("C E Action %s %s %s\n", e.Author, e.Room, e.Text)
}
}
-func main() {
+func testIrc() {
irc := &irc.IRC{}
h := TmpHandler{
exit: make(chan bool),
@@ -70,7 +71,7 @@ func main() {
err = irc.Send(&connector.Event{
Room: connector.RoomID("#ezbrtest@irc.ulminfo.fr"),
Type: connector.EVENT_MESSAGE,
- Message: "EZBR TEST",
+ Text: "EZBR TEST",
})
if err != nil {
log.Fatalf("Send: %s", err)
@@ -80,7 +81,7 @@ func main() {
err = irc.Send(&connector.Event{
Recipient: connector.UserID("lx@irc.ulminfo.fr"),
Type: connector.EVENT_MESSAGE,
- Message: "EZBR TEST direct message lol",
+ Text: "EZBR TEST direct message lol",
})
if err != nil {
log.Fatalf("Send: %s", err)
@@ -91,3 +92,54 @@ func main() {
fmt.Printf("got exit signal\n")
irc.Close()
}
+
+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()
+}