Skip to content

Commit

Permalink
solved #11
Browse files Browse the repository at this point in the history
  • Loading branch information
gaowanliang committed Jan 26, 2021
1 parent 22708e6 commit 06e8a3e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Aria2.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func formatTellSomething(info []rpc.StatusInfo, err error) string {
m["CompletedLength"] = byte2Readable(completedLength)
m["Progress"] = printProgressBar(completedLength * 100.0 / bytes)
m["Threads"] = "-"
m["Seeders"] = Files.NumSeeders
m["Peers"] = Files.Connections
downloadSpeed, err := strconv.ParseFloat(Files.DownloadSpeed, 64)
dropErr(err)
m["Speed"] = byte2Readable(downloadSpeed)
Expand Down Expand Up @@ -123,7 +125,7 @@ func formatTellSomething(info []rpc.StatusInfo, err error) string {
res += fmt.Sprintf(locText("queryInformationFormat2"), m["Name"], m["Status"], m["Progress"], m["CompletedLength"], m["Size"], m["Threads"], m["GID"])
} else {
//res += fmt.Sprintf(locText("queryInformationFormat3"), m["GID"], m["Name"], m["Progress"], m["Size"], m["Speed"])
res += fmt.Sprintf(locText("queryInformationFormat3"), m["Name"], m["Progress"], m["CompletedLength"], m["Size"], m["Speed"], m["remainingTime"], m["Threads"], m["GID"])
res += fmt.Sprintf(locText("queryInformationBTFormat3"), m["Name"], m["Progress"], m["CompletedLength"], m["Size"], m["Speed"], m["remainingTime"], m["Seeders"], m["Peers"], m["GID"])
}
} else {
for _, File := range Files.Files {
Expand Down
25 changes: 19 additions & 6 deletions Telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TMSelectMessage(bot *tgBotApi.BotAPI) {
var MessageID = 0
var lastGid = ""
var lastFilesInfo [][]string
myID := toInt64(info.UserID)
for {
a := <-TMSelectMessageChan
b := strings.Split(a, "~")
Expand All @@ -68,6 +69,7 @@ func TMSelectMessage(bot *tgBotApi.BotAPI) {
if len(b) != 1 {
if b[1] == "Start" {
setTMDownloadFilesAndStart(gid, lastFilesInfo)
bot.Send(tgBotApi.NewDeleteMessage(myID, MessageID))
break
}
for i := 0; i < len(lastFilesInfo); i++ {
Expand Down Expand Up @@ -157,8 +159,8 @@ func TMSelectMessage(bot *tgBotApi.BotAPI) {
inlineKeyBoardRow = make([]tgBotApi.InlineKeyboardButton, 0)
inlineKeyBoardRow = append(inlineKeyBoardRow, tgBotApi.NewInlineKeyboardButtonData(locText("startDownload"), gid+"~Start"+":7"))
Keyboards = append(Keyboards, inlineKeyBoardRow)
myID, err := strconv.ParseInt(info.UserID, 10, 64)
dropErr(err)
//myID, err := strconv.ParseInt(info.UserID, 10, 64)
//dropErr(err)
msg := tgBotApi.NewMessage(myID, text)
lastFilesInfo = fileList
if lastGid != gid {
Expand Down Expand Up @@ -391,6 +393,17 @@ func uploadFiles(chatMsgID int, chatMsg string, bot *tgBotApi.BotAPI) {
mail := getNewOneDriveInfo(chatMsg)
text = locText("oneDriveOAuthFileCreateSuccess") + mail
}
case "googledDrive":
switch b[1] {
case "new":
text = fmt.Sprintf(
`%s https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=ad5e65fd-856d-4356-aefc-537a9700c137&response_type=code&redirect_uri=http://localhost/onedrive-login&response_mode=query&scope=offline_access%%20User.Read%%20Files.ReadWrite.All`,
locText("oneDriveGetAccess"),
)
case "create":
mail := getNewOneDriveInfo(chatMsg)
text = locText("oneDriveOAuthFileCreateSuccess") + mail
}
case "odInfo":
uploadDFToOneDrive("./info/onedrive/" + b[1])
default:
Expand Down Expand Up @@ -450,10 +463,10 @@ func uploadFiles(chatMsgID int, chatMsg string, bot *tgBotApi.BotAPI) {
}
dir, _ := ioutil.ReadDir("./info/googleDrive")
if len(dir) == 0 {
text = locText("noOneDriveInfo")
text = "没有Google Drive上传配置,是否需要新建配置"
inlineKeyBoardRow := make([]tgBotApi.InlineKeyboardButton, 0)
inlineKeyBoardRow = append(inlineKeyBoardRow, tgBotApi.NewInlineKeyboardButtonData(locText("yes"), "onedrive~new"+":9"))
inlineKeyBoardRow = append(inlineKeyBoardRow, tgBotApi.NewInlineKeyboardButtonData(locText("no"), "onedrive~cancel"+":9"))
inlineKeyBoardRow = append(inlineKeyBoardRow, tgBotApi.NewInlineKeyboardButtonData(locText("yes"), "googleDrive~new"+":9"))
inlineKeyBoardRow = append(inlineKeyBoardRow, tgBotApi.NewInlineKeyboardButtonData(locText("no"), "googleDrive~cancel"+":9"))
Keyboards = append(Keyboards, inlineKeyBoardRow)
} else {
text = locText("accountsAreCurrentlyLogin")
Expand Down Expand Up @@ -580,7 +593,7 @@ func activeRefresh(chatMsgID int, bot *tgBotApi.BotAPI, ticker *time.Ticker, fla

func refreshPath(MessageID int, myID int64, bot *tgBotApi.BotAPI, ticker *time.Ticker) int {
res := formatTellSomething(aria2Rpc.TellActive())
log.Println(res, len(res))
//log.Println(res, len(res))
text := ""
if res != "" {
text = res
Expand Down
1 change: 1 addition & 0 deletions i18n/active.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"queryInformationFormat1": "*Filename:* `%s`\n`%s`\n*Downloaded:* %s *of* %s\n*Threads:* %s\n*GID:* `%s`",
"queryInformationFormat2": "*Filename:* `%s`\n*Status:* %s\n`%s`\n*Downloaded:* %s *of* %s\n*Threads:* %s\n*GID:* `%s`",
"queryInformationFormat3": "*Filename:* `%s`\n`%s`\n*Downloaded:* %s *of* %s\n*Speed:* %s/s\n*ETA:* %s\n*Threads:* %s\n*GID:* `%s`",
"queryInformationBTFormat3": "*Filename:* `%s`\n`%s`\n*Downloaded:* %s *of* %s\n*Speed:* %s/s\n*ETA:* %s\n*Seeders:* %s *&* *Peers:* %s\n*GID:* `%s`",
"ResumeAll": "Resume All",
"StopAll": "Stop All",
"downloadFolderClear": "Delete all files in download folder",
Expand Down
1 change: 1 addition & 0 deletions i18n/active.zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"queryInformationFormat1": "*文件名:* `%s`\n`%s`\n*已下载:* %s *共* %s\n*线程数:* %s\n*GID:* `%s`",
"queryInformationFormat2": "*文件名:* `%s`\n*状态:* %s\n`%s`\n*已下载:* %s *共* %s\n*线程数:* %s\n*GID:* `%s`",
"queryInformationFormat3": "*文件名:* `%s`\n`%s`\n*已下载:* %s *共* %s\n*速度:* %s/s\n*剩余时间:* %s\n*线程数:* %s\n*GID:* `%s`",
"queryInformationBTFormat3": "*文件名:* `%s`\n`%s`\n*已下载:* %s *共* %s\n*速度:* %s/s\n*剩余时间:* %s\n*做种者:* %s *&* *下载者:* %s\n*GID:* `%s`",
"ResumeAll": "恢复全部",
"StopAll": "停止全部",
"downloadFolderClear": "删除下载文件夹中所有文件",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func locLan(locLanguage string) {
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
dropErr(err)
ioutil.WriteFile(fmt.Sprintf("i18n/active.%s.json", locLanguage), data, 0644)
ioutil.WriteFile(fmt.Sprintf("i18n/active.%s.json", locLanguage), data, 0666)
} else {
url := "https://cdn.jsdelivr.net/gh/gaowanliang/DownloadBot@latest/i18n/"
j := pageDownload(url)
Expand Down

0 comments on commit 06e8a3e

Please sign in to comment.