Skip to content

Instantly share code, notes, and snippets.

@iProdigy
Created May 29, 2024 04:46
Show Gist options
  • Save iProdigy/53654691a76679221a74fd442dea068a to your computer and use it in GitHub Desktop.
Save iProdigy/53654691a76679221a74fd442dea068a to your computer and use it in GitHub Desktop.
export default {
async fetch(request, env, ctx) {
if (!isValidAgent(request.headers.get("User-Agent"))) {
return new Response();
}
const form = await request.formData();
const payload = JSON.parse(form.get("payload_json"));
const extra = payload.extra;
if (payload.type === "KILL_COUNT" && isNoteworthyKc(extra.boss, extra.count, extra.isPersonalBest)) {
return Response.redirect("https://discord.com/api/webhooks/redacted/redacted", 307);
}
return new Response();
},
};
function isNoteworthyKc(boss, kc, pb) {
if (pb || kc === 1) return true;
if (boss === "TzKal-Zuk") return kc % 5 === 0;
if (boss === "Sol Heredit") return kc % 25 === 0;
return kc % 100 === 0;
}
function isValidAgent(ua) {
if (typeof ua !== "string") return false;
if (!ua.startsWith("RuneLite/") && !ua.startsWith("HDOS/")) return false;
return ua.includes("Dink/");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment