-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathechobot.go
51 lines (41 loc) · 1.33 KB
/
echobot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"github.com/deltachat-bot/deltabot-cli-go/botcli"
"github.com/deltachat/deltachat-rpc-client-go/deltachat"
"github.com/spf13/cobra"
)
// echo back received text
func echo(bot *deltachat.Bot, accId deltachat.AccountId, msgId deltachat.MsgId) {
msg, _ := bot.Rpc.GetMessage(accId, msgId)
if msg.FromId > deltachat.ContactLastSpecial && msg.Text != "" {
bot.Rpc.MiscSendTextMessage(accId, msg.ChatId, msg.Text) //nolint:errcheck
}
}
func onInfoCmd(cli *botcli.BotCli, bot *deltachat.Bot, cmd *cobra.Command, args []string) {
sysinfo, _ := bot.Rpc.GetSystemInfo()
for key, val := range sysinfo {
fmt.Printf("%v=%#v\n", key, val)
}
}
func onBotInit(cli *botcli.BotCli, bot *deltachat.Bot, cmd *cobra.Command, args []string) {
bot.OnNewMsg(echo)
}
func onBotStart(cli *botcli.BotCli, bot *deltachat.Bot, cmd *cobra.Command, args []string) {
cli.Logger.Info("OnBotStart event triggered: bot is about to start!")
}
func main() {
cli := botcli.New("echobot")
// add an "info" CLI subcommand as example
infoCmd := &cobra.Command{
Use: "info",
Short: "display information about the Delta Chat core running in this system",
Args: cobra.ExactArgs(0),
}
cli.AddCommand(infoCmd, onInfoCmd)
cli.OnBotInit(onBotInit)
cli.OnBotStart(onBotStart)
if err := cli.Start(); err != nil {
cli.Logger.Error(err)
}
}