Skip to content

Commit

Permalink
chore: better /setcommands feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Oct 28, 2024
1 parent 33c6d5c commit 282398f
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/bot/setcommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,38 +120,61 @@ function getGroupChatCommands(): BotCommand[] {
}

export async function setCommandsHandler(ctx: CommandContext<GrammyContext>) {

const updatedCommands = {
private_chat: false,
group_chat: false,
owner: false,
}

// set private chat commands
try {
await ctx.api.setMyCommands([...getPrivateChatCommands()], {
scope: {
type: "all_private_chats",
},
});

updatedCommands.private_chat = true;
} catch (err) {
logger.error("Error setting private chat commands", { err });
}

// set group chat commands
await ctx.api.setMyCommands(getGroupChatCommands(), {
scope: {
type: "all_group_chats",
},
});

logger.info("Setting admin commands");
try {
// set group chat commands
await ctx.api.setMyCommands(getGroupChatCommands(), {
scope: {
type: "all_group_chats",
},
});

updatedCommands.group_chat = true;
} catch (err) {
logger.error("Error setting group chat commands", { err });
}


// set private chat commands for owner

try {
await ctx.api.setMyCommands([...getPrivateChatCommands(), ...getPrivateChatAdminCommands()], {
scope: {
type: "chat",
chat_id: ctx.from?.id ?? ctx.chat?.id,
},
});

updatedCommands.owner = true;
} catch (er) {
logger.error("Error setting private chat commands for owner", { er });
}

return ctx.reply("admin-commands-updated");
const msgParts = [
`Commands updated:`,
`Private chat commands: ${updatedCommands.private_chat ? "✅" : "❌"}`,
`Group chat commands: ${updatedCommands.group_chat ? "✅" : "❌"}`,
`Owner commands: ${updatedCommands.owner ? "✅" : "❌"}`,
]

return ctx.reply(msgParts.join("\n"));
}

0 comments on commit 282398f

Please sign in to comment.