Skip to content

Commit

Permalink
total users
Browse files Browse the repository at this point in the history
  • Loading branch information
chisa-dev committed Jan 25, 2025
1 parent 93f3798 commit 0827660
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
19 changes: 18 additions & 1 deletion controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,22 @@ async function getUserDefaultLanguage(chatId) {
}
}

async function getTotalUsers() {
try {
const { count, error } = await supabase
.from('users')
.select('*', { count: 'exact', head: true }); // Count rows without fetching data

if (error) {
console.error('Error getting total users:', error.message);
return 0; // Return 0 if there is an error
}

return count || 0; // Return count or fallback to 0
} catch (error) {
console.error('Unexpected error while getting total users:', error.message);
return 0; // Return 0 if there is an exception
}
}

module.exports = { saveUser, incrementMessageCount, getMessageCount, getUserSettings, updateUserLanguage, getUserDefaultLanguage, checkMessageCount };
module.exports = { saveUser, incrementMessageCount, getMessageCount, getUserSettings, updateUserLanguage, getUserDefaultLanguage, checkMessageCount, getTotalUsers};
19 changes: 17 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ bot.onText(/\/settings/, async (msg) => {
}
);

});


// Handle the /total_users command
bot.onText(/\/total_users/, async (msg) => {
try {
const totalUsers = await db.getTotalUsers();
await bot.sendMessage(chatId, `👥 Total users: *${totalUsers}*`, {
parse_mode: 'Markdown',
});
} catch (error) {
console.error('Error fetching total users:', error);
await bot.sendMessage(chatId, '❌ Unable to fetch total users at the moment.');
}

});

// Inline Query for Translation
Expand Down Expand Up @@ -555,10 +570,10 @@ bot.on('callback_query', async (query) => {

// Handle different feature options
if (query.data.startsWith('translate')){
bot.sendMessage(chatId, '📜 Okay, send me the text you want to translate or fix grammar for.');
bot.sendMessage(chatId, '📜 Okay, send me the text you want to translate.');
}
if (query.data.startsWith('grammar_fix')){
bot.sendMessage(chatId, '🔍 Okay, send me the text you want to fix grammar for.');
bot.sendMessage(chatId, '🔍 Okay, send me the text you want to fix.');
}
if (query.data.startsWith('download_mp3')){
bot.sendMessage(chatId, '🎵 Okay, send me the YouTube video link you want to download as MP3.');
Expand Down

0 comments on commit 0827660

Please sign in to comment.