Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "log"
- "net/http"
- "github.com/BurntSushi/toml"
- "github.com/fatih/color"
- "github.com/go-chi/chi"
- "github.com/go-chi/chi/middleware"
- tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
- )
- var (
- yellow = color.New(color.FgYellow).SprintFunc()
- red = color.New(color.FgRed).SprintFunc()
- g = color.New(color.FgGreen, color.Bold).SprintFunc()
- b = color.New(color.FgBlue, color.Bold).SprintFunc()
- )
- func bot(token string) {
- bot, err := tgbotapi.NewBotAPI(token)
- if err != nil {
- log.Panic(err)
- }
- bot.Debug = false
- log.Printf("Authorized on account %s", bot.Self.UserName)
- u := tgbotapi.NewUpdate(0)
- u.Timeout = 60
- updates, err := bot.GetUpdatesChan(u)
- for update := range updates {
- if update.Message == nil { // ignore any non-Message Updates
- continue
- }
- fmt.Printf("%s %s %s %s\n", red("message>"), yellow(update.Message.Chat.ID, ">"), b(update.Message.From.UserName+">"), g(update.Message.Text))
- msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
- msg.ReplyToMessageID = update.Message.MessageID
- bot.Send(msg)
- }
- }
- var token string
- func edit(w http.ResponseWriter, r *http.Request) {
- token = r.FormValue("token")
- fmt.Printf("%s %s %s\n", yellow("edit>"), b("token>"), g(token))
- w.Write([]byte(token))
- }
- type tomlConfig struct {
- Token string
- }
- func main() {
- var config tomlConfig
- if _, err := toml.DecodeFile("token.toml", &config); err != nil {
- fmt.Println(err)
- }
- token = config.Token
- fmt.Printf("%s %s\n", yellow("token:"), g(token))
- go bot(token)
- r := chi.NewRouter()
- r.Use(middleware.Logger)
- r.Get("/edit", edit) //http://localhost:3000/edit?token=1234567:fdsferfsqqqweeasfweriopj
- http.ListenAndServe(":3000", r)
- }
RAW Paste Data