├── .gitignore ├── LICENSE ├── README.md ├── config_default.yaml ├── data └── fonts │ ├── FZSEJW.ttf │ ├── FZSJ-QINGCRJ.ttf │ ├── FZXS14.ttf │ ├── NotoSansSC-Regular.otf │ ├── NotoSerifSC-Regular.otf │ └── consola.ttf ├── index.js ├── main.py ├── package.json ├── plugins └── readme.txt ├── poetry.lock ├── pyproject.toml ├── requirements.txt ├── utils ├── channel.js ├── client.js └── receiver.js └── yunzai_nonebot ├── __init__.py ├── hijack ├── __init__.py ├── adapter.py ├── bot.py ├── driver.py ├── event.py ├── logger.py ├── message.py ├── params.py └── plugin.py ├── rpc ├── __init__.py ├── hola.proto ├── hola_pb2.py ├── hola_pb2.pyi ├── hola_pb2_grpc.py └── typing.py └── utils ├── __init__.py ├── deserializer ├── __init__.py ├── v11 │ ├── __init__.py │ ├── message.py │ ├── request.py │ └── utils.py └── v12 │ ├── __init__.py │ ├── message.py │ ├── request.py │ └── utils.py ├── exception.py ├── map.py ├── queue.py ├── serializer ├── __init__.py ├── v11 │ ├── __init__.py │ ├── event.py │ ├── result.py │ └── utils.py └── v12 │ ├── __init__.py │ ├── event.py │ ├── result.py │ └── utils.py └── service.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | __pycache__ 3 | .idea/ 4 | config.yaml 5 | plugins/* 6 | !plugins/readme.txt 7 | data/* 8 | !data/fonts 9 | -------------------------------------------------------------------------------- /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 | # !!!Windows系统不要用git执行命令,用Powershell执行命令!!! 2 | 3 | # 3月19日提示:如果你在3月19日更新了py-plugin版本,请先在py-plugin目录输入poetry run pip install nonebot2 nonebot-adapter-onebot 4 | 5 | # 1.前期准备 6 | 7 | ### 安装python 8 | 9 | ​ python版本>=3.8 **不要使用python3.11** 10 | 11 | ​ Linux系统安装python教程请百度 12 | 13 | ​ ubuntu系统使用apt-get即可,如果是centos系统,建议采用源码编译的方式,编译前请一定要安装以下依赖!否则以后可能出现无法安装依赖的情况 14 | 15 | ```shell 16 | zlib-devel bzip2-devel expat-devel gdbm-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel 17 | ``` 18 | 19 | ​ centos系统安装python可以参考https://blog.csdn.net/weixin_41287692/article/details/105434826 20 | 21 | ​ 注意,安装完成后不要删除源码文件夹,未来可能有用 22 | 23 | ​ Windows安装python,请下载软件一路安装过去,[python3.9.10](https://www.123pan.com/s/jqW9-w78JH.html) 24 | 25 | 26 | ### 安装poetry 27 | 28 | [poetry官网](https://python-poetry.org/docs/) 29 | 30 | **Linux, macOS** 31 | 32 | ```shell 33 | curl -sSL https://install.python-poetry.org | python - 34 | ``` 35 | poetry可执行文件位于```$HOME/.local/bin```,将其添加到环境变量或给```$HOME/.local/bin/poetry```添加软连接 36 | 37 | **Windows** 38 | 39 | 请按住shift键+右键打开Powershell运行下面命令 40 | 41 | ```shell 42 | (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python - 43 | ``` 44 | 45 | 注意这里的```python```指你的python解释器,若你的python对应的命令为python3或其它自定义的命令,请注意替换原命令中的```python``` 46 | 47 | 然后将```%APPDATA%\Python\Scripts```添加到PATH环境变量(位置在右键此电脑→属性→高级系统设置→环境变量) 48 | 49 | 等待安装完成,输入`poetry`查看是否有输出,有则说明poetry安装完成 50 | 51 | # 2. 插件使用 52 | 53 | ### 2.1 拉取代码 54 | 55 | ​ 进入云崽根目录,输入 56 | 57 | ```shell 58 | git clone https://github.com/realhuhu/py-plugin.git ./plugins/py-plugin/ 59 | ``` 60 | 61 | ### 2.2 安装nodejs 依赖 62 | 63 | ​ cd到云崽根目录 64 | 65 | ​ 如果是v2版本云崽,输入`npm install iconv-lite @grpc/grpc-js @grpc/proto-loader` 66 | 67 | ​ 如果是v3版本云崽,输入`pnpm install --filter=py-plugin ` 68 | 69 | ### 2.3 安装nodejs 依赖 70 | 71 | ​ 首先进入py-plugin目录,然后有两种选择: 72 | 73 | ​ **方法一(推荐):** 74 | 75 | ```shell 76 | poetry install 77 | ``` 78 | 79 | ​ 此时正在安装python依赖,第一行内容大致如下 80 | 81 | ```shell 82 | Creating virtualenv py-plugin-8_cve6GP-py3.8 in /root/.cache/pypoetry/virtualenvs 83 | ``` 84 | 85 | ​ **方法二:** 86 | 87 | ```shell 88 | poetry run pip install -r requirements.txt --trusted-host mirrors.aliyun.com 89 | ``` 90 | 91 | ​ 等待安装完成即可,之后重启云崽 92 | 93 | ### 2.2 使用 94 | 95 | ### 2.2.1 获取插件 96 | 97 | ​ 插件可以通过clone到plugins文件夹或者poetry run pip install的方式安装 98 | 99 | ​ 可以在github搜索或前往[nonebot商店](https://v2.nonebot.dev/store)获取插件 100 | 101 | ​ 获取插件后,需要将插件名称添加到config.yaml中,重启云崽即可 102 | 103 | #### 命令安装(推荐) 104 | 105 | ​ 对于可以pip install或nb plugin install的插件,可以使用```#py下载插件```指令进行安装 106 | 107 | ![image-20221120202102903](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202211202021020.png) 108 | 109 | ![image-20221120202148165](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202211202021203.png) 110 | 111 | ​ 此方法能自动安装依赖,并自动将插件添加到config.yaml的plugins下 112 | 113 | #### pip安装(推荐) 114 | 115 | ​ 如果无法命令安装,也可以使用pip安装, 116 | 117 | ​ 如上图插件,进入py-plugin目录,输入命令```poetry run pip install nonebot-plugin-gspanel```即可安装 118 | 119 | ​ 此方法能自动安装依赖,但需要手动将插件名称添加到config.yaml的plugins下 120 | 121 | ![image-20221117164932853](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202211202025156.png) 122 | 123 | ​ 输入命令```poetry run pip uninstall nonebot-plugin-gspanel```彻底卸载插件 124 | 125 | #### clone到plugins文件夹(不推荐) 126 | 127 | ​ ![image-20221117163456296](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202211171635372.png) 128 | 129 | ​ 例如安装该插件,点击右上角跳转到github,获取clone链接 130 | 131 | ![image-20221117163642282](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202211171636344.png) 132 | 133 | ​ 进入plugins文件夹,输入git clone 你的链接,完成后可以发现文件夹中多了这一项 134 | 135 | ![](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202211171639292.png) 136 | 137 | ​ 在config.yaml中添加这个插件,重启即可 138 | 139 | ![image-20221117163841418](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202211171638464.png) 140 | 141 | ![image-20221117163950890](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202211171639930.png) 142 | 143 | ​ 144 | 145 | 若同时采用了两种安装方式,则会优先运行pip/命令安装的插件 146 | 147 | nonebot机器人的命令以/开头,注意替换为# 148 | 149 | ![image-20221117165119644](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202211171651686.png) 150 | 151 | ![image-20221117165127354](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202211171651398.png) 152 | 153 | ### 2.2.2 指令 154 | 155 | ​ #py帮助:查看py的指令 156 | 157 | ​ #py信息:查看py解释器的文件夹 158 | 159 | ​ #py信息+插件名称:查看插件安装位置 160 | 161 | ​ #py下载插件+插件名称:自动运行poetry run pip install 插件,并将插件添加到config.yaml的plugins下,之后重启服务器 162 | 163 | ​ #py卸载插件+插件名称:自动运行poetry run pip uninstall 插件,并将将插件从config.yaml的plugins下删除,之后重启服务器 164 | 165 | ​ #py禁用插件+插件名称:将插件从config.yaml的plugins下删除,之后重启服务器 166 | 167 | ​ #py启用插件+插件名称:将插件添加到config.yaml的plugins下,之后重启服务器 168 | 169 | ​ #py全部插件:查看config.yaml的plugins下所有插件 170 | 171 | ​ #py更新插件+插件名称:更新指定插件,**不支持git安装的插件** 172 | 173 | ​ #py更新全部插件+插件名称:更新全部插件,**不支持git安装的插件** 174 | 175 | ​ #py重启:重新启动py服务器 176 | 177 | ​ #py查看配置,查看当前的config.yaml 178 | 179 | ​ #py修改配置+指令:修改配置。如`#py修改配置config.nickname=["云崽","yunzai"]` 180 | 181 | 182 | 183 | ### 2.2.3 配置文件 184 | 185 | ```yaml 186 | log_level: INFO #日志等级 187 | command_start: 188 | - "#" 189 | command_sep: 190 | - "." 191 | nickname: 192 | - 云崽 193 | - yunzai 194 | superusers: 195 | - 123456 196 | - 654321 197 | need_at: no #是否需要@机器人或加上机器人名字,默认no 198 | plugins: #加载哪些插件就往下加 199 | host: 127.0.0.1 200 | port: 50052 201 | 202 | #输出编码,默认windows使用gbk,其它平台使用utf-8 203 | #开启后强制使用你指定的编码 204 | #encoding: 205 | 206 | #是否分开启动py服务器与云崽本体,默认不分开 207 | #开启后需要你手动启动py服务器,再启动云崽 208 | #independent: true 209 | 210 | #开机时检查,执行on_startup注册的函数,如petpet开机时会检查更新素材,默认会检查 211 | #开启下面选项跳过检查 212 | #setup_check: false 213 | 214 | #关机时检查,执行on_shutdown注册的函数,默认会检查 215 | #开启下面选项跳过检查 216 | #shutdown_check: false 217 | ``` 218 | 219 | 若插件支持配置,在config.yaml中配置即可 220 | 221 | ![image-20221117164035336](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202211171640377.png) 222 | 223 | ![image-20221117164106239](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202211171641279.png) 224 | 225 | # 3. 常见问题 226 | 227 | 如果启动时报错,先重启一两遍看看能不能正常运行,如果还是报错按下面方法修复 228 | 229 | #### 1.安装nodejs 依赖报错 230 | 231 | 先安装cnpm 232 | 233 | ```shell 234 | npm install -g cnpm --registry=https://registry.npm.taobao.org 235 | ``` 236 | 237 | 然后用cnpm安装 238 | 239 | ```shell 240 | cnpm install @grpc/grpc-js @grpc/proto-loader 241 | ``` 242 | 243 | 如果还是报错,可能是node版本问题,建议重装node 244 | 245 | #### 2.poetry install 报错 246 | 247 | 原因:需要安装 Microsoft Visual C++ 14.0 以上 248 | 249 | 在 https://go.microsoft.com/fwlink/?LinkId=691126 下载安装包,使用默认配置安装即可 250 | 251 | #### 3.python安装依赖时提示ModuleNotFoundError:No module named _ctypes 252 | 253 | 如果是centos输入`sudo yum install libffi-devel ` 254 | 255 | 如果是ubuntu输入`sudo apt install libffi-dev -y ` 256 | 257 | 之后进Python源码文件夹,依次输入 258 | 259 | ```shell 260 | sudo make clean 261 | sudo ./configure 262 | sudo make && sudo make install 263 | ``` 264 | 265 | 之后重启云崽即可 266 | 267 | #### 4.python安装依赖时提示ModuleNotFoundError:No module named _sqlite 268 | 269 | 如果是centos输入`yum install sqlite-devel ` 270 | 271 | 如果是ubuntu输入`sudo apt-get install libsqlite3-dev ` 272 | 273 | 之后进Python源码文件夹,依次输入 274 | 275 | ```shell 276 | sudo make clean 277 | sudo ./configure 278 | sudo make && sudo make install 279 | ``` 280 | 281 | 之后重启云崽即可 282 | 283 | #### 5.安装插件时提示 git clone失败,请查看控制台 284 | 285 | 大部分是因为网络原因连不上github(部分插件被gitee识别为图床,因此只能通过github安装),多试几次就好了。如果一直卡住并且等不及了,可以发送 #重启,然后再发送安装指令,重新下载安装插件 286 | 287 | ### 6.发送命令无反应 288 | 289 | 说明python服务未启动,绝大部分出现于node app启动的情况下。启动时有提示`成功建立连接`才说明启动成功。如果没有这个提示请重启 290 | 291 | ```shell 292 | [PyBot][14:03:07.125][INFO] [drivers]Py服务器开机中 293 | [PyBot][14:03:07.786][SUCCESS] [plugin.manager]插件导入成功: "nonebot_plugin_gspanel" 294 | [PyBot][14:03:07.909][SUCCESS] [plugin.manager]插件导入成功: "nonebot_plugin_abstract" 295 | [PyBot][14:03:07.989][SUCCESS] [plugin.manager]插件导入成功: "nonebot_plugin_minesweeper" 296 | [PyBot][14:03:08.001][SUCCESS] [plugin.manager]插件导入成功: "nonebot_plugin_remake" 297 | [PyBot][14:03:08.060][SUCCESS] [plugin.manager]插件导入成功: "honkai_mys" 298 | [PyBot][14:03:08.862][SUCCESS] [plugin.manager]插件导入成功: "nonebot_plugin_memes" 299 | [PyBot][14:03:10.015][SUCCESS] [plugin.manager]插件导入成功: "nonebot_plugin_petpet" 300 | [PyBot][14:03:10.015][INFO] [gspanel.__utils__]正在检查面板插件所需资源... 301 | [PyBot][14:03:10.017][INFO] [gspanel.__utils__]面板插件所需资源检查完毕! 302 | [PyBot][14:03:10.253][INFO] [htmlrender.browser]使用 chromium 启动 303 | [PyBot][14:03:10.385][INFO] [htmlrender]Browser Started. 304 | [PyBot][14:03:10.385][INFO] [memes.download]正在检查资源文件... 305 | [PyBot][14:03:10.386][INFO] [petpet.download]正在检查资源文件... 306 | [PyBot][14:03:12.387][INFO] [drivers]Py服务器已开机(Py started) 307 | [PyBot][14:05:03.188][SUCCESS] [core.server.server]成功建立request连接 308 | [PyBot][14:05:03.188][SUCCESS] [core.server.server]成功建立result连接 309 | ``` 310 | 311 | # 5.使用远程 312 | 313 | ​ 在config.yaml中将host改为159.75.113.47,port改成50053即可,需要使用什么插件就在config.yaml的plugins添加 。[支持的插件](https://gitee.com/realhuhu/py-plugin/issues/I6655A) 314 | 315 | ![截图_20230321232514](https://typora-1304907527.cos.ap-nanjing.myqcloud.com/202303212325967.png) 316 | 317 | -------------------------------------------------------------------------------- /config_default.yaml: -------------------------------------------------------------------------------- 1 | log_level: INFO #日志等级 2 | command_start: 3 | - "#" 4 | command_sep: 5 | - "." 6 | nickname: 7 | - 云崽 8 | - yunzai 9 | superusers: 10 | - 123456 11 | - 654321 12 | need_at: no #是否需要@机器人或加上机器人名字,默认no 13 | plugins: #加载哪些插件就往下加 14 | host: 127.0.0.1 15 | port: 50052 16 | 17 | #输出编码,默认windows使用gbk,其它平台使用utf-8 18 | #开启后强制使用你指定的编码 19 | #encoding: 20 | 21 | #是否分开启动py服务器与云崽本体,默认不分开 22 | #开启后需要你手动启动py服务器,再启动云崽 23 | #independent: true 24 | 25 | #开机时检查,执行on_startup注册的函数,如petpet开机时会检查更新素材,默认会检查 26 | #开启下面选项跳过检查 27 | #setup_check: false 28 | 29 | #关机时检查,执行on_shutdown注册的函数,默认会检查 30 | #开启下面选项跳过检查 31 | #shutdown_check: false 32 | -------------------------------------------------------------------------------- /data/fonts/FZSEJW.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realhuhu/py-plugin/38996805cba6e85bf28be8d8fae83ffd74ed3a52/data/fonts/FZSEJW.ttf -------------------------------------------------------------------------------- /data/fonts/FZSJ-QINGCRJ.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realhuhu/py-plugin/38996805cba6e85bf28be8d8fae83ffd74ed3a52/data/fonts/FZSJ-QINGCRJ.ttf -------------------------------------------------------------------------------- /data/fonts/FZXS14.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realhuhu/py-plugin/38996805cba6e85bf28be8d8fae83ffd74ed3a52/data/fonts/FZXS14.ttf -------------------------------------------------------------------------------- /data/fonts/NotoSansSC-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realhuhu/py-plugin/38996805cba6e85bf28be8d8fae83ffd74ed3a52/data/fonts/NotoSansSC-Regular.otf -------------------------------------------------------------------------------- /data/fonts/NotoSerifSC-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realhuhu/py-plugin/38996805cba6e85bf28be8d8fae83ffd74ed3a52/data/fonts/NotoSerifSC-Regular.otf -------------------------------------------------------------------------------- /data/fonts/consola.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realhuhu/py-plugin/38996805cba6e85bf28be8d8fae83ffd74ed3a52/data/fonts/consola.ttf -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import fs from "node:fs"; 2 | import YAML from 'yaml' 3 | import path from "path"; 4 | import {exec} from "child_process"; 5 | import {create_client, setup_server, setup_client} from "./utils/client.js"; 6 | 7 | if (typeof segment === "undefined") { 8 | try { 9 | global.segment = (await import("icqq")).segment 10 | } catch { 11 | global.segment = (await import("oicq")).segment 12 | } 13 | } 14 | 15 | global.py_plugin_path = path.join(process.cwd(), "plugins", "py-plugin"); 16 | if (!fs.existsSync(path.join(py_plugin_path, "config.yaml"))) { 17 | fs.copyFileSync(path.join(py_plugin_path, "config_default.yaml"), path.join(py_plugin_path, "config.yaml")); 18 | } 19 | global.py_plugin_config = YAML.parse(fs.readFileSync(path.join(global.py_plugin_path, "config.yaml"), 'utf8')) 20 | py_plugin_config.plugins = py_plugin_config.plugins || [] 21 | global.py_plugin_client = create_client(py_plugin_config) 22 | 23 | setup_server().then(msg => { 24 | logger.mark(msg) 25 | setup_client() 26 | }).catch(logger.error) 27 | 28 | export class PyPlugin extends plugin { 29 | constructor() { 30 | super({ 31 | name: 'py-plugin', 32 | dsc: 'py-plugin', 33 | event: 'message', 34 | priority: 5000, 35 | rule: [ 36 | { 37 | reg: "#?n?py帮助", 38 | fnc: 'py_help' 39 | }, 40 | { 41 | reg: "#?n?py信息.*", 42 | fnc: 'py_info' 43 | }, 44 | { 45 | reg: "#?n?py(下载|卸载|启用|禁用|更新|全部|更新全部)插件.*", 46 | fnc: 'py_manage' 47 | }, 48 | { 49 | reg: "#?n?py(强制)?重启", 50 | fnc: 'py_restart' 51 | }, 52 | { 53 | reg: "#?n?py(查看|修改)配置.*", 54 | fnc: 'py_modify' 55 | }, 56 | ] 57 | }) 58 | } 59 | 60 | async py_help(e) { 61 | if (!e.isMaster) return 62 | e.reply("py下载|卸载|启用|禁用|更新插件+插件名\npy更新全部插件\npy全部插件\npy重启\npy查看|修改配置") 63 | } 64 | 65 | async py_info(e) { 66 | if (!e.isMaster) return 67 | let plugin = e.msg.replace(/#?n?py信息/, "").replace(/\s*/g, "") 68 | let res 69 | if (!plugin) { 70 | e.reply(`python文件夹:${(await this.poetry("env", "list", "--full-path")).msg}`) 71 | } else { 72 | res = await this.poetry("run", "pip", "show", plugin) 73 | if (res.err) { 74 | e.reply(`出错了:${res.err},请确认插件名正确`) 75 | } else { 76 | e.reply(res.msg) 77 | } 78 | } 79 | } 80 | 81 | async py_manage(e) { 82 | if (!e.isMaster) return 83 | let command = e.msg.match(/(?<=#?n?py)(下载|卸载|启用|禁用|更新全部|更新|全部)/g)[0] 84 | let plugin = e.msg.replace(/#?(n)?py(下载|卸载|启用|禁用|更新|全部|更新全部)插件/, "").replace(/\s*/g, "") 85 | let res, index 86 | switch (command) { 87 | case "下载": 88 | if (py_plugin_config.host !== "127.0.0.1") { 89 | e.reply("远程模式下不需要下载插件,请使用 #py启用插件") 90 | return 91 | } 92 | e.reply(`下载中:${plugin}`) 93 | res = await this.poetry("run", "pip", "install", plugin) 94 | if (res.err) { 95 | e.reply(`出错了:${res.err}`) 96 | return 97 | } 98 | e.reply(`下载完成:${plugin}`) 99 | py_plugin_config.plugins.push(plugin) 100 | break 101 | case "卸载": 102 | if (py_plugin_config.host !== "127.0.0.1") { 103 | e.reply("远程模式下不需要卸载插件,请使用 #py禁用插件") 104 | return 105 | } 106 | if (fs.readdirSync(path.join(py_plugin_path, "plugins")).indexOf(plugin) !== -1) { 107 | e.reply(`无法卸载:${plugin},只能卸载通过pip安装和指令安装的插件`) 108 | return 109 | } 110 | e.reply(`卸载中:${plugin}`) 111 | res = await this.poetry("run", "pip", "uninstall", plugin, "-y") 112 | if (res.err) { 113 | e.reply(`出错了:${res.err}`) 114 | return 115 | } 116 | e.reply(`卸载完成:${plugin}`) 117 | index = py_plugin_config.plugins.indexOf(plugin) 118 | if (index !== -1) { 119 | py_plugin_config.plugins.splice(index, 1) 120 | } 121 | break 122 | case "启用": 123 | if (py_plugin_config.plugins.indexOf(plugin) !== -1) { 124 | e.reply("该插件已启用!") 125 | return 126 | } 127 | e.reply(`已启用:${plugin}`) 128 | py_plugin_config.plugins.push(plugin) 129 | break 130 | case "禁用": 131 | if (py_plugin_config.plugins.indexOf(plugin) === -1) { 132 | e.reply("该插件未启用!") 133 | return 134 | } 135 | e.reply(`已禁用:${plugin}`) 136 | index = py_plugin_config.plugins.indexOf(plugin) 137 | if (index !== -1) { 138 | py_plugin_config.plugins.splice(index, 1) 139 | } 140 | break 141 | case "更新": 142 | if (py_plugin_config.host !== "127.0.0.1") { 143 | e.reply("远程模式下无法更新插件") 144 | return 145 | } 146 | e.reply(`更新中:${plugin}`) 147 | res = await this.poetry("run", "pip", "install", "--upgrade", plugin) 148 | if (res.err) { 149 | e.reply(`出错了:${res.err}`) 150 | return 151 | } 152 | e.reply(`更新完成:${plugin}`) 153 | py_plugin_config.plugins.push(plugin) 154 | break 155 | case "全部": 156 | e.reply(`已加载插件:\n${py_plugin_config.plugins.join("\n")}`) 157 | return 158 | case "更新全部": 159 | if (py_plugin_config.host !== "127.0.0.1") { 160 | e.reply("远程模式下无法更新插件") 161 | return 162 | } 163 | e.reply(`更新全部插件:\n${py_plugin_config.plugins.join("\n")}`) 164 | let result = await Promise.all(py_plugin_config.plugins.map(plugin => new Promise(resolve => { 165 | this.poetry("run", "pip", "install", "--upgrade", plugin).then(res => resolve({plugin, err: res.err})) 166 | }))) 167 | 168 | let msg = `更新完成:\n${result.filter(x => !x.err).map(x => x.plugin).join("\n")}` 169 | if (result.filter(x => x.err).length) { 170 | msg += `\n\n更新失败:\n${result.filter(x => x.err).map(x => `[${x.plugin}]: ${x.err}`).join("\n")}` 171 | } 172 | e.reply(msg) 173 | return 174 | } 175 | py_plugin_config.plugins = [...new Set(py_plugin_config.plugins)] 176 | await this.save_cfg(py_plugin_config) 177 | await this.py_restart(e) 178 | } 179 | 180 | async py_restart(e) { 181 | if (!e.isMaster || py_plugin_config.host !== "127.0.0.1") return 182 | setup_server().then(() => { 183 | e.reply("已重启python服务器") 184 | }).catch(err => { 185 | e.reply("重启失败,请查看控制台") 186 | logger.warn(err) 187 | }) 188 | } 189 | 190 | async py_modify(e) { 191 | if (!e.isMaster) return 192 | let command = e.msg.match(/(?<=#?n?py)(查看|修改)/g)[0] 193 | 194 | switch (command) { 195 | case "查看": 196 | e.reply(YAML.stringify(py_plugin_config)) 197 | break 198 | case "修改": 199 | let config = py_plugin_config 200 | try { 201 | eval(e.msg.replace(/#?n?py(查看|修改)配置/, "")) 202 | } catch (err) { 203 | e.reply(`语法错误:${err.message}`) 204 | return 205 | } 206 | e.reply(YAML.stringify(config) + "\n配置已保存,重启python服务器中") 207 | await this.save_cfg(config) 208 | await this.py_restart(e) 209 | break 210 | } 211 | } 212 | 213 | async poetry(...args) { 214 | return new Promise(resolve => { 215 | exec( 216 | `poetry ${args.join(" ")}`, 217 | {cwd: py_plugin_path}, 218 | (error, stdout, stderr) => { 219 | resolve({ 220 | err: error && error.message.replace(/WARNING.*?\r\n/g, ""), 221 | msg: stdout 222 | }) 223 | } 224 | ); 225 | }) 226 | } 227 | 228 | async save_cfg(data) { 229 | return new Promise(resolve => { 230 | let yamlStr = YAML.stringify(data); 231 | yamlStr = yamlStr.replace("plugins: []", "plugins:") 232 | fs.writeFile(path.join(py_plugin_path, "config.yaml"), yamlStr, () => { 233 | resolve() 234 | }); 235 | }) 236 | } 237 | } 238 | 239 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import shutil 2 | from pathlib import Path 3 | 4 | import yunzai_nonebot 5 | 6 | root = Path(__file__).absolute().parent 7 | config_path = root / "config.yaml" 8 | 9 | if not config_path.exists(): 10 | shutil.copy(root / "config_default.yaml", config_path) 11 | 12 | yunzai_nonebot.init(Path(__file__).absolute().parent / "config.yaml") 13 | 14 | for plugin in set(filter(lambda x: x, yunzai_nonebot.get_driver().config.plugins)): 15 | yunzai_nonebot.load_plugin(plugin.replace("-", "_")) 16 | 17 | yunzai_nonebot.run() 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "py-plugin", 3 | "description": "Yunzai-Bot插件", 4 | "type": "module", 5 | "module": "index.js", 6 | "main": "index.js", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [ 11 | "云崽", 12 | "原神", 13 | "Yunzai-Bot", 14 | "Genshin" 15 | ], 16 | "author": "realhuhu", 17 | "license": "GPL", 18 | "dependencies": { 19 | "@grpc/grpc-js": "^1.8.12", 20 | "@grpc/proto-loader": "^0.7.5", 21 | "iconv-lite": "^0.6.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /plugins/readme.txt: -------------------------------------------------------------------------------- 1 | clone的插件或自定义插件放在这 -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "py-plugin" 3 | version = "3.1.0" 4 | description = "" 5 | authors = ["realhuhu <2661467107@qq.com>"] 6 | readme = "README.md" 7 | 8 | [tool.poetry.dependencies] 9 | python = "^3.8" 10 | nonebot2 = "^2.0.0rc3" 11 | nonebot-adapter-onebot = "^2.2.2" 12 | omegaconf = "^2.3.0" 13 | googleapis-common-protos = "^1.59.0" 14 | grpcio = "^1.51.3" 15 | 16 | 17 | [tool.poetry.group.dev.dependencies] 18 | grpcio-tools = "^1.51.3" 19 | 20 | [build-system] 21 | requires = ["poetry-core"] 22 | build-backend = "poetry.core.masonry.api" 23 | 24 | [[tool.poetry.source]] 25 | name = "aliyun" 26 | url = "https://mirrors.aliyun.com/pypi/simple" 27 | default = true -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | --index-url https://mirrors.aliyun.com/pypi/simple 2 | 3 | antlr4-python3-runtime==4.9.3 ; python_version >= "3.8" and python_version < "4.0" 4 | colorama==0.4.6 ; python_version >= "3.8" and python_version < "4.0" and sys_platform == "win32" 5 | googleapis-common-protos==1.59.0 ; python_version >= "3.8" and python_version < "4.0" 6 | grpcio==1.51.3 ; python_version >= "3.8" and python_version < "4.0" 7 | idna==3.4 ; python_version >= "3.8" and python_version < "4.0" 8 | loguru==0.6.0 ; python_version >= "3.8" and python_version < "4.0" 9 | msgpack==1.0.5 ; python_version >= "3.8" and python_version < "4.0" 10 | multidict==6.0.4 ; python_version >= "3.8" and python_version < "4.0" 11 | nonebot-adapter-onebot==2.2.2 ; python_version >= "3.8" and python_version < "4.0" 12 | nonebot2==2.0.0rc3 ; python_version >= "3.8" and python_version < "4.0" 13 | omegaconf==2.3.0 ; python_version >= "3.8" and python_version < "4.0" 14 | protobuf==4.22.1 ; python_version >= "3.8" and python_version < "4.0" 15 | pydantic[dotenv]==1.10.7 ; python_version >= "3.8" and python_version < "4.0" 16 | pygtrie==2.5.0 ; python_version >= "3.8" and python_version < "4.0" 17 | python-dotenv==1.0.0 ; python_version >= "3.8" and python_version < "4.0" 18 | pyyaml==6.0 ; python_version >= "3.8" and python_version < "4.0" 19 | tomlkit==0.11.6 ; python_version >= "3.8" and python_version < "4.0" 20 | typing-extensions==4.5.0 ; python_version >= "3.8" and python_version < "4.0" 21 | win32-setctime==1.1.0 ; python_version >= "3.8" and python_version < "4.0" and sys_platform == "win32" 22 | yarl==1.8.2 ; python_version >= "3.8" and python_version < "4.0" 23 | -------------------------------------------------------------------------------- /utils/channel.js: -------------------------------------------------------------------------------- 1 | import {parse_sender, parse_message} from "./receiver.js"; 2 | import {setup_client} from "./client.js"; 3 | 4 | 5 | const parse_user = x => { 6 | return { 7 | user_id: x.user_id, 8 | nickname: x.nickname, 9 | sex: x.sex, 10 | age: x.age, 11 | } 12 | } 13 | 14 | const parse_friend = x => { 15 | return { 16 | user_id: x.user_id, 17 | nickname: x.nickname, 18 | sex: x.sex, 19 | remark: x.remark, 20 | } 21 | } 22 | 23 | const parse_member = x => { 24 | return { 25 | group_id: x.group_id, 26 | user_id: x.user_id, 27 | nickname: x.nickname, 28 | card: x.card, 29 | sex: x.sex, 30 | age: x.age, 31 | area: x.area, 32 | join_time: x.join_time, 33 | last_sent_time: x.last_sent_time, 34 | level: x.level, 35 | role: x.role, 36 | title: x.title, 37 | title_expire_time: x.title_expire_time, 38 | shutup_timestamp: x.shutup_time, 39 | } 40 | } 41 | 42 | const parse_group = x => { 43 | return { 44 | group_id: x.group_id, 45 | group_name: x.group_name, 46 | group_create_time: x.create_time, 47 | group_level: x.grade, 48 | member_count: x.member_count, 49 | max_member_count: x.max_member_count, 50 | } 51 | } 52 | 53 | const parse_grpc_message = async message => { 54 | let serialized_message = [], anonymous = false, music = null, source = null 55 | for (let message_segment of message) { 56 | let type = message_segment.segment 57 | let data = message_segment[type] 58 | switch (type) { 59 | case "text": 60 | serialized_message.push(data.data) 61 | break 62 | case "face": 63 | serialized_message.push(segment.face(data.id)) 64 | break 65 | case "image": 66 | serialized_message.push(segment.image(data.file || data.content)) 67 | break 68 | case "record": 69 | serialized_message.push(segment.record(data.file || data.content)) 70 | break 71 | case "video": 72 | serialized_message.push(segment.video(data.file || data.content)) 73 | break 74 | case "at": 75 | serialized_message.push(segment.at(Number(data.qq))) 76 | break 77 | case "rps": 78 | serialized_message.push(segment.rps()) 79 | break 80 | case "dice": 81 | serialized_message.push(segment.dice()) 82 | break 83 | case "poke": 84 | serialized_message.push(segment.poke(data.id)) 85 | break 86 | case "anonymous": 87 | anonymous = true 88 | break 89 | case "share": 90 | serialized_message.push(segment.share(data.url, data.title, data.image, data.content)) 91 | break 92 | case "contact": 93 | break 94 | case "location": 95 | serialized_message.push(segment.location(data.lat, data.lon, data.title)) 96 | break 97 | case "music": 98 | music = data 99 | break 100 | case "custom_music": 101 | break 102 | case "reply": 103 | source = await Bot.getMsg(data.id) 104 | break 105 | case "xml": 106 | serialized_message.push(segment.xml(data.data)) 107 | break 108 | case "json": 109 | serialized_message.push(segment.json(data.data)) 110 | break 111 | } 112 | } 113 | return {serialized_message, source, anonymous, music} 114 | } 115 | 116 | const resolve_request = async request => { 117 | let type = request.request 118 | let load = request[type] 119 | switch (type) { 120 | case "send_message": 121 | let {serialized_message, source, anonymous, music} = await parse_grpc_message(load.message), client 122 | client = (load.detail_type === "group" || Number(load.group_id)) ? Bot.pickGroup(load.group_id) : Bot.pickFriend(load.user_id) 123 | if (music) return await client.shareMusic(music.type, music.id) 124 | return await client.sendMsg(serialized_message, source, anonymous) 125 | case "delete_message": 126 | return await Bot.deleteMsg(load.message_id) 127 | case "get_message": 128 | return await Bot.getMsg(load.message_id) 129 | case "get_forward_message": 130 | return await Bot.getForwardMsg(load.id) 131 | case "send_like": 132 | return await Bot.sendLike(load.user_id, load.times) 133 | case "set_group_kick": 134 | return await Bot.pickGroup(load.group_id).kickMember(load.user_id, "", load.reject_add_request) 135 | case "set_group_ban": 136 | return await Bot.pickGroup(load.group_id).muteMember(load.user_id, load.duration) 137 | case "set_group_anonymous_ban": 138 | return await Bot.pickGroup(load.group_id).muteAnony(load.anonymous_flag, load.duration) 139 | case "set_group_whole_ban": 140 | return await Bot.pickGroup(load.group_id).muteAll(load.enable) 141 | case "set_group_admin": 142 | return await Bot.pickGroup(load.group_id).setAdmin(load.user_id, load.enable) 143 | case "set_group_anonymous": 144 | return await Bot.pickGroup(load.group_id).allowAnony(load.enable) 145 | case "set_group_card": 146 | return await Bot.pickGroup(load.group_id).setCard(load.user_id, load.card) 147 | case "set_group_name": 148 | return await Bot.pickGroup(load.group_id).setName(load.group_name) 149 | case "set_group_leave": 150 | return await Bot.pickGroup(load.group_id).quit() 151 | case "set_group_special_title": 152 | return await Bot.pickGroup(load.group_id).setTitle(load.user_id, load.special_title, load.duration) 153 | case "set_friend_add_request": 154 | return await Bot.setFriendAddRequest(load.flag, load.approve, load.remark) 155 | case "set_group_add_request": 156 | return await Bot.setGroupAddRequest(load.flag, load.approve, load.reason) 157 | case "get_self_info": 158 | return {user_id: Bot.uin, nickname: Bot.nickname} 159 | case "get_user_info": 160 | return await Bot.getStrangerInfo(load.user_id) 161 | case "get_friend_list": 162 | return Bot.getFriendList() 163 | case "get_group_info": 164 | return await Bot.getGroupInfo(load.group_id) 165 | case "get_group_list": 166 | return Bot.getGroupList() 167 | case "get_group_member_info": 168 | return await Bot.pickMember(load.group_id, load.user_id).renew() 169 | case "get_group_member_list": 170 | return await Bot.pickGroup(load.group_id).getMemberMap() 171 | case "send_forward_message": 172 | let forward_message = await Promise.all(load.message.map(async node => ({ 173 | user_id: Number(node.uin), 174 | nickname: node.name, 175 | message: (await parse_grpc_message(node.content)).serialized_message 176 | }))) 177 | if (load.detail_type === "group") { 178 | return await Bot.pickGroup(load.group_id).sendMsg(segment.xml((await Bot.pickGroup(load.group_id).makeForwardMsg(forward_message)).data)) 179 | } else { 180 | return await Bot.pickFriend(load.user_id).sendMsg(segment.xml((await Bot.pickFriend(load.user_id).makeForwardMsg(forward_message)).data)) 181 | } 182 | } 183 | } 184 | 185 | const create_result = async (request, raw) => { 186 | let type = request.request 187 | let data 188 | switch (type) { 189 | case "send_message": 190 | data = {message_id: raw?.message_id, time: raw?.time} 191 | break 192 | case "get_message": 193 | data = { 194 | message_id: raw.message_id, 195 | real_id: 0,//OVERWRITE 196 | sender: await parse_sender(raw.sender), time: raw.time, message: await parse_message(raw.message) 197 | } 198 | break 199 | case "send_forward_message": 200 | data = { 201 | message_id: raw.message_id, 202 | time: raw.time 203 | } 204 | break 205 | case "get_forward_message": 206 | data = {} //TODO 207 | break 208 | case "get_self_info": 209 | data = raw 210 | break 211 | case "get_user_info": 212 | data = {user: parse_user(raw)} 213 | break 214 | case "get_friend_list": 215 | data = {friend_list: [...raw.values()].map(parse_friend)} 216 | break 217 | case "get_group_info": 218 | data = {group: parse_group(raw)} 219 | break 220 | case "get_group_list": 221 | data = {group_list: [...raw.values()].map(parse_group)} 222 | break 223 | case "get_group_member_info": 224 | data = {member: parse_member(raw)} 225 | break 226 | case "get_group_member_list": 227 | data = {member_list: [...raw.values()].map(parse_member)} 228 | break 229 | case "delete_message": 230 | case "send_like": 231 | case "set_group_kick": 232 | case "set_group_ban": 233 | case "set_group_anonymous_ban": 234 | case "set_group_whole_ban": 235 | case "set_group_admin": 236 | case "set_group_anonymous": 237 | case "set_group_card": 238 | case "set_group_name": 239 | case "set_group_leave": 240 | case "set_group_special_title": 241 | case "set_friend_add_request": 242 | case "set_group_add_request": 243 | data = {} 244 | break 245 | } 246 | 247 | return data && { 248 | result: { 249 | request_id: request.request_id, self_id: Bot.uin.toString(), [type]: data 250 | } 251 | } 252 | } 253 | 254 | export const setup_channel = (client, ignore, retry) => new Promise((resolve, reject) => { 255 | return new Promise(resolve1 => { 256 | client.Option({code: 100}, (err, response) => { 257 | resolve1(err && err.details) 258 | }) 259 | }).then(err => { 260 | if (err && !ignore) { 261 | reject(`[py-plugin] 连接服务器错误: ${err}`) 262 | } else if (err) { 263 | logger.error(`[py-plugin] 连接服务器错误: ${err},${retry}秒后尝试重连`) 264 | setTimeout(() => { 265 | setup_client(true, retry >= 320 ? 600 : retry * 2) 266 | }, retry * 1000) 267 | } else { 268 | logger.info("[py-plugin] 连接服务器成功") 269 | let channel = client.Channel() 270 | channel.on("data", data => { 271 | resolve_request(data.request).then(raw => { 272 | return create_result(data.request, raw) 273 | }).then(result => { 274 | result && channel.write(result) 275 | }) 276 | }); 277 | channel.on("error", err => { 278 | if (err.details) { 279 | logger.error(`[py-plugin] 服务器连接丢失:${err.details},5秒后尝试重连`); 280 | retry = 5; 281 | setTimeout(() => { 282 | setup_client(true, retry >= 320 ? 600 : retry * 2) 283 | }, retry * 1000) 284 | } 285 | }); 286 | channel.write({head: {self_id: Bot.uin.toString()}}) 287 | resolve(channel) 288 | } 289 | }) 290 | }) 291 | -------------------------------------------------------------------------------- /utils/client.js: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import chalk from "chalk"; 3 | import grpc from "@grpc/grpc-js"; 4 | import iconv from 'iconv-lite' 5 | import protoLoader from "@grpc/proto-loader"; 6 | import {spawn} from "child_process"; 7 | import {setup_channel} from "./channel.js"; 8 | import {request_receiver, message_receiver, notice_receiver} from "./receiver.js"; 9 | 10 | const py_logger = raw => { 11 | // try { 12 | // let head = chalk.blue(raw.match(/\[.*?\]\[.*?\]/g)[0]) 13 | // let level = raw.match(/(?<=\[.*?\]\[.*?\])\[.*?\]/g)[0] 14 | // switch (level) { 15 | // case"[TRACE]": 16 | // level = chalk.grey(level) 17 | // break 18 | // case"[DEBUG]": 19 | // level = chalk.gray(level) 20 | // break 21 | // case"[SUCCESS]": 22 | // level = chalk.green(level) 23 | // break 24 | // case"[WARNING]": 25 | // level = chalk.yellow(level) 26 | // break 27 | // case"[ERROR]": 28 | // level = chalk.red(level) 29 | // break 30 | // case"[CRITICAL]": 31 | // level = chalk.bgRed(level) 32 | // break 33 | // } 34 | // let name = chalk.yellow(raw.match(/(?<=\[.*?\]\[.*?\]\[.*?\] )\[.*?\]/g)[0]) 35 | // let message = raw.match(/(?<=\[.*?\]\[.*?\]\[.*?\] \[.*?\]).*/g)[0] 36 | // console.log(head + level, name, message); 37 | // } catch { 38 | // console.log(raw); 39 | // } 40 | process.stdout.write(raw); 41 | } 42 | export const create_client = config => { 43 | const packageDefinition = protoLoader.loadSync(path.join(py_plugin_path, "yunzai_nonebot", "rpc", "hola.proto"), { 44 | keepCase: true, 45 | longs: String, 46 | enums: String, 47 | defaults: true, 48 | oneofs: true, 49 | includeDirs: [ 50 | process.cwd() 51 | ], 52 | }); 53 | const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); 54 | const channel = protoDescriptor.hola; 55 | return new channel.Pipe(`${config.host || "127.0.0.1"}:${config.port || 50052}`, grpc.credentials.createInsecure(), { 56 | "grpc.max_receive_message_length": 1024 * 1024 * 128, 57 | "grpc.max_send_message_length": 1024 * 1024 * 128, 58 | }); 59 | } 60 | 61 | export const setup_server = () => new Promise((resolve, reject) => { 62 | if (py_plugin_config.independent || py_plugin_config.host !== "127.0.0.1") { 63 | resolve("[py-plugin] 连接服务器中,请确保Py服务器已启动") 64 | } else { 65 | py_plugin_client.Option({code: 1}, function (err, response) { 66 | let encoding = py_plugin_config.encoding || (process.platform === "win32" ? "gbk" : "utf-8") 67 | logger.info("[py-plugin] python服务器启动中"); 68 | const cmd = spawn( 69 | "poetry", 70 | ["run", "python", "main.py"], 71 | { 72 | cwd: py_plugin_path, 73 | shell: false, 74 | }, 75 | ); 76 | 77 | cmd.stdout.on("data", data => { 78 | py_logger(iconv.decode(data, encoding)); 79 | if (data.toString().includes("Py started")) { 80 | py_plugin_client.Option({code: 100}, function (err, response) { 81 | response && response.code === "100" ? resolve("[py-plugin] python服务器启动成功") : reject(err || response) 82 | }); 83 | } 84 | }); 85 | 86 | cmd.stderr.on("data", data => { 87 | py_logger(iconv.decode(data, encoding)); 88 | }); 89 | 90 | cmd.stderr.on("end", () => { 91 | logger.warn("[py-plugin] python服务器已关闭"); 92 | }); 93 | 94 | cmd.on("error", err => { 95 | logger.warn("[py-plugin] python服务器启动失败"); 96 | logger.warn(err); 97 | }); 98 | }); 99 | } 100 | }) 101 | 102 | export const setup_client = (ignore, retry) => { 103 | setup_channel(py_plugin_client, ignore, retry).then(channel => { 104 | Bot.on("request", event => request_receiver(channel, event)) 105 | Bot.on("message", event => message_receiver(channel, event)) 106 | Bot.on("notice", event => notice_receiver(channel, event)) 107 | }).catch(err => { 108 | logger.error(err) 109 | }) 110 | } 111 | -------------------------------------------------------------------------------- /utils/receiver.js: -------------------------------------------------------------------------------- 1 | export const parse_message = async message => { 2 | return message.map(segment => { 3 | //OMIT 4 | switch (segment.type) { 5 | //TextElem 6 | case "text": 7 | return { 8 | text: { 9 | data: segment.text 10 | } 11 | } 12 | //AtElem 13 | case "at"://OMIT 14 | return { 15 | at: { 16 | qq: segment.qq, 17 | } 18 | } 19 | //FaceElem 20 | case "face"://OMIT 21 | return { 22 | face: { 23 | id: segment.id 24 | } 25 | } 26 | case "sface"://PY UNIMPLEMENTED 27 | return { 28 | text: { 29 | data: `[sface ${segment.text}]` 30 | } 31 | } 32 | //BfaceElem 33 | case "bface"://PY UNIMPLEMENTED 34 | return { 35 | text: { 36 | data: `[bface ${segment.text}]` 37 | } 38 | } 39 | //MfaceElem 40 | case "rps"://OMIT 41 | return { 42 | rps: {} 43 | } 44 | case "dice"://OMIT 45 | return { 46 | dice: {} 47 | } 48 | //ImageElem 49 | case "image"://OMIT 50 | return { 51 | image: { 52 | file: segment.file, 53 | url: segment.url, 54 | } 55 | } 56 | //FlashElem 57 | case "flash"://OMIT 58 | return { 59 | image: { 60 | file: segment.file, 61 | type: "flash", 62 | url: segment.url, 63 | } 64 | } 65 | //PttElem 66 | case "record"://OMIT 67 | return { 68 | record: { 69 | file: segment.file, 70 | url: segment.url, 71 | } 72 | } 73 | //VideoElem 74 | case "video"://OMIT 75 | return { 76 | video: { 77 | file: segment.file, 78 | url: undefined//TODO 79 | } 80 | } 81 | //LocationElem 82 | case "location"://OMIT 83 | return { 84 | location: { 85 | lat: segment.lat, 86 | lon: segment.lon, 87 | title: segment.name, 88 | content: segment.address 89 | } 90 | } 91 | //ShareElem 92 | case "share": 93 | return { 94 | share: { 95 | url: segment.url, 96 | title: segment.title, 97 | content: segment.content, 98 | image: segment.image 99 | } 100 | } 101 | //JsonElem 102 | case "json": 103 | return { 104 | json: { 105 | data: segment.data 106 | } 107 | } 108 | //XmlElem 109 | case "xml"://OMIT 110 | return { 111 | xml: { 112 | data: segment.data 113 | } 114 | } 115 | //PokeElem 116 | case "poke": 117 | return { 118 | poke: { 119 | type: segment.type, 120 | id: segment.id, 121 | name: segment.text 122 | } 123 | } 124 | //ReplyElem 125 | case "reply": 126 | return { 127 | reply: { 128 | id: segment.id, 129 | } 130 | } 131 | default: 132 | logger.warn(`[py-plugin][parse-message] 无法识别的消息:${segment}`) 133 | return { 134 | text: { 135 | data: "[py-plugin未知消息]", 136 | } 137 | } 138 | } 139 | }).filter(x => x) 140 | } 141 | 142 | export const parse_sender = async sender => { 143 | return { 144 | user_id: sender.user_id, 145 | nickname: sender.nickname, 146 | sex: sender.sex || "unknown", 147 | age: sender.age, 148 | card: sender.card, 149 | area: sender.area, 150 | level: sender.level?.toString(), 151 | role: sender.role, 152 | title: sender.title 153 | } 154 | } 155 | 156 | export const parse_reply = async (handler, flag) => { 157 | let message = await handler.getChatHistory(flag, 1) 158 | message = message && message.pop() 159 | return message && { 160 | time: message.time, 161 | message_type: message.message_type, 162 | message_id: message.message_id, 163 | sender: await parse_sender(message.sender), 164 | message: await parse_message(message.message) 165 | } 166 | 167 | } 168 | 169 | export const parse_anonymous = async anonymous => { 170 | return anonymous && { 171 | id: anonymous.id, 172 | name: anonymous.name, 173 | flag: anonymous.flag 174 | } 175 | } 176 | 177 | const call_back = (channel, data) => { 178 | data && channel.write({ 179 | event: { 180 | plugins: py_plugin_config.plugins.map(x => x.replace(/-/g, "_")), 181 | self_id: Bot.uin.toString(), 182 | ...data 183 | } 184 | }) 185 | } 186 | 187 | export const message_receiver = async (channel, event) => { 188 | let data 189 | switch (event.message_type) { 190 | case "private": 191 | data = { 192 | private_message: { 193 | time: event.time, 194 | self_id: event.self_id, 195 | sub_type: event.sub_type, 196 | message_id: event.message_id, 197 | user_id: event.user_id, 198 | message: await parse_message(event.message), 199 | raw_message: event.raw_message, 200 | sender: await parse_sender(event.sender), 201 | to_me: true, 202 | reply: event.source && await parse_reply(event.friend, event.source.time + 1) 203 | } 204 | } 205 | break 206 | case "group": 207 | data = { 208 | group_message: { 209 | time: event.time, 210 | self_id: event.self_id, 211 | sub_type: event.sub_type, 212 | message_id: event.message_id, 213 | group_id: event.group_id, 214 | user_id: event.user_id, 215 | anonymous: await parse_anonymous(event.anonymous), 216 | message: await parse_message(event.message), 217 | raw_message: event.raw_message, 218 | sender: await parse_sender(event.sender), 219 | to_me: event.atme, 220 | reply: event.source && await parse_reply(event.group, event.source.seq) 221 | } 222 | } 223 | break 224 | default: 225 | return `[py-plugin][before-match-message] 未知的message类型` 226 | } 227 | call_back(channel, data) 228 | } 229 | 230 | export const request_receiver = async (channel, event) => { 231 | let data 232 | switch (`${event.request_type}.${event.sub_type}`) { 233 | case "friend.add": 234 | case "friend.single": 235 | data = { 236 | friend_request: { 237 | time: event.time, 238 | self_id: event.self_id, 239 | user_id: event.user_id, 240 | comment: event.comment, 241 | flag: event.flag 242 | } 243 | } 244 | break 245 | case "group.add": 246 | case "group.invite": 247 | data = { 248 | group_request: { 249 | time: event.time, 250 | self_id: event.self_id, 251 | sub_type: event.sub_type, 252 | group_id: event.group_id, 253 | user_id: event.user_id, 254 | comment: event.comment, 255 | flag: event.flag 256 | } 257 | } 258 | break 259 | default: 260 | return `[py-plugin][before-match-request] 未知的request类型` 261 | } 262 | call_back(channel, data) 263 | } 264 | 265 | export const notice_receiver = async (channel, event) => { 266 | let data, time = Math.round(new Date().getTime() / 1000) 267 | //OMIT 268 | switch (`${event.notice_type}.${event.sub_type}`) { 269 | //FriendIncreaseEvent 270 | case "friend.increase": 271 | data = { 272 | friend_add_notice: { 273 | time: time,//OVERWRITE 274 | self_id: event.self_id, 275 | user_id: event.user_id 276 | } 277 | } 278 | break 279 | //FriendDecreaseEvent 280 | case "friend.recall"://OMIT 281 | data = { 282 | friend_recall_notice: { 283 | time: time,//OVERWRITE 284 | self_id: event.self_id, 285 | user_id: event.user_id, 286 | message_id: event.message_id 287 | } 288 | } 289 | break 290 | //FriendPokeEvent OVERWRITE 291 | case "friend.poke"://OMIT 292 | data = { 293 | private_message: { 294 | time: time,//OVERWRITE 295 | self_id: event.self_id, 296 | sub_type: "friend",//OVERWRITE 297 | user_id: event.user_id, 298 | message: [{poke: {}}],//TODO 299 | sender: { 300 | user_id: event.operator_id, 301 | nickname: event.sender.nickname, 302 | }, 303 | to_me: event.target_id === event.self_id, 304 | } 305 | } 306 | break 307 | //MemberIncreaseEvent 308 | case "group.increase"://OMIT 309 | data = { 310 | group_increase_notice: { 311 | time: time,//OVERWRITE 312 | self_id: event.self_id, 313 | sub_type: event.sub_type, 314 | user_id: event.user_id, 315 | group_id: event.group_id, 316 | operator_id: 0//JS UNIMPLEMENTED 317 | } 318 | } 319 | break 320 | //MemberDecreaseEvent 321 | case "group.decrease"://OMIT 322 | data = { 323 | group_decrease_notice: { 324 | time: time,//OVERWRITE 325 | self_id: event.self_id, 326 | sub_type: event.sub_type, 327 | user_id: event.user_id, 328 | group_id: event.group_id, 329 | operator_id: event.operator_id 330 | } 331 | } 332 | break 333 | //GroupRecallEvent 334 | case "group.recall"://OMIT 335 | data = { 336 | group_recall_notice: { 337 | time: time,//OVERWRITE 338 | self_id: event.self_id, 339 | user_id: event.user_id, 340 | group_id: event.group_id, 341 | operator_id: event.operator_id, 342 | message_id: event.message_id 343 | } 344 | } 345 | break 346 | //GroupMuteEvent 347 | case "group.ban"://OMIT 348 | data = { 349 | group_ban_notice: { 350 | time: time,//OVERWRITE 351 | self_id: event.self_id, 352 | sub_type: event.duration ? "ban" : "lift_ban", 353 | user_id: event.user_id, 354 | group_id: event.group_id, 355 | operator_id: event.operator_id, 356 | duration: event.duration 357 | } 358 | } 359 | break 360 | //GroupAdminEvent 361 | case "group.admin": 362 | data = { 363 | group_admin_notice: { 364 | time: time,//OVERWRITE 365 | self_id: event.self_id, 366 | sub_type: event.set ? "set" : "unset", 367 | user_id: event.user_id, 368 | group_id: event.group_id 369 | } 370 | } 371 | break 372 | //GroupPokeEvent 373 | case "group.poke"://OMIT 374 | data = { 375 | poke_notify: { 376 | time: time,//OVERWRITE 377 | self_id: event.self_id, 378 | post_type: event.post_type, 379 | notice_type: "notify",//OVERWRITE 380 | sub_type: event.sub_type, 381 | user_id: event.user_id, 382 | target_id: event.target_id, 383 | group_id: event.group_id 384 | } 385 | } 386 | break 387 | default: 388 | return `[py-plugin][before-match-notice] 未知的notice类型` 389 | } 390 | call_back(channel, data) 391 | } 392 | -------------------------------------------------------------------------------- /yunzai_nonebot/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from pathlib import Path 3 | 4 | import nonebot 5 | from nonebot import * 6 | 7 | from .hijack import hijack_driver, hijack_logger, hijack_adapter, hijack_params, hijack_event, hijack_matcher, \ 8 | hijack_plugin 9 | 10 | 11 | def init(config_path: Path): 12 | plugins_path = config_path.parent / "plugins" 13 | sys.path.append(str(plugins_path)) 14 | for i in plugins_path.iterdir(): 15 | sys.path.append(str(i)) 16 | 17 | hijack_logger() 18 | hijack_params() 19 | hijack_event() 20 | driver = hijack_driver(config_path) 21 | logger.configure( 22 | extra={"log_level": driver.config.log_level, "independent": driver.config.dict().get("independent")} 23 | ) 24 | adapter = hijack_adapter() 25 | driver.register_adapter(adapter) 26 | hijack_matcher() 27 | hijack_plugin() 28 | 29 | 30 | def run(*args, **kwargs): 31 | nonebot.run(*args, **kwargs) 32 | -------------------------------------------------------------------------------- /yunzai_nonebot/hijack/__init__.py: -------------------------------------------------------------------------------- 1 | from .driver import hijack_driver 2 | from .logger import hijack_logger 3 | from .adapter import hijack_adapter 4 | from .params import hijack_params 5 | from .event import hijack_event 6 | from .message import hijack_matcher 7 | from .plugin import hijack_plugin 8 | -------------------------------------------------------------------------------- /yunzai_nonebot/hijack/adapter.py: -------------------------------------------------------------------------------- 1 | from typing import Any 2 | 3 | from nonebot import Bot, logger 4 | from nonebot.adapters.onebot import V11Adapter, V12Adapter, V11Bot, V12Bot 5 | 6 | from yunzai_nonebot.utils import AsyncMap, AsyncQueue, v11_to_request, result_to_v11, v12_to_request, result_to_v12 7 | from .driver import GRPCDriver 8 | 9 | 10 | class OneAdapter(V11Adapter, V12Adapter): 11 | def __init__(self, driver: GRPCDriver, **kwargs: Any): 12 | super().__init__(driver, **kwargs) 13 | 14 | @classmethod 15 | def get_name(cls) -> str: 16 | return "OneAdapter" 17 | 18 | async def _call_api(self, bot: Bot, api: str, **data: Any) -> Any: 19 | if api == "get_group_at_all_remain": 20 | return { 21 | "can_at_all": True, 22 | "remain_at_all_count_for_group": 100, 23 | "remain_at_all_count_for_uin": 100, 24 | } 25 | 26 | if isinstance(bot, V11Bot): 27 | request_type, request = v11_to_request(bot, api, **data) 28 | request_id = await AsyncQueue(bot.self_id).put(request_type, request) 29 | result = await AsyncMap(bot.self_id).get(request_id) 30 | if not result: 31 | logger.error(f"ob11获取result失败:{request_type}({request_id})") 32 | return None 33 | 34 | return result_to_v11(result) 35 | if isinstance(bot, V12Bot): 36 | request_type, request = v12_to_request(bot, api, **data) 37 | request_id = await AsyncQueue(bot.self_id).put(request_type, request) 38 | result = await AsyncMap(bot.self_id).get(request_id) 39 | if not result: 40 | logger.error(f"ob12获取result失败:{request_type}({request_id})") 41 | return None 42 | 43 | return result_to_v12(result) 44 | 45 | 46 | def hijack_adapter(): 47 | return OneAdapter 48 | -------------------------------------------------------------------------------- /yunzai_nonebot/hijack/bot.py: -------------------------------------------------------------------------------- 1 | from typing import Union, Any, TYPE_CHECKING 2 | 3 | from nonebot.message import handle_event 4 | from nonebot.adapters.onebot import v11, v12 5 | from nonebot.internal.adapter import Bot, Event, Message, MessageSegment 6 | 7 | from yunzai_nonebot.rpc import hola_pb2 8 | from yunzai_nonebot.utils import event_to_v11, event_to_v12 9 | from .event import OneEvent 10 | 11 | if TYPE_CHECKING: 12 | from .adapter import OneAdapter 13 | 14 | 15 | class OneBot(Bot): 16 | def __init__(self, adapter: "OneAdapter", self_id: str): 17 | super().__init__(adapter, self_id) 18 | self.v11 = v11.bot.Bot(adapter, self_id) 19 | self.v12 = v12.bot.Bot(adapter, self_id, "yunzai", "yunzai") 20 | 21 | async def send(self, event: OneEvent, message: Union[str, Message, MessageSegment], **kwargs: Any) -> Any: 22 | if kwargs.pop("at_sender", None): 23 | message = v11.MessageSegment.at(event.v11.sender.user_id) + message 24 | 25 | return await self.adapter._call_api( 26 | self.v11, 27 | "send_msg", 28 | detail_type=event.v11.message_type, 29 | user_id=event.v11.dict().get("user_id"), 30 | group_id=event.v11.dict().get("group_id"), 31 | message=message 32 | ) 33 | 34 | async def handle_event(self, event: hola_pb2.Event) -> None: 35 | await handle_event( 36 | self, 37 | OneEvent( 38 | v11=event_to_v11(self.v11, event), 39 | v12=event_to_v12(event), 40 | plugins=event.plugins 41 | ) 42 | ) 43 | -------------------------------------------------------------------------------- /yunzai_nonebot/hijack/driver.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import traceback 3 | from pathlib import Path 4 | from typing import Type, Callable, Union, Awaitable, Set, Optional, AsyncGenerator, Any, TYPE_CHECKING 5 | 6 | import nonebot 7 | from nonebot.log import logger 8 | from nonebot.config import Env, Config 9 | from nonebot.internal.driver import Driver 10 | from omegaconf import OmegaConf 11 | 12 | from yunzai_nonebot.utils import Servicer, AsyncMap 13 | from yunzai_nonebot.rpc import hola_pb2 14 | from yunzai_nonebot.hijack.bot import OneBot 15 | 16 | if TYPE_CHECKING: 17 | from yunzai_nonebot.hijack.adapter import OneAdapter 18 | 19 | HOOK_FUNC = Union[Callable[[], None], Callable[[], Awaitable[None]]] 20 | 21 | 22 | class GRPCDriver(Driver): 23 | 24 | def __init__(self, config: Config): 25 | super().__init__(Env(), config) 26 | self.startup_funcs: Set[HOOK_FUNC] = set() 27 | self.shutdown_funcs: Set[HOOK_FUNC] = set() 28 | self.servicer = Servicer(self.handler, config) 29 | self.adapter: Optional["OneAdapter"] = None 30 | 31 | @property 32 | def type(self) -> str: 33 | return "grpc_driver" 34 | 35 | @property 36 | def logger(self): 37 | return logger 38 | 39 | def run(self, *args, **kwargs): 40 | loop = asyncio.get_event_loop() 41 | try: 42 | loop.run_until_complete(self.serve()) 43 | except KeyboardInterrupt: 44 | logger.info("已强制退出Py服务器") 45 | loop.run_until_complete(self.servicer.server.stop(0)) 46 | 47 | def on_startup(self, func: HOOK_FUNC) -> HOOK_FUNC: 48 | self.startup_funcs.add(func) 49 | return func 50 | 51 | def on_shutdown(self, func: HOOK_FUNC) -> HOOK_FUNC: 52 | self.shutdown_funcs.add(func) 53 | return func 54 | 55 | async def serve(self): 56 | logger.info("开机中..") 57 | await self.servicer.server.start() 58 | 59 | if self.config.dict().get("setup_check") is not False: 60 | logger.info("检查与更新插件资源...") 61 | await self.startup() 62 | 63 | await asyncio.sleep(2) 64 | logger.info("Py服务器已开机(Py started)") 65 | try: 66 | await self.servicer.server.wait_for_termination() 67 | except asyncio.exceptions.CancelledError: 68 | if self.config.dict().get("shutdown_check") is not False: 69 | logger.info("关机检查...") 70 | await self.shutdown() 71 | logger.info("已关机") 72 | 73 | async def startup(self): 74 | for handler in self.startup_funcs: 75 | try: 76 | if asyncio.iscoroutinefunction(handler): 77 | await handler() 78 | else: 79 | handler() 80 | except: 81 | logger.warning(traceback.format_exc()) 82 | 83 | async def shutdown(self): 84 | for handler in self.shutdown_funcs: 85 | try: 86 | if asyncio.iscoroutinefunction(handler): 87 | await handler() 88 | else: 89 | handler() 90 | except: 91 | logger.warning(traceback.format_exc()) 92 | 93 | def register_adapter(self, adapter: Type["OneAdapter"], **kwargs) -> None: 94 | self.adapter = adapter(self, **kwargs) 95 | 96 | async def handler(self, self_id: str, request_iterator: AsyncGenerator[hola_pb2.ToServer, Any]): 97 | if bot := self.adapter.bots.get(self_id): 98 | self.adapter.bot_disconnect(bot) 99 | 100 | self.adapter.bot_connect(OneBot(self.adapter, self_id)) 101 | result_store = AsyncMap(self_id) 102 | try: 103 | async for grpc_request in request_iterator: 104 | try: 105 | grpc_request_type = grpc_request.WhichOneof("to_server_type") 106 | if grpc_request_type == "event": 107 | logger.debug(f"收到消息:{grpc_request}") 108 | asyncio.create_task(self.adapter.bots[self_id].handle_event(grpc_request.event)) 109 | elif grpc_request_type == "result": 110 | logger.debug(f"收到请求结果:{grpc_request}") 111 | asyncio.create_task(result_store.set(grpc_request.result.request_id, grpc_request.result)) 112 | except Exception: 113 | logger.error(traceback.format_exc()) 114 | except StopAsyncIteration: 115 | logger.warning("中断request连接") 116 | 117 | 118 | def hijack_driver(config_path: Path): 119 | fields = Config.__fields__ 120 | yaml = {} 121 | for k, v in OmegaConf.to_object(OmegaConf.load(config_path)).items(): 122 | if field := fields.get(k): 123 | yaml[k.lower()] = field.default.__class__(v) 124 | else: 125 | yaml[k.lower()] = v 126 | yaml["plugins"] = yaml.get("plugins") or [] 127 | logger.info(yaml) 128 | config = Config.parse_obj(yaml) 129 | driver = GRPCDriver(config) 130 | nonebot._driver = driver 131 | return driver 132 | -------------------------------------------------------------------------------- /yunzai_nonebot/hijack/event.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | from nonebot.adapters.onebot import v11, v12 4 | from nonebot.internal.adapter import Event 5 | 6 | 7 | class OneEvent(Event): 8 | def get_event_name(self) -> str: 9 | return self.v11.get_event_name() 10 | 11 | def get_event_description(self) -> str: 12 | return self.v11.get_event_description() 13 | 14 | def get_user_id(self) -> str: 15 | return self.v11.get_user_id() 16 | 17 | def get_session_id(self) -> str: 18 | return self.v11.get_session_id() 19 | 20 | def get_message(self) -> "Message": 21 | return self.v11.get_message() 22 | 23 | def is_tome(self) -> bool: 24 | return self.v11.is_tome() 25 | 26 | def get_type(self) -> str: 27 | return self.v11.get_type() 28 | 29 | 30 | def strip(func): 31 | def wrapper(*args, **kwargs): 32 | description = func(*args, **kwargs) 33 | return re.sub("Message \d+ ", "", description) 34 | 35 | return wrapper 36 | 37 | 38 | def hijack_event(): 39 | v11.GroupMessageEvent.get_event_description = strip(v11.GroupMessageEvent.get_event_description) 40 | v11.PrivateMessageEvent.get_event_description = strip(v11.PrivateMessageEvent.get_event_description) 41 | v12.PrivateMessageEvent.get_event_description = strip(v12.PrivateMessageEvent.get_event_description) 42 | v12.PrivateMessageEvent.get_event_description = strip(v12.PrivateMessageEvent.get_event_description) 43 | -------------------------------------------------------------------------------- /yunzai_nonebot/hijack/logger.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | from nonebot.log import logger 5 | 6 | 7 | def default_filter(record): 8 | record["name"] = re.sub( 9 | "(nonebot_plugin_|yunzai_nonebot.hijack.|yunzai_nonebot.utils.|nonebot.)", 10 | "", 11 | record["name"] 12 | ) 13 | record["name"] = re.sub(".*onebot.v1[12].", "onebot", record["name"]) 14 | 15 | if record["name"] in ["internal.matcher.matcher"] and not record["extra"].get("independent"): 16 | return False 17 | if "OneAdapter" in record["message"] and not record["extra"].get("independent"): 18 | return False 19 | record["message"] = record["message"].replace("Event will be handled by", " 触发") 20 | log_level = record["extra"].get("log_level", "INFO") 21 | levelno = logger.level(log_level).no if isinstance(log_level, str) else log_level 22 | return record["level"].no >= levelno 23 | 24 | 25 | default_format: str = ( 26 | "[PyBot]" 27 | "[{time:HH:mm:ss.SSS}]" 28 | "[{level}] " 29 | "[{name}]" 30 | "{message}" 31 | ) 32 | 33 | 34 | def hijack_logger(): 35 | logger.remove() 36 | logger.add( 37 | sys.stdout, 38 | level=0, 39 | diagnose=False, 40 | filter=default_filter, 41 | format=default_format, 42 | ) 43 | -------------------------------------------------------------------------------- /yunzai_nonebot/hijack/message.py: -------------------------------------------------------------------------------- 1 | from nonebot import message 2 | 3 | 4 | def patch(func): 5 | async def wrapper(*args, **kwargs): 6 | matcher = args[0] 7 | event = args[2] 8 | if matcher.plugin_name.replace("-", "_") not in event.plugins: 9 | return 10 | return await func(*args, **kwargs) 11 | 12 | return wrapper 13 | 14 | 15 | def hijack_matcher(): 16 | message._check_matcher = patch(message._check_matcher) 17 | -------------------------------------------------------------------------------- /yunzai_nonebot/hijack/params.py: -------------------------------------------------------------------------------- 1 | from typing import Any, get_args, Union 2 | 3 | from nonebot import logger 4 | from nonebot.internal import params 5 | from nonebot.exception import SkippedException 6 | from nonebot.adapters.onebot import v11, v12 7 | 8 | from .bot import OneBot 9 | from .event import OneEvent 10 | 11 | 12 | async def bot_solve(self, bot: Union[OneBot, v11.Bot, v12.Bot], **kwargs: Any) -> Any: 13 | if not isinstance(bot, OneBot): 14 | return bot 15 | 16 | checker = self.extra.get("checker") 17 | if not checker or get_args(checker.type_) or checker.type_ == v11.bot.Bot: 18 | return bot.v11 19 | 20 | return bot.v12 21 | 22 | 23 | async def bot_check(self, bot: Union[OneBot, v11.Bot, v12.Bot], **kwargs: Any) -> None: 24 | if checker := self.extra.get("checker"): 25 | if not isinstance(bot, OneBot): 26 | params.check_field_type(checker, bot) 27 | else: 28 | types = get_args(checker.type_) or (checker.type_,) 29 | if not any(map(lambda x: issubclass(x, v11.bot.Bot) or issubclass(x, v12.bot.Bot), types)): 30 | logger.error("py-plugin只支持OneBot V11和OneBot V12的插件") 31 | raise SkippedException 32 | 33 | 34 | async def event_solve(self, event: Union[OneEvent, v11.Event, v12.Event], **kwargs: Any) -> Any: 35 | if not isinstance(event, OneEvent): 36 | return event 37 | 38 | checker = self.extra.get("checker") 39 | if not checker or get_args(checker.type_) or issubclass(checker.type_, v11.event.Event): 40 | return event.v11 41 | 42 | return event.v12 43 | 44 | 45 | async def event_check(self, event: Union[OneEvent, v11.Event, v12.Event], **kwargs: Any) -> None: 46 | if checker := self.extra.get("checker"): 47 | if not isinstance(event, OneEvent): 48 | params.check_field_type(checker, event) 49 | else: 50 | types = get_args(checker.type_) or (checker.type_,) 51 | if not any(map(lambda x: issubclass(x, v11.event.Event) or issubclass(x, v12.event.Event), types)): 52 | logger.error("py-plugin只支持OneBot V11和OneBot V12的插件") 53 | raise SkippedException 54 | 55 | 56 | def hijack_params(): 57 | params.BotParam._solve = bot_solve 58 | params.BotParam._check = bot_check 59 | params.EventParam._solve = event_solve 60 | params.EventParam._check = event_check 61 | -------------------------------------------------------------------------------- /yunzai_nonebot/hijack/plugin.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | from typing import Any 3 | 4 | from pydantic import BaseModel 5 | from nonebot import plugin, logger 6 | from nonebot.utils import path_to_module_name, escape_tag 7 | 8 | 9 | class Plugin(BaseModel): 10 | module: Any 11 | 12 | 13 | def load_plugin(self, name): 14 | try: 15 | if name in self.plugins: 16 | module = importlib.import_module(name) 17 | elif name in self._third_party_plugin_names: 18 | module = importlib.import_module(self._third_party_plugin_names[name]) 19 | elif name in self._searched_plugin_names: 20 | module = importlib.import_module( 21 | path_to_module_name(self._searched_plugin_names[name]) 22 | ) 23 | else: 24 | raise RuntimeError(f"没有找到插件: {name}! 请确认是否已安装") 25 | 26 | logger.opt(colors=True).success( 27 | f'插件导入成功"{escape_tag(name)}"' 28 | ) 29 | if (plugin := getattr(module, "__plugin__", None)) is None: 30 | logger.warning(f"修复导入:{name}") 31 | return Plugin(module=__import__(name)) 32 | return plugin 33 | except Exception as e: 34 | logger.opt(colors=True, exception=e).error( 35 | f'插件导入失败 "{escape_tag(name)}"' 36 | ) 37 | 38 | 39 | def hijack_plugin(): 40 | plugin.PluginManager.load_plugin = load_plugin 41 | -------------------------------------------------------------------------------- /yunzai_nonebot/rpc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realhuhu/py-plugin/38996805cba6e85bf28be8d8fae83ffd74ed3a52/yunzai_nonebot/rpc/__init__.py -------------------------------------------------------------------------------- /yunzai_nonebot/rpc/hola.proto: -------------------------------------------------------------------------------- 1 | //python -m grpc_tools.protoc -I . --python_out=. --pyi_out=. --grpc_python_out=. .\yunzai_nonebot\rpc\hola.proto 2 | 3 | syntax = "proto3"; 4 | 5 | package hola; 6 | 7 | service Pipe { 8 | rpc Option (OptionCode) returns (OptionCode) {}; 9 | rpc Channel (stream ToServer) returns (stream ToClient) {}; 10 | } 11 | 12 | //--------message---------// 13 | message OptionCode { 14 | uint64 code = 1; 15 | } 16 | 17 | message ToServer { 18 | oneof to_server_type { 19 | Head head = 1; 20 | Event event = 2; 21 | Result result = 3; 22 | } 23 | } 24 | 25 | message ToClient { 26 | oneof to_client_type { 27 | Request request = 1; 28 | } 29 | } 30 | 31 | message Head { 32 | string self_id = 1; 33 | } 34 | 35 | message Event { 36 | repeated string plugins = 1; 37 | string self_id = 2; 38 | oneof event { 39 | FriendRequestEvent friend_request = 3; 40 | GroupRequestEvent group_request = 4; 41 | PrivateMessageEvent private_message = 5; 42 | GroupMessageEvent group_message = 6; 43 | FriendAddNoticeEvent friend_add_notice = 7; 44 | FriendRecallNoticeEvent friend_recall_notice = 8; 45 | GroupIncreaseNoticeEvent group_increase_notice = 9; 46 | GroupDecreaseNoticeEvent group_decrease_notice = 10; 47 | GroupRecallNoticeEvent group_recall_notice = 11; 48 | GroupBanNoticeEvent group_ban_notice = 12; 49 | GroupAdminNoticeEvent group_admin_notice = 13; 50 | PokeNotifyEvent poke_notify = 14; 51 | } 52 | } 53 | 54 | message Request { 55 | string request_id = 1; 56 | string self_id = 2; 57 | oneof request { 58 | SendMessageRequest send_message = 3; 59 | DeleteMessageRequest delete_message = 4; 60 | GetMessageRequest get_message = 5; 61 | GetForwardMessageRequest get_forward_message = 6; 62 | SendLikeRequest send_like = 7; 63 | SetGroupKickRequest set_group_kick = 8; 64 | SetGroupBanRequest set_group_ban = 9; 65 | SetGroupAnonymousBanRequest set_group_anonymous_ban = 10; 66 | SetGroupWholeBanRequest set_group_whole_ban = 11; 67 | SetGroupAdminRequest set_group_admin = 12; 68 | SetGroupAnonymousRequest set_group_anonymous = 13; 69 | SetGroupCardRequest set_group_card = 14; 70 | SetGroupNameRequest set_group_name = 15; 71 | SetGroupLeaveRequest set_group_leave = 16; 72 | SetGroupSpecialTitleRequest set_group_special_title = 17; 73 | SetFriendAddRequestRequest set_friend_add_request = 18; 74 | SetGroupAddRequestRequest set_group_add_request = 19; 75 | GetSelfInfoRequest get_self_info = 20; 76 | GetUserInfoRequest get_user_info = 21; 77 | GetFriendListRequest get_friend_list = 22; 78 | GetGroupInfoRequest get_group_info = 23; 79 | GetGroupListRequest get_group_list = 24; 80 | GetGroupMemberInfoRequest get_group_member_info = 25; 81 | GetGroupMemberListRequest get_group_member_list = 26; 82 | SendForwardMessageRequest send_forward_message = 27; 83 | } 84 | } 85 | 86 | message Result { 87 | string request_id = 1; 88 | string self_id = 2; 89 | oneof result { 90 | SendMessageResult send_message = 3; 91 | DeleteMessageResult delete_message = 4; 92 | GetMessageResult get_message = 5; 93 | GetForwardMessageResult get_forward_message = 6; 94 | SendLikeResult send_like = 7; 95 | SetGroupKickResult set_group_kick = 8; 96 | SetGroupBanResult set_group_ban = 9; 97 | SetGroupAnonymousBanResult set_group_anonymous_ban = 10; 98 | SetGroupWholeBanResult set_group_whole_ban = 11; 99 | SetGroupAdminResult set_group_admin = 12; 100 | SetGroupAnonymousResult set_group_anonymous = 13; 101 | SetGroupCardResult set_group_card = 14; 102 | SetGroupNameResult set_group_name = 15; 103 | SetGroupLeaveResult set_group_leave = 16; 104 | SetGroupSpecialTitleResult set_group_special_title = 17; 105 | SetFriendAddRequestResult set_friend_add_request = 18; 106 | SetGroupAddRequestResult set_group_add_request = 19; 107 | GetSelfInfoResult get_self_info = 20; 108 | GetUserInfoResult get_user_info = 21; 109 | GetFriendListResult get_friend_list = 22; 110 | GetGroupInfoResult get_group_info = 23; 111 | GetGroupListResult get_group_list = 24; 112 | GetGroupMemberInfoResult get_group_member_info = 25; 113 | GetGroupMemberListResult get_group_member_list = 26; 114 | SendForwardMessageResult send_forward_message = 27; 115 | } 116 | } 117 | //--------model---------// 118 | 119 | message Group { 120 | int64 group_id = 1; 121 | string group_name = 2; 122 | int64 group_create_time = 3; 123 | int64 group_level = 4; 124 | int64 member_count = 5; 125 | int64 max_member_count = 6; 126 | } 127 | 128 | message User { 129 | int64 user_id = 1; 130 | string nickname = 2; 131 | string sex = 3; 132 | string age = 4; 133 | } 134 | 135 | message Friend { 136 | int64 user_id = 1; 137 | string nickname = 2; 138 | string sex = 3; 139 | string remark = 4; 140 | } 141 | 142 | message Member { 143 | int64 group_id = 1; 144 | int64 user_id = 2; 145 | string nickname = 3; 146 | string card = 4; 147 | string sex = 5; 148 | int64 age = 6; 149 | string area = 7; 150 | int64 join_time = 8; 151 | int64 last_sent_time = 9; 152 | int64 level = 10; 153 | string role = 11; 154 | string title = 12; 155 | int64 title_expire_time = 13; 156 | int64 shutup_timestamp = 14; 157 | } 158 | 159 | message Sender { 160 | int64 user_id = 1;//发送者QQ号 161 | string nickname = 2;//昵称 162 | string sex = 3;//性别 {male|female|unknown} 163 | int64 age = 4;//年龄 164 | 165 | //以下在群聊中才有效 166 | string card = 5;//群名片/备注 167 | string area = 6;//地区 168 | string level = 7;//成员等级 169 | string role = 8;//角色 {owner|admin|member} 170 | string title = 9;//专属头衔 171 | } 172 | 173 | message Reply { 174 | int64 time = 1;//发送时间 175 | string message_type = 2;//消息类型 176 | string message_id = 3;//消息ID 177 | int64 real_id = 4;//消息真实ID 178 | Sender sender = 5;//发送人信息 179 | repeated ReceivableMessageSegment message = 6;//消息内容 180 | } 181 | 182 | message Anonymous { 183 | int64 id = 1;//匿名用户ID 184 | string name = 2;//匿名用户名称 185 | string flag = 3;//匿名用户flag,在调用禁言API时需要传入 186 | } 187 | 188 | message ReceivableMessageSegment { 189 | oneof segment { 190 | TextSegment text = 1; 191 | AtSegment at = 2; 192 | FaceSegment face = 3; 193 | RpsSegment rps = 4; 194 | DiceSegment dice = 5; 195 | ImageSegment image = 6; 196 | RecordSegment record = 7; 197 | VideoSegment video = 8; 198 | LocationSegment location = 9; 199 | ShareSegment share = 10; 200 | JsonSegment json = 11; 201 | XmlSegment xml = 12; 202 | PokeSegment poke = 13; 203 | ReplySegment reply = 14; 204 | } 205 | } 206 | 207 | message GroupMessageResponse { 208 | int64 group_id = 1; 209 | repeated SendibleMessageSegment message = 2; 210 | } 211 | 212 | message PrivateMessageResponse { 213 | int64 user_id = 1; 214 | repeated SendibleMessageSegment message = 2; 215 | } 216 | 217 | message SendibleMessageSegment { 218 | oneof segment { 219 | TextSegment text = 1; 220 | FaceSegment face = 2; 221 | ImageSegment image = 3; 222 | RecordSegment record = 4; 223 | VideoSegment video = 5; 224 | AtSegment at = 6; 225 | RpsSegment rps = 7; 226 | DiceSegment dice = 8; 227 | PokeSegment poke = 9; 228 | AnonymousSegment anonymous = 10; 229 | ShareSegment share = 11; 230 | ContactSegment contact = 12; 231 | LocationSegment location = 13; 232 | MusicSegment music = 14; 233 | CustomMusicSegment custom_music = 15; 234 | ReplySegment reply = 16; 235 | XmlSegment xml = 17; 236 | JsonSegment json = 18; 237 | } 238 | } 239 | //--------request---------// 240 | message FriendRequestEvent { 241 | int64 time = 1;//事件发生的时间戳 242 | int64 self_id = 2;//收到事件的机器人QQ号 243 | int64 user_id = 3;//发送请求的QQ号 244 | string comment = 4;//验证信息 245 | string flag = 5;//请求flag,在调用处理请求的API时需要传入 246 | } 247 | 248 | message GroupRequestEvent { 249 | int64 time = 1;//事件发生的时间戳 250 | int64 self_id = 2;//收到事件的机器人QQ号 251 | string sub_type = 3;//请求子类型,分别表示加群请求、邀请登录号入群 {add|invite} 252 | int64 group_id = 4;//群号 253 | int64 user_id = 5;//发送请求的QQ号 254 | string comment = 6;//验证信息 255 | string flag = 7;//请求flag,在调用处理请求的API时需要传入 256 | } 257 | //--------message---------// 258 | message PrivateMessageEvent { 259 | int64 time = 1;//事件发生的时间戳 260 | int64 self_id = 2;//收到事件的机器人QQ号 261 | string sub_type = 3;//消息子类型 {friend|group|other} 262 | string message_id = 4;//消息ID 263 | int64 user_id = 5;//发送者QQ号 264 | repeated ReceivableMessageSegment message = 6;//消息内容 265 | string raw_message = 7;//原始消息内容 266 | Sender sender = 8;//发送人信息 267 | bool to_me = 9;//消息是否与机器人有关 268 | Reply reply = 10;//消息中提取的回复消息 269 | } 270 | 271 | message GroupMessageEvent { 272 | int64 time = 1;//事件发生的时间戳 273 | int64 self_id = 2;//收到事件的机器人QQ号 274 | string sub_type = 3;//消息子类型 {normal|anonymous|notice} 275 | string message_id = 4;//消息ID 276 | int64 group_id = 5;//群号 277 | int64 user_id = 6;//发送者QQ号 278 | Anonymous anonymous = 7;//匿名信息 279 | repeated ReceivableMessageSegment message = 8;//消息内容 280 | string raw_message = 9;//原始消息内容 281 | Sender sender = 10;//发送人信息 282 | bool to_me = 11;//消息是否与机器人有关 283 | Reply reply = 12;//消息中提取的回复消息 284 | } 285 | //--------notice---------// 286 | message FriendAddNoticeEvent { 287 | int64 time = 1;//事件发生的时间戳 288 | int64 self_id = 2;//收到事件的机器人QQ号 289 | int64 user_id = 3;//新添加好友QQ号 290 | } 291 | 292 | message FriendRecallNoticeEvent { 293 | int64 time = 1;//事件发生的时间戳 294 | int64 self_id = 2;//收到事件的机器人QQ号 295 | int64 user_id = 3;//好友QQ号 296 | string message_id = 4;//被撤回的消息ID 297 | } 298 | 299 | message GroupIncreaseNoticeEvent { 300 | int64 time = 1;//事件发生的时间戳 301 | int64 self_id = 2;//收到事件的机器人QQ号 302 | string sub_type = 3;//事件子类型,分别表示管理员已同意入群、管理员邀请入群 {approve|invite} 303 | int64 user_id = 4;//加入者QQ号 304 | int64 group_id = 5;//群号 305 | int64 operator_id = 6;//操作者QQ号 306 | } 307 | 308 | message GroupDecreaseNoticeEvent { 309 | int64 time = 1;//事件发生的时间戳 310 | int64 self_id = 2;//收到事件的机器人QQ号 311 | string sub_type = 3;//消息子类型 {leave|kick|kick_me} 312 | int64 user_id = 4;//离开者QQ号 313 | int64 group_id = 5;//群号 314 | int64 operator_id = 6;//操作者QQ号(如果是主动退群,则和user_id相同) 315 | } 316 | 317 | message GroupRecallNoticeEvent { 318 | int64 time = 1;//事件发生的时间戳 319 | int64 self_id = 2;//收到事件的机器人QQ号 320 | int64 user_id = 3;//消息发送者QQ号 321 | int64 group_id = 4;//群号 322 | int64 operator_id = 5;//操作者QQ号 323 | string message_id = 6;//被撤回的消息ID 324 | } 325 | 326 | message GroupBanNoticeEvent { 327 | int64 time = 1;//事件发生的时间戳 328 | int64 self_id = 2;//收到事件的机器人QQ号 329 | string sub_type = 3;//事件子类型,分别表示禁言、解除禁言 {ban|lift_ban} 330 | int64 user_id = 4;//被禁言QQ号 331 | int64 group_id = 5;//群号 332 | int64 operator_id = 6;//操作者QQ号 333 | int64 duration = 7;//禁言时长,单位秒 334 | } 335 | 336 | message GroupAdminNoticeEvent { 337 | int64 time = 1;//事件发生的时间戳 338 | int64 self_id = 2;//收到事件的机器人QQ号 339 | string sub_type = 3;//消息子类型 {set|unset} 340 | int64 user_id = 4;//管理员QQ号 341 | int64 group_id = 5;//群号 342 | } 343 | 344 | message PokeNotifyEvent { 345 | int64 time = 1;//事件发生的时间戳 346 | int64 self_id = 2;//收到事件的机器人QQ号 347 | int64 user_id = 3;//发送者QQ号 348 | int64 target_id = 4;//被戳者QQ号 349 | int64 group_id = 5;//群号 350 | } 351 | //--------segment---------// 352 | message TextSegment { 353 | string data = 1;//纯文本内容 354 | } 355 | 356 | message AtSegment { 357 | string qq = 1;//@的QQ号,all表示全体成员 358 | } 359 | 360 | message FaceSegment { 361 | string id = 1;//QQ表情ID 362 | } 363 | 364 | message RpsSegment {} 365 | 366 | message DiceSegment {} 367 | 368 | message ImageSegment { 369 | string file = 1;//图片文件名 370 | string type = 2;//图片类型,flash表示闪照,无此参数表示普通图片 371 | string url = 3;//图片URL 372 | 373 | bytes content = 4; // 图片二进制数据(发送) 374 | string timeout = 5; // 超时时间(发送) 375 | } 376 | 377 | message RecordSegment { 378 | string file = 1;//语音文件名 379 | string url = 2;//语音URL 380 | bytes content = 3; // 录音二进制数据(发送) 381 | string timeout = 4; // 超时时间(发送) 382 | } 383 | 384 | message VideoSegment { 385 | string file = 1;//视频文件名 386 | string url = 2;//视频URL 387 | bytes content = 3; // 视频二进制数据(发送) 388 | string timeout = 4; // 超时时间(发送) 389 | } 390 | 391 | message LocationSegment { 392 | string lat = 1;//纬度 393 | string lon = 2;//经度 394 | string title = 3;//标题 395 | string content = 4;//内容描述 396 | } 397 | 398 | message ShareSegment { 399 | string url = 1;//URL 400 | string title = 2;//标题 401 | string content = 3;//内容描述 402 | string image = 4;//图片URL 403 | } 404 | 405 | message JsonSegment { 406 | string data = 1;//JSON内容 407 | } 408 | 409 | message XmlSegment { 410 | string data = 1;//XML内容 411 | } 412 | 413 | message PokeSegment { 414 | string type = 1;//类型 415 | string id = 2;//ID 416 | string name = 3;//表情名(接收) 417 | } 418 | 419 | message ReplySegment { 420 | string id = 1;//回复时引用的消息ID 421 | } 422 | 423 | message AnonymousSegment { 424 | bool ignore = 1;//表示无法匿名时是否继续发送 425 | }//(发送) 426 | 427 | message ContactSegment { 428 | string type = 1;//推荐类型 {qq|group} 429 | string id = 2;//被推荐用户QQ|群号 430 | }//(发送) 431 | 432 | message MusicSegment { 433 | string type = 1;//音乐来源 {qq|163|xm} 434 | int64 id = 2;//歌曲ID 435 | }//(发送) 436 | 437 | message CustomMusicSegment { 438 | string type = 1;//音乐来源 custom 439 | string url = 2;//点击后跳转目标URL 440 | string audio = 3;//音乐URL 441 | string title = 4;//标题 442 | string content = 5;//发送时可选,内容描述 443 | string image = 6;//发送时可选,图片 URL 444 | }//(发送) 445 | 446 | message ForwardSegment { 447 | string name = 1;//名称 448 | string uin = 2;//QQ 449 | repeated SendibleMessageSegment content = 3;//内容 450 | } 451 | 452 | //--------request result---------// 453 | message SendMessageRequest {//v11{send_private_msg|send_group_msg|send_msg} v12{send_message} 454 | string detail_type = 1; 455 | int64 user_id = 2; 456 | int64 group_id = 3; 457 | repeated SendibleMessageSegment message = 4; 458 | } 459 | message SendMessageResult { 460 | string message_id = 1; 461 | int64 time = 2; 462 | } 463 | 464 | message DeleteMessageRequest {//v11{delete_msg} v12{delete_message} 465 | string message_id = 1; 466 | } 467 | message DeleteMessageResult {} 468 | 469 | message GetMessageRequest {//v11{get_msg} 470 | string message_id = 1; 471 | } 472 | message GetMessageResult { 473 | string message_id = 1; 474 | int64 real_id = 2; 475 | Sender sender = 3; 476 | int64 time = 4; 477 | repeated ReceivableMessageSegment message = 5; 478 | } 479 | 480 | message GetForwardMessageRequest {//v11{get_forward_msg} 481 | string id = 1; 482 | } 483 | message GetForwardMessageResult { 484 | repeated ForwardSegment messages = 1; 485 | } //TODO 486 | 487 | message SendLikeRequest {//v11{send_like} 488 | int64 user_id = 1; 489 | int64 times = 2; 490 | } 491 | message SendLikeResult {} 492 | 493 | message SetGroupKickRequest {//v11{set_group_kick} v12{kick_group_member} 494 | int64 group_id = 1; 495 | int64 user_id = 2; 496 | bool reject_add_request = 3; 497 | } 498 | message SetGroupKickResult {} 499 | 500 | message SetGroupBanRequest {//v11{set_group_ban} v12{ban_group_member|unban_group_member} 501 | int64 group_id = 1; 502 | int64 user_id = 2; 503 | int64 duration = 3; 504 | } 505 | message SetGroupBanResult {} 506 | 507 | message SetGroupAnonymousBanRequest {//v11{set_group_anonymous_ban} 508 | int64 group_id = 1; 509 | map anonymous = 2; 510 | string flag = 3; 511 | string anonymous_flag = 4; 512 | int64 duration = 5; 513 | } 514 | message SetGroupAnonymousBanResult {} 515 | 516 | message SetGroupWholeBanRequest {//v11{set_group_whole_ban} 517 | int64 group_id = 1; 518 | bool enable = 2; 519 | } 520 | message SetGroupWholeBanResult {} 521 | 522 | message SetGroupAdminRequest {//v11{set_group_admin} v12{set_group_admin} 523 | int64 group_id = 1; 524 | int64 user_id = 2; 525 | bool enable = 3; 526 | } 527 | message SetGroupAdminResult {} 528 | 529 | message SetGroupAnonymousRequest {//v11{set_group_anonymous} 530 | int64 group_id = 1; 531 | bool enable = 2; 532 | } 533 | message SetGroupAnonymousResult {} 534 | 535 | message SetGroupCardRequest {//v11{set_group_card} 536 | int64 group_id = 1; 537 | int64 user_id = 2; 538 | string card = 3; 539 | } 540 | message SetGroupCardResult {} 541 | 542 | message SetGroupNameRequest {//v11{set_group_name} v12{set_group_name} 543 | int64 group_id = 1; 544 | string group_name = 2; 545 | } 546 | message SetGroupNameResult {} 547 | 548 | message SetGroupLeaveRequest {//v11{set_group_leave} v12{set_group_name} 549 | int64 group_id = 1; 550 | bool is_dismiss = 2; 551 | } 552 | message SetGroupLeaveResult {} 553 | 554 | message SetGroupSpecialTitleRequest {//v11{set_group_special_title} 555 | int64 group_id = 1; 556 | int64 user_id = 2; 557 | string special_title = 3; 558 | int64 duration = 4; 559 | } 560 | message SetGroupSpecialTitleResult {} 561 | 562 | message SetFriendAddRequestRequest {//v11{set_friend_add_request} 563 | string flag = 1; 564 | bool approve = 2; 565 | string remark = 3; 566 | } 567 | message SetFriendAddRequestResult {} 568 | 569 | message SetGroupAddRequestRequest {//v11{set_group_add_request} 570 | string flag = 1; 571 | string sub_type = 2; 572 | bool approve = 3; 573 | string reason = 4; 574 | } 575 | message SetGroupAddRequestResult {} 576 | 577 | message GetSelfInfoRequest {} //v11{get_login_info} v12{get_self_info} 578 | message GetSelfInfoResult { 579 | int64 user_id = 1; 580 | string nickname = 2; 581 | } 582 | 583 | message GetUserInfoRequest {//v11{get_stranger_info} v12{get_user_info} 584 | int64 user_id = 1; 585 | } 586 | message GetUserInfoResult { 587 | User user = 1; 588 | } 589 | 590 | message GetFriendListRequest {} //v11{get_friend_list} v12{get_friend_list} 591 | message GetFriendListResult { 592 | repeated Friend friend_list = 1; 593 | } 594 | 595 | message GetGroupInfoRequest {//v11{get_group_info} v12{get_group_info} 596 | int64 group_id = 1; 597 | } 598 | message GetGroupInfoResult { 599 | Group group = 1; 600 | } 601 | 602 | message GetGroupListRequest {} //v11{get_group_list} v12{get_group_list} 603 | message GetGroupListResult { 604 | repeated Group group_list = 1; 605 | } 606 | 607 | message GetGroupMemberInfoRequest {//v11{get_group_member_info} v12{get_group_member_info} 608 | int64 group_id = 1; 609 | int64 user_id = 2; 610 | } 611 | message GetGroupMemberInfoResult { 612 | Member member = 1; 613 | } 614 | 615 | message GetGroupMemberListRequest {//v11{get_group_member_list} v12{get_group_member_list} 616 | int64 group_id = 1; 617 | } 618 | message GetGroupMemberListResult { 619 | repeated Member member_list = 1; 620 | } 621 | 622 | message SendForwardMessageRequest { 623 | string detail_type = 1; 624 | int64 user_id = 2; 625 | int64 group_id = 3; 626 | repeated ForwardSegment message = 4; 627 | } 628 | message SendForwardMessageResult { 629 | string message_id = 1; 630 | int64 time = 2; 631 | } -------------------------------------------------------------------------------- /yunzai_nonebot/rpc/hola_pb2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by the protocol buffer compiler. DO NOT EDIT! 3 | # source: yunzai_nonebot/rpc/hola.proto 4 | """Generated protocol buffer code.""" 5 | from google.protobuf.internal import builder as _builder 6 | from google.protobuf import descriptor as _descriptor 7 | from google.protobuf import descriptor_pool as _descriptor_pool 8 | from google.protobuf import symbol_database as _symbol_database 9 | # @@protoc_insertion_point(imports) 10 | 11 | _sym_db = _symbol_database.Default() 12 | 13 | 14 | 15 | 16 | DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1dyunzai_nonebot/rpc/hola.proto\x12\x04hola\"\x1a\n\nOptionCode\x12\x0c\n\x04\x63ode\x18\x01 \x01(\x04\"v\n\x08ToServer\x12\x1a\n\x04head\x18\x01 \x01(\x0b\x32\n.hola.HeadH\x00\x12\x1c\n\x05\x65vent\x18\x02 \x01(\x0b\x32\x0b.hola.EventH\x00\x12\x1e\n\x06result\x18\x03 \x01(\x0b\x32\x0c.hola.ResultH\x00\x42\x10\n\x0eto_server_type\">\n\x08ToClient\x12 \n\x07request\x18\x01 \x01(\x0b\x32\r.hola.RequestH\x00\x42\x10\n\x0eto_client_type\"\x17\n\x04Head\x12\x0f\n\x07self_id\x18\x01 \x01(\t\"\xd7\x05\n\x05\x45vent\x12\x0f\n\x07plugins\x18\x01 \x03(\t\x12\x0f\n\x07self_id\x18\x02 \x01(\t\x12\x32\n\x0e\x66riend_request\x18\x03 \x01(\x0b\x32\x18.hola.FriendRequestEventH\x00\x12\x30\n\rgroup_request\x18\x04 \x01(\x0b\x32\x17.hola.GroupRequestEventH\x00\x12\x34\n\x0fprivate_message\x18\x05 \x01(\x0b\x32\x19.hola.PrivateMessageEventH\x00\x12\x30\n\rgroup_message\x18\x06 \x01(\x0b\x32\x17.hola.GroupMessageEventH\x00\x12\x37\n\x11\x66riend_add_notice\x18\x07 \x01(\x0b\x32\x1a.hola.FriendAddNoticeEventH\x00\x12=\n\x14\x66riend_recall_notice\x18\x08 \x01(\x0b\x32\x1d.hola.FriendRecallNoticeEventH\x00\x12?\n\x15group_increase_notice\x18\t \x01(\x0b\x32\x1e.hola.GroupIncreaseNoticeEventH\x00\x12?\n\x15group_decrease_notice\x18\n \x01(\x0b\x32\x1e.hola.GroupDecreaseNoticeEventH\x00\x12;\n\x13group_recall_notice\x18\x0b \x01(\x0b\x32\x1c.hola.GroupRecallNoticeEventH\x00\x12\x35\n\x10group_ban_notice\x18\x0c \x01(\x0b\x32\x19.hola.GroupBanNoticeEventH\x00\x12\x39\n\x12group_admin_notice\x18\r \x01(\x0b\x32\x1b.hola.GroupAdminNoticeEventH\x00\x12,\n\x0bpoke_notify\x18\x0e \x01(\x0b\x32\x15.hola.PokeNotifyEventH\x00\x42\x07\n\x05\x65vent\"\xd7\x0b\n\x07Request\x12\x12\n\nrequest_id\x18\x01 \x01(\t\x12\x0f\n\x07self_id\x18\x02 \x01(\t\x12\x30\n\x0csend_message\x18\x03 \x01(\x0b\x32\x18.hola.SendMessageRequestH\x00\x12\x34\n\x0e\x64\x65lete_message\x18\x04 \x01(\x0b\x32\x1a.hola.DeleteMessageRequestH\x00\x12.\n\x0bget_message\x18\x05 \x01(\x0b\x32\x17.hola.GetMessageRequestH\x00\x12=\n\x13get_forward_message\x18\x06 \x01(\x0b\x32\x1e.hola.GetForwardMessageRequestH\x00\x12*\n\tsend_like\x18\x07 \x01(\x0b\x32\x15.hola.SendLikeRequestH\x00\x12\x33\n\x0eset_group_kick\x18\x08 \x01(\x0b\x32\x19.hola.SetGroupKickRequestH\x00\x12\x31\n\rset_group_ban\x18\t \x01(\x0b\x32\x18.hola.SetGroupBanRequestH\x00\x12\x44\n\x17set_group_anonymous_ban\x18\n \x01(\x0b\x32!.hola.SetGroupAnonymousBanRequestH\x00\x12<\n\x13set_group_whole_ban\x18\x0b \x01(\x0b\x32\x1d.hola.SetGroupWholeBanRequestH\x00\x12\x35\n\x0fset_group_admin\x18\x0c \x01(\x0b\x32\x1a.hola.SetGroupAdminRequestH\x00\x12=\n\x13set_group_anonymous\x18\r \x01(\x0b\x32\x1e.hola.SetGroupAnonymousRequestH\x00\x12\x33\n\x0eset_group_card\x18\x0e \x01(\x0b\x32\x19.hola.SetGroupCardRequestH\x00\x12\x33\n\x0eset_group_name\x18\x0f \x01(\x0b\x32\x19.hola.SetGroupNameRequestH\x00\x12\x35\n\x0fset_group_leave\x18\x10 \x01(\x0b\x32\x1a.hola.SetGroupLeaveRequestH\x00\x12\x44\n\x17set_group_special_title\x18\x11 \x01(\x0b\x32!.hola.SetGroupSpecialTitleRequestH\x00\x12\x42\n\x16set_friend_add_request\x18\x12 \x01(\x0b\x32 .hola.SetFriendAddRequestRequestH\x00\x12@\n\x15set_group_add_request\x18\x13 \x01(\x0b\x32\x1f.hola.SetGroupAddRequestRequestH\x00\x12\x31\n\rget_self_info\x18\x14 \x01(\x0b\x32\x18.hola.GetSelfInfoRequestH\x00\x12\x31\n\rget_user_info\x18\x15 \x01(\x0b\x32\x18.hola.GetUserInfoRequestH\x00\x12\x35\n\x0fget_friend_list\x18\x16 \x01(\x0b\x32\x1a.hola.GetFriendListRequestH\x00\x12\x33\n\x0eget_group_info\x18\x17 \x01(\x0b\x32\x19.hola.GetGroupInfoRequestH\x00\x12\x33\n\x0eget_group_list\x18\x18 \x01(\x0b\x32\x19.hola.GetGroupListRequestH\x00\x12@\n\x15get_group_member_info\x18\x19 \x01(\x0b\x32\x1f.hola.GetGroupMemberInfoRequestH\x00\x12@\n\x15get_group_member_list\x18\x1a \x01(\x0b\x32\x1f.hola.GetGroupMemberListRequestH\x00\x12?\n\x14send_forward_message\x18\x1b \x01(\x0b\x32\x1f.hola.SendForwardMessageRequestH\x00\x42\t\n\x07request\"\xbc\x0b\n\x06Result\x12\x12\n\nrequest_id\x18\x01 \x01(\t\x12\x0f\n\x07self_id\x18\x02 \x01(\t\x12/\n\x0csend_message\x18\x03 \x01(\x0b\x32\x17.hola.SendMessageResultH\x00\x12\x33\n\x0e\x64\x65lete_message\x18\x04 \x01(\x0b\x32\x19.hola.DeleteMessageResultH\x00\x12-\n\x0bget_message\x18\x05 \x01(\x0b\x32\x16.hola.GetMessageResultH\x00\x12<\n\x13get_forward_message\x18\x06 \x01(\x0b\x32\x1d.hola.GetForwardMessageResultH\x00\x12)\n\tsend_like\x18\x07 \x01(\x0b\x32\x14.hola.SendLikeResultH\x00\x12\x32\n\x0eset_group_kick\x18\x08 \x01(\x0b\x32\x18.hola.SetGroupKickResultH\x00\x12\x30\n\rset_group_ban\x18\t \x01(\x0b\x32\x17.hola.SetGroupBanResultH\x00\x12\x43\n\x17set_group_anonymous_ban\x18\n \x01(\x0b\x32 .hola.SetGroupAnonymousBanResultH\x00\x12;\n\x13set_group_whole_ban\x18\x0b \x01(\x0b\x32\x1c.hola.SetGroupWholeBanResultH\x00\x12\x34\n\x0fset_group_admin\x18\x0c \x01(\x0b\x32\x19.hola.SetGroupAdminResultH\x00\x12<\n\x13set_group_anonymous\x18\r \x01(\x0b\x32\x1d.hola.SetGroupAnonymousResultH\x00\x12\x32\n\x0eset_group_card\x18\x0e \x01(\x0b\x32\x18.hola.SetGroupCardResultH\x00\x12\x32\n\x0eset_group_name\x18\x0f \x01(\x0b\x32\x18.hola.SetGroupNameResultH\x00\x12\x34\n\x0fset_group_leave\x18\x10 \x01(\x0b\x32\x19.hola.SetGroupLeaveResultH\x00\x12\x43\n\x17set_group_special_title\x18\x11 \x01(\x0b\x32 .hola.SetGroupSpecialTitleResultH\x00\x12\x41\n\x16set_friend_add_request\x18\x12 \x01(\x0b\x32\x1f.hola.SetFriendAddRequestResultH\x00\x12?\n\x15set_group_add_request\x18\x13 \x01(\x0b\x32\x1e.hola.SetGroupAddRequestResultH\x00\x12\x30\n\rget_self_info\x18\x14 \x01(\x0b\x32\x17.hola.GetSelfInfoResultH\x00\x12\x30\n\rget_user_info\x18\x15 \x01(\x0b\x32\x17.hola.GetUserInfoResultH\x00\x12\x34\n\x0fget_friend_list\x18\x16 \x01(\x0b\x32\x19.hola.GetFriendListResultH\x00\x12\x32\n\x0eget_group_info\x18\x17 \x01(\x0b\x32\x18.hola.GetGroupInfoResultH\x00\x12\x32\n\x0eget_group_list\x18\x18 \x01(\x0b\x32\x18.hola.GetGroupListResultH\x00\x12?\n\x15get_group_member_info\x18\x19 \x01(\x0b\x32\x1e.hola.GetGroupMemberInfoResultH\x00\x12?\n\x15get_group_member_list\x18\x1a \x01(\x0b\x32\x1e.hola.GetGroupMemberListResultH\x00\x12>\n\x14send_forward_message\x18\x1b \x01(\x0b\x32\x1e.hola.SendForwardMessageResultH\x00\x42\x08\n\x06result\"\x8d\x01\n\x05Group\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x12\n\ngroup_name\x18\x02 \x01(\t\x12\x19\n\x11group_create_time\x18\x03 \x01(\x03\x12\x13\n\x0bgroup_level\x18\x04 \x01(\x03\x12\x14\n\x0cmember_count\x18\x05 \x01(\x03\x12\x18\n\x10max_member_count\x18\x06 \x01(\x03\"C\n\x04User\x12\x0f\n\x07user_id\x18\x01 \x01(\x03\x12\x10\n\x08nickname\x18\x02 \x01(\t\x12\x0b\n\x03sex\x18\x03 \x01(\t\x12\x0b\n\x03\x61ge\x18\x04 \x01(\t\"H\n\x06\x46riend\x12\x0f\n\x07user_id\x18\x01 \x01(\x03\x12\x10\n\x08nickname\x18\x02 \x01(\t\x12\x0b\n\x03sex\x18\x03 \x01(\t\x12\x0e\n\x06remark\x18\x04 \x01(\t\"\xff\x01\n\x06Member\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x0f\n\x07user_id\x18\x02 \x01(\x03\x12\x10\n\x08nickname\x18\x03 \x01(\t\x12\x0c\n\x04\x63\x61rd\x18\x04 \x01(\t\x12\x0b\n\x03sex\x18\x05 \x01(\t\x12\x0b\n\x03\x61ge\x18\x06 \x01(\x03\x12\x0c\n\x04\x61rea\x18\x07 \x01(\t\x12\x11\n\tjoin_time\x18\x08 \x01(\x03\x12\x16\n\x0elast_sent_time\x18\t \x01(\x03\x12\r\n\x05level\x18\n \x01(\x03\x12\x0c\n\x04role\x18\x0b \x01(\t\x12\r\n\x05title\x18\x0c \x01(\t\x12\x19\n\x11title_expire_time\x18\r \x01(\x03\x12\x18\n\x10shutup_timestamp\x18\x0e \x01(\x03\"\x8d\x01\n\x06Sender\x12\x0f\n\x07user_id\x18\x01 \x01(\x03\x12\x10\n\x08nickname\x18\x02 \x01(\t\x12\x0b\n\x03sex\x18\x03 \x01(\t\x12\x0b\n\x03\x61ge\x18\x04 \x01(\x03\x12\x0c\n\x04\x63\x61rd\x18\x05 \x01(\t\x12\x0c\n\x04\x61rea\x18\x06 \x01(\t\x12\r\n\x05level\x18\x07 \x01(\t\x12\x0c\n\x04role\x18\x08 \x01(\t\x12\r\n\x05title\x18\t \x01(\t\"\x9f\x01\n\x05Reply\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x14\n\x0cmessage_type\x18\x02 \x01(\t\x12\x12\n\nmessage_id\x18\x03 \x01(\t\x12\x0f\n\x07real_id\x18\x04 \x01(\x03\x12\x1c\n\x06sender\x18\x05 \x01(\x0b\x32\x0c.hola.Sender\x12/\n\x07message\x18\x06 \x03(\x0b\x32\x1e.hola.ReceivableMessageSegment\"3\n\tAnonymous\x12\n\n\x02id\x18\x01 \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x0c\n\x04\x66lag\x18\x03 \x01(\t\"\x9b\x04\n\x18ReceivableMessageSegment\x12!\n\x04text\x18\x01 \x01(\x0b\x32\x11.hola.TextSegmentH\x00\x12\x1d\n\x02\x61t\x18\x02 \x01(\x0b\x32\x0f.hola.AtSegmentH\x00\x12!\n\x04\x66\x61\x63\x65\x18\x03 \x01(\x0b\x32\x11.hola.FaceSegmentH\x00\x12\x1f\n\x03rps\x18\x04 \x01(\x0b\x32\x10.hola.RpsSegmentH\x00\x12!\n\x04\x64ice\x18\x05 \x01(\x0b\x32\x11.hola.DiceSegmentH\x00\x12#\n\x05image\x18\x06 \x01(\x0b\x32\x12.hola.ImageSegmentH\x00\x12%\n\x06record\x18\x07 \x01(\x0b\x32\x13.hola.RecordSegmentH\x00\x12#\n\x05video\x18\x08 \x01(\x0b\x32\x12.hola.VideoSegmentH\x00\x12)\n\x08location\x18\t \x01(\x0b\x32\x15.hola.LocationSegmentH\x00\x12#\n\x05share\x18\n \x01(\x0b\x32\x12.hola.ShareSegmentH\x00\x12!\n\x04json\x18\x0b \x01(\x0b\x32\x11.hola.JsonSegmentH\x00\x12\x1f\n\x03xml\x18\x0c \x01(\x0b\x32\x10.hola.XmlSegmentH\x00\x12!\n\x04poke\x18\r \x01(\x0b\x32\x11.hola.PokeSegmentH\x00\x12#\n\x05reply\x18\x0e \x01(\x0b\x32\x12.hola.ReplySegmentH\x00\x42\t\n\x07segment\"W\n\x14GroupMessageResponse\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12-\n\x07message\x18\x02 \x03(\x0b\x32\x1c.hola.SendibleMessageSegment\"X\n\x16PrivateMessageResponse\x12\x0f\n\x07user_id\x18\x01 \x01(\x03\x12-\n\x07message\x18\x02 \x03(\x0b\x32\x1c.hola.SendibleMessageSegment\"\xc6\x05\n\x16SendibleMessageSegment\x12!\n\x04text\x18\x01 \x01(\x0b\x32\x11.hola.TextSegmentH\x00\x12!\n\x04\x66\x61\x63\x65\x18\x02 \x01(\x0b\x32\x11.hola.FaceSegmentH\x00\x12#\n\x05image\x18\x03 \x01(\x0b\x32\x12.hola.ImageSegmentH\x00\x12%\n\x06record\x18\x04 \x01(\x0b\x32\x13.hola.RecordSegmentH\x00\x12#\n\x05video\x18\x05 \x01(\x0b\x32\x12.hola.VideoSegmentH\x00\x12\x1d\n\x02\x61t\x18\x06 \x01(\x0b\x32\x0f.hola.AtSegmentH\x00\x12\x1f\n\x03rps\x18\x07 \x01(\x0b\x32\x10.hola.RpsSegmentH\x00\x12!\n\x04\x64ice\x18\x08 \x01(\x0b\x32\x11.hola.DiceSegmentH\x00\x12!\n\x04poke\x18\t \x01(\x0b\x32\x11.hola.PokeSegmentH\x00\x12+\n\tanonymous\x18\n \x01(\x0b\x32\x16.hola.AnonymousSegmentH\x00\x12#\n\x05share\x18\x0b \x01(\x0b\x32\x12.hola.ShareSegmentH\x00\x12\'\n\x07\x63ontact\x18\x0c \x01(\x0b\x32\x14.hola.ContactSegmentH\x00\x12)\n\x08location\x18\r \x01(\x0b\x32\x15.hola.LocationSegmentH\x00\x12#\n\x05music\x18\x0e \x01(\x0b\x32\x12.hola.MusicSegmentH\x00\x12\x30\n\x0c\x63ustom_music\x18\x0f \x01(\x0b\x32\x18.hola.CustomMusicSegmentH\x00\x12#\n\x05reply\x18\x10 \x01(\x0b\x32\x12.hola.ReplySegmentH\x00\x12\x1f\n\x03xml\x18\x11 \x01(\x0b\x32\x10.hola.XmlSegmentH\x00\x12!\n\x04json\x18\x12 \x01(\x0b\x32\x11.hola.JsonSegmentH\x00\x42\t\n\x07segment\"c\n\x12\x46riendRequestEvent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x0f\n\x07self_id\x18\x02 \x01(\x03\x12\x0f\n\x07user_id\x18\x03 \x01(\x03\x12\x0f\n\x07\x63omment\x18\x04 \x01(\t\x12\x0c\n\x04\x66lag\x18\x05 \x01(\t\"\x86\x01\n\x11GroupRequestEvent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x0f\n\x07self_id\x18\x02 \x01(\x03\x12\x10\n\x08sub_type\x18\x03 \x01(\t\x12\x10\n\x08group_id\x18\x04 \x01(\x03\x12\x0f\n\x07user_id\x18\x05 \x01(\x03\x12\x0f\n\x07\x63omment\x18\x06 \x01(\t\x12\x0c\n\x04\x66lag\x18\x07 \x01(\t\"\xfa\x01\n\x13PrivateMessageEvent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x0f\n\x07self_id\x18\x02 \x01(\x03\x12\x10\n\x08sub_type\x18\x03 \x01(\t\x12\x12\n\nmessage_id\x18\x04 \x01(\t\x12\x0f\n\x07user_id\x18\x05 \x01(\x03\x12/\n\x07message\x18\x06 \x03(\x0b\x32\x1e.hola.ReceivableMessageSegment\x12\x13\n\x0braw_message\x18\x07 \x01(\t\x12\x1c\n\x06sender\x18\x08 \x01(\x0b\x32\x0c.hola.Sender\x12\r\n\x05to_me\x18\t \x01(\x08\x12\x1a\n\x05reply\x18\n \x01(\x0b\x32\x0b.hola.Reply\"\xae\x02\n\x11GroupMessageEvent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x0f\n\x07self_id\x18\x02 \x01(\x03\x12\x10\n\x08sub_type\x18\x03 \x01(\t\x12\x12\n\nmessage_id\x18\x04 \x01(\t\x12\x10\n\x08group_id\x18\x05 \x01(\x03\x12\x0f\n\x07user_id\x18\x06 \x01(\x03\x12\"\n\tanonymous\x18\x07 \x01(\x0b\x32\x0f.hola.Anonymous\x12/\n\x07message\x18\x08 \x03(\x0b\x32\x1e.hola.ReceivableMessageSegment\x12\x13\n\x0braw_message\x18\t \x01(\t\x12\x1c\n\x06sender\x18\n \x01(\x0b\x32\x0c.hola.Sender\x12\r\n\x05to_me\x18\x0b \x01(\x08\x12\x1a\n\x05reply\x18\x0c \x01(\x0b\x32\x0b.hola.Reply\"F\n\x14\x46riendAddNoticeEvent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x0f\n\x07self_id\x18\x02 \x01(\x03\x12\x0f\n\x07user_id\x18\x03 \x01(\x03\"]\n\x17\x46riendRecallNoticeEvent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x0f\n\x07self_id\x18\x02 \x01(\x03\x12\x0f\n\x07user_id\x18\x03 \x01(\x03\x12\x12\n\nmessage_id\x18\x04 \x01(\t\"\x83\x01\n\x18GroupIncreaseNoticeEvent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x0f\n\x07self_id\x18\x02 \x01(\x03\x12\x10\n\x08sub_type\x18\x03 \x01(\t\x12\x0f\n\x07user_id\x18\x04 \x01(\x03\x12\x10\n\x08group_id\x18\x05 \x01(\x03\x12\x13\n\x0boperator_id\x18\x06 \x01(\x03\"\x83\x01\n\x18GroupDecreaseNoticeEvent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x0f\n\x07self_id\x18\x02 \x01(\x03\x12\x10\n\x08sub_type\x18\x03 \x01(\t\x12\x0f\n\x07user_id\x18\x04 \x01(\x03\x12\x10\n\x08group_id\x18\x05 \x01(\x03\x12\x13\n\x0boperator_id\x18\x06 \x01(\x03\"\x83\x01\n\x16GroupRecallNoticeEvent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x0f\n\x07self_id\x18\x02 \x01(\x03\x12\x0f\n\x07user_id\x18\x03 \x01(\x03\x12\x10\n\x08group_id\x18\x04 \x01(\x03\x12\x13\n\x0boperator_id\x18\x05 \x01(\x03\x12\x12\n\nmessage_id\x18\x06 \x01(\t\"\x90\x01\n\x13GroupBanNoticeEvent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x0f\n\x07self_id\x18\x02 \x01(\x03\x12\x10\n\x08sub_type\x18\x03 \x01(\t\x12\x0f\n\x07user_id\x18\x04 \x01(\x03\x12\x10\n\x08group_id\x18\x05 \x01(\x03\x12\x13\n\x0boperator_id\x18\x06 \x01(\x03\x12\x10\n\x08\x64uration\x18\x07 \x01(\x03\"k\n\x15GroupAdminNoticeEvent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x0f\n\x07self_id\x18\x02 \x01(\x03\x12\x10\n\x08sub_type\x18\x03 \x01(\t\x12\x0f\n\x07user_id\x18\x04 \x01(\x03\x12\x10\n\x08group_id\x18\x05 \x01(\x03\"f\n\x0fPokeNotifyEvent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\x0f\n\x07self_id\x18\x02 \x01(\x03\x12\x0f\n\x07user_id\x18\x03 \x01(\x03\x12\x11\n\ttarget_id\x18\x04 \x01(\x03\x12\x10\n\x08group_id\x18\x05 \x01(\x03\"\x1b\n\x0bTextSegment\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\t\"\x17\n\tAtSegment\x12\n\n\x02qq\x18\x01 \x01(\t\"\x19\n\x0b\x46\x61\x63\x65Segment\x12\n\n\x02id\x18\x01 \x01(\t\"\x0c\n\nRpsSegment\"\r\n\x0b\x44iceSegment\"Y\n\x0cImageSegment\x12\x0c\n\x04\x66ile\x18\x01 \x01(\t\x12\x0c\n\x04type\x18\x02 \x01(\t\x12\x0b\n\x03url\x18\x03 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x04 \x01(\x0c\x12\x0f\n\x07timeout\x18\x05 \x01(\t\"L\n\rRecordSegment\x12\x0c\n\x04\x66ile\x18\x01 \x01(\t\x12\x0b\n\x03url\x18\x02 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x03 \x01(\x0c\x12\x0f\n\x07timeout\x18\x04 \x01(\t\"K\n\x0cVideoSegment\x12\x0c\n\x04\x66ile\x18\x01 \x01(\t\x12\x0b\n\x03url\x18\x02 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x03 \x01(\x0c\x12\x0f\n\x07timeout\x18\x04 \x01(\t\"K\n\x0fLocationSegment\x12\x0b\n\x03lat\x18\x01 \x01(\t\x12\x0b\n\x03lon\x18\x02 \x01(\t\x12\r\n\x05title\x18\x03 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x04 \x01(\t\"J\n\x0cShareSegment\x12\x0b\n\x03url\x18\x01 \x01(\t\x12\r\n\x05title\x18\x02 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x03 \x01(\t\x12\r\n\x05image\x18\x04 \x01(\t\"\x1b\n\x0bJsonSegment\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\t\"\x1a\n\nXmlSegment\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\t\"5\n\x0bPokeSegment\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\n\n\x02id\x18\x02 \x01(\t\x12\x0c\n\x04name\x18\x03 \x01(\t\"\x1a\n\x0cReplySegment\x12\n\n\x02id\x18\x01 \x01(\t\"\"\n\x10\x41nonymousSegment\x12\x0e\n\x06ignore\x18\x01 \x01(\x08\"*\n\x0e\x43ontactSegment\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\n\n\x02id\x18\x02 \x01(\t\"(\n\x0cMusicSegment\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\n\n\x02id\x18\x02 \x01(\x03\"m\n\x12\x43ustomMusicSegment\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x0b\n\x03url\x18\x02 \x01(\t\x12\r\n\x05\x61udio\x18\x03 \x01(\t\x12\r\n\x05title\x18\x04 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x05 \x01(\t\x12\r\n\x05image\x18\x06 \x01(\t\"Z\n\x0e\x46orwardSegment\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0b\n\x03uin\x18\x02 \x01(\t\x12-\n\x07\x63ontent\x18\x03 \x03(\x0b\x32\x1c.hola.SendibleMessageSegment\"{\n\x12SendMessageRequest\x12\x13\n\x0b\x64\x65tail_type\x18\x01 \x01(\t\x12\x0f\n\x07user_id\x18\x02 \x01(\x03\x12\x10\n\x08group_id\x18\x03 \x01(\x03\x12-\n\x07message\x18\x04 \x03(\x0b\x32\x1c.hola.SendibleMessageSegment\"5\n\x11SendMessageResult\x12\x12\n\nmessage_id\x18\x01 \x01(\t\x12\x0c\n\x04time\x18\x02 \x01(\x03\"*\n\x14\x44\x65leteMessageRequest\x12\x12\n\nmessage_id\x18\x01 \x01(\t\"\x15\n\x13\x44\x65leteMessageResult\"\'\n\x11GetMessageRequest\x12\x12\n\nmessage_id\x18\x01 \x01(\t\"\x94\x01\n\x10GetMessageResult\x12\x12\n\nmessage_id\x18\x01 \x01(\t\x12\x0f\n\x07real_id\x18\x02 \x01(\x03\x12\x1c\n\x06sender\x18\x03 \x01(\x0b\x32\x0c.hola.Sender\x12\x0c\n\x04time\x18\x04 \x01(\x03\x12/\n\x07message\x18\x05 \x03(\x0b\x32\x1e.hola.ReceivableMessageSegment\"&\n\x18GetForwardMessageRequest\x12\n\n\x02id\x18\x01 \x01(\t\"A\n\x17GetForwardMessageResult\x12&\n\x08messages\x18\x01 \x03(\x0b\x32\x14.hola.ForwardSegment\"1\n\x0fSendLikeRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\x03\x12\r\n\x05times\x18\x02 \x01(\x03\"\x10\n\x0eSendLikeResult\"T\n\x13SetGroupKickRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x0f\n\x07user_id\x18\x02 \x01(\x03\x12\x1a\n\x12reject_add_request\x18\x03 \x01(\x08\"\x14\n\x12SetGroupKickResult\"I\n\x12SetGroupBanRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x0f\n\x07user_id\x18\x02 \x01(\x03\x12\x10\n\x08\x64uration\x18\x03 \x01(\x03\"\x13\n\x11SetGroupBanResult\"\xde\x01\n\x1bSetGroupAnonymousBanRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x43\n\tanonymous\x18\x02 \x03(\x0b\x32\x30.hola.SetGroupAnonymousBanRequest.AnonymousEntry\x12\x0c\n\x04\x66lag\x18\x03 \x01(\t\x12\x16\n\x0e\x61nonymous_flag\x18\x04 \x01(\t\x12\x10\n\x08\x64uration\x18\x05 \x01(\x03\x1a\x30\n\x0e\x41nonymousEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x1c\n\x1aSetGroupAnonymousBanResult\";\n\x17SetGroupWholeBanRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x0e\n\x06\x65nable\x18\x02 \x01(\x08\"\x18\n\x16SetGroupWholeBanResult\"I\n\x14SetGroupAdminRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x0f\n\x07user_id\x18\x02 \x01(\x03\x12\x0e\n\x06\x65nable\x18\x03 \x01(\x08\"\x15\n\x13SetGroupAdminResult\"<\n\x18SetGroupAnonymousRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x0e\n\x06\x65nable\x18\x02 \x01(\x08\"\x19\n\x17SetGroupAnonymousResult\"F\n\x13SetGroupCardRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x0f\n\x07user_id\x18\x02 \x01(\x03\x12\x0c\n\x04\x63\x61rd\x18\x03 \x01(\t\"\x14\n\x12SetGroupCardResult\";\n\x13SetGroupNameRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x12\n\ngroup_name\x18\x02 \x01(\t\"\x14\n\x12SetGroupNameResult\"<\n\x14SetGroupLeaveRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x12\n\nis_dismiss\x18\x02 \x01(\x08\"\x15\n\x13SetGroupLeaveResult\"i\n\x1bSetGroupSpecialTitleRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x0f\n\x07user_id\x18\x02 \x01(\x03\x12\x15\n\rspecial_title\x18\x03 \x01(\t\x12\x10\n\x08\x64uration\x18\x04 \x01(\x03\"\x1c\n\x1aSetGroupSpecialTitleResult\"K\n\x1aSetFriendAddRequestRequest\x12\x0c\n\x04\x66lag\x18\x01 \x01(\t\x12\x0f\n\x07\x61pprove\x18\x02 \x01(\x08\x12\x0e\n\x06remark\x18\x03 \x01(\t\"\x1b\n\x19SetFriendAddRequestResult\"\\\n\x19SetGroupAddRequestRequest\x12\x0c\n\x04\x66lag\x18\x01 \x01(\t\x12\x10\n\x08sub_type\x18\x02 \x01(\t\x12\x0f\n\x07\x61pprove\x18\x03 \x01(\x08\x12\x0e\n\x06reason\x18\x04 \x01(\t\"\x1a\n\x18SetGroupAddRequestResult\"\x14\n\x12GetSelfInfoRequest\"6\n\x11GetSelfInfoResult\x12\x0f\n\x07user_id\x18\x01 \x01(\x03\x12\x10\n\x08nickname\x18\x02 \x01(\t\"%\n\x12GetUserInfoRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\x03\"-\n\x11GetUserInfoResult\x12\x18\n\x04user\x18\x01 \x01(\x0b\x32\n.hola.User\"\x16\n\x14GetFriendListRequest\"8\n\x13GetFriendListResult\x12!\n\x0b\x66riend_list\x18\x01 \x03(\x0b\x32\x0c.hola.Friend\"\'\n\x13GetGroupInfoRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\"0\n\x12GetGroupInfoResult\x12\x1a\n\x05group\x18\x01 \x01(\x0b\x32\x0b.hola.Group\"\x15\n\x13GetGroupListRequest\"5\n\x12GetGroupListResult\x12\x1f\n\ngroup_list\x18\x01 \x03(\x0b\x32\x0b.hola.Group\">\n\x19GetGroupMemberInfoRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\x12\x0f\n\x07user_id\x18\x02 \x01(\x03\"8\n\x18GetGroupMemberInfoResult\x12\x1c\n\x06member\x18\x01 \x01(\x0b\x32\x0c.hola.Member\"-\n\x19GetGroupMemberListRequest\x12\x10\n\x08group_id\x18\x01 \x01(\x03\"=\n\x18GetGroupMemberListResult\x12!\n\x0bmember_list\x18\x01 \x03(\x0b\x32\x0c.hola.Member\"z\n\x19SendForwardMessageRequest\x12\x13\n\x0b\x64\x65tail_type\x18\x01 \x01(\t\x12\x0f\n\x07user_id\x18\x02 \x01(\x03\x12\x10\n\x08group_id\x18\x03 \x01(\x03\x12%\n\x07message\x18\x04 \x03(\x0b\x32\x14.hola.ForwardSegment\"<\n\x18SendForwardMessageResult\x12\x12\n\nmessage_id\x18\x01 \x01(\t\x12\x0c\n\x04time\x18\x02 \x01(\x03\x32g\n\x04Pipe\x12.\n\x06Option\x12\x10.hola.OptionCode\x1a\x10.hola.OptionCode\"\x00\x12/\n\x07\x43hannel\x12\x0e.hola.ToServer\x1a\x0e.hola.ToClient\"\x00(\x01\x30\x01\x62\x06proto3') 17 | 18 | _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) 19 | _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'yunzai_nonebot.rpc.hola_pb2', globals()) 20 | if _descriptor._USE_C_DESCRIPTORS == False: 21 | 22 | DESCRIPTOR._options = None 23 | _SETGROUPANONYMOUSBANREQUEST_ANONYMOUSENTRY._options = None 24 | _SETGROUPANONYMOUSBANREQUEST_ANONYMOUSENTRY._serialized_options = b'8\001' 25 | _OPTIONCODE._serialized_start=39 26 | _OPTIONCODE._serialized_end=65 27 | _TOSERVER._serialized_start=67 28 | _TOSERVER._serialized_end=185 29 | _TOCLIENT._serialized_start=187 30 | _TOCLIENT._serialized_end=249 31 | _HEAD._serialized_start=251 32 | _HEAD._serialized_end=274 33 | _EVENT._serialized_start=277 34 | _EVENT._serialized_end=1004 35 | _REQUEST._serialized_start=1007 36 | _REQUEST._serialized_end=2502 37 | _RESULT._serialized_start=2505 38 | _RESULT._serialized_end=3973 39 | _GROUP._serialized_start=3976 40 | _GROUP._serialized_end=4117 41 | _USER._serialized_start=4119 42 | _USER._serialized_end=4186 43 | _FRIEND._serialized_start=4188 44 | _FRIEND._serialized_end=4260 45 | _MEMBER._serialized_start=4263 46 | _MEMBER._serialized_end=4518 47 | _SENDER._serialized_start=4521 48 | _SENDER._serialized_end=4662 49 | _REPLY._serialized_start=4665 50 | _REPLY._serialized_end=4824 51 | _ANONYMOUS._serialized_start=4826 52 | _ANONYMOUS._serialized_end=4877 53 | _RECEIVABLEMESSAGESEGMENT._serialized_start=4880 54 | _RECEIVABLEMESSAGESEGMENT._serialized_end=5419 55 | _GROUPMESSAGERESPONSE._serialized_start=5421 56 | _GROUPMESSAGERESPONSE._serialized_end=5508 57 | _PRIVATEMESSAGERESPONSE._serialized_start=5510 58 | _PRIVATEMESSAGERESPONSE._serialized_end=5598 59 | _SENDIBLEMESSAGESEGMENT._serialized_start=5601 60 | _SENDIBLEMESSAGESEGMENT._serialized_end=6311 61 | _FRIENDREQUESTEVENT._serialized_start=6313 62 | _FRIENDREQUESTEVENT._serialized_end=6412 63 | _GROUPREQUESTEVENT._serialized_start=6415 64 | _GROUPREQUESTEVENT._serialized_end=6549 65 | _PRIVATEMESSAGEEVENT._serialized_start=6552 66 | _PRIVATEMESSAGEEVENT._serialized_end=6802 67 | _GROUPMESSAGEEVENT._serialized_start=6805 68 | _GROUPMESSAGEEVENT._serialized_end=7107 69 | _FRIENDADDNOTICEEVENT._serialized_start=7109 70 | _FRIENDADDNOTICEEVENT._serialized_end=7179 71 | _FRIENDRECALLNOTICEEVENT._serialized_start=7181 72 | _FRIENDRECALLNOTICEEVENT._serialized_end=7274 73 | _GROUPINCREASENOTICEEVENT._serialized_start=7277 74 | _GROUPINCREASENOTICEEVENT._serialized_end=7408 75 | _GROUPDECREASENOTICEEVENT._serialized_start=7411 76 | _GROUPDECREASENOTICEEVENT._serialized_end=7542 77 | _GROUPRECALLNOTICEEVENT._serialized_start=7545 78 | _GROUPRECALLNOTICEEVENT._serialized_end=7676 79 | _GROUPBANNOTICEEVENT._serialized_start=7679 80 | _GROUPBANNOTICEEVENT._serialized_end=7823 81 | _GROUPADMINNOTICEEVENT._serialized_start=7825 82 | _GROUPADMINNOTICEEVENT._serialized_end=7932 83 | _POKENOTIFYEVENT._serialized_start=7934 84 | _POKENOTIFYEVENT._serialized_end=8036 85 | _TEXTSEGMENT._serialized_start=8038 86 | _TEXTSEGMENT._serialized_end=8065 87 | _ATSEGMENT._serialized_start=8067 88 | _ATSEGMENT._serialized_end=8090 89 | _FACESEGMENT._serialized_start=8092 90 | _FACESEGMENT._serialized_end=8117 91 | _RPSSEGMENT._serialized_start=8119 92 | _RPSSEGMENT._serialized_end=8131 93 | _DICESEGMENT._serialized_start=8133 94 | _DICESEGMENT._serialized_end=8146 95 | _IMAGESEGMENT._serialized_start=8148 96 | _IMAGESEGMENT._serialized_end=8237 97 | _RECORDSEGMENT._serialized_start=8239 98 | _RECORDSEGMENT._serialized_end=8315 99 | _VIDEOSEGMENT._serialized_start=8317 100 | _VIDEOSEGMENT._serialized_end=8392 101 | _LOCATIONSEGMENT._serialized_start=8394 102 | _LOCATIONSEGMENT._serialized_end=8469 103 | _SHARESEGMENT._serialized_start=8471 104 | _SHARESEGMENT._serialized_end=8545 105 | _JSONSEGMENT._serialized_start=8547 106 | _JSONSEGMENT._serialized_end=8574 107 | _XMLSEGMENT._serialized_start=8576 108 | _XMLSEGMENT._serialized_end=8602 109 | _POKESEGMENT._serialized_start=8604 110 | _POKESEGMENT._serialized_end=8657 111 | _REPLYSEGMENT._serialized_start=8659 112 | _REPLYSEGMENT._serialized_end=8685 113 | _ANONYMOUSSEGMENT._serialized_start=8687 114 | _ANONYMOUSSEGMENT._serialized_end=8721 115 | _CONTACTSEGMENT._serialized_start=8723 116 | _CONTACTSEGMENT._serialized_end=8765 117 | _MUSICSEGMENT._serialized_start=8767 118 | _MUSICSEGMENT._serialized_end=8807 119 | _CUSTOMMUSICSEGMENT._serialized_start=8809 120 | _CUSTOMMUSICSEGMENT._serialized_end=8918 121 | _FORWARDSEGMENT._serialized_start=8920 122 | _FORWARDSEGMENT._serialized_end=9010 123 | _SENDMESSAGEREQUEST._serialized_start=9012 124 | _SENDMESSAGEREQUEST._serialized_end=9135 125 | _SENDMESSAGERESULT._serialized_start=9137 126 | _SENDMESSAGERESULT._serialized_end=9190 127 | _DELETEMESSAGEREQUEST._serialized_start=9192 128 | _DELETEMESSAGEREQUEST._serialized_end=9234 129 | _DELETEMESSAGERESULT._serialized_start=9236 130 | _DELETEMESSAGERESULT._serialized_end=9257 131 | _GETMESSAGEREQUEST._serialized_start=9259 132 | _GETMESSAGEREQUEST._serialized_end=9298 133 | _GETMESSAGERESULT._serialized_start=9301 134 | _GETMESSAGERESULT._serialized_end=9449 135 | _GETFORWARDMESSAGEREQUEST._serialized_start=9451 136 | _GETFORWARDMESSAGEREQUEST._serialized_end=9489 137 | _GETFORWARDMESSAGERESULT._serialized_start=9491 138 | _GETFORWARDMESSAGERESULT._serialized_end=9556 139 | _SENDLIKEREQUEST._serialized_start=9558 140 | _SENDLIKEREQUEST._serialized_end=9607 141 | _SENDLIKERESULT._serialized_start=9609 142 | _SENDLIKERESULT._serialized_end=9625 143 | _SETGROUPKICKREQUEST._serialized_start=9627 144 | _SETGROUPKICKREQUEST._serialized_end=9711 145 | _SETGROUPKICKRESULT._serialized_start=9713 146 | _SETGROUPKICKRESULT._serialized_end=9733 147 | _SETGROUPBANREQUEST._serialized_start=9735 148 | _SETGROUPBANREQUEST._serialized_end=9808 149 | _SETGROUPBANRESULT._serialized_start=9810 150 | _SETGROUPBANRESULT._serialized_end=9829 151 | _SETGROUPANONYMOUSBANREQUEST._serialized_start=9832 152 | _SETGROUPANONYMOUSBANREQUEST._serialized_end=10054 153 | _SETGROUPANONYMOUSBANREQUEST_ANONYMOUSENTRY._serialized_start=10006 154 | _SETGROUPANONYMOUSBANREQUEST_ANONYMOUSENTRY._serialized_end=10054 155 | _SETGROUPANONYMOUSBANRESULT._serialized_start=10056 156 | _SETGROUPANONYMOUSBANRESULT._serialized_end=10084 157 | _SETGROUPWHOLEBANREQUEST._serialized_start=10086 158 | _SETGROUPWHOLEBANREQUEST._serialized_end=10145 159 | _SETGROUPWHOLEBANRESULT._serialized_start=10147 160 | _SETGROUPWHOLEBANRESULT._serialized_end=10171 161 | _SETGROUPADMINREQUEST._serialized_start=10173 162 | _SETGROUPADMINREQUEST._serialized_end=10246 163 | _SETGROUPADMINRESULT._serialized_start=10248 164 | _SETGROUPADMINRESULT._serialized_end=10269 165 | _SETGROUPANONYMOUSREQUEST._serialized_start=10271 166 | _SETGROUPANONYMOUSREQUEST._serialized_end=10331 167 | _SETGROUPANONYMOUSRESULT._serialized_start=10333 168 | _SETGROUPANONYMOUSRESULT._serialized_end=10358 169 | _SETGROUPCARDREQUEST._serialized_start=10360 170 | _SETGROUPCARDREQUEST._serialized_end=10430 171 | _SETGROUPCARDRESULT._serialized_start=10432 172 | _SETGROUPCARDRESULT._serialized_end=10452 173 | _SETGROUPNAMEREQUEST._serialized_start=10454 174 | _SETGROUPNAMEREQUEST._serialized_end=10513 175 | _SETGROUPNAMERESULT._serialized_start=10515 176 | _SETGROUPNAMERESULT._serialized_end=10535 177 | _SETGROUPLEAVEREQUEST._serialized_start=10537 178 | _SETGROUPLEAVEREQUEST._serialized_end=10597 179 | _SETGROUPLEAVERESULT._serialized_start=10599 180 | _SETGROUPLEAVERESULT._serialized_end=10620 181 | _SETGROUPSPECIALTITLEREQUEST._serialized_start=10622 182 | _SETGROUPSPECIALTITLEREQUEST._serialized_end=10727 183 | _SETGROUPSPECIALTITLERESULT._serialized_start=10729 184 | _SETGROUPSPECIALTITLERESULT._serialized_end=10757 185 | _SETFRIENDADDREQUESTREQUEST._serialized_start=10759 186 | _SETFRIENDADDREQUESTREQUEST._serialized_end=10834 187 | _SETFRIENDADDREQUESTRESULT._serialized_start=10836 188 | _SETFRIENDADDREQUESTRESULT._serialized_end=10863 189 | _SETGROUPADDREQUESTREQUEST._serialized_start=10865 190 | _SETGROUPADDREQUESTREQUEST._serialized_end=10957 191 | _SETGROUPADDREQUESTRESULT._serialized_start=10959 192 | _SETGROUPADDREQUESTRESULT._serialized_end=10985 193 | _GETSELFINFOREQUEST._serialized_start=10987 194 | _GETSELFINFOREQUEST._serialized_end=11007 195 | _GETSELFINFORESULT._serialized_start=11009 196 | _GETSELFINFORESULT._serialized_end=11063 197 | _GETUSERINFOREQUEST._serialized_start=11065 198 | _GETUSERINFOREQUEST._serialized_end=11102 199 | _GETUSERINFORESULT._serialized_start=11104 200 | _GETUSERINFORESULT._serialized_end=11149 201 | _GETFRIENDLISTREQUEST._serialized_start=11151 202 | _GETFRIENDLISTREQUEST._serialized_end=11173 203 | _GETFRIENDLISTRESULT._serialized_start=11175 204 | _GETFRIENDLISTRESULT._serialized_end=11231 205 | _GETGROUPINFOREQUEST._serialized_start=11233 206 | _GETGROUPINFOREQUEST._serialized_end=11272 207 | _GETGROUPINFORESULT._serialized_start=11274 208 | _GETGROUPINFORESULT._serialized_end=11322 209 | _GETGROUPLISTREQUEST._serialized_start=11324 210 | _GETGROUPLISTREQUEST._serialized_end=11345 211 | _GETGROUPLISTRESULT._serialized_start=11347 212 | _GETGROUPLISTRESULT._serialized_end=11400 213 | _GETGROUPMEMBERINFOREQUEST._serialized_start=11402 214 | _GETGROUPMEMBERINFOREQUEST._serialized_end=11464 215 | _GETGROUPMEMBERINFORESULT._serialized_start=11466 216 | _GETGROUPMEMBERINFORESULT._serialized_end=11522 217 | _GETGROUPMEMBERLISTREQUEST._serialized_start=11524 218 | _GETGROUPMEMBERLISTREQUEST._serialized_end=11569 219 | _GETGROUPMEMBERLISTRESULT._serialized_start=11571 220 | _GETGROUPMEMBERLISTRESULT._serialized_end=11632 221 | _SENDFORWARDMESSAGEREQUEST._serialized_start=11634 222 | _SENDFORWARDMESSAGEREQUEST._serialized_end=11756 223 | _SENDFORWARDMESSAGERESULT._serialized_start=11758 224 | _SENDFORWARDMESSAGERESULT._serialized_end=11818 225 | _PIPE._serialized_start=11820 226 | _PIPE._serialized_end=11923 227 | # @@protoc_insertion_point(module_scope) 228 | -------------------------------------------------------------------------------- /yunzai_nonebot/rpc/hola_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | """Client and server classes corresponding to protobuf-defined services.""" 3 | import grpc 4 | 5 | from yunzai_nonebot.rpc import hola_pb2 as yunzai__nonebot_dot_rpc_dot_hola__pb2 6 | 7 | 8 | class PipeStub(object): 9 | """Missing associated documentation comment in .proto file.""" 10 | 11 | def __init__(self, channel): 12 | """Constructor. 13 | 14 | Args: 15 | channel: A grpc.Channel. 16 | """ 17 | self.Option = channel.unary_unary( 18 | '/hola.Pipe/Option', 19 | request_serializer=yunzai__nonebot_dot_rpc_dot_hola__pb2.OptionCode.SerializeToString, 20 | response_deserializer=yunzai__nonebot_dot_rpc_dot_hola__pb2.OptionCode.FromString, 21 | ) 22 | self.Channel = channel.stream_stream( 23 | '/hola.Pipe/Channel', 24 | request_serializer=yunzai__nonebot_dot_rpc_dot_hola__pb2.ToServer.SerializeToString, 25 | response_deserializer=yunzai__nonebot_dot_rpc_dot_hola__pb2.ToClient.FromString, 26 | ) 27 | 28 | 29 | class PipeServicer(object): 30 | """Missing associated documentation comment in .proto file.""" 31 | 32 | def Option(self, request, context): 33 | """Missing associated documentation comment in .proto file.""" 34 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 35 | context.set_details('Method not implemented!') 36 | raise NotImplementedError('Method not implemented!') 37 | 38 | def Channel(self, request_iterator, context): 39 | """Missing associated documentation comment in .proto file.""" 40 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 41 | context.set_details('Method not implemented!') 42 | raise NotImplementedError('Method not implemented!') 43 | 44 | 45 | def add_PipeServicer_to_server(servicer, server): 46 | rpc_method_handlers = { 47 | 'Option': grpc.unary_unary_rpc_method_handler( 48 | servicer.Option, 49 | request_deserializer=yunzai__nonebot_dot_rpc_dot_hola__pb2.OptionCode.FromString, 50 | response_serializer=yunzai__nonebot_dot_rpc_dot_hola__pb2.OptionCode.SerializeToString, 51 | ), 52 | 'Channel': grpc.stream_stream_rpc_method_handler( 53 | servicer.Channel, 54 | request_deserializer=yunzai__nonebot_dot_rpc_dot_hola__pb2.ToServer.FromString, 55 | response_serializer=yunzai__nonebot_dot_rpc_dot_hola__pb2.ToClient.SerializeToString, 56 | ), 57 | } 58 | generic_handler = grpc.method_handlers_generic_handler( 59 | 'hola.Pipe', rpc_method_handlers) 60 | server.add_generic_rpc_handlers((generic_handler,)) 61 | 62 | 63 | # This class is part of an EXPERIMENTAL API. 64 | class Pipe(object): 65 | """Missing associated documentation comment in .proto file.""" 66 | 67 | @staticmethod 68 | def Option(request, 69 | target, 70 | options=(), 71 | channel_credentials=None, 72 | call_credentials=None, 73 | insecure=False, 74 | compression=None, 75 | wait_for_ready=None, 76 | timeout=None, 77 | metadata=None): 78 | return grpc.experimental.unary_unary(request, target, '/hola.Pipe/Option', 79 | yunzai__nonebot_dot_rpc_dot_hola__pb2.OptionCode.SerializeToString, 80 | yunzai__nonebot_dot_rpc_dot_hola__pb2.OptionCode.FromString, 81 | options, channel_credentials, 82 | insecure, call_credentials, compression, wait_for_ready, timeout, metadata) 83 | 84 | @staticmethod 85 | def Channel(request_iterator, 86 | target, 87 | options=(), 88 | channel_credentials=None, 89 | call_credentials=None, 90 | insecure=False, 91 | compression=None, 92 | wait_for_ready=None, 93 | timeout=None, 94 | metadata=None): 95 | return grpc.experimental.stream_stream(request_iterator, target, '/hola.Pipe/Channel', 96 | yunzai__nonebot_dot_rpc_dot_hola__pb2.ToServer.SerializeToString, 97 | yunzai__nonebot_dot_rpc_dot_hola__pb2.ToClient.FromString, 98 | options, channel_credentials, 99 | insecure, call_credentials, compression, wait_for_ready, timeout, metadata) 100 | -------------------------------------------------------------------------------- /yunzai_nonebot/rpc/typing.py: -------------------------------------------------------------------------------- 1 | from typing import Union 2 | 3 | from .hola_pb2 import * 4 | 5 | GRPCEvent = Union[ 6 | FriendRequestEvent, 7 | GroupRequestEvent, 8 | PrivateMessageEvent, 9 | GroupMessageEvent, 10 | FriendAddNoticeEvent, 11 | FriendRecallNoticeEvent, 12 | GroupIncreaseNoticeEvent, 13 | GroupDecreaseNoticeEvent, 14 | GroupRecallNoticeEvent, 15 | GroupBanNoticeEvent, 16 | GroupAdminNoticeEvent, 17 | PokeNotifyEvent, 18 | ] 19 | 20 | GRPCRequest = Union[ 21 | SendMessageRequest, 22 | DeleteMessageRequest, 23 | GetMessageRequest, 24 | GetForwardMessageRequest, 25 | SendLikeRequest, 26 | SetGroupKickRequest, 27 | SetGroupBanRequest, 28 | SetGroupAnonymousBanRequest, 29 | SetGroupWholeBanRequest, 30 | SetGroupAdminRequest, 31 | SetGroupAnonymousRequest, 32 | SetGroupCardRequest, 33 | SetGroupNameRequest, 34 | SetGroupLeaveRequest, 35 | SetGroupSpecialTitleRequest, 36 | SetFriendAddRequestRequest, 37 | SetGroupAddRequestRequest, 38 | GetSelfInfoRequest, 39 | GetUserInfoRequest, 40 | GetFriendListRequest, 41 | GetGroupInfoRequest, 42 | GetGroupListRequest, 43 | GetGroupMemberInfoRequest, 44 | GetGroupMemberListRequest, 45 | SendForwardMessageRequest 46 | ] 47 | 48 | GRPCResult = Union[ 49 | SendMessageResult, 50 | DeleteMessageResult, 51 | GetMessageResult, 52 | GetForwardMessageResult, 53 | SendLikeResult, 54 | SetGroupKickResult, 55 | SetGroupBanResult, 56 | SetGroupAnonymousBanResult, 57 | SetGroupWholeBanResult, 58 | SetGroupAdminResult, 59 | SetGroupAnonymousResult, 60 | SetGroupCardResult, 61 | SetGroupNameResult, 62 | SetGroupLeaveResult, 63 | SetGroupSpecialTitleResult, 64 | SetFriendAddRequestResult, 65 | SetGroupAddRequestResult, 66 | GetSelfInfoResult, 67 | GetUserInfoResult, 68 | GetFriendListResult, 69 | GetGroupInfoResult, 70 | GetGroupListResult, 71 | GetGroupMemberInfoResult, 72 | GetGroupMemberListResult, 73 | SendForwardMessageResult 74 | ] 75 | 76 | GRPCReceivableMessageSegment = Union[ 77 | TextSegment, 78 | AtSegment, 79 | FaceSegment, 80 | RpsSegment, 81 | DiceSegment, 82 | ImageSegment, 83 | RecordSegment, 84 | VideoSegment, 85 | LocationSegment, 86 | ShareSegment, 87 | JsonSegment, 88 | XmlSegment, 89 | PokeSegment, 90 | ReplySegment, 91 | ] 92 | 93 | GRPCSendibleMessageSegment = Union[ 94 | TextSegment, 95 | FaceSegment, 96 | ImageSegment, 97 | RecordSegment, 98 | VideoSegment, 99 | AtSegment, 100 | RpsSegment, 101 | DiceSegment, 102 | PokeSegment, 103 | AnonymousSegment, 104 | ShareSegment, 105 | ContactSegment, 106 | LocationSegment, 107 | MusicSegment, 108 | CustomMusicSegment, 109 | ReplySegment, 110 | XmlSegment, 111 | JsonSegment, 112 | ] 113 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .queue import AsyncQueue 2 | from .map import AsyncMap 3 | from .service import Servicer 4 | from .serializer import event_to_v11, event_to_v12, result_to_v11, result_to_v12 5 | from .deserializer import v11_to_request, v12_to_request 6 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/deserializer/__init__.py: -------------------------------------------------------------------------------- 1 | from .v11 import v11_to_request 2 | from .v12 import v12_to_request 3 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/deserializer/v11/__init__.py: -------------------------------------------------------------------------------- 1 | from .request import v11_to_request 2 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/deserializer/v11/message.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | from nonebot.adapters.onebot.v11 import Message, Bot, MessageSegment 4 | from yunzai_nonebot.rpc import hola_pb2, typing as GRPCTyping 5 | from .utils import format_file 6 | 7 | 8 | def convert(bot: Bot, message: Message) -> List[GRPCTyping.SendibleMessageSegment]: 9 | grpc_message = [] 10 | for message_segment in message: 11 | if message_segment.type == "anonymous": 12 | data = hola_pb2.AnonymousSegment( 13 | ignore=message_segment.data.get("ignore") 14 | ) 15 | elif message_segment.type == "at": 16 | data = hola_pb2.AtSegment( 17 | qq=message_segment.data.get("qq") 18 | ) 19 | elif message_segment.type == "contact": 20 | data = hola_pb2.ContactSegment( 21 | type=message_segment.data.get("type"), 22 | id=message_segment.data.get("id") 23 | ) 24 | elif message_segment.type == "dice": 25 | data = hola_pb2.DiceSegment() 26 | elif message_segment.type == "face": 27 | data = hola_pb2.FaceSegment( 28 | id=message_segment.data.get("id") 29 | ) 30 | elif message_segment.type == "image": 31 | file = format_file(bot, message_segment.data.get("file")) 32 | data = hola_pb2.ImageSegment( 33 | file=file if isinstance(file, str) else None, 34 | type=message_segment.data.get("type"), 35 | content=file if isinstance(file, bytes) else None, 36 | timeout=message_segment.data.get("timeout"), 37 | ) 38 | elif message_segment.type == "json": 39 | data = hola_pb2.JsonSegment( 40 | data=message_segment.data.get("data") 41 | ) 42 | elif message_segment.type == "location": 43 | data = hola_pb2.LocationSegment( 44 | lat=message_segment.data.get("lat"), 45 | lon=message_segment.data.get("lon"), 46 | title=message_segment.data.get("title"), 47 | content=message_segment.data.get("content"), 48 | ) 49 | elif message_segment.type == "music" and message_segment.data.get("type") == "custom": 50 | data = hola_pb2.CustomMusicSegment( 51 | type="custom", 52 | url=message_segment.data.get("url"), 53 | audio=message_segment.data.get("audio"), 54 | title=message_segment.data.get("title"), 55 | content=message_segment.data.get("content"), 56 | image=message_segment.data.get("image"), 57 | ) 58 | elif message_segment.type == "music": 59 | data = hola_pb2.MusicSegment( 60 | type=message_segment.data.get("type"), 61 | id=message_segment.data.get("id"), 62 | ) 63 | elif message_segment.type == "poke": 64 | data = hola_pb2.PokeSegment( 65 | type=message_segment.data.get("type"), 66 | id=message_segment.data.get("id") 67 | ) 68 | elif message_segment.type == "record": 69 | file = format_file(bot, message_segment.data.get("file")) 70 | data = hola_pb2.RecordSegment( 71 | file=file if isinstance(file, str) else None, 72 | content=file if isinstance(file, bytes) else None, 73 | timeout=message_segment.data.get("timeout"), 74 | ) 75 | elif message_segment.type == "reply": 76 | data = hola_pb2.ReplySegment( 77 | id=message_segment.data.get("id") 78 | ) 79 | elif message_segment.type == "rps": 80 | data = hola_pb2.RpsSegment() 81 | elif message_segment.type == "share": 82 | data = hola_pb2.ShareSegment( 83 | url=message_segment.data.get("url"), 84 | title=message_segment.data.get("title"), 85 | content=message_segment.data.get("content"), 86 | image=message_segment.data.get("image"), 87 | ) 88 | elif message_segment.type == "text": 89 | data = hola_pb2.TextSegment( 90 | data=message_segment.data.get("text") 91 | ) 92 | elif message_segment.type == "video": 93 | file = format_file(bot, message_segment.data.get("file")) 94 | data = hola_pb2.VideoSegment( 95 | file=file if isinstance(file, str) else None, 96 | content=file if isinstance(file, bytes) else None, 97 | timeout=message_segment.data.get("timeout"), 98 | ) 99 | elif message_segment.type == "xml": 100 | data = hola_pb2.XmlSegment( 101 | data=message_segment.data.get("data") 102 | ) 103 | else: 104 | continue 105 | grpc_message.append(hola_pb2.SendibleMessageSegment( 106 | **{message_segment.type: data} 107 | )) 108 | return grpc_message 109 | 110 | 111 | def make_forward(bot, nodes) -> List[GRPCTyping.ForwardSegment]: 112 | forward_list = [] 113 | for node in nodes: 114 | if isinstance(node, MessageSegment): 115 | forward_list.append(hola_pb2.ForwardSegment( 116 | name=node.data.get("user_id") or "2661467107", 117 | uin=str(node.data.get("nickname") or "云崽"), 118 | content=convert(bot, node.data.get("content")) 119 | )) 120 | else: 121 | data = node["data"] 122 | forward_list.append(hola_pb2.ForwardSegment( 123 | name=data.get("name") or "2661467107", 124 | uin=str(data.get("uin") or "云崽"), 125 | content=convert(bot, Message(data["content"])) 126 | )) 127 | return forward_list 128 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/deserializer/v11/request.py: -------------------------------------------------------------------------------- 1 | from typing import Any, Tuple 2 | 3 | from nonebot.adapters.onebot.v11 import Bot, Message 4 | from yunzai_nonebot.rpc import hola_pb2, typing as GRPCTyping 5 | from .message import convert, make_forward 6 | from .utils import message_id_to_str 7 | from yunzai_nonebot.utils.exception import DeserializeRequestError 8 | 9 | 10 | def v11_to_request(bot: Bot, api: str, **data: Any) -> Tuple[str, GRPCTyping.GRPCRequest]: 11 | if api == "send_msg": 12 | return "send_message", hola_pb2.SendMessageRequest( 13 | detail_type=data.get("message_type"), 14 | user_id=data.get("user_id") and int(data.get("user_id")), 15 | group_id=data.get("group_id") and int(data.get("group_id")), 16 | message=convert(bot, Message(data.get("message"))) 17 | ) 18 | if api == "send_private_msg": 19 | return "send_message", hola_pb2.SendMessageRequest( 20 | detail_type="private", 21 | user_id=data.get("user_id") and int(data.get("user_id")), 22 | message=convert(bot, Message(data.get("message"))) 23 | ) 24 | if api == "send_group_msg": 25 | return "send_message", hola_pb2.SendMessageRequest( 26 | detail_type="group", 27 | group_id=data.get("group_id") and int(data.get("group_id")), 28 | message=convert(bot, Message(data.get("message"))) 29 | ) 30 | if api == "delete_msg": 31 | return "delete_message", hola_pb2.DeleteMessageRequest( 32 | message_id=message_id_to_str(data.get("message_id")) 33 | ) 34 | if api == "get_msg": 35 | return "get_message", hola_pb2.GetMessageRequest( 36 | message_id=message_id_to_str(data.get("message_id")) 37 | ) 38 | # if api == "get_forward_msg": 39 | # return 40 | # TODO 41 | if api == "send_like": 42 | return "send_like", hola_pb2.SendLikeRequest( 43 | user_id=data.get("user_id") and int(data.get("user_id")), 44 | times=data.get("times") 45 | ) 46 | if api == "set_group_kick": 47 | return "set_group_kick", hola_pb2.SetGroupKickRequest( 48 | group_id=data.get("group_id") and int(data.get("group_id")), 49 | user_id=data.get("user_id") and int(data.get("user_id")), 50 | reject_add_request=data.get("reject_add_request"), 51 | ) 52 | if api == "set_group_ban": 53 | return "set_group_ban", hola_pb2.SetGroupBanRequest( 54 | group_id=data.get("group_id") and int(data.get("group_id")), 55 | user_id=data.get("user_id") and int(data.get("user_id")), 56 | duration=data.get("duration"), 57 | ) 58 | if api == "set_group_anonymous_ban": 59 | return "set_group_anonymous_ban", hola_pb2.SetGroupAnonymousBanRequest( 60 | group_id=data.get("group_id") and int(data.get("group_id")), 61 | anonymous=data.get("anonymous"), 62 | flag=data.get("flag"), 63 | anonymous_flag=data.get("anonymous_flag"), 64 | duration=data.get("duration"), 65 | ) 66 | if api == "set_group_whole_ban": 67 | return "set_group_whole_ban", hola_pb2.SetGroupWholeBanRequest( 68 | group_id=data.get("group_id") and int(data.get("group_id")), 69 | enable=data.get("enable") 70 | ) 71 | if api == "set_group_admin": 72 | return "set_group_admin", hola_pb2.SetGroupAdminRequest( 73 | group_id=data.get("group_id") and int(data.get("group_id")), 74 | user_id=data.get("user_id") and int(data.get("user_id")), 75 | enable=data.get("enable") 76 | ) 77 | if api == "set_group_anonymous": 78 | return "set_group_anonymous", hola_pb2.SetGroupAnonymousRequest( 79 | group_id=data.get("group_id") and int(data.get("group_id")), 80 | enable=data.get("enable") 81 | ) 82 | if api == "set_group_card": 83 | return "set_group_card", hola_pb2.SetGroupCardRequest( 84 | group_id=data.get("group_id") and int(data.get("group_id")), 85 | user_id=data.get("user_id") and int(data.get("user_id")), 86 | card=data.get("card") 87 | ) 88 | if api == "set_group_name": 89 | return "set_group_name", hola_pb2.SetGroupNameRequest( 90 | group_id=data.get("group_id") and int(data.get("group_id")), 91 | group_name=data.get("group_name"), 92 | ) 93 | if api == "set_group_leave": 94 | return "set_group_leave", hola_pb2.SetGroupLeaveRequest( 95 | group_id=data.get("group_id") and int(data.get("group_id")), 96 | is_dismiss=data.get("is_dismiss") 97 | ) 98 | if api == "set_group_special_title": 99 | return "set_group_special_title", hola_pb2.SetGroupSpecialTitleRequest( 100 | group_id=data.get("group_id") and int(data.get("group_id")), 101 | user_id=data.get("user_id") and int(data.get("user_id")), 102 | special_title=data.get("special_title"), 103 | duration=data.get("duration") 104 | ) 105 | if api == "set_friend_add_request": 106 | return "set_friend_add_request", hola_pb2.SetFriendAddRequestRequest( 107 | flag=data.get("flag"), 108 | approve=data.get("approve"), 109 | remark=data.get("remark") 110 | ) 111 | if api == "set_group_add_request": 112 | return "set_group_add_request", hola_pb2.SetGroupAddRequestRequest( 113 | flag=data.get("flag"), 114 | sub_type=data.get("sub_type"), 115 | approve=data.get("approve"), 116 | reason=data.get("reason"), 117 | ) 118 | if api == "get_login_info": 119 | return "get_self_info", hola_pb2.GetSelfInfoRequest() 120 | if api == "get_stranger_info": 121 | return "get_user_info", hola_pb2.GetUserInfoRequest( 122 | user_id=data.get("user_id") and int(data.get("user_id")) 123 | ) 124 | if api == "get_friend_list": 125 | return "get_friend_list", hola_pb2.GetFriendListRequest() 126 | if api == "get_group_info": 127 | return "get_group_info", hola_pb2.GetGroupInfoRequest( 128 | group_id=data.get("group_id") and int(data.get("group_id")) 129 | ) 130 | if api == "get_group_list": 131 | return "get_group_list", hola_pb2.GetGroupListRequest() 132 | if api == "get_group_member_info": 133 | return "get_group_member_info", hola_pb2.GetGroupMemberInfoRequest( 134 | group_id=data.get("group_id") and int(data.get("group_id")), 135 | user_id=data.get("user_id") and int(data.get("user_id")) 136 | ) 137 | if api == "get_group_member_list": 138 | return "get_group_member_list", hola_pb2.GetGroupMemberListRequest( 139 | group_id=data.get("group_id") and int(data.get("group_id")) 140 | ) 141 | if api == "send_group_forward_msg": 142 | return "send_forward_message", hola_pb2.SendForwardMessageRequest( 143 | detail_type="group", 144 | group_id=data.get("group_id") and int(data.get("group_id")), 145 | message=make_forward(bot, data.get("messages")) 146 | ) 147 | if api == "send_private_forward_msg": 148 | return "send_forward_message", hola_pb2.SendForwardMessageRequest( 149 | detail_type="private", 150 | user_id=data.get("user_id") and int(data.get("user_id")), 151 | message=make_forward(bot, data.get("messages")) 152 | ) 153 | 154 | raise DeserializeRequestError(bot, api) 155 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/deserializer/v11/utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | import base64 3 | from urllib.request import url2pathname 4 | from urllib.parse import urlparse, unquote 5 | from nonebot.adapters.onebot.v11 import Bot 6 | 7 | 8 | def message_id_to_str(message_id: int) -> str: 9 | return base64.b64encode(bytes.fromhex("{:08x}".format(message_id))).decode("utf-8") 10 | 11 | 12 | def format_file(bot: Bot, file): 13 | if hasattr(bot.adapter.config, "server") and isinstance(file, str) and file.startswith("file"): 14 | with open(os.path.normpath(url2pathname(unquote(urlparse(file).path))), "rb") as f: 15 | return f.read() 16 | return file 17 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/deserializer/v12/__init__.py: -------------------------------------------------------------------------------- 1 | from .request import v12_to_request 2 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/deserializer/v12/message.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | from nonebot.adapters.onebot.v12 import Message, Bot 4 | from yunzai_nonebot.rpc import hola_pb2, typing as GRPCTyping 5 | from .utils import format_file 6 | 7 | 8 | def convert(bot: Bot, message: Message) -> List[GRPCTyping.SendibleMessageSegment]: 9 | grpc_message = [] 10 | message_type = None 11 | for message_segment in message: 12 | if message_segment.type == "text": 13 | data = hola_pb2.TextSegment( 14 | data=message_segment.data.get("text") 15 | ) 16 | elif message_segment.type == "mention": 17 | message_type = "at" 18 | data = hola_pb2.AtSegment( 19 | qq=message_segment.data.get("qq") 20 | ) 21 | elif message_segment.type == "mention_all": 22 | message_type = "at" 23 | data = hola_pb2.AtSegment( 24 | qq="all" 25 | ) 26 | elif message_segment.type == "image": 27 | file = format_file(bot, message_segment.data.get("file_id")) 28 | data = hola_pb2.ImageSegment( 29 | file=file if isinstance(file, str) else None, 30 | type=message_segment.data.get("type"), 31 | content=file if isinstance(file, bytes) else None, 32 | timeout=message_segment.data.get("timeout"), 33 | ) 34 | elif message_segment.type == "audio": 35 | message_type = "record" 36 | file = format_file(bot, message_segment.data.get("file_id")) 37 | data = hola_pb2.RecordSegment( 38 | file=file if isinstance(file, str) else None, 39 | content=file if isinstance(file, bytes) else None, 40 | timeout=message_segment.data.get("timeout"), 41 | ) 42 | elif message_segment.type == "video": 43 | file = format_file(bot, message_segment.data.get("file_id")) 44 | data = hola_pb2.VideoSegment( 45 | file=file if isinstance(file, str) else None, 46 | content=file if isinstance(file, bytes) else None, 47 | timeout=message_segment.data.get("timeout"), 48 | ) 49 | elif message_segment.type == "location": 50 | data = hola_pb2.LocationSegment( 51 | lat=message_segment.data.get("latitude"), 52 | lon=message_segment.data.get("longitude"), 53 | title=message_segment.data.get("title"), 54 | content=message_segment.data.get("content"), 55 | ) 56 | elif message_segment.type == "reply": 57 | data = hola_pb2.ReplySegment( 58 | id=message_segment.data.get("message_id") 59 | ) 60 | else: 61 | continue 62 | 63 | grpc_message.append(hola_pb2.SendibleMessageSegment( 64 | **{message_type or message_segment.type: data} 65 | )) 66 | return grpc_message 67 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/deserializer/v12/request.py: -------------------------------------------------------------------------------- 1 | from typing import Any, Tuple 2 | 3 | from nonebot.adapters.onebot.v12 import Bot, Message 4 | from yunzai_nonebot.rpc import hola_pb2, typing as GRPCTyping 5 | from .message import convert 6 | from yunzai_nonebot.utils.exception import DeserializeRequestError 7 | 8 | 9 | def v12_to_request(bot: Bot, api: str, **data: Any) -> Tuple[str, GRPCTyping.GRPCRequest]: 10 | if api == "send_message": 11 | return "send_message", hola_pb2.SendMessageRequest( 12 | detail_type=data.get("detail_type"), 13 | user_id=int(data.get("user_id")), 14 | group_id=int(data.get("group_id")), 15 | message=convert(bot, Message(data.get("message"))) 16 | ) 17 | if api == "delete_message": 18 | return "delete_message", hola_pb2.DeleteMessageRequest( 19 | message_id=data.get("message_id") 20 | ) 21 | if api == "get_self_info": 22 | return "get_self_info", hola_pb2.GetSelfInfoRequest() 23 | if api == "get_user_info": 24 | return "get_user_info", hola_pb2.GetUserInfoRequest( 25 | user_id=int(data.get("user_id")) 26 | ) 27 | if api == "get_friend_list": 28 | return "get_friend_list", hola_pb2.GetFriendListRequest() 29 | if api == "get_group_info": 30 | return "get_group_info", hola_pb2.GetGroupInfoRequest( 31 | group_id=int(data.get("group_id")) 32 | ) 33 | if api == "get_group_list": 34 | return "get_group_list", hola_pb2.GetGroupListRequest() 35 | if api == "get_group_member_info": 36 | return "get_group_member_info", hola_pb2.GetGroupMemberInfoRequest( 37 | group_id=int(data.get("group_id")), 38 | user_id=int(data.get("user_id")) 39 | ) 40 | if api == "get_group_member_list": 41 | return "get_group_member_list", hola_pb2.GetGroupMemberListRequest( 42 | group_id=int(data.get("group_id")) 43 | ) 44 | if api == "set_group_name": 45 | return "set_group_name", hola_pb2.SetGroupNameRequest( 46 | group_id=int(data.get("group_id")), 47 | group_name=data.get("group_name"), 48 | ) 49 | if api == "leave_group": 50 | return "set_group_leave", hola_pb2.SetGroupLeaveRequest( 51 | group_id=int(data.get("group_id")), 52 | ) 53 | raise DeserializeRequestError(bot, api) 54 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/deserializer/v12/utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | from urllib.request import url2pathname 3 | from urllib.parse import urlparse, unquote 4 | from nonebot.adapters.onebot.v12 import Bot 5 | 6 | 7 | def format_file(bot: Bot, file): 8 | if hasattr(bot.adapter.config, "server") and isinstance(file, str) and file.startswith("file"): 9 | with open(os.path.normpath(url2pathname(unquote(urlparse(file).path))), "rb") as f: 10 | return f.read() 11 | return file 12 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/exception.py: -------------------------------------------------------------------------------- 1 | class InitChannelError(Exception): 2 | ... 3 | 4 | 5 | class SerializeEventError(Exception): 6 | def __init__(self, event): 7 | self.event = event 8 | 9 | def __str__(self): 10 | return f"event:{self.event}" 11 | 12 | __repr__ = __str__ 13 | 14 | 15 | class DeserializeRequestError(Exception): 16 | def __init__(self, bot, api): 17 | self.bot = bot 18 | self.api = api 19 | 20 | def __str__(self): 21 | return f"无法处理的api:{self.bot}-{self.api}" 22 | 23 | __repr__ = __str__ 24 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/map.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | from typing import Any, Dict, Optional 3 | 4 | from yunzai_nonebot.rpc import hola_pb2 5 | 6 | 7 | class AsyncMapMCS(type): 8 | instance: Dict[str, Optional["AsyncMap"]] = {} 9 | 10 | def __call__(cls: "AsyncMap", type: str, *args, **kwargs) -> "AsyncMap": 11 | if not cls.__class__.instance.get(type): 12 | cls.__class__.instance[type] = super().__call__(type, *args, **kwargs) 13 | 14 | return cls.__class__.instance[type] 15 | 16 | 17 | class AsyncMap(metaclass=AsyncMapMCS): 18 | def __init__(self, type): 19 | self.type: str = type 20 | self._map: Dict[str, asyncio.Future] = {} 21 | 22 | def __str__(self): 23 | return f"" 24 | 25 | async def set(self, request_id: str, value: Any) -> None: 26 | future = self._map.get(request_id) 27 | if future: 28 | future.set_result(value) 29 | 30 | async def get(self, request_id: str, timeout=10) -> Optional[hola_pb2.Result]: 31 | future = asyncio.get_event_loop().create_future() 32 | self._map[request_id] = future 33 | try: 34 | return await asyncio.wait_for(future, timeout) 35 | except asyncio.TimeoutError: 36 | return None 37 | finally: 38 | del self._map[request_id] 39 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/queue.py: -------------------------------------------------------------------------------- 1 | from uuid import uuid4 2 | from typing import Optional, Dict 3 | from asyncio.queues import LifoQueue 4 | 5 | from yunzai_nonebot.rpc import hola_pb2, typing as GRPCTyping 6 | 7 | 8 | class AsyncQueueMCS(type): 9 | instance: Dict[str, Optional["AsyncQueue"]] = {} 10 | 11 | def __call__(cls: "AsyncQueue", type: str, *args, **kwargs) -> "AsyncQueue": 12 | if not cls.__class__.instance.get(type): 13 | cls.__class__.instance[type] = super().__call__(type, *args, **kwargs) 14 | 15 | return cls.__class__.instance[type] 16 | 17 | 18 | class AsyncQueue(metaclass=AsyncQueueMCS): 19 | def __init__(self, type): 20 | self.queue = LifoQueue() 21 | self.type = type 22 | 23 | def __aiter__(self): 24 | return self 25 | 26 | def __str__(self): 27 | return f"" 28 | 29 | async def __anext__(self): 30 | return await self.queue.get() 31 | 32 | async def put(self, request_type: str, request: GRPCTyping.GRPCRequest) -> str: 33 | request_id = str(uuid4()) 34 | await self.queue.put(hola_pb2.ToClient( 35 | request=hola_pb2.Request( 36 | self_id=self.type, 37 | request_id=request_id, 38 | **{request_type: request} 39 | ) 40 | )) 41 | return request_id 42 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/serializer/__init__.py: -------------------------------------------------------------------------------- 1 | from .v11 import event_to_v11, result_to_v11 2 | from .v12 import event_to_v12, result_to_v12 3 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/serializer/v11/__init__.py: -------------------------------------------------------------------------------- 1 | from .event import event_to_v11 2 | from .result import result_to_v11 3 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/serializer/v11/event.py: -------------------------------------------------------------------------------- 1 | import re 2 | from copy import deepcopy 3 | 4 | from yunzai_nonebot.rpc import hola_pb2 5 | from nonebot.adapters.onebot import v11 6 | from .utils import ( 7 | message_parser, 8 | sender_parser, 9 | reply_parser, 10 | anonymous_parser, 11 | message_id_to_int 12 | ) 13 | from yunzai_nonebot.utils.exception import SerializeEventError 14 | 15 | 16 | def _check_first_at(bot, event: v11.event.MessageEvent) -> None: 17 | if len(event.message) < 2: 18 | return 19 | 20 | if event.message[0].type == "at" and event.message[0].data.get("qq") == event.self_id: 21 | return 22 | 23 | if event.message[0].type == "at" and event.message[1].type == "text": 24 | event.message[0], event.message[1] = event.message[1], event.message[0] 25 | 26 | 27 | def _check_reply(bot, event: v11.event.MessageEvent) -> None: 28 | reply = event.reply 29 | if not reply: 30 | return 31 | 32 | if event.message[0].type == "at" and str(reply.sender.user_id) == event.message[0].data.get("qq"): 33 | event.message.pop(0) 34 | 35 | 36 | def _check_at_me(bot, event: v11.event.MessageEvent) -> None: 37 | if not bot.config.need_at: 38 | event.to_me = True 39 | return 40 | 41 | if not isinstance(event, v11.event.MessageEvent): 42 | return 43 | 44 | # ensure message not empty 45 | if not event.message: 46 | event.message.append(v11.message.MessageSegment.text("")) 47 | 48 | if event.message_type == "private": 49 | event.to_me = True 50 | else: 51 | 52 | def _is_at_me_seg(segment: v11.message.MessageSegment): 53 | return segment.type == "at" and str(segment.data.get("qq", "")) == str( 54 | event.self_id 55 | ) 56 | 57 | # check the first segment 58 | if _is_at_me_seg(event.message[0]): 59 | event.to_me = True 60 | event.message.pop(0) 61 | if event.message and event.message[0].type == "text": 62 | event.message[0].data["text"] = event.message[0].data["text"].lstrip() 63 | if not event.message[0].data["text"]: 64 | del event.message[0] 65 | if event.message and _is_at_me_seg(event.message[0]): 66 | event.message.pop(0) 67 | if event.message and event.message[0].type == "text": 68 | event.message[0].data["text"] = ( 69 | event.message[0].data["text"].lstrip() 70 | ) 71 | if not event.message[0].data["text"]: 72 | del event.message[0] 73 | 74 | if not event.to_me: 75 | # check the last segment 76 | i = -1 77 | last_msg_seg = event.message[i] 78 | if ( 79 | last_msg_seg.type == "text" 80 | and not last_msg_seg.data["text"].strip() 81 | and len(event.message) >= 2 82 | ): 83 | i -= 1 84 | last_msg_seg = event.message[i] 85 | 86 | if _is_at_me_seg(last_msg_seg): 87 | event.to_me = True 88 | del event.message[i:] 89 | 90 | if not event.message: 91 | event.message.append(v11.message.MessageSegment.text("")) 92 | 93 | 94 | def _check_nickname(bot, event: v11.event.MessageEvent) -> None: 95 | if len(event.message) == 0: 96 | return 97 | 98 | first_msg_seg = event.message[0] 99 | if first_msg_seg.type != "text": 100 | return 101 | 102 | nicknames = set(filter(lambda n: n, bot.config.nickname)) 103 | if not nicknames: 104 | return 105 | 106 | nickname_regex = "|".join(nicknames) 107 | first_text = first_msg_seg.data["text"] 108 | if m := re.search(rf"^({nickname_regex})([\s,,]*|$)", first_text, re.IGNORECASE): 109 | event.to_me = True 110 | first_msg_seg.data["text"] = first_text[m.end():] 111 | 112 | 113 | def check(bot, event: v11.event.MessageEvent) -> None: 114 | _check_reply(bot, event) 115 | _check_at_me(bot, event) 116 | _check_nickname(bot, event) 117 | _check_first_at(bot, event) 118 | 119 | 120 | def event_to_v11(bot, event: hola_pb2.Event) -> v11.event.Event: 121 | event_type = event.WhichOneof("event") 122 | if event_type == "friend_request": 123 | event = event.friend_request 124 | return v11.FriendRequestEvent( 125 | time=event.time, 126 | self_id=event.self_id, 127 | post_type="request", 128 | request_type="friend", 129 | user_id=event.user_id, 130 | comment=event.comment, 131 | flag=event.flag 132 | ) 133 | if event_type == "group_request": 134 | event = event.group_request 135 | return v11.GroupRequestEvent( 136 | time=event.time, 137 | self_id=event.self_id, 138 | post_type="request", 139 | request_type="group", 140 | sub_type=event.sub_type, 141 | group_id=event.group_id, 142 | user_id=event.user_id, 143 | comment=event.comment, 144 | flag=event.flag 145 | ) 146 | if event_type == "private_message": 147 | event = event.private_message 148 | message = message_parser(event.message) 149 | event = v11.PrivateMessageEvent( 150 | time=event.time, 151 | self_id=event.self_id, 152 | post_type="message", 153 | sub_type=event.sub_type, 154 | user_id=event.user_id, 155 | message_type="private", 156 | message_id=message_id_to_int(event.message_id), 157 | message=message, 158 | original_message=deepcopy(message), 159 | raw_message=event.raw_message, 160 | font=0, 161 | sender=sender_parser(event.sender), 162 | to_me=event.to_me, 163 | reply=None if not event.reply.time else reply_parser(event.reply) 164 | ) 165 | check(bot, event) 166 | return event 167 | if event_type == "group_message": 168 | event = event.group_message 169 | message = message_parser(event.message) 170 | event = v11.GroupMessageEvent( 171 | time=event.time, 172 | self_id=event.self_id, 173 | post_type="message", 174 | sub_type=event.sub_type, 175 | user_id=event.user_id, 176 | message_type="group", 177 | message_id=message_id_to_int(event.message_id), 178 | message=message, 179 | original_message=deepcopy(message), 180 | raw_message=event.raw_message, 181 | font=0, 182 | sender=sender_parser(event.sender), 183 | to_me=event.to_me, 184 | reply=None if not event.reply.time else reply_parser(event.reply), 185 | group_id=event.group_id, 186 | anonymous=None if not event.anonymous.id else anonymous_parser(event.anonymous), 187 | ) 188 | check(bot, event) 189 | return event 190 | if event_type == "friend_add_notice": 191 | event = event.friend_add_notice 192 | return v11.FriendAddNoticeEvent( 193 | time=event.time, 194 | self_id=event.self_id, 195 | post_type="notice", 196 | notice_type="friend_add", 197 | user_id=event.user_id 198 | ) 199 | if event_type == "friend_recall_notice": 200 | event = event.friend_recall_notice 201 | return v11.FriendRecallNoticeEvent( 202 | time=event.time, 203 | self_id=event.self_id, 204 | post_type="notice", 205 | notice_type="friend_recall", 206 | user_id=event.user_id, 207 | message_id=message_id_to_int(event.message_id), 208 | ) 209 | if event_type == "group_increase_notice": 210 | event = event.group_increase_notice 211 | return v11.GroupIncreaseNoticeEvent( 212 | time=event.time, 213 | self_id=event.self_id, 214 | post_type="notice", 215 | notice_type="group_increase", 216 | sub_type=event.sub_type, 217 | user_id=event.user_id, 218 | group_id=event.group_id, 219 | operator_id=event.operator_id 220 | ) 221 | if event_type == "group_decrease_notice": 222 | event = event.group_decrease_notice 223 | return v11.GroupDecreaseNoticeEvent( 224 | time=event.time, 225 | self_id=event.self_id, 226 | post_type="notice", 227 | notice_type="group_decrease", 228 | sub_type=event.sub_type, 229 | user_id=event.user_id, 230 | group_id=event.group_id, 231 | operator_id=event.operator_id 232 | ) 233 | if event_type == "group_recall_notice": 234 | event = event.group_recall_notice 235 | return v11.GroupRecallNoticeEvent( 236 | time=event.time, 237 | self_id=event.self_id, 238 | post_type="notice", 239 | notice_type="group_recall", 240 | user_id=event.user_id, 241 | group_id=event.group_id, 242 | operator_id=event.operator_id, 243 | message_id=message_id_to_int(event.message_id), 244 | ) 245 | if event_type == "group_ban_notice": 246 | event = event.group_ban_notice 247 | return v11.GroupBanNoticeEvent( 248 | time=event.time, 249 | self_id=event.self_id, 250 | post_type="notice", 251 | notice_type="group_ban", 252 | sub_type=event.sub_type, 253 | user_id=event.user_id, 254 | group_id=event.group_id, 255 | operator_id=event.operator_id, 256 | duration=event.duration 257 | ) 258 | if event_type == "group_admin_notice": 259 | event = event.group_admin_notice 260 | return v11.GroupAdminNoticeEvent( 261 | time=event.time, 262 | self_id=event.self_id, 263 | post_type="notice", 264 | notice_type="group_admin", 265 | sub_type=event.sub_type, 266 | user_id=event.user_id, 267 | group_id=event.group_id, 268 | ) 269 | if event_type == "poke_notify": 270 | event = event.poke_notify 271 | return v11.PokeNotifyEvent( 272 | time=event.time, 273 | self_id=event.self_id, 274 | post_type="notice", 275 | notice_type="notify", 276 | sub_type="poke", 277 | user_id=event.user_id, 278 | target_id=event.target_id, 279 | group_id=event.group_id, 280 | ) 281 | 282 | raise SerializeEventError(event) 283 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/serializer/v11/result.py: -------------------------------------------------------------------------------- 1 | from yunzai_nonebot.rpc import hola_pb2 2 | from .utils import sender_parser, message_parser, message_id_to_int 3 | 4 | 5 | def result_to_v11(result: hola_pb2.Result): 6 | result_type = result.WhichOneof("result") 7 | if result_type == "send_message": 8 | result = result.send_message 9 | return { 10 | "message_id": message_id_to_int(result.message_id), 11 | } 12 | if result_type == "delete_message": 13 | return None 14 | if result_type == "get_message": 15 | result = result.get_message 16 | return { 17 | "message_id": message_id_to_int(result.message_id), 18 | "real_id": result.real_id, 19 | "time": result.time, 20 | "sender": sender_parser(result.sender), 21 | "message": message_parser(result.message) 22 | } 23 | if result_type == "get_forward_message": 24 | return # TODO 25 | if result_type == "send_like": 26 | return None 27 | if result_type == "set_group_kick": 28 | return None 29 | if result_type == "set_group_ban": 30 | return None 31 | if result_type == "set_group_anonymous_ban": 32 | return None 33 | if result_type == "set_group_whole_ban": 34 | return None 35 | if result_type == "set_group_admin": 36 | return None 37 | if result_type == "set_group_anonymous": 38 | return None 39 | if result_type == "set_group_card": 40 | return None 41 | if result_type == "set_group_name": 42 | return None 43 | if result_type == "set_group_leave": 44 | return None 45 | if result_type == "set_group_special_title": 46 | return None 47 | if result_type == "set_friend_add_request": 48 | return None 49 | if result_type == "set_group_add_request": 50 | return None 51 | if result_type == "get_self_info": 52 | result = result.get_self_info 53 | return { 54 | "user_id": result.user_id, 55 | "nickname": result.nickname 56 | } 57 | if result_type == "get_user_info": 58 | result = result.get_user_info.user 59 | return { 60 | "user_id": result.user_id, 61 | "nickname": result.nickname, 62 | "sex": result.sex, 63 | "age": result.age, 64 | } 65 | if result_type == "get_friend_list": 66 | result = result.get_friend_list 67 | return [ 68 | { 69 | "user_id": friend.user_id, 70 | "nickname": friend.nickname, 71 | "sex": friend.sex, 72 | "remark": friend.remark, 73 | } for friend in result.friend_list 74 | ] 75 | if result_type == "get_group_info": 76 | result = result.get_group_info.group 77 | return { 78 | "group_id": result.group_id, 79 | "group_name": result.group_name, 80 | "group_create_time": result.group_create_time, 81 | "group_level": result.group_level, 82 | "member_count": result.member_count, 83 | "max_member_count": result.max_member_count, 84 | } 85 | if result_type == "get_group_list": 86 | result = result.get_group_list 87 | return [ 88 | { 89 | "group_id": group.group_id, 90 | "group_name": group.group_name, 91 | "group_create_time": group.group_create_time, 92 | "group_level": group.group_level, 93 | "member_count": group.member_count, 94 | "max_member_count": group.max_member_count, 95 | } for group in result.group_list 96 | ] 97 | if result_type == "get_group_member_info": 98 | result = result.get_group_member_info.member 99 | return { 100 | "group_id": result.group_id, 101 | "user_id": result.user_id, 102 | "nickname": result.nickname, 103 | "card": result.card, 104 | "sex": result.sex, 105 | "age": result.age, 106 | "area": result.area, 107 | "join_time": result.join_time, 108 | "last_sent_time": result.last_sent_time, 109 | "level": result.level, 110 | "role": result.role, 111 | "title": result.title, 112 | "title_expire_time": result.title_expire_time, 113 | "shutup_timestamp": result.shutup_timestamp, 114 | } 115 | if result_type == "get_group_member_list": 116 | result = result.get_group_member_list 117 | return [ 118 | { 119 | "group_id": member.group_id, 120 | "user_id": member.user_id, 121 | "nickname": member.nickname, 122 | "card": member.card, 123 | "sex": member.sex, 124 | "age": member.age, 125 | "area": member.area, 126 | "join_time": member.join_time, 127 | "last_sent_time": member.last_sent_time, 128 | "level": member.level, 129 | "role": member.role, 130 | "title": member.title, 131 | "title_expire_time": member.title_expire_time, 132 | "shutup_timestamp": member.shutup_timestamp, 133 | } for member in result.member_list 134 | ] 135 | if result_type == "send_forward_message": 136 | result = result.send_forward_message 137 | return { 138 | "message_id": message_id_to_int(result.message_id), 139 | } 140 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/serializer/v11/utils.py: -------------------------------------------------------------------------------- 1 | import base64 2 | from typing import Iterator 3 | 4 | from nonebot.adapters.onebot import v11 5 | from yunzai_nonebot.rpc.hola_pb2 import ReceivableMessageSegment, Sender, Reply, Anonymous 6 | 7 | 8 | def message_id_to_int(message_id: str) -> int: 9 | return int.from_bytes(base64.b64decode(message_id), "big") 10 | 11 | 12 | def message_parser(message: Iterator[ReceivableMessageSegment]) -> v11.message.Message: 13 | serialized_message = v11.message.Message() 14 | for message_segment in message: 15 | message_type = message_segment.WhichOneof("segment") 16 | if message_type == "text": 17 | message_segment = message_segment.text 18 | serialized_message_segment = v11.message.MessageSegment( 19 | type="text", 20 | data={ 21 | "text": message_segment.data 22 | } 23 | ) 24 | elif message_type == "at": 25 | message_segment = message_segment.at 26 | serialized_message_segment = v11.message.MessageSegment( 27 | type="at", 28 | data={ 29 | "qq": message_segment.qq 30 | } 31 | ) 32 | elif message_type == "face": 33 | message_segment = message_segment.face 34 | serialized_message_segment = v11.message.MessageSegment( 35 | type="face", 36 | data={ 37 | "id": message_segment.id 38 | } 39 | ) 40 | elif message_type == "rps": 41 | serialized_message_segment = v11.message.MessageSegment( 42 | type="rps", 43 | data={} 44 | ) 45 | elif message_type == "dice": 46 | serialized_message_segment = v11.message.MessageSegment( 47 | type="dice", 48 | data={} 49 | ) 50 | elif message_type == "image": 51 | message_segment = message_segment.image 52 | serialized_message_segment = v11.message.MessageSegment( 53 | type="image", 54 | data={ 55 | "file": message_segment.file, 56 | "type": message_segment.type, 57 | "url": message_segment.url 58 | } 59 | ) 60 | elif message_type == "record": 61 | message_segment = message_segment.record 62 | serialized_message_segment = v11.message.MessageSegment( 63 | type="record", 64 | data={ 65 | "file": message_segment.file, 66 | "url": message_segment.url 67 | } 68 | ) 69 | elif message_type == "video": 70 | message_segment = message_segment.video 71 | serialized_message_segment = v11.message.MessageSegment( 72 | type="video", 73 | data={ 74 | "file": message_segment.file, 75 | "url": message_segment.url 76 | } 77 | ) 78 | elif message_type == "location": 79 | message_segment = message_segment.location 80 | serialized_message_segment = v11.message.MessageSegment( 81 | type="location", 82 | data={ 83 | "lat": message_segment.lat, 84 | "lon": message_segment.lon, 85 | "title": message_segment.title, 86 | "content": message_segment.content, 87 | } 88 | ) 89 | elif message_type == "share": 90 | message_segment = message_segment.share 91 | serialized_message_segment = v11.message.MessageSegment( 92 | type="share", 93 | data={ 94 | "url": message_segment.url, 95 | "title": message_segment.title, 96 | "content": message_segment.content, 97 | "image": message_segment.image, 98 | } 99 | ) 100 | elif message_type == "json": 101 | message_segment = message_segment.json 102 | serialized_message_segment = v11.message.MessageSegment( 103 | type="json", 104 | data={ 105 | "data": message_segment.data, 106 | } 107 | ) 108 | elif message_type == "xml": 109 | message_segment = message_segment.xml 110 | serialized_message_segment = v11.message.MessageSegment( 111 | type="xml", 112 | data={ 113 | "data": message_segment.data, 114 | } 115 | ) 116 | elif message_type == "poke": 117 | message_segment = message_segment.poke 118 | serialized_message_segment = v11.message.MessageSegment( 119 | type="poke", 120 | data={ 121 | "type": message_segment.type, 122 | "id": message_segment.id, 123 | } 124 | ) 125 | elif message_type == "reply": 126 | message_segment = message_segment.reply 127 | serialized_message_segment = v11.message.MessageSegment( 128 | type="reply", 129 | data={ 130 | "id": message_segment.id, 131 | } 132 | ) 133 | else: 134 | continue 135 | serialized_message.append(serialized_message_segment) 136 | return serialized_message 137 | 138 | 139 | def sender_parser(sender: Sender) -> v11.event.Sender: 140 | return v11.event.Sender( 141 | user_id=sender.user_id, 142 | nickname=sender.nickname, 143 | sex=sender.sex, 144 | age=sender.age, 145 | card=sender.card, 146 | area=sender.area, 147 | level=sender.level, 148 | role=sender.role, 149 | title=sender.title, 150 | ) 151 | 152 | 153 | def reply_parser(reply: Reply) -> v11.event.Reply: 154 | return v11.event.Reply( 155 | time=reply.time, 156 | message_type=reply.message_type, 157 | message_id=message_id_to_int(reply.message_id), 158 | real_id=reply.real_id, 159 | sender=sender_parser(reply.sender), 160 | message=message_parser(reply.message) 161 | ) 162 | 163 | 164 | def anonymous_parser(anonymous: Anonymous) -> v11.event.Anonymous: 165 | return v11.event.Anonymous( 166 | id=anonymous.id, 167 | name=anonymous.name, 168 | flag=anonymous.flag, 169 | ) 170 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/serializer/v12/__init__.py: -------------------------------------------------------------------------------- 1 | from .event import event_to_v12 2 | from .result import result_to_v12 3 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/serializer/v12/event.py: -------------------------------------------------------------------------------- 1 | from uuid import uuid4 2 | from datetime import datetime 3 | from copy import deepcopy 4 | 5 | from yunzai_nonebot.rpc import hola_pb2 6 | from nonebot.adapters.onebot import v12 7 | from .utils import ( 8 | message_parser, 9 | reply_parser, 10 | ) 11 | from yunzai_nonebot.utils.exception import SerializeEventError 12 | 13 | 14 | def event_to_v12(event: hola_pb2.Event) -> v12.event.Event: 15 | self = v12.event.BotSelf(platform="yunzai", user_id=event.self_id) 16 | event_type = event.WhichOneof("event") 17 | if event_type == "private_message": 18 | event = event.private_message 19 | message = message_parser(event.message) 20 | return v12.event.PrivateMessageEvent( 21 | id=str(uuid4()), 22 | time=datetime.utcfromtimestamp(event.time), 23 | type="message", 24 | detail_type="private", 25 | sub_type=event.sub_type, 26 | self=self, 27 | message_id=event.message_id, 28 | message=message, 29 | original_message=deepcopy(message), 30 | alt_message=event.raw_message, 31 | user_id=event.user_id, 32 | to_me=True, 33 | reply=None if not event.reply.time else reply_parser(event.reply) 34 | ) 35 | if event_type == "group_message": 36 | event = event.group_message 37 | message = message_parser(event.message) 38 | return v12.event.PrivateMessageEvent( 39 | id=str(uuid4()), 40 | time=datetime.utcfromtimestamp(event.time), 41 | type="message", 42 | detail_type="private", 43 | sub_type=event.sub_type, 44 | self=self, 45 | message_id=event.message_id, 46 | message=message, 47 | original_message=deepcopy(message), 48 | alt_message=event.raw_message, 49 | user_id=event.user_id, 50 | to_me=event.to_me, 51 | reply=None if not event.reply.time else reply_parser(event.reply), 52 | group_id=event.group_id, 53 | ) 54 | if event_type == "friend_add_notice": 55 | event = event.friend_add_notice 56 | return v12.FriendIncreaseEvent( 57 | id=str(uuid4()), 58 | time=datetime.utcfromtimestamp(event.time), 59 | type="notice", 60 | detail_type="friend_increase", 61 | sub_type="", 62 | self=self, 63 | user_id=str(event.user_id) 64 | ) 65 | if event_type == "friend_recall_notice": 66 | event = event.friend_recall_notice 67 | return v12.PrivateMessageDeleteEvent( 68 | id=str(uuid4()), 69 | time=datetime.utcfromtimestamp(event.time), 70 | type="notice", 71 | detail_type="private_message_delete", 72 | sub_type="", 73 | self=self, 74 | message_id=event.message_id, 75 | user_id=str(event.user_id) 76 | ) 77 | if event_type == "group_increase_notice": 78 | event = event.group_increase_notice 79 | return v12.GroupMemberIncreaseEvent( 80 | id=str(uuid4()), 81 | time=datetime.utcfromtimestamp(event.time), 82 | type="notice", 83 | detail_type="group_member_increase", 84 | sub_type=event.sub_type, 85 | self=self, 86 | user_id=str(event.user_id), 87 | group_id=str(event.group_id), 88 | operator_id=str(event.operator_id) 89 | ) 90 | if event_type == "group_decrease_notice": 91 | event = event.group_decrease_notice 92 | return v12.GroupMemberDecreaseEvent( 93 | id=str(uuid4()), 94 | time=datetime.utcfromtimestamp(event.time), 95 | type="notice", 96 | detail_type="group_member_decrease", 97 | sub_type=event.sub_type, 98 | self=self, 99 | user_id=str(event.user_id), 100 | group_id=str(event.group_id), 101 | operator_id=str(event.operator_id) 102 | ) 103 | if event_type == "group_recall_notice": 104 | event = event.group_recall_notice 105 | return v12.GroupMessageDeleteEvent( 106 | id=str(uuid4()), 107 | time=datetime.utcfromtimestamp(event.time), 108 | type="notice", 109 | detail_type="group_message_delete", 110 | sub_type="", 111 | self=self, 112 | user_id=str(event.user_id), 113 | group_id=str(event.group_id), 114 | operator_id=str(event.operator_id), 115 | message_id=str(event.message_id), 116 | ) 117 | 118 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/serializer/v12/result.py: -------------------------------------------------------------------------------- 1 | from yunzai_nonebot.rpc import hola_pb2 2 | 3 | 4 | def result_to_v12(result: hola_pb2.Result): 5 | result_type = result.WhichOneof("result") 6 | if result_type == "send_message": 7 | result = result.send_message 8 | return { 9 | "message_id": result.message_id, 10 | "time": result.time 11 | } 12 | if result_type == "delete_message": 13 | return None 14 | if result_type == "get_self_info": 15 | result = result.get_self_info 16 | return { 17 | "user_id": str(result.user_id), 18 | "user_name": result.nickname, 19 | "user_displayname": "PyBot" 20 | } 21 | if result_type == "get_user_info": 22 | result = result.get_user_info.user 23 | return { 24 | "user_id": str(result.user_id), 25 | "user_name": result.nickname, 26 | "user_displayname": result.nickname 27 | } 28 | if result_type == "get_friend_list": 29 | result = result.get_friend_list 30 | return [ 31 | { 32 | "user_id": str(friend.user_id), 33 | "user_name": friend.nickname, 34 | "user_displayname": friend.nickname 35 | } for friend in result.friend_list 36 | ] 37 | if result_type == "get_group_info": 38 | result = result.get_group_info.group 39 | return { 40 | "group_id": str(result.group_id), 41 | "group_name": result.group_name, 42 | } 43 | if result_type == "get_group_list": 44 | result = result.get_group_list 45 | return [ 46 | { 47 | "group_id": str(group.group_id), 48 | "group_name": group.group_name, 49 | } for group in result.group_list 50 | ] 51 | if result_type == "get_group_member_info": 52 | result = result.get_group_member_info.member 53 | return { 54 | "user_id": str(result.user_id), 55 | "user_name": result.nickname, 56 | "user_displayname": result.nickname 57 | } 58 | if result_type == "get_group_member_list": 59 | result = result.get_group_member_list 60 | return [ 61 | { 62 | "user_id": str(group_member.user_id), 63 | "user_name": group_member.nickname, 64 | "user_displayname": group_member.nickname 65 | } for group_member in result.group_member_list 66 | ] 67 | if result_type == "set_group_name": 68 | return None 69 | if result_type == "set_group_leave": 70 | return None 71 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/serializer/v12/utils.py: -------------------------------------------------------------------------------- 1 | from typing import Iterator 2 | 3 | from nonebot.adapters.onebot import v12 4 | from yunzai_nonebot.rpc.hola_pb2 import ReceivableMessageSegment, Sender, Reply, Anonymous 5 | 6 | 7 | def message_parser(message: Iterator[ReceivableMessageSegment]) -> v12.message.Message: 8 | serialized_message = v12.message.Message() 9 | for message_segment in message: 10 | message_type = message_segment.WhichOneof("segment") 11 | if message_type == "text": 12 | message_segment = message_segment.text 13 | serialized_message_segment = v12.message.MessageSegment( 14 | type="text", 15 | data={ 16 | "text": message_segment.data 17 | } 18 | ) 19 | elif message_type == "at": 20 | message_segment = message_segment.at 21 | serialized_message_segment = v12.message.MessageSegment( 22 | type="mention", 23 | data={ 24 | "user_id": str(message_segment.qq) 25 | } 26 | ) 27 | elif message_type == "image": 28 | message_segment = message_segment.image 29 | serialized_message_segment = v12.message.MessageSegment( 30 | type="image", 31 | data={ 32 | "file_id": message_segment.file, 33 | "type": message_segment.type, 34 | "url": message_segment.url, 35 | } 36 | ) 37 | elif message_type == "record": 38 | message_segment = message_segment.record 39 | serialized_message_segment = v12.message.MessageSegment( 40 | type="audio", 41 | data={ 42 | "file_id": message_segment.file, 43 | "url": message_segment.url 44 | } 45 | ) 46 | elif message_type == "video": 47 | message_segment = message_segment.video 48 | serialized_message_segment = v12.message.MessageSegment( 49 | type="video", 50 | data={ 51 | "file_id": message_segment.file, 52 | "url": message_segment.url 53 | } 54 | ) 55 | elif message_type == "location": 56 | message_segment = message_segment.location 57 | serialized_message_segment = v12.message.MessageSegment( 58 | type="location", 59 | data={ 60 | "latitude": message_segment.lat, 61 | "longitude": message_segment.lon, 62 | "title": message_segment.title, 63 | "content": message_segment.content, 64 | } 65 | ) 66 | elif message_type == "reply": 67 | message_segment = message_segment.reply 68 | serialized_message_segment = v12.message.MessageSegment( 69 | type="reply", 70 | data={ 71 | "message_id": message_segment.id, 72 | } 73 | ) 74 | else: 75 | continue 76 | serialized_message.append(serialized_message_segment) 77 | return serialized_message 78 | 79 | 80 | def reply_parser(reply: Reply) -> v12.event.Reply: 81 | return v12.event.Reply( 82 | message_id=reply.message_id, 83 | user_id=str(reply.sender.user_id), 84 | ) 85 | -------------------------------------------------------------------------------- /yunzai_nonebot/utils/service.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import traceback 3 | from collections import defaultdict 4 | from typing import Dict, AsyncGenerator, Any 5 | 6 | import grpc 7 | from nonebot import logger 8 | from nonebot.config import Config 9 | 10 | from yunzai_nonebot.rpc import hola_pb2_grpc, hola_pb2 11 | from yunzai_nonebot.utils import AsyncQueue 12 | from yunzai_nonebot.utils.exception import InitChannelError 13 | 14 | 15 | class Servicer(hola_pb2_grpc.Pipe): 16 | def __init__(self, handler, config: Config): 17 | self.connections: Dict[str, asyncio.Task] = {} 18 | self.contexts: Dict[str, grpc.ServicerContext] = {} 19 | self.handler = handler 20 | self.server: grpc.Server = grpc.aio.server( 21 | options=[ 22 | ('grpc.max_send_message_length', 256 * 1024 * 1024), 23 | ('grpc.max_receive_message_length', 256 * 1024 * 1024), 24 | ] 25 | ) 26 | hola_pb2_grpc.add_PipeServicer_to_server(self, self.server) 27 | self.server.add_insecure_port(f'{config.host}:{config.port}') 28 | 29 | async def Option( 30 | self, 31 | request: hola_pb2.OptionCode, 32 | context: grpc.ServicerContext, 33 | **kwargs 34 | ): 35 | code = request.code 36 | if code == 1: 37 | await self.server.stop(0) 38 | 39 | return hola_pb2.OptionCode(code=code) 40 | 41 | async def Channel( 42 | self, 43 | request_iterator: AsyncGenerator[hola_pb2.ToServer, Any], 44 | context: grpc.ServicerContext, 45 | **kwargs 46 | ) -> AsyncGenerator[hola_pb2.ToClient, Any]: 47 | try: 48 | init = await request_iterator.__anext__() 49 | 50 | if init.WhichOneof("to_server_type") != "head": 51 | raise InitChannelError 52 | 53 | self_id = init.head.self_id 54 | if context := self.contexts.get(self_id): 55 | context.abort_with_status(grpc.StatusCode.OK) 56 | 57 | self.connections[self_id] = asyncio.create_task(self.handler(self_id, request_iterator)) 58 | logger.success(f"{init.head.self_id}已连接") 59 | async for response in AsyncQueue(self_id): 60 | logger.debug(f"发出请求:{response}") 61 | yield response 62 | except Exception: 63 | context.set_code(grpc.StatusCode.INTERNAL) 64 | context.set_details(traceback.format_exc()) 65 | --------------------------------------------------------------------------------