Created
June 11, 2017 16:31
-
-
Save rikoudosenin/9370fb72bcde123d040bda8e02d11610 to your computer and use it in GitHub Desktop.
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
package me.sage.crypto; | |
import java.io.IOException; | |
import com.google.gson.Gson; | |
import me.sage.crypto.coinmarketcap.COINAPI; | |
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; | |
import net.dv8tion.jda.core.hooks.ListenerAdapter; | |
import okhttp3.OkHttpClient; | |
import okhttp3.Request; | |
import okhttp3.Response; | |
public class BotListener extends ListenerAdapter{ | |
private static OkHttpClient client = new OkHttpClient(); | |
public static String getJSON(String url) throws IOException { | |
Request request = new Request.Builder() | |
.url(url) | |
.build(); | |
Response response = client.newCall(request).execute(); | |
return response.body().string(); | |
} | |
public static String[] getUserData(int limit) { | |
String json = null; | |
try { | |
json = getJSON("https://api.coinmarketcap.com/v1/ticker/?limit=" + limit); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
Gson gson = new Gson(); | |
COINAPI[] coinobj = gson.fromJson(json, COINAPI[].class); | |
return new String[] { | |
"Price: " + coinobj[0].getName(), | |
"Price: " + coinobj[0].getName() | |
}; | |
} | |
@Override | |
public void onMessageReceived(MessageReceivedEvent e) { | |
if(e.getMessage().getRawContent().equalsIgnoreCase("//test")) { | |
e.getChannel().sendMessage("testing, testing?!").queue(); | |
if(e.getMessage().getRawContent().equalsIgnoreCase("//coin")) { | |
for(String str1 : getUserData(10)) { | |
System.out.println(str1); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment