Skip to content

Commit

Permalink
Add new '/ratz gituserinfo' and '/ratz gitrepoinfo' commands
Browse files Browse the repository at this point in the history
Added the '/ratz gituserinfo' and '/ratz gitrepoinfo' commands to retrieve information about GitHub users and GitHub repositories.
  • Loading branch information
Gisgar3 committed Jul 16, 2018
1 parent 35f5b4d commit 999c437
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
8 changes: 6 additions & 2 deletions commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"/ratz stop",
"/ratz btcinfo",
"/ratz ratcoininfo + Twitch Username",
"/ratz laststream"
"/ratz laststream",
"/ratz gituserinfo + GitHub Username",
"/ratz gitrepoinfo + {GitHubUsername}/{RepositoryName}"
],
"definitions": [
"Shows all commands for ratzBot",
Expand All @@ -23,6 +25,8 @@
"Stops YouTube video audio",
"Shows information about Bitcoin",
"Shows the amount of RTC a user has on Twitch",
"Shows last stream VOD and VOD information"
"Shows last stream VOD and VOD information",
"Shows information for provided GitHub user",
"Show information for provided GitHub repository (which is owned by the provided GitHub username)"
]
}
70 changes: 70 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,76 @@ bot.on('message', (message) => {
}
})
}
if (message.content.startsWith("/ratz gituserinfo ")) {
var result = message.content.slice(18);
var getGitUserInfo = {
method: "GET",
url: `https://api.github.com/users/${result}`,
headers: {
"User-Agent": "Gisgar3"
}
}
request(getGitUserInfo, (error, response, body) => {
try {
if (!error & response.statusCode == 200) {
var stats = JSON.parse(body);
const embed = new Discord.RichEmbed()
.setTitle(`GitHub User Information for ${result}`)
.setURL(stats.html_url)
.setColor(0xcb00ff)
.setThumbnail(stats.avatar_url)
.addField("Name", stats.name)
.addField("Company", "" + stats.company)
.addField("Bio", "" + stats.bio)
.addField("Location", "" + stats.location)
.addField("Email", "" + stats.email)
.addField("Hireable", "" + stats.hireable)
.addField("Public Repositories", stats.public_repos)
message.channel.send(embed);
}
else {
message.channel.send(`${message.author}, an error occured during the process. Try again later.`);
}
}
catch (err) {
message.channel.send(`${message.author}, an error occured during the process. Try again later.`);
}
})
}
if (message.content.startsWith("/ratz gitrepoinfo ")) {
var result = message.content.slice(18);
var getGitRepoInfo = {
method: "GET",
url: `https://api.github.com/repos/${result}`,
headers: {
'User-Agent': 'Gisgar3'
}
}
request(getGitRepoInfo, (error, response, body) => {
try {
if (!error & response.statusCode == 200) {
var stats = JSON.parse(body);
const embed = new Discord.RichEmbed()
.setTitle(`GitHub Repository for ${result}`)
.setURL(stats.html_url)
.setColor(0xcb00ff)
.setThumbnail(stats.owner.avatar_url)
.addField("Name", stats.name)
.addField("Description", stats.description)
.addField("Owner", stats.owner.login)
.addField("Language", stats.language)
.addField("Archive Status", stats.archived)
message.channel.send(embed);
}
else {
message.channel.send(`${message.author}, an error occured during the process. Try again later.`);
}
}
catch (err) {
message.channel.send(`${message.author}, an error occured during the process. Try again later.`);
}
})
}
if (message.content.toString() == "/ratz btcinfo") {
var getBTCInfo = {
method: "GET",
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ratzbot",
"version": "2.5.1",
"version": "2.6.0 RC",
"description": "Discord bot for Twitch streamer ratzDoll",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 999c437

Please sign in to comment.