aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go93
1 files changed, 93 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..47d2cec
--- /dev/null
+++ b/main.go
@@ -0,0 +1,93 @@
+package main
+
+import (
+ "strings"
+ "time"
+ "fmt"
+ "log"
+
+ "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
+ "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/irc"
+)
+
+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.Message)
+ if strings.Contains(e.Message, "ezbrexit") {
+ fmt.Printf("we have to exit")
+ 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)
+ }
+}
+
+func main() {
+ 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,
+ Message: "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,
+ Message: "EZBR TEST direct message lol",
+ })
+ if err != nil {
+ log.Fatalf("Send: %s", err)
+ }
+
+ fmt.Printf("waiting exit signal")
+ <-h.exit
+ fmt.Printf("got exit signal")
+ irc.Close()
+}