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-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-06-27 01:56:23 +00:00
|
|
|
// Always Accept Contact Requests
|
|
|
|
func (ts *EchoBotService) IsKnownContact(hostname string) bool {
|
|
|
|
return true
|
2016-02-29 00:18:25 +00:00
|
|
|
}
|
2016-01-02 02:08:28 +00:00
|
|
|
|
2016-06-27 01:56:23 +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-02-29 00:18:25 +00:00
|
|
|
}
|
2016-01-02 02:08:28 +00:00
|
|
|
|
2016-06-27 01:56:23 +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
|
|
|
}
|
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
|
|
|
}
|