raylu 1 semana atrás
pai
commit
cebcdd0188
5 arquivos alterados com 103 adições e 2 exclusões
  1. 1 0
      .gitignore
  2. 78 0
      ts/ci_newbies.ts
  3. 1 0
      tsconfig.json
  4. 21 0
      www/ci_newbies.html
  5. 2 2
      www/style.css

+ 1 - 0
.gitignore

@@ -4,6 +4,7 @@ config.toml
 node_modules/
 uv.lock
 www/buy.js*
+www/ci_newbies.js*
 www/coop.js*
 www/corps.js*
 www/gov.js*

+ 78 - 0
ts/ci_newbies.ts

@@ -0,0 +1,78 @@
+const sinceInput = document.querySelector('#since') as HTMLInputElement;
+const newbies = document.querySelector('textarea#newbies') as HTMLTextAreaElement;
+
+{
+	const twoDaysAgo = new Date();
+	twoDaysAgo.setUTCDate(twoDaysAgo.getUTCDate() - 2);
+	twoDaysAgo.setUTCHours(0, 0, 0, 0);
+	sinceInput.value = twoDaysAgo.toISOString().slice(0, 10);
+}
+
+sinceInput.addEventListener('change', () => void render());
+render();
+
+async function render(): Promise<void> {
+	const loader = document.querySelector('#loader') as HTMLElement;
+	loader.style.display = 'block';
+	try {
+		await _render();
+	} catch (e) {
+		console.error(e);
+	}
+	loader.style.display = 'none';
+}
+
+async function _render(): Promise<void> {
+	if (sinceInput.valueAsDate === null) {
+		console.warn(sinceInput.value, 'is not a valid date');
+		newbies.value = '';
+		return;
+	}
+	newbies.style.display = 'none';
+
+	const planets = ['Katoa'];
+	const joined: Map<string, Join> = new Map();
+	for (const planet of planets) {
+		const messages: Message[] = await fetchJSON('https://api.fnar.net/chat/messages?' + new URLSearchParams({
+			'channel_names': planet + ' Global Site Owners',
+			'updated_since': sinceInput.valueAsDate?.toISOString(),
+		}).toString());
+		for (const message of messages)
+			if (message.Type == 'JOINED') {
+				const old_join = joined.get(message.SenderUserName)
+				if (old_join === undefined || old_join.timestamp > message.MessageTimestamp)
+					joined.set(message.SenderUserName, {timestamp: message.MessageTimestamp, planet});
+			}
+	}
+
+	const sortedJoined = Array.from(joined.entries()).sort((a, b) => a[1].timestamp - b[1].timestamp);
+	const lines: string[] = [];
+	for (const [username, join] of sortedJoined) {
+		const dtStr = new Date(join.timestamp).toISOString().replace('T', ' ').replace('Z', '');
+		lines.push(`${username}\t${dtStr}\t${join.planet}`);
+	}
+	newbies.value = lines.join('\n');
+	newbies.style.display = 'block';
+}
+
+document.querySelector('#copy')!.addEventListener('click', () => {
+	navigator.clipboard.writeText(newbies.value);
+});
+
+async function fetchJSON(url: string, options: RequestInit = {}): Promise<any> {
+	const controller = new AbortController();
+	const timeoutId = setTimeout(() => controller.abort(), 5000);
+	const doc = await fetch(url, {...options, signal: controller.signal}).then((r) => r.json());
+	clearTimeout(timeoutId);
+	return doc;
+}
+
+interface Message {
+	Type: string;
+	MessageTimestamp: number;
+	SenderUserName: string;
+}
+interface Join {
+	timestamp: number;
+	planet: string;
+}

+ 1 - 0
tsconfig.json

@@ -9,6 +9,7 @@
 		"skipLibCheck": true,
 		"forceConsistentCasingInFileNames": true,
 		"moduleResolution": "bundler",
+		"moduleDetection": "force",
 		"isolatedModules": true,
 		"sourceMap": true,
 	},

+ 21 - 0
www/ci_newbies.html

@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="UTF-8">
+	<title>PrUn CI newbies</title>
+	<link rel="stylesheet" type="text/css" href="style.css">
+	<link rel="icon" href="https://www.raylu.net/hammer-man.svg" />
+	<meta name="viewport" content="width=device-width, initial-scale=1">
+	<meta name="theme-color" content="#222">
+</head>
+<body>
+	<a href="/">← back</a>
+	<main class="newbies">
+		<input type="date" id="since">
+		<section id="loader"></section>
+		<br><textarea id="newbies"></textarea>
+		<br><input type="button" id="copy" value="copy">
+	</main>
+	<script src="ci_newbies.js"></script>
+</body>
+</html>

+ 2 - 2
www/style.css

@@ -232,8 +232,8 @@ main.mat {
 	}
 }
 
-main.ledger {
-	textarea#ledger {
+main.ledger, main.newbies {
+	textarea {
 		margin-top: 2em;
 		width: 100%;
 		height: 70vh;