aboutsummaryrefslogtreecommitdiff
path: root/test/main.go
blob: 1baa9df77313d33959005613c954d97146b16c9f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main

import (
	"strings"
	"time"
	"fmt"

	log "github.com/sirupsen/logrus"

	"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
	"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/irc"
	"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/xmpp"
)

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 {
		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.Text)
	}
}

func testIrc() {
	irc := &irc.IRC{}
	h := TmpHandler{
		exit: make(chan bool),
	}
	irc.SetHandler(&h)

	err := irc.Configure(connector.Configuration{
		"server": "irc.ulminfo.fr",
		"port": "6666",
		"ssl": "true",
		"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,
		Text: "EZBR TEST",
	})
	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,
		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")
	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()
}