Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #18 from BigBotNetwork/greg-dev
Browse files Browse the repository at this point in the history
Greg dev
  • Loading branch information
greg6775 authored Oct 30, 2019
2 parents 16a20c4 + b018a29 commit 2184e45
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 4 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
<artifactId>gson</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>

<repositories>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/bbn/hadder/Hadder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.bbn.hadder.commands.general.*;
import com.bbn.hadder.commands.fun.GifCommand;
import com.bbn.hadder.commands.misc.GitHubCommand;
import com.bbn.hadder.commands.moderation.*;
import com.bbn.hadder.commands.owner.ShutdownCommand;
import com.bbn.hadder.commands.settings.PrefixCommand;
Expand Down Expand Up @@ -45,7 +46,7 @@ public static void main(String[] args) {
builder.setToken(config.getString("Token"));


CommandHandler.cmdlist.addAll(List.of(new TestCommand(), new BanCommand(), new PrefixCommand(), new ShutdownCommand(), new KickCommand(), new PingCommand(), new GifCommand(), new ClearCommand()));
CommandHandler.cmdlist.addAll(List.of(new TestCommand(), new BanCommand(), new PrefixCommand(), new ShutdownCommand(), new KickCommand(), new PingCommand(), new GifCommand(), new ClearCommand(), new GitHubCommand()));

builder.addEventListeners(
new MentionListener(),
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/com/bbn/hadder/commands/misc/GitHubCommand.java
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"};
}
}
4 changes: 1 addition & 3 deletions src/main/java/com/bbn/hadder/listener/CommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

import javax.annotation.Nonnull;

/*
* @author Skidder / GregTCLTK
*/

public class CommandListener extends ListenerAdapter {

@Override
public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
public void onMessageReceived(MessageReceivedEvent event) {
if (event.isFromType(ChannelType.TEXT)) {
if (event.getMessage().getContentRaw().startsWith(Rethink.get("user", "id", event.getAuthor().getId(), "prefix"))) {
if (!event.getAuthor().isBot()) {
Expand Down

0 comments on commit 2184e45

Please sign in to comment.