├── .gitignore ├── LICENSE ├── README.md ├── config.example.yml ├── config.js ├── package-lock.json ├── package.json ├── src ├── app.js └── game │ ├── core.js │ ├── index.js │ ├── logger.js │ ├── player.js │ ├── role.js │ ├── roles │ ├── hunter.js │ ├── seer.js │ ├── villager.js │ ├── werewolf.js │ └── witch.js │ ├── sheriff.js │ ├── speech.js │ ├── utils.js │ └── voter.js └── tests ├── app.js ├── game ├── roles.js ├── sheriff.js ├── vote.js └── wolves.js ├── index.js └── utils.js /.gitignore: -------------------------------------------------------------------------------- 1 | config.yml 2 | koishi.config.js 3 | go-cqhttp 4 | go-cqhttp.lnk 5 | 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # Diagnostic reports (https://nodejs.org/api/report.html) 15 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 16 | 17 | # Runtime data 18 | pids 19 | *.pid 20 | *.seed 21 | *.pid.lock 22 | 23 | # Directory for instrumented libs generated by jscoverage/JSCover 24 | lib-cov 25 | 26 | # Coverage directory used by tools like istanbul 27 | coverage 28 | *.lcov 29 | 30 | # nyc test coverage 31 | .nyc_output 32 | 33 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 34 | .grunt 35 | 36 | # Bower dependency directory (https://bower.io/) 37 | bower_components 38 | 39 | # node-waf configuration 40 | .lock-wscript 41 | 42 | # Compiled binary addons (https://nodejs.org/api/addons.html) 43 | build/Release 44 | 45 | # Dependency directories 46 | node_modules/ 47 | jspm_packages/ 48 | 49 | # TypeScript v1 declaration files 50 | typings/ 51 | 52 | # TypeScript cache 53 | *.tsbuildinfo 54 | 55 | # Optional npm cache directory 56 | .npm 57 | 58 | # Optional eslint cache 59 | .eslintcache 60 | 61 | # Microbundle cache 62 | .rpt2_cache/ 63 | .rts2_cache_cjs/ 64 | .rts2_cache_es/ 65 | .rts2_cache_umd/ 66 | 67 | # Optional REPL history 68 | .node_repl_history 69 | 70 | # Output of 'npm pack' 71 | *.tgz 72 | 73 | # Yarn Integrity file 74 | .yarn-integrity 75 | 76 | # dotenv environment variables file 77 | .env 78 | .env.test 79 | 80 | # parcel-bundler cache (https://parceljs.org/) 81 | .cache 82 | 83 | # Next.js build output 84 | .next 85 | 86 | # Nuxt.js build / generate output 87 | .nuxt 88 | dist 89 | 90 | # Gatsby files 91 | .cache/ 92 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 93 | # https://nextjs.org/blog/next-9-1#public-directory-support 94 | # public 95 | 96 | # vuepress build output 97 | .vuepress/dist 98 | 99 | # Serverless directories 100 | .serverless/ 101 | 102 | # FuseBox cache 103 | .fusebox/ 104 | 105 | # DynamoDB Local files 106 | .dynamodb/ 107 | 108 | # TernJS port file 109 | .tern-port 110 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # werewolf-bot 2 | 3 | 让你在群里玩狼人杀的 QQbot。 4 | 5 | 本 bot 为「现役&退役OIer 狼人杀群」(群号 690869318)编写,欢迎退役 / 非退役 OIer 加群。 6 | 7 | ### Tutorials 8 | 9 | 该 bot 只会在配置文件限定的 QQ 群内生效。 10 | 11 | ##### 注册 12 | 13 | 使用 `register` 注册。 14 | 15 | 注册成功后会被 bot 添加到当局游戏人员名单中。 16 | 17 | 如需取消报名可使用 `unregister`。 18 | 19 | 只能在游戏未开始时注册。 20 | 21 | ##### 开始游戏 22 | 23 | 使用 `start game` 开始游戏 24 | 25 | 开始游戏后会根据配置文件里的角色分配方案随机分配角色。 26 | 27 | 如果配置文件内没有对应人数的角色分配方案则无法开始游戏。 28 | 29 | ##### 角色功能 30 | 31 | 在分配到角色后使用 `help` 命令即可查看角色功能,包括用法和注意事项等。 32 | 33 | **以下所有角色命令的 `` 部分请自行使用 qq 或 nick 或座位号替换。** 34 | 35 | ### Usage 36 | 37 | 以下简短教程默认你有 NodeJS 基础且熟悉 Koishi 机器人部署。 38 | 39 | 1. clone 本项目到本地 40 | 2. 自行搭建 go-cqhttp 或类似服务 41 | 3. 复制 `config.example.yml` 到 `config.yml`,自行填写内容 42 | 4. 运行 `npm start` 启动程序 43 | 44 | ### Dependencies 45 | 46 | * Koishi 47 | * Mirai 48 | * go-cqhttp -------------------------------------------------------------------------------- /config.example.yml: -------------------------------------------------------------------------------- 1 | qq: 2 | group: 3 | master: 4 | server: 5 | type: # 选填 http 或 ws 6 | http: 7 | port: 8 | secret: 9 | token: 10 | ws: 11 | token: 12 | server: 13 | retry: 14 | max: 0 15 | rule: 16 | winCondition: all 17 | timeLimit: 18 | night: 19 | werewolf: 300 20 | seer: 60 21 | witch: 60 22 | templates: 23 | - [werewolf, werewolf, villager, villager, witch, seer] 24 | op: 25 | - 2601960221 26 | nicks: 27 | 2601960221: memset0 -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | const YAML = require('YAML'); 4 | 5 | const configDir = path.join(__dirname, './config.yml'); 6 | const configParser = YAML.parse; 7 | 8 | const config = configParser(fs.readFileSync(configDir).toString()); 9 | 10 | config.query = function (path, defaultValue = undefined) { 11 | const keyList = path.split('.'); 12 | let ctx = config; 13 | for (const key of keyList) { 14 | if (!Object.keys(ctx).includes(key)) { 15 | return defaultValue; 16 | } 17 | ctx = ctx[key]; 18 | } 19 | return ctx; 20 | } 21 | 22 | module.exports = config; -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "werewolf-bot", 3 | "version": "2.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@types/accepts": { 8 | "version": "1.3.5", 9 | "resolved": "https://registry.npmjs.org/@types/accepts/-/accepts-1.3.5.tgz", 10 | "integrity": "sha512-jOdnI/3qTpHABjM5cx1Hc0sKsPoYCp+DP/GJRGtDlPd7fiV9oXGGIcjW/ZOxLIvjGz8MA+uMZI9metHlgqbgwQ==", 11 | "requires": { 12 | "@types/node": "*" 13 | } 14 | }, 15 | "@types/body-parser": { 16 | "version": "1.19.0", 17 | "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.0.tgz", 18 | "integrity": "sha512-W98JrE0j2K78swW4ukqMleo8R7h/pFETjM2DQ90MF6XK2i4LO4W3gQ71Lt4w3bfm2EvVSyWHplECvB5sK22yFQ==", 19 | "requires": { 20 | "@types/connect": "*", 21 | "@types/node": "*" 22 | } 23 | }, 24 | "@types/connect": { 25 | "version": "3.4.34", 26 | "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.34.tgz", 27 | "integrity": "sha512-ePPA/JuI+X0vb+gSWlPKOY0NdNAie/rPUqX2GUPpbZwiKTkSPhjXWuee47E4MtE54QVzGCQMQkAL6JhV2E1+cQ==", 28 | "requires": { 29 | "@types/node": "*" 30 | } 31 | }, 32 | "@types/content-disposition": { 33 | "version": "0.5.3", 34 | "resolved": "https://registry.npmjs.org/@types/content-disposition/-/content-disposition-0.5.3.tgz", 35 | "integrity": "sha512-P1bffQfhD3O4LW0ioENXUhZ9OIa0Zn+P7M+pWgkCKaT53wVLSq0mrKksCID/FGHpFhRSxRGhgrQmfhRuzwtKdg==" 36 | }, 37 | "@types/cookies": { 38 | "version": "0.7.6", 39 | "resolved": "https://registry.npmjs.org/@types/cookies/-/cookies-0.7.6.tgz", 40 | "integrity": "sha512-FK4U5Qyn7/Sc5ih233OuHO0qAkOpEcD/eG6584yEiLKizTFRny86qHLe/rej3HFQrkBuUjF4whFliAdODbVN/w==", 41 | "requires": { 42 | "@types/connect": "*", 43 | "@types/express": "*", 44 | "@types/keygrip": "*", 45 | "@types/node": "*" 46 | } 47 | }, 48 | "@types/express": { 49 | "version": "4.17.11", 50 | "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.11.tgz", 51 | "integrity": "sha512-no+R6rW60JEc59977wIxreQVsIEOAYwgCqldrA/vkpCnbD7MqTefO97lmoBe4WE0F156bC4uLSP1XHDOySnChg==", 52 | "requires": { 53 | "@types/body-parser": "*", 54 | "@types/express-serve-static-core": "^4.17.18", 55 | "@types/qs": "*", 56 | "@types/serve-static": "*" 57 | } 58 | }, 59 | "@types/express-serve-static-core": { 60 | "version": "4.17.18", 61 | "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.18.tgz", 62 | "integrity": "sha512-m4JTwx5RUBNZvky/JJ8swEJPKFd8si08pPF2PfizYjGZOKr/svUWPcoUmLow6MmPzhasphB7gSTINY67xn3JNA==", 63 | "requires": { 64 | "@types/node": "*", 65 | "@types/qs": "*", 66 | "@types/range-parser": "*" 67 | } 68 | }, 69 | "@types/http-assert": { 70 | "version": "1.5.1", 71 | "resolved": "https://registry.npmjs.org/@types/http-assert/-/http-assert-1.5.1.tgz", 72 | "integrity": "sha512-PGAK759pxyfXE78NbKxyfRcWYA/KwW17X290cNev/qAsn9eQIxkH4shoNBafH37wewhDG/0p1cHPbK6+SzZjWQ==" 73 | }, 74 | "@types/http-errors": { 75 | "version": "1.8.0", 76 | "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-1.8.0.tgz", 77 | "integrity": "sha512-2aoSC4UUbHDj2uCsCxcG/vRMXey/m17bC7UwitVm5hn22nI8O8Y9iDpA76Orc+DWkQ4zZrOKEshCqR/jSuXAHA==" 78 | }, 79 | "@types/keygrip": { 80 | "version": "1.0.2", 81 | "resolved": "https://registry.npmjs.org/@types/keygrip/-/keygrip-1.0.2.tgz", 82 | "integrity": "sha512-GJhpTepz2udxGexqos8wgaBx4I/zWIDPh/KOGEwAqtuGDkOUJu5eFvwmdBX4AmB8Odsr+9pHCQqiAqDL/yKMKw==" 83 | }, 84 | "@types/koa": { 85 | "version": "2.11.6", 86 | "resolved": "https://registry.npmjs.org/@types/koa/-/koa-2.11.6.tgz", 87 | "integrity": "sha512-BhyrMj06eQkk04C97fovEDQMpLpd2IxCB4ecitaXwOKGq78Wi2tooaDOWOFGajPk8IkQOAtMppApgSVkYe1F/A==", 88 | "requires": { 89 | "@types/accepts": "*", 90 | "@types/content-disposition": "*", 91 | "@types/cookies": "*", 92 | "@types/http-assert": "*", 93 | "@types/http-errors": "*", 94 | "@types/keygrip": "*", 95 | "@types/koa-compose": "*", 96 | "@types/node": "*" 97 | } 98 | }, 99 | "@types/koa-bodyparser": { 100 | "version": "4.3.0", 101 | "resolved": "https://registry.npmjs.org/@types/koa-bodyparser/-/koa-bodyparser-4.3.0.tgz", 102 | "integrity": "sha512-aB/vwwq4G9FAtKzqZ2p8UHTscXxZvICFKVjuckqxCtkX1Ro7F5KHkTCUqTRZFBgDoEkmeca+bFLI1bIsdPPZTA==", 103 | "requires": { 104 | "@types/koa": "*" 105 | } 106 | }, 107 | "@types/koa-compose": { 108 | "version": "3.2.5", 109 | "resolved": "https://registry.npmjs.org/@types/koa-compose/-/koa-compose-3.2.5.tgz", 110 | "integrity": "sha512-B8nG/OoE1ORZqCkBVsup/AKcvjdgoHnfi4pZMn5UwAPCbhk/96xyv284eBYW8JlQbQ7zDmnpFr68I/40mFoIBQ==", 111 | "requires": { 112 | "@types/koa": "*" 113 | } 114 | }, 115 | "@types/koa-router": { 116 | "version": "7.4.1", 117 | "resolved": "https://registry.npmjs.org/@types/koa-router/-/koa-router-7.4.1.tgz", 118 | "integrity": "sha512-Hg78TXz78QYfEgdq3nTeRmQFEwJKZljsXb/DhtexmyrpRDRnl59oMglh9uPj3/WgKor0woANrYTnxA8gaWGK2A==", 119 | "requires": { 120 | "@types/koa": "*" 121 | } 122 | }, 123 | "@types/mime": { 124 | "version": "2.0.3", 125 | "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.3.tgz", 126 | "integrity": "sha512-Jus9s4CDbqwocc5pOAnh8ShfrnMcPHuJYzVcSUU7lrh8Ni5HuIqX3oilL86p3dlTrk0LzHRCgA/GQ7uNCw6l2Q==" 127 | }, 128 | "@types/node": { 129 | "version": "14.14.21", 130 | "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.21.tgz", 131 | "integrity": "sha512-cHYfKsnwllYhjOzuC5q1VpguABBeecUp24yFluHpn/BQaVxB1CuQ1FSRZCzrPxrkIfWISXV2LbeoBthLWg0+0A==" 132 | }, 133 | "@types/qs": { 134 | "version": "6.9.5", 135 | "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.5.tgz", 136 | "integrity": "sha512-/JHkVHtx/REVG0VVToGRGH2+23hsYLHdyG+GrvoUGlGAd0ErauXDyvHtRI/7H7mzLm+tBCKA7pfcpkQ1lf58iQ==" 137 | }, 138 | "@types/range-parser": { 139 | "version": "1.2.3", 140 | "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.3.tgz", 141 | "integrity": "sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==" 142 | }, 143 | "@types/serve-static": { 144 | "version": "1.13.8", 145 | "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.8.tgz", 146 | "integrity": "sha512-MoJhSQreaVoL+/hurAZzIm8wafFR6ajiTM1m4A0kv6AGeVBl4r4pOV8bGFrjjq1sGxDTnCoF8i22o0/aE5XCyA==", 147 | "requires": { 148 | "@types/mime": "*", 149 | "@types/node": "*" 150 | } 151 | }, 152 | "accepts": { 153 | "version": "1.3.7", 154 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", 155 | "integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", 156 | "requires": { 157 | "mime-types": "~2.1.24", 158 | "negotiator": "0.6.2" 159 | } 160 | }, 161 | "any-promise": { 162 | "version": "1.3.0", 163 | "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", 164 | "integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8=" 165 | }, 166 | "assertion-error": { 167 | "version": "1.1.0", 168 | "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", 169 | "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==" 170 | }, 171 | "axios": { 172 | "version": "0.21.1", 173 | "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", 174 | "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", 175 | "requires": { 176 | "follow-redirects": "^1.10.0" 177 | } 178 | }, 179 | "bytes": { 180 | "version": "3.1.0", 181 | "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", 182 | "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" 183 | }, 184 | "cac": { 185 | "version": "6.7.1", 186 | "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.1.tgz", 187 | "integrity": "sha512-LfGt47+ugCY65W4yUEyxnZKd/tJSBJD/gUAxQGiQjH7yqdhbaX2XN0Rli4+0W0DJiDONmYeh0TlJxMtXGZspIg==" 188 | }, 189 | "cache-content-type": { 190 | "version": "1.0.1", 191 | "resolved": "https://registry.npmjs.org/cache-content-type/-/cache-content-type-1.0.1.tgz", 192 | "integrity": "sha512-IKufZ1o4Ut42YUrZSo8+qnMTrFuKkvyoLXUywKz9GJ5BrhOFGhLdkx9sG4KAnVvbY6kEcSFjLQul+DVmBm2bgA==", 193 | "requires": { 194 | "mime-types": "^2.1.18", 195 | "ylru": "^1.2.0" 196 | } 197 | }, 198 | "chai": { 199 | "version": "4.2.0", 200 | "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", 201 | "integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==", 202 | "requires": { 203 | "assertion-error": "^1.1.0", 204 | "check-error": "^1.0.2", 205 | "deep-eql": "^3.0.1", 206 | "get-func-name": "^2.0.0", 207 | "pathval": "^1.1.0", 208 | "type-detect": "^4.0.5" 209 | } 210 | }, 211 | "chai-as-promised": { 212 | "version": "7.1.1", 213 | "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz", 214 | "integrity": "sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==", 215 | "requires": { 216 | "check-error": "^1.0.2" 217 | } 218 | }, 219 | "check-error": { 220 | "version": "1.0.2", 221 | "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", 222 | "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=" 223 | }, 224 | "co": { 225 | "version": "4.6.0", 226 | "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", 227 | "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=" 228 | }, 229 | "co-body": { 230 | "version": "6.1.0", 231 | "resolved": "https://registry.npmjs.org/co-body/-/co-body-6.1.0.tgz", 232 | "integrity": "sha512-m7pOT6CdLN7FuXUcpuz/8lfQ/L77x8SchHCF4G0RBTJO20Wzmhn5Sp4/5WsKy8OSpifBSUrmg83qEqaDHdyFuQ==", 233 | "requires": { 234 | "inflation": "^2.0.0", 235 | "qs": "^6.5.2", 236 | "raw-body": "^2.3.3", 237 | "type-is": "^1.6.16" 238 | } 239 | }, 240 | "colors": { 241 | "version": "1.4.0", 242 | "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", 243 | "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==" 244 | }, 245 | "content-disposition": { 246 | "version": "0.5.3", 247 | "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", 248 | "integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==", 249 | "requires": { 250 | "safe-buffer": "5.1.2" 251 | } 252 | }, 253 | "content-type": { 254 | "version": "1.0.4", 255 | "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", 256 | "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" 257 | }, 258 | "cookies": { 259 | "version": "0.8.0", 260 | "resolved": "https://registry.npmjs.org/cookies/-/cookies-0.8.0.tgz", 261 | "integrity": "sha512-8aPsApQfebXnuI+537McwYsDtjVxGm8gTIzQI3FDW6t5t/DAhERxtnbEPN/8RX+uZthoz4eCOgloXaE5cYyNow==", 262 | "requires": { 263 | "depd": "~2.0.0", 264 | "keygrip": "~1.1.0" 265 | } 266 | }, 267 | "copy-to": { 268 | "version": "2.0.1", 269 | "resolved": "https://registry.npmjs.org/copy-to/-/copy-to-2.0.1.tgz", 270 | "integrity": "sha1-JoD7uAaKSNCGVrYJgJK9r8kG9KU=" 271 | }, 272 | "debug": { 273 | "version": "3.1.0", 274 | "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", 275 | "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", 276 | "requires": { 277 | "ms": "2.0.0" 278 | } 279 | }, 280 | "deep-eql": { 281 | "version": "3.0.1", 282 | "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", 283 | "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", 284 | "requires": { 285 | "type-detect": "^4.0.0" 286 | } 287 | }, 288 | "deep-equal": { 289 | "version": "1.0.1", 290 | "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz", 291 | "integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=" 292 | }, 293 | "delegates": { 294 | "version": "1.0.0", 295 | "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", 296 | "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=" 297 | }, 298 | "depd": { 299 | "version": "2.0.0", 300 | "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", 301 | "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==" 302 | }, 303 | "destroy": { 304 | "version": "1.0.4", 305 | "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", 306 | "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" 307 | }, 308 | "ee-first": { 309 | "version": "1.1.1", 310 | "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", 311 | "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 312 | }, 313 | "encodeurl": { 314 | "version": "1.0.2", 315 | "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", 316 | "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" 317 | }, 318 | "escape-html": { 319 | "version": "1.0.3", 320 | "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", 321 | "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" 322 | }, 323 | "fastest-levenshtein": { 324 | "version": "1.0.12", 325 | "resolved": "https://registry.npmjs.org/fastest-levenshtein/-/fastest-levenshtein-1.0.12.tgz", 326 | "integrity": "sha512-On2N+BpYJ15xIC974QNVuYGMOlEVt4s0EOI3wwMqOmK1fdDY+FN/zltPV8vosq4ad4c/gJ1KHScUn/6AWIgiow==" 327 | }, 328 | "follow-redirects": { 329 | "version": "1.13.1", 330 | "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.1.tgz", 331 | "integrity": "sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg==" 332 | }, 333 | "fresh": { 334 | "version": "0.5.2", 335 | "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", 336 | "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" 337 | }, 338 | "get-func-name": { 339 | "version": "2.0.0", 340 | "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", 341 | "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=" 342 | }, 343 | "has-flag": { 344 | "version": "4.0.0", 345 | "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", 346 | "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" 347 | }, 348 | "http-assert": { 349 | "version": "1.4.1", 350 | "resolved": "https://registry.npmjs.org/http-assert/-/http-assert-1.4.1.tgz", 351 | "integrity": "sha512-rdw7q6GTlibqVVbXr0CKelfV5iY8G2HqEUkhSk297BMbSpSL8crXC+9rjKoMcZZEsksX30le6f/4ul4E28gegw==", 352 | "requires": { 353 | "deep-equal": "~1.0.1", 354 | "http-errors": "~1.7.2" 355 | }, 356 | "dependencies": { 357 | "depd": { 358 | "version": "1.1.2", 359 | "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", 360 | "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" 361 | }, 362 | "http-errors": { 363 | "version": "1.7.3", 364 | "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.3.tgz", 365 | "integrity": "sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw==", 366 | "requires": { 367 | "depd": "~1.1.2", 368 | "inherits": "2.0.4", 369 | "setprototypeof": "1.1.1", 370 | "statuses": ">= 1.5.0 < 2", 371 | "toidentifier": "1.0.0" 372 | } 373 | } 374 | } 375 | }, 376 | "http-errors": { 377 | "version": "1.8.0", 378 | "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.0.tgz", 379 | "integrity": "sha512-4I8r0C5JDhT5VkvI47QktDW75rNlGVsUf/8hzjCC/wkWI/jdTRmBb9aI7erSG82r1bjKY3F6k28WnsVxB1C73A==", 380 | "requires": { 381 | "depd": "~1.1.2", 382 | "inherits": "2.0.4", 383 | "setprototypeof": "1.2.0", 384 | "statuses": ">= 1.5.0 < 2", 385 | "toidentifier": "1.0.0" 386 | }, 387 | "dependencies": { 388 | "depd": { 389 | "version": "1.1.2", 390 | "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", 391 | "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" 392 | }, 393 | "setprototypeof": { 394 | "version": "1.2.0", 395 | "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", 396 | "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" 397 | } 398 | } 399 | }, 400 | "iconv-lite": { 401 | "version": "0.4.24", 402 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", 403 | "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", 404 | "requires": { 405 | "safer-buffer": ">= 2.1.2 < 3" 406 | } 407 | }, 408 | "inflation": { 409 | "version": "2.0.0", 410 | "resolved": "https://registry.npmjs.org/inflation/-/inflation-2.0.0.tgz", 411 | "integrity": "sha1-i0F+R8KPklpFEz2RTKH9OJEH8w8=" 412 | }, 413 | "inherits": { 414 | "version": "2.0.4", 415 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 416 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 417 | }, 418 | "is-generator-function": { 419 | "version": "1.0.8", 420 | "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.8.tgz", 421 | "integrity": "sha512-2Omr/twNtufVZFr1GhxjOMFPAj2sjc/dKaIqBhvo4qciXfJmITGH6ZGd8eZYNHza8t1y0e01AuqRhJwfWp26WQ==" 422 | }, 423 | "keygrip": { 424 | "version": "1.1.0", 425 | "resolved": "https://registry.npmjs.org/keygrip/-/keygrip-1.1.0.tgz", 426 | "integrity": "sha512-iYSchDJ+liQ8iwbSI2QqsQOvqv58eJCEanyJPJi+Khyu8smkcKSFUCbPwzFcL7YVtZ6eONjqRX/38caJ7QjRAQ==", 427 | "requires": { 428 | "tsscmp": "1.0.6" 429 | } 430 | }, 431 | "kleur": { 432 | "version": "4.1.3", 433 | "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.3.tgz", 434 | "integrity": "sha512-H1tr8QP2PxFTNwAFM74Mui2b6ovcY9FoxJefgrwxY+OCJcq01k5nvhf4M/KnizzrJvLRap5STUy7dgDV35iUBw==" 435 | }, 436 | "koa": { 437 | "version": "2.13.1", 438 | "resolved": "https://registry.npmjs.org/koa/-/koa-2.13.1.tgz", 439 | "integrity": "sha512-Lb2Dloc72auj5vK4X4qqL7B5jyDPQaZucc9sR/71byg7ryoD1NCaCm63CShk9ID9quQvDEi1bGR/iGjCG7As3w==", 440 | "requires": { 441 | "accepts": "^1.3.5", 442 | "cache-content-type": "^1.0.0", 443 | "content-disposition": "~0.5.2", 444 | "content-type": "^1.0.4", 445 | "cookies": "~0.8.0", 446 | "debug": "~3.1.0", 447 | "delegates": "^1.0.0", 448 | "depd": "^2.0.0", 449 | "destroy": "^1.0.4", 450 | "encodeurl": "^1.0.2", 451 | "escape-html": "^1.0.3", 452 | "fresh": "~0.5.2", 453 | "http-assert": "^1.3.0", 454 | "http-errors": "^1.6.3", 455 | "is-generator-function": "^1.0.7", 456 | "koa-compose": "^4.1.0", 457 | "koa-convert": "^1.2.0", 458 | "on-finished": "^2.3.0", 459 | "only": "~0.0.2", 460 | "parseurl": "^1.3.2", 461 | "statuses": "^1.5.0", 462 | "type-is": "^1.6.16", 463 | "vary": "^1.1.2" 464 | } 465 | }, 466 | "koa-bodyparser": { 467 | "version": "4.3.0", 468 | "resolved": "https://registry.npmjs.org/koa-bodyparser/-/koa-bodyparser-4.3.0.tgz", 469 | "integrity": "sha512-uyV8G29KAGwZc4q/0WUAjH+Tsmuv9ImfBUF2oZVyZtaeo0husInagyn/JH85xMSxM0hEk/mbCII5ubLDuqW/Rw==", 470 | "requires": { 471 | "co-body": "^6.0.0", 472 | "copy-to": "^2.0.1" 473 | } 474 | }, 475 | "koa-compose": { 476 | "version": "4.1.0", 477 | "resolved": "https://registry.npmjs.org/koa-compose/-/koa-compose-4.1.0.tgz", 478 | "integrity": "sha512-8ODW8TrDuMYvXRwra/Kh7/rJo9BtOfPc6qO8eAfC80CnCvSjSl0bkRM24X6/XBBEyj0v1nRUQ1LyOy3dbqOWXw==" 479 | }, 480 | "koa-convert": { 481 | "version": "1.2.0", 482 | "resolved": "https://registry.npmjs.org/koa-convert/-/koa-convert-1.2.0.tgz", 483 | "integrity": "sha1-2kCHXfSd4FOQmNFwC1CCDOvNIdA=", 484 | "requires": { 485 | "co": "^4.6.0", 486 | "koa-compose": "^3.0.0" 487 | }, 488 | "dependencies": { 489 | "koa-compose": { 490 | "version": "3.2.1", 491 | "resolved": "https://registry.npmjs.org/koa-compose/-/koa-compose-3.2.1.tgz", 492 | "integrity": "sha1-qFzLQLfZhtjlo0Wzoazo6rz1Tec=", 493 | "requires": { 494 | "any-promise": "^1.1.0" 495 | } 496 | } 497 | } 498 | }, 499 | "koa-router": { 500 | "version": "10.0.0", 501 | "resolved": "https://registry.npmjs.org/koa-router/-/koa-router-10.0.0.tgz", 502 | "integrity": "sha512-gAE5J1gBQTvfR8rMMtMUkE26+1MbO3DGpGmvfmM2pR9Z7w2VIb2Ecqeal98yVO7+4ltffby7gWOzpCmdNOQe0w==", 503 | "requires": { 504 | "debug": "^4.1.1", 505 | "http-errors": "^1.7.3", 506 | "koa-compose": "^4.1.0", 507 | "methods": "^1.1.2", 508 | "path-to-regexp": "^6.1.0" 509 | }, 510 | "dependencies": { 511 | "debug": { 512 | "version": "4.3.1", 513 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", 514 | "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", 515 | "requires": { 516 | "ms": "2.1.2" 517 | } 518 | }, 519 | "ms": { 520 | "version": "2.1.2", 521 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", 522 | "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" 523 | } 524 | } 525 | }, 526 | "koishi": { 527 | "version": "2.5.0", 528 | "resolved": "https://registry.npmjs.org/koishi/-/koishi-2.5.0.tgz", 529 | "integrity": "sha512-OYEyMoV+izSeafJzv4APBUGPWZSvBWU9oQvzFhdqNDLAtcfmlMPt/fFQWMG3KEGFy+i5/8A5i/Hj/Qn/844q7g==", 530 | "requires": { 531 | "cac": "^6.7.1", 532 | "kleur": "^4.1.3", 533 | "koishi-core": "^2.5.0", 534 | "koishi-plugin-common": "^3.0.3", 535 | "prompts": "^2.4.0" 536 | } 537 | }, 538 | "koishi-adapter-cqhttp": { 539 | "version": "1.0.8", 540 | "resolved": "https://registry.npmjs.org/koishi-adapter-cqhttp/-/koishi-adapter-cqhttp-1.0.8.tgz", 541 | "integrity": "sha512-PDRIB94hhuCuJ4vj9g/JQ4Tx/KewiwVhCVwjWj9HpYNT9Cwb9tAQFmcoNUdFURiyRiZfqNbG+dDLwHtQCCXoTA==", 542 | "requires": { 543 | "axios": "^0.21.0", 544 | "koishi-utils": "^3.2.1", 545 | "ms": "^2.1.2", 546 | "ws": "^7.4.0" 547 | }, 548 | "dependencies": { 549 | "ms": { 550 | "version": "2.1.3", 551 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", 552 | "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" 553 | } 554 | } 555 | }, 556 | "koishi-core": { 557 | "version": "2.5.0", 558 | "resolved": "https://registry.npmjs.org/koishi-core/-/koishi-core-2.5.0.tgz", 559 | "integrity": "sha512-EkrLVHk4MQnQFgq1/qB6MVkEREezEBA6ZtC0Y4sJ/E0QHwal2sJ7YNv4S+dX1R2u0eXyPrxtE7mJxttq2WNdPA==", 560 | "requires": { 561 | "@types/koa-bodyparser": "^4.3.0", 562 | "@types/koa-router": "^7.4.1", 563 | "fastest-levenshtein": "^1.0.12", 564 | "koa": "^2.13.0", 565 | "koa-bodyparser": "^4.3.0", 566 | "koa-router": "^10.0.0", 567 | "koishi-utils": "^3.2.1", 568 | "lru-cache": "^6.0.0" 569 | } 570 | }, 571 | "koishi-plugin-common": { 572 | "version": "3.0.3", 573 | "resolved": "https://registry.npmjs.org/koishi-plugin-common/-/koishi-plugin-common-3.0.3.tgz", 574 | "integrity": "sha512-oz60J8N5Bq9gWoprS3kNvqnSQqBWWFSvbtP70h5Fv55+7/GZW85s3kYbo3doZxEK3SKco3Jh9EteJXuYvJPFzQ==" 575 | }, 576 | "koishi-test-utils": { 577 | "version": "5.0.3", 578 | "resolved": "https://registry.npmjs.org/koishi-test-utils/-/koishi-test-utils-5.0.3.tgz", 579 | "integrity": "sha512-nnGqJnXFfAe2CREA1cddWxeCOzQ9rewNG+/cWQSu9ezETv/nwMtK7kS2Ys2xTzXOXWe4FF0HHe+0F2wqwbe/tw==", 580 | "requires": { 581 | "chai": "^4.2.0", 582 | "chai-as-promised": "^7.1.1", 583 | "koishi-core": "^2.4.2", 584 | "koishi-utils": "^3.1.5" 585 | } 586 | }, 587 | "koishi-utils": { 588 | "version": "3.2.1", 589 | "resolved": "https://registry.npmjs.org/koishi-utils/-/koishi-utils-3.2.1.tgz", 590 | "integrity": "sha512-P/lW1y5LgBwBOlp6NH5zTXksYEXxTS/+gcewI9Uy9pn8P0HyfpdkWwQxyXl7Q78uclOFTBqKSFvodPalFaJaBA==", 591 | "requires": { 592 | "supports-color": "^7.2.0" 593 | } 594 | }, 595 | "lodash": { 596 | "version": "4.17.20", 597 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", 598 | "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==" 599 | }, 600 | "lru-cache": { 601 | "version": "6.0.0", 602 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", 603 | "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", 604 | "requires": { 605 | "yallist": "^4.0.0" 606 | } 607 | }, 608 | "media-typer": { 609 | "version": "0.3.0", 610 | "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", 611 | "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" 612 | }, 613 | "methods": { 614 | "version": "1.1.2", 615 | "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", 616 | "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" 617 | }, 618 | "mime-db": { 619 | "version": "1.45.0", 620 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.45.0.tgz", 621 | "integrity": "sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==" 622 | }, 623 | "mime-types": { 624 | "version": "2.1.28", 625 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.28.tgz", 626 | "integrity": "sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ==", 627 | "requires": { 628 | "mime-db": "1.45.0" 629 | } 630 | }, 631 | "ms": { 632 | "version": "2.0.0", 633 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 634 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 635 | }, 636 | "negotiator": { 637 | "version": "0.6.2", 638 | "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", 639 | "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" 640 | }, 641 | "on-finished": { 642 | "version": "2.3.0", 643 | "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", 644 | "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", 645 | "requires": { 646 | "ee-first": "1.1.1" 647 | } 648 | }, 649 | "only": { 650 | "version": "0.0.2", 651 | "resolved": "https://registry.npmjs.org/only/-/only-0.0.2.tgz", 652 | "integrity": "sha1-Kv3oTQPlC5qO3EROMGEKcCle37Q=" 653 | }, 654 | "parseurl": { 655 | "version": "1.3.3", 656 | "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", 657 | "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" 658 | }, 659 | "path-to-regexp": { 660 | "version": "6.2.0", 661 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.0.tgz", 662 | "integrity": "sha512-f66KywYG6+43afgE/8j/GoiNyygk/bnoCbps++3ErRKsIYkGGupyv07R2Ok5m9i67Iqc+T2g1eAUGUPzWhYTyg==" 663 | }, 664 | "pathval": { 665 | "version": "1.1.0", 666 | "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", 667 | "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=" 668 | }, 669 | "prompts": { 670 | "version": "2.4.0", 671 | "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.0.tgz", 672 | "integrity": "sha512-awZAKrk3vN6CroQukBL+R9051a4R3zCZBlJm/HBfrSZ8iTpYix3VX1vU4mveiLpiwmOJT4wokTF9m6HUk4KqWQ==", 673 | "requires": { 674 | "kleur": "^3.0.3", 675 | "sisteransi": "^1.0.5" 676 | }, 677 | "dependencies": { 678 | "kleur": { 679 | "version": "3.0.3", 680 | "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", 681 | "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==" 682 | } 683 | } 684 | }, 685 | "qs": { 686 | "version": "6.9.6", 687 | "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.6.tgz", 688 | "integrity": "sha512-TIRk4aqYLNoJUbd+g2lEdz5kLWIuTMRagAXxl78Q0RiVjAOugHmeKNGdd3cwo/ktpf9aL9epCfFqWDEKysUlLQ==" 689 | }, 690 | "raw-body": { 691 | "version": "2.4.1", 692 | "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.1.tgz", 693 | "integrity": "sha512-9WmIKF6mkvA0SLmA2Knm9+qj89e+j1zqgyn8aXGd7+nAduPoqgI9lO57SAZNn/Byzo5P7JhXTyg9PzaJbH73bA==", 694 | "requires": { 695 | "bytes": "3.1.0", 696 | "http-errors": "1.7.3", 697 | "iconv-lite": "0.4.24", 698 | "unpipe": "1.0.0" 699 | }, 700 | "dependencies": { 701 | "depd": { 702 | "version": "1.1.2", 703 | "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", 704 | "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" 705 | }, 706 | "http-errors": { 707 | "version": "1.7.3", 708 | "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.3.tgz", 709 | "integrity": "sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw==", 710 | "requires": { 711 | "depd": "~1.1.2", 712 | "inherits": "2.0.4", 713 | "setprototypeof": "1.1.1", 714 | "statuses": ">= 1.5.0 < 2", 715 | "toidentifier": "1.0.0" 716 | } 717 | } 718 | } 719 | }, 720 | "safe-buffer": { 721 | "version": "5.1.2", 722 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 723 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 724 | }, 725 | "safer-buffer": { 726 | "version": "2.1.2", 727 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 728 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 729 | }, 730 | "setprototypeof": { 731 | "version": "1.1.1", 732 | "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", 733 | "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" 734 | }, 735 | "shuffle-array": { 736 | "version": "1.0.1", 737 | "resolved": "https://registry.npmjs.org/shuffle-array/-/shuffle-array-1.0.1.tgz", 738 | "integrity": "sha1-xP88/nTRb5NzBZIwGyXmV3sSiYs=" 739 | }, 740 | "sisteransi": { 741 | "version": "1.0.5", 742 | "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", 743 | "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==" 744 | }, 745 | "sleep-promise": { 746 | "version": "9.1.0", 747 | "resolved": "https://registry.npmjs.org/sleep-promise/-/sleep-promise-9.1.0.tgz", 748 | "integrity": "sha512-UHYzVpz9Xn8b+jikYSD6bqvf754xL2uBUzDFwiU6NcdZeifPr6UfgU43xpkPu67VMS88+TI2PSI7Eohgqf2fKA==" 749 | }, 750 | "statuses": { 751 | "version": "1.5.0", 752 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", 753 | "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" 754 | }, 755 | "supports-color": { 756 | "version": "7.2.0", 757 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", 758 | "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", 759 | "requires": { 760 | "has-flag": "^4.0.0" 761 | } 762 | }, 763 | "toidentifier": { 764 | "version": "1.0.0", 765 | "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", 766 | "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" 767 | }, 768 | "tsscmp": { 769 | "version": "1.0.6", 770 | "resolved": "https://registry.npmjs.org/tsscmp/-/tsscmp-1.0.6.tgz", 771 | "integrity": "sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA==" 772 | }, 773 | "type-detect": { 774 | "version": "4.0.8", 775 | "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", 776 | "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==" 777 | }, 778 | "type-is": { 779 | "version": "1.6.18", 780 | "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", 781 | "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", 782 | "requires": { 783 | "media-typer": "0.3.0", 784 | "mime-types": "~2.1.24" 785 | } 786 | }, 787 | "unpipe": { 788 | "version": "1.0.0", 789 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", 790 | "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" 791 | }, 792 | "vary": { 793 | "version": "1.1.2", 794 | "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", 795 | "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" 796 | }, 797 | "ws": { 798 | "version": "7.4.2", 799 | "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.2.tgz", 800 | "integrity": "sha512-T4tewALS3+qsrpGI/8dqNMLIVdq/g/85U98HPMa6F0m6xTbvhXU6RCQLqPH3+SlomNV/LdY6RXEbBpMH6EOJnA==" 801 | }, 802 | "yallist": { 803 | "version": "4.0.0", 804 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", 805 | "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" 806 | }, 807 | "yaml": { 808 | "version": "1.10.0", 809 | "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.0.tgz", 810 | "integrity": "sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==" 811 | }, 812 | "ylru": { 813 | "version": "1.2.1", 814 | "resolved": "https://registry.npmjs.org/ylru/-/ylru-1.2.1.tgz", 815 | "integrity": "sha512-faQrqNMzcPCHGVC2aaOINk13K+aaBDUPjGWl0teOXywElLjyVAB6Oe2jj62jHYtwsU49jXhScYbvPENK+6zAvQ==" 816 | } 817 | } 818 | } 819 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "werewolf-bot", 3 | "version": "2.0.0", 4 | "description": "让你在群里玩狼人杀的 QQ bot。", 5 | "main": "src/main.js", 6 | "dependencies": { 7 | "colors": "^1.4.0", 8 | "koishi": "^2.5.0", 9 | "koishi-adapter-cqhttp": "^1.0.8", 10 | "koishi-plugin-common": "^3.0.3", 11 | "koishi-test-utils": "^5.0.3", 12 | "koishi-utils": "^3.2.1", 13 | "lodash": "^4.17.20", 14 | "shuffle-array": "^1.0.1", 15 | "sleep-promise": "^9.1.0", 16 | "yaml": "^1.10.0" 17 | }, 18 | "devDependencies": {}, 19 | "scripts": { 20 | "start": "node src/app.js", 21 | "test": "node tests/index.js" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "git+https://github.com/memset0/werewolf-bot.git" 26 | }, 27 | "author": "memset0", 28 | "license": "GPL-3.0-or-later", 29 | "bugs": { 30 | "url": "https://github.com/memset0/werewolf-bot/issues" 31 | }, 32 | "homepage": "https://github.com/memset0/werewolf-bot#readme" 33 | } 34 | -------------------------------------------------------------------------------- /src/app.js: -------------------------------------------------------------------------------- 1 | const config = require('../config'); 2 | 3 | const { App } = require('koishi'); 4 | require('koishi-adapter-cqhttp') 5 | const app = new App(config.server.type === 'http' ? { 6 | type: 'cqhttp:http', 7 | selfId: config.qq, 8 | port: config.server.http.port, 9 | secret: config.server.http.secret, 10 | token: config.server.http.token, 11 | } : config.server.type === 'ws' ? { 12 | type: 'cqhttp:ws', 13 | selfId: config.qq, 14 | token: config.server.ws.token, 15 | server: config.server.ws.server, 16 | } : {}); 17 | 18 | app.command('help').dispose() 19 | app.plugin(require('./game/index')); 20 | 21 | (async function () { 22 | let retryCount = 0; 23 | while (retryCount++ <= config.retry.max || config.retry.max === -1) { 24 | try { 25 | const bot = app.bots.find(bot => bot); 26 | await app.start(); 27 | await bot.sendPrivateMsg(config.master, '您的 bot 已启动~'); 28 | } catch (err) { 29 | await bot.sendPrivateMsg(config.master, '您的 bot 遇到未知问题:' + err.message); 30 | await bot.sendPrivateMsg(config.master, err.stack); 31 | } 32 | } 33 | })(); -------------------------------------------------------------------------------- /src/game/core.js: -------------------------------------------------------------------------------- 1 | const colors = require('colors/safe'); 2 | 3 | const utils = require('./utils'); 4 | const config = require('../../config'); 5 | 6 | const Logger = require('./logger'); 7 | const Player = require('./player'); 8 | const Voter = require('./voter'); 9 | const Speech = require('./speech'); 10 | const Sheriff = require('./sheriff'); 11 | const Seer = require('./roles/seer'); 12 | const Hunter = require('./roles/hunter'); 13 | const Witch = require('./roles/witch'); 14 | const Villager = require('./roles/villager'); 15 | const Werewolf = require('./roles/werewolf'); 16 | 17 | class Game { 18 | 19 | log() { 20 | console.log('[GAME]', ...arguments); 21 | } 22 | 23 | async sendGroup(message) { 24 | console.log(colors.cyan('[SEND G]'), message.slice(0, 40).replace(/\n/g, colors.grey('\\n')), message.length > 40 ? colors.grey('...') : ''); 25 | return await this.bot.sendGroupMsg(config.group, message); 26 | } 27 | 28 | async sendPlayer(message) { 29 | if (typeof message === 'function') { 30 | return await Promise.all(this.playerList.map(player => { 31 | this.bot.sendPrivateMessage(player.id, message(player)); 32 | })); 33 | } else { 34 | return await Promise.all(this.playerList.map(player => { 35 | this.bot.sendPrivateMessage(player.id, message); 36 | })); 37 | } 38 | } 39 | 40 | addPlayer(player) { 41 | this.playerList.push(player); 42 | } 43 | 44 | removePlayer(player) { 45 | let index = -1; 46 | for (const i in this.playerList) { 47 | const registeredPlayer = this.playerList[i]; 48 | if (registeredPlayer.id == player.id) { 49 | index = i; 50 | break; 51 | } 52 | } 53 | if (index > -1) { 54 | this.playerList.splice(index, 1); 55 | return true; 56 | } 57 | return false; 58 | } 59 | 60 | getPlayer(input) { 61 | for (const player of this.playerList) { 62 | if (player.id === parseInt(input)) { 63 | return player; 64 | } 65 | } 66 | for (const player of this.playerList) { 67 | if (player.place === parseInt(input)) { 68 | return player; 69 | } 70 | } 71 | for (const player of this.playerList) { 72 | if (player.nick === String(input)) { 73 | return player; 74 | } 75 | } 76 | for (const player of this.playerList) { 77 | if (player.displayName === String(input)) { 78 | return player; 79 | } 80 | } 81 | return null; 82 | } 83 | 84 | getAlivePlayerList() { 85 | let alivePlayerList = []; 86 | for (const player of this.playerList) { 87 | if (player.alive) { 88 | alivePlayerList.push(player); 89 | } 90 | } 91 | return alivePlayerList; 92 | } 93 | 94 | findNextAlivePlayer(currentPlayer) { 95 | let targetPlace = currentPlayer.place; 96 | while (targetPlace === currentPlayer.place || !this.getPlayer(targetPlace).alive) { 97 | targetPlace++; 98 | if (targetPlace === this.playerList.length + 1) { 99 | targetPlace = 1; 100 | } 101 | if (targetPlace === currentPlayer.place) { 102 | return null; 103 | } 104 | } 105 | return this.getPlayer(targetPlace); 106 | } 107 | 108 | findPrevAlivePlayer(currentPlayer) { 109 | let targetPlace = currentPlayer.place; 110 | while (targetPlace === currentPlayer.place || !this.getPlayer(targetPlace).alive) { 111 | targetPlace--; 112 | if (targetPlace === 0) { 113 | targetPlace = this.playerList.length; 114 | } 115 | if (targetPlace === currentPlayer.place) { 116 | return null; 117 | } 118 | } 119 | return this.getPlayer(targetPlace); 120 | } 121 | 122 | async setRole(player, role) { 123 | player.setRole(role); 124 | this.roles[role].addPlayer(player); 125 | await player.send(`游戏开始!你的角色是 ${this.roles[role].getDisplayName()}`); 126 | } 127 | 128 | 129 | getTemplate() { 130 | const playerNumber = this.playerList.length; 131 | for (const template of this.templateList) { 132 | if (template.length === playerNumber) { 133 | return template; 134 | } 135 | } 136 | return null; 137 | } 138 | 139 | setTemplate(template) { 140 | this.templateList = [template]; 141 | } 142 | 143 | 144 | checkWinCondition() { 145 | if (config.rule.winCondition === 'all') { 146 | let flag 147 | let counter 148 | flag = false; 149 | for (const player of this.playerList) { 150 | if (!player.roleClass.isWolf() && player.alive) { 151 | flag = true; 152 | } 153 | } 154 | if (!flag) { 155 | return { 156 | res: true, 157 | winner: '狼人', 158 | message: '所有好人已经出局', 159 | }; 160 | } 161 | flag = false; 162 | for (const player of this.playerList) { 163 | if (player.roleClass.isWolf() && player.alive) { 164 | flag = true; 165 | } 166 | } 167 | if (!flag) { 168 | return { 169 | res: true, 170 | winner: '好人', 171 | message: '所有狼人已经出局' 172 | }; 173 | } 174 | counter = 0; 175 | for (const player of this.playerList) { 176 | if (player.alive) { 177 | if (player.roleClass.isWolf()) { 178 | counter++; 179 | } else { 180 | counter--; 181 | } 182 | } 183 | } 184 | if (counter >= 0) { 185 | return { 186 | res: true, 187 | winner: '狼人', 188 | message: '未出局的好人数量小于等于狼人数量' 189 | }; 190 | } 191 | 192 | } else if (config.rule.winCondition === 'part') { 193 | let flag_1 194 | let flag_2 195 | flag_1 = false; 196 | flag_2 = false; 197 | for (const player of this.playerList) { 198 | if (player.role === 'villager') { 199 | flag_1 = true; 200 | if (player.alive) { 201 | flag_2 = true; 202 | } 203 | } 204 | } 205 | if (flag_1 && !flag_2) { 206 | return { 207 | res: true, 208 | winner: '狼人', 209 | message: '所有村民已经出局' 210 | }; 211 | } 212 | flag_1 = false; 213 | flag_2 = false; 214 | for (const player of this.playerList) { 215 | if (!player.roleClass.isWolf() && player.role !== 'villager') { 216 | flag_1 = true; 217 | if (player.alive) { 218 | flag_2 = true; 219 | } 220 | } 221 | } 222 | if (flag_1 && !flag_2) { 223 | return { 224 | res: true, 225 | winner: '狼人', 226 | message: '所有神已经出局' 227 | }; 228 | } 229 | flag_2 = false; 230 | for (const player of this.playerList) { 231 | if (player.roleClass.isWolf() && player.alive) { 232 | flag_2 = true; 233 | } 234 | } 235 | if (!flag_2) { 236 | return { 237 | res: true, 238 | winner: '好人', 239 | message: '所有狼人已经出局' 240 | }; 241 | } 242 | } 243 | 244 | return { 245 | res: false, 246 | winner: null, 247 | error: '没有合法的获胜条件', 248 | } 249 | } 250 | 251 | async processKilled(player) { 252 | if (player.role === 'hunter') { 253 | if (!this.roles.witch.poisonedPlayer || player.id !== this.roles.witch.poisonedPlayer.id) { 254 | await this.roles.hunter.processKilled(); 255 | if (this.roles.hunter.shotPlayer) { 256 | this.roles.hunter.shotPlayer.alive = false; 257 | await this.processKilled(this.roles.hunter.shotPlayer); 258 | } 259 | } 260 | } 261 | } 262 | 263 | async processNight(roundId) { 264 | this.roundId = roundId; 265 | this.roundType = 'night'; 266 | await this.sendGroup(`第 ${roundId} 个晚上开始了`); 267 | 268 | await this.roles.werewolf.processNight(roundId); 269 | await this.roles.witch.processNight(roundId); 270 | await this.roles.seer.processNight(roundId); 271 | 272 | const diedPlayerList = []; 273 | if (this.roles.werewolf.killedPlayer && (!this.roles.witch.savedPlayer || this.roles.witch.savedPlayer.id !== this.roles.werewolf.killedPlayer.id)) { 274 | diedPlayerList.push(this.roles.werewolf.killedPlayer); 275 | } 276 | if (this.roles.witch.poisonedPlayer) { 277 | diedPlayerList.push(this.roles.witch.poisonedPlayer); 278 | } 279 | let hasBoomed = false; 280 | if (config.query('rule.sheriff', false) && (roundId === 1 || (roundId === 2 && this.sheriff.crashed))) { 281 | hasBoomed = !await this.sheriff.runForTheSheriff(); 282 | } 283 | 284 | for (const currentPlayer of diedPlayerList) { 285 | currentPlayer.alive = false; 286 | } 287 | utils.random.shuffle(diedPlayerList); 288 | 289 | let message = `第 ${roundId} 个晚上结束了,`; 290 | if (diedPlayerList.length === 0) { 291 | message += `今天是平安夜`; 292 | } else if (diedPlayerList.length === 1) { 293 | message += `今天晚上 [CQ:at,qq=${diedPlayerList[0].id}] 死了`; 294 | } else if (diedPlayerList.length === 2) { 295 | message += `今天晚上 [CQ:at,qq=${diedPlayerList[0].id}] 和 [CQ:at,qq=${diedPlayerList[1].id}] 死了`; 296 | } 297 | if (roundId === 1 && diedPlayerList.length !== 0 && !hasBoomed) { 298 | message += ',请留遗言'; 299 | } 300 | await this.sendGroup(message); 301 | 302 | for (const diedPlayer of diedPlayerList) { 303 | await this.processKilled(diedPlayer); 304 | } 305 | 306 | if (this.checkWinCondition().res) { 307 | await this.stop(); 308 | } else if (hasBoomed) { 309 | await this.processNight(roundId + 1); 310 | } else { 311 | await this.processDay(roundId, diedPlayerList); 312 | } 313 | } 314 | 315 | async processDay(roundId, diedPlayerList = []) { 316 | this.roundId = roundId; 317 | this.roundType = 'day'; 318 | 319 | await this.sendGroup(`第 ${roundId} 个白天开始了,请进行发言`); 320 | 321 | let speechOrder; 322 | const alivePlayerList = this.getAlivePlayerList(); 323 | const generateSpeechOrder = (firstPlayer, side, playerList = alivePlayerList) => { 324 | let speechOrder = []; 325 | let index = playerList.indexOf(firstPlayer); 326 | do { 327 | speechOrder.push(playerList[index]); 328 | if (side === 'right') { 329 | index++; 330 | if (index === playerList.length) { 331 | index = 0; 332 | } 333 | } else { 334 | if (index === 0) { 335 | index = playerList.length; 336 | } 337 | index--; 338 | } 339 | } while (index != playerList.indexOf(firstPlayer)); 340 | return speechOrder; 341 | }; 342 | if (this.sheriff.exists()) { 343 | if (diedPlayerList.length === 1) { 344 | await this.sendGroup('请警长选择死左死右发言'); 345 | let diedPlayer = diedPlayerList[0]; 346 | let side = await this.sheriff.get().waitForReceiveGroup(['left', 'right']); 347 | if (side === 'left') { 348 | speechOrder = generateSpeechOrder(this.findPrevAlivePlayer(diedPlayer), 'left'); 349 | } else { 350 | speechOrder = generateSpeechOrder(this.findNextAlivePlayer(diedPlayer), 'right'); 351 | } 352 | } else { 353 | await this.sendGroup('请警长选择警左警右发言'); 354 | let side = await this.sheriff.get().waitForReceiveGroup(['left', 'right']); 355 | speechOrder = generateSpeechOrder(this.sheriff.get(), side); 356 | } 357 | } else { 358 | await this.sendGroup('本局游戏没有警长,采取随机顺序发言'); 359 | if (diedPlayerList.length === 1) { 360 | let diedPlayer = diedPlayerList[0]; 361 | if (utils.random.choose(['right', 'left']) === 'right') { 362 | speechOrder = generateSpeechOrder(this.findNextAlivePlayer(diedPlayer), 'right'); 363 | } else { 364 | speechOrder = generateSpeechOrder(this.findPrevAlivePlayer(diedPlayer), 'left'); 365 | } 366 | } else { 367 | speechOrder = generateSpeechOrder(utils.random.choose(alivePlayerList), utils.random.choose(['right', 'left'])); 368 | } 369 | } 370 | 371 | if (await this.speech.process(speechOrder)) { 372 | await this.sendGroup('发言完毕,请投票'); 373 | 374 | this.voter.votablePlayers = this.voter.targets = alivePlayerList.map(player => player.id); 375 | let voteResult = await this.voter.process(); 376 | 377 | if (voteResult.length !== 1) { 378 | await this.sendGroup('第一轮投票没有结果,请进行第二轮发言'); 379 | if (await this.speech.process(generateSpeechOrder(utils.random.choose(voteResult), utils.random.choose(['right', 'left']), voteResult))) { 380 | await this.sendGroup('发言完毕,请投票'); 381 | voteResult = await this.voter.process(); 382 | } else { 383 | voteResult = null; 384 | } 385 | } 386 | 387 | if (voteResult) { 388 | if (voteResult.length === 1) { 389 | await this.sendGroup(`投票结束,${voteResult[0].displayName} 出局了`); 390 | voteResult[0].alive = false; 391 | await this.processKilled(voteResult[0]); 392 | } else { 393 | await this.sendGroup('投票结束,没有人出局'); 394 | } 395 | } 396 | } 397 | 398 | if (this.checkWinCondition().res) { 399 | await this.stop(); 400 | } else { 401 | await this.processNight(roundId + 1); 402 | } 403 | } 404 | 405 | async start() { 406 | if (this.started) { 407 | await this.sendGroup('游戏已经开始'); 408 | return; 409 | } 410 | if (!this.getTemplate()) { 411 | await this.sendGroup('没有合法的板子,无法开始游戏'); 412 | return; 413 | } 414 | 415 | this.started = true; 416 | this.logger.reset(); 417 | 418 | for (const roleName in this.roles) { 419 | const roleClass = this.roles[roleName]; 420 | roleClass.resetPlayer(); 421 | } 422 | 423 | let roleList = this.getTemplate(); 424 | utils.random.shuffle(roleList); 425 | 426 | for (const i in roleList) { 427 | const player = this.playerList[i]; 428 | const role = roleList[i]; 429 | 430 | player.setPlace(parseInt(i) + 1); 431 | await this.setRole(player, role); 432 | } 433 | 434 | for (const roleName in this.roles) { 435 | const roleClass = this.roles[roleName]; 436 | await roleClass.onGameStart(); 437 | for (const player of roleClass.playerList) { 438 | roleClass.help(player); 439 | } 440 | } 441 | 442 | await this.processNight(1); 443 | } 444 | 445 | async stop(result = null) { 446 | if (!this.started) { 447 | await this.sendGroup('游戏尚未开始'); 448 | return; 449 | } 450 | 451 | if (!result) { 452 | result = this.checkWinCondition(); 453 | if (!result.res) { 454 | result = { 455 | ...result, 456 | message: '游戏被手动结束', 457 | winner: 'bot ', 458 | }; 459 | } 460 | } 461 | 462 | let message = '游戏结束!\n' + 463 | `因为${result.message},${result.winner}阵营获得胜利\n` + 464 | '存活玩家:\n'; 465 | for (const player of this.playerList) { 466 | if (player.alive) { 467 | message += `<${this.roles[player.role].getDisplayName()}> ${player.displayName} [CQ:at,qq=${player.id}]\n`; 468 | } 469 | } 470 | message += '死亡玩家:\n'; 471 | for (const player of this.playerList) { 472 | if (!player.alive) { 473 | message += `<${this.roles[player.role].getDisplayName()}> ${player.displayName} [CQ:at,qq=${player.id}]\n`; 474 | } 475 | } 476 | message += '感谢你的游玩'; 477 | await this.sendGroup(message); 478 | 479 | this.started = false; 480 | this.playerList = []; 481 | 482 | this.voter.promise = null; 483 | this.speech.promise = null; 484 | for (const roleName in this.roles) { 485 | let roleClass = this.roles[roleName]; 486 | roleClass.promise = null; 487 | } 488 | } 489 | 490 | async register(id) { 491 | console.log('[GAME]', 'Register', id); 492 | 493 | if (this.started) { 494 | await this.sendGroup(`[CQ:at,qq=${id}] 游戏已经开始了,无法注册`); 495 | return; 496 | } 497 | 498 | if (this.getPlayer(id)) { 499 | await this.sendGroup(`[CQ:at,qq=${id}] 注册失败,你已经成功报名`); 500 | return; 501 | } 502 | 503 | this.addPlayer(new Player(id, this)); 504 | const currentPlayer = this.getPlayer(id); 505 | await this.sendGroup(`[CQ:at,qq=${currentPlayer.id}] 玩家 ${currentPlayer.getNick()} 注册成功!`); 506 | await this.helper.listAllPlayers(); 507 | await currentPlayer.send('hello!我是狼人杀 bot (*^▽^*)\n游玩前建议阅读说明书:https://github.com/memset0/QQbot-The-Werewolves-of-Millers-Hollow,别忘了给个 star 哦'); 508 | } 509 | 510 | async unregister(id) { 511 | this.log('Unregister', id); 512 | 513 | if (this.started) { 514 | await this.sendGroup(`[CQ:at,qq=${id}] 游戏已经开始了,无法取消注册`); 515 | return; 516 | } 517 | 518 | if (!this.getPlayer(id)) { 519 | await this.sendGroup(`[CQ:at,qq=${id}] 取消注册失败,你尚未成功报名`); 520 | return; 521 | } 522 | 523 | this.removePlayer(this.getPlayer(id)); 524 | await this.sendGroup(`[CQ:at,qq=${id}] 成功取消注册`); 525 | await this.helper.listAllPlayers(); 526 | } 527 | 528 | async status() { 529 | this.log('Status'); 530 | 531 | await this.helper.listAllPlayers(); 532 | } 533 | 534 | constructor(app, bot) { 535 | this.app = app; 536 | this.bot = bot; 537 | this.started = false; 538 | this.playerList = []; 539 | 540 | this.config = config; 541 | this.templateList = config.templates; 542 | 543 | this.logger = new Logger(); 544 | this.roles = { 545 | werewolf: new Werewolf(this), 546 | witch: new Witch(this), 547 | seer: new Seer(this), 548 | hunter: new Hunter(this), 549 | villager: new Villager(this), 550 | }; 551 | this.voter = new Voter(this); 552 | this.speech = new Speech(this); 553 | this.sheriff = new Sheriff(this); 554 | 555 | this.helper = { 556 | listAllPlayers: async () => { 557 | let message = ''; 558 | if (this.playerList.length) { 559 | message += `已经注册的玩家有 ${this.playerList.length} 个:\n`; 560 | for (const i in this.playerList) { 561 | const player = this.playerList[i]; 562 | if (this.started) { 563 | message += `${player.displayName} (${player.alive ? '存活' : '出局'})\n`; 564 | } else { 565 | message += `[${parseInt(i) + 1}]${player.nick}\n`; 566 | } 567 | } 568 | } else { 569 | message += '当前没有玩家注册'; 570 | } 571 | return await this.sendGroup(message); 572 | }, 573 | 574 | listVotes: async (voteResult, countResult) => { 575 | let message = ''; 576 | message += '本轮票型:'; 577 | for (const player of this.playerList) { 578 | const targetPlayer = voteResult[player.id]; 579 | if (targetPlayer !== undefined) { 580 | message += `\n${player.displayName} → ${targetPlayer ? targetPlayer.displayName : null}`; 581 | } 582 | } 583 | message += '\n本轮票数统计:'; 584 | for (const playerId in countResult) { 585 | const player = this.getPlayer(playerId); 586 | message += `\n${player.displayName} 获得 ${countResult[playerId].length} 票,来自:` 587 | for (const index in countResult[playerId]) { 588 | message += countResult[playerId][index].displayName; 589 | if (index + 1 !== countResult[playerId].length) { 590 | message += ','; 591 | } 592 | } 593 | } 594 | return await this.sendGroup(message); 595 | }, 596 | } 597 | } 598 | } 599 | 600 | module.exports = Game; -------------------------------------------------------------------------------- /src/game/index.js: -------------------------------------------------------------------------------- 1 | const colors = require('colors/safe'); 2 | 3 | const config = require('../../config'); 4 | 5 | const Game = require('./core'); 6 | 7 | module.exports = async (app) => { 8 | if (!app.test) { 9 | await new Promise((resolve) => { app.on('connect', resolve) }); 10 | } 11 | let bot = app.bots.find(bot => bot); 12 | let game = new Game(app, bot); 13 | global.app = app; 14 | global.bot = bot; 15 | global.game = game; 16 | app.game = game; 17 | 18 | if (app.test) { 19 | bot.sendGroupMsg = (message) => { }; 20 | bot.sendPrivateMsg = (message) => { }; 21 | } 22 | 23 | app.on('message', async (session) => { 24 | const { message, messageType, sender } = session; 25 | 26 | if (messageType === 'private' && !game.getPlayer(session.sender.userId)) { 27 | return; // 不是游戏中玩家发送的消息 28 | } 29 | if (messageType === 'group' && session.groupId !== config.group) { 30 | return; // 不在目标群聊中发送的消息 31 | } 32 | 33 | const player = game.getPlayer(sender.userId); 34 | 35 | if (messageType === 'group' && !player) { 36 | if (message === 'register') { 37 | game.register(sender.userId); 38 | return; 39 | } else if (message === 'unregister') { 40 | game.unregister(sender.userId); 41 | return; 42 | } 43 | } 44 | 45 | if (messageType === 'private' && player) { 46 | player.receive(message); 47 | return; 48 | } 49 | 50 | if (messageType === 'group' && player) { 51 | player.receiveGroup(message); 52 | return; 53 | } 54 | }); 55 | 56 | }; -------------------------------------------------------------------------------- /src/game/logger.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const colors = require('colors/safe'); 3 | 4 | class Logger { 5 | 6 | push() { 7 | this.log.push(Array.from(arguments).join(' ')); 8 | } 9 | 10 | get() { 11 | return this.log.join('\n'); 12 | } 13 | 14 | set(messageList) { 15 | this.log = messageList; 16 | } 17 | 18 | reset() { 19 | this.log = []; 20 | } 21 | 22 | equal(target) { 23 | return this.get() === target; 24 | } 25 | 26 | check(target) { 27 | console.log(colors.brightGreen(this.get())); 28 | assert.strictEqual(this.get(), target); 29 | console.log(colors.green('=>', colors.bgBrightBlue('pass'))); 30 | } 31 | 32 | constructor() { 33 | this.log = []; 34 | } 35 | }; 36 | 37 | module.exports = Logger; -------------------------------------------------------------------------------- /src/game/player.js: -------------------------------------------------------------------------------- 1 | const colors = require('colors/safe'); 2 | 3 | const config = require('../../config'); 4 | 5 | function parseCommand(message) { 6 | const spaceIndex = message.indexOf(' '); 7 | return { 8 | command: ~spaceIndex ? message.slice(0, spaceIndex) : message, 9 | targetPlayer: ~spaceIndex ? game.getPlayer(message.slice(spaceIndex + 1)) : null, 10 | fit: spaceIndex === -1 11 | }; 12 | } 13 | 14 | class Player { 15 | 16 | send(message) { 17 | console.log(colors.cyan('[SEND P]'), this.id, message.slice(0, 40).replace(/\n/g, colors.grey('\\n')), message.length > 40 ? colors.grey('...') : ''); 18 | this.game.bot.sendPrivateMsg(this.id, message); 19 | } 20 | 21 | receive(message) { 22 | console.log(colors.magenta('[RECEIVE P]'), this.displayName, message); 23 | if (this.promise.private && this.promise.private.data.possibleMessages.includes(message)) { 24 | this.promise.private.resolve(message); 25 | this.promise.private = null; 26 | return; 27 | } 28 | const { command, targetPlayer, fit } = parseCommand(message); 29 | if (this.game.voter.promise) { 30 | if (command === 'vote' && targetPlayer) { 31 | return this.game.voter.vote(this, targetPlayer); 32 | } else if (command === 'pass' && fit) { 33 | return this.game.voter.pass(this); 34 | } 35 | } 36 | if (this.role && this.roleClass.commands.includes(command)) { 37 | if (fit) { 38 | return this.roleClass[command](this); 39 | } else { 40 | return this.roleClass[command](this, targetPlayer); 41 | } 42 | } 43 | if (this.role && this.roleClass.isWolf() && message.startsWith('# ')) { 44 | return this.roleClass.chat(this, message.slice(2)); 45 | } 46 | } 47 | 48 | receiveGroup(message) { 49 | console.log(colors.magenta('[RECEIVE G]'), this.displayName, message); 50 | if (this.promise.group && this.promise.group.data.possibleMessages.includes(message)) { 51 | this.promise.group.resolve(message); 52 | this.promise.group = null; 53 | return; 54 | } 55 | if (message === 'status') { 56 | return this.game.status(); 57 | } 58 | if (message === 'start game') { 59 | return this.game.start(); 60 | } 61 | if (message === 'stop game') { 62 | return this.game.stop(); 63 | } 64 | if (message === 'log') { 65 | return this.game.log(); 66 | } 67 | } 68 | 69 | async _waitForReceive(type, possibleMessages) { 70 | return new Promise((resolve, reject) => { 71 | this.promise[type] = { 72 | resolve, 73 | reject, 74 | data: { possibleMessages }, 75 | }; 76 | }); 77 | } 78 | 79 | async _cancelWait(type) { 80 | if (this.promise[type]) { 81 | this.promise[type] = null; 82 | } 83 | } 84 | 85 | async waitForReceive(possibleMessages) { return this._waitForReceive('private', possibleMessages); } 86 | async waitForReceiveGroup(possibleMessages) { return this._waitForReceive('group', possibleMessages); } 87 | cancelWait() { return this._cancelWait('private'); } 88 | cancelWaitGroup() { return this._cancelWait('group'); } 89 | 90 | setRole(role) { 91 | this.role = role; 92 | this.roleClass = this.game.roles[this.role] || null; 93 | } 94 | 95 | setNick(nick) { 96 | this.hasNick = true; 97 | this.nick = nick; 98 | this.displayName = nick; 99 | } 100 | 101 | setPlace(place) { 102 | this.place = parseInt(place); 103 | if (this.hasNick) { 104 | this.displayName = `[${place}]${this.nick}`; 105 | } else { 106 | this.displayName = `[${place}](no nick)`; 107 | } 108 | } 109 | 110 | constructor(id, game) { 111 | this.id = id; 112 | this.game = game; 113 | 114 | this.alive = true; 115 | this.op = !!(this.game.config.op.includes(this.id)); 116 | 117 | this.nick = `nick<${id}>`; 118 | this.hasNick = false; 119 | this.displayName = `${id}`; 120 | 121 | this.role = null; 122 | this.roleClass = null; 123 | this.place = null; 124 | 125 | for (const currentId in config.nicks) { 126 | if (currentId == id) { 127 | this.setNick(config.nicks[currentId]); 128 | break; 129 | } 130 | } 131 | 132 | this.promise = { 133 | private: null, 134 | group: null, 135 | }; 136 | } 137 | } 138 | 139 | module.exports = Player; -------------------------------------------------------------------------------- /src/game/role.js: -------------------------------------------------------------------------------- 1 | const colors = require('colors/safe'); 2 | const sleep = require('sleep-promise'); 3 | const { Random } = require('koishi-utils'); 4 | 5 | const utils = require('./utils'); 6 | 7 | class Role { 8 | log() { 9 | console.log(colors.brightBlue('[ROLE]'), colors.blue(this.name), ...arguments); 10 | } 11 | 12 | addPlayer(player) { 13 | this.log('add', player.displayName); 14 | this.playerList.push(player); 15 | } 16 | 17 | removePlayer(player) { 18 | let index = -1; 19 | for (const i in this.playerList) { 20 | const currentPlayer = this.playerList[i]; 21 | if (currentPlayer.id == player.id) { 22 | index = i; 23 | break; 24 | } 25 | } 26 | 27 | if (index !== -1) { 28 | this.playerList.splice(index, 1); 29 | } else { 30 | console.error('ERROR! No such player to remove.'); 31 | } 32 | } 33 | 34 | resetPlayer() { 35 | while (this.playerList.length) { 36 | this.playerList.pop(); 37 | } 38 | } 39 | 40 | send(message) { 41 | for (const currentPlayer of this.playerList) { 42 | currentPlayer.send(message); 43 | } 44 | } 45 | 46 | isActive() { 47 | return this.playerList.length !== 0; 48 | } 49 | 50 | isAlive() { 51 | for (const currentPlayer of this.playerList) { 52 | if (currentPlayer.alive) { 53 | return true; 54 | } 55 | } 56 | return false; 57 | } 58 | 59 | processNight(roundId) { 60 | this.roundId = roundId; 61 | this.roundType = 'night'; 62 | console.warn('WARN! Function `processNight` undefined.'); 63 | } 64 | 65 | async help(player) { 66 | if (!this.helpMessage || !this.helpMessage.length) { 67 | player.send('当前角色暂时没有帮助信息'); 68 | return; 69 | } 70 | 71 | await player.send(this.helpMessage.join('\n')); 72 | } 73 | 74 | getName() { 75 | return this.name || this.displayName.replace(/\[CQ.+?\]/g, ''); 76 | } 77 | 78 | getDisplayName() { 79 | return this.displayName || this.name; 80 | } 81 | 82 | isWolf() { 83 | return this.name === 'werewolf'; 84 | } 85 | 86 | async setTimeLimit(timeLimit, resolver) { 87 | if (!timeLimit || isNaN(parseInt(timeLimit))) { 88 | return; 89 | } 90 | timeLimit = parseInt(timeLimit) * 1000; 91 | 92 | const myKey = Random.int(1, 1145141919810); 93 | this.timeLimitKey = myKey; 94 | 95 | const warnTimeInterval = [15 * 1000, 5 * 1000, 0]; 96 | for (const warnTime of warnTimeInterval) { 97 | if (timeLimit > warnTime) { 98 | await sleep(timeLimit - warnTime); 99 | 100 | if (this.timeLimitKey === myKey) { 101 | timeLimit = warnTime; 102 | if (warnTime) { 103 | this.send(`你还有 ${warnTime / 1000} 秒的决策时间,超时将按照 pass 进行结算`); 104 | } else { 105 | await sleep(150); 106 | this.send('决策超时,自动结算'); 107 | resolver(); 108 | this.endTurn(); 109 | } 110 | } else { 111 | return; 112 | } 113 | } 114 | } 115 | } 116 | 117 | endTurn() { 118 | this.roundId = null; 119 | this.roundType = null; 120 | 121 | this.promise = null; 122 | 123 | this.dayResolver = undefined; 124 | this.skillResolver = undefined; 125 | this.nightResolver = undefined; 126 | this.killedResolver = undefined; 127 | 128 | this.timeLimitKey = null; 129 | } 130 | 131 | async onGameStart() { } 132 | async onGameStop() { } 133 | 134 | constructor(game) { 135 | this.game = game; 136 | this.logger = this.game.logger; 137 | this.sendGroup = (message) => this.game.sendGroup(message); 138 | this.sendPlayer = (message) => this.game.sendPlayer(message); 139 | 140 | this.roundId = null; 141 | this.roundType = null; 142 | 143 | this.playerList = []; 144 | this.helpMessage = []; 145 | 146 | this.commands = ['help']; 147 | } 148 | } 149 | 150 | module.exports = Role; -------------------------------------------------------------------------------- /src/game/roles/hunter.js: -------------------------------------------------------------------------------- 1 | const Role = require('../role'); 2 | const config = require('../../../config'); 3 | 4 | class Hunter extends Role { 5 | shoot(player, targetPlayer) { 6 | if (!targetPlayer || !targetPlayer.alive || !this.killedResolver) { 7 | this.send('shoot 命令不合法'); 8 | return; 9 | } 10 | 11 | this.log('Shoot ', targetPlayer.displayName); 12 | this.logger.push('hunter:shoot', player.place, targetPlayer.place); 13 | 14 | this.sendGroup(`${player.displayName} 翻枪带走了 ${targetPlayer.displayName}`); 15 | this.shotPlayer = targetPlayer; 16 | 17 | this.killedResolver(); 18 | this.endTurn(); 19 | } 20 | 21 | pass(player) { 22 | if (!this.killedResolver) { 23 | this.send('pass 命令不合法'); 24 | return; 25 | } 26 | 27 | this.log('Pass'); 28 | this.logger.push('hunter:pass', player.place); 29 | 30 | this.killedResolver(); 31 | this.endTurn(); 32 | } 33 | 34 | processKilled(roundId, roundType) { 35 | this.roundId = roundId; 36 | this.roundType = roundType; 37 | 38 | this.shotPlayer = null; 39 | 40 | return new Promise((resolve) => { 41 | if (!this.isActive()) { 42 | resolve(); 43 | return; 44 | } 45 | 46 | this.killedResolver = resolve; 47 | this.setTimeLimit(config.query('timeLimit.skill.killed.hunter'), this.killedResolver); 48 | 49 | this.sendGroup(`${this.playerList[0].displayName} 出局,可以发动技能`); 50 | this.send(`你可以发动技能带走一个玩家`); 51 | }); 52 | } 53 | 54 | constructor(game) { 55 | super(game); 56 | 57 | this.name = 'hunter'; 58 | this.displayName = '猎人'; 59 | this.commands = this.commands.concat(['shoot']); 60 | 61 | this.helpMessage = [ 62 | 'shoot :开枪带走 ', 63 | '注意:你的技能只能在出局时使用,且如果被女巫毒死时不能发动技能', 64 | ]; 65 | } 66 | } 67 | 68 | module.exports = Hunter; -------------------------------------------------------------------------------- /src/game/roles/seer.js: -------------------------------------------------------------------------------- 1 | const config = require('../../../config'); 2 | const Role = require('../role'); 3 | 4 | class Seer extends Role { 5 | suspect(player, targetPlayer) { 6 | if (!player.alive || !targetPlayer || !this.nightResolver) { 7 | this.send('suspect 命令不合法'); 8 | return; 9 | } 10 | 11 | let response; 12 | if (targetPlayer.roleClass.isWolf()) { 13 | response = true; 14 | } else { 15 | response = false; 16 | } 17 | this.send(`${targetPlayer.displayName} 是${response ? '坏' : '好'}人`); 18 | 19 | this.log('Suspect', targetPlayer.displayName); 20 | this.logger.push('seer:suspect', player.place, targetPlayer.place, response ? 'bad' : 'good'); 21 | 22 | this.suspectedPlayer = targetPlayer; 23 | 24 | this.nightResolver(); 25 | this.endTurn(); 26 | } 27 | 28 | pass() { 29 | if (!this.nightResolver) { 30 | this.send('pass 命令不合法'); 31 | return; 32 | } 33 | this.send('你结束了你的回合'); 34 | 35 | this.log('Pass'); 36 | this.logger.push('seer:pass', player.place); 37 | 38 | this.nightResolver(); 39 | this.endTurn(); 40 | } 41 | 42 | processNight(roundId) { 43 | this.roundId = roundId; 44 | this.roundType = 'night'; 45 | 46 | this.suspectedPlayer = null; 47 | 48 | return new Promise((resolve) => { 49 | if (!this.isActive()) { 50 | resolve(); 51 | return; 52 | } 53 | 54 | this.nightResolver = resolve; 55 | this.setTimeLimit(config.query('timeLimit.skill.night.seer'), this.nightResolver); 56 | 57 | this.sendGroup('预言家正在决策中...'); 58 | this.send(`现在是第 ${roundId} 个晚上`); 59 | }); 60 | } 61 | 62 | constructor(game) { 63 | super(game); 64 | 65 | this.name = 'seer'; 66 | this.displayName = '预言家'; 67 | this.commands = this.commands.concat(['suspect', 'pass']); 68 | 69 | this.helpMessage = [ 70 | 'suspect :查验 是好人还是坏人', 71 | 'pass:跳过查验', 72 | '注意:无论是否存活,都需要用 pass 命令你的操作回合', 73 | ]; 74 | } 75 | } 76 | 77 | module.exports = Seer; -------------------------------------------------------------------------------- /src/game/roles/villager.js: -------------------------------------------------------------------------------- 1 | const Role = require('../role'); 2 | 3 | class Villager extends Role { 4 | constructor(game) { 5 | super(game); 6 | 7 | this.name = 'villager'; 8 | this.displayName = '村民'; 9 | } 10 | } 11 | 12 | module.exports = Villager; -------------------------------------------------------------------------------- /src/game/roles/werewolf.js: -------------------------------------------------------------------------------- 1 | const Role = require('../role'); 2 | const utils = require('../utils'); 3 | const config = require('../../../config'); 4 | 5 | class Werewolf extends Role { 6 | async onGameStart() { 7 | if (!this.isActive()) { 8 | return; 9 | } 10 | 11 | let message = '本局游戏中的狼有:'; 12 | for (const player of this.playerList) { 13 | message += '\n' + player.displayName; 14 | } 15 | await this.send(message); 16 | } 17 | 18 | chat(player, message) { 19 | if (!player || !player.alive || !this.roundId || this.roundType !== 'night' || !this.nightResolver) { 20 | return player.send('chat 命令不合法'); 21 | } 22 | 23 | this.log('Team Chat', player.displayName, message); 24 | for (const currentPlayer of this.playerList) { 25 | if (player.id != currentPlayer.id && currentPlayer.alive) { 26 | currentPlayer.send(`(${player.displayName}) ${utils.encodeMessage(message)}`); 27 | } 28 | } 29 | } 30 | 31 | kill(player, targetPlayer) { 32 | if (!player || !player.alive || !targetPlayer || !targetPlayer.alive || !this.nightResolver) { 33 | return player.send('kill 命令不合法'); 34 | } 35 | 36 | for (const currentPlayer of this.playerList) { 37 | currentPlayer.send(`${player.displayName} 决定杀害 ${targetPlayer.displayName}`); 38 | } 39 | this.killedPlayer = targetPlayer; 40 | 41 | this.log('Kill', targetPlayer.displayName, '(by ' + player.displayName + ')'); 42 | this.logger.push('werewolf:kill', player.place, targetPlayer.place); 43 | 44 | this.nightResolver(); 45 | this.endTurn(); 46 | } 47 | 48 | pass(player) { 49 | if (!player || !player.alive || !this.nightResolver) { 50 | return player.send('pass 命令不合法'); 51 | } 52 | 53 | for (const currentPlayer of this.playerList) { 54 | currentPlayer.send(`${player.displayName} 决定跳过本回合`); 55 | } 56 | 57 | this.log('pass', '(by ' + player.displayName + ')'); 58 | this.logger.push('werewolf:pass', player.place); 59 | 60 | this.nightResolver(); 61 | this.endTurn(); 62 | } 63 | 64 | async boom(player) { 65 | if (!player || !player.alive || !this.game.speech.promise) { 66 | return player.send('boom 命令不合法'); 67 | } 68 | 69 | this.log('boom', player.displayName); 70 | this.logger.push('werewolf:boom', player.place); 71 | 72 | player.alive = false; 73 | await this.game.processKilled(player); 74 | 75 | await this.sendGroup(`${player.displayName} 自爆`); 76 | await this.game.speech.stop(player); 77 | } 78 | 79 | processNight(roundId) { 80 | this.roundId = roundId; 81 | this.roundType = 'night'; 82 | 83 | this.killedPlayer = null; 84 | 85 | return new Promise((resolve) => { 86 | if (!this.isActive()) { 87 | resolve(); 88 | return; 89 | } 90 | 91 | this.nightResolver = resolve; 92 | this.setTimeLimit(config.query('timeLimit.skill.night.werewolf'), this.nightResolver); 93 | 94 | this.sendGroup('狼人正在决策中...'); 95 | this.send(`现在是第 ${roundId} 个晚上!请狼人决定今晚要杀的人`); 96 | }); 97 | } 98 | 99 | constructor(game) { 100 | super(game); 101 | 102 | this.name = 'werewolf'; 103 | this.displayName = '狼人'; 104 | this.commands = this.commands.concat(['boom', 'kill', 'pass']); 105 | 106 | this.helpMessage = [ 107 | '# 或 chat :可以进行队内交流', 108 | 'kill :决定今晚刀的人', 109 | 'pass:跳过今晚刀人回合', 110 | 'boom:自爆,需在发言回合使用,自身出局且游戏直接进入黑夜', 111 | '注意:使用 kill 或 pass 命令后,操作回合立刻结束;操作回合结束后狼人没有内部交流权限。' 112 | ]; 113 | } 114 | } 115 | 116 | module.exports = Werewolf; -------------------------------------------------------------------------------- /src/game/roles/witch.js: -------------------------------------------------------------------------------- 1 | const Role = require('../role'); 2 | const config = require('../../../config'); 3 | 4 | class Witch extends Role { 5 | poison(player, targetPlayer) { 6 | if (!player.alive || !targetPlayer || !targetPlayer.alive || !this.roundId || this.roundType !== 'night' || !this.nightResolver) { 7 | this.send('posion 命令不合法'); 8 | return; 9 | } 10 | 11 | if (this.poisoned) { 12 | this.send('你已经使用过毒药了'); 13 | return; 14 | } 15 | 16 | this.send(`你用毒药杀了 ${targetPlayer.displayName} 并结束了你的操作回合`); 17 | this.poisonedPlayer = targetPlayer; 18 | this.poisoned = true; 19 | 20 | this.log('Poison', targetPlayer.displayName); 21 | this.logger.push('witch:poison', player.place, targetPlayer.place); 22 | 23 | this.nightResolver(); 24 | this.endTurn(); 25 | } 26 | 27 | save(player, targetPlayer) { 28 | if (!player.alive || !targetPlayer || !targetPlayer.alive || !this.roundId || this.roundType !== 'night' || !this.nightResolver) { 29 | this.send('save 命令不合法'); 30 | return; 31 | } 32 | 33 | if (this.saved) { 34 | this.send('你已经使用过解药了'); 35 | return; 36 | } 37 | 38 | if (targetPlayer.id !== this.game.roles.werewolf.killedPlayer.id) { 39 | this.send('你只能对今晚死亡的人使用解药'); 40 | return; 41 | } 42 | 43 | if (targetPlayer.id === this.playerList[0].id && !(this.rules.saveHerself || (this.rules.saveHerselfAtFirstNight && this.roundId === 1))) { 44 | this.send('你不能对自己使用解药'); 45 | return; 46 | } 47 | 48 | this.send(`你用解药救了 ${targetPlayer.displayName} 并结束了你的操作回合`); 49 | this.savedPlayer = targetPlayer; 50 | this.saved = true; 51 | 52 | this.log('Save', targetPlayer.displayName); 53 | this.logger.push('witch:save', player.place, targetPlayer.place); 54 | 55 | this.nightResolver(); 56 | this.endTurn(); 57 | } 58 | 59 | pass(player) { 60 | if (!this.roundId || this.roundType !== 'night' || !this.nightResolver) { 61 | this.send('pass 命令不合法'); 62 | return; 63 | } 64 | 65 | this.send('你结束了你的操作回合'); 66 | 67 | this.log('Pass'); 68 | this.logger.push('witch:pass', player.place); 69 | 70 | this.nightResolver(); 71 | this.endTurn(); 72 | } 73 | 74 | processNight(roundId) { 75 | this.roundId = roundId; 76 | this.roundType = 'night'; 77 | 78 | this.savedPlayer = null; 79 | this.poisonedPlayer = null; 80 | 81 | return new Promise((resolve) => { 82 | if (!this.isActive()) { 83 | resolve(); 84 | return; 85 | } 86 | 87 | this.nightResolver = resolve; 88 | this.setTimeLimit(config.query('timeLimit.skill.night.witch'), this.nightResolver); 89 | 90 | this.sendGroup('女巫正在决策中...'); 91 | if (!this.saved) { 92 | if (this.game.roles.werewolf.killedPlayer) { 93 | this.send(`现在是第 ${roundId} 个晚上!今天晚上 ${this.game.roles.werewolf.killedPlayer.displayName} 死了`); 94 | } else { 95 | this.send(`现在是第 ${roundId} 个晚上!没有玩家被狼人杀害`); 96 | } 97 | } else { 98 | this.send(`现在是第 ${roundId} 个晚上`); 99 | } 100 | }); 101 | } 102 | 103 | constructor(game) { 104 | super(game); 105 | 106 | this.name = 'witch'; 107 | this.displayName = '女巫'; 108 | this.commands = this.commands.concat(['save', 'poison', 'pass']); 109 | 110 | this.saved = false; 111 | this.poisoned = false; 112 | 113 | this.rules = { 114 | saveHerself: config.query('rule.witch.saveHerself', false), 115 | saveHerselfAtFirstNight: config.query('rule.witch.saveHerselfAtFirstNight', false), 116 | }; 117 | this.log('(rules)', this.rules); 118 | 119 | this.helpMessage = [ 120 | 'poison :对 使用毒药', 121 | 'save : 对 使用解药', 122 | 'pass:结束当前回合', 123 | '注意:你的毒药和解药各只有一瓶,且每个操作回合至多使用其中一瓶;当你使用过解药后,你将不会看到每晚的死亡报告', 124 | ]; 125 | } 126 | } 127 | 128 | module.exports = Witch; -------------------------------------------------------------------------------- /src/game/sheriff.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const lodash = require('lodash'); 3 | 4 | const Voter = require('./voter'); 5 | const utils = require('./utils'); 6 | 7 | class Sheriff { 8 | 9 | exists() { 10 | return !!(this.sheriff && this.sheriff.alive); 11 | } 12 | 13 | get() { 14 | return this.exists() ? this.sheriff : null; 15 | } 16 | 17 | generateSpeechOrder(playerList) { 18 | const startIndex = utils.random.int(0, playerList.length); 19 | const order = playerList.slice(startIndex, playerList.length).concat(playerList.slice(0, startIndex)); 20 | return order; 21 | } 22 | 23 | async runForTheSheriff() { 24 | await this.game.sendGroup('现在进行警长竞选,上警的玩家请举手'); 25 | 26 | const alivePlayerList = this.game.getAlivePlayerList(); 27 | const receivedMessage = await Promise.all(alivePlayerList.map(player => player.waitForReceive(['pass', 'raise']))); 28 | const registeredPlayerList = lodash.filter(alivePlayerList, (_, index) => receivedMessage[index] === 'raise'); 29 | const unregisteredPlayerList = lodash.filter(alivePlayerList, (_, index) => receivedMessage[index] === 'pass'); 30 | 31 | if (!await this.speech.process(this.generateSpeechOrder(registeredPlayerList))) { 32 | if (this.crashed) { 33 | await this.game.sendGroup('由于狼队的两连爆,本轮游戏没有警长'); 34 | } 35 | this.crashed = true; 36 | return false; 37 | } 38 | 39 | const votablePlayers = unregisteredPlayerList.map(player => player.id); 40 | const targetPlayers = registeredPlayerList.map(player => player.id); 41 | 42 | let voteResult = await this.voter.process(votablePlayers, targetPlayers); 43 | if (voteResult.length !== 1) { 44 | if (!await this.speech.process(this.generateSpeechOrder(voteResult))) { 45 | if (this.crashed) { 46 | await this.game.sendGroup('由于狼队的两连爆,本轮游戏没有警长'); 47 | } 48 | this.crashed = true; 49 | return false; 50 | } else { 51 | voteResult = await this.voter.process(); 52 | } 53 | } 54 | 55 | if (!voteResult || voteResult.length !== 1) { 56 | await this.game.sendGroup('由于村民们的意见难以统一,本轮游戏没有警长'); 57 | return true; 58 | } 59 | this.sheriff = voteResult[0]; 60 | await this.game.sendGroup(`本轮游戏的警长是 [CQ:at,qq=${this.sheriff.id}]`); 61 | return true; 62 | } 63 | 64 | reset() { 65 | this.sheriff = null; 66 | this.crashed = false; 67 | } 68 | 69 | constructor(game) { 70 | this.game = game; 71 | this.voter = this.game.voter; 72 | this.speech = this.game.speech; 73 | assert(this.game && this.voter && this.speech); 74 | 75 | this.reset(); 76 | } 77 | } 78 | 79 | module.exports = Sheriff; -------------------------------------------------------------------------------- /src/game/speech.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | class Speech { 4 | 5 | async process(speechOrder) { 6 | this.game.logger.push('speech', speechOrder.map(player => player.place).join(',')); 7 | return new Promise(async (resolve, reject) => { 8 | this.promise = { resolve, reject }; 9 | await this.game.sendGroup( 10 | '本轮发言顺序:\n' + 11 | speechOrder.map((player, index) => (String.fromCharCode('a'.charCodeAt(0) + index) + '. ' + player.displayName)).join('\n') 12 | ); 13 | for (const currentPlayer of speechOrder) { 14 | this.currentPlayer = currentPlayer; 15 | await this.game.sendGroup(`请 [CQ:at,qq=${currentPlayer.id}] 发言`); 16 | await currentPlayer.waitForReceiveGroup(['pass']); 17 | if (!this.promise) { 18 | return; 19 | } 20 | } 21 | this.currentPlayer = null; 22 | this.promise.resolve(true); 23 | }); 24 | } 25 | 26 | async stop(player) { 27 | if (!this.promise) { 28 | return; 29 | } 30 | if (this.currentPlayer) { 31 | this.currentPlayer.cancelWaitGroup(); 32 | this.currentPlayer = null; 33 | } 34 | await this.game.sendGroup(`本轮发言中断,直接进入黑夜`); 35 | this.promise.resolve(false); 36 | } 37 | 38 | reset() { 39 | this.promise = null; 40 | this.currentPlayer = null; 41 | } 42 | 43 | constructor(game) { 44 | this.game = game; 45 | assert(this.game); 46 | 47 | this.reset(); 48 | } 49 | } 50 | 51 | module.exports = Speech; -------------------------------------------------------------------------------- /src/game/utils.js: -------------------------------------------------------------------------------- 1 | const lodash = require('lodash'); 2 | 3 | const config = require('../../config'); 4 | 5 | const utils = { 6 | random: { 7 | int(start, end) { 8 | if (app.test) { 9 | return start; 10 | } 11 | return Math.floor(Math.random() * (end - start)) + start; 12 | }, 13 | 14 | choose(array) { 15 | if (app.start) { 16 | return array[0]; 17 | } 18 | return array[utils.random.int(0, array.length)]; 19 | }, 20 | 21 | shuffle(array) { 22 | if (app.test) { 23 | return; 24 | } 25 | array = lodash.shuffle(array); 26 | }, 27 | 28 | key() { 29 | const length = 16; 30 | const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-='; 31 | let res = ''; 32 | for (let i = 0; i < length; i++){ 33 | res += chars[Math.floor(Math.random() * chars.length)]; 34 | } 35 | return res; 36 | } 37 | }, 38 | 39 | decodeMessage(message) { 40 | return message.replace(/[/gm, '[').replace(/]/gm, ']').replace(/&/gm, '&'); 41 | }, 42 | 43 | encodeMessage(message) { 44 | return message.replace(/&/gm, '&').replace(/\[/gm, '[').replace(/\]/gm, ']'); 45 | }, 46 | 47 | timeLimit: { 48 | message(timeLimit, format = '(时间限制:<1>)') { 49 | if (isNaN(Number(timeLimit))) { 50 | timeLimit = config.query('timeLimit.' + timeLimit, -1); 51 | } 52 | if (timeLimit == -1) { 53 | return ''; 54 | } else { 55 | return format.replace('<1>', timeLimit); 56 | } 57 | } 58 | } 59 | } 60 | 61 | module.exports = utils; -------------------------------------------------------------------------------- /src/game/voter.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | class Voter { 4 | 5 | log() { 6 | console.log('[VOTE]', ...arguments); 7 | } 8 | 9 | countResult() { 10 | return Object.keys(this.result).length 11 | } 12 | 13 | countVotablePlayer() { 14 | return this.votablePlayers.length; 15 | } 16 | 17 | isEnd() { 18 | if (this.countVotablePlayer() === this.countResult()) { 19 | return true; 20 | } else { 21 | return false; 22 | } 23 | } 24 | 25 | vote(player, targetPlayer) { 26 | if (!this.promise) { 27 | player.send('投票未开始'); 28 | return; 29 | } 30 | if (!this.votablePlayers.includes(player.id)) { 31 | player.send('你没有投票权限'); 32 | return; 33 | } 34 | if (!targetPlayer || !this.targetPlayers.includes(targetPlayer.id)) { 35 | player.send('投票不合法'); 36 | return; 37 | } 38 | 39 | if (Object.keys(this.result).includes(String(player.id))) { 40 | player.send('你已经投票 / 弃权过了'); 41 | return; 42 | } 43 | 44 | this.result[String(player.id)] = targetPlayer; 45 | 46 | this.log('Vote', player.displayName, 'To', targetPlayer.displayName); 47 | player.send(`你投票给了 ${targetPlayer.displayName}`); 48 | this.game.sendGroup(`${player.displayName} 完成投票,当前投票情况 ${this.countResult()} / ${this.countVotablePlayer()}`); 49 | 50 | if (this.isEnd()) { 51 | this.end(); 52 | } 53 | } 54 | 55 | pass(player) { 56 | if (!this.promise) { 57 | player.send('投票未开始'); 58 | return; 59 | } 60 | if (!this.votablePlayers.includes(player.id)) { 61 | player.send('你没有投票权限'); 62 | return; 63 | } 64 | 65 | if (Object.keys(this.result).includes(String(player.id))) { 66 | player.send('你已经投票 / 弃权过了'); 67 | return; 68 | } 69 | 70 | this.result[String(player.id)] = null; 71 | 72 | this.log('Pass', player.displayName); 73 | player.send('你放弃了你的投票权'); 74 | this.game.sendGroup(`${player.displayName} 完成投票,当前投票情况 ${this.countResult()} / ${this.countVotablePlayer()}`); 75 | 76 | if (this.isEnd()) { 77 | this.end(); 78 | } 79 | } 80 | 81 | process(votablePlayers = null, targetPlayers = null) { 82 | if (this.promise) { 83 | console.error('ERROR! A vote is already started!'); 84 | return; 85 | } 86 | 87 | this.votablePlayers = votablePlayers || this.game.playerList; 88 | this.targetPlayers = targetPlayers || this.game.playerList; 89 | 90 | return new Promise((resolve, reject) => { 91 | this.promise = { resolve, reject }; 92 | this.result = {}; 93 | if (this.isEnd()) { 94 | this.end(); 95 | } 96 | }); 97 | } 98 | 99 | async end() { 100 | const sheriffId = this.game.sheriff.exists() ? String(this.game.sheriff.get().id) : null; 101 | let voteCounter = {}; 102 | let countResult = []; 103 | for (const playerId in this.result) { 104 | const targetPlayer = this.result[playerId], weight = playerId === sheriffId ? 1.5 : 1; 105 | if (targetPlayer) { 106 | if (voteCounter[targetPlayer.id]) { 107 | voteCounter[targetPlayer.id] += weight; 108 | countResult[targetPlayer.id].push(this.game.getPlayer(playerId)); 109 | } else { 110 | voteCounter[targetPlayer.id] = weight; 111 | countResult[targetPlayer.id] = [this.game.getPlayer(playerId)]; 112 | } 113 | } 114 | } 115 | this.log('End', voteCounter); 116 | 117 | let response = []; 118 | let maxVoteNumber = -1; 119 | for (const targetPlayerId in voteCounter) { 120 | let voteNumber = voteCounter[targetPlayerId]; 121 | this.log('>', targetPlayerId, voteNumber); 122 | if (voteNumber > maxVoteNumber) { 123 | maxVoteNumber = voteNumber; 124 | response = [this.game.getPlayer(targetPlayerId)]; 125 | } else if (voteNumber == maxVoteNumber) { 126 | response.push(this.game.getPlayer(targetPlayerId)); 127 | } 128 | } 129 | this.log('Result', response.map(player => player.displayName), maxVoteNumber); 130 | 131 | await this.game.helper.listVotes(this.result, countResult); 132 | 133 | this.promise.resolve(response); 134 | this.promise = null; 135 | } 136 | 137 | async stop() { 138 | if (this.promise) { 139 | this.promise.resolve(); 140 | this.promise = null; 141 | } 142 | } 143 | 144 | reset() { 145 | this.promise = null; 146 | } 147 | 148 | constructor(game) { 149 | this.game = game; 150 | assert(this.game); 151 | this.votablePlayers = []; 152 | this.targetPlayers = []; 153 | this.reset(); 154 | } 155 | } 156 | 157 | module.exports = Voter; 158 | -------------------------------------------------------------------------------- /tests/app.js: -------------------------------------------------------------------------------- 1 | const { MockedApp } = require('koishi-test-utils'); 2 | 3 | class TesterApp extends MockedApp { 4 | constructor() { 5 | super(); 6 | this.test = true; 7 | this.plugin(require('../src/game/index')); 8 | } 9 | } 10 | 11 | process.on('unhandledRejection', error => { 12 | console.error(error.message); 13 | process.exit(1); 14 | }); 15 | 16 | module.exports = TesterApp; -------------------------------------------------------------------------------- /tests/game/roles.js: -------------------------------------------------------------------------------- 1 | const App = require('../app'); 2 | const utils = require('../utils'); 3 | const config = require('../../config'); 4 | 5 | (async () => { 6 | const app = new App(); 7 | const interval = 50; 8 | const logger = global.game.logger; 9 | const setTemplate = function () { 10 | return global.game.setTemplate(Array.from(arguments)); 11 | } 12 | 13 | const { p, g } = utils.generateSession(app, config.group, [ 14 | 1000000001, 15 | 1000000002, 16 | 1000000003, 17 | 1000000004, 18 | 1000000005, 19 | 1000000006, 20 | ]); 21 | 22 | // 狼 23 | setTemplate('werewolf', 'villager', 'villager', 'villager'); 24 | await utils.receiveByInterval(interval, [ 25 | [g[0], 'register'], 26 | [g[1], 'register'], 27 | [g[2], 'register'], 28 | [g[3], 'register'], 29 | [g[0], 'start game'], 30 | [p[0], 'kill 1'], 31 | [g[0], 'stop game'], 32 | ]); 33 | logger.check('werewolf:kill 1 1'); 34 | await utils.receiveByInterval(interval, [ 35 | [g[0], 'register'], 36 | [g[1], 'register'], 37 | [g[2], 'register'], 38 | [g[3], 'register'], 39 | [g[0], 'start game'], 40 | [p[0], 'kill null'], 41 | [p[0], 'kill 2'], 42 | [g[0], 'stop game'], 43 | ]); 44 | logger.check('werewolf:kill 1 2\nspeech 3,4,1'); 45 | setTemplate('werewolf', 'werewolf', 'werewolf', 'villager'); 46 | await utils.receiveByInterval(interval, [ 47 | [g[0], 'register'], 48 | [g[1], 'register'], 49 | [g[2], 'register'], 50 | [g[3], 'register'], 51 | [g[0], 'start game'], 52 | [p[0], '# hello'], 53 | [p[1], '# hi'], 54 | [p[2], '# how are you'], 55 | [p[0], 'kill 4'], 56 | ]); 57 | logger.check('werewolf:kill 1 4'); 58 | 59 | // 女巫 60 | setTemplate('werewolf', 'witch', 'villager', 'villager', 'villager'); 61 | await utils.receiveByInterval(interval, [ 62 | [g[0], 'register'], 63 | [g[1], 'register'], 64 | [g[2], 'register'], 65 | [g[3], 'register'], 66 | [g[4], 'register'], 67 | [g[0], 'start game'], 68 | [p[0], 'kill 2'], 69 | [p[1], 'save 2'], 70 | [g[0], 'stop game'], 71 | ]); 72 | logger.check('werewolf:kill 1 2\nwitch:save 2 2\nspeech 1,2,3,4,5'); 73 | await utils.receiveByInterval(interval, [ 74 | [g[0], 'register'], 75 | [g[1], 'register'], 76 | [g[2], 'register'], 77 | [g[3], 'register'], 78 | [g[4], 'register'], 79 | [g[0], 'start game'], 80 | [p[0], 'kill 2'], 81 | [p[1], 'poison 3'], 82 | [g[0], 'stop game'], 83 | ]); 84 | logger.check('werewolf:kill 1 2\nwitch:poison 2 3\nspeech 1,4,5'); 85 | await utils.receiveByInterval(interval, [ 86 | [g[0], 'register'], 87 | [g[1], 'register'], 88 | [g[2], 'register'], 89 | [g[3], 'register'], 90 | [g[4], 'register'], 91 | [g[0], 'start game'], 92 | [p[0], 'kill 2'], 93 | [p[1], 'pass'], 94 | [g[0], 'stop game'], 95 | ]); 96 | logger.check('werewolf:kill 1 2\nwitch:pass 2\nspeech 3,4,5,1') 97 | 98 | // 预言家 99 | setTemplate('seer', 'werewolf', 'witch', 'villager'); 100 | { 101 | let target = [true, false, true, true]; 102 | for (let i = 1; i <= target.length; i++) { 103 | await utils.receiveByInterval(interval, [ 104 | [g[0], 'register'], 105 | [g[1], 'register'], 106 | [g[2], 'register'], 107 | [g[3], 'register'], 108 | [g[0], 'start game'], 109 | [p[1], 'pass'], 110 | [p[2], 'pass'], 111 | [p[0], `suspect ${i}`], 112 | [g[0], 'stop game'], 113 | ]); 114 | logger.check(`werewolf:pass 2\nwitch:pass 3\nseer:suspect 1 ${i} ${i == 2 ? "bad" : "good"}\nspeech 1,2,3,4`); 115 | } 116 | } 117 | 118 | // 猎人 119 | setTemplate('werewolf', 'hunter', 'villager', 'villager'); 120 | await utils.receiveByInterval(interval, [ 121 | [g[0], 'register'], 122 | [g[1], 'register'], 123 | [g[2], 'register'], 124 | [g[3], 'register'], 125 | [g[0], 'start game'], 126 | [p[0], 'kill 2'], 127 | [p[1], 'shoot 1'], 128 | ]); 129 | logger.check('werewolf:kill 1 2\nhunter:shoot 2 1'); 130 | await utils.receiveByInterval(interval, [ 131 | [g[0], 'register'], 132 | [g[1], 'register'], 133 | [g[2], 'register'], 134 | [g[3], 'register'], 135 | [g[0], 'start game'], 136 | [p[0], 'pass'], 137 | [g[0], 'pass'], 138 | [g[1], 'pass'], 139 | [g[2], 'pass'], 140 | [g[3], 'pass'], 141 | [p[0], 'vote 2'], 142 | [p[1], 'vote 2'], 143 | [p[2], 'vote 2'], 144 | [p[3], 'vote 2'], 145 | [p[1], 'shoot 1'], 146 | ]); 147 | logger.check('werewolf:pass 1\nspeech 1,2,3,4\nhunter:shoot 2 1'); 148 | 149 | process.exit(0); 150 | })(); -------------------------------------------------------------------------------- /tests/game/sheriff.js: -------------------------------------------------------------------------------- 1 | const App = require('../app'); 2 | const utils = require('../utils'); 3 | const config = require('../../config'); 4 | 5 | (async () => { 6 | const app = new App(); 7 | const interval = 50; 8 | const logger = global.game.logger; 9 | const setTemplate = function () { 10 | return global.game.setTemplate(Array.from(arguments)); 11 | } 12 | 13 | const { p, g } = utils.generateSession(app, config.group, [ 14 | 1000000000, 15 | 1000000001, 16 | 1000000002, 17 | 1000000003, 18 | 1000000004, 19 | 1000000005, 20 | 1000000006, 21 | 1000000007, 22 | 1000000008, 23 | ]); 24 | 25 | setTemplate( 26 | 'werewolf', 'werewolf', 'werewolf', 'witch', 'villager', 'villager', 'villager', 'villager' 27 | ); 28 | await utils.receiveByInterval(interval, [ 29 | [g[1], 'register'], 30 | [g[2], 'register'], 31 | [g[3], 'register'], 32 | [g[4], 'register'], 33 | [g[5], 'register'], 34 | [g[6], 'register'], 35 | [g[7], 'register'], 36 | [g[8], 'register'], 37 | [g[1], 'start game'], 38 | [p[1], 'kill 8'], 39 | [p[4], 'poison 2'], 40 | [p[1], 'raise'], 41 | [p[2], 'raise'], 42 | [p[3], 'pass'], 43 | [p[4], 'pass'], 44 | [p[5], 'raise'], 45 | [p[6], 'raise'], 46 | [p[7], 'pass'], 47 | [p[8], 'pass'], 48 | [g[1], 'No.3 boom, please'], 49 | [p[3], 'boom'], 50 | [p[1], 'kill 4'], 51 | [p[4], 'pass'], 52 | [p[1], 'raise'], 53 | // [p[2], 'pass'], 54 | [p[3], 'raise'], 55 | [p[4], 'pass'], 56 | [p[5], 'raise'], 57 | [p[6], 'pass'], 58 | [p[7], 'raise'], 59 | // [p[8], 'pass'], 60 | [g[1], 'pass'], 61 | [g[5], 'pass'], 62 | [g[7], 'pass'], 63 | // [p[2], 'vote 5'], 64 | [p[4], 'vote 7'], 65 | [p[6], 'vote 3'], 66 | [p[6], 'vote 6'], 67 | [p[6], 'vote 7'], 68 | // [p[8], 'vote 5'], 69 | [p[1], 'help'], 70 | [g[1], 'status'], 71 | [g[1], 'stop game'] 72 | ]); 73 | logger.check('werewolf:kill 1 8\nwitch:poison 4 2\nspeech 1,2,5,6\nwerewolf:boom 3\nwerewolf:kill 1 4\nwitch:pass 4\nspeech 1,5,7'); 74 | 75 | await utils.receiveByInterval(interval, [ 76 | [g[1], 'register'], 77 | [g[2], 'register'], 78 | [g[3], 'register'], 79 | [g[4], 'register'], 80 | [g[5], 'register'], 81 | [g[6], 'register'], 82 | [g[7], 'register'], 83 | [g[8], 'register'], 84 | [g[1], 'start game'], 85 | [p[1], 'pass'], 86 | [p[4], 'pass'], 87 | [p[1], 'raise'], 88 | [p[2], 'pass'], 89 | [p[3], 'raise'], 90 | [p[4], 'pass'], 91 | [p[5], 'raise'], 92 | [p[6], 'pass'], 93 | [p[7], 'raise'], 94 | [p[8], 'pass'], 95 | [g[1], 'pass'], 96 | [g[3], 'pass'], 97 | [g[5], 'pass'], 98 | [g[7], 'pass'], 99 | [p[2], 'vote 5'], 100 | [p[4], 'vote 5'], 101 | [p[6], 'vote 6'], 102 | [p[6], 'vote 3'], 103 | [p[6], 'vote 7'], 104 | [p[8], 'vote 5'], 105 | [p[1], 'help'], 106 | [g[1], 'status'], 107 | [g[5], 'right'], 108 | 109 | [g[5], 'pass'], 110 | [g[6], 'pass'], 111 | [g[7], 'pass'], 112 | [g[8], 'pass'], 113 | [g[1], 'pass'], 114 | [g[2], 'pass'], 115 | [g[3], 'pass'], 116 | [g[4], 'pass'], 117 | 118 | [p[1], 'vote 1'], 119 | [p[2], 'vote 1'], 120 | [p[3], 'vote 1'], 121 | [p[4], 'vote 1'], 122 | [p[5], 'vote 2'], 123 | [p[6], 'vote 2'], 124 | [p[7], 'vote 2'], 125 | [p[8], 'vote 2'] 126 | ]); 127 | logger.check('werewolf:pass 1\nwitch:pass 4\nspeech 1,3,5,7\nspeech 5,6,7,8,1,2,3,4'); 128 | })(); 129 | -------------------------------------------------------------------------------- /tests/game/vote.js: -------------------------------------------------------------------------------- 1 | const { MockedApp } = require('koishi-test-utils'); 2 | 3 | const utils = require('../utils'); 4 | const config = require('../../config'); 5 | 6 | const app = new MockedApp(); 7 | app.test = true; 8 | app.plugin(require('../../src/game/index')); 9 | 10 | try { 11 | (async () => { 12 | const interval = 50; 13 | const { p, g } = utils.generateSession(app, config.group, [ 14 | 1000000001, 15 | 1000000002, 16 | 1000000003, 17 | 1000000004, 18 | 1000000005, 19 | 1000000006, 20 | ]); 21 | 22 | global.game.setTemplate(['werewolf', 'werewolf', 'villager', 'villager', 'villager', 'villager']); 23 | await utils.receiveByInterval(interval, [ 24 | [g[0], 'register'], 25 | [g[1], 'register'], 26 | [g[2], 'register'], 27 | [g[3], 'register'], 28 | [g[4], 'register'], 29 | [g[5], 'register'], 30 | [g[0], 'start game'], 31 | [p[0], 'pass'], 32 | [p[0], 'vote 1'], 33 | [p[1], 'vote 1'], 34 | [p[2], 'vote 1'], 35 | [p[3], 'vote 2'], 36 | [p[4], 'vote 2'], 37 | [p[5], 'vote 2'], 38 | [p[0], 'vote 1'], 39 | [p[1], 'vote 1'], 40 | [p[2], 'vote 2'], 41 | [p[3], 'vote 2'], 42 | [p[4], 'vote 2'], 43 | [p[5], 'vote 2'], 44 | [g[0], 'stop game'], 45 | ]); 46 | 47 | })(); 48 | } catch (err) { 49 | console.error(err); 50 | console.log('ERROR!!!'); 51 | } -------------------------------------------------------------------------------- /tests/game/wolves.js: -------------------------------------------------------------------------------- 1 | const App = require('../app'); 2 | const utils = require('../utils'); 3 | const config = require('../../config'); 4 | 5 | (async () => { 6 | const app = new App(); 7 | const interval = 100; 8 | const logger = global.game.logger; 9 | const setTemplate = function () { 10 | return global.game.setTemplate(Array.from(arguments)); 11 | } 12 | 13 | const { p, g } = utils.generateSession(app, config.group, [ 14 | 1000000000, 15 | 1000000001, 16 | 1000000002, 17 | 1000000003, 18 | 1000000004, 19 | 1000000005, 20 | 1000000006, 21 | 1000000007, 22 | 1000000008, 23 | ]); 24 | 25 | setTemplate('werewolf', 'werewolf', 'werewolf', 'villager', 'villager', 'villager', 'villager', 'villager'); 26 | await utils.receiveByInterval(interval, [ 27 | [g[1], 'register'], 28 | [g[2], 'register'], 29 | [g[3], 'register'], 30 | [g[4], 'register'], 31 | [g[5], 'register'], 32 | [g[6], 'register'], 33 | [g[7], 'register'], 34 | [g[8], 'register'], 35 | [g[1], 'start game'], 36 | [p[1], 'kill 4'], 37 | [g[4], 'pass'], 38 | [g[5], 'pass'], 39 | [p[3], 'boom'], 40 | [p[3], 'kill 5'], 41 | [p[1], 'kill 4'], 42 | [p[1], 'kill 5'], 43 | [g[6], 'pass'], 44 | [g[7], 'pass'], 45 | [g[8], 'pass'], 46 | [g[1], 'pass'], 47 | [g[2], 'pass'], 48 | [p[1], 'vote 1'], 49 | [p[2], 'pass'], 50 | [p[3], 'pass'], 51 | [p[4], 'pass'], 52 | [p[5], 'pass'], 53 | [p[6], 'vote 6'], 54 | [p[7], 'pass'], 55 | [p[8], 'pass'], 56 | [p[2], 'boom'], 57 | [g[1], 'stop game'], 58 | ]); 59 | logger.check('werewolf:kill 1 4\nspeech 5,6,7,8,1,2,3\nwerewolf:boom 3\n' + 60 | 'werewolf:kill 1 5\nspeech 6,7,8,1,2\nspeech 1,6\nwerewolf:boom 2'); 61 | 62 | process.exit(0); 63 | })(); -------------------------------------------------------------------------------- /tests/index.js: -------------------------------------------------------------------------------- 1 | require('./game/roles'); 2 | require('./game/vote'); -------------------------------------------------------------------------------- /tests/utils.js: -------------------------------------------------------------------------------- 1 | const sleep = require('sleep-promise'); 2 | 3 | const utils = { 4 | generateSession(app, group, idList) { 5 | const playerSessions = idList.map(id => app.session(id)); 6 | const groupSessions = idList.map(id => app.session(id, group)); 7 | return { 8 | p: playerSessions, 9 | g: groupSessions, 10 | }; 11 | }, 12 | 13 | async receiveByInterval(interval, data) { 14 | for(let item of data) { 15 | const session = item[0]; 16 | const message = item[1]; 17 | await session.receive(message); 18 | await sleep(interval); 19 | } 20 | } 21 | }; 22 | 23 | module.exports = utils; --------------------------------------------------------------------------------