arnaucube
arnaucube/goNmapTelegramBotPublic Self-hosted repository
goNmapTelegramBot/telegramBot.go
telegramBot.goRaw
 1package main
 2
 3import (
 4	"fmt"
 5	"log"
 6
 7	"gopkg.in/telegram-bot-api.v4"
 8)
 9
10func telegramBot() {
11	bot, err := tgbotapi.NewBotAPI(config.TelegramBotToken)
12	if err != nil {
13		log.Panic(err)
14	}
15
16	//bot.Debug = true
17	//log.Printf("Authorized on account %s", bot.Self.UserName)
18
19	u := tgbotapi.NewUpdate(0)
20	u.Timeout = 60
21
22	updates, err := bot.GetUpdatesChan(u)
23
24	for update := range updates {
25		if update.Message == nil {
26			continue
27		}
28
29		//log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
30		fmt.Println("new ip to scan: " + update.Message.Text)
31		var result string
32		ok := checkIp(update.Message.Text)
33		if update.Message.Text == "/start" {
34			result = "welcome to nmap telegram bot, written in Go lang"
35		} else {
36
37			if ok {
38				result = nmap(update.Message.Text)
39			} else {
40				result = "ip not valid"
41			}
42		}
43
44		msg := tgbotapi.NewMessage(update.Message.Chat.ID, result)
45		msg.ReplyToMessageID = update.Message.MessageID
46
47		bot.Send(msg)
48	}
49}