forked from RepoMirrors/kami-blue
use github api for contributors (d1gress)
GitHub API impl for contributors
This commit is contained in:
commit
9ff732ed33
|
@ -1,12 +1,18 @@
|
|||
package me.zeroeightsix.kami.command.commands;
|
||||
|
||||
import me.zeroeightsix.kami.command.Command;
|
||||
import me.zeroeightsix.kami.util.WebUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static me.zeroeightsix.kami.util.MessageSendHelper.sendChatMessage;
|
||||
|
||||
/**
|
||||
* Created by S-B99 on 01/12/2019.
|
||||
* Revamped by d1gress/Qther on 13 April 2020
|
||||
*/
|
||||
|
||||
public class CreditsCommand extends Command {
|
||||
|
||||
public CreditsCommand() {
|
||||
|
@ -16,43 +22,62 @@ public class CreditsCommand extends Command {
|
|||
|
||||
@Override
|
||||
public void call(String[] args) {
|
||||
sendChatMessage("\n" +
|
||||
"Name (Github if not same as name)\n" +
|
||||
"&l&9Author:\n" +
|
||||
"086 (zeroeightysix)\n" +
|
||||
"&l&9Contributors:\n" +
|
||||
"Bella (S-B99)\n" +
|
||||
"hub (blockparole)\n" +
|
||||
"Sasha (EmotionalLove)\n" +
|
||||
"Qther (d1gress / Vonr)\n" +
|
||||
"HHSGPA\n" +
|
||||
"20kdc\n" +
|
||||
"IronException\n" +
|
||||
"cats (Cuhnt)\n" +
|
||||
"Katatje\n" +
|
||||
"Deauthorized\n" +
|
||||
"snowmii\n" +
|
||||
"kdb424\n" +
|
||||
"Jack (jacksonellsworth03)\n" +
|
||||
"cookiedragon234\n" +
|
||||
"0x2E (PretendingToCode)\n" +
|
||||
"babbaj\n" +
|
||||
"ZeroMemes\n" +
|
||||
"TheBritishMidget (TBM)\n" +
|
||||
"Hamburger (Hamburger2k)\n" +
|
||||
"Darki\n" +
|
||||
"Crystallinqq\n" +
|
||||
"Elementars\n" +
|
||||
"fsck\n" +
|
||||
"Jamie (jamie27)\n" +
|
||||
"Waizy\n" +
|
||||
"It is the end\n" +
|
||||
"fluffcq\n" +
|
||||
"leijurv\n" +
|
||||
"polymer\n" +
|
||||
"Battery Settings (Bluskript)\n" +
|
||||
"An-En (AnotherEntity)\n" +
|
||||
"Arisa (Arisa-Snowbell)\n" +
|
||||
"UrM0ther");
|
||||
List<Integer> exceptions = Arrays.asList(
|
||||
17222512, // s-b99 / dominika
|
||||
27009727, // zeroeightysix
|
||||
48992448, // blockparole
|
||||
19880089, // EmotionalLove
|
||||
55198830, 24369412, // d1gress and Vonr
|
||||
51212427, // Cuhnt
|
||||
11698651, // jacksonellworth03
|
||||
44139104, // TheBritishMidget
|
||||
59456376, // Hamburger2k
|
||||
41800112, // PretendingToCode
|
||||
52386117, // Bluskript
|
||||
26636167, // AnotherEntity
|
||||
22961592, // ArisaSnowbell
|
||||
13212688, // jamie27
|
||||
50775247, // DarkiBoi
|
||||
12820770, // Babbaj
|
||||
11377481, // Crystallinqq
|
||||
3837873, // leijurv
|
||||
49104462, // Elementars
|
||||
56689414, // WaizyNet
|
||||
58238984, // Itistheend
|
||||
|
||||
// Bots
|
||||
27856297 // dependabot
|
||||
);
|
||||
String message =
|
||||
"\nName (Github if not same as name)" +
|
||||
"\n&l&9Author:" +
|
||||
"\n086 (zeroeightysix)" +
|
||||
"\n&l&9Contributors:" +
|
||||
"\nBella (S-B99)" +
|
||||
"\nhub (blockparole)" +
|
||||
"\nSasha (EmotionalLove)" +
|
||||
"\nQther (d1gress / Vonr)" +
|
||||
"\ncats (Cuhnt)" +
|
||||
"\nJack (jacksonellsworth03)" +
|
||||
"\nTheBritishMidget (TBM)" +
|
||||
"\nHamburger (Hamburger2k)" +
|
||||
"\n0x2E (PretendingToCode)" +
|
||||
"\nBattery Settings (Bluskript)" +
|
||||
"\nAn-En (AnotherEntity)" +
|
||||
"\nArisa (Arisa-Snowbell)" +
|
||||
"\nJamie (jamie27)" +
|
||||
"\nDarki (DarkiBoi)" +
|
||||
"\nWaizy (WaizyNet)" +
|
||||
"\nIt is the end (Itistheend)" +
|
||||
"\nbabbaj" +
|
||||
"\nCrystallinqq" +
|
||||
"\nleijurv" +
|
||||
"\nElementars";
|
||||
|
||||
for (WebUtils.GithubUser u : WebUtils.getContributors(exceptions)) {
|
||||
message = message.concat("\n" + u.login);
|
||||
}
|
||||
|
||||
sendChatMessage(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,21 @@
|
|||
package me.zeroeightsix.kami.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import me.zeroeightsix.kami.KamiMod;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Created by Dewy on 09/04/2020
|
||||
* Updated by d1gress/Qther on 13 April 2020
|
||||
*/
|
||||
public class WebUtils {
|
||||
|
||||
|
@ -18,4 +26,77 @@ public class WebUtils {
|
|||
KamiMod.log.error("Couldn't open link: " + url.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static java.util.List<GithubUser> getContributors() {
|
||||
// log attempt
|
||||
KamiMod.log.info("Attempting to get contributors from github api...");
|
||||
|
||||
//initialize list
|
||||
java.util.List<GithubUser> contributorsAsList = new LinkedList<>(Collections.emptyList());
|
||||
|
||||
try {
|
||||
// connect to https://api.github.com/repos/kami-blue/client/contributors
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(KamiMod.CAPES_JSON).openConnection();
|
||||
connection.connect();
|
||||
|
||||
// then parse it
|
||||
GithubUser[] contributors = new Gson().fromJson(new InputStreamReader(connection.getInputStream()), GithubUser[].class);
|
||||
|
||||
// disconnect from api
|
||||
connection.disconnect();
|
||||
|
||||
// add contributors to the list
|
||||
contributorsAsList.addAll(Arrays.asList(contributors));
|
||||
|
||||
} catch (Throwable t) {
|
||||
// throw error
|
||||
KamiMod.log.error("Attempt to get contributors from github api failed.\nError:\n\n" + t.toString());
|
||||
}
|
||||
|
||||
|
||||
return contributorsAsList;
|
||||
}
|
||||
|
||||
public static java.util.List<GithubUser> getContributors(java.util.List<Integer> exceptions) {
|
||||
// log attempt
|
||||
KamiMod.log.info("Attempting to get contributors from github api...");
|
||||
|
||||
//initialize list
|
||||
java.util.List<GithubUser> contributorsAsList = new LinkedList<>(Collections.emptyList());
|
||||
|
||||
try {
|
||||
// connect to https://api.github.com/repos/kami-blue/client/contributors
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://api.github.com/repos/kami-blue/client/contributors").openConnection();
|
||||
connection.connect();
|
||||
|
||||
// then parse it
|
||||
GithubUser[] contributors = new Gson().fromJson(new InputStreamReader(connection.getInputStream()), GithubUser[].class);
|
||||
|
||||
// disconnect from api
|
||||
connection.disconnect();
|
||||
|
||||
// add contributors to the list
|
||||
for (GithubUser githubUser : contributors) {
|
||||
contributorsAsList.add(githubUser);
|
||||
for (int exception : exceptions) {
|
||||
if (githubUser.id == exception) {
|
||||
contributorsAsList.remove(githubUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
// throw error
|
||||
KamiMod.log.error("Attempt to get contributors from github api failed.\nError:\n\n" + t.toString());
|
||||
MessageSendHelper.sendErrorMessage("Attempt to get contributors from github api failed.\nError:\n\n" + t.toString());
|
||||
}
|
||||
|
||||
return contributorsAsList;
|
||||
}
|
||||
|
||||
public class GithubUser {
|
||||
public String login;
|
||||
public int id;
|
||||
public String contributions;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue