diff --git a/README.md b/README.md index bf8709d..6f79cc6 100644 --- a/README.md +++ b/README.md @@ -10,16 +10,19 @@ - [x] Aria2 control - [ ] [SimpleTorrent](https://github.com/boypt/simple-torrent) control - [ ] qbittorrent control +- [ ] Multi download server control at the same time #### The robot protocol supports - [x] Telegram Bot -- [ ] DingTalk robot +- [ ] DingTalk Bot #### Function +- [x] Control server files + - [x] Delete file - [x] Download files - [x] Download HTTP/FTP link - [x] Download Magnet link - - [ ] Download the files in the BT file + - [x] Download the files in the BT file - [ ] Custom Torrent/Magnet download - [ ] Do not download files smaller than the specified size - [ ] Download Torrent/Magnet according to the size of storage space @@ -57,37 +60,45 @@ ## Setup 1. Create your own bot and get its access token by using [@BotFather](https://telegram.me/botfather) -2. (Optional) Telegram blocked in your region/country? be sure to have a HTTP proxy up and running,and You can set your system environment variable `HTTPS_ Proxy` is the proxy address. +2. (Optional) Telegram blocked in your region/country? be sure to have a HTTP proxy up and running,and You can set your system environment variable `HTTPS_Proxy` is the proxy address. 3. Download this program 4. Configure `config.json` at the root of the program that you want to execute. 5. Run the executable file -## 3 ways to pass parameters -You can pass parameters to `DownloadBot in three ways: -* [X] configuration file -* [ ] cli -* [ ] environment variable - -Option priorities also follow this order, so cli has the highest priority. - -| | Aria2 server | Aria2 key | Telegram bot key | Telegram user id | Max items in range(default 20) | language | -|-----------------------------|-----------------|--------------|------------------|------------------|--------------------------------|-------------| -| configuration file option | aria2-server | aria2-key | bot-key | user-id | max-index | language | -| cli option | --aria2-server | --aria2-key | --bot-key | --user-id | --max-index | --language | -| environment variable option | ta.aria2-server | ta.aria2-key | ta.bot-key | ta.user-id | ta.max-index | ta.language | - ## Example of a profile ```json { - "aria2-server": "ws://192.168.1.154:6800/jsonrpc", - "aria2-key": "xxx", - "bot-key": "123456789:xxx", - "user-id": "123456", - "max-index": 10, - "language":"en" + "aria2-server": "ws://127.0.0.1:5800/jsonrpc", + "aria2-key": "xxxxxxxx", + "bot-key": "123456789:xxxxxxxxx", + "user-id": "123456789", + "max-index": 10, + "sign":"Main Aria2", + "language":"zh-CN", + "downloadFolder":"C:/aria2/Aria2Data" } ``` +#### Corresponding explanations +* aria2-server : Aria2 server address. Websocket connection is used by default. If you want to use websocket to connect to aria2, be sure to set `enable-rpc=true` in `aria2.conf`. If not necessary, please try to **set the local aria2 address**, in order to maximize the use of this program +* aria2-key : The value of `rpc-secret` in aria2.conf +* bot-key : ID of telegram BOT +* user-id : The ID of the administrator +* max-index:Maximum display quantity of download information, 10 pieces are recommended (to be improved in the future) +* sign: Identification of this Bot, If multiple servers are required to connect to the same Bot, the specific server can be determined through this item. +* language: Language of Bot output +* downloadFolder: Aria2 download file save address + +#### Currently supported languages and language tags +| Languages | Tag | +|---------------------|-------| +| English | en | +| Simplified Chinese | zh-CN | +| Traditional Chinese | zh-TW | + +When you fill in the above language tag in `config.json`, the program will automatically download the language pack + +#### About user-id If you don't know your `user-id`, you can leave this field blank and enter `/myid` after running the robot, and the robot will return your `user-id` diff --git a/README_zh-CN.md b/README_zh-CN.md index 72f70b7..01fe976 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -11,12 +11,15 @@ - [x] Aria2 控制 - [ ] [SimpleTorrent](https://github.com/boypt/simple-torrent) 控制 - [ ] qbittorrent 控制 +- [ ] 多下载服务器同时控制 #### 机器人协议支持 - [x] Telegram Bot - [ ] 钉钉机器人 #### 功能 +- [x] 控制服务器文件 + - [x] 删除文件 - [x] 下载文件 - [x] 下载 HTTP/FTP 链接 - [x] 下载 Magnet 链接 @@ -63,33 +66,39 @@ 4. 在想要执行本程序的根目录配置`config.json` 5. 运行可执行文件 -## 三种方式传递参数 -您可以通过三种方式将参数传递给`DownloadBot`: -* [X] 配置文件 -* [ ] Cil 命令行 -* [ ] 系统环境变量 - - -Option priorities also follow this order, so cli has the highest priority. - -| | Aria2 server | Aria2 key | Telegram bot key | Telegram user id |Max items in range(default 20) |language| -|----------------------------- |----------------- |-------------- |------------------ |------------------ |-------------------------------- |---| -| 配置文件 参数 | aria2-server | aria2-key | bot-key | user-id |max-index |language| -| Cil 命令行 参数 | --aria2-server | --aria2-key | --bot-key | --user-id |--max-index |--language| -| 系统环境变量参数 | ta.aria2-server | ta.aria2-key | ta.bot-key | ta.user-id |ta.max-index |ta.language| - - ### 配置文件示例 ```json { - "aria2-server": "ws://192.168.1.154:6800/jsonrpc", - "aria2-key": "xxx", - "bot-key": "123456789:xxx", - "user-id": "123456", - "max-index": 10, - "language":"en" + "aria2-server": "ws://127.0.0.1:5800/jsonrpc", + "aria2-key": "xxxxxxxx", + "bot-key": "123456789:xxxxxxxxx", + "user-id": "123456789", + "max-index": 10, + "sign":"Main Aria2", + "language":"zh-CN", + "downloadFolder":"C:/aria2/Aria2Data" } ``` +#### 各项对应解释 +* aria2-server:aria2服务器地址,默认使用websocket连接。如果要使用websocket连接aria2,请务必设置`aria2.conf`内的`enable-rpc=true`。如果不是必须,请尽量设置本地的aria2地址,以便于最大化的使用本程序 +* aria2-key:aria2.conf中rpc-secret的值 +* bot-key:Telegram Bot的标识 +* user-id:管理员的ID +* max-index:下载信息最大显示数量,建议10条(以后会改进) +* sign:此机器人的标识,如果需要多个服务器连接同一个机器人,通过这一项可以确定具体是哪一台服务器 +* language:机器人输出的语言 +* downloadFolder:Aria2下载文件保存的地址 + +#### 目前支持的语言及语言标签 +| 语言 | 标签 | +|----------|-------| +| 英语 | en | +| 简体中文 | zh-CN | +| 繁体中文 | zh-TW | + +当您在`config.json`中填写上面语言的标签的时候,程序会自动下载语言包 + +#### 关于user-id 如果您不知道您的 `user-id` ,可以将此项留空,在运行这个机器人后输入`/myid`,此机器人就会返回您的`user-id`. diff --git a/README_zh-TW.md b/README_zh-TW.md index 2ebfb75..d54502e 100644 --- a/README_zh-TW.md +++ b/README_zh-TW.md @@ -9,12 +9,15 @@ - [x] Aria2 控制 - [ ] [SimpleTorrent](https://github.com/boypt/simple-torrent) 控制 - [ ] qbittorrent 控制 +- [ ] 多下載伺服器同時控制 #### 機器人協定支援 - [x] Telegram Bot - [ ] 釘釘機器人 #### 功能 +- [x] 控制伺服器檔 + - [x] 刪除檔 - [x] 下載檔案 - [x] 下載 HTTP/FTP 連結 - [x] 下載 Magnet 連結 @@ -28,7 +31,7 @@ - [ ] 下載完成後,向 OneDrive 上傳檔 - [ ] 下載完成後,向 Google Drive 上傳檔 - [ ] 下載完成後,向 Mega 上傳檔 - - [ ] 下載完成後,向 天翼網盤 上傳檔 + - [ ] 下載完成後,向 天翼網盤 上傳文件 - [x] 附加其他功能 - [x] 多語言支援 - [x] 簡體中文 @@ -61,32 +64,40 @@ 4. 在想要執行本程式的根目錄配置`config.json` 5. 運行可執行檔 -## 三種方式傳遞參數 -您可以通過三種方式將參數傳遞給`DownloadBot`: -* [X] 設定檔 -* [ ] Cil 命令列 -* [ ] 系統環境變數 - -Option priorities also follow this order, so cli has the highest priority. - -| | Aria2 server | Aria2 key | Telegram bot key | Telegram user id | Max items in range(default 20) | language | -|------------------|-----------------|--------------|------------------|------------------|--------------------------------|-------------| -| 設定檔 參數 | aria2-server | aria2-key | bot-key | user-id | max-index | language | -| Cil 命令列 參數 | --aria2-server | --aria2-key | --bot-key | --user-id | --max-index | --language | -| 系統環境變數參數 | ta.aria2-server | ta.aria2-key | ta.bot-key | ta.user-id | ta.max-index | ta.language | - ### 設定檔示例 ```json { - "aria2-server": "ws://192.168.1.154:6800/jsonrpc", - "aria2-key": "xxx", - "bot-key": "123456789:xxx", - "user-id": "123456", - "max-index": 10, - "language":"en" + "aria2-server": "ws://127.0.0.1:5800/jsonrpc", + "aria2-key": "xxxxxxxx", + "bot-key": "123456789:xxxxxxxxx", + "user-id": "123456789", + "max-index": 10, + "sign":"Main Aria2", + "language":"zh-CN", + "downloadFolder":"C:/aria2/Aria2Data" } ``` +#### 各項對應解釋 +* aria2-server:aria2伺服器位址,默認使用websocket連接。如果要使用websocket連接aria2,請務必設置`aria2.conf`內的`enable-rpc=true`。如果不是必須,請儘量設置本地的aria2位址,以便於最大化的使用本程式 +* aria2-key:aria2.conf中rpc-secret的值 +* bot-key:Telegram Bot的標識 +* user-id:管理員的ID +* max-index:下載資訊最大顯示數量,建議10條(以後會改進) +* sign:此機器人的標識,如果需要多個伺服器連接同一個機器人,通過這一項可以確定具體是哪一台伺服器 +* language:機器人輸出的語言 +* downloadFolder:Aria2下載檔案保存的位址 + +#### 目前支援的語言及語言標籤 +| 語言 | 標籤 | +|----------|-------| +| 英語 | en | +| 簡體中文 | zh-CN | +| 繁體中文 | zh-TW | + +當您在`config.json`中填寫上面語言的標籤的時候,程式會自動下載語言包 + +#### 關於user-id 如果您不知道您的 `user-id` ,可以將此項留空,在運行這個機器人後輸入`/myid`,此機器人就會返回您的`user-id`. diff --git a/Telegram.go b/Telegram.go index eb521d0..208ea2c 100644 --- a/Telegram.go +++ b/Telegram.go @@ -45,19 +45,24 @@ func SuddenMessage(bot *tgbotapi.BotAPI) { } func tgBot(BotKey string, wg *sync.WaitGroup) { + Keyboards := make([][]tgbotapi.KeyboardButton, 0) + Keyboards = append(Keyboards, tgbotapi.NewKeyboardButtonRow( + tgbotapi.NewKeyboardButton(locText("nowDownload")), + tgbotapi.NewKeyboardButton(locText("nowWaiting")), + tgbotapi.NewKeyboardButton(locText("nowOver")), + )) + Keyboards = append(Keyboards, tgbotapi.NewKeyboardButtonRow( + tgbotapi.NewKeyboardButton(locText("pauseTask")), + tgbotapi.NewKeyboardButton(locText("resumeTask")), + tgbotapi.NewKeyboardButton(locText("removeTask")), + )) + if isLocal(info.Aria2Server) { + Keyboards = append(Keyboards, tgbotapi.NewKeyboardButtonRow( + tgbotapi.NewKeyboardButton(locText("removeDownloadFolderAllFile")), + )) + } - var numericKeyboard = tgbotapi.NewReplyKeyboard( - tgbotapi.NewKeyboardButtonRow( - tgbotapi.NewKeyboardButton(locText("nowDownload")), - tgbotapi.NewKeyboardButton(locText("nowWaiting")), - tgbotapi.NewKeyboardButton(locText("nowOver")), - ), - tgbotapi.NewKeyboardButtonRow( - tgbotapi.NewKeyboardButton(locText("pauseTask")), - tgbotapi.NewKeyboardButton(locText("resumeTask")), - tgbotapi.NewKeyboardButton(locText("removeTask")), - ), - ) + var numericKeyboard = tgbotapi.NewReplyKeyboard(Keyboards...) bot, err := tgbotapi.NewBotAPI(BotKey) dropErr(err) @@ -101,113 +106,138 @@ func tgBot(BotKey string, wg *sync.WaitGroup) { } if update.Message != nil { // - - // 创建新的MessageConfig。我们还没有文本,所以将其留空。 msg := tgbotapi.NewMessage(update.Message.Chat.ID, "") msg.ParseMode = "Markdown" + if fmt.Sprint(update.Message.Chat.ID) == info.UserID { - switch update.Message.Text { - case locText("nowDownload"): - res := formatTellSomething(aria2Rpc.TellActive()) - if res != "" { - msg.Text = res - } else { - // log.Println(aria2Rpc.TellStatus("42fa911166acf119")) - msg.Text = locText("noActiveTask") - } - case locText("nowWaiting"): - res := formatTellSomething(aria2Rpc.TellWaiting(0, info.MaxIndex)) - if res != "" { - msg.Text = res - } else { - msg.Text = locText("noWaittingTask") - } - case locText("nowOver"): - res := formatTellSomething(aria2Rpc.TellStopped(0, info.MaxIndex)) - if res != "" { - msg.Text = res - } else { - msg.Text = locText("noOverTask") - } - case locText("pauseTask"): - InlineKeyboards := make([]tgbotapi.InlineKeyboardButton, 0) - for _, value := range formatGidAndName(aria2Rpc.TellActive()) { - log.Printf("%s %s", value["GID"], value["Name"]) - InlineKeyboards = append(InlineKeyboards, tgbotapi.NewInlineKeyboardButtonData(value["Name"], value["GID"]+":1")) - } - if len(InlineKeyboards) != 0 { - msg.Text = locText("stopWhichOne") - if len(InlineKeyboards) > 1 { - InlineKeyboards = append(InlineKeyboards, tgbotapi.NewInlineKeyboardButtonData("停止全部", "ALL:4")) - } - msg.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(InlineKeyboards) - } else { - msg.Text = locText("noWaittingTask") - } - case locText("resumeTask"): - InlineKeyboards := make([]tgbotapi.InlineKeyboardButton, 0) - for _, value := range formatGidAndName(aria2Rpc.TellWaiting(0, info.MaxIndex)) { - log.Printf("%s %s", value["GID"], value["Name"]) - InlineKeyboards = append(InlineKeyboards, tgbotapi.NewInlineKeyboardButtonData(value["Name"], value["GID"]+":2")) + // 创建新的MessageConfig。我们还没有文本,所以将其留空。 - } - if len(InlineKeyboards) != 0 { - msg.Text = locText("resumeWhichOne") - if len(InlineKeyboards) > 1 { - InlineKeyboards = append(InlineKeyboards, tgbotapi.NewInlineKeyboardButtonData("恢复全部", "ALL:5")) + switch update.Message.Text { + case locText("nowDownload"): + res := formatTellSomething(aria2Rpc.TellActive()) + if res != "" { + msg.Text = res + } else { + msg.Text = locText("noActiveTask") + } + case locText("nowWaiting"): + res := formatTellSomething(aria2Rpc.TellWaiting(0, info.MaxIndex)) + if res != "" { + msg.Text = res + } else { + msg.Text = locText("noWaittingTask") + } + case locText("nowOver"): + res := formatTellSomething(aria2Rpc.TellStopped(0, info.MaxIndex)) + if res != "" { + msg.Text = res + } else { + msg.Text = locText("noOverTask") + } + case locText("pauseTask"): + InlineKeyboardss := make([][]tgbotapi.InlineKeyboardButton, 0) + + for _, value := range formatGidAndName(aria2Rpc.TellActive()) { + log.Printf("%s %s", value["GID"], value["Name"]) + InlineKeyboards := make([]tgbotapi.InlineKeyboardButton, 0) + InlineKeyboards = append(InlineKeyboards, tgbotapi.NewInlineKeyboardButtonData(value["Name"], value["GID"]+":1")) + InlineKeyboardss = append(InlineKeyboardss, InlineKeyboards) + } + if len(InlineKeyboardss) != 0 { + msg.Text = locText("stopWhichOne") + if len(InlineKeyboardss) > 1 { + InlineKeyboards := make([]tgbotapi.InlineKeyboardButton, 0) + InlineKeyboards = append(InlineKeyboards, tgbotapi.NewInlineKeyboardButtonData(locText("StopAll"), "ALL:4")) + InlineKeyboardss = append(InlineKeyboardss, InlineKeyboards) + } + msg.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(InlineKeyboardss...) + } else { + msg.Text = locText("noWaittingTask") + } + case locText("resumeTask"): + InlineKeyboardss := make([][]tgbotapi.InlineKeyboardButton, 0) + + for _, value := range formatGidAndName(aria2Rpc.TellWaiting(0, info.MaxIndex)) { + log.Printf("%s %s", value["GID"], value["Name"]) + InlineKeyboards := make([]tgbotapi.InlineKeyboardButton, 0) + InlineKeyboards = append(InlineKeyboards, tgbotapi.NewInlineKeyboardButtonData(value["Name"], value["GID"]+":2")) + InlineKeyboardss = append(InlineKeyboardss, InlineKeyboards) + } + if len(InlineKeyboardss) != 0 { + msg.Text = locText("resumeWhichOne") + if len(InlineKeyboardss) > 1 { + InlineKeyboards := make([]tgbotapi.InlineKeyboardButton, 0) + InlineKeyboards = append(InlineKeyboards, tgbotapi.NewInlineKeyboardButtonData(locText("ResumeAll"), "ALL:5")) + InlineKeyboardss = append(InlineKeyboardss, InlineKeyboards) + } + msg.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(InlineKeyboardss...) + } else { + msg.Text = locText("noActiveTask") + } + case locText("removeTask"): + InlineKeyboardss := make([][]tgbotapi.InlineKeyboardButton, 0) + for _, value := range formatGidAndName(aria2Rpc.TellActive()) { + log.Printf("%s %s", value["GID"], value["Name"]) + InlineKeyboards := make([]tgbotapi.InlineKeyboardButton, 0) + InlineKeyboards = append(InlineKeyboards, tgbotapi.NewInlineKeyboardButtonData(value["Name"], value["GID"]+":3")) + InlineKeyboardss = append(InlineKeyboardss, InlineKeyboards) + } + for _, value := range formatGidAndName(aria2Rpc.TellWaiting(0, info.MaxIndex)) { + log.Printf("%s %s", value["GID"], value["Name"]) + InlineKeyboards := make([]tgbotapi.InlineKeyboardButton, 0) + InlineKeyboards = append(InlineKeyboards, tgbotapi.NewInlineKeyboardButtonData(value["Name"], value["GID"]+":3")) + InlineKeyboardss = append(InlineKeyboardss, InlineKeyboards) + } + if len(InlineKeyboardss) != 0 { + msg.Text = locText("removeWhichOne") + msg.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(InlineKeyboardss...) + } else { + msg.Text = locText("noOverTask") + } + case locText("removeDownloadFolderAllFile"): + dropErr(RemoveContents(info.DownloadFolder)) + msg.Text = locText("fileRemoveComplete") + default: + if !download(update.Message.Text) { + msg.Text = locText("unknownLink") + } + if update.Message.Document != nil { + bt, _ := bot.GetFileDirectURL(update.Message.Document.FileID) + resp, err := http.Get(bt) + dropErr(err) + defer resp.Body.Close() + out, err := os.Create("temp.torrent") + dropErr(err) + defer out.Close() + _, err = io.Copy(out, resp.Body) + dropErr(err) + if download("temp.torrent") { + msg.Text = "" + } } - msg.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(InlineKeyboards) - } else { - msg.Text = locText("noActiveTask") - } - case locText("removeTask"): - InlineKeyboards := make([]tgbotapi.InlineKeyboardButton, 0) - for _, value := range formatGidAndName(aria2Rpc.TellActive()) { - log.Printf("%s %s", value["GID"], value["Name"]) - InlineKeyboards = append(InlineKeyboards, tgbotapi.NewInlineKeyboardButtonData(value["Name"], value["GID"]+":3")) - } - for _, value := range formatGidAndName(aria2Rpc.TellWaiting(0, info.MaxIndex)) { - log.Printf("%s %s", value["GID"], value["Name"]) - InlineKeyboards = append(InlineKeyboards, tgbotapi.NewInlineKeyboardButtonData(value["Name"], value["GID"]+":3")) - } - if len(InlineKeyboards) != 0 { - msg.Text = locText("removeWhichOne") - msg.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(InlineKeyboards) - } else { - msg.Text = locText("noOverTask") - } - default: - if !download(update.Message.Text) { - msg.Text = locText("unknownLink") } - if update.Message.Document != nil { - bt, _ := bot.GetFileDirectURL(update.Message.Document.FileID) - resp, err := http.Get(bt) - dropErr(err) - defer resp.Body.Close() - out, err := os.Create("temp.torrent") - dropErr(err) - defer out.Close() - _, err = io.Copy(out, resp.Body) + + // 从消息中提取命令。 + switch update.Message.Command() { + case "start": + version, err := aria2Rpc.GetVersion() dropErr(err) - if download("temp.torrent") { - msg.Text = "" + msg.Text = fmt.Sprintf(locText("commandStartRes"), info.Sign, version.Version) + if isLocal(info.Aria2Server) { + msg.Text += "\n" + locText("inLocal") } - } - } + msg.ReplyMarkup = numericKeyboard - // 从消息中提取命令。 - switch update.Message.Command() { - case "start": - version, err := aria2Rpc.GetVersion() - dropErr(err) - msg.Text = fmt.Sprintf(locText("commandStartRes"), info.Sign, version.Version) - msg.ReplyMarkup = numericKeyboard - - case "help": - msg.Text = locText("commandHelpRes") - case "myid": - msg.Text = fmt.Sprintf(locText("commandMyidRes"), update.Message.Chat.ID) + case "help": + msg.Text = locText("commandHelpRes") + case "myid": + msg.Text = fmt.Sprintf(locText("commandMyidRes"), update.Message.Chat.ID) + } + } else { + msg.Text = locText("doNotHavePermissionControl") + if update.Message.Command() == "myid" { + msg.Text = fmt.Sprintf(locText("commandMyidRes"), update.Message.Chat.ID) + } } if msg.Text != "" { diff --git a/i18n/active.en.json b/i18n/active.en.json index 0d8cb76..84201d0 100644 --- a/i18n/active.en.json +++ b/i18n/active.en.json @@ -32,5 +32,12 @@ "removed": "Removed", "queryInformationFormat1": "GID: %s\nName: %s\nProgess: %s\nSize: %s", "queryInformationFormat2": "GID: %s\nName: %s\nStatus: %s\nProgess: %s\nSize: %s", - "queryInformationFormat3": "GID:%s\nName:%s\nProgess:%s\nSize: %s\nSpeed: %s/s" + "queryInformationFormat3": "GID:%s\nName:%s\nProgess:%s\nSize: %s\nSpeed: %s/s", + "ResumeAll": "Resume All", + "StopAll": "Stop All", + "downloadFolderClear": "Delete all files in download folder", + "doNotHavePermissionControl": "You do not have permission to control this Bot", + "inLocal": "The server you are currently controlling is local, and you can control server files", + "removeDownloadFolderAllFile": "Delete all files in download folder", + "fileRemoveComplete": "File deleted successfully" } \ No newline at end of file diff --git a/i18n/active.zh-CN.json b/i18n/active.zh-CN.json index 2ddb346..44616e4 100644 --- a/i18n/active.zh-CN.json +++ b/i18n/active.zh-CN.json @@ -1,6 +1,6 @@ { "configCompleted": "配置信息加载完成!", - "authorizedAccount":"已登入授权账户 %s", + "authorizedAccount": "已登入授权账户 %s", "nowDownload": "⬇️ 正在下载", "nowWaiting": "⌛️ 正在等待", "nowOver": "✅ 已完成/已停止", @@ -32,5 +32,12 @@ "removed": "被移除", "queryInformationFormat1": "GID:%s\n名称: %s\n进度: %s\n大小: %s", "queryInformationFormat2": "GID:%s\n名称: %s\n状态: %s\n进度: %s\n大小: %s", - "queryInformationFormat3": "GID:%s\n名称: %s\n进度: %s\n大小: %s\n速度: %s/s" + "queryInformationFormat3": "GID:%s\n名称: %s\n进度: %s\n大小: %s\n速度: %s/s", + "ResumeAll": "恢复全部", + "StopAll": "停止全部", + "downloadFolderClear": "删除下载文件夹中所有文件", + "doNotHavePermissionControl": "您没有控制此机器人的权限", + "inLocal": "您当前控制的服务器在本地,可以控制服务器文件", + "removeDownloadFolderAllFile": "删除下载文件夹内所有文件", + "fileRemoveComplete": "文件删除成功" } \ No newline at end of file diff --git a/i18n/active.zh-TW.json b/i18n/active.zh-TW.json index 0a42f83..66f69b4 100644 --- a/i18n/active.zh-TW.json +++ b/i18n/active.zh-TW.json @@ -32,5 +32,12 @@ "removed": "被移除", "queryInformationFormat1": "GID:%s\n名稱: %s\n進度: %s\n大小: %s", "queryInformationFormat2": "GID:%s\n名稱: %s\n狀態: %s\n進度: %s\n大小: %s", - "queryInformationFormat3": "GID:%s\n名稱: %s\n進度: %s\n大小: %s\n速度: %s/s" + "queryInformationFormat3": "GID:%s\n名稱: %s\n進度: %s\n大小: %s\n速度: %s/s", + "ResumeAll": "恢復全部", + "StopAll": "停止全部", + "downloadFolderClear": "刪除下載檔案夾中所有檔", + "doNotHavePermissionControl": "您沒有控制此機器人的許可權", + "inLocal": "您當前控制的伺服器在本地,可以控制伺服器檔", + "removeDownloadFolderAllFile": "刪除下載檔案夾內所有檔", + "fileRemoveComplete": "檔刪除成功" } \ No newline at end of file diff --git a/struct.go b/struct.go index d5d6395..78820ed 100644 --- a/struct.go +++ b/struct.go @@ -8,13 +8,14 @@ import ( // Config 是读入的配置文件的struct type Config struct { - Aria2Server string `json:"aria2-server"` - Aria2Key string `json:"aria2-key"` - BotKey string `json:"bot-key"` - UserID string `json:"user-id"` - MaxIndex int `json:"max-index"` - Sign string `json:"sign"` - Language string `json:"language"` + Aria2Server string `json:"aria2-server"` + Aria2Key string `json:"aria2-key"` + BotKey string `json:"bot-key"` + UserID string `json:"user-id"` + MaxIndex int `json:"max-index"` + Sign string `json:"sign"` + Language string `json:"language"` + DownloadFolder string `json:"downloadFolder"` } // Aria2Notifier is Aria2 websocket message diff --git a/utils.go b/utils.go index b6f1671..c4be82b 100644 --- a/utils.go +++ b/utils.go @@ -7,8 +7,10 @@ import ( "net/http" "os" "path" + "path/filepath" "regexp" "strconv" + "strings" "github.com/nicksnyder/go-i18n/v2/i18n" "golang.org/x/text/language" @@ -57,9 +59,12 @@ var bundle *i18n.Bundle var loc *i18n.Localizer func locLan(locLanguaged string) { + _, err := os.Stat(info.DownloadFolder) + dropErr(err) + bundle = i18n.NewBundle(language.Chinese) bundle.RegisterUnmarshalFunc("json", json.Unmarshal) - _, err := os.Stat("i18n") + _, err = os.Stat("i18n") if err != nil { err := os.Mkdir("i18n", 0666) dropErr(err) @@ -87,3 +92,26 @@ func locLan(locLanguaged string) { func locText(MessageID string) string { return loc.MustLocalize(&i18n.LocalizeConfig{MessageID: MessageID}) } + +func isLocal(uri string) bool { + return strings.Contains(uri, "127.0.0.1") || strings.Contains(uri, "localhost") +} + +func RemoveContents(dir string) error { + d, err := os.Open(dir) + if err != nil { + return err + } + defer d.Close() + names, err := d.Readdirnames(-1) + if err != nil { + return err + } + for _, name := range names { + err = os.RemoveAll(filepath.Join(dir, name)) + if err != nil { + return err + } + } + return nil +}