-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,441 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,85 @@ | ||
# discordtrivia | ||
Trivia bot for Discord chat, v0.17 | ||
Trivia bot for Discord chat | ||
|
||
Prerequisites: | ||
-------------- | ||
- node.js (tested with v14) | ||
- npm modules **discord.js** (v12), **path**, **readline**, and **request** | ||
|
||
Settings: | ||
-------------- | ||
The settings.txt file contains the current settings for the bot. All channel IDs should be enclosed in quotes. | ||
|
||
- filepath: (*string*) filepath to the file containing the trivia questions | ||
- lang: (*string*) localization file to use (setting this to "en" will use "local_en.txt") | ||
- anyoneStart: (*boolean*) whether non-privileged users can start the trivia | ||
- anyoneStop: (*boolean*) whether non-privileged users can stop the trivia | ||
- anyoneAnswer: (*boolean*) whether privileged users can answer the trivia | ||
- autoDownload: (*boolean*) whether the trivia file should be downloaded from the URL specified in "downloadUrl" | ||
- tiebreaker: (*boolean*) whether the trivia should continue past "maxQuestionNum" if there is a tie for first place | ||
- tts: (*boolean*) whether the bot should have TTS enabled on announcements | ||
- startTime: (*number*) time until the first question is asked after the trivia begins in milliseconds | ||
- hintTime: (*number*) time until the hint is given after a question is asked in milliseconds | ||
- skipTime: (*number*) time until the answer is given after a question is asked in milliseconds | ||
- betweenTime: (*number*) time until the next question is asked after an answer is given in milliseconds | ||
- downloadUrl: (*string*) *optional* URL of trivia questions to download (set to "" if not being used) | ||
- maxQuestionNum: (*number*) number of questions to ask before stopping the trivia (no greater than the number of questions in the trivia file) | ||
- allowedChannels: (*Array<string>*) array of channel names the bot can run in | ||
- triviaChannel: (*string*) *optional* ID of the text channel in which the trivia is to be held (set to "" if not being used, the bot will start in any channel whose name matches allowedChannels in which !start is typed) | ||
- musicChannel: (*string*) *optional* ID of the text channel in which music commands can be sent (integrates with SexualRhinoceros's MusicBot, set to "" if not being used) | ||
- schedule: (*Array<number>*) *optional* array of Unix timestamps (in ms) when the trivia should be started if not occuring at that time (set to [] if not being used) | ||
- token: (*string*) Discord auth token | ||
- debug: (*boolean*) enable debug logging | ||
|
||
Instructions: | ||
-------------- | ||
- Create file trivia.txt with your questions in the same directory as trivia.js. The questions should be in the following format, with one question per line: | ||
- What is the fifth word in this question?*word | ||
- Enter the Discord username and password to be used on lines 4 and 5 of trivia.js. | ||
- Create a txt file with your questions in the same directory as trivia.js. The questions should be in the following format, with one question per line: | ||
- What is the fifth word in this question?\*word | ||
- The first line of the file should be "<!-- DISCORD TRIVIA FILE -->" | ||
- Create a Discord bot user and copy the token to settings.txt | ||
- On Windows: Drag trivia.js to the node.exe file to run it. On other platforms, go to https://nodejs.org/en/download/ and download the proper binary for your system. | ||
- Using Discord, type !start into the channel. | ||
- Type !start into the command line or into the Discord trivia channel. | ||
- When the round is complete or !stop is sent, the results for the round will be sent to a file named results<timestamp>.html. | ||
|
||
By default, the trivia bot will ask 150 questions. Change the value of maxQuestionNum (line 16) to the number of questions you would like to ask. If there are fewer questions in the file than maxQuestionNum, the trivia bot will only ask the number of questions in the file. | ||
If the bot loses connection, it will dump the score table so far to results<timestamp>.html. As soon as it detects that it is able to connect, it will continue asking questions. If the bot is terminated during a loss of connection, paste the error info over lines 55 to 64 of trivia.js and start the bot. Afterwards, make sure to replace those values with the previous values. | ||
|
||
If !start is sent again after the trivia has been stopped, it will scramble the questions again, start a new trivia round, and scores/players/etc. will be reset. | ||
Localization: | ||
-------------- | ||
local_en.txt comes with default messages in English and can be customized to suit your needs. | ||
|
||
If the bot loses connection, it will dump the score table so far to results<timestamp>.html. As soon as it detects that it is able to connect, it will continue asking questions. If the bot is terminated during a loss of connection, paste the error info over lines 15 to 29 and start the bot. Afterwards, make sure to replace those values with the previous values. | ||
The "ordinals" value allows an array to define how rankings are displayed, starting with "0th", "1st", "2nd", and "3rd". Ordinal values beyond the end of the array will loop around. The "clean" and "typos" values use regex to clean answer input to compare to answers in the trivia file. The "special" value lists characters besides alphanumeric characters that should treated as letters for the hint with blanks. The "streakMsg" and "scoreMsg" values allow certain messages to be sent when a player reaches a certain score or streak. | ||
|
||
"c"-group messages are displayed in the console. "d"-group messages are displayed in Discord, and may be displayed in the console. "t"-group messages are used in the construction of longer, complex messages. | ||
|
||
Valid commands: | ||
-------------- | ||
Use in the chat as the credentials provided or a user who can manage server | ||
- !start: starts a new round of trivia in the channel (only works in #trivia or #test channels) | ||
- !stop: ends the round of trivia | ||
- !hint: sends the question's hint now | ||
- !skip: skips the current question | ||
- !list: changes trivia list to the specified list | ||
- !pause: pauses the round of trivia | ||
- !continue: continues the round of trivia, if paused | ||
- !questions: changes number of questions to the specified number | ||
- !anyone start: toggles ability of general users to use !start and !list | ||
- !anyone stop: toggles ability of general users to use !start, !stop, !hint, !skip, !list, !pause, !continue, and !questions | ||
- !anyone answer: toggles ability of privileged users to answer questions | ||
- !start: starts a new round of trivia | ||
- !stop: ends the round of trivia | ||
- !hint: sends a hint for this question now | ||
- !skip: skips the current question | ||
- !list *list*: changes trivia list to the specified list | ||
- !pause: pauses the round of trivia | ||
- !continue: continues the round of trivia, if paused | ||
- !exit: terminates the bot | ||
- !questions *number*: changes number of questions to the specified number | ||
- !echo: repeats the message afterwards in the trivia channel | ||
- !results: sends a DM to you with the most recent results | ||
- !download: downloads the questions from the URL specified in settings.txt to the trivia | ||
- !settings: reloads settings from settings.txt | ||
- !settings *filename*: loads settings from the filename specified and saves the settings to settings.txt | ||
- !disallow: prevents a user from answering the trivia | ||
- !allow: allows a user to answer the trivia | ||
- !anyone start: toggles ability of general users to use !start and !list | ||
- !anyone stop: toggles ability of general users to use !stop, !hint, !skip, !pause, !continue, !questions, !download, !settings, !settings, !disallow, !allow, !anyone start, !anyone stop, !anyone answer, !reload, !timer, and !schedule | ||
- !anyone answer: toggles ability of privileged users to answer questions | ||
- !reload: toggles whether or not player data will be kept between rounds | ||
- !timer: sets a timer to start the trivia in the specified number of seconds | ||
- !schedule: sets a timer to start the trivia at the specifed Unix timestamp (in seconds) | ||
- !emoji: tests emoji in the trivia channel | ||
|
||
Anyone can use these in the chat | ||
- !info: sends a DM to the user who typed !info with their score and place | ||
- !top: sends a DM to the user who typed !top with the top ten and their scores | ||
- !help: sends a DM to the user who typed !help with information on commands they can use | ||
- !info: sends a DM to the user who typed !info with their score and place | ||
- !top: sends a DM to the user who typed !top with the top ten and their scores | ||
- !help: sends a DM to the user who typed !help with information on commands they can use | ||
- !when: sends a DM to the user who typed !when with the time of the next scheduled trivia round |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
"ordinals": ["$th", "$st", "$nd", "$rd", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$st", "$nd", "$rd", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$st", "$nd", "$rd", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$st", "$nd", "$rd", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$st", "$nd", "$rd", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$st", "$nd", "$rd", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$st", "$nd", "$rd", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$st", "$nd", "$rd", "$th", "$th", "$th", "$th", "$th", "$th", "$th", "$st", "$nd", "$rd", "$th", "$th", "$th", "$th", "$th", "$th"], | ||
"clean": [["ß","ss"],["à|á|â|ã|ä|å","a"],["æ","ae"],["ç","c"],["ð","d"],["è|é|ê|ë","e"],["ì|í|î|ï","i"],["ñ","n"],["ò|ó|ô|õ|ö","o"],["ù|ú|û|ü","u"],["ý|ÿ","y"],["&","and"],["[-—:_.+!?;,(\\[\\]\\<\\>\\{\\}\\|\\\\\\/\r\n]"," "],[" +(?= )",""],["[^a-zA-Z0-9 ]",""]], | ||
"typos": [["kn|m","n"],["y","i"],["k|x|q|cc","c"],["e|ah|aa","a"],["u|oo","o"],["ph","f"],["ll","l"],["z","s"]], | ||
"special": ["ß", "ç", "ð", "ñ", "ý", "ÿ", "à", "á", "â", "ã", "ä", "å", "æ", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ò", "ó", "ô", "õ", "ö", "ù", "ú", "û", "ü", "ẞ", "Ç", "Ð", "Ñ", "Ý", "Ÿ", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ò", "Ó", "Ô", "Õ", "Ö", "Ù", "Ú", "Û", "Ü"], | ||
"streakMsg": [[5,"*Awesome! ${message.author.toString()} got 5 questions in a row!*"],[10,"*Amazing! ${message.author.toString()} got 10 questions in a row!*"]], | ||
"scoreMsg": [[25,"*Astounding! ${bot.user.toString()} reached 25 points!*"],[50,"*Astonishing! ${bot.user.toString()} reached 50 points!*"]], | ||
"c_settingsLoaded": "settings.txt loaded", | ||
"c_settingsFailed": "settings.txt error! Loading previous settings...", | ||
"c_langLoaded": "local_${settings.lang}.txt loaded", | ||
"c_langFailed": "local_${settings.lang}.txt error! Loading previous settings...", | ||
"c_start": "Started the trivia", | ||
"c_stop": "Stopped the trivia", | ||
"c_downloadSuccess": "New questions downloaded to ${settings.filepath}", | ||
"c_downloadFailure": "Download failed", | ||
"c_fileReadError": "File read error.", | ||
"c_scrambled": "Questions scrambled to shuffled.txt", | ||
"c_reconnect": "Connection lost. Existing score data has been dumped.", | ||
"c_reconnectAttempt": "Attempting to reconnect in 10 seconds...", | ||
"c_reconnectReattempt": "Attempt failed. Attempting to reconnect in 10 seconds...", | ||
"c_list": "Trivia list changed to ${settings.filepath}", | ||
"c_questions": "Trivia set to ask ${settings.maxQuestionNum} questions", | ||
"c_reloadOff": "Data will be kept when a new round begins", | ||
"c_reloadOn": "Data will be cleared when a new round begins", | ||
"c_ban": "*@${message.author.username} ${message.author.toString()} has been banned for suspicious activity* (answered in ${timeTaken} ms, WPM was ${(12000 * message.content.length / timeTaken).toFixed()})", | ||
"c_strike": "*@${message.author.username} ${message.author.toString()} has received a strike for suspicious activity* (answered in ${timeTaken} ms, WPM was ${(12000 * message.content.length / timeTaken).toFixed()})", | ||
"c_commandInvalid": "This command cannot be used in the console.", | ||
"c_channelNotFound": "triviaChannel not found! Check that the channel name is correctly specified in settings.txt", | ||
"c_invalid": "Invalid command.", | ||
"c_loginError": "Login error! Check that the token is correctly specified in settings.txt", | ||
"c_startBot": "The trivia bot has been started.", | ||
"c_terminate": "The trivia bot has been terminated.", | ||
"c_attachmentFailure": "Attachment file ${filename} not found!", | ||
"c_musicFailure": "Music channel ${answerMusic} not found!", | ||
"c_incomingDM": "DM from ${message.author.username}: ${message.cleanContent}", | ||
"d_pause": "Paused the trivia", | ||
"d_continue": "Continuing the trivia", | ||
"d_anyoneStartOn": "Anyone can start the trivia", | ||
"d_anyoneStartOff": "Only server staff can start or stop the trivia", | ||
"d_anyoneStopOn": "Anyone can start or stop the trivia", | ||
"d_anyoneStopOff": "Only server staff can start or stop the trivia", | ||
"d_anyoneAnswerOn": "Anyone can answer the trivia", | ||
"d_anyoneAnswerOff": "Server staff cannot answer the trivia", | ||
"d_timer": "Trivia set to start in ${time} sec", | ||
"d_schedule": "Trivia set to start at ${time}", | ||
"d_noSchedule": "Trivia is not scheduled", | ||
"d_topTenDefault": "Top ten:\nNo one yet.", | ||
"d_game": "Discord Trivia", | ||
"d_start": "Attention. The trivia round is starting. (${settings.maxQuestionNum} questions out of ${allQuestionNum})", | ||
"d_end": "Attention. ${settings.maxQuestionNum + tieQuestionNum} questions have been reached. The trivia round is ending.", | ||
"d_stop": "Attention. The trivia round is ending.", | ||
"d_tiebreaker": "Attention. There's a tie for first place! The trivia will continue until there's a clear winner...", | ||
"d_skipConnect": "The last question has been skipped due to connectivity issues. No points will be awarded for it.", | ||
"d_hintNotice": "Here's a hint", | ||
"d_hintTypeLen": "no. of characters", | ||
"d_hintTypeLst": "last character", | ||
"d_hintTypeScr": "scrambled", | ||
"d_hintTypeBln": "fill in the blanks", | ||
"d_hintTypeVow": "vowels", | ||
"d_skip": "*Time's up!* **Answer**: ${answerText}", | ||
"d_skipEndStreak": "*<@${lastRoundWinner}>'s streak ended at ${roundWinnerStreak}!*", | ||
"d_info": "Your info", | ||
"d_helpA": "Commands:\n- **!start**: starts the round of trivia\n- **!stop**: ends the round of trivia\n- **!hint**: sends a hint for this question now\n- **!skip**: skips the current question\n- **!list** *list*: changes trivia list to the specified list\n- **!pause**: pauses the round of trivia\n- **!continue**: continues the round of trivia\n- **!exit**: terminates the bot\n- **!questions** *number*: changes number of questions to the specified number\n- **!echo**: repeats the message afterwards in the trivia channel\n- **!results**: sends a DM to you with the most recent results\n- **!download**: downloads the questions from the URL specified in settings.txt to the trivia\n- **!settings**: reloads settings from settings.txt\n- **!settings** *filename*: loads settings from the filename specified and saves the settings to settings.txt\n- **!disallow**: prevents a user from answering the trivia\n- **!allow**: allows a user to answer the trivia\n- **!anyone start**: toggles ability to use !start and !list\n- **!anyone stop**: toggles ability to use !stop, !hint, !skip, !pause, !continue, !questions, !download, !settings, !settings, !disallow, !allow, !anyone start, !anyone stop, !anyone answer, !reload, !timer, and !schedule\n- **!anyone answer**: toggles ability for server staff to answer\n- **!reload**: toggles whether or not player data will be kept between rounds\n- **!timer**: sets a timer to start the trivia in the specified number of seconds\n- **!schedule**: sets a timer to start the trivia at the specifed Unix timestamp\n- **!emoji**: tests emoji in the trivia channel\n- **!info**: sends a DM to you with your score and place\n- **!top**: sends a DM to you with the top ten and their scores\n- **!help**: sends a DM to you with information on commands you can use\n- **!when**: sends a DM to you with the time of the next scheduled trivia round", | ||
"d_helpB": "Commands:\n- **!start**: starts the round of trivia\n- **!stop**: ends the round of trivia\n- **!hint**: sends a hint for this question now\n- **!skip**: skips the current question\n- **!list** *list*: changes trivia list to the specified list\n- **!pause**: pauses the round of trivia\n- **!continue**: continues the round of trivia\n- **!questions** *number*: changes number of questions to the specified number\n- **!download**: downloads the questions from the URL specified in settings.txt to the trivia\n- **!settings**: reloads settings from settings.txt\n- **!settings** *filename*: loads settings from the filename specified and saves the settings to settings.txt\n- **!disallow**: prevents a user from answering the trivia\n- **!allow**: allows a user to answer the trivia\n- **!anyone start**: toggles ability to use !start and !list\n- **!anyone stop**: toggles ability to use !stop, !hint, !skip, !pause, !continue, !questions, !download, !settings, !settings, !disallow, !allow, !anyone start, !anyone stop, !anyone answer, !reload, !timer, and !schedule\n- **!anyone answer**: toggles ability for server staff to answer\n- **!reload**: toggles whether or not player data will be kept between rounds\n- **!timer**: sets a timer to start the trivia in the specified number of seconds\n- **!schedule**: sets a timer to start the trivia at the specifed Unix timestamp\n- **!emoji**: tests emoji in the trivia channel\n- **!info**: sends a DM to you with your score and place\n- **!top**: sends a DM to you with the top ten and their scores\n- **!help**: sends a DM to you with information on commands you can use\n- **!when**: sends a DM to you with the time of the next scheduled trivia round", | ||
"d_helpC": "Commands:\n- **!start**: starts the round of trivia\n- **!list** *list*: changes trivia list to the specified list\n- **!info**: sends a DM to you with your score and place\n- **!top**: sends a DM to you with the top ten and their scores\n- **!help**: sends a DM to you with information on commands you can use\n- **!when**: sends a DM to you with the time of the next scheduled trivia round", | ||
"d_helpD": "Commands:\n- **!info**: sends a DM to you with your score and place\n- **!top**: sends a DM to you with the top ten and their scores\n- **!help**: sends a DM to you with information on commands you can use\n- **!when**: sends a DM to you with the time of the next scheduled trivia round", | ||
"d_invalidDM": "This command cannot be used in a Direct Message.", | ||
"d_ban": "*${message.author.toString()} has been banned for suspicious activity*", | ||
"d_banDm": "*You have been banned for suspicious activity*", | ||
"d_streakContinue": "*${message.author.toString()} stretches their streak to ${roundWinnerStreak}!*", | ||
"d_streakBroken": "*<@${lastRoundWinner}>'s streak ended at ${roundWinnerStreak} by ${message.author.toString()}!*", | ||
"d_rankUp": "*${message.author.toString()} has moved up in rank* (${getOrdinal(oldRank)} to ${getOrdinal(rank)})", | ||
"d_timeNewRecord": "*${message.author.toString()} broke the current round time record with ${(timeTaken / 1000).toFixed(3)} sec! Previous record holder was <@${lastBestTimePlayer}> with ${(lastBestTime / 1000).toFixed(3)} sec!*", | ||
"d_streakNewRecord": "*${message.author.toString()} broke the current round streak record with ${roundWinnerStreak}! Previous record holder was <@${lastBestStreakPlayer}> with ${lastBestStreak}!*", | ||
"d_terminate": "Attention. The trivia bot has been terminated.", | ||
"d_winner": "Congratulations on winning this round of trivia!", | ||
"d_noResults": "No results yet.", | ||
"t_first": "1st Place", | ||
"t_second": "2nd Place", | ||
"t_third": "3rd Place", | ||
"t_noOne": "None", | ||
"t_points": "Points", | ||
"t_bestStreak": "Best streak", | ||
"t_avgTime": "Avg. time", | ||
"t_bestTime": "Best time", | ||
"t_bestBestStreak": "Best streak", | ||
"t_bestAvgTime": "Best avg. time", | ||
"t_bestBestTime": "Best time", | ||
"t_with": "with", | ||
"t_place": "Place", | ||
"t_sec": "sec", | ||
"t_roundWinner": "Winner", | ||
"t_answer": "Answer", | ||
"t_streak": "Streak", | ||
"t_time": "Time", | ||
"t_topTen": "Top ten" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"dependencies": { | ||
"discord.js": "^12.4.1", | ||
"path": "^0.12.7", | ||
"readline": "^1.3.0", | ||
"request": "^2.88.2" | ||
} | ||
} |
Oops, something went wrong.