forked from indes/flowerss-bot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
130 lines (108 loc) · 2.87 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
119
120
121
122
123
124
125
126
127
128
129
130
package config
import (
"fmt"
"text/template"
"github.com/spf13/viper"
tb "gopkg.in/tucnak/telebot.v2"
)
type RunType string
var (
version = "dev"
commit = "none"
date = "unknown"
ProjectName string = "flowerss"
BotToken string
Socks5 string
TelegraphToken []string
TelegraphAccountName string
TelegraphAuthorName string = "flowerss-bot"
TelegraphAuthorURL string
// EnableTelegraph 是否启用telegraph
EnableTelegraph bool = false
PreviewText int = 0
DisableWebPagePreview bool = false
Mysql MysqlConfig
SQLitePath string
EnableMysql bool = false
// UpdateInterval rss抓取间隔
UpdateInterval int = 10
// ErrorThreshold rss源抓取错误阈值
ErrorThreshold uint = 100
// MessageTpl rss更新推送模版
MessageTpl *template.Template
// MessageMode telegram消息渲染模式
MessageMode tb.ParseMode
// TelegramEndpoint telegram bot 服务器地址, 默认为空
TelegramEndpoint string = tb.DefaultApiURL
// UserAgent User-Agent
UserAgent string
// RunMode 运行模式 Release / Debug
RunMode RunType = ReleaseMode
// AllowUsers 允许使用bot的用户
AllowUsers []int64
// DBLogMode 是否打印数据库日志
DBLogMode bool = false
)
const (
logo = `
__ _
/ _| | _____ _____ _ __ ___ ___
| |_| |/ _ \ \ /\ / / _ \ '__/ __/ __|
| _| | (_) \ V V / __/ | \__ \__ \
|_| |_|\___/ \_/\_/ \___|_| |___/___/
`
defaultMessageTplMode = tb.ModeHTML
defaultMessageTpl = `<b>{{.SourceTitle}}</b>{{ if .PreviewText }}
---------- Preview ----------
{{.PreviewText}}
-----------------------------
{{- end}}{{if .EnableTelegraph}}
{{.ContentTitle}} <a href="{{.TelegraphURL}}">Telegraph</a> | <a href="{{.RawLink}}">原文</a>
{{- else }}
<a href="{{.RawLink}}">{{.ContentTitle}}</a>
{{- end }}
{{.Tags}}
`
defaultMessageMarkdownTpl = `** {{.SourceTitle}} **{{ if .PreviewText }}
---------- Preview ----------
{{.PreviewText}}
-----------------------------
{{- end}}{{if .EnableTelegraph}}
{{.ContentTitle}} [Telegraph]({{.TelegraphURL}}) | [原文]({{.RawLink}})
{{- else }}
[{{.ContentTitle}}]({{.RawLink}})
{{- end }}
{{.Tags}}
`
TestMode RunType = "Test"
ReleaseMode RunType = "Release"
)
// MysqlConfig mysql 配置
type MysqlConfig struct {
Host string
Port int
User string
Password string
DB string
}
type TplData struct {
SourceTitle string
ContentTitle string
RawLink string
PreviewText string
TelegraphURL string
Tags string
EnableTelegraph bool
}
func AppVersionInfo() (s string) {
s = fmt.Sprintf("version %v, commit %v, built at %v", version, commit, date)
return
}
// GetString get string config value by key
func GetString(key string) string {
var value string
if viper.IsSet(key) {
value = viper.GetString(key)
}
return value
}