commit
c570d4f994
6 changed files with 58 additions and 42 deletions
2
pom.xml
2
pom.xml
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
<groupId>Hadder</groupId>
|
<groupId>Hadder</groupId>
|
||||||
<artifactId>Hadder</artifactId>
|
<artifactId>Hadder</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>0.2-ALPHA</version>
|
||||||
|
|
||||||
<name>Hadder</name>
|
<name>Hadder</name>
|
||||||
|
|
||||||
|
|
|
||||||
3
src/META-INF/MANIFEST.MF
Normal file
3
src/META-INF/MANIFEST.MF
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: com.bbn.hadder.Hadder
|
||||||
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.bbn.hadder;
|
package com.bbn.hadder;
|
||||||
|
|
||||||
import com.rethinkdb.RethinkDB;
|
import com.rethinkdb.RethinkDB;
|
||||||
|
import com.rethinkdb.gen.exc.ReqlOpFailedError;
|
||||||
import com.rethinkdb.net.Connection;
|
import com.rethinkdb.net.Connection;
|
||||||
import com.rethinkdb.net.Cursor;
|
import com.rethinkdb.net.Cursor;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
|
@ -70,4 +71,23 @@ public class Rethink {
|
||||||
} catch (ClassCastException ignored) {}
|
} catch (ClassCastException ignored) {}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setup() {
|
||||||
|
try {
|
||||||
|
r.dbCreate("Hadder").run(conn);
|
||||||
|
} catch (ReqlOpFailedError e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
r.tableCreate("server").run(conn);
|
||||||
|
} catch (ReqlOpFailedError e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
r.tableCreate("user").run(conn);
|
||||||
|
} catch (ReqlOpFailedError e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,37 +21,43 @@ import java.nio.file.Paths;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class GifCommand implements Command {
|
public class GifCommand implements Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executed(String[] args, MessageReceivedEvent event) {
|
public void executed(String[] args, MessageReceivedEvent event) {
|
||||||
String url;
|
if (args.length > 0) {
|
||||||
JSONArray array;
|
String url;
|
||||||
String query = "";
|
JSONArray array;
|
||||||
for(String arg : args) {
|
StringBuilder query = new StringBuilder();
|
||||||
query += arg.toLowerCase() + "+";
|
for (String arg : args) {
|
||||||
query = query.substring(0, query.length()-1);
|
query.append(arg.toLowerCase()).append("+");
|
||||||
}
|
query = new StringBuilder(query.substring(0, query.length() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
File configfile = new File("./config.json");
|
File configfile = new File("./config.json");
|
||||||
|
|
||||||
JSONObject config = null;
|
JSONObject config = null;
|
||||||
try {
|
try {
|
||||||
config = new JSONObject(new String(Files.readAllBytes(Paths.get(configfile.toURI()))));
|
config = new JSONObject(new String(Files.readAllBytes(Paths.get(configfile.toURI()))));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
OkHttpClient caller = new OkHttpClient();
|
OkHttpClient caller = new OkHttpClient();
|
||||||
Request request = new Request.Builder().url("http://api.giphy.com/v1/gifs/search?q=" + query + "&api_key=" + config.getString("Giphy")).build();
|
Request request = new Request.Builder().url("http://api.giphy.com/v1/gifs/search?q=" + query + "&api_key=" + config.getString("Giphy")).build();
|
||||||
try {
|
try {
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
Response response = caller.newCall(request).execute();
|
Response response = caller.newCall(request).execute();
|
||||||
JSONObject json = new JSONObject(response.body().string());
|
JSONObject json = new JSONObject(response.body().string());
|
||||||
array = json.getJSONArray("data");
|
array = json.getJSONArray("data");
|
||||||
int gifIndex = rand.nextInt(array.length());
|
int gifIndex = rand.nextInt(array.length());
|
||||||
url = (String) array.getJSONObject(gifIndex).get("url");
|
url = (String) array.getJSONObject(gifIndex).get("url");
|
||||||
event.getTextChannel().sendMessage(url).queue();
|
event.getTextChannel().sendMessage(url).queue();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
|
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.ERROR, builder).setTitle("Error").setDescription("Please try again with another term.").build()).queue();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
EmbedBuilder builder = new EmbedBuilder();
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.ERROR, builder).setTitle("Error").setDescription("Please try again with another term.").build()).queue();
|
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.WARNING, builder).setDescription("You have to write at least one search term!").build()).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,25 +4,11 @@ package com.bbn.hadder.commands.owner;
|
||||||
* @author Skidder / GregTCLTK
|
* @author Skidder / GregTCLTK
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bbn.hadder.Hadder;
|
|
||||||
import com.bbn.hadder.Rethink;
|
|
||||||
import com.bbn.hadder.commands.Command;
|
import com.bbn.hadder.commands.Command;
|
||||||
import com.bbn.hadder.utils.MessageEditor;
|
import com.bbn.hadder.utils.MessageEditor;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.JDA;
|
|
||||||
import net.dv8tion.jda.api.JDABuilder;
|
|
||||||
import net.dv8tion.jda.api.OnlineStatus;
|
|
||||||
import net.dv8tion.jda.api.entities.Activity;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import javax.security.auth.login.LoginException;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
public class ShutdownCommand implements Command {
|
public class ShutdownCommand implements Command {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ public class ReadyListener extends ListenerAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReady(@Nonnull ReadyEvent event) {
|
public void onReady(@Nonnull ReadyEvent event) {
|
||||||
|
Rethink.setup();
|
||||||
for (Guild g : event.getJDA().getGuilds()) {
|
for (Guild g : event.getJDA().getGuilds()) {
|
||||||
Rethink.insertServer(g.getId());
|
Rethink.insertServer(g.getId());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue