Skip to content

Instantly share code, notes, and snippets.

@NotArchon
Created May 8, 2023 14:42
Show Gist options
  • Save NotArchon/2296494901d5654341db6f5da4a89604 to your computer and use it in GitHub Desktop.
Save NotArchon/2296494901d5654341db6f5da4a89604 to your computer and use it in GitHub Desktop.
package com.neox.web.model.voting;
import io.archon.misc.utils.EnumUtils;
import io.archon.webserver.network.HttpAsyncRequest;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.Map;
import java.util.function.Function;
@RequiredArgsConstructor
@Getter
public enum VotingSite {
// https://topg.org/voting_check
TOPG(
"TopG", "topg", true, 12, // confirmed 5/4/23
"https://topg.org/runescape-private-servers/in-653862-%USER-ID%",
"monitor.topg.org",
httpReq -> httpReq.getStringParam("p_resp")
),
// https://www.runelocus.com/tutorials/callback-documentation
RUNELOCUS(
"RuneLocus", "runelocus", true, 12, // confirmed 5/4/23
"https://www.runelocus.com/top-rsps-list/47282/vote?callback=%USER-ID%",
"callback.runelocus.com",
httpReq -> httpReq.getStringParam("callback")
),
// https://www.top100arena.com/content/incentive-voting
TOP100_ARENA(
"Top100 Arena", "top100arena", true, 24, // confirmed 5/4/23
"https://www.top100arena.com/listing/99916/vote?incentive=%USER-ID%",
"3.86.48.116", // listed on link above
httpReq -> httpReq.getStringParam("postback")
),
// https://runelist.io/setup-vote
RUNELIST(
"RuneList", "runelist", true, 24, // confirmed 5/4/23
"https://runelist.io/toplist/server/283/vote/%USER-ID%",
"66.248.237.69", // had to force a callback to get
httpReq -> {
String uri = httpReq.getUri();
int i = uri.lastIndexOf("/");
if(i == -1 || i == uri.length() - 1)
throw new IllegalStateException("incomplete uri");
return uri.substring(i + 1);
}
),
// 0 documentation for this site... but as of 5/8/23 this works
MOPARSCAPE(
"MoparScape", "moparscape", true, 12, // confirmed 5/4/23
"https://www.moparscape.org/rsps-list/server/neox?name=%USER-ID%",
"248.35.35.78", // had to force a callback to get
httpReq -> httpReq.getStringParam("name")
),
// https://www.rsps-list.com/incentive/
RSPS_LIST(
"RSPS-List", "rsps-list", true, 24, // todo confirm
"https://www.rsps-list.com/index.php?a=in&u=Neox&id=%USER-ID%",
"51.81.81.226", // had to force a callback to get
httpReq -> {
int voted = httpReq.getNumberParam("voted", 0).intValue(); // "either 1 to indicate a successful vote or 0 for a failed/duplicated one."
if(voted == 0)
return null; // not throwing an exception since their site allows users to keep voting
return httpReq.getStringParam("userid");
}
),
;
@Getter private static final Map<String, VotingSite> map = EnumUtils.map(values(), v -> Map.entry(v.siteKey, v));
@Getter private final String name;
private final String siteKey;
@Getter private final boolean active;
@Getter private final int resetHours;
@Getter private final String voteLink;
@Getter private final String expectedHost; // if request ip is not equal, the given host will be looked up
@Getter private final Function<HttpAsyncRequest, String> getUserId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment