├── config.json ├── events ├── guildDelete.js ├── guildCreate.js ├── ready.js └── message.js ├── commands ├── utilities │ ├── icon.js │ ├── ping.js │ └── avatar.js ├── invite.js ├── general │ ├── weather.js │ ├── translate.js │ └── google.js └── help.js ├── app.js ├── package.json ├── LICENSE └── README.md /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "prefix" : "g!", 3 | "token" : "TOKEN_HERE" 4 | } 5 | -------------------------------------------------------------------------------- /events/guildDelete.js: -------------------------------------------------------------------------------- 1 | const config = require(`../config.json`); 2 | exports.run = (client, guild) => { 3 | console.log(`${client.user.username} has been removed from: ${guild.name} (id: ${guild.id})`); 4 | client.user.setActivity(`${client.guilds.size} Servers | ${config.prefix}help`, {type: 'WATCHING'}); 5 | }; -------------------------------------------------------------------------------- /events/guildCreate.js: -------------------------------------------------------------------------------- 1 | const config = require(`../config.json`); 2 | exports.run = (client, guild) => { 3 | console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`); 4 | client.user.setActivity(`${client.guilds.size} Servers | ${config.prefix}help`, {type: 'WATCHING'}); 5 | }; -------------------------------------------------------------------------------- /commands/utilities/icon.js: -------------------------------------------------------------------------------- 1 | const Discord = require(`discord.js`); 2 | exports.run = (client, message) => { 3 | let embed = new Discord.RichEmbed() 4 | .setTitle(`${message.guild.name} Icon`) 5 | .setURL(message.guild.iconURL) 6 | .setImage(message.guild.iconURL) 7 | .setColor(0xffffff); 8 | message.channel.send({ 9 | embed: embed 10 | }); 11 | return message.react("👌"); 12 | }; -------------------------------------------------------------------------------- /events/ready.js: -------------------------------------------------------------------------------- 1 | const Discord = require(`discord.js`); 2 | const config = require(`../config.json`); 3 | exports.run = (client) => { 4 | console.log(`[Bot is online | Node: ${process.version} | Discord.js: ${Discord.version}]\nConnected as: ${client.user.username} (ID: ${client.user.id})\nGuilds Connected: ${client.guilds.size}`); 5 | client.user.setActivity(`${client.guilds.size} Servers | ${config.prefix}help`, {type: 'WATCHING'}); 6 | }; -------------------------------------------------------------------------------- /commands/utilities/ping.js: -------------------------------------------------------------------------------- 1 | exports.run = (client, message) => { 2 | message.channel.send({ 3 | embed: { 4 | color: 0xffffff, 5 | description: ':ping_pong: **PONG!** - API Lantancy is **' + `${Date.now() - message.createdTimestamp}` + ' ms**', 6 | timestamp: new Date(), 7 | footer: { 8 | icon_url: client.user.avatarURL, 9 | text: `Heartbeat - ${Math.round(client.ping)}ms.` 10 | } 11 | } 12 | }); 13 | return message.react("👌"); 14 | }; -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | const Discord = require(`discord.js`); 2 | const client = new Discord.Client(); 3 | const fs = require(`fs`); 4 | const config = require(`./config.json`); 5 | 6 | fs.readdir(`./events/`, (err, files) => { 7 | if (err) return console.error(err); 8 | files.forEach(file => { 9 | let eventFunction = require(`./events/${file}`); 10 | let eventName = file.split(".")[0]; 11 | client.on(eventName, (...args) => eventFunction.run(client, ...args)); 12 | }); 13 | }); 14 | 15 | client.login(config.token); // Discord Google bot made by OblivionSan - https://oblivionsan.tk 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "googlebot", 3 | "version": "1.0.0", 4 | "description": "Discord GoogleBot created by OblivionSan.", 5 | "main": "app.js", 6 | "dependencies": { 7 | "discord.js": "^11.2.1", 8 | "fs": "0.0.1-security", 9 | "google": "^2.1.0", 10 | "google-translate-api": "^2.3.0", 11 | "moment": "^2.18.1", 12 | "moment-duration-format": "^1.3.0", 13 | "ms": "^2.0.0", 14 | "opusscript": "0.0.3", 15 | "weather-js": "^2.0.0" 16 | }, 17 | "devDependencies": {}, 18 | "scripts": { 19 | "test": "echo \"Error: no test specified\" && exit 1" 20 | }, 21 | "author": "OblivionSan", 22 | "license": "MIT" 23 | } 24 | -------------------------------------------------------------------------------- /commands/invite.js: -------------------------------------------------------------------------------- 1 | const config = require(`../config.json`); 2 | const p = config.prefix; 3 | exports.run = (client, message) => { 4 | message.author.send({ 5 | embed: { 6 | color: 0xffffff, 7 | title: "Discord Invite Link", 8 | url: `https://discordapp.com/oauth2/authorize/?permissions=2146958591&scope=bot&client_id=${client.user.id}`, 9 | description: `Once invited, type \`${p}help\` to see my commands.`, 10 | timestamp: new Date(), 11 | footer: { 12 | icon_url: client.user.avatarURL, 13 | text: client.user.username 14 | } 15 | } 16 | }); 17 | return message.react("👌"); 18 | }; -------------------------------------------------------------------------------- /commands/utilities/avatar.js: -------------------------------------------------------------------------------- 1 | const Discord = require(`discord.js`); 2 | exports.run = (client, message) => { 3 | let args = message.content.split(/[ ]+/); 4 | if (args.length == 2 || message.content.includes("@")) { 5 | let user = message.mentions.members.first(); 6 | let embed = new Discord.RichEmbed() 7 | .setTitle(user.user.username) 8 | .setURL(user.user.displayAvatarURL) 9 | .setImage(user.user.displayAvatarURL) 10 | .setFooter(`Avatar ID = ${user.user.avatar}`) 11 | .setColor(0xffffff); 12 | message.channel.send({ 13 | embed: embed 14 | }); 15 | return message.react("👌"); 16 | } else message.channel.send({ 17 | embed: { 18 | color: 0xffffff, 19 | description: `:warning: **${message.author.username}**, You didn't give me a valid user. {m!avatar \`@username\`}`, 20 | footer: { 21 | text: 'API Lantancy is ' + `${Date.now() - message.createdTimestamp}` + ' ms' 22 | } 23 | } 24 | }); 25 | }; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Oblivion サン 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /events/message.js: -------------------------------------------------------------------------------- 1 | const talkedRecently = new Set(); 2 | const config = require(`../config.json`); 3 | exports.run = (client, message) => { 4 | if (message.author.bot) return; 5 | if (message.channel.type === 'dm') return; 6 | if (message.content.indexOf(config.prefix) !== 0) return; 7 | 8 | if (talkedRecently.has(message.author.id)) return; 9 | talkedRecently.add(message.author.id); 10 | setTimeout(() => { 11 | talkedRecently.delete(message.author.id); 12 | }, 2500); 13 | 14 | const args = message.content.slice(config.prefix.length).trim().split(/ +/g); 15 | const command = args.shift().toLowerCase(); 16 | 17 | 18 | try { 19 | let genFile = require(`../commands/${command}.js`); 20 | genFile.run(client, message, args); 21 | } catch (err) { 22 | try { 23 | let utlFile = require(`../commands/general/${command}.js`); 24 | utlFile.run(client, message, args); 25 | } catch (err) { 26 | try { 27 | let utlFile = require(`../commands/utilities/${command}.js`); 28 | utlFile.run(client, message, args); 29 | } catch (err) { 30 | console.log(err); 31 | } 32 | } 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /commands/general/weather.js: -------------------------------------------------------------------------------- 1 | const weather = require(`weather-js`); 2 | const Discord = require(`discord.js`); 3 | exports.run = (client, message) => { 4 | let args = message.content.split(/[ ]+/); 5 | weather.find({ search: args.slice(1).join(' '), degreeType: 'C' }, function (err, result) { 6 | if (err) console.log('Weather CMD error: ' + err); 7 | if (result === undefined || result.length === 0) { 8 | message.channel.send({ 9 | embed: { 10 | color: 0xff2727, 11 | description: `:warning: **${message.author.username}**, please enter a valid location.`, 12 | footer: { 13 | text: 'API Lantancy is ' + `${Date.now() - message.createdTimestamp}` + ' ms', 14 | } 15 | } 16 | }); 17 | return; 18 | } 19 | 20 | var current = result[0].current; 21 | var location = result[0].location; 22 | 23 | let embed = new Discord.RichEmbed() 24 | .setAuthor(`${current.skytext} weather in ${current.observationpoint}`, current.imageUrl) 25 | .setColor(0xffffff) 26 | .addField('Timezone', `UTC${location.timezone}`, true) 27 | .addField('Degree Type', location.degreetype, true) 28 | .addField('Temperature', `${current.temperature} Degrees`, true) 29 | .addField('Feels Like', `${current.feelslike} Degrees`, true) 30 | .addField('Winds', current.winddisplay, true) 31 | .addField('Humidity', `${current.humidity}%`, true); 32 | message.channel.send({ embed }); 33 | return message.react("👌"); 34 | }); 35 | }; 36 | -------------------------------------------------------------------------------- /commands/general/translate.js: -------------------------------------------------------------------------------- 1 | const translate = require('google-translate-api'); 2 | const Discord = require(`discord.js`); 3 | exports.run = (client, message) => { 4 | let args = message.content.split(/[ ]+/); 5 | let lang = args[1]; 6 | let suffix = args.slice(2).join(' '); 7 | if (!suffix) message.channel.send({ 8 | embed: { 9 | color: 0xff2727, 10 | description: `:warning: **${message.author.username}**, You didn't give me anything to translate.\n{m!translate \`language\` \`input\`}`, 11 | timestamp: new Date(), 12 | footer: { 13 | text: 'API Lantancy is ' + `${Date.now() - message.createdTimestamp}` + ' ms' 14 | } 15 | } 16 | }); 17 | if (!lang) return; 18 | translate(suffix, {from: 'en', to: lang}).then(res => { 19 | let embed = new Discord.RichEmbed() 20 | .setColor(`#4885ed`) 21 | .setAuthor(`Language detected: "${lang}"`, `http://nyamato.me/i/kbfuj.png`) 22 | .setDescription(`**Original**: ${suffix}\n**Translation**: ${res.text}`) 23 | .setTimestamp() 24 | .setFooter('API Lantancy is ' + `${Date.now() - message.createdTimestamp}` + ' ms', message.author.displayAvatarURL); 25 | return message.channel.send({ 26 | embed: embed 27 | }); 28 | }).catch(error => message.channel.send({ 29 | embed: { 30 | color: 0xff2727, 31 | description: `:warning: **${message.author.username}**, ${error}`, 32 | timestamp: new Date(), 33 | footer: { 34 | text: 'API Lantancy is ' + `${Date.now() - message.createdTimestamp}` + ' ms' 35 | } 36 | } 37 | })); return message.react("👌"); 38 | }; -------------------------------------------------------------------------------- /commands/help.js: -------------------------------------------------------------------------------- 1 | const config = require(`../config.json`); 2 | const p = config.prefix; 3 | const Discord = require(`discord.js`); 4 | exports.run = (client, message) => { 5 | if (message.content === `${p}help`, message) { 6 | let embed = new Discord.RichEmbed() 7 | .setAuthor("GoogleBot's Command List", client.user.displayAvatarURL) 8 | .setDescription("GoogleBot developed by [**Oblivion サン#9469**](https://oblivionsan.tk) | [**Support Server**](https://discord.gg/kxNeGRC)") 9 | .setColor(`#ffffff`) 10 | .addField(`❯ General Commands`, `• **${p}google** : Responds with a Google search of your input.\n• **${p}invite** : DM's you a invite link for the bot.\n• **${p}translate** \`{lang} {input}\` : Translation from English to choosen language.\n• **${p}weather** : Responds with a weather statistic of your input.`) 11 | .addField(`❯ Utility Commands`, `• **${p}avatar** \`{@user}\` : Responds with a url linking to given user avatar.\n• **${p}channel** : Responds with the channel information.\n• **${p}emotes** : Responds with server emotes and amount.\n• **${p}icon** : Responds with a url linking to your server icon.\n• **${p}info** \`{@user}\` : Responds with given user information.\n• **${p}ping** : Responds with \`'PONG!'\` also displays api lantancy.\n• **${p}roles** : Responds with server roles with amount.\n• **${p}server** : Responds with the server information.\n• **${p}stats** : Responds with the bots statistics.\n`) 12 | .setTimestamp() 13 | .setFooter('API Lantancy is ' + `${Date.now() - message.createdTimestamp}` + ' ms', client.user.avatarURL); 14 | message.author.send({ 15 | embed: embed 16 | }); 17 | } 18 | 19 | if (message.content === `${p}help`, message) { 20 | let embed = new Discord.RichEmbed() 21 | .setColor("#ffffff") 22 | .setDescription(`:inbox_tray: **${message.author.username}**, I've DM'd you a list of my commands.`); 23 | message.channel.send({ 24 | embed: embed 25 | }); 26 | return; 27 | } 28 | }; -------------------------------------------------------------------------------- /commands/general/google.js: -------------------------------------------------------------------------------- 1 | const google = require('google'); 2 | const Discord = require(`discord.js`); 3 | exports.run = (client, message) => { 4 | let args = message.content.split(/[ ]+/); 5 | let suffix = args.slice(1).join(' '); 6 | if (!suffix) { 7 | message.channel.send({ 8 | embed: { 9 | color: 0xff2727, 10 | description: `:warning: **${message.author.username}**, You didn't give me anything to search. {m!google \`input\`}`, 11 | footer: { 12 | text: 'API Lantancy is ' + `${Date.now() - message.createdTimestamp}` + ' ms', 13 | } 14 | } 15 | }); 16 | } 17 | google.resultsPerPage = 25; 18 | google(suffix, function (err, res) { 19 | if (err) message.channel.send({ 20 | embed: { 21 | color: 0xff2727, 22 | description: `:warning: **${message.author.username}**, ${err}`, 23 | footer: { 24 | text: 'API Lantancy is ' + `${Date.now() - message.createdTimestamp}` + ' ms', 25 | } 26 | } 27 | }); 28 | for (var i = 0; i < res.links.length; ++i) { 29 | var link = res.links[i]; 30 | if (!link.href) { 31 | res.next; 32 | } else { 33 | let embed = new Discord.RichEmbed() 34 | .setColor(`#ffffff`) 35 | .setAuthor(`Result for "${suffix}"`, `https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/2000px-Google_%22G%22_Logo.svg.png`) 36 | .setDescription(`**Link**: [${link.title}](${link.href})\n**Description**:\n${link.description}`) 37 | .setTimestamp() 38 | .setFooter('API Lantancy is ' + `${Date.now() - message.createdTimestamp}` + ' ms', message.author.displayAvatarURL); 39 | return message.channel.send({ 40 | embed: embed 41 | }); 42 | } return message.react("👌"); 43 | } 44 | }); 45 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Google based discord-bot. 2 | [![GitHub License](https://img.shields.io/github/license/OblivionSan/discord-googlebot.svg?style=flat-square)](https://github.com/OblivionSan/discord-googlebot/blob/master/LICENSE) 3 | [![GitHub Stars](https://img.shields.io/github/stars/OblivionSan/discord-googlebot.svg?style=flat-square)](https://github.com/OblivionSan/discord-googlebot/stargazers) 4 | [![GitHub forks](https://img.shields.io/github/forks/OblivionSan/discord-googlebot.svg?style=flat-square)](https://github.com/OblivionSan/discord-googlebot/network) 5 | [![GitHub issues](https://img.shields.io/github/issues/OblivionSan/discord-googlebot.svg?style=flat-square)](https://github.com/OblivionSan/discord-googlebot/issues) 6 | 7 | Simple Google bot made with various apis 8 | > You must have [Node](https://nodejs.org/) installed to run this bot. 9 | 10 | ## Getting started 11 | 12 | ``` 13 | $ git clone https://github.com/OblivionSan/discord-googlebot.git 14 | $ npm install 15 | ``` 16 | Create a discord bot token [here](https://discordapp.com/developers/applications/me) and replace it where you see **TOKEN_HERE**, replace **PREFIX** to your prefered prefix. 17 | 18 | **config.json** example 19 | ```json 20 | { 21 | "prefix" : "g!", 22 | "token" : "TOKEN_HERE" 23 | } 24 | ``` 25 | Invite your bot to your discord server using the link given. Make sure to replace `` with your bots [client id](https://discordapp.com/developers/applications/me). 26 | ``` 27 | https://discordapp.com/oauth2/authorize?&client_id=&scope=bot&permissions=0 28 | ``` 29 | To start your bot, simply open up command prompt in your bots directory and then type the following. 30 | ``` 31 | $ node app.js 32 | ``` 33 | 34 | ## Built with 35 | > [Discord.js](https://discord.js.org/#/) - Node Module used. 36 | 37 | > [Google](https://www.npmjs.com/package/google) - Node Module used. 38 | 39 | > [Google-Translate-api](https://www.npmjs.com/package/google-translate-api) - Node Module used. 40 | 41 | > [Node](https://nodejs.org/) - JavaScript run-time environment. 42 | 43 | ## Author 44 | - **OblivionSan** - [@OblivionSan](https://twitter.com/OblivionSan) | [Discord Server](https://discord.gg/kxNeGRC) | [Website](https://oblivionsan.tk) 45 | --------------------------------------------------------------------------------