This repository has been archived by the owner on Mar 5, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from BigBotNetwork/greg-dev
Greg dev
- Loading branch information
Showing
4 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/com/bbn/hadder/commands/misc/GitHubCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.bbn.hadder.commands.misc; | ||
|
||
/* | ||
* @author Skidder / GregTCLTK | ||
*/ | ||
|
||
import com.bbn.hadder.commands.Command; | ||
import com.bbn.hadder.utils.MessageEditor; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.io.IOException; | ||
|
||
public class GitHubCommand implements Command { | ||
@Override | ||
public void executed(String[] args, MessageReceivedEvent event) { | ||
if (args.length > 0) { | ||
Request request = new Request.Builder().url("https://api.github.com/users/" + args[0]).build(); | ||
try { | ||
|
||
Response response = new OkHttpClient().newCall(request).execute(); | ||
JSONObject json = new JSONObject(response.body().string()); | ||
|
||
String nickname = json.getString("name"); | ||
String bio = "None"; | ||
String location = "Unknown"; | ||
String website = "None"; | ||
try { | ||
bio = json.getString("bio"); | ||
} catch (JSONException e) { | ||
|
||
} | ||
try { | ||
location = json.getString("location"); | ||
} catch (JSONException e) { | ||
|
||
} | ||
|
||
if(!json.getString("blog").equals("")) website = json.getString("blog"); | ||
|
||
EmbedBuilder builder = new EmbedBuilder(); | ||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, builder) | ||
.setAuthor("Information about " + nickname + " (" + args[0] + ")", "https://github.com/" + args[0] + "", "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png") | ||
.setThumbnail(json.getString("avatar_url")) | ||
.addField("User bio", bio, false) | ||
.addField("Location", location, true) | ||
.addField("Website", website, true) | ||
.addField("Public repositories", String.valueOf(json.getInt("public_repos")), true) | ||
.addField("Public gists", String.valueOf(json.getInt("public_gists")), true) | ||
.addField("Followers", String.valueOf(json.getInt("followers")), true) | ||
.addField("Following", String.valueOf(json.getInt("following")), true) | ||
.build()).queue(); | ||
|
||
} catch (IOException | NullPointerException e) { | ||
EmbedBuilder builder = new EmbedBuilder(); | ||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.ERROR, builder).setDescription("The GitHub API might be down at the moment!").build()).queue(); | ||
} catch (JSONException e) { | ||
EmbedBuilder builder = new EmbedBuilder(); | ||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.WARNING, builder).setDescription("This user does not exist!").build()).queue(); | ||
} | ||
} else { | ||
EmbedBuilder builder = new EmbedBuilder(); | ||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.WARNING, builder).setDescription("You have to specify a user!").build()).queue(); | ||
} | ||
} | ||
|
||
@Override | ||
public String[] labels() { | ||
return new String[]{"GitHub"}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters