Advertisement
Guest User

functions.go

a guest
Nov 6th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.03 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.         "fmt"
  5.         "net/http"
  6.         "strconv"
  7.         "strings"
  8.         "io/ioutil"
  9.         "regexp"
  10. )
  11.  
  12. func sendMessage(userid int, message string) {
  13.         modmsg := strings.Replace(message, " ", "%20", -1)
  14.         _, err := http.Get("https://api.telegram.org/bot" + token + "/sendmessage?&chat_id=" + strconv.Itoa(userid) + "&text=" + modmsg)
  15.         if err != nil {
  16.                 fmt.Println("[ERROR]Unable to access API")
  17.         }
  18.         fmt.Printf("[BOT -> %d] %s\n", userid, message)
  19. }
  20.  
  21. func interpret(chatid int, message string) {
  22.         r, _ := regexp.Compile(`^([a-zA-Zа-яёА-ЯЁ0-9 ]*)\/w`)
  23.         if r.MatchString(message) {
  24.                 sendMessage(chatid, r.FindStringSubmatch(message)[1] + " - ачивмент анлокед")
  25.         }
  26.  
  27.         switch message {  //This is here for later use if needed.
  28.         case "/start":
  29.                 sendMessage(chatid, "Welcome to Telegram ...!")
  30.         case "/sp":
  31.                 sendMessage(chatid, "Текст")
  32.         case "/about":
  33.                 sendMessage(chatid, "текст2")
  34.         case "/social":
  35.                 sendMessage(chatid, "1")
  36.                 sendMessage(chatid, "2")
  37.                 sendMessage(chatid, "3")
  38.                 sendMessage(chatid, "4")
  39.                 sendMessage(chatid, "5")
  40.                 sendMessage(chatid, "6")
  41.         case "/gs":
  42.                 sendMessage(chatid, "12")
  43.                 sendMessage(chatid, "13")
  44.                 sendMessage(chatid, "14")
  45.                 sendMessage(chatid, "15")
  46.                 sendMessage(chatid, "16")
  47.         case "/zzz":
  48.                 sendMessage(chatid, "17")
  49.         case "/nuke":
  50.                 body, err := http.Get("https://api.twitch.tv/kraken/streams/nuke73")
  51.                 if err != nil {
  52.                         sendMessage(chatid, "Cannot retrieve data of streamer")
  53.                 }
  54.         output, _ := ioutil.ReadAll(body.Body)
  55.                 sendMessage(chatid, twitchDecode(output))
  56.         default:
  57.         }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement