Spaces:
Paused
Paused
| import axios from 'axios'; | |
| import config from '../../config.cjs'; | |
| const githubStalk = async (m, gss) => { | |
| try { | |
| const prefix = config.PREFIX; | |
| const cmd = m.body.startsWith(prefix) ? m.body.slice(prefix.length).split(' ')[0].toLowerCase() : ''; | |
| const text = m.body.slice(prefix.length + cmd.length).trim(); | |
| const args = text.split(' '); | |
| const validCommands = ['githubstalk', 'ghstalk']; | |
| if (validCommands.includes(cmd)) { | |
| if (!args[0]) return m.reply('Mention a GitHub username to stalk.'); | |
| const username = args[0]; | |
| try { | |
| // Fetch GitHub user data using Axios | |
| const githubResponse = await axios.get(`https://api.github.com/users/${username}`); | |
| const userData = githubResponse.data; | |
| if (githubResponse.status !== 200) { | |
| return m.reply(`β GitHub user not found.`); | |
| } | |
| // Construct the response message | |
| let responseMessage = `π *GitHub Profile - @${userData.login}*\n\n`; | |
| responseMessage += ` β¦ *Name*: ${userData.name || 'N/A'}\n`; | |
| responseMessage += ` β¦ *Username*: @${userData.login}\n`; | |
| responseMessage += ` β¦ *Bio*: ${userData.bio || 'N/A'}\n`; | |
| responseMessage += ` β¦ *ID*: ${userData.id}\n`; | |
| responseMessage += ` β¦ *Node ID*: ${userData.node_id}\n`; | |
| responseMessage += ` β¦ *Profile URL*: ${userData.avatar_url}\n`; | |
| responseMessage += ` β¦ *GitHub URL*: ${userData.html_url}\n`; | |
| responseMessage += ` β¦ *Type*: ${userData.type}\n`; | |
| responseMessage += ` β¦ *Admin*: ${userData.site_admin ? 'Yes' : 'No'}\n`; | |
| responseMessage += ` β¦ *Company*: ${userData.company || 'N/A'}\n`; | |
| responseMessage += ` β¦ *Blog*: ${userData.blog || 'N/A'}\n`; | |
| responseMessage += ` β¦ *Location*: ${userData.location || 'N/A'}\n`; | |
| responseMessage += ` β¦ *Email*: ${userData.email || 'N/A'}\n`; | |
| responseMessage += ` β¦ *Public Repositories*: ${userData.public_repos}\n`; | |
| responseMessage += ` β¦ *Public Gists*: ${userData.public_gists}\n`; | |
| responseMessage += ` β¦ *Followers*: ${userData.followers}\n`; | |
| responseMessage += ` β¦ *Following*: ${userData.following}\n`; | |
| responseMessage += ` β¦ *Created At*: ${userData.created_at}\n`; | |
| responseMessage += ` β¦ *Updated At*: ${userData.updated_at}\n`; | |
| const githubReposResponse = await axios.get(`https://api.github.com/users/${username}/repos?per_page=5&sort=stargazers_count&direction=desc`); | |
| const reposData = githubReposResponse.data; | |
| if (reposData.length > 0) { | |
| const topRepos = reposData.slice(0, 5); // Display the top 5 starred repositories | |
| const reposList = topRepos.map(repo => { | |
| return ` β¦ *Repository*: [${repo.name}](${repo.html_url}) | |
| β¦ *Description*: ${repo.description || 'N/A'} | |
| β¦ *Stars*: ${repo.stargazers_count} | |
| β¦ *Forks*: ${repo.forks}`; | |
| }); | |
| const reposCaption = `π *Top Starred Repositories*\n\n${reposList.join('\n\n')}`; | |
| responseMessage += `\n\n${reposCaption}`; | |
| } else { | |
| responseMessage += `\n\nNo public repositories found.`; | |
| } | |
| // Send the message with the updated caption and user's avatar | |
| await gss.sendMessage(m.from, { image: { url: userData.avatar_url }, caption: responseMessage }, { quoted: m }); | |
| } catch (error) { | |
| console.error('Error fetching GitHub data:', error); | |
| await gss.sendMessage(m.from, 'An error occurred while fetching GitHub data.', { quoted: m }); | |
| } | |
| } | |
| } catch (error) { | |
| console.error('Error processing the command:', error); | |
| m.reply('An error occurred while processing the command.'); | |
| } | |
| }; | |
| export default githubStalk; | |