Skip to content

Commit

Permalink
minor corrects
Browse files Browse the repository at this point in the history
  • Loading branch information
chupapee committed Jul 12, 2023
1 parent 06f4f85 commit 18e2044
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 29 deletions.
7 changes: 4 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ PROD_BOT_TOKEN=
# dev
DEV_BOT_TOKEN=

# bot's author telegram id
BOT_AUTHOR_ID=
# telegram id of bot admin
BOT_ADMIN_ID=

# pages url to scrape
# scraping page urls
TWITTER_PAGE_URL=
INSTA_PAGE_URL=
YOUTUBE_PAGE_URL=
TIKTOK_PAGE_URL=

# firebase config variables for analytics data collection
FIREBASE_API_KEY=
Expand Down
2 changes: 1 addition & 1 deletion ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
apps: [
{
name: 'social-media-bot',
name: 'social-media-downloader-bot',
script: './dist/index.js',
instances: 1,
autorestart: true,
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "insta-twitter-youtube-bot",
"name": "social-media-downloader-bot",
"version": "1.0.0",
"main": "./src/index.ts",
"author": "k.khamidov <khamidoff09@gmail.com>",
Expand All @@ -13,9 +13,9 @@
"format": "prettier --write ./src/*",

"process:start": "yarn build && npx pm2 start ecosystem.config.js",
"process:stop": "npx pm2 stop social-media-bot",
"process:delete": "npx pm2 delete social-media-bot",
"process:restart": "yarn build && npx pm2 restart social-media-bot",
"process:stop": "npx pm2 stop social-media-downloader-bot",
"process:delete": "npx pm2 delete social-media-downloader-bot",
"process:restart": "yarn build && npx pm2 restart social-media-downloader-bot",
"update": "git pull && yarn process:restart"
},
"dependencies": {
Expand Down
8 changes: 4 additions & 4 deletions src/entities/storage/api/storageApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { doc, getDoc, updateDoc } from '@firebase/firestore';

import { BOT_AUTHOR_ID, db } from '../../../shared/config';
import { BOT_ADMIN_ID, db } from '../../../shared/config';
import {
DatabaseEntities,
DatabaseUser,
Expand All @@ -22,7 +22,7 @@ export async function getUsers(
if (appType) return response[appType];
return response;
} catch (error) {
console.log(error, 'GETTING DB USERS FAILED');
console.error(error, 'GETTING DB USERS FAILED');
}
}

Expand All @@ -36,7 +36,7 @@ export async function saveUser(
newUser: DatabaseUser,
appType: SocialMediaType
) {
if (newUser.id !== BOT_AUTHOR_ID) {
if (newUser.id !== BOT_ADMIN_ID) {
const usersRef = doc(db, 'users', 'list');
const updatedUsers = [...oldUsers, updatable(newUser)];
try {
Expand All @@ -45,7 +45,7 @@ export async function saveUser(
});
console.log('USER SAVED SUCCESSFULLY');
} catch (error) {
console.log(error, 'SAVING USER IN DB FAILED');
console.error(error, 'SAVING USER IN DB FAILED');
}
}
};
2 changes: 1 addition & 1 deletion src/entities/twitter/model/processTweetJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const processTweetJson = (
const { quoted_status_result } = tweetJson.data!.tweetResult.result;
if (quoted_status_result?.result) {
const quotedTweet = processQuotedTweet(tweetJson, originalLink);
fullCaption += `\n\n<strong>↩️ Reply to </strong>${quotedTweet}`;
fullCaption += `\n\n<strong>↩️ Replying to </strong>${quotedTweet}`;
}

return {
Expand Down
4 changes: 2 additions & 2 deletions src/features/onBotUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export const onBotUp = async () => {
);
await timeout(500);
} catch (error) {
console.log(error, 'here');
console.error(error, 'onBotUp error');
}
}
toggleBotUpFlag();
}
} catch (error) {
console.log(error, 'wakeUp error');
console.error(error, 'onBotUp error');
}
};
2 changes: 1 addition & 1 deletion src/features/storage/saveFeedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export const saveFeedback = async (feedback: Feedback) => {
});
console.log('FEEDBACK SAVED SUCCESSFULLY');
} catch (error) {
console.log(error, 'SAVING FEEDBACK FAILED');
console.error(error, 'SAVING FEEDBACK FAILED');
}
};
2 changes: 1 addition & 1 deletion src/features/storage/saveServiceFinisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export async function saveServiceFinisher(
const oldUsers = await getUsers(socialMediaType);
if (oldUsers) await saveUser(oldUsers, newUser, socialMediaType);
} catch (error) {
console.log(error, 'ERROR saveServiceFinish');
console.error(error, 'ERROR saveServiceFinish');
}
}
2 changes: 1 addition & 1 deletion src/features/storage/saveServiceInitiator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export const saveServiceInitiator = async (
const oldUsers = await getUsers(socialMediaType);
if (oldUsers) await saveUser(oldUsers, newUser, socialMediaType);
} catch (error) {
console.log(error, 'ERROR saveServiceInitiator');
console.error(error, 'ERROR saveServiceInitiator');
}
};
2 changes: 1 addition & 1 deletion src/features/storage/toggleBotUpFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export const toggleBotUpFlag = async () => {
try {
await updateDoc(usersRef, { socialBotUpFlag: true });
} catch (error) {
console.log(error, 'SAVING USER FAILED');
console.error(error, 'SAVING USER FAILED');
}
};
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bot.use(i18n.middleware());
bot.use(stage.middleware());

bot.catch((error) => {
console.log(error, 'INDEX.TS');
console.error(error, 'INDEX.TS');
});

onBotUp();
Expand Down
2 changes: 1 addition & 1 deletion src/scenes/tiktok/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ tiktokScene.enter((ctx) => {
await ctx.reply(ctx.i18n.t('incorrectLink'));
break;
default:
console.log(error, 'ERROR');
console.error(error, 'ERROR');
await ctx.reply(ctx.i18n.t('smthWentWrong'));
}
throw new Error(error.message);
Expand Down
2 changes: 1 addition & 1 deletion src/scenes/twitter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ twitterScene.enter(async (ctx) => {
},
});
} catch (error) {
console.log(error, 'error message');
console.error(error, 'error message');
await ctx.reply(ctx.i18n.t('smthWentWrong'));
if (error instanceof Error) throw new Error(error.message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/scenes/youtube/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ youtubeScene.enter((ctx) => {
);
}
} catch (error) {
console.log(error);
console.error(error);
await ctx.reply(ctx.i18n.t('smthWentWrong'));
if (error instanceof Error) throw new Error(error.message);
}
Expand Down
5 changes: 2 additions & 3 deletions src/shared/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ export const BOT_TOKEN = isDevEnv
? getEnvVar('DEV_BOT_TOKEN')
: getEnvVar('PROD_BOT_TOKEN');

/** bot's author telegram id */
export const BOT_AUTHOR_ID = Number(getEnvVar('BOT_AUTHOR_ID'));
/** Telegram id of bot admin */
export const BOT_ADMIN_ID = Number(getEnvVar('BOT_ADMIN_ID'));

/** Pages url to scrape */
/** Scraping page urls */
export const TWITTER_PAGE_URL = getEnvVar('TWITTER_PAGE_URL');
export const INSTA_PAGE_URL = getEnvVar('INSTA_PAGE_URL');
export const TIKTOK_PAGE_URL = getEnvVar('TIKTOK_PAGE_URL');
Expand Down
4 changes: 2 additions & 2 deletions src/shared/notifyAdmin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { User } from 'typegram';

import { bot } from '../index';
import { BOT_ADMIN_ID, BOT_AUTHOR_ID } from './config';
import { BOT_ADMIN_ID } from './config';

interface NotifyAdminFullArgs {
user?: User;
Expand All @@ -20,7 +20,7 @@ export const notifyAdmin = ({
if (user) {
const formattedUser = JSON.stringify(user, null, 2);
bot.telegram.sendMessage(
BOT_AUTHOR_ID,
BOT_ADMIN_ID,
`From: ${formattedUser}${formattedText}${formattedLink}`
);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const retryGettingPage = async <T>(
try {
content = await Promise.race([timeout(timeoutNum), getPage(link)]);
} catch (error) {
console.log(error, 'puppeeter page preparing failed');
console.error(error, 'puppeeter page preparing failed');
}
attemptsCount++;
}
Expand Down

0 comments on commit 18e2044

Please sign in to comment.