go-ricochet/examples/echobot/main.go

37 lines
1005 B
Go
Raw Normal View History

2016-01-02 02:08:28 +00:00
package main
import (
"github.com/s-rah/go-ricochet"
"log"
2016-01-02 02:08:28 +00:00
)
type EchoBotService struct {
goricochet.StandardRicochetService
}
2016-01-02 02:08:28 +00:00
// Always Accept Contact Requests
func (ts *EchoBotService) IsKnownContact(hostname string) bool {
return true
}
2016-01-02 02:08:28 +00:00
func (ts *EchoBotService) OnContactRequest(oc *goricochet.OpenConnection, channelID int32, nick string, message string) {
ts.StandardRicochetService.OnContactRequest(oc, channelID, nick, message)
oc.AckContactRequestOnResponse(channelID, "Accepted")
oc.CloseChannel(channelID)
}
2016-01-02 02:08:28 +00:00
func (ebs *EchoBotService) OnChatMessage(oc *goricochet.OpenConnection, channelID int32, messageId int32, message string) {
log.Printf("Received Message from %s: %s", oc.OtherHostname, message)
oc.AckChatMessage(channelID, messageId)
if oc.GetChannelType(6) == "none" {
oc.OpenChatChannel(6)
2016-01-02 02:08:28 +00:00
}
oc.SendMessage(6, message)
}
func main() {
ricochetService := new(EchoBotService)
ricochetService.Init("./private_key")
ricochetService.Listen(ricochetService, 12345)
2016-01-02 02:08:28 +00:00
}