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