kowalski/commands/info.js

60 lines
2.1 KiB
JavaScript
Raw Normal View History

2024-07-25 23:57:38 -03:00
const { getStrings } = require('../plugins/checklang.js');
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
2024-07-24 22:39:27 -03:00
async function getUserInfo(ctx) {
const Strings = getStrings(ctx.from.language_code);
2024-07-24 22:39:27 -03:00
userInfo = Strings.userInfo
2024-09-06 21:56:19 -03:00
.replace('{userName}', `${ctx.from.first_name} ${ctx.from.last_name}` || Strings.unKnown)
.replace('{userId}', ctx.from.id || Strings.unKnown)
.replace('{userHandle}', ctx.from.username ? `@${ctx.from.username}` : Strings.varNone)
.replace('{userPremium}', ctx.from.is_premium ? Strings.varYes : Strings.varNo)
.replace('{userLang}', ctx.from.language_code || Strings.unKnown);
2024-07-24 22:39:27 -03:00
return userInfo;
2024-07-24 22:39:27 -03:00
}
async function getChatInfo(ctx) {
const Strings = getStrings(ctx.from.language_code);
2024-07-24 22:39:27 -03:00
if (ctx.chat.type === 'group' || ctx.chat.type === 'supergroup') {
chatInfo = Strings.chatInfo
.replace('{chatId}', ctx.chat.id || Strings.unKnown)
.replace('{chatName}', ctx.chat.title || Strings.unKnown)
.replace('{chatHandle}', ctx.chat.username ? `@${ctx.chat.username}` : Strings.varNone)
.replace('{chatMembersCount}', await ctx.getChatMembersCount(ctx.chat.id || Strings.unKnown))
.replace('{chatType}', ctx.chat.type || Strings.unKnown)
.replace('{isForum}', ctx.chat.is_forum ? Strings.varYes : Strings.varNo);
2024-07-24 22:39:27 -03:00
return chatInfo;
2024-07-24 22:39:27 -03:00
} else {
return ctx.reply(
Strings.groupOnly, {
parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id
});
2024-07-24 22:39:27 -03:00
}
}
module.exports = (bot) => {
bot.command('chatinfo', spamwatchMiddleware, async (ctx) => {
2024-07-24 22:39:27 -03:00
const chatInfo = await getChatInfo(ctx);
ctx.reply(
chatInfo, {
2024-07-25 03:55:05 +00:00
parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id
2024-07-24 22:39:27 -03:00
}
);
});
bot.command('userinfo', spamwatchMiddleware, async (ctx) => {
2024-07-24 22:39:27 -03:00
const userInfo = await getUserInfo(ctx);
ctx.reply(
userInfo, {
2024-07-25 03:55:05 +00:00
parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id,
2024-07-24 22:39:27 -03:00
}
);
});
};