Skip to content

Commit

Permalink
fix: fix configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
en9inerd committed Feb 13, 2024
1 parent c2335bf commit c9af714
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
38 changes: 19 additions & 19 deletions config/default.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
// default example
// import { readFile } from 'fs/promises';
// example of config file
import { readFile } from 'fs/promises';

// const version = JSON.parse(await readFile(new URL('../package.json', import.meta.url))).version;
// App version
const version = JSON.parse(await readFile(new URL('../package.json', import.meta.url))).version;

export default {
botConfig: {
botDataDir: process.env.TG_BOT_DIR_INFO || './botData',
apiId: parseInt(process.env.TG_BOT_API_ID),
apiHash: process.env.TG_BOT_API_HASH,
token: process.env.TG_BOT_TOKEN,
deviceModel: process.env.TG_BOT_DEVICE_MODEL || 'Linux BotServer',
appVersion: process.env.TG_BOT_APP_VERSION || '1.0',
systemVersion: process.env.TG_BOT_SYSTEM_VERSION || '1.0',
connectionLangCode: process.env.TG_BOT_CONNECTION_LANG_CODE || 'en',
systemLangCode: process.env.TG_BOT_SYSTEM_LANG_CODE || 'en',
connectionRetries: parseInt(process.env.TG_BOT_CONNECTION_RETRIES) || 5,
useWSS: process.env.TG_BOT_USE_WSS?.toLowerCase() === 'true',
testServers: process.env.TG_BOT_TEST_SERVERS?.toLowerCase() === 'true',
appVersion: process.env.TG_BOT_APP_VERSION || version,
// systemVersion: process.env.TG_BOT_SYSTEM_VERSION || '',
// connectionLangCode: process.env.TG_BOT_CONNECTION_LANG_CODE || 'en',
// systemLangCode: process.env.TG_BOT_SYSTEM_LANG_CODE || 'en',
// connectionRetries: parseInt(process.env.TG_BOT_CONNECTION_RETRIES) || Infinity,
// useWSS: process.env.TG_BOT_USE_WSS?.toLowerCase() === 'true',
// testServers: process.env.TG_BOT_TEST_SERVERS?.toLowerCase() === 'true',

dcId: parseInt(process.env.TG_BOT_DC_ID) || null,
serverAddress: process.env.TG_BOT_SERVER_ADDRESS || '',
serverPort: parseInt(process.env.TG_BOT_SERVER_PORT) || null,
// dcId: parseInt(process.env.TG_BOT_DC_ID) || null,
// serverAddress: process.env.TG_BOT_SERVER_ADDRESS || '',
// serverPort: parseInt(process.env.TG_BOT_SERVER_PORT) || null,

// Bot info
profilePhotoUrl: process.env.TG_BOT_PROFILE_PHOTO_URL || null,
name: process.env.TG_BOT_NAME || 'TeleBuilder Bot',
about: process.env.TG_BOT_ABOUT || 'TeleBuilder Bot about',
description: process.env.TG_BOT_DESCRIPTION || 'TeleBuilder Bot description',
botInfoLangCode: process.env.TG_BOT_INFO_LANG_CODE || '',
// profilePhotoUrl: process.env.TG_BOT_PROFILE_PHOTO_URL || null,
// name: process.env.TG_BOT_NAME || 'TeleBuilder Bot',
// about: process.env.TG_BOT_ABOUT || 'TeleBuilder Bot about',
// description: process.env.TG_BOT_DESCRIPTION || 'TeleBuilder Bot description',
// botInfoLangCode: process.env.TG_BOT_INFO_LANG_CODE || '',
}
};
38 changes: 19 additions & 19 deletions src/clients/bot.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,30 @@ export class TelegramBotClient extends TelegramClient {
constructor(
protected readonly params?: ClientParams
) {
const sessionName = config.get<string>('botConfig.testServers') ? 'testSession' : 'session';
const sessionName = config.get<boolean>('botConfig.testServers', false) ? 'testSession' : 'session';

super(
new StringSession(Store.get(sessionName, '')),
config.get('botConfig.apiId'),
config.get('botConfig.apiHash'),
{
baseLogger: params?.baseLogger,
connectionRetries: config.get('botConfig.connectionRetries'),
deviceModel: config.get('botConfig.deviceModel'),
connectionRetries: config.get('botConfig.connectionRetries', Infinity),
deviceModel: config.get<string>('botConfig.deviceModel', ''),
appVersion: config.get('botConfig.appVersion'),
systemVersion: config.get('botConfig.systemVersion'),
langCode: config.get('botConfig.connectionLangCode'),
systemLangCode: config.get('botConfig.systemLangCode'),
testServers: config.get('botConfig.testServers'),
useWSS: config.get('botConfig.useWSS'),
systemVersion: config.get<string>('botConfig.systemVersion', ''),
langCode: config.get<string>('botConfig.connectionLangCode', 'en'),
systemLangCode: config.get<string>('botConfig.systemLangCode', 'en'),
testServers: config.get<boolean>('botConfig.testServers', false),
useWSS: config.get<boolean>('botConfig.useWSS', true),
},
);
this.sessionName = sessionName;
container.client = this;

const dcId = config.get<number>('botConfig.dcId');
const serverAddress = config.get<string>('botConfig.serverAddress');
const serverPort = config.get<number>('botConfig.serverPort');
const dcId = config.get<number | null>('botConfig.dcId', null);
const serverAddress = config.get<string>('botConfig.serverAddress', '');
const serverPort = config.get<number | null>('botConfig.serverPort', null);
if (dcId && serverAddress && serverPort && !this.session.serverAddress) {
this.session.setDC(dcId, serverAddress, serverPort);
}
Expand Down Expand Up @@ -114,7 +114,7 @@ export class TelegramBotClient extends TelegramClient {
private async initBot(): Promise<void> {
// Start the bot
await this.start({
botAuthToken: config.get('botConfig.token'),
botAuthToken: config.get<string>('botConfig.token'),
});

// Save the session if it doesn't exist
Expand Down Expand Up @@ -260,7 +260,7 @@ export class TelegramBotClient extends TelegramClient {
}

private async uploadProfilePhoto(): Promise<void> {
const profilePhotoUrl = config.get<string>('botConfig.profilePhotoUrl');
const profilePhotoUrl = config.get<string | null>('botConfig.profilePhotoUrl', null);
if (profilePhotoUrl) {
const response = await fetch(profilePhotoUrl);
const extension = response.headers.get('content-type')?.split('/')[1];
Expand All @@ -284,20 +284,20 @@ export class TelegramBotClient extends TelegramClient {
}

private async updateProfileInfo(): Promise<void> {
const name = config.get<string>('botConfig.name');
const about = config.get<string>('botConfig.about');
const description = config.get<string>('botConfig.description');
const langCode = config.get<string>('botConfig.botInfoLangCode');
const name = config.get<string>('botConfig.name', '');
const about = config.get<string>('botConfig.about', '');
const description = config.get<string>('botConfig.description', '');
const langCode = config.get<string>('botConfig.botInfoLangCode', '');

const botInfo = await this.invoke(
new Api.bots.GetBotInfo({
langCode
}),
);

if (botInfo?.description !== description ||
if ((botInfo?.description !== description ||
botInfo?.about !== about ||
botInfo?.name !== name
botInfo?.name !== name) && (description || about || name)
) {
await this.invoke(
new Api.bots.SetBotInfo({
Expand Down

0 comments on commit c9af714

Please sign in to comment.