2016-01-02 02:08:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/s-rah/go-ricochet"
|
2016-06-27 01:56:23 +00:00
|
|
|
"log"
|
2016-01-02 02:08:28 +00:00
|
|
|
)
|
|
|
|
|
2016-11-08 23:12:50 +00:00
|
|
|
// EchoBotService is an example service which simply echoes back what a client
|
|
|
|
// sends it.
|
2016-02-29 00:18:25 +00:00
|
|
|
type EchoBotService struct {
|
2016-06-27 01:56:23 +00:00
|
|
|
goricochet.StandardRicochetService
|
2016-02-29 00:18:25 +00:00
|
|
|
}
|
2016-01-02 02:08:28 +00:00
|
|
|
|
2016-11-08 23:12:50 +00:00
|
|
|
// IsKnownContact is configured to always accept Contact Requests
|
|
|
|
func (ebs *EchoBotService) IsKnownContact(hostname string) bool {
|
2016-06-27 01:56:23 +00:00
|
|
|
return true
|
2016-02-29 00:18:25 +00:00
|
|
|
}
|
2016-01-02 02:08:28 +00:00
|
|
|
|
2016-11-08 23:12:50 +00:00
|
|
|
// OnContactRequest - we always accept new contact request.
|
|
|
|
func (ebs *EchoBotService) OnContactRequest(oc *goricochet.OpenConnection, channelID int32, nick string, message string) {
|
2016-06-27 01:56:23 +00:00
|
|
|
ts.StandardRicochetService.OnContactRequest(oc, channelID, nick, message)
|
|
|
|
oc.AckContactRequestOnResponse(channelID, "Accepted")
|
|
|
|
oc.CloseChannel(channelID)
|
2016-02-29 00:18:25 +00:00
|
|
|
}
|
2016-01-02 02:08:28 +00:00
|
|
|
|
2016-11-08 23:12:50 +00:00
|
|
|
// OnChatMessage we acknowledge the message, grab the message content and send it back - opening
|
|
|
|
// a new channel if necessary.
|
|
|
|
func (ebs *EchoBotService) OnChatMessage(oc *goricochet.OpenConnection, channelID int32, messageID int32, message string) {
|
2016-06-27 01:56:23 +00:00
|
|
|
log.Printf("Received Message from %s: %s", oc.OtherHostname, message)
|
2016-11-08 23:12:50 +00:00
|
|
|
oc.AckChatMessage(channelID, messageID)
|
2016-06-27 01:56:23 +00:00
|
|
|
if oc.GetChannelType(6) == "none" {
|
|
|
|
oc.OpenChatChannel(6)
|
2016-01-02 02:08:28 +00:00
|
|
|
}
|
2016-06-27 01:56:23 +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
|
|
|
}
|