Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubaid7 authored May 6, 2021
1 parent dac5d89 commit ae6b143
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 1 deletion.
36 changes: 36 additions & 0 deletions Episode 40/commands/Main-Commands/Search/djs-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { MessageEmbed } = require('discord.js')
const fetch = require('node-fetch') // npm i node-fetch

module.exports = {
commands: ['djs-docs', 'docs'], // You Can Keep Any Name
description: 'Shows Docs About Something That You Searched.', // Optional

callback: async(message, args, client) => {

const query = args.slice().join(' ')
if(!query) return message.reply('Please Provide A Query To Search For.') // If No Query Is Searched
const url = 'https://djsdocs.sorta.moe/v2/embed?src=stable&q=' + query // From Here BOT Will Send Docs. // <v2> Can Be Chnaged To <v1> // <stable> Can Be Changed To <master>

let response
try {
response = await fetch(url).then(res => res.json())
}
catch (e) {
return message.reply('An Error Occured, Try Again Later.')
}

const pkg = response
const embed = new MessageEmbed()
.setColor('RANDOM')
.setThumbnail('https://cdn.discordapp.com/emojis/586438523796848640.png?v=1') // We Will Keep Discord.JS Thumbnail // You Can Keep Any Thumbnail
.setAuthor(pkg.author.name, pkg.author.icon_url)
.setDescription(pkg.description)
.setTimestamp()
// .setFooter(`Requested By`)
// If The Docs Searched Has Fields
if(pkg.fields) {embed.addFields(pkg.fields)}
// If The Docs Searched Has Title
if(pkg.title) {embed.setTitle(pkg.title)}
message.channel.send(embed)
}
}
36 changes: 36 additions & 0 deletions Episode 40/commands/Main-Commands/Search/github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { MessageEmbed } = require('discord.js')
const fetch = require('node-fetch') // npm i node-fetch

module.exports = {
commands: ['github', 'gh'], // You Can Keep Any Name
description: 'Shows Info About Serched User', // Optional

callback: async(message, args, client) => {

const name = args.join(' ')
if(!name) return message.reply('Provide A Valid User To Search.') // If User Is Not Found On GitHub
const url = `https://api.github.com/users/${name}` // Link From BOT Will Get Info

let response
try{
response = await fetch(url).then(res => res.json())
}
catch(e) {
return message.reply('An Error Occured, Try Again Later.')
}

const embed = new MessageEmbed()
.setColor('RANDOM')
.setTitle(`${response.login}(${response.id})`)
.setURL(response.html_url)
.setThumbnail(response.avatar_url)
.setDescription(response.bio ? response.bio : 'No Bio') // Bio Of User Searched
.addField('Public Repositories:-', response.public_repos.toLocaleString()) // Repos Of User Searched
.addField('Followers:-', response.followers.toLocaleString()) // Followers Of User Searched
.addField('Following:-', response.following.toLocaleString()) // How Many Following Of User Searched
.addField('Email:-', response.email ? response.email : 'No Email') // Email Of User Searched
.addField('Company:-', response.company ? response.commands : 'No Company') // Company Of User Searched
.addField('Location:-', response.location ? response.location : 'No Location') // Location Of User Searched
message.channel.send(embed)
}
}
41 changes: 40 additions & 1 deletion Episode 40/commands/Main-Commands/Search/npm.js
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@

const { MessageEmbed } = require('discord.js')
const fetch = require('node-fetch') // npm i node-fetch

module.exports = {
commands: ['npm', 'npm-package'], // You Can Keep Any Name
description: 'Shows Info About Searched NPM Package', // Optional

callback: async(message, args, client) => {

const npm = args[0]
if(!npm) return message.reply('Please Provide A Valid Package To Search.') // If No Packge In Searched.

let response
try {
response = await fetch('https://api.npms.io/v2/search?q=' + args[0]).then(res => res.json()) // Search For Package
}
catch (e) {
return message.reply('An Error Occured, Try Again Later.')
}
try {
const pkg = response.results[0].package
const embed = new MessageEmbed()
.setTitle(pkg.name)
.setColor('RANDOM')
.setURL(pkg.links.npm)
.setThumbnail('https://images-ext-1.discordapp.net/external/JsiJqfRfsvrh5IsOkIF_WmOd0_qSnf8lY9Wu9mRUJYI/https/images-ext-2.discordapp.net/external/ouvh4fn7V9pphARfI-8nQdcfnYgjHZdXWlEg2sNowyw/https/cdn.auth0.com/blog/npm-package-development/logo.png')
.setDescription(pkg.description)
.addField('Author:-', pkg.author ? pkg.author.name : 'None') // 'None' Because If No Author Is Their
.addField('Version:-', pkg.version)
.addField('Repository:-', pkg.links.repository ? pkg.links.repository : 'None') // 'None' Because If No Repository Is Their
.addField('Maintainers:-', pkg.maintainers ? pkg.maintainers.map(e => e.username).join(', ') : 'None') // 'None' Because If No Maintainer Are Their
.addField('Keywords:-', pkg.keywords ? pkg.keywords.join(', ') : 'None') // 'None' Because If No keyWords Are Their
.setTimestamp()
message.channel.send(embed)
}
catch (e) {
message.reply('Thats Not A Valid Package.') // If No Packges Found
}
}
}
47 changes: 47 additions & 0 deletions Episode 40/commands/Main-Commands/Search/wiki.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { MessageEmbed } = require('discord.js')
const fetch = require('node-fetch') // npm i node-fetch

module.exports = {
commands: ['wikipedia', 'wiki', 'wikip'], // You Can Keep Any Name
description: 'Search Any Thing On WikiPedia.', // Optional

callback: async(message, args, client) => {

const wiki = args.slice().join(' ')
if(!wiki) return message.reply('Provide A Query To Search.') // If Nothing Is Searched
const url = `https://en.wikipedia.org/api/rest_v1/page/summary/${encodeURIComponent(wiki)}` // From Here BOT Will Search For It

let response
try {
response = await fetch(url).then(res => res.json())
}
catch (e) {
return message.reply('An Error Occured, Try Again.')
}

try {
if(response.type === 'disambiguation') { // If Their Are Many Results With Same Seached Topic
const embed = new MessageEmbed()
.setColor('RANDOM')
.setTitle(response.title)
.setURL(response.content_urls.desktop.page)
.setDescription([`
${response.extract}
Links For Topic You Searched [Link](${response.content_urls.desktop.page}).`]) // If Their Are Many Results With Same Seached Topic
message.channel.send(embed)
}
else { // If Only One Result
const embed = new MessageEmbed()
.setColor('RANDOM')
.setTitle(response.title)
.setThumbnail(response.thumbnail.source)
.setURL(response.content_urls.desktop.page)
.setDescription(response.extract)
message.channel.send(embed)
}
}
catch {
return message.reply('Provide A Valid Query To Search.') // If Searched Query Is Not Available
}
}
}

0 comments on commit ae6b143

Please sign in to comment.