cwtchbot/cmd/echobot/main.go

45 lines
1.4 KiB
Go
Raw Permalink Normal View History

2020-11-09 21:45:13 +00:00
package main
2019-10-28 02:09:02 +00:00
import (
"cwtch.im/cwtch/event"
2020-11-09 21:45:13 +00:00
"cwtch.im/cwtch/model"
"cwtch.im/cwtch/model/attr"
"cwtch.im/cwtch/model/constants"
"fmt"
2019-10-28 02:09:02 +00:00
"git.openprivacy.ca/sarah/cwtchbot"
2023-02-07 21:42:08 +00:00
_ "github.com/mutecomm/go-sqlcipher/v4"
2019-10-28 02:09:02 +00:00
"os/user"
"path"
)
func main() {
user, _ := user.Current()
cwtchbot := bot.NewCwtchBot(path.Join(user.HomeDir, "/.echobot/"), "echobot")
cwtchbot.Launch()
// Set Some Profile Information
cwtchbot.Peer.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name, "echobot2")
cwtchbot.Peer.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.ProfileAttribute1, "A Cwtchbot Echobot")
fmt.Printf("echobot address: %v\n", cwtchbot.Peer.GetOnion())
2023-02-07 21:42:08 +00:00
2019-10-28 02:09:02 +00:00
for {
message := cwtchbot.Queue.Next()
2023-02-07 21:42:08 +00:00
cid, _ := cwtchbot.Peer.FetchConversationInfo(message.Data[event.RemotePeer])
2019-10-28 02:09:02 +00:00
switch message.EventType {
2020-11-09 21:45:13 +00:00
case event.NewMessageFromPeer:
msg := cwtchbot.UnpackMessage(message.Data[event.Data])
fmt.Printf("Message: %v\n", msg)
reply := string(cwtchbot.PackMessage(msg.Overlay, msg.Data))
2023-02-07 21:42:08 +00:00
cwtchbot.Peer.SendMessage(cid.ID, reply)
case event.ContactCreated:
fmt.Printf("Auto approving stranger %v %v\n", cid, message.Data[event.RemotePeer])
// accept the stranger as a new contact
cwtchbot.Peer.AcceptConversation(cid.ID)
// Send Hello...
reply := string(cwtchbot.PackMessage(model.OverlayChat, "Hello!"))
cwtchbot.Peer.SendMessage(cid.ID, reply)
2019-10-28 02:09:02 +00:00
}
}
}