├── .gitignore
├── LICENSE
├── README.md
├── data
├── general_knowledge.json
├── random_1.json
├── tech_1.json
└── us_states.json
├── example.js
├── index.js
├── locale
└── en.json
├── package.json
└── quiz.js
/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################
2 | ############### .gitignore ##################
3 | ################################################
4 | #
5 | # This file is only relevant if you are using git.
6 | #
7 | # Files which match the splat patterns below will
8 | # be ignored by git. This keeps random crap and
9 | # and sensitive credentials from being uploaded to
10 | # your repository. It allows you to configure your
11 | # app for your machine without accidentally
12 | # committing settings which will smash the local
13 | # settings of other developers on your team.
14 | #
15 | # Some reasonable defaults are included below,
16 | # but, of course, you should modify/extend/prune
17 | # to fit your needs!
18 | ################################################
19 |
20 |
21 |
22 |
23 | ################################################
24 | # Local Configuration
25 | #
26 | # Explicitly ignore files which contain:
27 | #
28 | # 1. Sensitive information you'd rather not push to
29 | # your git repository.
30 | # e.g., your personal API keys or passwords.
31 | #
32 | # 2. Environment-specific configuration
33 | # Basically, anything that would be annoying
34 | # to have to change every time you do a
35 | # `git pull`
36 | # e.g., your local development database, or
37 | # the S3 bucket you're using for file uploads
38 | # development.
39 | #
40 | ################################################
41 |
42 | config/local.js
43 |
44 |
45 |
46 |
47 |
48 | ################################################
49 | # Dependencies
50 | #
51 | # When releasing a production app, you may
52 | # consider including your node_modules and
53 | # bower_components directory in your git repo,
54 | # but during development, its best to exclude it,
55 | # since different developers may be working on
56 | # different kernels, where dependencies would
57 | # need to be recompiled anyway.
58 | #
59 | # More on that here about node_modules dir:
60 | # http://www.futurealoof.com/posts/nodemodules-in-git.html
61 | # (credit Mikeal Rogers, @mikeal)
62 | #
63 | # About bower_components dir, you can see this:
64 | # http://addyosmani.com/blog/checking-in-front-end-dependencies/
65 | # (credit Addy Osmani, @addyosmani)
66 | #
67 | ################################################
68 |
69 | node_modules
70 | bower_components
71 |
72 |
73 | ################################################
74 | # Node.js / NPM
75 | #
76 | # Common files generated by Node, NPM, and the
77 | # related ecosystem.
78 | ################################################
79 | lib-cov
80 | *.seed
81 | *.log
82 | *.out
83 | *.pid
84 | npm-debug.log
85 |
86 |
87 |
88 |
89 |
90 | ################################################
91 | # Miscellaneous
92 | #
93 | # Common files generated by text editors,
94 | # operating systems, file systems, etc.
95 | ################################################
96 |
97 | *~
98 | *#
99 | .DS_STORE
100 | .netbeans
101 | nbproject
102 | .idea
103 | .node_history
104 | local_example.js
105 | *.tgz
106 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Slack Quizbot
2 |
3 | A NodeJS module using Slack's RTM to create a Slack Quizbot to run quizzes in your Slack channel. There are some quizzes included but you can create your own quiz with the [Slack Quizbot Quiz Builder](http://codebyfire.github.io/slackquizbotbuilder).
4 |
5 | ## Requirements
6 | * Slack bot - instructions on how to create a bot for your team at https://api.slack.com/bot-users
7 | * NodeJS - Download NodeJS from https://nodejs.org/download/
8 |
9 | ## Installation
10 |
11 | Create a folder and install the slackquizbot module at that location:
12 |
13 | ```nodejs
14 | npm install slackquizbot
15 | ```
16 |
17 | Create a myquizbot.js file containing the following, adding in your unique bot token:
18 |
19 | ```js
20 | var QuizBot = require('slackquizbot');
21 | var myQuizBot = new QuizBot("_YOUR_SLACK_BOT_TOKEN_");
22 | ```
23 |
24 | Start your Quizbot:
25 |
26 | ```nodejs
27 | node myquizbot.js
28 | ```
29 |
30 | ## Bot Commands
31 |
32 | Make sure your bot is present in the channel you want to run the quiz in. All commands will also work in DMs with your bot so you can test these commands privately.
33 |
34 | #### List quizzes
35 | Ask Quizbot to tell you all the available quizzes
36 | > @quizbot list quizzes
37 |
38 | #### Start quiz
39 | Start the general knowledge quiz
40 | > @quizbot start quiz general_knowledge
41 |
42 | #### Answering questions
43 | Whenever a question is active Quizbot will search for any matching answers automatically
44 |
45 | #### Pause quiz
46 | To pause a quiz for any reason
47 | > @quizbot pause quiz
48 |
49 | #### Resume quiz
50 | Resume a paused quiz
51 | > @quizbot resume quiz
52 |
53 | #### Stop quiz
54 | To prematurely stop a quiz
55 | > @quizbot stop quiz
56 |
57 | #### Show scores
58 | To list everyone's current score
59 | > @quizbot show scores
60 |
61 | ## Create your own quizzes
62 | You can create your own quizzes using the [Slack Quizbot Quiz Builder](http://codebyfire.github.io/slackquizbotbuilder). Once you've downloaded your JSON file, you can use it by either directly placing the file in a local folder called 'data' or in Slack you can DM the file to your Quizbot.
63 |
--------------------------------------------------------------------------------
/data/general_knowledge.json:
--------------------------------------------------------------------------------
1 | {
2 | "questions": [
3 | {
4 | "text": "_____ is by far the healthiest snack. It builds bone, muscle, tissue, aids digestion, and is good for the teeth.",
5 | "answers": [
6 | {
7 | "text": [
8 | "popcorn"
9 | ]
10 | }
11 | ]
12 | },
13 | {
14 | "text": "Hexakosioihexekontahexaphobia is the fear of the number ___ ?",
15 | "answers": [
16 | {
17 | "text": [
18 | "666"
19 | ]
20 | }
21 | ]
22 | },
23 | {
24 | "text": "Cotton Candy was invented by a ____",
25 | "answers": [
26 | {
27 | "text": [
28 | "Dentist"
29 | ]
30 | }
31 | ]
32 | },
33 | {
34 | "text": "The _____ in Mario games are based on a real species called 'Amanita Muscaria' that when eaten, make people feel like they're growing?",
35 | "answers": [
36 | {
37 | "text": [
38 | "mushroom"
39 | ]
40 | }
41 | ]
42 | },
43 | {
44 | "text": "The medical term for _____ headaches is sphenopalatine ganglioneuralgia. Clue: causes brain freeze",
45 | "answers": [
46 | {
47 | "text": [
48 | "ice cream"
49 | ]
50 | }
51 | ]
52 | },
53 | {
54 | "text": "True or False : In the original story of \"The Little Mermaid,\" Ariel doesn't marry the prince. He marries someone else, and she kills herself.",
55 | "answers": [
56 | {
57 | "text": [
58 | "True"
59 | ]
60 | }
61 | ]
62 | },
63 | {
64 | "text": "Penguins have an organ near the ____ that filters salt from the water out of their system",
65 | "answers": [
66 | {
67 | "text": [
68 | "eyes"
69 | ]
70 | }
71 | ]
72 | },
73 | {
74 | "text": "Daniel Radcliffe was in the ____ when he found out he'd been cast as Harry Potter. He cried.",
75 | "answers": [
76 | {
77 | "text": [
78 | "Bath"
79 | ]
80 | }
81 | ]
82 | },
83 | {
84 | "text": "_______ is the fear of being without your mobile phone or losing your signal.",
85 | "answers": [
86 | {
87 | "text": [
88 | "nomophobia"
89 | ]
90 | }
91 | ]
92 | },
93 | {
94 | "text": "Banana ketchup is popular in the _____.",
95 | "answers": [
96 | {
97 | "text": [
98 | "philippines"
99 | ]
100 | }
101 | ]
102 | },
103 | {
104 | "text": "The most shoplifted book of all time is the _____",
105 | "answers": [
106 | {
107 | "text": [
108 | "Bible"
109 | ]
110 | }
111 | ]
112 | },
113 | {
114 | "text": "______ have killed more humans than all the wars in history.",
115 | "answers": [
116 | {
117 | "text": [
118 | "mosquitoes"
119 | ]
120 | }
121 | ]
122 | },
123 | {
124 | "text": "Biting the --- triggers a rush of chemicals to the brain which reduce anxiety, stress and increases mood.",
125 | "answers": [
126 | {
127 | "text": [
128 | "lip"
129 | ]
130 | }
131 | ]
132 | },
133 | {
134 | "text": "A brain gets in good shape by memorizing a _____",
135 | "answers": [
136 | {
137 | "text": [
138 | "song"
139 | ]
140 | }
141 | ]
142 | },
143 | {
144 | "text": "Sleeping without a --- improves quality of sleep by over 95% and is an effective way of treating insomnia. Clue: female underwear.",
145 | "answers": [
146 | {
147 | "text": [
148 | "Bra"
149 | ]
150 | }
151 | ]
152 | },
153 | {
154 | "text": "_______ in the shower helps boost your immunity, lower your blood pressure, reduce stress, and improve your mood",
155 | "answers": [
156 | {
157 | "text": [
158 | "Singing"
159 | ]
160 | }
161 | ]
162 | },
163 | {
164 | "text": "The letter __ was the last letter added to the English alphabet",
165 | "answers": [
166 | {
167 | "text": [
168 | "J"
169 | ]
170 | }
171 | ]
172 | },
173 | {
174 | "text": "Only 2% of the world's population has _____ eyes.",
175 | "answers": [
176 | {
177 | "text": [
178 | "green"
179 | ]
180 | }
181 | ]
182 | },
183 | {
184 | "text": "The male brain is ___ % bigger than the female's but the female brain works more efficiently.",
185 | "answers": [
186 | {
187 | "text": [
188 | "10%"
189 | ]
190 | }
191 | ]
192 | },
193 | {
194 | "text": "Strawberries are a member of the ____ family\nCLUE: flower",
195 | "answers": [
196 | {
197 | "text": [
198 | "Rose"
199 | ]
200 | }
201 | ]
202 | },
203 | {
204 | "text": "",
205 | "answers": [
206 | {
207 | "text": [
208 | ""
209 | ]
210 | }
211 | ]
212 | },
213 | {
214 | "text": "What is the capital of France?",
215 | "answers": [
216 | {
217 | "text": [
218 | "Paris"
219 | ]
220 | }
221 | ],
222 | "answersNeeded": 1
223 | },
224 | {
225 | "text": "What is arachnophobia a fear of?",
226 | "answers": [
227 | {
228 | "text": [
229 | "Spiders",
230 | "spider"
231 | ]
232 | }
233 | ],
234 | "answersNeeded": 1
235 | },
236 | {
237 | "text": "Name these film stars",
238 | "answers": [
239 | {
240 | "text": [
241 | "Harrison Ford"
242 | ]
243 | },
244 | {
245 | "text": [
246 | "Meryl Streep"
247 | ]
248 | },
249 | {
250 | "text": [
251 | "Johnny Depp",
252 | "Jonny Depp"
253 | ]
254 | },
255 | {
256 | "text": [
257 | "Jodie Foster"
258 | ]
259 | }
260 | ],
261 | "image": "http://i61.tinypic.com/2ronzih.png",
262 | "points": 1,
263 | "time": 120
264 | },
265 | {
266 | "text": "The inventor of the mercury thermometer, Gabriel Fahrenheit, was from which country?",
267 | "answers": [
268 | {
269 | "text": [
270 | "Germany"
271 | ]
272 | }
273 | ]
274 | },
275 | {
276 | "text": "What is the chemical symbol for lead?",
277 | "answers": [
278 | {
279 | "text": [
280 | "Pb"
281 | ]
282 | }
283 | ]
284 | },
285 | {
286 | "text": "What would you find in a philatelist's collection?",
287 | "answers": [
288 | {
289 | "text": [
290 | "Stamps",
291 | "Stamp"
292 | ]
293 | }
294 | ]
295 | },
296 | {
297 | "text": "Who is this athlete, the current mens 100 metre world record holder?",
298 | "answers": [
299 | {
300 | "text": [
301 | "Usain Bolt"
302 | ]
303 | }
304 | ],
305 | "image": "http://i58.tinypic.com/a1nu45.jpg"
306 | },
307 | {
308 | "text": "The cob and pen are the male and female names respectively of which bird?",
309 | "answers": [
310 | {
311 | "text": [
312 | "swan"
313 | ]
314 | }
315 | ]
316 | },
317 | {
318 | "text": "What is the name of the scale used for measuring earthquakes?",
319 | "answers": [
320 | {
321 | "text": [
322 | "Richter scale",
323 | "Richter"
324 | ]
325 | }
326 | ]
327 | },
328 | {
329 | "text": "Name the seven dwarfs as appeared in Disney's 1937 film Snow White and the Seven Dwarfs",
330 | "answers": [
331 | {
332 | "text": [
333 | "Happy"
334 | ]
335 | },
336 | {
337 | "text": [
338 | "Sleepy"
339 | ]
340 | },
341 | {
342 | "text": [
343 | "Grumpy"
344 | ]
345 | },
346 | {
347 | "text": [
348 | "Dopey"
349 | ]
350 | },
351 | {
352 | "text": [
353 | "Sneezy"
354 | ]
355 | },
356 | {
357 | "text": [
358 | "Bashful"
359 | ]
360 | },
361 | {
362 | "text": [
363 | "Doc"
364 | ]
365 | }
366 | ],
367 | "points": 1
368 | }
369 | ],
370 | "settings": {
371 | "startQuestionGap": 3,
372 | "questionTime": 60,
373 | "nextQuestionGap": 10,
374 | "pointsPerQuestion": 1,
375 | "randomise": true
376 | }
377 | }
--------------------------------------------------------------------------------
/data/random_1.json:
--------------------------------------------------------------------------------
1 | {
2 | "questions": [
3 | {
4 | "text": "What nation produces two thirds of the world's vanilla? Clue: starts with letter M",
5 | "answers": [
6 | {
7 | "text": [
8 | "Madagascar"
9 | ]
10 | }
11 | ],
12 | "image": ""
13 | },
14 | {
15 | "text": "What is the most widely eaten fish in the world? Clue: starts with H.",
16 | "answers": [
17 | {
18 | "text": [
19 | "Herring"
20 | ]
21 | }
22 | ]
23 | },
24 | {
25 | "text": "What bird was domesticated first? Long neck, wide wings.",
26 | "answers": [
27 | {
28 | "text": [
29 | "Goose"
30 | ]
31 | }
32 | ]
33 | },
34 | {
35 | "text": "What's the common name for a cubic decimeter?",
36 | "answers": [
37 | {
38 | "text": [
39 | "Liter"
40 | ]
41 | }
42 | ]
43 | },
44 | {
45 | "text": "What socialist writer's last words were: \"Last words are for fools who haven't said enough\"?",
46 | "answers": [
47 | {
48 | "text": [
49 | "Karl Marx",
50 | "marx"
51 | ]
52 | }
53 | ]
54 | },
55 | {
56 | "text": "What Italian astronomer invented the thermometer in 1592?",
57 | "answers": [
58 | {
59 | "text": [
60 | "Galileo"
61 | ]
62 | }
63 | ]
64 | },
65 | {
66 | "text": "Which country gave the USA the 'Statute of Liberty?",
67 | "answers": [
68 | {
69 | "text": [
70 | "France"
71 | ]
72 | }
73 | ]
74 | },
75 | {
76 | "text": "What measure of energy comes from the Latin word meaning \"heat\"?",
77 | "answers": [
78 | {
79 | "text": [
80 | "Calorie"
81 | ]
82 | }
83 | ]
84 | },
85 | {
86 | "text": "Who averaged one patent for every three weeks of his life?",
87 | "answers": [
88 | {
89 | "text": [
90 | "Thomas Edison"
91 | ]
92 | }
93 | ]
94 | },
95 | {
96 | "text": "What mathematical symbol did math whiz Ferdinand von Lindemann determine to be a transcendental number in 1882?",
97 | "answers": [
98 | {
99 | "text": [
100 | "Pi"
101 | ]
102 | }
103 | ]
104 | },
105 | {
106 | "text": "----- is the strongest bone in the human body.",
107 | "answers": [
108 | {
109 | "text": [
110 | "Femur"
111 | ]
112 | }
113 | ]
114 | },
115 | {
116 | "text": "Your tongue has how many thousand tastebuds?",
117 | "answers": [
118 | {
119 | "text": [
120 | "3"
121 | ]
122 | }
123 | ]
124 | },
125 | {
126 | "text": "---- can sleep standing up.",
127 | "answers": [
128 | {
129 | "text": [
130 | "Cows"
131 | ]
132 | }
133 | ]
134 | },
135 | {
136 | "text": "These reptiles breath through their skin.",
137 | "answers": [
138 | {
139 | "text": [
140 | "Salamanders"
141 | ]
142 | }
143 | ]
144 | },
145 | {
146 | "text": "____________ is the only continent on earth without an active volcano.",
147 | "answers": [
148 | {
149 | "text": [
150 | "Australia"
151 | ]
152 | }
153 | ]
154 | },
155 | {
156 | "text": "----- is the scientific name for 1/100th of a second.",
157 | "answers": [
158 | {
159 | "text": [
160 | "Jiffy"
161 | ]
162 | }
163 | ]
164 | },
165 | {
166 | "text": "The youngest pope ever was -- years old.",
167 | "answers": [
168 | {
169 | "text": [
170 | "11"
171 | ]
172 | }
173 | ]
174 | },
175 | {
176 | "text": "____________ is the only planet that rotates clockwise.",
177 | "answers": [
178 | {
179 | "text": [
180 | "Venus"
181 | ]
182 | }
183 | ]
184 | },
185 | {
186 | "text": "____________ is the fear of teeth.",
187 | "answers": [
188 | {
189 | "text": [
190 | "Odontophobia"
191 | ]
192 | }
193 | ]
194 | },
195 | {
196 | "text": "The name of the woman on the statue of liberty is Mother of ------.",
197 | "answers": [
198 | {
199 | "text": [
200 | "Exiles"
201 | ]
202 | }
203 | ]
204 | }
205 | ],
206 | "settings": {
207 | "startQuestionGap": 3,
208 | "questionTime": 60,
209 | "nextQuestionGap": 10,
210 | "pointsPerQuestion": 1,
211 | "randomise": false
212 | }
213 | }
--------------------------------------------------------------------------------
/data/tech_1.json:
--------------------------------------------------------------------------------
1 | {
2 | "questions": [
3 | {
4 | "text": "Which operation takes more than O(1) time with the Hash Table data structure?",
5 | "answers": [
6 | {
7 | "text": [
8 | "Sort",
9 | "sort"
10 | ]
11 | }
12 | ]
13 | },
14 | {
15 | "text": "If you need to sort a very large list of integers (billions), what efficient sorting algorithm would be your best bet?",
16 | "answers": [
17 | {
18 | "text": [
19 | "Quicksort",
20 | "quicksort"
21 | ]
22 | }
23 | ]
24 | },
25 | {
26 | "text": "What mega media company merged with AOL at the turn of the century? Clue: initials are TW.",
27 | "answers": [
28 | {
29 | "text": [
30 | "Time Warner",
31 | "TW",
32 | "time warner"
33 | ]
34 | }
35 | ]
36 | },
37 | {
38 | "text": "What do they call people who register domain names with the hope of selling them for a profit",
39 | "answers": [
40 | {
41 | "text": [
42 | "squatters",
43 | "Squatters",
44 | "Cybersquatters",
45 | "cybersquatters"
46 | ]
47 | }
48 | ]
49 | },
50 | {
51 | "text": "Name one of authors of the book The C programming language. The authors are often referred to as K&R.",
52 | "answers": [
53 | {
54 | "text": [
55 | "Brian Kernighan",
56 | "Dennis Ritchie"
57 | ]
58 | }
59 | ]
60 | },
61 | {
62 | "text": "Dennis Richie also developed what computer operating system at Bell labs with Ken Thompson and Douglas Mcllroy?",
63 | "answers": [
64 | {
65 | "text": [
66 | "Unix"
67 | ]
68 | }
69 | ]
70 | },
71 | {
72 | "text": "Name the primary creator of the Java programming language.",
73 | "answers": [
74 | {
75 | "text": [
76 | "James Gosling"
77 | ]
78 | }
79 | ]
80 | },
81 | {
82 | "text": "In 1914, Thomas J Watson renamed the Computing Tabulating Recording Corporation (CTR) to what?",
83 | "answers": [
84 | {
85 | "text": [
86 | "IBM"
87 | ]
88 | }
89 | ]
90 | },
91 | {
92 | "text": "Name the famous computer scientist who worked to break Nazi codes at Bletchley Park during WWII.",
93 | "answers": [
94 | {
95 | "text": [
96 | "Alan Turing"
97 | ]
98 | }
99 | ]
100 | },
101 | {
102 | "text": "Who single handedly built the first Apple computer that launched the personal computing era?",
103 | "answers": [
104 | {
105 | "text": [
106 | "Steve Wozniak",
107 | "Woz"
108 | ]
109 | }
110 | ]
111 | },
112 | {
113 | "text": "What is the year of the Unix epoch?",
114 | "answers": [
115 | {
116 | "text": [
117 | "1970"
118 | ]
119 | }
120 | ]
121 | },
122 | {
123 | "text": "What does the company AMD stand for?",
124 | "answers": [
125 | {
126 | "text": [
127 | "Advanced Micro Devices"
128 | ]
129 | }
130 | ]
131 | },
132 | {
133 | "text": "Who wrote a BASIC version for the 8080 microprocessor, Altair, in 1975?",
134 | "answers": [
135 | {
136 | "text": [
137 | "Bill Gates",
138 | "Paul Allen"
139 | ]
140 | }
141 | ]
142 | },
143 | {
144 | "text": "Who is the Ada programming language named after?",
145 | "answers": [
146 | {
147 | "text": [
148 | "Ada Lovelace"
149 | ]
150 | }
151 | ]
152 | },
153 | {
154 | "text": "Which Google vice president co-designed TCP/IP is regarded by some as the father of the Internet?",
155 | "answers": [
156 | {
157 | "text": [
158 | "Vint Cerf"
159 | ]
160 | }
161 | ]
162 | },
163 | {
164 | "text": "Vint Cerf is regarded as the father of the Internet but who is the person that actually invented the World Wide Web?",
165 | "answers": [
166 | {
167 | "text": [
168 | "Tim Berners-Lee"
169 | ]
170 | }
171 | ]
172 | },
173 | {
174 | "text": "Into how many zones are DVD’s divided worldwide?",
175 | "answers": [
176 | {
177 | "text": [
178 | "Eight",
179 | "8"
180 | ]
181 | }
182 | ]
183 | },
184 | {
185 | "text": "The Apple ---- was the first computer to have a GUI and a mouse.",
186 | "answers": [
187 | {
188 | "text": [
189 | "Lisa"
190 | ]
191 | }
192 | ]
193 | },
194 | {
195 | "text": "Name one the founders of Yahoo.",
196 | "answers": [
197 | {
198 | "text": [
199 | "David Filo",
200 | "Jerry Yang"
201 | ]
202 | }
203 | ]
204 | },
205 | {
206 | "text": "Who founded the Free Software Foundation?",
207 | "answers": [
208 | {
209 | "text": [
210 | "Richard Stallman"
211 | ]
212 | }
213 | ]
214 | },
215 | {
216 | "text": "Which company is the largest manufacturer of network equipment?",
217 | "answers": [
218 | {
219 | "text": [
220 | "Cisco"
221 | ]
222 | }
223 | ]
224 | },
225 | {
226 | "text": "What is CE in Windows CE stand for?",
227 | "answers": [
228 | {
229 | "text": [
230 | "Consumer Electronics"
231 | ]
232 | }
233 | ]
234 | },
235 | {
236 | "text": "What is BSD in BSD Unix?",
237 | "answers": [
238 | {
239 | "text": [
240 | "Berkley Software Distribution"
241 | ]
242 | }
243 | ]
244 | },
245 | {
246 | "text": "What is the name of the popular free software license written by Richard Stallman for the GNU project?",
247 | "answers": [
248 | {
249 | "text": [
250 | "GPL",
251 | "GNU Public License"
252 | ]
253 | }
254 | ]
255 | },
256 | {
257 | "text": "What year was Google founded?",
258 | "answers": [
259 | {
260 | "text": [
261 | "1998"
262 | ]
263 | }
264 | ]
265 | },
266 | {
267 | "text": "What free loving programmer created the GCC compiler and the original Emacs?",
268 | "answers": [
269 | {
270 | "text": [
271 | "Richard Stallman"
272 | ]
273 | }
274 | ]
275 | },
276 | {
277 | "text": "What company is the world's largest maker of computer mice?",
278 | "answers": [
279 | {
280 | "text": [
281 | "Logitech"
282 | ]
283 | }
284 | ]
285 | },
286 | {
287 | "text": "What was the first full-length computer generated feature film?",
288 | "answers": [
289 | {
290 | "text": [
291 | "Toy story"
292 | ]
293 | }
294 | ]
295 | },
296 | {
297 | "text": "Which company invented the floppy disk?",
298 | "answers": [
299 | {
300 | "text": [
301 | "IBM"
302 | ]
303 | }
304 | ]
305 | },
306 | {
307 | "text": "What is the name of Linux’s Mascot?",
308 | "answers": [
309 | {
310 | "text": [
311 | "Tux"
312 | ]
313 | }
314 | ]
315 | },
316 | {
317 | "text": "A nibble is how many bits?",
318 | "answers": [
319 | {
320 | "text": [
321 | "4"
322 | ]
323 | }
324 | ]
325 | },
326 | {
327 | "text": "What game system was the first to offer online gaming?",
328 | "answers": [
329 | {
330 | "text": [
331 | "Dreamcast"
332 | ]
333 | }
334 | ]
335 | },
336 | {
337 | "text": "What Apple media file format became the basis for MPEG-4 files?",
338 | "answers": [
339 | {
340 | "text": [
341 | "QuickTime"
342 | ]
343 | }
344 | ]
345 | },
346 | {
347 | "text": "What does the computer acronym PnP stand for?",
348 | "answers": [
349 | {
350 | "text": [
351 | "Plug & Play",
352 | "Plug n Play",
353 | "Plug and Play"
354 | ]
355 | }
356 | ]
357 | },
358 | {
359 | "text": "What file-sharing software was named for creator Shawn Fanning’s frizzy hair?",
360 | "answers": [
361 | {
362 | "text": [
363 | "Napster"
364 | ]
365 | }
366 | ]
367 | },
368 | {
369 | "text": "What does the “W” stand for on a WAP phone?",
370 | "answers": [
371 | {
372 | "text": [
373 | "wireless"
374 | ]
375 | }
376 | ]
377 | },
378 | {
379 | "text": "How many zeros are in a Googol?",
380 | "answers": [
381 | {
382 | "text": [
383 | "100"
384 | ]
385 | }
386 | ]
387 | },
388 | {
389 | "text": "What chess-playing computer developed by IBM that defeated world champion Garry Kasparov in 1997? Feel free to Google this one. LOL.",
390 | "answers": [
391 | {
392 | "text": [
393 | "Deep blue"
394 | ]
395 | }
396 | ]
397 | },
398 | {
399 | "text": "Amazon has recently released a variety of services for web developers. Some of these services are Elastic Compute Cloud (ECC), Simple Storage Service (S3), SimpleDB, and several others. Collectively these services are known as what?",
400 | "answers": [
401 | {
402 | "text": [
403 | "Amazon Web Services",
404 | "AWS"
405 | ]
406 | }
407 | ]
408 | },
409 | {
410 | "text": "Complete this quote: Computers are useless. They can only give you a-----s. (Pablo Picasso)",
411 | "answers": [
412 | {
413 | "text": [
414 | "answers"
415 | ]
416 | }
417 | ]
418 | },
419 | {
420 | "text": "An Athlon 600 mhz CPU has -- million transistors. Clue: between 10 and 40.",
421 | "answers": [
422 | {
423 | "text": [
424 | "22"
425 | ]
426 | }
427 | ]
428 | },
429 | {
430 | "text": "There are -- million lines of code in Windows 98. Clue: two digit less than 20.",
431 | "answers": [
432 | {
433 | "text": [
434 | "18"
435 | ]
436 | }
437 | ]
438 | },
439 | {
440 | "text": "The M in MP3 stands for ----",
441 | "answers": [
442 | {
443 | "text": [
444 | "MPEG"
445 | ]
446 | }
447 | ]
448 | },
449 | {
450 | "text": "An outbreak in which multiplayer video game attracted the attention of epidemiologists?",
451 | "answers": [
452 | {
453 | "text": [
454 | "World of Warcraft",
455 | "wow"
456 | ]
457 | }
458 | ]
459 | },
460 | {
461 | "text": "What was the first computer with internally stored programs? Clue: four capital letters.",
462 | "answers": [
463 | {
464 | "text": [
465 | "SSEM"
466 | ]
467 | }
468 | ]
469 | },
470 | {
471 | "text": "Before it became Google's email domain, fans of which known cat used Gmail.com?",
472 | "answers": [
473 | {
474 | "text": [
475 | "garfield"
476 | ]
477 | }
478 | ]
479 | },
480 | {
481 | "text": "Which popular CD burning app’s name is a historical pun?",
482 | "answers": [
483 | {
484 | "text": [
485 | "Nero"
486 | ]
487 | }
488 | ]
489 | },
490 | {
491 | "text": "Nintendo’s only attempt into breakfast cereal featured which characters?",
492 | "answers": [
493 | {
494 | "text": [
495 | "mario"
496 | ]
497 | },
498 | {
499 | "text": [
500 | "link"
501 | ]
502 | }
503 | ]
504 | },
505 | {
506 | "text": "What preinstalled Windows game was secretly intended to increase mouse proficiency?",
507 | "answers": [
508 | {
509 | "text": [
510 | "Solitaire"
511 | ]
512 | }
513 | ]
514 | },
515 | {
516 | "text": "The first Google server was built from what? Clue: kiddie thingies.",
517 | "answers": [
518 | {
519 | "text": [
520 | "LEGO"
521 | ]
522 | }
523 | ]
524 | },
525 | {
526 | "text": "",
527 | "answers": [
528 | {
529 | "text": [
530 | ""
531 | ]
532 | }
533 | ]
534 | }
535 | ],
536 | "settings": {
537 | "startQuestionGap": 3,
538 | "questionTime": 90,
539 | "nextQuestionGap": 10,
540 | "pointsPerQuestion": 3,
541 | "randomise": true,
542 | "questionGap": 10
543 | }
544 | }
--------------------------------------------------------------------------------
/data/us_states.json:
--------------------------------------------------------------------------------
1 | {"questions":[{"text":"Which is the only US state to have a border with only one other US state?","answers":[{"text":["Maine"]}]},{"text":"After Alaska, which is the least populated state, with approximately six people per square mile?","answers":[{"text":["Wyoming"]}]},{"text":"Established in 1630, which city is the longest serving continuously state capital?","answers":[{"text":["Boston"]}]},{"text":"Name the top five largest states by area","answers":[{"text":["Alaska"]},{"text":["Texas"]},{"text":["California"]},{"text":["Montana"]},{"text":["New Mexico"]}]},{"text":"Baton Rouge has been the capital of which state since 1880?","answers":[{"text":["Louisiana"]}]},{"text":"Which US state is claimed to be named after the wife of King Charles I of England?","answers":[{"text":["Maryland"]}]},{"text":"Fargo is the largest city of which US state?","answers":[{"text":["North Dakota"]}]},{"text":"Which state has a border with Colorado, Nebraska, Missouri and Oklahoma?","answers":[{"text":["Kansas"]}]},{"text":"Which US state has the least populated capital?","answers":[{"text":["Vermont"]}]},{"text":"Name the 8 states whose names both begin and end with a vowel","answers":[{"text":["Alaska"]},{"text":["Alabama"]},{"text":["Arizona"]},{"text":["Idaho"]},{"text":["Indiana"]},{"text":["Iowa"]},{"text":["Oklahoma"]},{"text":["Ohio"]}],"points":1}],"settings":{"startQuestionGap":3,"questionTime":60,"nextQuestionGap":10,"pointsPerQuestion":3,"randomise":false}}
--------------------------------------------------------------------------------
/example.js:
--------------------------------------------------------------------------------
1 | var QuizBot = require('slackquizbot');
2 | var myQuizBot = new QuizBot('_YOUR_SLACK_BOT_TOKEN_');
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | var fs = require('fs');
2 | var SlackAPI = require('slackbotapi');
3 | var Quiz = require('./quiz.js');
4 |
5 | function QuizBot(slackToken, locale) {
6 | if (typeof locale === 'undefined') { locale = 'en'; }
7 |
8 | this.slack = new SlackAPI({
9 | 'token': slackToken,
10 | 'logging': false
11 | });
12 |
13 | this.slack.on('hello', this.onConnectToSlack.bind(this));
14 | this.slack.on('message', this.onSlackMessage.bind(this));
15 | this.slack.on('file_shared', this.onFileShared.bind(this));
16 |
17 | this.quizzes = [];
18 | this.locale = locale;
19 | }
20 |
21 | QuizBot.prototype.loadLocale = function(lang) {
22 | var isLocalSuccess = this.tryLoadLocale('locale/' + lang + '.json');
23 | if(!isLocalSuccess) {
24 | var isBuiltInSuccess = this.tryLoadLocale(__dirname + '/locale/' + lang + '.json');
25 | if(!isBuiltInSuccess) {
26 | this.onLocaleLoadFailed(lang);
27 | return false;
28 | }
29 | }
30 | return true;
31 | };
32 | QuizBot.prototype.tryLoadLocale = function(filePath) {
33 | try {
34 | var data = fs.readFileSync(filePath, 'utf8');
35 | this.locale = JSON.parse(data);
36 | return true;
37 | }catch (e) {
38 | return false;
39 | }
40 | }
41 | QuizBot.prototype.getLocale = function(quiz, id) {
42 | if(quiz != null) {
43 | var customQuizLocale = quiz.getCustomLocale(id);
44 | if(customQuizLocale) {
45 | return customQuizLocale;
46 | }
47 | }
48 |
49 | if(this.locale[id] && this.locale[id].length > 0) {
50 | var rnd = Math.floor(Math.random() * this.locale[id].length);
51 | return this.locale[id][rnd];
52 | }else{
53 | return "Oops, I don't have locale for " + id;
54 | }
55 | };
56 | QuizBot.prototype.onLocaleLoadFailed = function(lang) {
57 | this.slack.sendMsg(slackChannel, this.getLocale(null, quizId.length == 0 ? 'quizLoadFailedEmpty' : 'quizLoadFailed').replace("", quizId));// + " [" + err + "]");
58 | };
59 |
60 | QuizBot.prototype.saveQuizToDisk = function(name, url, slackChannel) {
61 | var quizId = name.replace(/\.[^/.]+$/, "");
62 |
63 | var http = require('https');
64 |
65 | var content = '';
66 | var request = http.request(url, function (res) {
67 | res.on('data', function (chunk) {
68 | content += chunk;
69 | }.bind(this));
70 | res.on('end', function () {
71 | try {
72 | fs.mkdirSync('data');
73 | }catch(e) {}
74 | fs.writeFile('data/' + quizId + '.json', content, function(err) {
75 | if (err) {
76 | this.slack.sendMsg(slackChannel, "Couldn't save file. Error: " + err);
77 | return;
78 | }
79 | this.slack.sendMsg(slackChannel, "Quiz successfully saved as " + quizId + '!');
80 | }.bind(this));
81 | }.bind(this));
82 | }.bind(this));
83 | request.on('error', function (e) {
84 | this.slack.sendMsg(slackChannel, "There was an error: " + e.message);
85 | }.bind(this));
86 | request.end();
87 | };
88 |
89 | QuizBot.prototype.listQuizzes = function(slackChannel) {
90 | this.quizList = [];
91 | fs.readdir(__dirname + '/data', function(err, files) {
92 | if (err) {
93 | //this.slack.sendMsg(slackChannel, "Couldn't find directory. Error: " + err);
94 | //return;
95 | }else{
96 | for(var i=0; i", quizId));// + " [" + err + "]");
157 | };
158 |
159 | QuizBot.prototype.startQuiz = function(quiz, slackChannel, quizId) {
160 | var isValid = true;
161 | if(quiz != null && quiz.state > 0) {
162 | isValid = false;
163 | }
164 | if(isValid) {
165 | this.loadQuiz(slackChannel, quizId);
166 | }else{
167 | this.slack.sendMsg(slackChannel, this.getLocale(quiz, 'quizAlreadyRunning'));
168 | }
169 | };
170 | QuizBot.prototype.pauseQuiz = function(quiz, slackChannel) {
171 | if(quiz == null) {
172 | this.slack.sendMsg(slackChannel, this.getLocale(quiz, 'quizNotLoadedYet'));
173 | }else{
174 | this.slack.sendMsg(slackChannel, this.getLocale(quiz, 'quizPaused'));
175 | quiz.pause();
176 | }
177 | };
178 | QuizBot.prototype.resumeQuiz = function(quiz, slackChannel) {
179 | if(quiz == null) {
180 | this.slack.sendMsg(slackChannel, this.getLocale(quiz, 'quizNotLoadedYet'));
181 | }else{
182 | this.slack.sendMsg(slackChannel, this.getLocale(quiz, 'quizResumed'));
183 | quiz.resume();
184 | }
185 | };
186 | QuizBot.prototype.stopQuiz = function(quiz, slackChannel) {
187 | if(quiz == null) {
188 | this.slack.sendMsg(slackChannel, this.getLocale(quiz, 'quizNotLoadedYet'));
189 | }else{
190 | this.slack.sendMsg(slackChannel, this.getLocale(quiz, 'quizStopped'));
191 | quiz.stop();
192 | this.quizzes[slackChannel] = null;
193 | }
194 | };
195 |
196 | QuizBot.prototype.onQuestionPrepped = function(quiz, questionIndex) {
197 | var text = "";
198 | if(questionIndex == 0) {
199 | text = this.getLocale(quiz, 'questionPrepFirst');
200 | }else if(questionIndex == quiz.questions.length-1) {
201 | text = this.getLocale(quiz, 'questionPrepLast');
202 | }else{
203 | text = this.getLocale(quiz, 'questionPrep');
204 | }
205 | text = text.replace("", questionIndex+1);
206 | this.slack.sendMsg(quiz.slackChannel, text);
207 | };
208 | QuizBot.prototype.onQuestionStarted = function(quiz, question) {
209 | var pointsPrefix = "";
210 | var text;
211 | if(question.points > 1 || question.answerCount > 1) {
212 | pointsPrefix = "For " + question.points + " point" + (question.points != 1 ? "s" : "") + (question.answerCount > 1 ? " each" : "") + ", ";
213 | text = pointsPrefix + "*" + question.text.substring(0, 1).toLowerCase() + question.text.substring(1) + "* " + (question.image != null ? question.image : "");
214 | }
215 | else{
216 | text = "*" + question.text + "* " + (question.image != null ? question.image : "");
217 |
218 | }
219 | this.slack.sendMsg(quiz.slackChannel, text);
220 | };
221 | QuizBot.prototype.onQuestionTimeout = function(quiz, question) {
222 | var correctAnswerText = question.answerCount == 1 ? this.getLocale(quiz, 'correctAnswerSingle') : this.getLocale(quiz, 'correctAnswerMultiple');
223 | correctAnswerText = correctAnswerText.replace("", quiz.getCorrectAnswers());
224 | this.slack.sendMsg(quiz.slackChannel, this.getLocale(quiz, 'questionTimeout') + ' ' + correctAnswerText);
225 | };
226 | QuizBot.prototype.onOtherPossibleAnswers = function(quiz, otherAnswers) {
227 | var text = otherAnswers.length == 1 ? this.getLocale(quiz, 'otherPossibleAnswer') : this.getLocale(quiz, 'otherPossibleAnswers');
228 | var answersText = "";
229 | for(var i=0; i", answersText);
240 | this.slack.sendMsg(quiz.slackChannel, text);
241 | };
242 | QuizBot.prototype.onCorrectAnswer = function(quiz, user, answers, points, answersLeft) {
243 | var correctMsg = "";
244 | if(answers.length == 1) {
245 | correctMsg = this.getLocale(quiz, 'correctAnswer');
246 | }else if(answers.length == 2) {
247 | correctMsg = this.getLocale(quiz, 'correctAnswers2');
248 | }else{
249 | correctMsg = this.getLocale(quiz, 'correctAnswers');
250 | }
251 | correctMsg = correctMsg.replace('', "<@" + user.name + ">");
252 | var answersText = "";
253 | for(var i=0; i', answersText);
264 | var answersRemainingText = "";
265 | if(answersLeft > 0) answersRemainingText = " *" + answersLeft + "* answer" + (answersLeft != 1 ? "s" : "") + " left...";
266 | var pointsText = points + " point" + (points != 1 ? "s" : "");
267 | correctMsg = correctMsg.replace('', pointsText);
268 | this.slack.sendMsg(quiz.slackChannel, "" + correctMsg + " " + answersRemainingText);
269 | };
270 | QuizBot.prototype.onShowScores = function(quiz, slackChannel) {
271 | if(quiz == null) {
272 | this.slack.sendMsg(slackChannel, this.getLocale(quiz, 'quizNotLoadedYet'));
273 | }else{
274 | this.slack.sendMsg(slackChannel, this.getLocale(quiz, 'latestScores') + quiz.getScores(this.getLocale(quiz, 'leads')));
275 | }
276 | };
277 | QuizBot.prototype.onIncorrectAnswer = function(quiz, user) {
278 | this.slack.sendMsg(quiz.slackChannel, this.getLocale(quiz, 'incorrectAnswer'));
279 | };
280 | QuizBot.prototype.onAnswerPrompt10SecondsLeft = function(quiz, secondsLeft) {
281 | this.slack.sendMsg(quiz.slackChannel, "Anyone? Only " + secondsLeft + " seconds left!");
282 | };
283 | QuizBot.prototype.onQuizComplete = function(quiz) {
284 | delete this.quizzes[quiz.slackChannel];
285 | this.slack.sendMsg(quiz.slackChannel, this.getLocale(quiz, 'finalScores') + quiz.getScores(this.getLocale(quiz, 'wins')));
286 | this.slack.sendMsg(quiz.slackChannel, this.getLocale(quiz, 'closer'));
287 | };
288 |
289 | QuizBot.prototype.getQuizByChannel = function(slackChannel) {
290 | return this.quizzes[slackChannel];
291 | };
292 |
293 | //************************
294 | // Slack handlers
295 | //************************
296 | QuizBot.prototype.onConnectToSlack = function(data) {
297 | this.name = this.slack.slackData.self.name;
298 | this.id = this.slack.slackData.self.id;
299 |
300 | if(this.loadLocale(this.locale)) {
301 | console.log("Quizbot [" + this.name + "] is up and running!");
302 | }else{
303 | console.log("Quizbot [" + this.name + "] could not load '" + this.locale + "' locale file");
304 | }
305 | };
306 |
307 | QuizBot.prototype.onSlackMessage = function(slackMsgData) {
308 | if(typeof slackMsgData.text == 'undefined') return;
309 |
310 | var quiz = this.getQuizByChannel(slackMsgData.channel);
311 | var user = this.slack.getUser(slackMsgData.user);
312 |
313 | //check for mention
314 | if(slackMsgData.text.indexOf('<@' + this.id + '>') > -1) {
315 | var startQuizIndex = slackMsgData.text.indexOf('start quiz');
316 | if(startQuizIndex > -1) {
317 | var rest = slackMsgData.text.substring(startQuizIndex + 11);
318 | var nextSpace = rest.indexOf(" ");
319 | var quizId = rest.substring(0, nextSpace > -1 ? nextSpace : rest.length);
320 | this.startQuiz(quiz, slackMsgData.channel, quizId);
321 | }else if(slackMsgData.text.match(/(pause quiz)\b/ig)) {
322 | this.pauseQuiz(quiz, slackMsgData.channel);
323 | }else if(slackMsgData.text.match(/(resume quiz)\b/ig)) {
324 | this.resumeQuiz(quiz, slackMsgData.channel);
325 | }else if(slackMsgData.text.match(/(stop quiz)\b/ig)) {
326 | this.stopQuiz(quiz, slackMsgData.channel);
327 | }else if(slackMsgData.text.match(/(quiz status)\b/ig)) {
328 | this.getQuizStatus(quiz, slackMsgData.channel);
329 | }else if(slackMsgData.text.match(/(show scores)\b/ig)) {
330 | this.onShowScores(quiz, slackMsgData.channel);
331 | }else if(slackMsgData.text.match(/(list quizzes)\b/ig)) {
332 | this.listQuizzes(slackMsgData.channel);
333 | }
334 | }else{
335 | //listen for normal text
336 | if(quiz != null) {
337 | if(quiz.isQuestionActive()) {
338 | quiz.checkAnswer(slackMsgData.text, user);
339 | }
340 | }
341 | }
342 | };
343 |
344 | QuizBot.prototype.onFileShared = function(data) {
345 | this.saveQuizToDisk(data.file.title, data.file.url, data.file.ims[0]);
346 | };
347 |
348 | module.exports = QuizBot;
349 |
--------------------------------------------------------------------------------
/locale/en.json:
--------------------------------------------------------------------------------
1 | {
2 | "quizLoadSuccess":[
3 | "Alright, we're all set!!",
4 | "I'm ready to go, are you?"
5 | ],
6 | "quizLoadFailed":[
7 | "Nope, couldn't find the quiz!",
8 | "Sorry, I can't locate the quiz...",
9 | " is not a valid quiz."
10 | ],
11 | "quizNotLoadedYet":[
12 | "I'm not running a quiz at the minute!",
13 | "There's no quiz running yet!"
14 | ],
15 | "quizLoadFailedEmpty":[
16 | "You need to enter a quiz id, like 'start quiz gk'!"
17 | ],
18 | "quizAlreadyRunning":[
19 | "There's already a quiz running!"
20 | ],
21 | "quizFinished":[
22 | "That's the end of the quiz!",
23 | "It's all over!"
24 | ],
25 | "quizPaused":[
26 | "Ok, we're going to take a little break..."
27 | ],
28 | "quizResumed":[
29 | "Ok, we're back!"
30 | ],
31 | "quizStopped":[
32 | "Ok, I've stopped the quiz.",
33 | "Ok, bailing out..."
34 | ],
35 | "correctAnswer":[
36 | " nails it with ! That's .",
37 | " has got it! It was ! .",
38 | "Well done , is correct for !",
39 | "! Yes , that's right! to you.",
40 | "Yes! to for ."
41 | ],
42 | "correctAnswers2":[
43 | " nails it with both ! !",
44 | "Good one , are correct! Have !",
45 | "Yes , those are both right! get you ."
46 | ],
47 | "correctAnswers":[
48 | " gets it with ! That's .",
49 | " has got it! It was . awarded!",
50 | "Well done ! are all correct! That's to you!",
51 | "Yes , those are right! earn you !"
52 | ],
53 | "otherPossibleAnswer":[
54 | "The other possible answer was .",
55 | " was the other one I would have accepted!"
56 | ],
57 | "otherPossibleAnswers":[
58 | "The other possible answers were .",
59 | " are the other ones I would have accepted!"
60 | ],
61 | "questionPrepFirst":[
62 | "Ok, let's go! Here's the first question..."
63 | ],
64 | "questionPrep":[
65 | "Here's the next question...",
66 | "Ok, question number ...",
67 | "Now for question ..."
68 | ],
69 | "questionPrepLast":[
70 | "This is the last question!",
71 | "Here comes the final question..."
72 | ],
73 | "questionTimeout":[
74 | "Time's up!",
75 | "Bong! Time has run out on that one...",
76 | "Nope? Ok, let's move on."
77 | ],
78 | "incorrectAnswer":[
79 | "Nope...",
80 | "Incorrect",
81 | "That's not it.",
82 | "Wrong!",
83 | "Not the right answer..."
84 | ],
85 | "correctAnswerSingle":[
86 | "The correct answer is ",
87 | "The answer is ",
88 | "It was actually !",
89 | "I was looking for there.",
90 | " is what I wanted to hear there."
91 | ],
92 | "correctAnswerMultiple":[
93 | "The correct answers were ",
94 | "The answers are ",
95 | "I was looking for !"
96 | ],
97 | "leads":[
98 | "leads",
99 | "heads the board",
100 | "is in front"
101 | ],
102 | "wins":[
103 | "wins",
104 | "triumphs",
105 | "is victorious"
106 | ],
107 | "latestScores":[
108 | "Here are the scores :trophy: ",
109 | "Let's have a look at the leaderboard :trophy:",
110 | "Who's winning so far? :trophy:",
111 | "The scores on the doors... :trophy:"
112 | ],
113 | "finalScores":[
114 | "Here are the final scores :trophy: ",
115 | "Let's have a look at the final leaderboard :trophy:",
116 | "So who won? :trophy:"
117 | ],
118 | "closer":[
119 | "That's a wrap, see you later everyone! :wave:",
120 | "Thanks for playing everyone! :clap:"
121 | ]
122 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "slackquizbot",
3 | "version": "0.1.11",
4 | "description": "A Slack bot who can run custom quizzes in your Slack channel",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/codebyfire/slackquizbot.git"
12 | },
13 | "keywords": [
14 | "slack",
15 | "bot",
16 | "quiz"
17 | ],
18 | "dependencies": {
19 | "eventemitter3": "^1.1.1",
20 | "slackbotapi": "*"
21 | },
22 | "author": "Richard Wallis (http://codebyfire.com)",
23 | "license": "GPL-2.0",
24 | "bugs": {
25 | "url": "https://github.com/codebyfire/slackquizbot/issues"
26 | },
27 | "homepage": "https://github.com/codebyfire/slackquizbot#readme"
28 | }
29 |
--------------------------------------------------------------------------------
/quiz.js:
--------------------------------------------------------------------------------
1 | var util = require('util');
2 | var EventEmitter = require('eventemitter3');
3 |
4 | var QuizState = {
5 | IDLE: 0,
6 | QUESTION_PENDING: 1,
7 | QUESTION_ANSWERED: 2,
8 | PAUSED: 3
9 | };
10 |
11 | var QuizEvents = {
12 | QUESTION_PREP: 'questionPrep',
13 | QUESTION: 'question',
14 | CORRECT_ANSWER: 'correctAnswer',
15 | INCORRECT_ANSWER: 'incorrectAnswer',
16 | QUESTION_TIMEOUT: 'questionTimeout',
17 | OTHER_POSSIBLE_ANSWERS: 'otherPossibleAnswers',
18 | ANSWER_PROMPT_10_SECONDS_LEFT: 'answerPrompt10SecondsLeft',
19 | SHOW_SCORES: 'showScores',
20 | QUIZ_COMPLETE: 'quizComplete'
21 | }
22 |
23 |
24 | function Quiz() {
25 | this.settings = {
26 | startQuestionGap: 3,
27 | questionTime: 30,
28 | nextQuestionGap: 10,
29 | pointsPerQuestion: 1,
30 | showScoreInterval: 5,
31 | timeBetweenIncorrectResponses: 10
32 | };
33 | this.state = QuizState.IDLE;
34 | this.currentQuestionIndex = 0;
35 | this.questions = [];
36 | this.scores = [];
37 | this.lastIncorrectAnswerPing = 0;
38 | this.showScoreCount = 0;
39 | };
40 |
41 | util.inherits(Quiz, EventEmitter);
42 |
43 | Quiz.prototype.init = function(data, slackChannel) {
44 | this.questions = data.questions;
45 | for(var setting in data.settings) {
46 | this.settings[setting] = data.settings[setting];
47 | }
48 | if(this.settings.randomise) {
49 | this.questions = Quiz.prototype.shuffle(this.questions);
50 | }
51 | if(this.settings.hasOwnProperty("totalQuestions")) {
52 | this.questions.splice(0, this.questions.length - this.settings.totalQuestions);
53 | }
54 | this.locale = data.locale;
55 | this.slackChannel = slackChannel;
56 | };
57 | Quiz.prototype.start = function() {
58 | if(this.state == QuizState.IDLE) {
59 | this.currentQuestionIndex = 0;
60 | this.startQuestion();
61 | }
62 | };
63 | Quiz.prototype.pause = function() {
64 | if(this.state != QuizState.PAUSED) {
65 | this.prePausedState = this.state;
66 | this.state = QuizState.PAUSED;
67 | }
68 | };
69 | Quiz.prototype.resume = function() {
70 | if(this.state == QuizState.PAUSED) {
71 | this.state = this.prePausedState;
72 | }
73 | };
74 | Quiz.prototype.stop = function() {
75 | clearInterval(this.interval);
76 | this.state = QuizState.IDLE;
77 | };
78 |
79 | Quiz.prototype.shuffle = function(o) {
80 | for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
81 | return o;
82 | }
83 |
84 | Quiz.prototype.getCustomLocale = function(id) {
85 | if(this.locale != null && this.locale[id] && this.locale[id].length > 0) {
86 | var rnd = Math.floor(Math.random() * this.locale[id].length);
87 | return this.locale[id][rnd];
88 | }else{
89 | return false;
90 | }
91 | };
92 |
93 | Quiz.prototype.startQuestion = function() {
94 | if(this.state != QuizState.QUESTION_PENDING) {
95 | this.state = QuizState.QUESTION_PENDING;
96 | this.prepQuestion();
97 | }
98 | };
99 | Quiz.prototype.prepQuestion = function() {
100 | this.emit(QuizEvents.QUESTION_PREP, this, this.currentQuestionIndex);
101 | setTimeout(this.outputQuestion.bind(this), this.settings.startQuestionGap * 1000);
102 | }
103 | Quiz.prototype.outputQuestion = function() {
104 | this.interval = setInterval(this.update.bind(this), 1000);
105 | this.currentQuestion = this.questions[this.currentQuestionIndex];
106 | this.currentQuestion.timeLeft = this.currentQuestion.time || this.settings.questionTime;
107 | this.currentQuestion.points = this.currentQuestion.points || this.settings.pointsPerQuestion;
108 | this.currentQuestion.answerCount = this.currentQuestion.answersNeeded || this.currentQuestion.answers.length;
109 | this.currentQuestion.pendingAnswers = this.currentQuestion.answers;
110 | this.emit(QuizEvents.QUESTION, this, this.currentQuestion);
111 | }
112 | Quiz.prototype.timeoutQuestion = function() {
113 | this.emit(QuizEvents.QUESTION_TIMEOUT, this, this.currentQuestion);
114 | this.endQuestion();
115 | }
116 | Quiz.prototype.endQuestion = function() {
117 | this.state = QuizState.QUESTION_ANSWERED;
118 | clearInterval(this.interval);
119 | this.showScoreCount++;
120 | if(this.showScoreCount >= this.settings.showScoreInterval && this.scores.length > 0 && this.currentQuestionIndex < this.questions.length-1) {
121 | setTimeout((function() {this.emit(QuizEvents.SHOW_SCORES, this);}.bind(this)), 3000);
122 | this.showScoreCount = 0;
123 | setTimeout(this.nextQuestion.bind(this), 3000 + this.settings.nextQuestionGap * 1000);
124 | }else{
125 | setTimeout(this.nextQuestion.bind(this), this.settings.nextQuestionGap * 1000);
126 | }
127 | };
128 | Quiz.prototype.nextQuestion = function() {
129 | if(this.state == QuizState.QUESTION_ANSWERED) {
130 | if(this.currentQuestionIndex < this.questions.length-1) {
131 | this.currentQuestionIndex++;
132 | this.startQuestion();
133 | }else{
134 | this.complete();
135 | }
136 | }
137 | };
138 | Quiz.prototype.complete = function() {
139 | this.state = QuizState.IDLE;
140 | this.emit(QuizEvents.QUIZ_COMPLETE, this);
141 | };
142 | Quiz.prototype.isQuestionActive = function() {
143 | return this.state == QuizState.QUESTION_PENDING;
144 | };
145 | Quiz.prototype.checkAnswer = function(text, user) {
146 | if(user == null) return;
147 | var userText = text.toLowerCase();
148 | var i = this.currentQuestion.pendingAnswers.length-1;
149 | var correctAnswers = [];
150 | while(i >= 0 && this.currentQuestion.answerCount > 0) {
151 | for(var j=0; j -1) {
153 | correctAnswers.push(this.currentQuestion.pendingAnswers[i].text[0]);
154 | this.currentQuestion.answerCount--;
155 | this.currentQuestion.pendingAnswers.splice(i, 1);
156 | break;
157 | }
158 | }
159 | i--;
160 | }
161 | if(correctAnswers.length > 0) {
162 | var points = this.currentQuestion.points * correctAnswers.length;
163 | this.addScore(user.name, points);
164 | this.emit(QuizEvents.CORRECT_ANSWER, this, user, correctAnswers, points, this.currentQuestion.answerCount);
165 | if(this.currentQuestion.answerCount == 0) {
166 | if(this.currentQuestion.pendingAnswers.length > 0) {
167 | this.emit(QuizEvents.OTHER_POSSIBLE_ANSWERS, this, this.currentQuestion.pendingAnswers);
168 | }
169 | this.endQuestion();
170 | }
171 | }else{
172 | var now = new Date().getTime();
173 | if(now - this.lastIncorrectAnswerPing > this.settings.timeBetweenIncorrectResponses * 1000) {
174 | this.emit(QuizEvents.INCORRECT_ANSWER, this, user);
175 | this.lastIncorrectAnswerPing = now;
176 | }
177 | }
178 | };
179 | Quiz.prototype.getCorrectAnswers = function() {
180 | var text = "";
181 | var len = this.currentQuestion.answers.length;
182 | for(var i=0; i 0 && i < len-1) text += ", ";
184 | if(i > 0 && i == len-1) text += " and ";
185 | text += "*" + this.currentQuestion.answers[i].text[0] + "*";
186 |
187 | }
188 | return text;
189 | };
190 |
191 | Quiz.prototype.addScore = function(user, points) {
192 | var isFound = false;
193 | for(var i=0; i";
219 | if(i > 1 && i < len-1) text += ", ";
220 | if(i > 0 && i == len-1) text += " and ";
221 | if(i == 0) {
222 | text += "*" + username + "* " + verb + " with " + this.scores[i].points + " points! ";
223 | }else if(i == 1) {
224 | text += username + " has " + this.scores[i].points;
225 | }else{
226 | text += username + " " + this.scores[i].points;
227 | }
228 | }
229 | return text;
230 | };
231 |
232 | Quiz.prototype.update = function() {
233 | if(this.state == QuizState.PAUSED) return;
234 | this.currentQuestion.timeLeft--;
235 | if(this.currentQuestion.timeLeft <= 0) {
236 | this.timeoutQuestion();
237 | }else{
238 | if(this.currentQuestion.timeLeft == 10) {
239 | this.emit(QuizEvents.ANSWER_PROMPT_10_SECONDS_LEFT, this, this.currentQuestion.timeLeft);
240 | }
241 | }
242 | };
243 |
244 | module.exports = Quiz;
245 |
--------------------------------------------------------------------------------