Skip to content

Instantly share code, notes, and snippets.

@PixiBixi
Created August 22, 2016 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PixiBixi/2c7e14924b71595ac1744c688ba1ca6a to your computer and use it in GitHub Desktop.
Save PixiBixi/2c7e14924b71595ac1744c688ba1ca6a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"net"
"strings"
"time"
"github.com/tatsushid/go-fastping"
"github.com/tucnak/telebot"
)
func main() {
bot, err := telebot.NewBot("251435116:AAGZ94QdqmGlfRRQLqRQYz8MUMMpRD5THVw")
if err != nil {
log.Fatalln(err)
}
messages := make(chan telebot.Message)
bot.Listen(messages, 1*time.Second)
for message := range messages {
if message.Text == "!date" {
t := time.Now()
str := t.Format(time.ANSIC)
bot.SendMessage(message.Chat, fmt.Sprintf("Tiens grokon, vla la date: %s", str), nil)
}
if strings.HasPrefix(message.Text, "!ping") {
pts := strings.Split(message.Text, " ")
if len(pts) < 2 {
return
}
p := fastping.NewPinger()
ra, err := net.ResolveIPAddr("IP4:icmp", pts[1])
if err != nil {
fmt.Println(err)
return
}
p.AddIPAddr(ra)
p.OnRecv = func(addr *net.IPAddr, rtt time.Duration) {
bot.SendMessage(message.Chat, fmt.Sprintf("IP Addr: %s receive, RTT: %v\n", addr.String(), rtt), nil)
}
err = p.Run()
if err != nil {
fmt.Println(err)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment