A mastodon bot for posting random flags. All flags are obtained from various
Wikipedia pages, using scripts stored in the scripts dir. To run
all scripts, run ./pull_flags.sh. To run the actual bot, run
./bot.js, but first you'll need to configure some things using a
.env file. Here's an example with all options.
# URL of your mastodon server
FLAGBOT_MASTODON_URL=https://mastodon.social/
# To obtain one, log into your server, then go to Settings > Development
FLAGBOT_MASTODON_TOKEN=<your access token>
# All 4 of these are optional
FLAGBOT_ACCOUNT_URL=https://mastodon.social/@flagbot
FLAGBOT_WEBSITE_URL=https://flagbot.onrender.com/
FLAGBOT_OWNER_ACCOUNT=@TxzK@mastodon.social
FLAGBOT_SOURCE_CODE=https://github.com/TxzK/FlagBot
# Wether to run the server or not
FLAGBOT_SERVER=1
# Wether to post anything or not
FLAGBOT_POST=1
# Can be either public, unlisted, private, or direct. Default private
FLAGBOT_POST_VISIBILITY=public
# Intervals for posting and changing the display name
# Cron expressions, showing default values
FLAGBOT_STATUS_INTERVAL=0 */15 * * * *
FLAGBOT_DISPLAY_NAME_INTERVAL=0 */5 * * * *
# Port for the server. Default 3000
PORT=3000And before you can do any of this, you'll of course need to install the dependencies
using pnpm i. Also if you have viu installed,
you'll be able to see a preview of the flag being posted right in the console.
And also, the code is really messy. It lacks some error handling, often takes bad shortcuts and barely has any comments. Sorry.
If you are using a free hosting service to run the bot, (I am using render.com) you may need to expose a server. You may also need to use a pinging service (I recommend cron-job.org) to keep the service running. But the default page with the list of all flags is too large for it to handle. So there's a '/ping' page just for pinging.
All flags are saved inside flags dir. Flags are saved inside
following subdirs:
nationalFor national flagsdependencyFor the flags of dependent territories.subdivisionFor the flags of country subdivisions.micronationFor the flags of micronations.unofficialFor various unofficial, but widely used flags.proposedProposed flags.formerFormer flag of entities that still exists.historicalFlag of entities that no longer exists.
With each image file, a JSON file with the same name is also generated. It contains following fields.
nameName of the entity the flag belongs to.variantIt's also used for former flags to denote the timeline of use or for proposed flags to include more information.wikiWikipedia page for that entity. Optional.flagWikiWikipedia page for the flag itself. Optional.flagSrcSource for the flag, most likely a Wikipedia page. Only used in the webpage.imgSrcLink for where the image is from. Most often a Wikimedia Commons page.imgLinkLink to the actual image file. Only used in the webpage.dependencyOfFor if the flag belongs to a dependent territory of some country.subdivisionOfFor if the flag belongs to a subdivision of some country.micronationSet totruefor the micronations.
All code is licensed under CC0, meaning they're essentially under the public domain. Generated JSON files are also under the same license. The flags are from Wikipedia or Wikimedia Commons and are published under various different licenses. Visit the links for each individual flag to learn more.