Added documentation. Protected the command from general use.
This commit is contained in:
@@ -6,23 +6,45 @@ const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType(["group", "supergroup"]);
|
||||
|
||||
/**
|
||||
* What triggers this feature and adds to the log when it has been triggered.
|
||||
* The trigger is the command "/botInfo"
|
||||
*/
|
||||
feature.hears(
|
||||
"/getGroupID",
|
||||
logHandle("get-group-id"),
|
||||
async (ctx: Context) => {
|
||||
// Pulling the group IDs from the env variables.
|
||||
const GROUP_IDS = process.env.GROUP_IDS
|
||||
? process.env.GROUP_IDS.split(",")
|
||||
: undefined;
|
||||
|
||||
if (ctx.chat && ctx.msg) {
|
||||
// Checks if the context has a chat, msg, and from property.
|
||||
if (ctx.chat && ctx.msg && ctx.msg.from) {
|
||||
if (GROUP_IDS !== undefined) {
|
||||
const groupID = ctx.chat.id;
|
||||
const flag = GROUP_IDS.includes(`${groupID}`);
|
||||
|
||||
// Checks if the group is whitelisted
|
||||
if (flag) {
|
||||
await ctx.reply(`The group id is: \`${groupID}\``, {
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
});
|
||||
const chatMember = await ctx.getChatMember(ctx.msg.from.id);
|
||||
|
||||
// Checks if the user is an admin
|
||||
if (["creator", "administrator"].includes(chatMember.status)) {
|
||||
return await ctx.reply(`The group id is: \`${groupID}\``, {
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
});
|
||||
}
|
||||
|
||||
// Send a default message if the user is not an admin
|
||||
return await ctx.reply(
|
||||
`You have to be an admin to use this command\\!`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user