Added Google Search

This commit is contained in:
dragonfire535
2017-03-13 09:04:32 -04:00
parent 383b58c894
commit 60cf93b2cd
4 changed files with 44 additions and 4 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ class InfoCommand extends commando.Command {
.addField('Lib',
"[discord.js](https://discord.js.org/#/) (master)", true)
.addField('Modules',
"[Commando](https://github.com/Gawdl3y/discord.js-commando) (0.9.0), [cleverbot-node](https://github.com/fojas/cleverbot-node) (0.3.5), [pirate-speak](https://github.com/mikewesthad/pirate-speak) (1.0.1), [JIMP](https://github.com/oliver-moran/jimp) (0.2.27), [google-translate-api](https://github.com/matheuss/google-translate-api) (2.2.2), [urban](https://github.com/mvrilo/urban) (0.3.1), [zalgoize](https://github.com/clux/zalgolize) (1.2.4), [hepburn](https://github.com/lovell/hepburn) (1.0.0), [yahoo-weather](https://github.com/mamal72/node-yahoo-weather) (2.2.2), [imdb-api](https://github.com/worr/node-imdb-api) (2.2.1), [request-promise](https://github.com/request/request-promise) (4.1.1), [mathjs](http://mathjs.org/) (3.10.0), [string-to-binary](https://www.npmjs.com/package/string-to-binary) (0.1.2)")
"[Commando](https://github.com/Gawdl3y/discord.js-commando) (0.9.0), [cleverbot-node](https://github.com/fojas/cleverbot-node) (0.3.5), [pirate-speak](https://github.com/mikewesthad/pirate-speak) (1.0.1), [JIMP](https://github.com/oliver-moran/jimp) (0.2.27), [google-translate-api](https://github.com/matheuss/google-translate-api) (2.2.2), [urban](https://github.com/mvrilo/urban) (0.3.1), [zalgoize](https://github.com/clux/zalgolize) (1.2.4), [hepburn](https://github.com/lovell/hepburn) (1.0.0), [yahoo-weather](https://github.com/mamal72/node-yahoo-weather) (2.2.2), [imdb-api](https://github.com/worr/node-imdb-api) (2.2.1), [request-promise](https://github.com/request/request-promise) (4.1.1), [mathjs](http://mathjs.org/) (3.10.0), [string-to-binary](https://www.npmjs.com/package/string-to-binary) (0.1.2), [google](https://github.com/jprichardson/node-google) (2.1.0)")
.addField('Other Credit',
"[Cleverbot API](https://www.cleverbot.com/api/), [Wattpad API](https://developer.wattpad.com/docs/api), [Wordnik API](http://developer.wordnik.com/docs.html), [osu! API](https://osu.ppy.sh/p/api), [memegen.link](https://memegen.link/), [Yugioh Prices API](http://docs.yugiohprices.apiary.io/#), [YouTube Data API](https://developers.google.com/youtube/v3/), [Yoda Speak API](https://market.mashape.com/ismaelc/yoda-speak), [Discord Bots API](https://bots.discord.pw/api), [Heroku](https://www.heroku.com/)")
.addField('My Server',
+39
View File
@@ -0,0 +1,39 @@
const commando = require('discord.js-commando');
const google = require('google');
class GoogleCommand extends commando.Command {
constructor(Client){
super(Client, {
name: 'google',
group: 'search',
memberName: 'google',
description: 'Searches Google for something. (;google Discord)',
examples: [';google Discord']
});
}
async run(message, args) {
if(message.channel.type !== 'dm') {
if(!message.channel.permissionsFor(this.client.user).hasPermission('SEND_MESSAGES')) return;
if(!message.channel.permissionsFor(this.client.user).hasPermission('READ_MESSAGES')) return;
}
console.log("[Command] " + message.content);
let searchQuery = message.content.split(" ").slice(1).join(" ");
google.resultsPerPage = 2
google(searchQuery, function (err, res) {
if (err) message.channel.sendMessage(':x: An Error Occurred! Try again later!');
let link = res.links;
if(link === undefined) {
message.channel.sendMessage(':x: Error! No Results Found!');
} else {
if(link[0].href === undefined) {
message.channel.sendMessage(':x: Error! No Results Found!');
} else {
message.channel.sendMessage(link[0].href).catch(error => message.channel.sendMessage(':x: An Error Occurred! Try again later!'));
}
}
});
}
}
module.exports = GoogleCommand;
+3 -3
View File
@@ -190,8 +190,8 @@ client.once('ready', () => {
client.user.setGame(";help | dragonfire535");
});
process.on('unhandledRejection', function(reason, p){
console.log("A Possibly Unhandled Rejection has Occurred.");
});
//process.on('unhandledRejection', function(reason, p){
// console.log("A Possibly Unhandled Rejection has Occurred.");
//});
client.login(config.token);
+1
View File
@@ -19,6 +19,7 @@
"cleverbot-node": "^0.3.5",
"discord.js": "github:hydrabolt/discord.js",
"discord.js-commando": "^0.9.0",
"google": "^2.1.0",
"google-translate-api": "^2.2.2",
"hepburn": "^1.0.0",
"imdb-api": "^2.2.1",