mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-09-05 23:56:50 +08:00
feat: update database session configuration and retry settings
This commit is contained in:
+2
-1
@@ -56,10 +56,11 @@ func Init() {
|
|||||||
config.Cfg.Telegram.AppHash,
|
config.Cfg.Telegram.AppHash,
|
||||||
gotgproto.ClientTypeBot(config.Cfg.Telegram.Token),
|
gotgproto.ClientTypeBot(config.Cfg.Telegram.Token),
|
||||||
&gotgproto.ClientOpts{
|
&gotgproto.ClientOpts{
|
||||||
Session: sessionMaker.SqlSession(sqlite.Open("data/session.db")),
|
Session: sessionMaker.SqlSession(sqlite.Open(config.Cfg.DB.Session)),
|
||||||
DisableCopyright: true,
|
DisableCopyright: true,
|
||||||
Middlewares: FloodWaitMiddleware(),
|
Middlewares: FloodWaitMiddleware(),
|
||||||
Resolver: resolver,
|
Resolver: resolver,
|
||||||
|
MaxRetries: config.Cfg.Telegram.RpcRetry,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func FloodWaitMiddleware() []telegram.Middleware {
|
func FloodWaitMiddleware() []telegram.Middleware {
|
||||||
waiter := floodwait.NewSimpleWaiter().WithMaxRetries(5)
|
waiter := floodwait.NewSimpleWaiter().WithMaxRetries(uint(config.Cfg.Telegram.FloodRetry))
|
||||||
ratelimiter := ratelimit.New(rate.Every(time.Millisecond*100), 5)
|
ratelimiter := ratelimit.New(rate.Every(time.Millisecond*100), 5)
|
||||||
return []telegram.Middleware{
|
return []telegram.Middleware{
|
||||||
waiter,
|
waiter,
|
||||||
|
|||||||
+25
-21
@@ -10,19 +10,36 @@ stream = false # 使用stream模式, 详情请查看文档
|
|||||||
token = ""
|
token = ""
|
||||||
# Telegram API 配置, 若不配置也可运行, 将使用默认的 API ID 和 API HASH
|
# Telegram API 配置, 若不配置也可运行, 将使用默认的 API ID 和 API HASH
|
||||||
# 推荐使用自己的 API ID 和 API HASH (https://my.telegram.org)
|
# 推荐使用自己的 API ID 和 API HASH (https://my.telegram.org)
|
||||||
# app_id = 123456
|
# app_id = 1025907
|
||||||
# app_hash = "0123456789abcdef0123456789abcdef"
|
# app_hash = "452b0359b988148995f22ff0f4229750"
|
||||||
|
|
||||||
# 初始化超时时间, 单位: 秒
|
# 初始化超时时间, 单位: 秒
|
||||||
timeout = 60
|
timeout = 60
|
||||||
|
|
||||||
|
# flood_retry = 5
|
||||||
|
# rpc_retry = 5
|
||||||
|
|
||||||
[telegram.proxy]
|
[telegram.proxy]
|
||||||
# 启用代理连接 telegram, 只支持 socks5
|
# 启用代理连接 telegram, 只支持 socks5
|
||||||
enable = false
|
enable = false
|
||||||
url = "socks5://127.0.0.1:7890"
|
url = "socks5://127.0.0.1:7890"
|
||||||
|
|
||||||
|
# 用户列表
|
||||||
|
[[users]]
|
||||||
|
# telegram user id
|
||||||
|
id = 114514
|
||||||
|
# 使用黑名单模式,开启后下方留空以使用所有存储,反之则为白名单,白名单请在下方输入允许的存储名
|
||||||
|
blacklist = true
|
||||||
|
# 将列表留空并开启黑名单模式以允许使用所有存储,此处示例为黑名单模式,用户 114514 可使用所有存储
|
||||||
|
storages = []
|
||||||
|
|
||||||
# 存储配置列表
|
[[users]]
|
||||||
|
id = 123456
|
||||||
|
blacklist = false # 使用白名单模式,此时,用户123456 仅可使用下方列表中的存储
|
||||||
|
# 此时该用户只能使用名为 本机1 的存储
|
||||||
|
storages = ["本机1"]
|
||||||
|
|
||||||
|
# 存储列表
|
||||||
[[storages]]
|
[[storages]]
|
||||||
# 标识名, 需要唯一
|
# 标识名, 需要唯一
|
||||||
name = "本机1"
|
name = "本机1"
|
||||||
@@ -41,7 +58,9 @@ base_path = '/'
|
|||||||
url = 'https://alist.com'
|
url = 'https://alist.com'
|
||||||
username = 'admin'
|
username = 'admin'
|
||||||
password = 'password'
|
password = 'password'
|
||||||
token_exp = 86400 # 86400--1天 604800--7天 1296000--15天 2592000--30天 15552000--180天
|
# alist token 刷新时间
|
||||||
|
# 86400--1天 604800--7天 1296000--15天 2592000--30天 15552000--180天
|
||||||
|
token_exp = 86400
|
||||||
# alist 可直接使用 token 登录, 此时 username, password, token_exp 将被忽略
|
# alist 可直接使用 token 登录, 此时 username, password, token_exp 将被忽略
|
||||||
# 请自行在 alist 侧配置合理的 token 过期时间
|
# 请自行在 alist 侧配置合理的 token 过期时间
|
||||||
# token = ""
|
# token = ""
|
||||||
@@ -66,23 +85,6 @@ secret_access_key = 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG'
|
|||||||
bucket_name = 'saveanybot'
|
bucket_name = 'saveanybot'
|
||||||
base_path = '/path/telegram'
|
base_path = '/path/telegram'
|
||||||
|
|
||||||
# 用户列表
|
|
||||||
[[users]]
|
|
||||||
# telegram user id
|
|
||||||
id = 114514
|
|
||||||
# 开启黑名单,开启后下方留空以使用所有存储,反之则为白名单,白名单请在下方输入允许的存储名
|
|
||||||
blacklist = true
|
|
||||||
# 将列表留空并开启黑名单模式以允许使用所有存储,此处示例为黑名单模式,用户114514 可使用所有存储
|
|
||||||
storages = []
|
|
||||||
|
|
||||||
|
|
||||||
[[users]]
|
|
||||||
id = 123456
|
|
||||||
blacklist = false #开启白名单模式,此时,用户123456 仅可使用下方列表中的存储
|
|
||||||
# 此时该用户只能使用名为 本机1 的存储
|
|
||||||
storages = ["本机1"]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 其他配置
|
# 其他配置
|
||||||
|
|
||||||
@@ -98,3 +100,5 @@ storages = ["本机1"]
|
|||||||
|
|
||||||
# [db]
|
# [db]
|
||||||
# path = "data/data.db" # 数据库文件路径
|
# path = "data/data.db" # 数据库文件路径
|
||||||
|
# session = "data/session.db"
|
||||||
|
|
||||||
|
|||||||
+6
-4
@@ -39,6 +39,7 @@ type logConfig struct {
|
|||||||
|
|
||||||
type dbConfig struct {
|
type dbConfig struct {
|
||||||
Path string `toml:"path" mapstructure:"path"`
|
Path string `toml:"path" mapstructure:"path"`
|
||||||
|
Session string `toml:"session" mapstructure:"session"`
|
||||||
Expire int64 `toml:"expire" mapstructure:"expire"`
|
Expire int64 `toml:"expire" mapstructure:"expire"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,9 +49,8 @@ type telegramConfig struct {
|
|||||||
AppHash string `toml:"app_hash" mapstructure:"app_hash" json:"app_hash"`
|
AppHash string `toml:"app_hash" mapstructure:"app_hash" json:"app_hash"`
|
||||||
Timeout int `toml:"timeout" mapstructure:"timeout" json:"timeout"`
|
Timeout int `toml:"timeout" mapstructure:"timeout" json:"timeout"`
|
||||||
Proxy proxyConfig `toml:"proxy" mapstructure:"proxy"`
|
Proxy proxyConfig `toml:"proxy" mapstructure:"proxy"`
|
||||||
|
FloodRetry int `toml:"flood_retry" mapstructure:"flood_retry" json:"flood_retry"`
|
||||||
// Deprecated
|
RpcRetry int `toml:"rpc_retry" mapstructure:"rpc_retry" json:"rpc_retry"`
|
||||||
Admins []int64 `toml:"admins" mapstructure:"admins"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type proxyConfig struct {
|
type proxyConfig struct {
|
||||||
@@ -86,6 +86,8 @@ func Init() error {
|
|||||||
viper.SetDefault("telegram.app_id", 1025907)
|
viper.SetDefault("telegram.app_id", 1025907)
|
||||||
viper.SetDefault("telegram.app_hash", "452b0359b988148995f22ff0f4229750")
|
viper.SetDefault("telegram.app_hash", "452b0359b988148995f22ff0f4229750")
|
||||||
viper.SetDefault("telegram.timeout", 60)
|
viper.SetDefault("telegram.timeout", 60)
|
||||||
|
viper.SetDefault("telegram.flood_retry", 5)
|
||||||
|
viper.SetDefault("telegram.rpc_retry", 5)
|
||||||
|
|
||||||
viper.SetDefault("temp.base_path", "cache/")
|
viper.SetDefault("temp.base_path", "cache/")
|
||||||
viper.SetDefault("temp.cache_ttl", 3600)
|
viper.SetDefault("temp.cache_ttl", 3600)
|
||||||
@@ -95,6 +97,7 @@ func Init() error {
|
|||||||
viper.SetDefault("log.backup_count", 7)
|
viper.SetDefault("log.backup_count", 7)
|
||||||
|
|
||||||
viper.SetDefault("db.path", "data/saveany.db")
|
viper.SetDefault("db.path", "data/saveany.db")
|
||||||
|
viper.SetDefault("db.session", "data/session.db")
|
||||||
viper.SetDefault("db.expire", 86400*5)
|
viper.SetDefault("db.expire", 86400*5)
|
||||||
|
|
||||||
if err := viper.SafeWriteConfigAs("config.toml"); err != nil {
|
if err := viper.SafeWriteConfigAs("config.toml"); err != nil {
|
||||||
@@ -150,7 +153,6 @@ func Init() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user