This repository was archived by the owner on Apr 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
118 lines (101 loc) · 3.38 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"os"
"strconv"
"github.com/pkg/errors"
)
type Config struct {
DatabaseUrl string
TwitterCookie string
XCsrfToken string
TelegramBotToken string
ChannelChatID int64
GroupChatID int64
OwnerID int64
MoeIslandChannelID int64
MoeIslandGroupID int64
PopularTweetFactor int
PopularRetweetFactor int
BotApiUrl string
}
func loadConfig() (*Config, error) {
databaseUrl := os.Getenv("DATABASE_URL")
if databaseUrl == "" {
return nil, errors.New("DATABASE_URL is not set")
}
twitterCookie := os.Getenv("TWITTER_COOKIE")
if twitterCookie == "" {
return nil, errors.New("TWITTER_COOKIE is not set")
}
xcsrfToken := os.Getenv("XCSRF_TOKEN")
if xcsrfToken == "" {
return nil, errors.New("XCSRF_TOKEN is not set")
}
telegramBotToken := os.Getenv("TELEGRAM_BOT_TOKEN")
if telegramBotToken == "" {
return nil, errors.New("TELEGRAM_BOT_TOKEN is not set")
}
channelChatIDStr := os.Getenv("CHANNEL_CHAT_ID")
if channelChatIDStr == "" {
return nil, errors.New("CHANNEL_CHAT_ID is not set")
}
channelChatID, err := strconv.ParseInt(channelChatIDStr, 10, 64)
if channelChatID == 0 || err != nil {
return nil, errors.Wrap(err, "CHANNEL_CHAT_ID is not a number")
}
groupChatIDStr := os.Getenv("GROUP_CHAT_ID")
if groupChatIDStr == "" {
return nil, errors.New("GROUP_CHAT_ID is not set")
}
groupChatID, err := strconv.ParseInt(groupChatIDStr, 10, 64)
if groupChatID == 0 || err != nil {
return nil, errors.Wrap(err, "GROUP_CHAT_ID is not a number")
}
ownerIDStr := os.Getenv("OWNER_ID")
if ownerIDStr == "" {
return nil, errors.New("OWNER_ID is not set")
}
ownerID, err := strconv.ParseInt(ownerIDStr, 10, 64)
if ownerID == 0 || err != nil {
return nil, errors.Wrap(err, "OWNER_ID is not a number")
}
moeIslandChannelID, err := strconv.ParseInt(os.Getenv("MOE_ISLAND_CHANNEL_ID"), 10, 64)
if moeIslandChannelID == 0 || err != nil {
return nil, errors.Wrap(err, "MOE_ISLAND_CHANNEL_ID is not a number")
}
moeIslandGroupID, err := strconv.ParseInt(os.Getenv("MOE_ISLAND_GROUP_ID"), 10, 64)
if moeIslandGroupID == 0 || err != nil {
return nil, errors.Wrap(err, "MOE_ISLAND_GROUP_ID is not a number")
}
popularTweetFactorStr := os.Getenv("POPULAR_TWEET_FACTOR")
if popularTweetFactorStr == "" {
return nil, errors.New("POPULAR_TWEET_FACTOR is not set")
}
popularTweetFactor, err := strconv.Atoi(popularTweetFactorStr)
if popularTweetFactor == 0 || err != nil {
return nil, errors.Wrap(err, "POPULAR_TWEET_FACTOR is not a number")
}
popularRetweetFactorStr := os.Getenv("POPULAR_RETWEET_FACTOR")
if popularRetweetFactorStr == "" {
return nil, errors.New("POPULAR_RETWEET_FACTOR is not set")
}
popularRetweetFactor, err := strconv.Atoi(popularRetweetFactorStr)
if popularRetweetFactor == 0 || err != nil {
return nil, errors.Wrap(err, "POPULAR_RETWEET_FACTOR is not a number")
}
botApiUrl := os.Getenv("BOT_API_URL")
return &Config{
DatabaseUrl: databaseUrl,
TwitterCookie: twitterCookie,
XCsrfToken: xcsrfToken,
TelegramBotToken: telegramBotToken,
ChannelChatID: channelChatID,
GroupChatID: groupChatID,
OwnerID: ownerID,
MoeIslandChannelID: moeIslandChannelID,
MoeIslandGroupID: moeIslandGroupID,
PopularTweetFactor: popularTweetFactor,
PopularRetweetFactor: popularRetweetFactor,
BotApiUrl: botApiUrl,
}, nil
}