Skip to content

Commit

Permalink
Incorporate params, needs testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kractero committed Oct 15, 2023
1 parent 16d8078 commit c01024e
Show file tree
Hide file tree
Showing 22 changed files with 356 additions and 379 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
name: Deploy to GitHub Pages


on:
push:
branches: 'main'


jobs:
build_site:
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion src/lib/component/Textarea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
export let text: string;
export let bindValue: string | number | undefined;
export let forValue: string;
export let required: boolean = false;;
export let required: boolean = false;
export let disabled: boolean = false;
</script>

<div class="flex gap-4 justify-between max-w-lg">
<label class="w-24" for={forValue}>{text}</label>
<textarea
required={required}
id={forValue}
disabled={disabled}
rows="10"
bind:value={bindValue}
class="text-right text-black p-2 w-96 rounded-md border border-black dark:border-none"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/lib/loadStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function loadStorage(key: string) {
switch (key) {
case 'stationJDJ':
case 'junkdajunkRarities':
return {
common: Number(localStorage.getItem(`${key}Common`)) || 0.5,
uncommon: Number(localStorage.getItem(`${key}Uncommon`)) || 1,
Expand Down
21 changes: 15 additions & 6 deletions src/routes/tools/approval/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@
import { onDestroy, onMount } from 'svelte';
import { parser, sleep } from '$lib/globals';
import Head from '$lib/component/Head.svelte';
import { loadLocalStorage } from '$lib/loadLocalStorage';
import Terminal from '$lib/component/Terminal.svelte';
import Buttons from '$lib/component/Buttons.svelte';
import Input from '$lib/component/Input.svelte';
import { htmlContent } from '$lib/htmlContent';
import { handleDownload } from '$lib/download';
import Select from '$lib/component/Select.svelte';
const abortController = new AbortController();
import type { PageData } from './$types';
import { loadStorage } from '$lib/loadStorage';
import { pushHistory } from '$lib/helpers/utils';
export let data: PageData;
let progress = "";
let main = "";
let content = "";
let downloadable = false;
let council = "General Assembly";
let proposalid = "";
onMount(() => ({main, council, proposalid} = loadLocalStorage(["stationMain", "stationCouncil", "stationProposalID"])));
let main: string;
let council: string;
let proposalid: string;
onMount(() => {
main = data.parameters.main || loadStorage("useragent") as string || "";
council = data.parameters.council || loadStorage("approvalCouncil") as string || "General Assembly";
proposalid = data.parameters.proposal || loadStorage("approvalProposal") as string || "";
});
onDestroy(() => abortController.abort() );
async function approvals() {
pushHistory(`?main=${main}&council=${council}&proposal=${proposalid}`)
downloadable = false;
let councilID = 1;
if (council === "Security Council") {
Expand Down Expand Up @@ -84,7 +93,7 @@
<label class="w-24" for="mode">Council</label>
<Select bind:mode={council} options={['General Assembly', 'Security Council']} />
</div>
<Input text="Proposal ID" bind:bindValue={proposalid} forValue="proposalID" required={false} />
<Input text="Proposal ID" bind:bindValue={proposalid} forValue="proposalID" required={true} />
<Buttons>
<button disabled={!downloadable} type="button" on:click={() => handleDownload('html', htmlContent(content), 'Approvals')}
class="bg-green-500 rounded-md px-4 py-2 transition duration-300 hover:bg-green-300 disabled:opacity-20 disabled:hover:bg-green-500">
Expand Down
7 changes: 2 additions & 5 deletions src/routes/tools/containerise/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<script lang="ts">
import { handleDownload } from '$lib/download';
import { nsIterator } from '$lib/txtIterator';
import { onMount } from 'svelte';
import Head from '$lib/component/Head.svelte';
import { loadLocalStorage } from '$lib/loadLocalStorage';
import Terminal from '$lib/component/Terminal.svelte';
import Buttons from '$lib/component/Buttons.svelte';
import Textarea from '$lib/component/Textarea.svelte';
let progress = "";
let puppets = '';
let content: Array<string>;
let downloadable = false;
onMount(() => ({puppets} = loadLocalStorage(["stationPuppets"])));
async function containerise(puppets: string) {
async function containerise() {
downloadable = false;
content = (await nsIterator(puppets, 'Container Rules')) as Array<string>;
progress = `<p>Finished processing</p>`;
Expand Down Expand Up @@ -43,7 +40,7 @@
</p>

<div class="lg:w-[1024px] lg:max-w-5xl flex flex-col lg:flex-row gap-8 break-normal">
<form on:submit|preventDefault={() => containerise(puppets)} class="flex flex-col gap-8">
<form on:submit|preventDefault={() => containerise()} class="flex flex-col gap-8">
<Textarea text="Puppets" bind:bindValue={puppets} forValue="pup" required />
<Buttons>
<button disabled={!downloadable} on:click={() => handleDownload('txt', content, '')}
Expand Down
1 change: 1 addition & 0 deletions src/routes/tools/containerise/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const prerender = true;
15 changes: 6 additions & 9 deletions src/routes/tools/creation/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@
import { handleDownload } from '$lib/download';
import { htmlContent } from '$lib/htmlContent';
import { nsIterator } from '$lib/txtIterator';
import { onMount } from 'svelte';
import InputCredentials from '$lib/component/InputCredentials.svelte';
import Terminal from '$lib/component/Terminal.svelte';
import Head from '$lib/component/Head.svelte';
import { loadLocalStorage } from '$lib/loadLocalStorage';
import Buttons from '$lib/component/Buttons.svelte';
import Textarea from '$lib/component/Textarea.svelte';
let progress = "";
let puppets = '';
let main = '';
let content: string;
let downloadable = false;
onMount(() => ({puppets, main} = loadLocalStorage(["stationPuppets", "stationMain"])));
let puppets = '';
async function login(puppets: string) {
downloadable = false;
content = (await nsIterator(puppets, 'Creator', main)) as string;
content = (await nsIterator(puppets, 'Creator')) as string;
progress = "<p>Finished processing</p>"
downloadable = true;
}
</script>

<Head title={"Hare - Creator Assitant"} description={"Generate a sheet that has links for nation creation that works with the provided userscripts."} />
<Head title={"Hare - Creator Assistant"} description={"Generate a sheet that has links for nation creation that works with the provided userscripts."} />

<h1 class="text-4xl mb-2">Creator Assistant</h1>
<p class="text-xs mb-1">
Expand All @@ -40,7 +37,7 @@

<div class="lg:w-[1024px] lg:max-w-5xl flex flex-col lg:flex-row gap-8 break-normal">
<form on:submit|preventDefault={() => login(puppets)} class="flex flex-col gap-8">
<InputCredentials bind:main bind:puppets authenticated={false} />
<Textarea text="Puppets" bind:bindValue={puppets} forValue="pup" required />
<Buttons>
<button disabled={!downloadable} on:click={() => handleDownload('html', htmlContent(content), 'Creator')}
class="bg-green-500 rounded-md px-4 py-2 transition duration-300 hover:bg-green-300 disabled:opacity-20 disabled:hover:bg-green-500">
Expand Down
1 change: 1 addition & 0 deletions src/routes/tools/creation/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const prerender = true;
103 changes: 56 additions & 47 deletions src/routes/tools/endotart/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,59 @@
import { onDestroy, onMount } from 'svelte';
import { parseXML, parser, sleep } from '$lib/globals';
import Head from '$lib/component/Head.svelte';
import { loadLocalStorage } from '$lib/loadLocalStorage';
import Terminal from '$lib/component/Terminal.svelte';
import Buttons from '$lib/component/Buttons.svelte';
import Input from '$lib/component/Input.svelte';
import Textarea from '$lib/component/Textarea.svelte';
import type { NSNation, Nation, Region } from '$lib/types';
import Select from '$lib/component/Select.svelte';
const abortController = new AbortController();
import type { PageData } from './$types';
import { loadStorage } from '$lib/loadStorage';
import { pushHistory } from '$lib/helpers/utils';
export let data: PageData;
let progress = "";
let main = "";
let endotartnation = '';
let stopped = false;
let stoppable = false;
let immune = "";
let endotartsource = "XML";
let limit: number | undefined = undefined;
onMount(() => ({ main, endotartnation, limit, endotartsource } = loadLocalStorage(["stationMain", "stationEndotartNation", "stationEndotartLimit", "stationEndotartSource"])));
let source: string;
let main: string;
let endotarter: string;
let immune: string;
let limit: string;
onMount(() => {
main = data.parameters.main || loadStorage("useragent") as string || "";
endotarter = data.parameters.endotarter || loadStorage("endotartEndotarter") as string || "";
immune = data.parameters.immune ? data.parameters.immune.replaceAll(',', '\n') : loadStorage("endotartImmune") as string || "";
limit = data.parameters.limit || loadStorage("endotartLimit") as string || "";
source = data.parameters.source || loadStorage("endotartSource") as string || "XML";
});
onDestroy(() => abortController.abort() );
async function findWA() {
async function endotart() {
pushHistory(`?main=${main}${limit ? `&limit=${limit}` : ""}&nation=${endotarter}&source=${source}${immune ? `&immune=${immune}` : ""}`);
progress = "";
stoppable = true;
stopped = false;
const whiteList = immune ? immune.split('\n').map(nation => nation.toLowerCase().replace(' ', '_')) : [];
const regionalXML: Nation = await parseXML(`https://www.nationstates.net/cgi-bin/api.cgi?nation=${endotartnation}&q=endorsements+region+wa`, main)
const regionalXML: Nation = await parseXML(`https://www.nationstates.net/cgi-bin/api.cgi?nation=${endotarter}&q=endorsements+region+wa`, main)
if (regionalXML.NATION.UNSTATUS === "Non-member") {
progress += `<p class="text-red-400">${endotartnation} is not in the WA.</p>`
progress += `<p class="text-red-400">${endotarter} is not in the WA.</p>`
return;
}
await sleep(700)
progress += `<p>Searching for the nations in ${regionalXML.NATION.REGION} not being endorsed by ${endotartnation}, using the ${endotartsource}</p>`
const wamems: Region = await parseXML(`https://www.nationstates.net/cgi-bin/api.cgi?region=${regionalXML.NATION.REGION}&q=wanations`, main)
progress += `<p>Searching for the nations in ${regionalXML.NATION.REGION} not being endorsed by ${endotarter}, using the ${source}</p>`
if (whiteList.length > 0) {
progress += `<p>Nations immune to endocap: ${whiteList.map((region) => region.trim()).join(', ')}</p>`;
}
const wamems: Region = await parseXML(`https://www.nationstates.net/cgi-bin/api.cgi?region=${regionalXML.NATION.REGION}&q=wanations`, main)
const regionalWA = wamems.REGION.UNNATIONS.split(',')
let xml;
let NAME;
let ENDORSEMENTS;
if (endotartsource === "XML") {
if (source === "XML") {
const currentDate = new Date();
const utcMinus7Date = new Date(currentDate.getTime() - 7 * 60 * 60 * 1000);
utcMinus7Date.setDate(utcMinus7Date.getDate() - 1);
Expand All @@ -50,12 +64,13 @@
method: "GET"
});
if (nationRes.status === 404) {
progress += `<p>Could not find ${date} national dump, defaulting to the API.</p>`
endotartsource = "API";
progress += `<p class="text-yellow-400">Could not find ${date} national dump, defaulting to the API.</p>`
source = "API";
} else {
progress += `<p class="text-green-400">Found ${date} national dump.</p>`
progress += `<p>Parsing dump for endotarting...</p>`
const regionText = await nationRes.text()
xml = parser.parse(regionText)
progress += `<p>Found ${date} national dump.</p>`
}
}
Expand All @@ -64,44 +79,38 @@
break;
}
if (endotartsource === "API") {
if (source === "API") {
await sleep(700);
xml = await parseXML(`https://www.nationstates.net/cgi-bin/api.cgi?nation=${regionalWA[i]}&q=endorsements+name`, main) as Nation
NAME = String(xml.NATION.NAME);
ENDORSEMENTS = String(xml.NATION.ENDORSEMENTS).includes(',') ? xml.NATION.ENDORSEMENTS.split(',') : [xml.NATION.ENDORSEMENTS];
await sleep(700);
} else {
const nations = (xml.NATIONS.NATION as Array<NSNation>).filter(nation => String(nation.NAME).toLowerCase().replace(/ /g, '_') === (regionalWA[i].toLowerCase()));
if (nations.length > 0) {
({ NAME, ENDORSEMENTS } = nations[0])
} else {
progress += `<p class="text-yellow-400">${i+1}/${regionalWA.length} ${regionalWA[i]} not found, likely not in the dump yet`
}
const nations = (xml.NATIONS.NATION as Array<NSNation>).filter(nation => String(nation.NAME).toLowerCase().replace(/ /g, '_') === (regionalWA[i].toLowerCase()))[0];
({ NAME, ENDORSEMENTS } = nations)
}
if (NAME && ENDORSEMENTS) {
if (endotartnation.toLowerCase().replaceAll(' ', '_') === String(NAME).toLowerCase().replaceAll(' ', '_')) {
progress += `<p class="text-yellow-400 font-extralight">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> is the endotart nation.</p>`
} else if (limit) {
if (whiteList.includes(regionalWA[i])) {
progress += `<p class="text-yellow-400 font-extralight">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> is in your immune nations.</p>`
} else if (ENDORSEMENTS.length < limit && !ENDORSEMENTS.includes(endotartnation.toLowerCase().replaceAll(' ', '_')) && regionalWA[i] !== endotartnation.toLowerCase().replaceAll(' ', '_')) {
progress += `<p class="text-green-400">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> is not being endorsed by ${endotartnation}.</p>`
} else if (ENDORSEMENTS.length > limit) {
progress += `<p class="text-red-400 font-extralight">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> has more than ${limit} endorsements.</p>`
} else {
progress += `<p class="text-red-400 font-extralight">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> is already endorsed by ${endotartnation}.</p>`
}
if (endotartnation.toLowerCase().replaceAll(' ', '_') === String(NAME).toLowerCase().replaceAll(' ', '_')) {
progress += `<p class="text-yellow-400 font-extralight">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> is the endotart nation.</p>`
} else if (limit) {
if (whiteList.includes(regionalWA[i])) {
progress += `<p class="text-yellow-400 font-extralight">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> is in your immune nations.</p>`
} else if (ENDORSEMENTS.length < limit && !ENDORSEMENTS.includes(endotartnation.toLowerCase().replaceAll(' ', '_')) && regionalWA[i] !== endotartnation.toLowerCase().replaceAll(' ', '_')) {
progress += `<p class="text-green-400">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> is not being endorsed by ${endotartnation}.</p>`
} else if (ENDORSEMENTS.length > limit) {
progress += `<p class="text-red-400 font-extralight">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> has more than ${limit} endorsements.</p>`
} else {
progress += `<p class="text-red-400 font-extralight">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> is already endorsed by ${endotartnation}.</p>`
}
} else {
if (!ENDORSEMENTS.includes(endotartnation.toLowerCase().replaceAll(' ', '_')) && regionalWA[i] !== endotartnation.toLowerCase().replaceAll(' ', '_')) {
progress += `<p class="text-green-400">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> is not being endorsed by ${endotartnation}.</p>`
} else {
if (!ENDORSEMENTS.includes(endotartnation.toLowerCase().replaceAll(' ', '_')) && regionalWA[i] !== endotartnation.toLowerCase().replaceAll(' ', '_')) {
progress += `<p class="text-green-400">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> is not being endorsed by ${endotartnation}.</p>`
} else {
progress += `<p class="text-red-400 font-extralight">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> is already endorsed by ${endotartnation}.</p>`
}
progress += `<p class="text-red-400 font-extralight">${i+1}/${regionalWA.length} <a class="underline" href="https://nationstates.net/nation=${regionalWA[i]}"}>${regionalWA[i]}</a> is already endorsed by ${endotartnation}.</p>`
}
}
}
progress += `<p>Finished searching ${regionalXML.NATION.REGION} for nations not being endorsed by ${endotartnation}</p>`
progress += `<p>Finished searching ${regionalXML.NATION.REGION} for nations not being endorsed by ${endotarter}</p>`
stoppable = false;
}
</script>
Expand All @@ -114,13 +123,13 @@
<p class="mb-16">Specify a nation and get all the regionmates they are not endorsing.</p>

<div class="lg:w-[1024px] lg:max-w-5xl flex flex-col lg:flex-row gap-8 break-normal">
<form on:submit|preventDefault={findWA} class="flex flex-col gap-8">
<Input text="User Agent" bind:bindValue={main} forValue="main" required={true} />
<Input text="Endotart Nation" bind:bindValue={endotartnation} forValue="endotartnation" required={true} />
<form on:submit|preventDefault={endotart} class="flex flex-col gap-8">
<Input text="User main" bind:bindValue={main} forValue="main" required={true} />
<Input text="Endotart Nation" bind:bindValue={endotarter} forValue="endotarter" required={true} />
<Input text="Endorse Limit" bind:bindValue={limit} forValue="limit" required={false} />
<div class="flex gap-4 justify-between max-w-lg">
<label class="w-24" for="mode">Source</label>
<Select bind:mode={endotartsource} options={["XML", "API"]} />
<Select bind:mode={source} options={["XML", "API"]} />
</div>
<Textarea text="Immune Nations" bind:bindValue={immune} forValue="immune" />
<Buttons>
Expand All @@ -138,4 +147,4 @@
</Buttons>
</form>
<Terminal bind:progress={progress} />
</div>
</div>
Loading

0 comments on commit c01024e

Please sign in to comment.