Skip to content

Instantly share code, notes, and snippets.

@Bibliofile
Created December 8, 2019 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bibliofile/489812fa80e7095596bfbf9a0503f6df to your computer and use it in GitHub Desktop.
Save Bibliofile/489812fa80e7095596bfbf9a0503f6df to your computer and use it in GitHub Desktop.
Assorted servers 2019
// @ts-check
/**
* @typedef Server
* @property {string} name
* @property {string} link
* @property {string} owner
* @property {boolean?} expert
* @property {'Survival' | 'Custom'} type
* @property {'cloud' | 'mac'} host
* @property {string | string[]} theme
* @property {{[k: string]: string}} rules
*/
const { readFileSync, writeFileSync } = require('fs')
const json = JSON.parse(readFileSync('servers.json', 'utf-8'))
const servers = json.sort((a, b) => a.name.localeCompare(b.name))
/** @param {Server} server
* @param {{ owner: boolean }} opts
*/
function formatServer(server, opts) {
return opts.owner ? `[${server.name}](${server.link}) by ${server.owner}` : `[${server.name}](${server.link})`;
}
/**
* @param {string} theme
* @returns {(server: Server) => boolean}
*/
function byTheme(theme) {
return server => (Array.isArray(server.theme) ? server.theme : [server.theme]).includes(theme)
}
const themes = new Set()
const tpRules = new Set()
const owners = new Set()
for (const s of servers) {
for (const theme of Array.isArray(s.theme) ? s.theme : [s.theme]) {
themes.add(theme)
}
owners.add(s.owner)
tpRules.add(s.rules["trade portals"])
}
/**
* @param {(server: Server) => boolean} filter
* @param {string} title
* @param {{ owner: boolean }} formatOpts
*/
function serversBy(filter, title = 'Servers', formatOpts = { owner: true }) {
return `<details><summary>${title}</summary>
${servers
.filter(filter)
.map(s => formatServer(s, formatOpts))
.join('\n')}
</details>`
}
/** @param {string} text */
function formatTitle(text) {
return text.split(' ').map(word => word[0].toUpperCase() + word.substr(1)).join(' ')
}
const post = `
It can sometimes be difficult to find a server that you like. The "random join" option only works if someone is online when you are looking, and doesn't catch Mac servers. This is an update from [last year's thread](https://forums.theblockheads.net/t/assorted-servers/73996)
This thread organizes active forum servers into categories so that you can easily find ones you are interested in. I've also organized the servers based on Survival / Custom rules and based on a few custom rules. Enjoy! If you think I missed something obvious, or I made a mistake, please let me know!
Note: Servers were chosen by looking at threads in #multiplayer that have been active within since September. If I missed a server that you'd like added, let me know! I've skipped servers which don't have any credit or don't have join info in their OP.
### Servers by theme
${Array.from(themes)
.map(theme => serversBy(byTheme(theme), theme))
.join("\n")}
### Expert servers
${serversBy(s => s.expert)}
### Custom servers
${serversBy(s => s.type === "Custom")}
### Survival servers
${serversBy(s => s.type === "Survival")}
### Cloud servers
${serversBy(s => s.host === "cloud")}
### Mac servers
${serversBy(s => s.host === "mac")}
### Servers with PVP on
${serversBy(s => s.rules.pvp === "on")}
### Servers with PVP off
${serversBy(s => s.rules.pvp === "off")}
### Servers by size
${["1/16x", "1/4x", "1x", "4x", "16x"]
.map(size => serversBy(s => s.rules.size === size, size))
.join("\n")}
### Servers by TP rules
${Array.from(tpRules)
.map(rule =>
serversBy(s => s.rules["trade portals"] === rule, formatTitle(rule || 'normal'))
)
.join("\n")}
### Servers By Owner
${Array.from(owners)
.sort((a, b) => a.localeCompare(b, { ignoreCase: true }))
.map(owner => serversBy(s => s.owner === owner, formatTitle(owner), { owner: false }))
.join("\n")}
### All servers
${serversBy(() => true)}
---
Generated with [this script](https://gist.github.com/Bibliofile/...) and hand built JSON.
---
Part of the [2019 Advent Calendar](https://forums.theblockheads.net/t/the-2018-blockheads-advent-calendar/73937)
`;
writeFileSync('./post.md', post, 'utf-8');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment