Skip to content

Commit

Permalink
Add delete file function
Browse files Browse the repository at this point in the history
  • Loading branch information
gaowanliang committed Dec 15, 2020
1 parent c95ad8d commit 90869cd
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 93 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ At the same time, communication via the bot protocol facilitates use on machines
#### Function
- [x] Control server files
- [x] Delete file
- [ ] Move/Copy file
- [x] Move/Copy file
- [x] Download files
- [x] Download HTTP/FTP link
- [x] Download Magnet link
Expand All @@ -52,6 +52,9 @@ At the same time, communication via the bot protocol facilitates use on machines
- [ ] Nyaa
- [ ] ThePirateBay
- [ ] Other functions
- [x] File tree output system
- [x] File tree output for simple folders
- [x] Use images instead of text output for complex folder structures
- [ ] Get all CIDs used in DMM via actor ID
- [ ] Query the movie parameters in "ikoa" (using mahuateng).
- [ ] Get the numbers of all actors via the javlibary actors' website.
Expand Down
7 changes: 5 additions & 2 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@
- [ ] Nyaa
- [ ] ThePirateBay
- [ ] 其他功能
- [x] 文件树输出系统
- [x] 对于简单文件夹的文件树输出
- [x] 对于复杂文件夹结构使用图片代替文字输出
- [ ] 通过演员ID获取在DMM中使用的所有CID
- [ ] 查询 "ikoa "中的影片参数(利用mahuateng)
- [ ] 查询 "ikoa"中的影片参数(利用mahuateng)
- [ ] 通过javlibary演员网址获得所有演员的编号。
- [ ] 查询dmm cid信息、预览影片、预览图片。
- [ ] 在sukebei中按关键词搜索。
Expand All @@ -70,7 +73,7 @@

## 开始

1. 通过[@BotFather](https://telegram.me/botfather)创建您自己的bot并使用。
1. 通过 [@BotFather](https://telegram.me/botfather) 创建您自己的bot并使用。
2. (可选)您所在地区/国家的Telegram被封锁?一定要有一个 **HTTP** proxy启动并运行,您可以设置您的系统环境变量`HTTPS_PROXY`为代理地址来进行代理。
3. 下载本程序
4. 在想要执行本程序的根目录配置`config.json`
Expand Down
106 changes: 62 additions & 44 deletions README_zh-TW.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,79 @@
# DownloadBot

(目前) 🤖 一個可以控制你的Aria2伺服器、控制伺服器檔,同時可以上傳到OneDrive的Telegram Bot。

(目前)🤖 一個控制你的Aria2伺服器的Telegram Bot。
## 意義

這個項目主要就是利用吃灰小盤vps進行離線下載,對於大bt檔進行根據硬碟大小分段下載,每次都下載一部分,然後上傳網盤,刪除再下載其他部分,直到下載完所有檔。

同時,通過機器人協議通信,方便在無法進行內網穿透的機器上進行使用,而且簡化了平時使用下載程式的操作,提高了便利性。
## 實現

#### 下載方式

- [x] Aria2 控制
- [ ] [SimpleTorrent](https://github.com/boypt/simple-torrent) 控制
- [ ] qbittorrent 控制
- [ ] 多下載伺服器同時控制

#### 機器人協定支援

- [x] Telegram Bot
- [ ] 騰訊QQ(使用普通QQ用戶來進行交互)
- [ ] 釘釘機器人


#### 功能

- [x] 控制伺服器檔
- [x] 刪除檔
- [x] 刪除檔
- [x] 移動文件
- [x] 下載檔案
- [x] 下載 HTTP/FTP 連結
- [x] 下載 Magnet 連結
- [x] 下載 BT 文件內的文件
- [x] 智慧 Torrent/Magnet 下載方式
- [x] 只下載最大的文件
- [x] 不下載小於指定大小的檔
- [ ] 自我調整環境存儲空間的 Torrent/Magnet 下載
- [ ] 不下載超過存儲空間的檔
- [ ] 根據存儲空間分塊多次下載 Torrent/Magnet 內的檔
- [ ] 上傳文件
- [ ] 下載完成後,向 OneDrive 上傳檔
- [ ] 下載完成後,向 Google Drive 上傳檔
- [ ] 下載完成後,向 Mega 上傳檔
- [ ] 下載完成後,向 天翼網盤 上傳文件
- [x] 下載 HTTP/FTP 連結
- [x] 下載 Magnet 連結
- [x] 下載 BT 文件內的文件
- [x] 智慧 Torrent/Magnet 下載方式
- [x] 只選擇下載最大的文件
- [x] 根據檔大小智慧選擇檔,不選擇小文件
- [ ] 自我調整環境存儲空間的 Torrent/Magnet 下載
- [ ] 不下載超過存儲空間的檔
- [ ] 根據存儲空間分塊多次下載 Torrent/Magnet 內的檔
- [x] 上傳文件
- [x] 下載完成後,向 OneDrive 上傳檔
- [ ] 下載完成後,向 Google Drive 上傳檔
- [ ] 下載完成後,向 Mega 上傳檔
- [ ] 下載完成後,向 天翼網盤 上傳文件
- [x] 附加其他功能
- [x] 多語言支援
- [x] 簡體中文
- [x] 英語
- [x] 繁體中文
- [ ] 日語
- [ ] 無人值守的BT站下載
- [ ] Nyaa
- [ ] ThePirateBay
- [ ] 其他功能
- [ ] 通過演員ID獲取在DMM中使用的所有CID
- [ ] 查詢 "ikoa "中的影片參數(利用mahuateng)
- [ ] 通過javlibary演員網址獲得所有演員的編號。
- [ ] 查詢dmm cid資訊、預覽影片、預覽圖片。
- [ ] 在sukebei中按關鍵字搜索。
- [ ] 根據關鍵字在dmm中搜索,最多30項。
- [ ] 輸入dmm連結,列出所有專案。
- [ ] 搜索當前dmm熱門和最新電影,限制30條(測試版)
- [x] 多語言支援
- [x] 簡體中文
- [x] 英語
- [x] 繁體中文
- [ ] 日語
- [ ] 無人值守的BT站下載
- [ ] Nyaa
- [ ] ThePirateBay
- [ ] 其他功能
- [x] 檔樹輸出系統
- [x] 對於簡單資料夾的文件樹輸出
- [x] 對於複雜資料夾結構使用圖片代替文字輸出
- [ ] 通過演員ID獲取在DMM中使用的所有CID
- [ ] 查詢 "ikoa"中的影片參數(利用mahuateng)
- [ ] 通過javlibary演員網址獲得所有演員的編號。
- [ ] 查詢dmm cid資訊、預覽影片、預覽圖片。
- [ ] 在sukebei中按關鍵字搜索。
- [ ] 根據關鍵字在dmm中搜索,最多30項。
- [ ] 輸入dmm連結,列出所有專案。
- [ ] 搜索當前dmm熱門和最新電影,限制30條(測試版)

## 目前特點

1. 完全基於觸摸,更容易使用,使用這個機器人基本不需要命令。
2. 即時通知,使用Aria2的Websocket協議進行通信。
3. 更好的設定檔支持。

## 開始

1. 通過[@BotFather](https://telegram.me/botfather)創建您自己的bot並使用。
1. 通過 [@BotFather](https://telegram.me/botfather) 創建您自己的bot並使用。
2. (可選)您所在地區/國家的Telegram被封鎖?一定要有一個 **HTTP** proxy啟動並運行,您可以設置您的系統環境變數`HTTPS_PROXY`為代理位址來進行代理。
3. 下載本程式
4. 在想要執行本程式的根目錄配置`config.json`
Expand All @@ -69,18 +83,21 @@

```json
{
"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": "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-server:aria2伺服器位址,默認使用websocket連接。如果要使用websocket連接aria2,請務必設置`aria2.conf`內的`enable-rpc=true`
。如果不是必須,請儘量設置本地的aria2位址,以便於最大化的使用本程式
* aria2-key:`aria2.conf``rpc-secret`的值
* bot-key:Telegram Bot的標識
* user-id:管理員的ID
Expand All @@ -90,6 +107,7 @@
* downloadFolder:Aria2下載檔案保存的位址

#### 目前支援的語言及語言標籤

| 語言 | 標籤 |
|----------|-------|
| 英語 | en |
Expand All @@ -99,6 +117,6 @@
當您在`config.json`中填寫上面語言的標籤的時候,程式會自動下載語言包

#### 關於user-id
如果您不知道您的 `user-id` ,可以將此項留空,在運行這個機器人後輸入`/myid`,此機器人就會返回您的`user-id`.

如果您不知道您的 `user-id` ,可以將此項留空,在運行這個機器人後輸入`/myid`,此機器人就會返回您的`user-id`.

50 changes: 33 additions & 17 deletions Telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ func setCommands(bot *tgbotapi.BotAPI) {
}, {
Command: "myid",
Description: locText("tgCommandMyidDes"),
}, {
Command: "set_mode",
Description: locText("tgCommandsetTorrentOrMagnetDownloadModeDes"),
},
})
}
Expand All @@ -56,8 +53,8 @@ func SuddenMessage(bot *tgbotapi.BotAPI) {

// TMSelectMessage receive active requests from WebSocket
func TMSelectMessage(bot *tgbotapi.BotAPI) {
var MessageID int = 0
var lastGid string = ""
var MessageID = 0
var lastGid = ""
var lastFilesInfo [][]string
for {
a := <-TMSelectMessageChan
Expand Down Expand Up @@ -124,7 +121,7 @@ func TMSelectMessage(bot *tgbotapi.BotAPI) {
fileList = formatTMFiles(gid)
}

text := fmt.Sprintf("%s 的文件目录如下:\n", tellName(aria2Rpc.TellStatus(gid)))
text := fmt.Sprintf("%s %s\n", tellName(aria2Rpc.TellStatus(gid)), locText("fileDirectoryIsAsFollows"))
Keyboards := make([][]tgbotapi.InlineKeyboardButton, 0)
inlineKeyBoardRow := make([]tgbotapi.InlineKeyboardButton, 0)
index := 1
Expand All @@ -142,7 +139,7 @@ func TMSelectMessage(bot *tgbotapi.BotAPI) {
}
index++
}
text += "请选择您要下载的文件"
text += locText("pleaseSelectTheFileYouWantToDownload")
if len(inlineKeyBoardRow) != 0 {
Keyboards = append(Keyboards, inlineKeyBoardRow)
}
Expand Down Expand Up @@ -183,25 +180,40 @@ func removeFiles(bot *tgbotapi.BotAPI) {
var MessageID = 0
var filesSelect = make(map[int]bool)
fileList, _ := GetAllFile(info.DownloadFolder)
myID := toInt64(info.UserID)
if len(fileList) == 1 {
bot.Send(tgbotapi.NewMessage(myID, locText("noFilesFound")))
return
}
deleteFiles := make([]string, 0)
for {
a := <-FileControlChan
if a == "close" {
return
}
b := strings.Split(a, "~")
fileTree := ""

if len(b) == 1 {
filesSelect = make(map[int]bool)
for i := 1; i <= len(fileList); i++ {
filesSelect[i] = true
}
fileTree, filesSelect = printFolderTree(info.DownloadFolder, filesSelect, "0")
fileTree, filesSelect, deleteFiles = printFolderTree(info.DownloadFolder, filesSelect, "0")
} else {
fileTree, filesSelect = printFolderTree(info.DownloadFolder, filesSelect, b[1])
if b[1] == "cancel" {
tgbotapi.NewDeleteMessage(myID, MessageID)
bot.Send(tgbotapi.NewDeleteMessage(myID, MessageID))
return
} else if b[1] == "Delete" {
RemoveFiles(deleteFiles)
bot.Send(tgbotapi.NewDeleteMessage(myID, MessageID))
bot.Send(tgbotapi.NewMessage(myID, locText("filesDeletedSuccessfully")))
return
}
fileTree, filesSelect, deleteFiles = printFolderTree(info.DownloadFolder, filesSelect, b[1])
}

text := fmt.Sprintf("%s 的文件目录如下:\n", info.DownloadFolder) + fileTree
text := fmt.Sprintf("%s %s\n", info.DownloadFolder, locText("fileDirectoryIsAsFollows")) + fileTree
Keyboards := make([][]tgbotapi.InlineKeyboardButton, 0)
inlineKeyBoardRow := make([]tgbotapi.InlineKeyboardButton, 0)
index := 1
Expand All @@ -213,7 +225,7 @@ func removeFiles(bot *tgbotapi.BotAPI) {
}
index++
}
text += "请选择您要删除的文件"
text += locText("pleaseSelectTheFileYouWantToDelete")
if len(inlineKeyBoardRow) != 0 {
Keyboards = append(Keyboards, inlineKeyBoardRow)
}
Expand All @@ -225,8 +237,7 @@ func removeFiles(bot *tgbotapi.BotAPI) {
inlineKeyBoardRow = append(inlineKeyBoardRow, tgbotapi.NewInlineKeyboardButtonData(locText("confirmDelete"), "file~Delete"+":9"))
inlineKeyBoardRow = append(inlineKeyBoardRow, tgbotapi.NewInlineKeyboardButtonData(locText("cancel"), "file~cancel"+":9"))
Keyboards = append(Keyboards, inlineKeyBoardRow)
myID, err := strconv.ParseInt(info.UserID, 10, 64)
dropErr(err)

msg := tgbotapi.NewMessage(myID, text)
if MessageID == 0 {
msg.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(Keyboards...)
Expand Down Expand Up @@ -447,6 +458,14 @@ func tgBot(BotKey string, wg *sync.WaitGroup) {
}
case locText("removeDownloadFolderFiles"):
//dropErr(removeContents(info.DownloadFolder))
isFileChanClean := false
for !isFileChanClean {
select {
case _ = <-FileControlChan:
default:
isFileChanClean = true
}
}
FileControlChan <- "close"
go removeFiles(bot)
FileControlChan <- "file"
Expand Down Expand Up @@ -503,9 +522,6 @@ func tgBot(BotKey string, wg *sync.WaitGroup) {
msg.Text = locText("commandHelpRes")
case "myid":
msg.Text = fmt.Sprintf(locText("commandMyidRes"), update.Message.Chat.ID)
case "set_mode":
msg.Text = locText("selectATMMode")
msg.ReplyMarkup = tgbotapi.NewReplyKeyboard(createKeyBoardRow(locText("tmMode1"), locText("tmMode2"), locText("tmMode3"))...)
}
} else {
msg.Text = locText("doNotHavePermissionControl")
Expand Down
2 changes: 1 addition & 1 deletion gotree/goTree.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (p *printer) printItems(t []Tree, spaces []bool) string {
var result string
for i, f := range t {
last := i == len(t)-1
result += p.printText(f.Text(), spaces, last)
result += p.printText(strings.ReplaceAll(f.Text(), "\n", ""), spaces, last)
if len(f.Items()) > 0 {
spacesChild := append(spaces, last)
result += p.printItems(f.Items(), spacesChild)
Expand Down
16 changes: 15 additions & 1 deletion i18n/active.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,19 @@
"onDownloadStopDes": "Download stopped!",
"onDownloadCompleteDes": "%s Download completed!",
"onDownloadErrorDes": "%s Download error!",
"onBtDownloadCompleteDes": "BT %s Download completed!"
"onBtDownloadCompleteDes": "BT %s Download completed!",
"selected": "Selected",
"operationSuccess": "Operation was successful",
"selectAll": "🌝 Select all",
"invert": "🌚 Select Invert",
"startDownload": "🚀 Start",
"uploadDownloadFolderFiles": "Upload files in the download folder",
"moveDownloadFolderFiles": "Move the files in the download folder",
"confirmDelete": "Sure to delete",
"cancel": "cancel",
"filesDeletedSuccessfully": "File was deleted successfully",
"noFilesFound": "There are no files in the folder",
"fileDirectoryIsAsFollows": "file directory is as follows:",
"pleaseSelectTheFileYouWantToDelete": "Please select the file you want to delete",
"pleaseSelectTheFileYouWantToDownload": "Please select the file you want to download"
}
7 changes: 6 additions & 1 deletion i18n/active.zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,10 @@
"uploadDownloadFolderFiles": "上传下载文件夹内的文件",
"moveDownloadFolderFiles": "移动下载文件夹内的文件",
"confirmDelete": "确定删除",
"cancel": "取消"
"cancel": "取消",
"filesDeletedSuccessfully": "文件成功删除",
"noFilesFound": "文件夹内没有文件",
"fileDirectoryIsAsFollows": "的文件目录如下:",
"pleaseSelectTheFileYouWantToDelete": "请选择您要删除的文件",
"pleaseSelectTheFileYouWantToDownload": "请选择您要下载的文件"
}

0 comments on commit 90869cd

Please sign in to comment.