Skip to content

Commit

Permalink
Cleanup, formating
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrijs-pavlovs-dev committed Dec 18, 2023
1 parent be3a2e0 commit ad55a5d
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions apps/backend/src/services/bot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,13 @@ export class BotService {
@Command('getuserid')
async getUserId(@Ctx() ctx: Context) {
const user = await this.userRepository.findOne({ where: { id: ctx.from.id.toString() } });
// Check if the user is an admin
if (!user || !user.is_admin) {
await ctx.reply('You are not authorized to use this command.');
return;
}
if ('text' in ctx.message) {
const args = ctx.message.text.split(' ').slice(1);
const username = args[0];
console.log('Username to find:', username);

if (!username) {
await ctx.reply('Please provide a username.');
Expand All @@ -87,24 +85,21 @@ export class BotService {
const botToken = this.configService.get<string>('TELEGRAM_BOT_TOKEN');
const appId = this.configService.get<number>('TELEGRAM_APP_ID');
const appIdHash = this.configService.get<string>('TELEGRAM_APP_ID_HASH');
(async () => {
try {
const client = new TelegramClient(new StringSession(stringSession), Number(appId), appIdHash, {
connectionRetries: 5,
});
await client.start({
botAuthToken: botToken,
});
client.session.save();
const userEntity = await client.getInputEntity(username);
if ('userId' in userEntity) {
await ctx.reply('User ID: ' + userEntity.userId);
}
} catch (error) {
console.error('Error retrieving user information:', error);
await ctx.reply('Error retrieving user information:' + error.message);
try {
const client = new TelegramClient(new StringSession(stringSession), Number(appId), appIdHash, {
connectionRetries: 5,
});
await client.start({
botAuthToken: botToken,
});
client.session.save();
const userEntity = await client.getInputEntity(username);
if ('userId' in userEntity) {
await ctx.reply('User ID: ' + userEntity.userId);
}
})();
} catch (error) {
await ctx.reply('Error retrieving user information:' + error.message);
}
} else {
await ctx.reply('This command requires a text message.');
}
Expand Down

0 comments on commit ad55a5d

Please sign in to comment.