Discord bot for a community-generated Choose-Your-Own-Adventure story where whenever a reader gets to a dead-end node, it's their turn to write the next section of the story and the choices branching out from it.
by August Luhrs, Oct. 2020
Based on an idea from Marie Claire LeBlanc Flanagan @omarieclaire
Made with help from Dan Shiffman's Discord Bot tutorials (this one in particular)
and Shawn Van Every's recommendation to use nedb for the database stuff!
Discord App Icon the album art for The Fountain LP by Nicole Gustafsson
Everything takes place within the message event.
If the channel is initialized, the player can type messages in that channel to make new stories, select which story to play, and call any other commands (i.e !help).
Any messages sent from the player's private message with the bot are read, but the bot only responds if that player has !start
-ed the story from the server. When the player starts the story, a new playthrough is pushed to the currentStories array. That array is where all the magic happens -- it's what's referenced and adjusted as the player goes through the story and how the bot knows which passage to find in the database.
The story is represented most in the currentStories array by the "path" variable. You can imagine the path as the player's choices at each passage's branches laid flat. For example:
Passage 0
Branch 0, [Branch 1], Branch 2
|
|
Passage 01
[Branch 0], Branch 1
|
|
Passage 010
would be path: 010
-
Make sure you have MANAGE_SERVER permission for the server you want to add this to.
-
Once the bot has been added, any user with ADMINISTRATION or MANAGE_CHANNELS permissions can type
!init channel
in a channel they want the bot to listen to. (Note: it's literally the word "channel", not the specific name of the channel) -
HOW TO USE:
- To start a new story, type
!new
followed by the story title. i.e.!new Our Story
- To play, type
!start
followed by the story title, i.e.!start Our Story
- For help and a list of commands, type
!help
Still figuring this out. Feel free to use this wherever or copy it to make your own. Actually, use this wherever as long as it's not some fucking alt-right cesspool server. Attribution is appreciated!
First Steps
hello worldbasic story response structureprivate messagesave story to file and read from filetutorial on !help
Second Steps
redo instructions for clarityfix weird indentations on !helpuse currentStories to prevent duplicate nodes if concurrent players land on same spotoh wait, need to update myStory incase people are splicing the array mid-story, or prevent somehow -- using timer to clear arraysetting up channel specific stories, scalablegiving admins edit accessedit processnew story abilityhow to guide for adding to channelstest branch instead of commiting to mainperma-run on glitchfeedback commandshow which paths have been answered already! go back and make options boldprevent duplicate story namestest exporting the storiesfigure out how to import to glitch without erasing files -- guess i could just export before importinginit on specific channel so no server bleedremove channelwhat's up with having two projects running at same time? issue with not turning off bot before reuploading new code? regen token for now...add stop function to shutdown bot? SIGTERM && I'm the only one who canadd code comments for others understanding + overview in commentsadd backticks for commands in strings- prevent glitch db from getting overwritten
add finished tag to passage to fix if someone doesn't finish halfway throughadd bot photo (tree?)update err logs to if(err) and add db log with timestamp- have sample.db and local development guide for forking
- replace the if-hydra with a "command handler" and module.exports ala Coding Garden Discord Bot
- figure out the indentation issue in !help
error log retrieval commandfix the overlap bug- remove specific story without messing up path of the future stories
- bold paths of edited branches with pre-existing linked stories
Privacy Considerations
- get rid of usernames in db
- hide db
- private glitch project if hiding db
Stretch
- better name?
- save that story to file or email it or something
- story visualization tree map
- real time multiplayer with voting on next node and collab story at end
- nodes that can link to existing nodes/return to checkpoints
- personal stats
- upgrade to actual database server
- use indexing if db gets slow
- could create db from json file instead of db