Skip to content

Commit

Permalink
Initially realize the function of file copy
Browse files Browse the repository at this point in the history
  • Loading branch information
gaowanliang committed Dec 19, 2020
1 parent 8db5e1a commit 9356406
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 41 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ At the same time, communication via the bot protocol facilitates use on machines
- [ ] Allow users to create public WebSocket relays for users who are not comfortable establishing WebSocket communication
- [ ] Deploy a separate WebSocket relay in heroku for relaying
- [ ] [SimpleTorrent](https://github.com/boypt/simple-torrent) control
- [ ] qbitBitTorrent control
- [ ] qbittorrent control


#### The Bot protocol supports
Expand Down Expand Up @@ -49,6 +49,7 @@ At the same time, communication via the bot protocol facilitates use on machines
- [ ] Can be set to force seeding for a period of time at the end of each download
- [x] Upload a file
- [x] Upload the file to OneDrive when the download is complete
- [ ] Resume from break point
- [ ] Upload the file to Google Drive when the download is complete
- [ ] Upload the file to Mega when the download is complete
- [ ] Upload the file to 189Cloud when the download is complete
Expand Down Expand Up @@ -92,12 +93,11 @@ At the same time, communication via the bot protocol facilitates use on machines
## Screenshots

<div align="center">
<img src="./img/1.jpg" height="300px" alt=""><img src="./img/2.jpg" height="300px" alt="" >
<img src="./img/1.jpg" height="300px" alt=""> <img src="./img/2.jpg" height="300px" alt="" >
</div>
<br>
<br>
<div align="center">
<img src="./img/3.jpg" height="300px" alt=""><img src="./img/4.jpg" height="300px" alt="" > </div>
<img src="./img/3.jpg" height="300px" alt=""> <img src="./img/4.jpg" height="300px" alt="" > </div>


## Example of a profile
Expand Down
8 changes: 4 additions & 4 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- [ ] 允许用户建立公共WebSocket中继端,供不方便建立WebSocket通信的用户进行通信
- [ ] 在heroku单独部署WebSocket中继端进行中继
- [ ] [SimpleTorrent](https://github.com/boypt/simple-torrent) 控制
- [ ] qbitBitTorrent 控制
- [ ] qbittorrent 控制


#### 机器人协议支持
Expand Down Expand Up @@ -95,12 +95,12 @@
## 使用截图

<div align="center">
<img src="./img/1.jpg" height="300px" alt=""><img src="./img/2.jpg" height="300px" alt="" >
<img src="./img/1.jpg" height="300px" alt=""> <img src="./img/2.jpg" height="300px" alt="" >
</div>
<br>
<br>

<div align="center">
<img src="./img/3.jpg" height="300px" alt=""><img src="./img/4.jpg" height="300px" alt="" > </div>
<img src="./img/3.jpg" height="300px" alt=""> <img src="./img/4.jpg" height="300px" alt="" > </div>


## 配置文件示例
Expand Down
8 changes: 4 additions & 4 deletions README_zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- [ ] 允許用戶建立公共WebSocket中繼端,供不方便建立WebSocket通信的用戶進行通信
- [ ] 在heroku單獨部署WebSocket中繼端進行中繼
- [ ] [SimpleTorrent](https://github.com/boypt/simple-torrent) 控制
- [ ] qbitBitTorrent 控制
- [ ] qbittorrent 控制

#### 機器人協定支援

Expand Down Expand Up @@ -93,12 +93,12 @@
## 使用截圖

<div align="center">
<img src="./img/1.jpg" height="300px" alt=""><img src="./img/2.jpg" height="300px" alt="" >
<img src="./img/1.jpg" height="300px" alt=""> <img src="./img/2.jpg" height="300px" alt="" >
</div>
<br>
<br>

<div align="center">
<img src="./img/3.jpg" height="300px" alt=""><img src="./img/4.jpg" height="300px" alt="" > </div>
<img src="./img/3.jpg" height="300px" alt=""> <img src="./img/4.jpg" height="300px" alt="" > </div>

## 設定檔示例

Expand Down
112 changes: 101 additions & 11 deletions Telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func setCommands(bot *tgbotapi.BotAPI) {
Description: locText("tgCommandStartDes"),
}, {
Command: "myid",
Description: locText("tgCommandMyidDes"),
Description: locText("tgCommandMyIDDes"),
},
})
}
Expand Down Expand Up @@ -189,6 +189,8 @@ func removeFiles(bot *tgbotapi.BotAPI) {
for {
a := <-FileControlChan
if a == "close" {
tgbotapi.NewDeleteMessage(myID, MessageID)
bot.Send(tgbotapi.NewDeleteMessage(myID, MessageID))
return
}
b := strings.Split(a, "~")
Expand Down Expand Up @@ -252,6 +254,88 @@ func removeFiles(bot *tgbotapi.BotAPI) {
}
}

func copyFiles(bot *tgbotapi.BotAPI) {
s := <-FileControlChan
if s == "file" {
FileControlChan <- "file"
}
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
}
copyFiles := make([]string, 0)
for {
a := <-FileControlChan
if a == "close" {
tgbotapi.NewDeleteMessage(myID, MessageID)
bot.Send(tgbotapi.NewDeleteMessage(myID, MessageID))
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, copyFiles = printFolderTree(info.DownloadFolder, filesSelect, "0")
} else {
if b[1] == "cancel" {
tgbotapi.NewDeleteMessage(myID, MessageID)
bot.Send(tgbotapi.NewDeleteMessage(myID, MessageID))
return
} else if b[1] == "Copy" {
CopyFiles(copyFiles)
bot.Send(tgbotapi.NewDeleteMessage(myID, MessageID))
bot.Send(tgbotapi.NewMessage(myID, locText("filesCopySuccessfully")))
return
}
fileTree, filesSelect, copyFiles = printFolderTree(info.DownloadFolder, filesSelect, b[1])
}

text := fmt.Sprintf("%s %s\n", info.DownloadFolder, locText("fileDirectoryIsAsFollows")) + fileTree
Keyboards := make([][]tgbotapi.InlineKeyboardButton, 0)
inlineKeyBoardRow := make([]tgbotapi.InlineKeyboardButton, 0)
index := 1
for _, _ = range fileList {
inlineKeyBoardRow = append(inlineKeyBoardRow, tgbotapi.NewInlineKeyboardButtonData(fmt.Sprint(index), "file~"+fmt.Sprint(index)+":8"))
if index%7 == 0 {
Keyboards = append(Keyboards, inlineKeyBoardRow)
inlineKeyBoardRow = make([]tgbotapi.InlineKeyboardButton, 0)
}
index++
}
text += locText("pleaseSelectTheFileYouWantToCopy")
if len(inlineKeyBoardRow) != 0 {
Keyboards = append(Keyboards, inlineKeyBoardRow)
}
inlineKeyBoardRow = make([]tgbotapi.InlineKeyboardButton, 0)
inlineKeyBoardRow = append(inlineKeyBoardRow, tgbotapi.NewInlineKeyboardButtonData(locText("selectAll"), "file~selectAll"+":9"))
inlineKeyBoardRow = append(inlineKeyBoardRow, tgbotapi.NewInlineKeyboardButtonData(locText("invert"), "file~invert"+":9"))
Keyboards = append(Keyboards, inlineKeyBoardRow)
inlineKeyBoardRow = make([]tgbotapi.InlineKeyboardButton, 0)
inlineKeyBoardRow = append(inlineKeyBoardRow, tgbotapi.NewInlineKeyboardButtonData(locText("confirmCopy"), "file~Copy"+":9"))
inlineKeyBoardRow = append(inlineKeyBoardRow, tgbotapi.NewInlineKeyboardButtonData(locText("cancel"), "file~cancel"+":9"))
Keyboards = append(Keyboards, inlineKeyBoardRow)

msg := tgbotapi.NewMessage(myID, text)
if MessageID == 0 {
msg.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(Keyboards...)
res, err := bot.Send(msg)
dropErr(err)
MessageID = res.MessageID

} else {
newMsg := tgbotapi.NewEditMessageTextAndMarkup(myID, MessageID, text, tgbotapi.NewInlineKeyboardMarkup(Keyboards...))
bot.Send(newMsg)
}
}
}

func createKeyBoardRow(texts ...string) [][]tgbotapi.KeyboardButton {
Keyboards := make([][]tgbotapi.KeyboardButton, 0)
for _, text := range texts {
Expand Down Expand Up @@ -398,7 +482,7 @@ func tgBot(BotKey string, wg *sync.WaitGroup) {
if res != "" {
msg.Text = res
} else {
msg.Text = locText("noWaittingTask")
msg.Text = locText("noWaitingTask")
}
case locText("nowOver"):
res := formatTellSomething(aria2Rpc.TellStopped(0, info.MaxIndex))
Expand All @@ -422,7 +506,7 @@ func tgBot(BotKey string, wg *sync.WaitGroup) {
}
msg.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(InlineKeyboards...)
} else {
msg.Text = locText("noWaittingTask")
msg.Text = locText("noWaitingTask")
}
case locText("resumeTask"):

Expand Down Expand Up @@ -470,12 +554,18 @@ func tgBot(BotKey string, wg *sync.WaitGroup) {
FileControlChan <- "close"
go removeFiles(bot)
FileControlChan <- "file"
case locText("uploadDownloadFolderFiles"):
//msg.Text = printFolderTree(info.DownloadFolder)
//msg.ParseMode = ""
//dropErr(removeContents(info.DownloadFolder))
//go removeFiles(bot)
//FileControlChan <- "file"
case locText("moveDownloadFolderFiles"):
isFileChanClean := false
for !isFileChanClean {
select {
case _ = <-FileControlChan:
default:
isFileChanClean = true
}
}
FileControlChan <- "close"
go copyFiles(bot)
FileControlChan <- "file"
default:
if !download(update.Message.Text) {
msg.Text = locText("unknownLink")
Expand Down Expand Up @@ -510,12 +600,12 @@ func tgBot(BotKey string, wg *sync.WaitGroup) {
case "help":
msg.Text = locText("commandHelpRes")
case "myid":
msg.Text = fmt.Sprintf(locText("commandMyidRes"), update.Message.Chat.ID)
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)
msg.Text = fmt.Sprintf(locText("commandMyIDRes"), update.Message.Chat.ID)
}
}

Expand Down
12 changes: 6 additions & 6 deletions i18n/active.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
"resumeTask": "▶️ Resume task",
"removeTask": "❌ Remove task",
"tgCommandStartDes": "Get the online Aria2 server and open the panel",
"tgCommandMyidDes": "Get user ID",
"tgCommandMyIDDes": "Get user ID",
"taskNowStop": "Task stopped",
"taskNowResume": "Task resumed",
"taskNowRemove": "Task removed",
"taskNowStopAll": "All tasks have been stopped",
"taskNowResumeAll": "All tasks have been resumed",
"commandStartRes": "%s currently connected, version %s, please select an option",
"commandHelpRes": "🤖 A Telegram Bot that controls your Aria2 server.",
"commandMyidRes": "Your user ID is `%d`",
"commandMyIDRes": "Your user ID is `%d`",
"noActiveTask": "There are no tasks in progress!",
"noWaittingTask": "There are no waiting tasks!",
"noWaitingTask": "There are no waiting tasks!",
"noOverTask": "There are no finished/stopped Task!",
"stopWhichOne": "Stop which one?",
"resumeWhichOne": "Which one to resume?",
Expand All @@ -40,10 +40,10 @@
"inLocal": "The server you are currently controlling is local, and you can control server files",
"removeDownloadFolderFiles": "Delete files from the download folder",
"fileRemoveComplete": "File deleted successfully",
"tgCommandsetTorrentOrMagnetDownloadModeDes": "Set Torrent/Magnet download mode",
"tgCommandSetTorrentOrMagnetDownloadModeDes": "Set Torrent/Magnet download mode",
"selectATMMode": "Select a Torrent/Magnet download mode",
"tmMode1": "Download only the largest files",
"tmMode2": "Intelligent selection of large files",
"tmMode1": "Select the largest files",
"tmMode2": "Smart select the larger files",
"tmMode3": "Custom download file",
"nowTMMode": "The current Torrent/Magnet download mode is:",
"setTMMode": "The current Torrent/Magnet download mode has been set to:",
Expand Down
13 changes: 8 additions & 5 deletions i18n/active.zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
"resumeTask": "▶️ 继续任务",
"removeTask": "❌ 移除任务",
"tgCommandStartDes": "获取已上线的Aria2服务器,并打开面板",
"tgCommandMyidDes": "获取user-id",
"tgCommandMyIDDes": "获取user-id",
"taskNowStop": "任务已停止",
"taskNowResume": "任务已恢复",
"taskNowRemove": "任务已移除",
"taskNowStopAll": "任务已全部停止",
"taskNowResumeAll": "任务已全部恢复",
"commandStartRes": "%s 当前已连接,版本: %s ,请选择一个选项",
"commandHelpRes": "🤖 一个控制你的Aria2服务器的Telegram Bot。",
"commandMyidRes": "你的user-id为 `%d` ",
"commandMyIDRes": "你的user-id为 `%d` ",
"noActiveTask": "没有正在进行的任务!",
"noWaittingTask": "没有正在等待的任务!",
"noWaitingTask": "没有正在等待的任务!",
"noOverTask": "没有已完成/已停止的任务!",
"stopWhichOne": "停止哪一个?",
"resumeWhichOne": "恢复哪一个?",
Expand All @@ -40,7 +40,7 @@
"inLocal": "您当前控制的服务器在本地,可以控制服务器文件",
"removeDownloadFolderFiles": "删除下载文件夹内文件",
"fileRemoveComplete": "文件删除成功",
"tgCommandsetTorrentOrMagnetDownloadModeDes": "设置Torrent/Magnet下载模式",
"tgCommandSetTorrentOrMagnetDownloadModeDes": "设置Torrent/Magnet下载模式",
"selectATMMode": "选择一个Torrent/Magnet下载模式",
"tmMode1": "只下载最大的文件",
"tmMode2": "智能选择大文件",
Expand Down Expand Up @@ -72,5 +72,8 @@
"onlyMinutes": "%d 分钟 ",
"onlySeconds": "%d 秒",
"UnableEstimate": "无法估计",
"systemInfo": "\n*CPU:* %.2f%% *硬盘:* %.2f%% *内存:* %.2f%%\n*总下载速度:* %s/s 📥\n*总上传速度:* %s/s 📤"
"systemInfo": "\n*CPU:* %.2f%% *硬盘:* %.2f%% *内存:* %.2f%%\n*总下载速度:* %s/s 📥\n*总上传速度:* %s/s 📤",
"filesCopySuccessfully": "文件成功复制到moveFolder",
"pleaseSelectTheFileYouWantToCopy": "请选择您要复制的文件",
"confirmCopy": "确定复制"
}
8 changes: 4 additions & 4 deletions i18n/active.zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
"resumeTask": "▶️ 繼續任務",
"removeTask": "❌ 移除任務",
"tgCommandStartDes": "獲取已上線的Aria2伺服器,並打開面板",
"tgCommandMyidDes": "獲取user-id",
"tgCommandMyIDDes": "獲取user-id",
"taskNowStop": "任務已停止",
"taskNowResume": "任務已恢復",
"taskNowRemove": "任務已移除",
"taskNowStopAll": "任務已全部停止",
"taskNowResumeAll": "任務已全部恢復",
"commandStartRes": "%s 當前已連接,版本: %s ,請選擇一個選項",
"commandHelpRes": "🤖 一個控制你的Aria2伺服器的Telegram Bot。",
"commandMyidRes": "你的user-id為 `%d` ",
"commandMyIDRes": "你的user-id為 `%d` ",
"noActiveTask": "沒有正在進行的任務!",
"noWaittingTask": "沒有正在等待的任務!",
"noWaitingTask": "沒有正在等待的任務!",
"noOverTask": "沒有已完成/已停止的任務!",
"stopWhichOne": "停止哪一個?",
"resumeWhichOne": "恢復哪一個?",
Expand All @@ -40,7 +40,7 @@
"inLocal": "您當前控制的伺服器在本地,可以控制伺服器檔",
"removeDownloadFolderFiles": "刪除下載檔案夾內檔",
"fileRemoveComplete": "檔刪除成功",
"tgCommandsetTorrentOrMagnetDownloadModeDes": "設置Torrent/Magnet下載模式",
"tgCommandSetTorrentOrMagnetDownloadModeDes": "設置Torrent/Magnet下載模式",
"selectATMMode": "選擇一個Torrent/Magnet下載模式",
"tmMode1": "只下載最大的文件",
"tmMode2": "智能選擇大檔",
Expand Down

0 comments on commit 9356406

Please sign in to comment.