Add standalone complete Armoury and DiscordSRV-backed Diplomacy register
This commit is contained in:
parent
26df7d6958
commit
7ce8ead5d0
33 changed files with 157 additions and 26 deletions
|
|
@ -1,6 +1,6 @@
|
|||
plugins { java }
|
||||
group = "com.example"
|
||||
version = "1.0.9"
|
||||
version = "1.0.10"
|
||||
repositories { mavenCentral(); maven("https://repo.papermc.io/repository/maven-public/"); maven("https://jitpack.io") }
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ final class DiscordWebFeed implements Listener {
|
|||
DiscordWebFeed(DuneCore plugin) { this.plugin = plugin; }
|
||||
void start() {
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, this::exchange, 200L, 1200L);
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> { exchange(); diplomacy(); }, 200L, 1200L);
|
||||
}
|
||||
boolean enabled() { return plugin.getConfig().getBoolean("website.discord.enabled", false)
|
||||
&& Bukkit.getPluginManager().isPluginEnabled("DiscordSRV"); }
|
||||
|
|
@ -58,6 +58,21 @@ final class DiscordWebFeed implements Listener {
|
|||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "discordsrv broadcast #" + channel + " " + content);
|
||||
}
|
||||
static List<String> encode(String json) throws IOException {
|
||||
return encode(json, "DUNE_EXCHANGE");
|
||||
}
|
||||
private void diplomacy() {
|
||||
if (!enabled() || plugin.politics() == null) return;
|
||||
if (!plugin.getConfig().getString("network.local-planet", "arrakis").equalsIgnoreCase("arrakis")) return;
|
||||
try {
|
||||
for (String part : encode(gson.toJson(plugin.politics().websiteSnapshot()), "DUNE_DIPLOMACY"))
|
||||
send("diplomacy-channel-id", part);
|
||||
} catch (IOException | IllegalArgumentException ex) {
|
||||
plugin.getLogger().warning("Website diplomacy snapshot skipped: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
static List<String> encode(String json, String prefix) throws IOException {
|
||||
if (!prefix.equals("DUNE_EXCHANGE") && !prefix.equals("DUNE_DIPLOMACY"))
|
||||
throw new IllegalArgumentException("Unsupported website snapshot type");
|
||||
byte[] raw = json.getBytes(StandardCharsets.UTF_8);
|
||||
if (raw.length > 2_000_000) throw new IllegalArgumentException("Market exceeds the supported 2 MB snapshot limit");
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
|
|
@ -67,7 +82,7 @@ final class DiscordWebFeed implements Listener {
|
|||
if (parts > 90) throw new IllegalArgumentException("Market exceeds 90 Discord snapshot parts");
|
||||
String id = UUID.randomUUID().toString();
|
||||
List<String> messages = new ArrayList<>();
|
||||
for (int i = 0; i < parts; i++) messages.add("DUNE_EXCHANGE " + id + " " + (i + 1) + "/" + parts + " "
|
||||
for (int i = 0; i < parts; i++) messages.add(prefix + " " + id + " " + (i + 1) + "/" + parts + " "
|
||||
+ payload.substring(i * 1700, Math.min((i + 1) * 1700, payload.length())));
|
||||
return messages;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,4 +180,51 @@ public final class Politics {
|
|||
}
|
||||
public String leader(String house) {refresh();return winnerName("votes.house."+week()+"."+house);}
|
||||
public String emperor() {refresh();return winnerName("votes.emperor."+week());}
|
||||
/** Public current offices only: never export UUIDs, ballot records or expired appointments. */
|
||||
public synchronized Map<String,Object> websiteSnapshot() {
|
||||
refresh();
|
||||
return publicSnapshot(state, week());
|
||||
}
|
||||
static Map<String,Object> publicSnapshot(YamlConfiguration record, long bucket) {
|
||||
Map<String,Object> snapshot = new LinkedHashMap<>();
|
||||
snapshot.put("type", "dune_diplomacy");
|
||||
snapshot.put("updatedAt", Instant.now().toString());
|
||||
snapshot.put("electionWeek", bucket);
|
||||
List<Map<String,Object>> leaders = new ArrayList<>();
|
||||
for (String house : HOUSES) {
|
||||
Map<String,Object> office = new LinkedHashMap<>();
|
||||
office.put("faction", house);
|
||||
office.put("leader", publicWinnerName(record, "votes.house."+bucket+"."+house));
|
||||
leaders.add(office);
|
||||
}
|
||||
snapshot.put("leaders", leaders);
|
||||
String emperorPrefix = "votes.emperor."+bucket;
|
||||
String emperorId = recordWinnerId(record, emperorPrefix);
|
||||
snapshot.put("emperor", publicWinnerName(record, emperorPrefix));
|
||||
for (String key : new String[]{"steward", "water"}) {
|
||||
String root = "appointments."+key;
|
||||
String appointedHouse = record.getString(root+".house", "");
|
||||
boolean valid = !emperorId.isBlank() && record.getLong(root+".week", -1)==bucket
|
||||
&& emperorId.equals(record.getString(root+".emperor", ""))
|
||||
&& Arrays.asList(HOUSES).contains(appointedHouse);
|
||||
snapshot.put(key.equals("steward")?"spiceSteward":"houseOfWater", valid?appointedHouse:null);
|
||||
}
|
||||
return snapshot;
|
||||
}
|
||||
private static String recordWinnerId(YamlConfiguration record, String prefix) {
|
||||
var tally = record.getConfigurationSection(prefix+".tally");
|
||||
if (tally == null) return "";
|
||||
String best=""; int score=0;
|
||||
for (String id : tally.getKeys(false)) {
|
||||
int n=tally.getInt(id);
|
||||
if(n>score || (n==score && id.compareTo(best)<0)){best=id;score=n;}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
private static String publicWinnerName(YamlConfiguration record, String prefix) {
|
||||
String id=recordWinnerId(record,prefix);
|
||||
if(id.isBlank()) return null;
|
||||
String name=record.getString(prefix+".names."+id, "Unknown player");
|
||||
return name.matches("[A-Za-z0-9_]{1,32}")?name:"Unknown player";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,3 +67,4 @@ website:
|
|||
enabled: false
|
||||
exchange-channel-id: ""
|
||||
news-channel-id: ""
|
||||
diplomacy-channel-id: ""
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
name: DuneCore
|
||||
version: 1.0.9
|
||||
version: 1.0.10
|
||||
main: com.example.dunerealms.DuneCore
|
||||
api-version: '1.21'
|
||||
depend: [Vault, DuneEss]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package com.example.dunerealms;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.util.UUID;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
class DiplomacySnapshotTest {
|
||||
@Test void publicOfficesExcludeBallotsIdsAndExpiredAppointments() throws Exception {
|
||||
var record=new YamlConfiguration(); String id=UUID.randomUUID().toString(); long week=42;
|
||||
record.set("votes.emperor.42.tally."+id,2);
|
||||
record.set("votes.emperor.42.names."+id,"MuadDib");
|
||||
record.set("votes.house.42.Fremen.tally."+id,1);
|
||||
record.set("votes.house.42.Fremen.names."+id,"MuadDib");
|
||||
record.set("appointments.steward.week",42);
|
||||
record.set("appointments.steward.emperor",id);
|
||||
record.set("appointments.steward.house","Atreides");
|
||||
record.set("appointments.water.week",41);
|
||||
record.set("appointments.water.emperor",id);
|
||||
record.set("appointments.water.house","Corrino");
|
||||
var snapshot=Politics.publicSnapshot(record,week);
|
||||
assertEquals("MuadDib",snapshot.get("emperor"));
|
||||
assertEquals("Atreides",snapshot.get("spiceSteward"));
|
||||
assertNull(snapshot.get("houseOfWater"));
|
||||
assertFalse(snapshot.toString().contains(id));
|
||||
assertNull(Politics.publicSnapshot(record,43).get("emperor"));
|
||||
record.set("votes.emperor.42.tally."+UUID.randomUUID(),3);
|
||||
assertNull(Politics.publicSnapshot(record,42).get("spiceSteward"));
|
||||
assertTrue(DiscordWebFeed.encode("{}","DUNE_DIPLOMACY").getFirst().startsWith("DUNE_DIPLOMACY "));
|
||||
assertThrows(IllegalArgumentException.class,()->DiscordWebFeed.encode("{}","BAD"));
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
A Dune-themed Minecraft Java plugin suite for **Paper 1.21.4 and Java 21**. Explore Arrakis, harvest melange, join a faction, trade through the Spacing Guild, and encounter Shai-Hulud.
|
||||
|
||||
**[Project Dune website](https://project-dune.bonnystoat9.chatgpt.site)** — illustrated landing page, searchable online manual, Races & Houses, Exchange and News. The Site currently requires owner access through ChatGPT. Live feeds show “server not connected” until configured; see [DiscordSRV integration](website/DISCORD-FEEDS.md).
|
||||
**[Project Dune website](https://project-dune.bonnystoat9.chatgpt.site)** — illustrated landing page, searchable online manual, Races & Houses, Exchange and News. The website is public; profiles and private support tickets require sign-in. Live feeds show “server not connected” until configured; see [DiscordSRV integration](website/DISCORD-FEEDS.md).
|
||||
|
||||
**[Read the illustrated user manual](docs/Dune-User-Manual.pdf)** for the complete player and administrator guide, command reference, default configuration, 77 pages, 68 illustrated item and interface icons, ornate Minecraft-inspired House and spice backgrounds, and reserved chapters for the other planets.
|
||||
|
||||
|
|
@ -175,3 +175,6 @@ and links back to the Dune admin menu. `/dunenpc smuggle status|cancel` is avail
|
|||
All missions last **30 real minutes**, including offline/server downtime. Older contracts receive
|
||||
one 30-minute deadline on migration. Remaining time appears in the contract menu and status command.
|
||||
Expiry pays nothing, keeps cargo, and clears the camp once its last contract ends.
|
||||
|
||||
Sietch Armoury now has its own page with all 68 item entries and full suit abilities. Diplomacy displays current leaders, Emperor, Spice Steward and House of Water through the opt-in DuneCore 1.0.10 DiscordSRV snapshot bridge. Configure the dedicated diplomacy channel as described in website/DISCORD-FEEDS.md.
|
||||
|
||||
|
|
|
|||
|
|
@ -8,3 +8,5 @@ DISCORD_NEWS_CHANNEL_ID=
|
|||
# Comma-separated staff account emails; store as secrets in Sites.
|
||||
FORUM_ADMIN_EMAILS=
|
||||
SUPPORT_STAFF_EMAILS=
|
||||
|
||||
DISCORD_DIPLOMACY_CHANNEL_ID=
|
||||
|
|
|
|||
|
|
@ -75,3 +75,12 @@ Decoded schema:
|
|||
Run `node --test tests/feed-api.test.mjs` for unconnected state, multipart assembly, author filtering, partial/stale rejection and malformed offer validation. Run the Core Gradle tests for publisher encoding and existing gameplay regressions. Live DiscordSRV delivery requires a running server and configured channels.
|
||||
|
||||
Primary references: [DiscordSRV broadcast command](https://docs.discordsrv.com/commands/), [Discord Get Channel Messages](https://github.com/discord/discord-api-docs/blob/main/developers/resources/message.mdx), [Discord permissions](https://github.com/discord/discord-api-docs/blob/main/developers/topics/permissions.mdx).
|
||||
|
||||
|
||||
## Diplomacy register (DuneCore 1.0.10)
|
||||
|
||||
Set `website.discord.diplomacy-channel-id` to a dedicated Discord channel and configure the matching secret `DISCORD_DIPLOMACY_CHANNEL_ID` in Sites. Retain the existing server-side bot token and publisher ID. The same bot must have View Channel and Read Message History on that channel. No bot token belongs in browser files. The opt-in `website.discord.enabled` switch remains required. The Arrakis backend publishes a snapshot every 60 seconds via DiscordSRV.
|
||||
|
||||
`DUNE_DIPLOMACY <snapshot-id> <part>/<total> <base64>` uses the same gzip multipart format as exchange. The JSON type is `dune_diplomacy` with `updatedAt`, `electionWeek`, `leaders` (five faction/name pairs), `emperor`, `spiceSteward`, `houseOfWater`. Unelected/unappointed offices are null. Appointments are factions, not individual players. Expired appointments are excluded. Ballots, voter identities and UUIDs are not exported.
|
||||
|
||||
The website verifies publisher identity, full multipart delivery, supported faction names and snapshot freshness (five minutes). Missing configuration displays Server not connected; absent fresh records display awaiting snapshot. It does not guess current offices from chat messages. This is a read-only view: voting, appointments and diplomatic actions remain in Minecraft. The existing local/shared politics prototype limitations still apply.
|
||||
|
|
|
|||
|
|
@ -14,3 +14,5 @@ Art is reused from the Project Dune manual and optimized into WebP. Concept-art
|
|||
|
||||
See [Forums and player support](FORUMS-PORTAL.md) for independent forums, the YouSMP Discord page and private profile-based tickets.
|
||||
|
||||
|
||||
The standalone [Sietch Armoury](https://project-dune.bonnystoat9.chatgpt.site/armoury.html) contains all 68 illustrated item entries and full suit abilities. [Diplomacy](https://project-dune.bonnystoat9.chatgpt.site/diplomacy.html) reads the DuneCore 1.0.10 current-office snapshot via a dedicated DiscordSRV channel.
|
||||
|
|
|
|||
7
website/tests/diplomacy-api.test.mjs
Normal file
7
website/tests/diplomacy-api.test.mjs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import test from 'node:test';import assert from 'node:assert/strict';import {gzipSync} from 'node:zlib';import {handleFeed,decodeSnapshot,sanitizeDiplomacy} from '../worker/feed-api.mjs';
|
||||
const publisher='123456789012345678';const fresh=()=>({type:'dune_diplomacy',updatedAt:new Date().toISOString(),electionWeek:Math.floor(Date.now()/604800000),emperor:'MuadDib',spiceSteward:'Atreides',houseOfWater:null,leaders:['Fremen','Harkonnen','Corrino','Atreides','Ordos'].map(faction=>({faction,leader:faction==='Fremen'?'Stilgar':null}))});
|
||||
function encode(data){const payload=gzipSync(JSON.stringify(data)).toString('base64');return [{author:{id:publisher},content:'DUNE_DIPLOMACY state 1/1 '+payload,timestamp:new Date().toISOString()}]}
|
||||
test('Diplomacy is honestly disconnected without its configured channel',async()=>{const r=await handleFeed(new Request('https://example.test/api/diplomacy'),{});assert.equal((await r.json()).status,'not_connected')});
|
||||
test('Fresh verified snapshots return public offices only',async()=>{const data=fresh();data.ballots={secret:'player-id'};const r=await decodeSnapshot(encode(data),publisher,'diplomacy');assert.equal(r.emperor,'MuadDib');assert.equal(r.spiceSteward,'Atreides');assert.equal(r.leaders.length,5);assert.ok(!JSON.stringify(r).includes('secret'))});
|
||||
test('Wrong publishers, stale data and invalid offices are rejected',async()=>{assert.equal(await decodeSnapshot(encode(fresh()),'987654321098765432','diplomacy'),null);const stale=fresh();stale.updatedAt=new Date(Date.now()-600000).toISOString();assert.equal(await decodeSnapshot(encode(stale),publisher,'diplomacy'),null);const bad=fresh();bad.leaders[1].faction='Fremen';assert.equal(sanitizeDiplomacy(bad),null);bad.leaders=fresh().leaders;bad.emperor='<script>alert(1)</script>';assert.equal(sanitizeDiplomacy(bad),null)});
|
||||
test('Exchange and diplomacy payloads cannot cross feed types',async()=>{assert.equal(await decodeSnapshot(encode(fresh()),publisher),null);const data=fresh();const messages=encode(data);messages[0].content=messages[0].content.replace('DUNE_DIPLOMACY','DUNE_EXCHANGE');assert.equal(await decodeSnapshot(messages,publisher,'diplomacy'),null)});
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import test from 'node:test';import assert from 'node:assert/strict';import worker from '../dist/server/index.js';
|
||||
test('Built Worker serves all fifteen separate pages and site assets',async()=>{for(const path of ['/','/arrakis.html','/smugglers.html','/equipment.html','/admin.html','/install.html','/manual.html','/races.html','/exchange.html','/news.html','/forums.html','/discord.html','/portal.html','/profile.html','/tickets.html','/manual-data.json','/assets/item-0.webp']){const response=await worker.fetch(new Request('https://example.test'+path),{});assert.equal(response.status,200,path);assert.ok((await response.arrayBuffer()).byteLength>0,path)}});
|
||||
test('Built Worker serves all seventeen separate pages and site assets',async()=>{for(const path of ['/','/arrakis.html','/smugglers.html','/equipment.html','/admin.html','/install.html','/manual.html','/races.html','/exchange.html','/news.html','/forums.html','/armoury.html','/diplomacy.html','/discord.html','/portal.html','/profile.html','/tickets.html','/manual-data.json','/assets/item-0.webp']){const response=await worker.fetch(new Request('https://example.test'+path),{});assert.equal(response.status,200,path);assert.ok((await response.arrayBuffer()).byteLength>0,path)}});
|
||||
test('Built Worker retains unconnected feed state without leaking secrets',async()=>{const response=await worker.fetch(new Request('https://example.test/api/news'),{});const text=await response.text();assert.equal(JSON.parse(text).status,'not_connected');assert.ok(!text.includes('DISCORD_BOT_TOKEN'))});
|
||||
test('Unsupported paths and write requests are rejected',async()=>{assert.equal((await worker.fetch(new Request('https://example.test/missing'),{})).status,404);assert.equal((await worker.fetch(new Request('https://example.test/api/exchange',{method:'POST'}),{})).status,405)});
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
3
website/web/armoury.css
Normal file
3
website/web/armoury.css
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.armoury-catalogue,.diplomacy-section{padding:45px 6% 65px;max-width:1450px;margin:auto}.armoury-catalogue>p{font-size:13px;color:#c4cdb5;max-width:950px;line-height:1.8}.armoury-jumps{position:static;display:flex;flex-wrap:wrap;gap:10px;background:none;padding:0;margin:30px 0;border:0}.armoury-jumps a{font:20px VT323,monospace;padding:9px 13px;background:#29402e;border:2px solid #a38b51;color:#e6cd91}.armoury-chapter{margin:40px 0;padding:30px;background:#efe3c5;color:#283d2a;border:4px solid #b28b46;box-shadow:4px 5px #09180f;scroll-margin-top:20px}.armoury-chapter h2{font-size:52px;color:#2a422c}.armoury-chapter>p,.armoury-chapter li{font-size:12px;line-height:1.9}.armoury-chapter .equipment-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:20px;margin:25px 0}.armoury-chapter .equipment-grid article{border:2px solid #a28a53;padding:18px;background:#e1d5b2;min-width:0}.armoury-chapter .equipment-grid img{width:100%;aspect-ratio:1;object-fit:contain;background:#faf6e6;border:1px solid #a18c54}.armoury-chapter .equipment-grid h3{font-size:29px;margin:17px 0 12px}.armoury-chapter .equipment-grid p{font-size:11px;line-height:1.8}.armoury-chapter table{width:100%;border-collapse:collapse;font-size:11px;line-height:1.8;margin:20px 0}.armoury-chapter th,.armoury-chapter td{padding:12px;border:1px solid #ac9663;text-align:left}.armoury-chapter code{background:#d3c497;padding:2px 5px;overflow-wrap:anywhere}.diplomacy-toolbar{display:flex;justify-content:space-between;gap:25px;align-items:center;flex-wrap:wrap}.diplomacy-toolbar h2{font-size:65px}.imperial-offices,.diplomacy-leaders{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:22px;margin:28px 0 45px}.office-card{border:3px solid #b4995c;background:linear-gradient(#193527e8,#173023f3),url('assets/guild.webp') center/cover;padding:25px;box-shadow:4px 5px #08180e}.office-card img{width:54px;height:54px;float:right;margin:0 0 15px 15px}.office-card h3{font-size:32px;color:#e5c679}.office-holder{font:36px VT323,monospace;color:#e6ead6;overflow-wrap:anywhere;margin:20px 0 15px}.office-card>p:last-child{font-size:11px;color:#bfc9af;line-height:1.8}.diplomacy-guide{background:#ecdfbf;border:4px solid #b38e48;padding:30px;color:#283d2a}.diplomacy-guide h2{font-size:55px}.diplomacy-guide article{margin:30px 0;padding-top:25px;border-top:1px solid #ad955a}.diplomacy-guide p,.diplomacy-guide li,.diplomacy-guide table{font-size:12px;line-height:1.9}.diplomacy-guide table{width:100%;border-collapse:collapse}.diplomacy-guide th,.diplomacy-guide td{border:1px solid #ac9663;padding:10px;text-align:left}.diplomacy-guide code{overflow-wrap:anywhere}.banner-menu a[href='armoury.html']{--realm-art:url('assets/faction-kit-mannequins.webp')}.banner-menu a[href='diplomacy.html']{--realm-art:url('assets/kaitain.webp')}.banner-menu a:last-child{grid-column:1/-1}@media(max-width:900px){.imperial-offices,.diplomacy-leaders{grid-template-columns:repeat(2,minmax(0,1fr))}}@media(max-width:600px){.armoury-catalogue,.diplomacy-section{padding:35px 6%}.armoury-chapter,.diplomacy-guide{padding:22px 16px}.armoury-chapter h2{font-size:42px}.armoury-chapter .equipment-grid{grid-template-columns:1fr}.armoury-chapter table,.diplomacy-guide table{display:block;overflow-x:auto}.imperial-offices,.diplomacy-leaders{grid-template-columns:1fr}.diplomacy-toolbar h2{font-size:53px}.armoury-jumps a{font-size:19px}}
|
||||
|
||||
.page-intro.intro-community h1{font-size:clamp(56px,7vw,100px);overflow-wrap:anywhere}
|
||||
1
website/web/armoury.html
Normal file
1
website/web/armoury.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
website/web/diplomacy.html
Normal file
1
website/web/diplomacy.html
Normal file
File diff suppressed because one or more lines are too long
6
website/web/diplomacy.js
Normal file
6
website/web/diplomacy.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
const diplomacyHouses=['Fremen','Harkonnen','Corrino','Atreides','Ordos'];let diplomacyBusy=false;
|
||||
const dipEl=(tag,text,cls)=>{const e=document.createElement(tag);if(text!==undefined)e.textContent=text;if(cls)e.className=cls;return e};
|
||||
function officeCard(title,holder,description,icon){const a=dipEl('article',undefined,'office-card');const img=dipEl('img');img.src='assets/'+icon;img.alt='';a.append(img,dipEl('h3',title),dipEl('p',holder,'office-holder'),dipEl('p',description));return a}
|
||||
function showOffices(data){const live=data.status==='connected';const absent=live?'Not elected':'Server not connected';document.querySelector('#imperial-offices').replaceChildren(officeCard('Emperor',live?(data.emperor||'Not elected'):absent,'Elected player from the current seven-day election bucket.','faction-corrino.svg'),officeCard('Spice Steward',live?(data.spiceSteward||'Not appointed'):absent,'The Emperor’s current appointed faction for spice rights.','item-11.webp'),officeCard('House of Water',live?(data.houseOfWater||'Not appointed'):absent,'The Emperor’s current appointed faction for water rights.','item-17.webp'));document.querySelector('#faction-leaders').replaceChildren(...diplomacyHouses.map(h=>officeCard('House '+h,live?(data.leaders.find(x=>x.faction===h)?.leader||'Not elected'):absent,'Current elected faction leader. Votes are cast in Minecraft.','faction-'+h.toLowerCase()+'.svg')));document.querySelector('#diplomacy-updated').textContent=live?'Last game snapshot: '+new Date(data.updatedAt).toLocaleString()+' · Election bucket '+data.electionWeek:''}
|
||||
async function refreshDiplomacy(){if(diplomacyBusy)return;diplomacyBusy=true;const b=document.querySelector('#refresh-diplomacy');b.disabled=true;try{const r=await fetch('/api/diplomacy',{cache:'no-store'});if(!r.ok)throw Error();const data=await r.json();showOffices(data);document.querySelector('#diplomacy-status').textContent=data.status==='connected'?'Connected · Current game offices':data.status==='awaiting_snapshot'?'Connected to Discord · awaiting a fresh diplomacy snapshot':data.status==='unavailable'?'Diplomacy feed temporarily unavailable':'Server not connected · No current leaders or appointments can be confirmed'}catch{showOffices({status:'unavailable'});document.querySelector('#diplomacy-status').textContent='Diplomacy feed temporarily unavailable'}finally{diplomacyBusy=false;b.disabled=false}}
|
||||
showOffices({status:'not_connected'});document.querySelector('#refresh-diplomacy').addEventListener('click',refreshDiplomacy);refreshDiplomacy();setInterval(()=>{if(!document.hidden)refreshDiplomacy()},60000);
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue

Staff