Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require('axios');
- module.exports = {
- config: {
- name: 'stackoverflow',
- aliases: 'stack',
- version: '1.0',
- author: 'Samir ล , Faith Xe',
- countDown: 5,
- role: 0,
- shortDescription: {
- en: 'Stack Overflow search'
- },
- longDescription: {
- en: 'Search for a question on Stack Overflow'
- },
- category: 'programming',
- guide: {
- en: '{prefix}stackoverflow <search query>'
- }
- },
- onStart: async function ({ api, event, args }) {
- const searchQuery = args.join(' ');
- if (!searchQuery) {
- return api.sendMessage('Please provide a search query.', event.threadID, event.messageID);
- }
- try {
- const apiUrl = `https://api-samir.onrender.com/stackoverflow/search?q=${encodeURIComponent(searchQuery)}`;
- const response = await axios.get(apiUrl);
- const items = response.data.items;
- if (!items || items.length === 0) {
- return api.sendMessage('No results found on Stack Overflow.', event.threadID, event.messageID);
- }
- const selectedResult = items[Math.floor(Math.random() * items.length)]; // Randomly select a result
- const ownerInfo = selectedResult.owner;
- const profileImage = ownerInfo.profile_image;
- const message = {
- body: `๐ณ ๐๐ฉ๐๐๐ ๐๐ซ๐๐ง๐๐ก๐ค๐ฌ ๐๐๐จ๐ช๐ก๐ฉ๐จ๐ฌ \n` +
- `โโโโโโโโโโโโโโโโโ\n` +
- `๐ ๐๐ข๐ญ๐ฅ๐: ${selectedResult.title}\n\n` +
- `๐ท ๐๐๐ ๐ฌ: ${selectedResult.tags.join(', ')}\n\n` +
- `๐ ๐๐ข๐๐ฐ ๐๐จ๐ฎ๐ง๐ญ: ${selectedResult.view_count}\n\n` +
- `๐ค ๐๐ข๐ฌ๐ฉ๐ฅ๐๐ฒ ๐๐๐ฆ๐: ${ownerInfo.display_name}\n\n` +
- `๐ฌ ๐๐ง๐ฌ๐ฐ๐๐ซ ๐๐จ๐ฎ๐ง๐ญ: ${selectedResult.answer_count}\n\n` +
- `๐ ๐๐ซ๐๐๐ญ๐ข๐จ๐ง ๐๐๐ญ๐: ${new Date(selectedResult.creation_date * 1000).toLocaleString()}\n\n` +
- `๐ ๐๐๐ฌ๐ญ ๐๐๐ญ๐ข๐ฏ๐ข๐ญ๐ฒ ๐๐๐ญ๐: ${new Date(selectedResult.last_activity_date * 1000).toLocaleString()}\n\n` +
- `โญ ๐๐๐จ๐ซ๐: ${selectedResult.score}\n\n` +
- `โ ๐๐๐๐๐ฉ๐ญ ๐๐๐ญ๐: ${ownerInfo.accept_rate ? ownerInfo.accept_rate + '%' : 'N/A'}\n\n` +
- `๐ ๐๐ข๐ง๐ค: ${selectedResult.link}`,
- attachment: await global.utils.getStreamFromURL(profileImage)
- };
- return api.sendMessage(message, event.threadID, event.messageID);
- } catch (error) {
- console.error(error);
- return api.sendMessage('An error occurred while searching on Stack Overflow.', event.threadID, event.messageID);
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement