You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

  1. package main
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "log"
  6. "github.com/dghubble/go-twitter/twitter"
  7. "github.com/dghubble/oauth1"
  8. )
  9. //Bot stores the data from json botsConfig.json file
  10. type Bot struct {
  11. Title string `json:"title"`
  12. ConsumerKey string `json:"consumer_key"`
  13. ConsumerSecret string `json:"consumer_secret"`
  14. AccessTokenKey string `json:"access_token_key"`
  15. AccessTokenSecret string `json:"access_token_secret"`
  16. Client *twitter.Client
  17. SinceTweeted int64 `json:"sincetweeted"`
  18. Blocked bool `json:"blocked"`
  19. SinceBlocked int64 `json:"sinceblocked"`
  20. }
  21. var botnet []Bot
  22. var keywords []string
  23. var replies []string
  24. func readConfigTokensAndConnect() {
  25. file, err := ioutil.ReadFile("botsConfig.json")
  26. check(err)
  27. content := string(file)
  28. json.Unmarshal([]byte(content), &botnet)
  29. log.Println("botnetConfig.json read comlete")
  30. log.Print("connecting to twitter api")
  31. for k, _ := range botnet {
  32. configu := oauth1.NewConfig(botnet[k].ConsumerKey, botnet[k].ConsumerSecret)
  33. token := oauth1.NewToken(botnet[k].AccessTokenKey, botnet[k].AccessTokenSecret)
  34. httpClient := configu.Client(oauth1.NoContext, token)
  35. // twitter client
  36. client := twitter.NewClient(httpClient)
  37. botnet[k].Client = client
  38. botnet[k].Blocked = false
  39. }
  40. log.Println("connection successful")
  41. }
  42. func readKeywordsConfig() {
  43. file, err := ioutil.ReadFile("keywordsConfig.json")
  44. check(err)
  45. content := string(file)
  46. json.Unmarshal([]byte(content), &keywords)
  47. }
  48. func readRepliesConfig() {
  49. file, err := ioutil.ReadFile("repliesConfig.json")
  50. check(err)
  51. content := string(file)
  52. json.Unmarshal([]byte(content), &replies)
  53. }