Skip to content

Commit

Permalink
Tag user after download is completed
Browse files Browse the repository at this point in the history
  • Loading branch information
jashasweejena authored and out386 committed Oct 10, 2019
1 parent 19f465c commit 71c74e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ client_secret.json
credentials.json
npm-debug.log
out/
package-lock.json
18 changes: 12 additions & 6 deletions src/dl_model/detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export class DlVars {
gid: string;
readonly tgFromId: number;
readonly tgUsername: string;
readonly tgRepliedUsername: string;
readonly tgChatId: number;
readonly tgMessageId: number;
readonly startTime: number;
Expand All @@ -16,19 +17,24 @@ export class DlVars {
readonly downloadDir: string;

constructor(gid: string, msg: TelegramBot.Message, readonly isTar: boolean, downloadDir: string) {
var username: string;
if (msg.from.username) {
username = `@${msg.from.username}`;
} else {
username = `<a href="tg://user?id=${msg.from.id}">${msg.from.first_name}</a>`;
this.tgUsername = getUsername(msg);
if (msg.reply_to_message) {
this.tgRepliedUsername = getUsername(msg.reply_to_message);
}

this.gid = gid;
this.downloadDir = downloadDir;
this.tgFromId = msg.from.id;
this.tgUsername = username;
this.tgChatId = msg.chat.id;
this.tgMessageId = msg.message_id;
this.startTime = new Date().getTime();
}
}

function getUsername(msg: TelegramBot.Message): string {
if (msg.from.username) {
return `@${msg.from.username}`;
} else {
return `<a href="tg://user?id=${msg.from.id}">${msg.from.first_name}</a>`;
}
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ function cleanupDownload(gid: string, message: string, url?: string, dlDetails?:
if (!wasCancelAlled) {
// If the dl was stopped with a cancelAll command, a message has already been sent to the chat.
// Do not send another one.
if (dlDetails.tgRepliedUsername) {
message += `\ncc: ${dlDetails.tgRepliedUsername}`;
}
msgTools.sendMessageReplyOriginal(bot, dlDetails, message)
.catch((err) => {
console.error(`cleanupDownload sendMessage error: ${err.message}`);
Expand Down

0 comments on commit 71c74e1

Please sign in to comment.