-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.go
43 lines (38 loc) · 902 Bytes
/
bot.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
// go telegram bot to check remote server
// to install telebot, run: go get github.com/tucnak/telebot
package main
import (
"time"
"github.com/tucnak/telebot"
"log"
"os/exec"
)
func cmd(command string)string{
var (
cmdOut []byte
err error
)
cmdOut, err = exec.Command(command).Output();
if err != nil{
log.Fatal(err)
}
return string(cmdOut)
}
func main() {
bot, err := telebot.NewBot(botToken)
if err != nil {
return
}
messages := make(chan telebot.Message)
bot.Listen(messages, 1*time.Second)
for message := range messages {
if message.Text == "stat" {
uptime := cmd("uptime")
bot.SendMessage(message.Chat, uptime, nil)
}
if message.Text == "dir"{
ls := cmd("ls")
bot.SendMessage(message.Chat, ls, nil)
}
}
}