Skip to content
This repository has been archived by the owner on Jan 11, 2022. It is now read-only.

Commit

Permalink
Implement whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
andrusha committed Jun 24, 2020
1 parent 8851392 commit c22362e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const config = {
http: {
agent: process.env.HTTP_AGENT,
},
whitelist: process.env.WHITELIST ? process.env.WHITELIST.split(",") : [],
};

const envConfFile = path.resolve(
Expand Down
34 changes: 22 additions & 12 deletions handler/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,33 @@ if (!config.http || !config.http.agent) {
process.exit();
}

const isWhitelisted = (ctx) => {
return (
config.whitelist.length == 0 ||
config.whitelist.includes(ctx.message.from.username)
);
};

// Domain checks
const command = (ctx) => {
if (ctx.message.text) {
let urls = getUrls(ctx.message.text);

urls.forEach((url) => {
if (url.match(/https??:\/\/(vm\.)??tiktok\.com\/(\w|\W|\d)+/)) {
if (ctx.session) {
ctx.session.lookups++;
}
if (!ctx.message.text) return;
if (!isWhitelisted(ctx)) {
return ctx.reply(ctx.i18n.t("errors.whitelist"));
}

ctx.replyWithChatAction("typing");
let urls = getUrls(ctx.message.text);

download(ctx, url);
urls.forEach((url) => {
if (url.match(/https??:\/\/(vm\.)??tiktok\.com\/(\w|\W|\d)+/)) {
if (ctx.session) {
ctx.session.lookups++;
}
});
}

ctx.replyWithChatAction("typing");

download(ctx, url);
}
});
};

// Lookup process
Expand Down
1 change: 1 addition & 0 deletions locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ errors:
url: I can download only TikTok videos and this doesn't look like a valid URL.
http: Couldn't fetch shared URL. Please check if it's available and try again later.
stream: No valid streams were found. Please try again later!
whitelist: You need to be whitelisted to be able to use the bot. Contact administrator.

0 comments on commit c22362e

Please sign in to comment.