├── .gitignore
├── DOCCHANGELOG.md
├── LICENSE
├── README.md
├── demo
├── README.md
└── ncm_search.js
├── source
├── MiraiQQBot.http.js
└── wrapper.js
└── static
└── poke.png
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode/settings.json
2 | .vscode/tasks.json
3 | rhino.jar
4 | run.sh
5 | test.js
--------------------------------------------------------------------------------
/DOCCHANGELOG.md:
--------------------------------------------------------------------------------
1 | # [Mirai RhinoJS SDK 文档](https://stageguard.top/p/mirai-rhinojs-sdk.html)更新日志
2 |
3 | ## 注:在新功能上文档更新日志与api更新日志基本一致,这里主要记录要修改的已存在的方法或者数据。
4 |
5 | ### 2020.05.02
6 | BREAKING CHANGES
7 | * 文档大幅度修改
8 | * 修复文档头类型预览中超链接无法跳转的问题和一些错字([#2](https://github.com/StageGuard/mirai-rhinojs-sdk/issues/2))。
9 |
10 | ### 2020.04.07
11 | * 修改了`Permission`的父类为`Mirai.GroupInfo`
12 | * `GroupSenderInfo.getGroupInfo()`改为`GroupSenderInfo.getGroup()`
13 | * 添加了`Mirai.EventType(Const)`的用法
14 | * 添加了闪照`Mirai.MessageType.FlashImage`的用法,修改了`Mirai.MessageType.Image`参数。
15 |
16 | ### 2020.04.05
17 | * 修改`MessageChain.build`的构造方式
18 | * 添加`Session.getCachedMessage`调用方法
19 | * 添加`MessageChain.discordMessage`调用方法
20 | * 添加`MessageChain.addMessage`调用方法
21 | * 添加`MessageChain.addMessageF`调用方法
22 | * 添加`MessageChain.toChainArray`解释
23 | * 修改了几个错别字。
24 |
25 | ### 2020.04之前
26 | * 修改了关于`require`函数相对路径的解释
27 | * 修改了几个错别字
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 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 Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Deprecated
2 | 不再维护此仓库,请前往 [iTXTech/mirai-js](https://github.com/iTXTech/mirai-js) 查看另一个基于 Mozilla Rhino 和 Mirai 的 SDK。
3 |
4 | # mirai-rhinojs-sdk
5 | 为[Mirai](https://github.com/mamoe/mirai)的[mirai-api-http](https://github.com/mamoe/mirai-api-http)提供封装好的适用于全平台的SDK。
6 |
7 | ## Mozilla Rhino是什么?
8 | Mozilla Rhino: JavaScript in Java
9 |
10 | 
11 |
12 | Rhino is an implementation of JavaScript in Java.
13 |
14 | Rhino是一个可以在JavaScript上运行Java程序的库。
15 |
16 | ----
17 |
18 | ## 简介
19 | 为[Mirai](https://github.com/mamoe/mirai)的[mirai-api-http](https://github.com/mamoe/mirai-api-http)提供封装好的适用于全平台的SDK。
20 |
21 | ### 如何适用全平台?
22 |
23 | `Windows/Linux`用户可以下载rhino运行库运行脚本。
24 |
25 | 安卓用户可以在`Termux`配置java环境或下载基于rhino的应用(如Auto.js)
26 |
27 | ### 如何简单易用?
28 | 下面提供一个简单的例子:
29 | ```javascript
30 | //将消息类型等静态常量注册进全局对象
31 | Mirai.registerClasses2Object(this);
32 | //设置http api服务器地址和验证密钥
33 | Mirai.setServer("http://localhost:8081/");
34 | Mirai.setAuthKey("stageguard");
35 | //创建一个新的bot
36 | var bot = Mirai.createNewBot(你的qq号);
37 | //订阅bot消息
38 | bot.subscribe({
39 | //订阅群组消息
40 | group: (group, sender, message) => {
41 | message.contains("回复测试").then(() => {
42 | //回复这个群友,以下方法是等价的
43 | group.reply("回复你了1");
44 | group.reply(Plain("回复你了2"));
45 | sender.reply("回复你了3");
46 | bot.sendGroupMessage(group, [Plain("回复你了4")], sender.getSourceId());
47 | }).contains("at测试").then(() => {
48 | //at这个群友,以下方法是等价的
49 | sender.at("at你了1");
50 | group.at(sender, "at你了2");
51 | group.send(At(sender) + Plain("at你了3"));
52 | bot.send(group, At(sender) + Plain("at你了4"));
53 | bot.send(group, At(sender), Plain("at你了5"));
54 | bot.sendGroupMessage(group, [At(sender), Plain("at你了6")]);
55 | }).contains("私聊我").then(() => {
56 | //自动判断有无好友
57 | sender.send("私聊你了1");
58 | //自动判断有无好友
59 | bot.send(sender, "私聊你了2");
60 | //手动判断
61 | if(bot.haveFriend(sender)) {
62 | bot.sendFriendMessage(sender, [Plain("私聊你了3")]);
63 | } else {
64 | bot.sendTempMessage(sender, group, [Plain("私聊你了3")]);
65 | }
66 | }).contains("禁言").then(() => {
67 | //group中的permission参数表示的是bot在这个群组的权限
68 | //sender中的permission参数表示消息发送者在这个群组的权限
69 | if(group.getPermission() == MEMBER || sender.getPermission() == OWNER) {
70 | group.send("我没有权限做那个!");
71 | } else {
72 | //若无At类型消息,get()则返回一个参数都为null的新消息对象
73 | if(message.get(AT).getTarget() != null) {
74 | //禁言60秒,以下方法都是等价的
75 | //获取at类型消息的target参数(被at的人的qq号)
76 | var target = message.get(AT).getTarget();
77 | bot.mute(group, target, 60);
78 | bot.unmute(group, target);
79 | group.mute(target, 60);
80 | group.unmute(target);
81 | }
82 | }
83 | });
84 | },
85 | friend: (sender, message) => {},
86 | //订阅其他事件
87 | event: (event) => {
88 | switch(event.type) {
89 | //自动拒绝好友请求
90 | case NEW_FRIEND_REQUEST:
91 | event.reject();
92 | break;
93 | //bot下线
94 | case BOT_OFFLINE:
95 | case BOT_OFFLINE_FORCE:
96 | case BOT_OFFLINE_DROPPED:
97 | bot.destroy();
98 | break;
99 | }
100 | },
101 | error: (e) => {
102 | Log.e(e);
103 | },
104 | });
105 | ```
106 | mirai-rhinojs-sdk提供了非常灵活的语法,允许你多种方式实现同一功能,尽量做到符合逻辑,同时提供多种消息类型构造方式:
107 | ```javascript
108 | sender.send(At(1355416608), Plain("at你了"));
109 | //文本消息的构造函数可以省略
110 | sender.send(At(1355416608), "at你了");
111 | //伪操作符重载
112 | //伪操作符重载方式不能省略文本消息的构造函数
113 | sender.send(At(1355416608) + Plain("at你了"));
114 | ```
115 |
116 | mirai-rhinojs-sdk将会有两个版本,它们的用法大部分都是相同的,但略有区别:
117 |
118 | - (未实现)`core`: 此版本将mirai-core作为依赖使用,不需要预先部署mirai-console,这也意味着使用此版本将无法使用mirai-console插件。
119 | - (可用)`http`: 此版本基于mirai-console的插件mirai-api-http,该版本的通讯交互为轮询`fetchMessage`接口,处理消息并发送。
120 |
121 | ----
122 |
123 | ## 快速开始:
124 | ### 我不会JavaScript
125 | 你只需要在[W3school](https://www.w3school.com.cn/js/index.asp)简单学习基础语法就可以开始使用了。
126 | ### 我会JavaScript
127 |
128 | 现在开始使用!
129 |
130 | core版本
131 |
132 | core版本暂不可用,请等待发布
133 |
134 |
135 |
136 | http版本
137 |
138 | ### 部署mirai-console
139 |
140 | 前往[mirai-console](https://github.com/mamoe/mirai-console)和[mirai-api-http](https://github.com/mamoe/mirai-api-http)的release界面下载最新版本的wrapper和mirai-api-http,按照mirai-api-http的README做好配置。
141 |
142 | 安卓用户请浏览[mzdluo123/MiraiAndroid](https://github.com/mzdluo123/MiraiAndroid)项目下载mirai android app或浏览[我的博客](https://stageguard.top/2020/04/01/run-qqbot-on-termux-android/#%E8%AF%A6%E7%BB%86%E8%BF%87%E7%A8%8B)在termux部署。
143 |
144 | ### 运行脚本
145 |
146 | 请选择你的平台查看
147 |
148 |
149 | Android(AutoJS)
150 |
151 | ### 新建一个脚本并复制以下内容
152 | ```javascript
153 | //导入MiraiQQBot库
154 | eval(http.get("https://raw.githubusercontent.com/StageGuard/mirai-rhinojs-sdk/master/source/wrapper.js").body.string());
155 | //注册一些常量对象到全局对象
156 | Mirai.registerClasses2Object(scope);
157 | //http api服务器地址
158 | Mirai.setServer("http://localhost:8080/");
159 | //验证密钥
160 | Mirai.setAuthKey("stageguard");
161 | //创建新的bot
162 | var bot = Mirai.createNewBot(你的bot qq号);
163 |
164 | //订阅bot消息
165 | bot.subscribe({
166 | //订阅群组消息
167 | group: (group, sender, message) => {
168 | group.send(message);
169 | },
170 | friend: (sender, message) => {
171 | if(message.get(POKE).getName() == SIXSIXSIX) {
172 | sender.send(Poke(LIKE));
173 | }
174 | },
175 | });
176 | ```
177 | ### 运行脚本
178 |
179 |
180 |
181 | Windows/Linux/Android(Termux)
182 |
183 | ### 下载rhino运行库
184 | 前往[mozilla/rhino](https://github.com/mozilla/rhino)项目release界面下载rhino运行库(rhino-xxx.jar而不是rhino-runtime-xxx.jar)
185 |
186 | ### 新建一个js脚本,复制以下内容
187 |
188 | ```javascript
189 | //导入MiraiQQBot库
190 | (function(http_get) {
191 | eval(http_get("https://raw.githubusercontent.com/StageGuard/mirai-rhinojs-sdk/master/source/wrapper.js"));
192 | }((url) => {
193 | var connection = (new java.net.URL(url)).openConnection(), bufferedReader, line, result = "";
194 | connection.setDoInput(true);
195 | var bufferedReader = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
196 | while ((line = bufferedReader.readLine()) != null) result += (line + "\n");
197 | bufferedReader.close(); return result;
198 | }));
199 | //注册一些常量对象到全局对象
200 | Mirai.registerClasses2Object(scope);
201 | //http api服务器地址
202 | Mirai.setServer("http://localhost:8080/");
203 | //验证密钥
204 | Mirai.setAuthKey("stageguard");
205 | //创建新的bot
206 | var bot = Mirai.createNewBot(你的bot qq号);
207 |
208 | //订阅bot消息
209 | bot.subscribe({
210 | //订阅群组消息
211 | group: (group, sender, message) => {
212 | group.send(message);
213 | },
214 | friend: (sender, message) => {
215 | message.contains(SIXSIXSIX).then(() => sender.send(Poke(LIKE)));
216 | },
217 | });
218 | ```
219 | ### 运行脚本
220 |
221 | ```
222 | java -jar rhino.js -f your_script.js
223 | ```
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 | 出现以下日志,即为运行成功
233 |
234 | ```
235 | Bot xxxxxxxxxx created.
236 | Verification thread started for xxxxxxxxxx.
237 | Message subscription thread started for xxxxxxxxxx.
238 | Session is verified: xxxx
239 | ```
240 |
241 | 现在,你的bot就是复读机了(
242 |
243 | 尝试对你的BOT发送戳一戳中的666。
244 |
245 | 
246 |
247 | 尽情享用吧!
248 |
249 | 提供一些[demo](https://github.com/StageGuard/mirai-rhinojs-sdk/tree/master/demo)帮助快速理解并开发。
250 |
251 | ----
252 |
253 | 所有功能均为测试版,少部分功能(如加群响应,移除群员等功能未测试),若有BUG请开issue反馈。
254 |
255 | 所有SDK提供的方法请参考[SDK文档](https://stageguard.top/p/mirai-rhinojs-sdk.html)
256 |
257 | ----
258 |
259 | ## To-Do
260 | - [x] 编写SDK文档
261 | - [x] 支持监听EventMessage
262 | - [ ] 将MozillaRhino整合成mirai插件
263 |
264 | ## 更新日志
265 |
266 | ### 2020.06.26 → 1.6.4
267 |
268 | * 修复`Image`/`FlashImage`消息无法发送本地图片[(#4)](https://github.com/StageGuard/mirai-rhinojs-sdk/issues/4)。
269 |
270 | ### 2020.05.31 → 1.6.3
271 |
272 | * `discord` → `discard`。
273 | * 添加`MessageChain.contains`以更好地判断消息
274 | * `Mirai.utils.http`和`Mirai.utils.files`兼容`rsync.stop()`。
275 | * 修改了`MessageChain.__convert`的判断逻辑。
276 |
277 | 文档已更新,`MessageChain.contains`的用法请浏览[SDK文档](https://stageguard.top/p/mirai-rhinojs-sdk.html)。
278 |
279 | ### 2020.05.17 → 1.6.2
280 |
281 | * 调用`Mirai.registerClasses2Object`时`Mirai.utils`类也会注册到指定对象。
282 | * 添加`Mirai.__BotManager`中的检验管理和消息监听管理,其管理工作移动到`Mirai.Bot`。
283 | * 添加工具类`Mirai.utils.rsync`,允许在rhino中异步执行(其本质是`Thread`的封装)。
284 | * 修复了一些逻辑问题和bug。
285 |
286 |
287 | ### 2020.05.02 → 1.6.1
288 |
289 | * 修复了MessageSender.at()消息的问题。
290 | * 添加`Mirai.loadExternalObject`允许加载外部脚本。
291 |
292 | 文档已更新,新事件和方法浏览[SDK文档](https://stageguard.top/p/mirai-rhinojs-sdk.html)。
293 |
294 | ### 2020.05.02 → 1.6.0
295 |
296 | BREAKING CHANGES
297 |
298 | * 完全重构MiraiBot_HTTP.js并更名为MiraiQQBot.http.js
299 | * 简化部署方式
300 | * 新的bug。
301 |
302 | 文档已更新,新事件和方法浏览[SDK文档](https://stageguard.top/p/mirai-rhinojs-sdk.html)。
303 |
304 | ### 2020.04.14 → 1.5.1
305 |
306 | * `Session.sendTempMessage`适配http api 1.6.2版本。
307 | * 添加`EventType.NEW_FRIEND_REQUEST`和`EventType.NEW_MEMBER_JOIN_REQUEST`以支持监听新好友请求和新加群请求事件。
308 | * 添加`Session.handleFriendRequest`和`Session.handleMemberJoinRequest`以处理新好友请求和新加群请求。
309 |
310 | 文档已更新,新事件和方法浏览[SDK文档](https://stageguard.top/p/mirai-rhinojs-sdk.html)。
311 |
312 |
313 | ### 2020.04.12 → 1.5_alpha
314 |
315 | * 添加`Session.sendTempMessage`以支持发送临时消息。
316 | * 发送好友消息支持引用。
317 | * 添加`Session.get(Friend/Group/GroupMember)List`以支持获取好友/群/群成员列表。
318 | * 添加`Session.(un)mute(All)`以支持(全体)(解除)禁言。
319 | * 添加`Session.kick`以支持踢出群成员。
320 | * HTTP Post/Get 内置,不再需要NetworkUtils模块。
321 | * 修复了bug和一些逻辑问题。
322 |
323 | 文档已更新,新用法浏览[SDK文档](https://stageguard.top/p/mirai-rhinojs-sdk.html)。
324 |
325 | ### 2020.04.07 → 1.4.1_alpha
326 |
327 | * 为`Mirai.GroupInfo`的构造函数添加null判断
328 | * `Mirai.connect()`中的post auth修改到`Mirai.auth()`,添加`Mirai.Session.reAuth()`用于session失效后的重认证
329 | * 修复了小bug
330 |
331 | 文档已更新。
332 |
333 | ### 2020.04.07 → 1.4_alpha
334 |
335 | * 修改了`Permission`的父类为`Mirai.GroupInfo`
336 | * `GroupSenderInfo.getGroupInfo()`改为`GroupSenderInfo.getGroup()`
337 | * 添加了`Mirai.EventType(Const)`事件类型,现在可以监听事件了。
338 | * `Mirai.MessageListener.hookOtherMessage(JSON msg)` 改为 `Mirai.MessageListener.hookEvent(Mirai.EventType.? event)`来hook事件
339 |
340 | 文档已更新。
341 |
342 | ### 2020.04.06 → 1.3.1_alpha
343 |
344 | * 适配`mirai-api-http` 1.5版本的接口`/fetchMessage`返回的数据格式。
345 | * 添加`Mirai.MessageType.FlashImage`闪照消息类型,用法与`Mirai.MessageType.Image`相同。
346 | * 为`Mirai.MessageType.Image`构造函数增加了`path`参数,表示发送本地图片的路径,该路径是相对于`plugins/MiraiAPIHTTP/images/`的。
347 |
348 | 文档未更新。
349 |
350 | ### 2020.04.06 → 1.3_alpha
351 | * `Session.sendMessage`现在直接可以发送`Mirai.MessageType.?`消息而无需仅为了一个消息对象构建消息链。
352 | * `Mirai.GroupInfo.getBotPermission`方法改名为`Mirai.GroupInfo.getPermission`
353 | * 添加`Mirai.GroupInfo.Permission`群组权限常量OWNER, ADMIN和MEMBER
354 | * 添加`Mirai.EventType`事件类型和`Mirai.EventTypeConst`事件类型常量。也就是说现在支持监听事件了。
355 | * (`Mirai.MessageListener`中的`hookOtherMessage(JSON msg)`改成`hookEvent(Mirai.EventType.? event)`)
356 | * demo.js更新,为了展示这次MiraiBot_HTTP.js的新特性。
357 | * 修复了一些遗留bug。
358 |
359 | 文档未更新。
360 |
361 | ### 2020.04.05 → 1.2_alpha
362 | * 修改`MessageChain.build`的构造方式(原来的不受影响)
363 | * 添加`Session.getCachedMessage`方法
364 | * 添加`MessageChain.discordMessage`方法
365 | * 添加`MessageChain.addMessage`方法
366 | * 添加`MessageChain.addMessageF`方法
367 | * 添加`MessageChain.toChainArray`方法
368 |
369 | 有关这些新方法的用法请看[SDK文档](https://stageguard.top/p/mirai-rhinojs-sdk.html)
370 |
371 | ### 2020.04.05 → 1.1_alpha
372 | * 修复运行30分钟后出现的bug.
373 | * 添加消息撤回方法:Mirai.Session.recall().
374 | * 修复了捕捉消息出现错误时对错误的处理错误
375 | * 修复了不能抓取其他类型消息的bug
376 | ### 2020.04.04 → 1.0_alpha
377 | * 首次提交
378 |
379 | ## License
380 | ```
381 | mirai-rhinojs-sdk
382 | Copyright (C) 2020 StageGuard
383 |
384 | This program is free software: you can redistribute it and/or modify
385 | it under the terms of the GNU Affero General Public License as published
386 | by the Free Software Foundation, either version 3 of the License, or
387 | (at your option) any later version.
388 |
389 | This program is distributed in the hope that it will be useful,
390 | but WITHOUT ANY WARRANTY; without even the implied warranty of
391 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
392 | GNU Affero General Public License for more details.
393 |
394 | You should have received a copy of the GNU Affero General Public License
395 | along with this program. If not, see .
396 | ```
397 |
--------------------------------------------------------------------------------
/demo/README.md:
--------------------------------------------------------------------------------
1 | 这里是一些脚本demo,可以帮助你快速理解与开发。
2 |
3 | ## 如何使用?
4 | ```javascript
5 | Mirai.loadExternalObject(scope, "https://cdn.jsdelivr.net/gh/StageGuard/mirai-rhinojs-sdk/demo/xxx.js", "XXX");
6 | ...
7 | bot.subscribe({
8 | group: (group, sender, message) => {
9 | //这里的subscribe是在XXX里定义的,你也可以换成你的方式。
10 | XXX.subscribe(group, sender, message);
11 | //为了防止耗时操作阻塞监听线程,你可以使用rsync异步执行
12 | rsync.run((s) => XXX.subscribe(group, sender, message));
13 | },
14 | friend: (sender, message) => {
15 | XXX.subscribe(null, sender, message);
16 | }
17 | });
18 | ```
--------------------------------------------------------------------------------
/demo/ncm_search.js:
--------------------------------------------------------------------------------
1 | (function(){
2 | var r = {
3 | //给Cookie用的
4 | MUSUC_U: "1a4372514fdafca040210ec0652560d35157299fb65cde76f2d3fd620bb608a15ae0d78b925f50ab1ca91cba586f29c731b299d667364ed3",
5 | __csrf: "8ea789fbbf78b50e6b64b5ebbb786176",
6 | deviceId: "86e757286f4bf940a20aed3abb328cae",
7 | //代理
8 | useragents: [
9 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
10 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
11 | 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36',
12 | 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36',
13 | 'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36',
14 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) Mobile/14F89;GameHelper',
15 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1',
16 | 'Mozilla/5.0 (iPad; CPU OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1',
17 | 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:46.0) Gecko/20100101 Firefox/46.0',
18 | 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36',
19 | 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4',
20 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:46.0) Gecko/20100101 Firefox/46.0',
21 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
22 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/13.10586'
23 | ],
24 | //获取随机UserAgent
25 | getRandomUserAgent: function() {
26 | return this.useragents[Math.floor(Math.random() * this.useragents.length)];
27 | },
28 | //获取Header
29 | getHeader: function() {
30 | return [
31 | ["Referer", "http://music.163.com/"],
32 | ["Host", "interface.music.163.com"],
33 | ["Origin", "http://music.163.com/"],
34 | ["Conection", "Keep-Alive"],
35 | ["Content-Type", "application/x-www-form-urlencoded"],
36 | ["User-Agent", this.getRandomUserAgent()],
37 | ["Cookie", "__remember_me=true; MUSIC_U=" + this.MUSIC_U + "; __csrf=" + this.__csrf + "; os=android; osver=7.1.2; appver=5.4.1; deviceId=" + this.devideId + ";"]
38 | ];
39 | },
40 | getSongInputStreamAvaliableHeader: function(url) {
41 | return [
42 | ["User-Agent", this.getRandomUserAgent()],
43 | ["Host", url],
44 | ["Referer", "http://music.163.com/api/"],
45 | ["Range", "0-"],
46 | ["Connection", "Keep-Alive"]
47 | ];
48 | },
49 | //API
50 | API: {
51 | search: function(key, size, page, type) {
52 | var url = "https://music.163.com/weapi/search/get?csrf_token=";
53 | var params = JSON.stringify({
54 | s: key,
55 | type: type,
56 | offset: (page - 1) * size,
57 | limit: size,
58 | }, "", 0);
59 | var encrypted = r.EncryptUtils.encryptParam(params);
60 | return Mirai.utils.http.post(url, encrypted, r.getHeader());
61 | },
62 | search_suggest: function(keyword) {
63 | var url = "https://music.163.com/weapi/search/suggest/web";
64 | var params = JSON.stringify({
65 | csrf_token: "",
66 | s: keyword || ""
67 | }, "", 0);
68 | var encrypted = r.EncryptUtils.encryptParam(params);
69 | return Mirai.utils.http.post(url, encrypted, r.getHeader());
70 | },
71 | user_playlist: function(uid) {
72 | var url = "https://music.163.com/api/user/playlist?uid=" + uid + "&offset=0&limit=1000";
73 | return r.Operator.get(url, r.getHeader());
74 | },
75 | detail_user: function(uid) {
76 | var url = "https://music.163.com/weapi/v1/user/detail/" + uid;
77 | var params = JSON.stringify({
78 | csrf_token: ""
79 | }, "", 0);
80 | var encrypted = r.EncryptUtils.encryptParam(params);
81 | return Mirai.utils.http.post(url, encrypted, r.getHeader());
82 | },
83 | detail_album: function(id) {
84 | var url = "https://music.163.com/weapi/v1/album/" + id;
85 | var encrypted = r.EncryptUtils.encryptParam("{}");
86 | return Mirai.utils.http.post(url, encrypted, r.getHeader());
87 | },
88 |
89 | detail_song: function(id) {
90 | var url = "http://music.163.com/api/song/detail/?id=" + id + "&ids=[" + id + "]";
91 | return r.Operator.get(url, r.getHeader());
92 | },
93 | detail_song_mp3: function(id, br) {
94 | var url = "http://music.163.com/weapi/song/enhance/player/url";
95 | var params = JSON.stringify({
96 | ids: [id],
97 | br: br || 999000,
98 | csrf_token: "",
99 | }, "", 0);
100 | var encrypted = r.EncryptUtils.encryptParam(params);
101 | return Mirai.utils.http.post(url, encrypted, r.getHeader());
102 | },
103 | detail_song_comments: function(id, size, page) {
104 | var url = "http://music.163.com/weapi/v1/resource/comments/R_SO_4_" + id;
105 | var params = JSON.stringify({
106 | rid: id,
107 | offset: (page - 1) * size,
108 | limit: size,
109 | csrf_token: "",
110 | }, "", 0);
111 | var encrypted = r.EncryptUtils.encryptParam(params);
112 | return Mirai.utils.http.post(url, encrypted, r.getHeader());
113 | },
114 | detail_artist: function(id) {
115 | var url = "http://music.163.com/weapi/v1/artist/" + id;
116 | return r.Operator.get(url, r.getHeader());
117 | },
118 | /*detail_: function(id) {
119 | var url = "";
120 | var params = JSON.stringify({
121 | csrf_token: "",
122 | }, "", 0);
123 | var encrypted = r.EncryptUtils.encryptParam(params);
124 | return Mirai.utils.http.post(url, encrypted, r.getHeader());
125 | },*/
126 |
127 | },
128 |
129 | //加密算法
130 | EncryptUtils: {
131 | aesEncrypt: function(text, key) {
132 | var ivParameterSpec = new javax.crypto.spec.IvParameterSpec(java.lang.String("0102030405060708").getBytes("UTF-8"));
133 | var secretKeySpec = new javax.crypto.spec.SecretKeySpec(java.lang.String(key).getBytes("UTF-8"), "AES");
134 | var cipher = javax.crypto.Cipher.getInstance("AES/CBC/PKCS5Padding");
135 | cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
136 | var encrypted = cipher.doFinal(java.lang.String(text).getBytes());
137 | return java.util.Base64.getEncoder().encodeToString(encrypted);
138 | },
139 | rsaEncrypt: function(text, pubKey, modulus) {
140 | text = new java.lang.StringBuilder(text).reverse().toString();
141 | var biginteger = new java.math.BigInteger(java.lang.String.format("%x", new java.math.BigInteger(1, text.getBytes())), 16).modPow(new java.math.BigInteger(pubKey, 16), new java.math.BigInteger(modulus, 16));
142 | var hexString = java.lang.String(biginteger.toString(16));
143 | if (java.lang.String(hexString).length() >= 256) {
144 | return hexString.substring(hexString.length() - 256, hexString.length());
145 | } else {
146 | while (java.lang.String(hexString).length() < 256) {
147 | hexString = 0 + hexString;
148 | }
149 | return hexString;
150 | }
151 | },
152 | getRandomString: function(length) {
153 | var string = "0123456789abcde";
154 | var stringBuffer = new java.lang.StringBuffer();
155 | for (var i = 0; i < length; i++) {
156 | stringBuffer.append(string.charAt(Math.round(Math.random() * (string.length - 1))));
157 | }
158 | return stringBuffer.toString();
159 | },
160 | encryptParam: function(text) {
161 | if (text == null) return "params=null&encSecKey=null";
162 | var modulus = "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7" +
163 | "b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280" +
164 | "104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932" +
165 | "575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b" +
166 | "3ece0462db0a22b8e7";
167 | var nonce = "0CoJUm6Qyw8W8jud";
168 | var pubKey = "010001";
169 | var secKey = this.getRandomString(16);
170 | var encText = this.aesEncrypt(this.aesEncrypt(text, nonce), secKey);
171 | var encSecKey = this.rsaEncrypt(secKey, pubKey, modulus);
172 | try {
173 | return ("params=" + java.net.URLEncoder.encode(encText, "UTF-8") + "&encSecKey=" + java.net.URLEncoder.encode(encSecKey, "UTF-8"));
174 | } catch (error) {
175 | return "params=null&encSecKey=null";
176 | }
177 | },
178 | md5Encrypt: function(string) {
179 | string = java.net.URLEncoder.encode(string);
180 | var messageDigest = java.security.MessageDigest.getInstance("MD5");
181 | var charArr = java.lang.String(string).toCharArray();
182 | var byteArr = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, charArr.length);
183 | for (var i = 0; i < charArr.length; i++) byteArr[i] = charArr[i];
184 | var md5Bytes = messageDigest.digest(byteArr);
185 | var hexValue = new java.lang.StringBuffer();
186 | for (var i = 0; i < md5Bytes.length; i++) {
187 | var val = md5Bytes[i] & 0xff;
188 | if (val < 16) hexValue.append("0");
189 | hexValue.append(java.lang.Integer.toHexString(val));
190 | }
191 | return hexValue.toString();
192 | }
193 | },
194 | Type: {
195 | SONG: 1,
196 | ALBUM: 10,
197 | ARTIST: 100,
198 | PLAYLIST: 1000,
199 | USER: 1002,
200 | RADIO: 1009,
201 | },
202 | app_string: "{\"app\":\"com.tencent.structmsg\",\"config\":{\"autosize\":true,\"ctime\":{$current_time},\"forward\":true,\"token\":\"77943689edb0852dcd79b982d1d10401\",\"type\":\"normal\"},\"desc\":\"音乐\",\"meta\":{\"music\":{\"action\":\"\",\"android_pkg_name\":\"\",\"app_type\":1,\"appid\":100495085,\"desc\":\"{$desc}\",\"jumpUrl\":\"{$jumpUrl}\",\"musicUrl\":\"{$musicUrl}\",\"preview\":\"{$preview}\",\"sourceMsgId\":\"0\",\"source_icon\":\"\",\"source_url\":\"\",\"tag\":\"{$tag}\",\"title\":\"{$title}\"}},\"prompt\":\"{$prompt}\",\"ver\":\"0.0.0.1\",\"view\":\"music\"}",
203 | subscribe: function(group, sender, message) {
204 | if(message.contain(/^(搜|点)歌帮助/)) {sender.at(r.getHelp());return;}
205 | message.contains([
206 | "^(搜|点)歌${s:keyword} ${n:no}",
207 | "^(搜|点)歌${s:keyword}"
208 | ]).thenSync((index, k, s) => {
209 | var msg = message.get(PLAIN).getText();
210 | Log.v("Received ncm search: " + k.keyword);
211 | var search = JSON.parse(r.API.search(k.keyword, 9, 1, r.Type.SONG));
212 | if(search.code != 200) {sender.at(search.msg); return;}
213 | if(index == 1) {
214 | var result = new java.lang.StringBuilder();
215 | result.append("曲库共找到约" + search.result.songCount + "首歌曲");
216 | for (var i in search.result.songs) {
217 | var no = Number(Number(i) + 1);
218 | result.append("\n" + no + ". " + (function(artists) {
219 | var r = new java.lang.StringBuilder();
220 | for (var n in artists) r.append(artists[n].name + "/");
221 | r = String(r.toString());
222 | return r.slice(0, r.length - 1);
223 | } (search.result.songs[i].artists)) + " - " + search.result.songs[i].name);
224 | }
225 | if(search.result.songCount != 0) result.append("\n再次搜索并加上空格和序号获取歌曲");
226 | sender.at(String(result.toString()));
227 | } else {
228 | var num = k.no - 1;
229 | if(num > search.result.songCount) return;
230 | var song = JSON.parse(r.API.detail_song_mp3(search.result.songs[num].id));
231 | var album = JSON.parse(r.API.detail_album(search.result.songs[num].album.id));
232 | group.send(App(
233 | r.app_string
234 | .replace("{$current_time}", Number(String((new Date()).getTime()).substr(0, 10)))
235 | .replace("{$desc}", (function(artists) {
236 | var r = new java.lang.StringBuilder();
237 | for (var n in artists) r.append(artists[n].name + "/");
238 | r = String(r.toString());
239 | return r.slice(0, r.length - 1);
240 | } (search.result.songs[num].artists)))
241 | .replace("{$jumpUrl}", "http://music.163.com/song/" + search.result.songs[num].id + "/")
242 | .replace("{$musicUrl}", song.data[0].url)
243 | .replace("{$preview}", album.album.picUrl)
244 | .replace("{$tag}", "猪场音乐")
245 | .replace("{$title}", search.result.songs[num].name)
246 | .replace("{$prompt}", "[分享] " + search.result.songs[num].name)
247 | ));
248 | sender.at("直链:" + song.data[0].url);
249 | }
250 | });
251 | },
252 | getHelp: function() {
253 | return "网易云音乐搜歌+分享\n" +
254 | "输入\"点歌\"或\"搜歌\"+空格+歌曲名来搜歌\n" +
255 | "例如:点歌 hop";
256 | }
257 | }
258 | return r;
259 | }())
--------------------------------------------------------------------------------
/source/MiraiQQBot.http.js:
--------------------------------------------------------------------------------
1 | /*
2 | mirai-rhinojs-sdk: MiraiQQBot.http.js
3 | Copyright (C) 2020 StageGuard
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Affero General Public License as published
7 | by the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Affero General Public License for more details.
14 |
15 | You should have received a copy of the GNU Affero General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | function() {
20 | var r = {
21 | __version: "v1.6.4_http",
22 |
23 | WINDOWS: "Windows",
24 | LINUX: "Linux",
25 | ANDROID_AUTOJS: "Android_AutoJs",
26 |
27 | host: "",
28 |
29 | authKey: "",
30 | server: "",
31 |
32 | setAuthKey: function(k) {
33 | if (k && typeof(k) == "string") this.authKey = k;
34 | },
35 | setServer: function(s) {
36 | if (s && typeof(s) == "string") this.server = s;
37 | },
38 | __auth: function() {
39 | return JSON.parse(this.utils.http.post(this.server + "auth", JSON.stringify({
40 | authKey: this.authKey
41 | })));
42 | },
43 | //在http版本中,password没有作用
44 | createNewBot: function(qq, password) {
45 | if (this.authkey == "" || this.server == "") throw "Authenticate key or server is not set.";
46 | if (this.__BotManager.has(qq)) {
47 | return this.__BotManager.get(qq);
48 | } else {
49 | r.Log.i("Bot " + qq + " created.");
50 | return this.__BotManager.add(qq, this.__generateSessionKey());
51 | }
52 | },
53 | __generateSessionKey: function() {
54 | var result = this.__auth();
55 | if (result.code != 0) {
56 | throw "Authenticate key is invaild.";
57 | } else {
58 | return result.session;
59 | }
60 | },
61 | getBot: function(qq) {
62 | return this.__BotManager.get(qq);
63 | },
64 | loadExternalObject: function(object, filep, name) {
65 | try {
66 | object[name] = eval("(" + (/^htt(p|ps):\/\//.test(filep) ? r.utils.http.get(filep) : r.utils.file.read(filep, r.utils.file.STRING)) + ")");
67 | r.Log.i("External object(source=" + filep + ") is loaded.");
68 | } catch(e) {
69 | r.Log.e(e);
70 | }
71 | },
72 |
73 | };
74 |
75 | r.init = function(globalObject) {
76 | this.host = java.lang.System.getProperty("os.name");
77 | if ("context" in globalObject) this.host = r.ANDROID_AUTOJS;
78 |
79 | r.Log.w("* MiraiQQBot.js version: " + r.__version);
80 | r.Log.w("* 当前为不稳定版本");
81 | r.Log.i("* Update log: https://github.com/StageGuard/mirai-rhinojs-sdk");
82 | r.Log.i("* SDK: https://stageguard.top/p/mirai-rhinojs-sdk.html");
83 |
84 | };
85 | r.registerClasses2Object = function(obj) {
86 | if (! (obj instanceof Object)) r.Log.e(obj + " is not an object.");
87 | var reg = function(source) {
88 | for (var i in source) {
89 | if (source[i] instanceof Object && !(source[i] instanceof Function)) {
90 | reg(source[i]);
91 | } else {
92 | obj[i] = source[i];
93 | }
94 | }
95 | };
96 | reg(r.MessageType);
97 | reg(r.MessageTypeConst);
98 | reg(r.EventTypeConst);
99 | reg(r.GroupInfo.Permission);
100 | reg(r.utils);
101 | obj["Log"] = r.Log;
102 | };
103 |
104 | r.__BotManager = {
105 | bots: [],
106 | add: function(qq, sessionKey) {
107 | this.bots.push({
108 | qq: qq,
109 | instance: new r.Bot(qq, sessionKey)
110 | });
111 | return this.get(qq);
112 | },
113 | get: function(qq) {
114 | for (var i in this.bots) {
115 | if (this.bots[i].qq == qq) {
116 | return this.bots[i].instance;
117 | }
118 | }
119 | return null;
120 | },
121 | has: function(qq) {
122 | for (var i in this.bots) {
123 | if (this.bots[i].qq == qq) {
124 | return true;
125 | }
126 | }
127 | return false;
128 | },
129 | remove: function(qq) {
130 | for (var i in this.bots) {
131 | if (this.bots[i].qq == qq) {
132 | this.bots.splice(i, 1);
133 | }
134 | }
135 | },
136 | };
137 | r.Bot = function(qq, sessionKey) {
138 | this.sessionKey = sessionKey;
139 | this.qq = qq;
140 | this.subscriber = null;
141 |
142 | this.verify_sync = r.utils.rsync.flag("SVSync" + this.qq).loop((s) => {
143 | var result = JSON.parse(r.utils.http.post(r.server + "verify", JSON.stringify({
144 | sessionKey: this.sessionKey,
145 | qq: this.qq
146 | })));
147 | switch (result.code) {
148 | case 1:
149 | throw "Authenticate key is invaild";
150 | break;
151 | case 2:
152 | throw "Bot " + this.qq + " is not existed.";
153 | break;
154 | case 3:
155 | r.Log.w("Session " + this.sessionKey + " is invaild, regenerating session key for bot " + this.qq);
156 | this.setSessionKey(r.__generateSessionKey());
157 | this.verify_sync.restart();
158 | break;
159 | case 4:
160 | //throw "Session is unauthenticated.";
161 | break;
162 | case 10:
163 | throw "Permission denied for bot " + qq;
164 | break;
165 | case 0:
166 | r.Log.i("Session is verified: " + this.sessionKey + "(" + this.qq + ")");
167 | break;
168 | }
169 | }, -1, 600000);
170 | r.Log.i("Verification thread started for " + this.qq + ".");
171 | this.subscribe_sync = new r.utils.rsync((s) => {
172 | s.sleep(150);
173 | if (this.subscriber != null) {try{
174 | var p = JSON.parse(r.utils.http.get(r.server + "fetchMessage?sessionKey=" + this.sessionKey + "&count=10"));
175 | if (p.code != 0) {
176 | if (p.code == 3) {
177 | this.setSessionKey(r.__generateSessionKey());
178 | this.verify_sync.restart();
179 | } else {
180 | if (this.subscriber.error) this.subscriber.error(new Error(String("Error while hooking messages: {$msg}({$code})").replace("{$code}", p.code).replace("{$msg}", p.msg)));
181 | }
182 | } else if (p.data.length != 0) {
183 | for (var i in p.data) {
184 | switch (p.data[i].type) {
185 | case "GroupMessage":
186 | if (this.subscriber.group) this.subscriber.group(new r.GroupInfo(this.sessionKey, p.data[i].messageChain[0].id, p.data[i].sender.group), new r.MessageSender(this.sessionKey, p.data[i].messageChain[0].id, p.data[i].sender), r.MessageChain.build([p.data[i].messageChain]));
187 | break;
188 | case "TempMessage":
189 | if (this.subscriber.temp) this.subscriber.temp(new r.GroupInfo(this.sessionKey, p.data[i].messageChain[0].id, p.data[i].sender.group), new r.MessageSender(this.sessionKey, p.data[i].messageChain[0].id, p.data[i].sender), r.MessageChain.build([p.data[i].messageChain]));
190 | break;
191 | case "FriendMessage":
192 | if (this.subscriber.friend) this.subscriber.friend(new r.MessageSender(this.sessionKey, p.data[i].messageChain[0].id, p.data[i].sender), r.MessageChain.build([p.data[i].messageChain]));
193 | break;
194 | default:
195 | if (this.subscriber.event) this.subscriber.event(new r.EventType[p.data[i].type](p.data[i], this.sessionKey));
196 | break;
197 | }
198 | }
199 | }
200 | }catch(e) {
201 | if(/500/.test(e.toString())) {
202 | r.Log.w("Http server crashed an error, if this error log continues to print, please submit this issue to project-mirai/mirai-api-http with full error log.");
203 | } else {
204 | r.Log(e);
205 | }
206 | }}
207 | });
208 | this.subscribe_sync.flag("MsgSub" + this.qq);
209 | this.subscribe_sync.loop_times(-1);
210 | };
211 | r.Bot.prototype = {
212 | getSessionKey: function() {
213 | return this.sessionKey;
214 | },
215 | setSessionKey: function(s) {
216 | this.sessionKey = s;
217 | },
218 | subscribe: function(obj) {
219 | this.subscriber = obj;
220 | if(obj != null) {
221 | r.Log.i("Message subscription thread started for " + this.qq + ".");
222 | this.subscribe_sync.run();
223 | }
224 | },
225 | getSubscriber: function() {
226 | return this.subscriber;
227 | },
228 |
229 | //自动判断并发送消息
230 | send: function(target) {
231 | var msg = new Array();
232 | for (var i = 1; i < arguments.length; i++) msg.push(arguments[i]);
233 | //如果target是群组,直接发送群组消息
234 | if (target instanceof r.GroupInfo) {
235 | return r.__protocol.sendGroupMessage(this.sessionKey, target.getId(), r.MessageChain.build(msg).discard(r.MessageTypeConst.QUOUE).discard(r.MessageTypeConst.SOURCE).toSource());
236 | } else if (target instanceof r.MessageSender) {
237 | //如果是发送者,判断是否有好友,有则直接发好友消息
238 | var friends = r.__protocol.getFriendList(this.sessionKey);
239 | for (var i in friends) {
240 | if (friends[i].id == target.getId()) {
241 | return r.__protocol.sendFriendMessage(this.sessionKey, target.getId(), r.MessageChain.build(msg).discard(r.MessageTypeConst.QUOUE).discard(r.MessageTypeConst.SOURCE).toSource());
242 | }
243 | }
244 | //若无,则判断发送者是否与bot在同一个群,有则发送临时消息
245 | if (target.getPermission() != null) {
246 | return r.__protocol.sendTempMessage(this.sessionKey, target.getId(), target.group.id, r.MessageChain.build(msg).discard(r.MessageTypeConst.QUOUE).discard(r.MessageTypeConst.SOURCE).toSource());
247 | } else {
248 | r.Log.e("Cannot send message(target=" + target + ")");
249 | return 0;
250 | }
251 | }
252 | },
253 | //发送群组消息
254 | sendGroupMessage: function(target, msg, quote) {
255 | return r.__protocol.sendGroupMessage(this.sessionKey, (target instanceof r.GroupInfo) ? target.getId() : target, r.MessageChain.build(msg).toSource(), quote);
256 | },
257 | //发送好友消息
258 | sendFriendMessage: function(target, msg, quote) {
259 | return r.__protocol.sendFriendMessage(this.sessionKey, (target instanceof r.MessageSender) ? target.getId() : target, r.MessageChain.build(msg).toSource(), quote);
260 | },
261 | //发送临时消息
262 | sendTempMessage: function(target, from, msg, quote) {
263 | return r.__protocol.sendTempMessage(this.sessionKey, (target instanceof r.MessageSender) ? target.getId() : target, (from instanceof r.GroupInfo) ? from.getId() : from, r.MessageChain.build(msg).toSource(), quote);
264 | },
265 | //撤回消息
266 | recall: function(target) {
267 | r.__protocol.recall(this.sessionKey, target);
268 | },
269 | //获取好友,群组,群成员列表数组
270 | getFriendList: function() {
271 | return r.__protocol.getFriendList(this.sessionKey);
272 | },
273 | getGroupList: function() {
274 | return r.__protocol.getGroupList(this.sessionKey);
275 | },
276 | getGroupMemberList: function(group) {
277 | return r.__protocol.getGroupMemberList(this.sessionKey, (group instanceof r.GroupInfo) ? group.getId() : group);
278 | },
279 | //好友判断
280 | haveFriend: function(friend) {
281 | var id = (friend instanceof r.MessageSender) ? friend.getId() : friend;
282 | var list = this.getFriendList();
283 | for (var i in list) {
284 | if (list[i].id == id) {
285 | return true;
286 | }
287 | }
288 | return false;
289 | },
290 | //群组判断
291 | haveGroup: function(group) {
292 | var id = (group instanceof r.GroupInfo) ? group.etId() : group;
293 | var list = this.getGroupList();
294 | for (var i in list) {
295 | if (list[i].id == id) {
296 | return true;
297 | }
298 | }
299 | return false;
300 | },
301 | //管理员操作
302 | mute: function(group, target, time) {
303 | r.__protocol.mute(this.sessionKey, (group instanceof r.GroupInfo) ? group.getId() : group, (target instanceof r.MessageSender) ? target.getId() : target, Number(Math.min(Math.max(0, time == null ? 60 : time), 2591999)));
304 | },
305 | unmute: function(group, target) {
306 | r.__protocol.unmute(this.sessionKey, (group instanceof r.GroupInfo) ? group.getId() : group, (target instanceof r.MessageSender) ? target.getId() : target);
307 | },
308 | muteAll: function(group) {
309 | r.__protocol.muteAll(this.sessionKey, (group instanceof r.GroupInfo) ? group.getId() : group);
310 | },
311 | unmuteAll: function(group) {
312 | r.__protocol.unmuteAll(this.sessionKey, (group instanceof r.GroupInfo) ? group.getId() : group);
313 | },
314 | kick: function(group, target, msg) {
315 | r.__protocol.kick(this.sessionKey, (group instanceof r.GroupInfo) ? group.getId() : group, (target instanceof r.MessageSender) ? target.getId() : target, msg);
316 | },
317 | handleFriendRequest: function(iArg, accept, msg) {
318 | r.__protocol.handleFriendRequest(this.sessionKey, iArg.eventId, iArg.fromId, iArg.groupId, accept, msg);
319 | },
320 | handleMemberJoinRequest: function(iArg, accept, msg) {
321 | r.__protocol.handleMemberJoinRequest(this.sessionKey, iArg.eventId, iArg.fromId, iArg.groupId, accept, msg);
322 | },
323 |
324 | destroy: function() {
325 | r.__BotManager.remove(this.qq);
326 | delete this;
327 | },
328 |
329 | };
330 |
331 | r.MessageSender = (function self() {
332 | self.r = function(session, sourceId, json) {
333 | this.session = session;
334 | this.sourceId = sourceId;
335 | this.id = (json == null) ? null: json.id;
336 | this.name = (json == null) ? null: (json.memberName ? json.memberName: json.nickname);
337 | this.permission = null;
338 | this.group = (json == null) ? null: (json.group ? json.group: null);
339 | if (this.group != null) {
340 | this.permission = (json == null) ? null: json.permission;
341 | }
342 | }
343 | self.r.prototype = {
344 | getId: function() {
345 | return this.id;
346 | },
347 | getName: function() {
348 | return this.name;
349 | },
350 | getPermission: function() {
351 | return this.permission;
352 | },
353 |
354 | getSourceId: function() {
355 | return this.sourceId;
356 | },
357 |
358 | send: function() {
359 | var friends = r.__protocol.getFriendList(this.session);
360 | for (var i in friends) {
361 | if (friends[i].id == this.getId()) {
362 | return r.__protocol.sendFriendMessage(this.session, this.getId(), r.MessageChain.build(arguments).discard(r.MessageTypeConst.QUOUE).discard(r.MessageTypeConst.SOURCE).toSource());
363 | }
364 | }
365 | return r.__protocol.sendTempMessage(this.session, this.getId(), this.group.id, r.MessageChain.build(arguments).toSource());
366 | },
367 | reply: function() {
368 | return r.__protocol.sendGroupMessage(this.session, this.group.id, r.MessageChain.build(arguments).discard(r.MessageTypeConst.QUOUE).discard(r.MessageTypeConst.SOURCE).toSource(), this.sourceId);
369 | },
370 | at: function() {
371 | return r.__protocol.sendGroupMessage(this.session, this.group.id, r.MessageChain.build(arguments).addF(r.MessageType.At(this)).discard(r.MessageTypeConst.QUOUE).discard(r.MessageTypeConst.SOURCE).toSource());
372 | },
373 |
374 | mute: function(time) {
375 | if (this.group != null) r.__protocol.mute(this.session, this.group.id, this.id, Number(Math.min(Math.max(0, time == null ? 60 : time), 2591999)));
376 | },
377 | unmute: function() {
378 | if (this.group != null) r.__protocol.unmute(this.session, this.group.id, this.id);
379 | },
380 | kick: function(msg) {
381 | if (this.group != null) r.__protocol.kick(this.session, this.group.id, this.id, msg);
382 | },
383 |
384 | toString: function() {
385 | return (this.permission == null ? "Friend": "GroupMember") + "(id=" + this.id + ", name=" + this.name + (this.permission == null ? "": (", permission=" + this.permission)) + ")";
386 | }
387 | }
388 | return self.r;
389 | } ());
390 | r.GroupInfo = (function self() {
391 | self.r = function(session, sourceId, json) {
392 | this.session = session;
393 | this.sourceId = sourceId;
394 | this.id = (json == null) ? null: json.id;
395 | this.name = (json == null) ? null: json.name;
396 | this.permission = (json == null) ? null: json.permission;
397 | }
398 | self.r.prototype = {
399 | getId: function() {
400 | return this.id;
401 | },
402 | getName: function() {
403 | return this.name;
404 | },
405 | getPermission: function() {
406 | return this.permission;
407 | },
408 | send: function() {
409 | return r.__protocol.sendGroupMessage(this.session, this.id, r.MessageChain.build(arguments).discard(r.MessageTypeConst.QUOUE).discard(r.MessageTypeConst.SOURCE).toSource());
410 | },
411 | reply: function() {
412 | return r.__protocol.sendGroupMessage(this.session, this.id, r.MessageChain.build(arguments).discard(r.MessageTypeConst.QUOUE).discard(r.MessageTypeConst.SOURCE).toSource(), this.sourceId);
413 | },
414 | at: function(sender) {
415 | var msg = new Array();
416 | for (var i = 1; i < arguments.length; i++) msg.push(arguments[i]);
417 | return r.__protocol.sendGroupMessage(this.session, this.id, r.MessageChain.build(msg).addF(r.MessageType.At(sender)).discard(r.MessageTypeConst.QUOUE).discard(r.MessageTypeConst.SOURCE).toSource());
418 | },
419 | mute: function(target, time) {
420 | r.__protocol.mute(this.session, this.id, (target instanceof r.MessageSender) ? target.getId() : target, Number(Math.min(Math.max(0, time == null ? 60 : time), 2591999)));
421 | },
422 | unmute: function(target) {
423 | r.__protocol.unmute(this.session, this.id, (target instanceof r.MessageSender) ? target.getId() : target);
424 | },
425 | muteAll: function() {
426 | r.__protocol.muteAll(this.session, this.id);
427 | },
428 | unmuteAll: function() {
429 | r.__protocol.unmuteAll(this.session, this.id);
430 | },
431 | kick: function(target, msg) {
432 | r.__protocol.kick(this.session, this.id, (target instanceof r.MessageSender) ? target.getId() : target, msg);
433 | },
434 | toString: function() {
435 | return "Group(id=" + this.id + ", name=" + this.name + ", permission=" + this.permission + ")";
436 | }
437 | }
438 | return self.r;
439 | } ());
440 | r.GroupInfo.Permission = {
441 | OWNER: "OWNER",
442 | ADMIN: "ADMINISTRATOR",
443 | MEMBER: "MEMBER",
444 | }
445 |
446 | r.MessageChain = function(messageChain) {
447 | this.msg = messageChain;
448 | }
449 | r.MessageChain.__json2MessageArray = function(msg) {
450 | var chains = [];
451 | for (var i in msg) {
452 | if (msg[i] instanceof r.MessageChain) {
453 | var cc;
454 | for (var i in cc = msg[i].toChainArray()) {
455 | chains.push(cc[i]);
456 | }
457 | } else {
458 | switch (msg[i].type) {
459 | case r.MessageTypeConst.SOURCE:
460 | chains.push(new r.MessageType.Source(msg[i].id, msg[i].time, true));
461 | break;
462 | case r.MessageTypeConst.QUOTE:
463 | chains.push(new r.MessageType.Quote(msg[i].id, msg[i].senderId, msg[i].groupId, msg[i].origin, true));
464 | break;
465 | case r.MessageTypeConst.AT:
466 | chains.push(new r.MessageType.At(msg[i].target, msg[i].display, true));
467 | break;
468 | case r.MessageTypeConst.ATALL:
469 | chains.push(new r.MessageType.AtAll(true));
470 | break;
471 | case r.MessageTypeConst.PLAIN:
472 | chains.push(new r.MessageType.Plain(msg[i].text, true));
473 | break;
474 | case r.MessageTypeConst.FACE:
475 | chains.push(new r.MessageType.Face(msg[i].faceId, msg[i].name, true));
476 | break;
477 | case r.MessageTypeConst.IMAGE:
478 | chains.push(new r.MessageType.Image(msg[i].imageId, msg[i].url, msg[i].path, true));
479 | break;
480 | case r.MessageTypeConst.FLASHIMAGE:
481 | chains.push(new r.MessageType.FlashImage(msg[i].imageId, msg[i].url, msg[i].path, true));
482 | break;
483 | case r.MessageTypeConst.XML:
484 | chains.push(new r.MessageType.Xml(msg[i].xml, true));
485 | break;
486 | case r.MessageTypeConst.JSON2:
487 | chains.push(new r.MessageType.Json2(msg[i].json, true));
488 | break;
489 | case r.MessageTypeConst.APP:
490 | chains.push(new r.MessageType.App(msg[i].content, true));
491 | break;
492 | case r.MessageTypeConst.POKE:
493 | chains.push(new r.MessageType.Poke(msg[i].name, true));
494 | break;
495 | }
496 | }
497 | }
498 | return chains;
499 | };
500 | //把各种构造方法构造的消息链转成json后再转成消息数组
501 | r.MessageChain.__convert = function(raw) {
502 | if (raw.length == 1 && (raw[0] instanceof r.MessageChain)) {
503 | return raw[0];
504 | } else if (raw.length == 1 && (raw[0] instanceof Array)) {
505 | return this.__json2MessageArray(raw[0]);
506 | } else if (raw.length > 1) {
507 | var chains = [];
508 | for (var i in raw) chains.push((raw[i] instanceof r.MessageChain) ? raw[i] : JSON.parse((raw[i].slice(0, 1) == "{") ? raw[i] : r.MessageType.Plain(String(raw[i]))));
509 | return this.__json2MessageArray(chains);
510 | } else if (raw.length == 1) {
511 | var msgs = /\}\{"type":/gi.test(raw[0] = String(raw[0])) ? raw[0].replace(/\}\{"type":/gi, "}<_*split*flag_&@2>{\"type\":").split("<_*split*flag_&@2>") : [(/^{"type":"[A-Za-z]+",.+}$/.test(raw[0])) ? raw[0] : r.MessageType.Plain(raw[0])];
512 | var chains = [];
513 | for (var i in msgs) chains.push(JSON.parse(msgs[i]));
514 | return this.__json2MessageArray(chains);
515 | } else {
516 | r.Log.e("Unknown type of MessageChain constructor.");
517 | return [];
518 | }
519 | }
520 |
521 | r.MessageChain.build = function(raw) {
522 | var chain = this.__convert(raw);
523 | if (chain instanceof r.MessageChain) {
524 | return chain;
525 | } else {
526 | return new this(chain);
527 | }
528 | }
529 |
530 | r.MessageChain.__TContainerObj = (function(){
531 | var k = function(msg) {
532 | this.msg = msg;
533 | this.matcher_values = {};
534 | this.matcher_index = -1;
535 | this.flag = false;
536 | };
537 | k.prototype = {
538 | then: function(obj) {
539 | if(this.flag) {
540 | obj(this.matcher_index, this.matcher_values);
541 | }
542 | return this;
543 | },
544 | thenSync: function(obj) {
545 | if(this.flag) {
546 | r.utils.rsync.run((s) => obj(this.matcher_index, this.matcher_values, s));
547 | }
548 | return this;
549 | },
550 | or: function(obj) {
551 | if(!this.flag) {
552 | obj(this.matcher_index, this.matcher_values);
553 | }
554 | return this;
555 | },
556 | orSync: function(obj) {
557 | if(!this.flag) {
558 | r.utils.rsync.run((s) => obj(this.matcher_index, this.matcher_values, s));
559 | }
560 | return this;
561 | },
562 | contains: function(regex) {
563 | var list = {}, _for = true;
564 | this.flag = false;
565 | for(var n in (regex = (regex instanceof Array) ? regex : [regex])) {
566 | if(!_for) continue;
567 | var index = 1, matcher = regex[n] instanceof RegExp ? (function z(){
568 | z.s = regex[n].toString();
569 | return z.s.substr(1, z.s.length - 2)
570 | }()) : regex[n], mlist = [];
571 | const gexp = /\$\{([a-z](<([a-z]+((\s)*=(\s)*[A-Za-z0-9"]{1,})*(,)*(\s)*)*>)*:)*([^0-9]{1}[A-Za-z0-9]{1,})\}/i;
572 | const child_exp = /\(([^?][^:][\s\S]+)\)/i;
573 |
574 | while(matcher.search(child_exp) != -1) matcher = matcher.replace(child_exp, "(?:$1)");
575 | while(matcher.search(gexp) != -1) {
576 | var exp = gexp.exec(matcher);
577 | var type = "s"; //默认匹配s类型
578 | var props = []; //默认无任何属性
579 | if(exp[1]) { //是${t:name}类的
580 | type = exp[1].substr(0, 1);
581 | if(/[a-z]{1}<[^>]/.test(exp[1].substr(0, exp[1].length - 1))) props = (function(s1) {
582 | var p1 = (s1.search(",") != -1) ? s1.split(",") : [s1];
583 | for(var i in p1) p1[i] = (p1[i].search("=") != -1) ? (function(s2){
584 | var p2 = s2.split("=");
585 | return {prop: p2[0].replace(/\s/g, ""), value: /\d/.test(p2[1].replace(/\s/g, "")) ? Number(p2[1].replace(/\s/g, "")) : p2[1].replace(/[\s[^\f]]/g, "")};
586 | }(p1[i])) : {prop: p1[i].replace(/\s/g, ""), value: null}
587 | return p1;
588 | } (exp[1].substr(2, exp[1].length - 4)));
589 | }
590 | switch(type) {
591 | case "s": {
592 | var sp = false, lb = false, len = -1;
593 | for(var i in props) {
594 | if(props[i].prop == "sp") sp = true;
595 | if(props[i].prop == "lb") lb = true;
596 | if(props[i].prop == "len") len = props[i].value;
597 | }
598 | matcher = matcher.replace(exp[0], (function() {
599 | var r = "([";
600 | if(lb && sp) {
601 | r += "\\s\\S";
602 | } else {
603 | r += "^";
604 | r += sp ? "" : " ";
605 | r += lb ? "" : "\\n";
606 | }
607 | r += ("]" + (len == -1 ? "+" : "{" + len + "}"));
608 | r += ")";
609 | return r;
610 | }()));
611 | break;
612 | }
613 | case "n": {
614 | var bit = -1;
615 | for(var i in props) {
616 | if(props[i].prop == "bit") bit = props[i].value;
617 | }
618 | matcher = matcher.replace(exp[0], (function() {
619 | var r = bit == -1 ? "(\\d" : "([\\d";
620 | r += bit == -1 ? "+)" : ("]{" + bit + "})");
621 | return r;
622 | }()));
623 | break;
624 | }
625 | default: matcher = matcher.replace(gexp.exec(matcher)[0], "REP");
626 | }
627 | mlist.push({index: index ++, name: exp[exp.length - 1], type: type});
628 | }
629 | for(var i in this.msg) {
630 | var result = (new RegExp(matcher)).exec(this.msg[i]);
631 | if(result) {
632 | this.flag = true;
633 | this.matcher_index = n;
634 | for(var i in mlist) {
635 | list[mlist[i].name] = mlist[i].type == "n" ? Number(result[mlist[i].index]) : result[mlist[i].index];
636 | }
637 | _for = false;
638 | }
639 | }
640 | }
641 | this.matcher_values = list;
642 | return this;
643 | },
644 | }
645 | return k;
646 | }())
647 |
648 | r.MessageChain.prototype = {
649 | length: function() {
650 | return this.msg.length;
651 | },
652 | get: function(type) {
653 | for (var i in this.msg) {
654 | if (this.msg[i].type == type) {
655 | return this.msg[i];
656 | }
657 | }
658 | return new r.MessageType[type]();
659 | },
660 | discard: function(type) {
661 | for (var i in this.msg) {
662 | if (this.msg[i].type == type) {
663 | this.msg.splice(i, 1);
664 | }
665 | }
666 | return this;
667 | },
668 | contain: function(text) {
669 | for (var i in this.msg) {
670 | if (String(this.msg[i]._v()).search(text) != -1) return true;
671 | }
672 | return false;
673 | },
674 | contains: function self(regex) {
675 | self.chain = [];
676 | for (var i in this.msg) {
677 | self.chain.push(this.msg[i]._v());
678 | }
679 | return (new r.MessageChain.__TContainerObj(self.chain)).contains(regex);
680 | },
681 | add: function self() {
682 | var chain = r.MessageChain.__convert(arguments);
683 | for (var i in chain) this.msg.push(chain[i]);
684 | return this;
685 | },
686 | addF: function self() {
687 | var chain = r.MessageChain.__convert(arguments);
688 | for (var i in chain) this.msg.unshift(chain[i]);
689 | return this;
690 | },
691 | toSource: function self() {
692 | self.chain = [];
693 | for (var i in this.msg) {
694 | self.chain.push(this.msg[i].toSource());
695 | }
696 | return self.chain;
697 | },
698 | toChainArray: function() {
699 | return this.msg;
700 | },
701 | toString: function self() {
702 | self.str = "[";
703 | for (var i in this.msg) {
704 | self.str += JSON.stringify(this.msg[i].toSource());
705 | }
706 | return self.str.replace(/\}\{/gi, "}, {") + "]";
707 | },
708 |
709 |
710 | };
711 |
712 | r.MessageTypeConst = {
713 | SOURCE: "Source",
714 | QUOTE: "Quote",
715 | AT: "At",
716 | ATALL: "AtAll",
717 | FACE: "Face",
718 | PLAIN: "Plain",
719 | IMAGE: "Image",
720 | FLASHIMAGE: "FlashImage",
721 | XML: "Xml",
722 | JSON2: "Json",
723 | APP: "App",
724 | POKE: "Poke",
725 | PokeType: {
726 | POKE: "Poke",
727 | SHOWLOVE: "ShowLove",
728 | LIKE: "Like",
729 | HEARTBROKEN: "Heartbroken",
730 | SIXSIXSIX: "SixSixSix",
731 | FANGDAZHAO: "FangDaZhao"
732 | }
733 | };
734 |
735 | r.MessageType = {
736 | Source: (function self() {
737 | self.r = function(id, time) {
738 | this.id = id ? id: null;
739 | this.time = time ? time: null;
740 | }
741 | self.r.prototype = {
742 | type: r.MessageTypeConst.SOURCE,
743 | getId: function() {
744 | return this.id;
745 | },
746 | getTime: function() {
747 | return this.time;
748 | },
749 | toSource: function() {
750 | return {
751 | type: r.MessageTypeConst.SOURCE,
752 | id: this.id,
753 | time: this.time
754 | };
755 | },
756 | _v: function() {
757 | return "";
758 | }
759 | }
760 | return self.r;
761 | } ()),
762 | Quote: (function self() {
763 | self.r = function(id, senderId, groupId, origin) {
764 | this.id = id ? id: null;
765 | this.groupId = groupId ? groupId: null;
766 | this.senderId = senderId ? senderId: null;
767 | this.origin = origin ? r.MessageChain.build([origin]) : null;
768 | }
769 | self.r.prototype = {
770 | type: r.MessageTypeConst.QUOTE,
771 | getId: function() {
772 | return this.id;
773 | },
774 | getSenderId: function() {
775 | return this.senderId;
776 | },
777 | getGroupId: function() {
778 | return this.groupId;
779 | },
780 | getOrigin: function() {
781 | return this.origin;
782 | },
783 | toSource: function() {
784 | return {
785 | id: r.MessageTypeConst.QUOTE,
786 | senderId: this.senderId,
787 | groupId: this.groupId,
788 | origin: this.origin.toSource()
789 | };
790 | },
791 | _v: function() {
792 | return "";
793 | }
794 | }
795 | return self.r;
796 | } ()),
797 | At: (function self() {
798 | self.r = function(target, display, flag) {
799 | if (!flag && arguments.length) return JSON.stringify({
800 | type: r.MessageTypeConst.AT,
801 | target: (target instanceof r.MessageSender) ? target.getId() : Number(target),
802 | display: display
803 | });
804 | this.target = target ? target: null;
805 | this.display = display ? display: null;
806 | }
807 | self.r.prototype = {
808 | type: r.MessageTypeConst.AT,
809 | getTarget: function() {
810 | return this.target;
811 | },
812 | getDisplayText: function() {
813 | return this.display;
814 | },
815 | toSource: function() {
816 | return {
817 | type: r.MessageTypeConst.AT,
818 | target: this.target,
819 | display: this.display
820 | };
821 | },
822 | _v: function() {
823 | return this.target;
824 | }
825 | }
826 | return self.r;
827 | } ()),
828 | AtAll: (function self() {
829 | self.r = function(flag) {
830 | if (!flag && arguments.length) return JSON.stringify({
831 | type: r.MessageTypeConst.ATALL
832 | })
833 | }
834 | self.r.prototype = {
835 | type: r.MessageTypeConst.ATALL,
836 | toSource: function() {
837 | return {
838 | type: r.MessageTypeConst.ATALL
839 | };
840 | },
841 | _v: function() {
842 | return "";
843 | }
844 | }
845 | return self.r;
846 | } ()),
847 | Face: (function self() {
848 | self.r = function(faceId, flag) {
849 | if (!flag && arguments.length) return JSON.stringify({
850 | type: r.MessageTypeConst.FACE,
851 | faceId: faceId
852 | });
853 | this.faceId = faceId ? faceId: null;
854 | }
855 | self.r.prototype = {
856 | type: r.MessageTypeConst.FACE,
857 | getFaceId: function() {
858 | return this.faceId;
859 | },
860 | toSource: function() {
861 | return {
862 | type: r.MessageTypeConst.FACE,
863 | faceId: this.faceId,
864 | }
865 | },
866 | _v: function() {
867 | return this.faceId;
868 | }
869 | }
870 | return self.r;
871 | } ()),
872 | Plain: (function self() {
873 | self.r = function(text, flag) {
874 | if (!flag && arguments.length) return JSON.stringify({
875 | type: r.MessageTypeConst.PLAIN,
876 | text: text,
877 | });
878 | this.text = text ? String(text) : null;
879 | }
880 | self.r.prototype = {
881 | type: r.MessageTypeConst.PLAIN,
882 | getText: function() {
883 | return this.text;
884 | },
885 | toSource: function() {
886 | return {
887 | type: r.MessageTypeConst.PLAIN,
888 | text: this.text,
889 | };
890 | },
891 | _v: function() {
892 | return this.text;
893 | }
894 | }
895 | return self.r;
896 | } ()),
897 | Image: (function self() {
898 | self.r = function(imageId, url, path, flag) {
899 | if (!flag && arguments.length) return (function() {
900 | return JSON.stringify({
901 | type: r.MessageTypeConst.IMAGE,
902 | imageId: imageId == null ? null: imageId,
903 | url: url == null ? null: url,
904 | path: path == null ? null: path
905 | });
906 | } ());
907 | this.imageId = imageId ? imageId: null;
908 | this.url = url ? url: null;
909 | this.path = path ? path: null;
910 | }
911 | self.r.prototype = {
912 | type: r.MessageTypeConst.IMAGE,
913 | getImageId: function() {
914 | return this.imageId;
915 | },
916 | getUrl: function() {
917 | return this.url;
918 | },
919 | toSource: function() {
920 | return {
921 | type: r.MessageTypeConst.IMAGE,
922 | imageId: this.imageId,
923 | url: this.url,
924 | path: this.path == null ? null: this.path
925 | };
926 | },
927 | _v: function() {
928 | return this.imageId;
929 | }
930 | }
931 | return self.r;
932 | } ()),
933 | FlashImage: (function self() {
934 | self.r = function(imageId, url, path, flag) {
935 | if (!flag && arguments.length) return (function() {
936 | return JSON.stringify({
937 | type: r.MessageTypeConst.IMAGE,
938 | imageId: imageId == null ? null: imageId,
939 | url: url == null ? null: url,
940 | path: path == null ? null: path
941 | });
942 | } ());
943 | this.imageId = imageId ? imageId: null;
944 | this.url = url ? url: null;
945 | this.path = path ? path: null;
946 | }
947 | self.r.prototype = {
948 | type: r.MessageTypeConst.FLASHIMAGE,
949 | getImageId: function() {
950 | return this.imageId;
951 | },
952 | getUrl: function() {
953 | return this.url;
954 | },
955 | toSource: function() {
956 | return {
957 | type: r.MessageTypeConst.IMAGE,
958 | imageId: this.imageId == null ? null: this.imageId,
959 | url: this.url == null ? null: this.url,
960 | path: this.path == null ? null: this.path
961 | };
962 | },
963 | _v: function() {
964 | return this.imageId;
965 | }
966 | }
967 | return self.r;
968 | } ()),
969 | Xml: (function self() {
970 | self.r = function(xml, flag) {
971 | if (!flag && arguments.length) return JSON.stringify({
972 | type: r.MessageTypeConst.XML,
973 | xml: xml
974 | });
975 | this.xml = xml ? xml: null;
976 | }
977 | self.r.prototype = {
978 | type: r.MessageTypeConst.XML,
979 | getXml: function() {
980 | return this.xml;
981 | },
982 | toSource: function() {
983 | return {
984 | type: r.MessageTypeConst.XML,
985 | xml: this.xml
986 | };
987 | },
988 | _v: function() {
989 | return this.xml;
990 | },
991 | }
992 | return self.r;
993 | } ()),
994 | Json2: (function self() {
995 | self.r = function(json, flag) {
996 | if (!flag && arguments.length) return JSON.stringify({
997 | type: r.MessageTypeConst.JSON2,
998 | json: json
999 | });
1000 | this.json = json ? json: null;
1001 | }
1002 | self.r.prototype = {
1003 | type: r.MessageTypeConst.JSON2,
1004 | getJson: function() {
1005 | return j;
1006 | },
1007 | toSource: function() {
1008 | return {
1009 | type: r.MessageTypeConst.JSON2,
1010 | json: this.json
1011 | };
1012 | },
1013 | _v: function() {
1014 | return this.json;
1015 | }
1016 | }
1017 | return self.r;
1018 | } ()),
1019 | App: (function self() {
1020 | self.r = function(app, flag) {
1021 | if (!flag && arguments.length) return JSON.stringify({
1022 | type: r.MessageTypeConst.APP,
1023 | content: app
1024 | });
1025 | this.app = app ? app: null;
1026 | }
1027 | self.r.prototype = {
1028 | type: r.MessageTypeConst.APP,
1029 | getApp: function() {
1030 | return this.app;
1031 | },
1032 | toSource: function() {
1033 | return {
1034 | type: r.MessageTypeConst.APP,
1035 | content: this.app
1036 | };
1037 | },
1038 | _v: function() {
1039 | return this.app;
1040 | }
1041 | }
1042 | return self.r;
1043 | } ()),
1044 | Poke: (function self() {
1045 | self.r = function(name, flag) {
1046 | if (!flag && arguments.length) return JSON.stringify({
1047 | type: r.MessageTypeConst.POKE,
1048 | name: name
1049 | });
1050 | this.name = name ? name: null;
1051 | }
1052 | self.r.prototype = {
1053 | type: r.MessageTypeConst.POKE,
1054 | getName: function() {
1055 | return this.name;
1056 | },
1057 | toSource: function() {
1058 | return {
1059 | type: r.MessageTypeConst.POKE,
1060 | name: this.name
1061 | };
1062 | },
1063 | _v: function() {
1064 | return this.name;
1065 | }
1066 | }
1067 | return self.r;
1068 | } ()),
1069 | };
1070 | r.EventTypeConst = {
1071 | BOT_ONLINE: "BotOnlineEvent",
1072 | BOT_OFFLINE: "BotOfflineEventActive",
1073 | BOT_OFFLINE_FORCE: "BotOfflineEventForce",
1074 | BOT_OFFLINE_DROPPED: "BotOfflineEventDropped",
1075 | BOT_RELOGIN: "BotReloginEvent",
1076 | GROUP_RECALL: "GroupRecallEvent",
1077 | FRIEND_RECALL: "FriendRecallEvent",
1078 | BOT_GROUP_PERMISSION_CHANGE: "BotGroupPermissionChangeEvent",
1079 | BOT_MUTE: "BotMuteEvent",
1080 | BOT_UNMUTE: "BotUnmuteEvent",
1081 | BOT_JOIN_GROUP: "BotJoinGroupEvent",
1082 | GROUP_NAME_CHANGE: "GroupNameChangeEvent",
1083 | GROUP_ENTRANCE_ANN_CHANGE: "GroupEntranceAnnouncementChangeEvent",
1084 | GROUP_MUTE_ALL: "GroupMuteAllEvent",
1085 | GROUP_ALLOW_ANONYMOUS_CHAT: "GroupAllowAnonymousChatEvent",
1086 | GROUP_ALLOW_CONFESS_TALK: "GroupAllowConfessTalkEvent",
1087 | GROUP_ALLOW_MEMBER_INVITE: "GroupAllowMemberInviteEvent",
1088 | GROUP_MEMBER_JOIN: "MemberJoinEvent",
1089 | GROUP_MEMBER_KICK: "MemberLeaveEventKick",
1090 | GROUP_MEMBER_QUIT: "MemberLeaveEventQuit",
1091 | GROUP_MEMBER_NAME_CHANGE: "MemberCardChangeEvent",
1092 | GROUP_MEMBER_FAME_CHANHE: "MemberSpecialTitleChangeEvent",
1093 | GROUP_MEMBER_PERMISSION_CHANGE: "MemberPermissionChangeEvent",
1094 | GROUP_MEMBER_MUTE: "MemberMuteEvent",
1095 | GROUP_MEMBER_UNMUTE: "MemberUnmuteEvent",
1096 | NEW_FRIEND_REQUEST: "NewFriendRequestEvent",
1097 | NEW_MEMBER_JOIN_REQUEST: "MemberJoinRequestEvent",
1098 | },
1099 | r.EventType = {
1100 | BotOnlineEvent: (function self() {
1101 | self.r = function(json) {
1102 | this.id = json.qq;
1103 | }
1104 | self.r.prototype = {
1105 | type: r.EventTypeConst.BOT_ONLINE,
1106 | getId: function() {
1107 | return this.id;
1108 | }
1109 | }
1110 | return self.r;
1111 | } ()),
1112 | BotOfflineEvent: (function self() {
1113 | self.r = function(json) {
1114 | this.id = json.qq;
1115 | }
1116 | self.r.prototype = {
1117 | type: r.EventTypeConst.BOT_OFFLINE,
1118 | getId: function() {
1119 | return this.id;
1120 | }
1121 | }
1122 | return self.r;
1123 | } ()),
1124 | BotOfflineEventForce: (function self() {
1125 | self.r = function(json) {
1126 | this.id = json.qq;
1127 | }
1128 | self.r.prototype = {
1129 | type: r.EventTypeConst.BOT_OFFLINE_FORCE,
1130 | getId: function() {
1131 | return this.id;
1132 | }
1133 | }
1134 | return self.r;
1135 | } ()),
1136 | BotOfflineEventDropped: (function self() {
1137 | self.r = function(json) {
1138 | this.id = json.qq;
1139 | }
1140 | self.r.prototype = {
1141 | type: r.EventTypeConst.BOT_OFFLINE_DROPPED,
1142 | getId: function() {
1143 | return this.id;
1144 | }
1145 | }
1146 | return self.r;
1147 | } ()),
1148 | BotReloginEvent: (function self() {
1149 | self.r = function(json) {
1150 | this.id = json.qq;
1151 | }
1152 | self.r.prototype = {
1153 | type: r.EventTypeConst.BOT_RELOGIN,
1154 | getId: function() {
1155 | return this.id;
1156 | }
1157 | }
1158 | return self.r;
1159 | } ()),
1160 | GroupRecallEvent: (function self() {
1161 | self.r = function(json) {
1162 | this.senderId = json.authorId;
1163 | this.messageId = json.messageId;
1164 | this.time = json.time;
1165 | this.group = new r.GroupInfo(json.group);
1166 | this.operator = new r.MessageSender(json.operator);
1167 | }
1168 | self.r.prototype = {
1169 | type: r.EventTypeConst.GROUP_RECALL,
1170 | getSenderId: function() {
1171 | return this.senderId;
1172 | },
1173 | getMessageId: function() {
1174 | return this.messageId;
1175 | },
1176 | getTime: function() {
1177 | return this.time;
1178 | },
1179 | getGroup: function() {
1180 | return this.group;
1181 | },
1182 | getOperator: function() {
1183 | return this.operator;
1184 | },
1185 | }
1186 | return self.r;
1187 | } ()),
1188 | FriendRecallEvent: (function self() {
1189 | self.r = function(json) {
1190 | this.senderId = json.authorId;
1191 | this.messageId = json.messageId;
1192 | this.time = json.time;
1193 | }
1194 | self.r.prototype = {
1195 | type: r.EventTypeConst.FRIEND_RECALL,
1196 | getSenderId: function() {
1197 | return this.senderId;
1198 | },
1199 | getMessageId: function() {
1200 | return this.messageId;
1201 | },
1202 | getTime: function() {
1203 | return this.time;
1204 | },
1205 | }
1206 | return self.r;
1207 | } ()),
1208 | BotGroupPermissionChangeEvent: (function self() {
1209 | self.r = function(json) {
1210 | this.before = json.origin;
1211 | this.after = json.current;
1212 | this.group = new r.GroupInfo(json.group);
1213 | }
1214 | self.r.prototype = {
1215 | type: r.EventTypeConst.BOT_GROUP_PERMISSION_CHANGE,
1216 | getBefore: function() {
1217 | return this.before;
1218 | },
1219 | getAfter: function() {
1220 | return this.after;
1221 | },
1222 | getGroup: function() {
1223 | return this.group;
1224 | },
1225 | }
1226 | return self.r;
1227 | } ()),
1228 | BotMuteEvent: (function self() {
1229 | self.r = function(json) {
1230 | this.duration = json.durationSeconds;
1231 | this.operator = new r.MessageSender(json.operator);
1232 | }
1233 | self.r.prototype = {
1234 | type: r.EventTypeConst.BOT_MUTE,
1235 | getDuration: function() {
1236 | return this.duration;
1237 | },
1238 | getOperator: function() {
1239 | return this.operator;
1240 | },
1241 | }
1242 | return self.r;
1243 | } ()),
1244 | BotUnmuteEvent: (function self() {
1245 | self.r = function(json) {
1246 | this.operator = new r.MessageSender(json.operator);
1247 | }
1248 | self.r.prototype = {
1249 | type: r.EventTypeConst.BOT_UNMUTE,
1250 | getOperator: function() {
1251 | return this.operator;
1252 | },
1253 | }
1254 | return self.r;
1255 | } ()),
1256 | BotJoinGroupEvent: (function self() {
1257 | self.r = function(json) {
1258 | this.group = new r.GroupInfo(json.group);
1259 | }
1260 | self.r.prototype = {
1261 | type: r.EventTypeConst.BOT_JOIN_GROUP,
1262 | getGroup: function() {
1263 | return this.group;
1264 | },
1265 | }
1266 | return self.r;
1267 | } ()),
1268 | GroupNameChangeEvent: (function self() {
1269 | self.r = function(json) {
1270 | this.before = json.origin;
1271 | this.after = json.current;
1272 | this.group = new r.GroupInfo(json.group);
1273 | this.isByBot = json.isByBot;
1274 | }
1275 | self.r.prototype = {
1276 | type: r.EventTypeConst.GROUP_NAME_CHANGE,
1277 | getBefore: function() {
1278 | return this.before;
1279 | },
1280 | getAfter: function() {
1281 | return this.after;
1282 | },
1283 | getGroup: function() {
1284 | return this.group;
1285 | },
1286 | isChangedByBot: function() {
1287 | return this.isByBot;
1288 | }
1289 | }
1290 | return self.r;
1291 | } ()),
1292 | GroupEntranceAnnouncementChangeEvent: (function self() {
1293 | self.r = function(json) {
1294 | this.before = json.origin;
1295 | this.after = json.current;
1296 | this.group = new r.GroupInfo(json.group);
1297 | this.operator = new r.MessageSender(json.operator);
1298 | }
1299 | self.r.prototype = {
1300 | type: r.EventTypeConst.GROUP_ENTRANCE_ANN_CHANGE,
1301 | getBefore: function() {
1302 | return this.before;
1303 | },
1304 | getAfter: function() {
1305 | return this.after;
1306 | },
1307 | getGroup: function() {
1308 | return this.group;
1309 | },
1310 | getOperator: function() {
1311 | return this.operator;
1312 | },
1313 | }
1314 | return self.r;
1315 | } ()),
1316 | GroupMuteAllEvent: (function self() {
1317 | self.r = function(json) {
1318 | this.before = json.origin;
1319 | this.after = json.current;
1320 | this.group = new r.GroupInfo(json.group);
1321 | this.operator = new r.MessageSender(json.operator);
1322 | }
1323 | self.r.prototype = {
1324 | type: r.EventTypeConst.GROUP_MUTE_ALL,
1325 | getBefore: function() {
1326 | return this.before;
1327 | },
1328 | getAfter: function() {
1329 | return this.after;
1330 | },
1331 | getGroup: function() {
1332 | return this.group;
1333 | },
1334 | getOperator: function() {
1335 | return this.operator;
1336 | },
1337 | }
1338 | return self.r;
1339 | } ()),
1340 | MemberJoinEvent: (function self() {
1341 | self.r = function(json) {
1342 | this.member = new r.MessageSender(json.member);
1343 | }
1344 | self.r.prototype = {
1345 | type: r.EventTypeConst.GROUP_MEMBER_JOIN,
1346 | getMember: function() {
1347 | return this.member;
1348 | },
1349 | }
1350 | return self.r;
1351 | } ()),
1352 | MemberLeaveEventKick: (function self() {
1353 | self.r = function(json) {
1354 | this.member = new r.MessageSender(json.member);
1355 | this.operator = new r.MessageSender(json.operator);
1356 | }
1357 | self.r.prototype = {
1358 | type: r.EventTypeConst.GROUP_MEMBER_KICK,
1359 | getTarget: function() {
1360 | return this.member;
1361 | },
1362 | getOperator: function() {
1363 | return this.operator;
1364 | },
1365 | }
1366 | return self.r;
1367 | } ()),
1368 | MemberLeaveEventQuit: (function self() {
1369 | self.r = function(json) {
1370 | this.member = new r.MessageSender(json.member);
1371 | }
1372 | self.r.prototype = {
1373 | type: r.EventTypeConst.GROUP_MEMBER_QUIT,
1374 | getMember: function() {
1375 | return this.member;
1376 | },
1377 | }
1378 | return self.r;
1379 | } ()),
1380 | MemberCardChangeEvent: (function self() {
1381 | self.r = function(json) {
1382 | this.before = json.origin;
1383 | this.after = json.current;
1384 | this.member = new r.MessageSender(json.member);
1385 | this.operator = new r.MessageSender(json.operator);
1386 | }
1387 | self.r.prototype = {
1388 | type: r.EventTypeConst.GROUP_MEMBER_NAME_CHANGE,
1389 | getBefore: function() {
1390 | return this.before;
1391 | },
1392 | getAfter: function() {
1393 | return this.after;
1394 | },
1395 | getTarget: function() {
1396 | return this.member;
1397 | },
1398 | getOperator: function() {
1399 | return this.operator;
1400 | },
1401 | }
1402 | return self.r;
1403 | } ()),
1404 | MemberSpecialTitleChangeEvent: (function self() {
1405 | self.r = function(json) {
1406 | this.before = json.origin;
1407 | this.after = json.current;
1408 | this.member = new r.MessageSender(json.member);
1409 | }
1410 | self.r.prototype = {
1411 | type: r.EventTypeConst.GROUP_MEMBER_FAME_CHANHE,
1412 | getBefore: function() {
1413 | return this.before;
1414 | },
1415 | getAfter: function() {
1416 | return this.after;
1417 | },
1418 | getTarget: function() {
1419 | return this.member;
1420 | },
1421 | }
1422 | return self.r;
1423 | } ()),
1424 | MemberPermissionChangeEvent: (function self() {
1425 | self.r = function(json) {
1426 | this.before = json.origin;
1427 | this.after = json.current;
1428 | this.member = new r.MessageSender(json.member);
1429 | }
1430 | self.r.prototype = {
1431 | type: r.EventTypeConst.GROUP_MEMBER_PERMISSION_CHANGE,
1432 | getBefore: function() {
1433 | return this.before;
1434 | },
1435 | getAfter: function() {
1436 | return this.after;
1437 | },
1438 | getTarget: function() {
1439 | return this.member;
1440 | },
1441 | }
1442 | return self.r;
1443 | } ()),
1444 | MemberMuteEvent: (function self() {
1445 | self.r = function(json) {
1446 | this.duration = json.durationSeconds;
1447 | this.member = new r.MessageSender(json.member);
1448 | this.operator = new r.MessageSender(json.operator);
1449 | }
1450 | self.r.prototype = {
1451 | type: r.EventTypeConst.GROUP_MEMBER_MUTE,
1452 | getDuration: function() {
1453 | return this.duration;
1454 | },
1455 | getOperator: function() {
1456 | return this.operator;
1457 | },
1458 | getTarget: function() {
1459 | return this.member;
1460 | },
1461 | }
1462 | return self.r;
1463 | } ()),
1464 | MemberUnmuteEvent: (function self() {
1465 | self.r = function(json) {
1466 | this.member = new r.MessageSender(json.member);
1467 | this.operator = new r.MessageSender(json.operator);
1468 | }
1469 | self.r.prototype = {
1470 | type: r.EventTypeConst.GROUP_MEMBER_UNMUTE,
1471 | getOperator: function() {
1472 | return this.operator;
1473 | },
1474 | getTarget: function() {
1475 | return this.member;
1476 | },
1477 | }
1478 | return self.r;
1479 | } ()),
1480 | //匿名,坦白说和允许群组成员邀请事件没啥用,就不写了
1481 | //放在这的原因是防止hookEvent时出现找不到对象的错误。
1482 | GroupAllowAnonymousChatEvent: function() {},
1483 | GroupAllowConfessTalkEvent: function() {},
1484 | GroupAllowMemberInviteEvent: function() {},
1485 | NewFriendRequestEvent: (function self() {
1486 | self.r = function(json, sessionKey) {
1487 | this.sessionKey = sessionKey;
1488 | this.eventId = json.eventId;
1489 | this.fromId = json.fromId;
1490 | this.groupId = json.groupId;
1491 | this.nickname = json.nick;
1492 | }
1493 | self.r.prototype = {
1494 | type: r.EventTypeConst.NEW_FRIEND_REQUEST,
1495 | getEventId: function() {
1496 | return this.eventId;
1497 | },
1498 | getFromId: function() {
1499 | return this.fromId;
1500 | },
1501 | getGroupId: function() {
1502 | return this.groupId;
1503 | },
1504 | getNickname: function() {
1505 | return this.nickname;
1506 | },
1507 | toIArg: function() {
1508 | return {
1509 | eventId: this.eventId,
1510 | fromId: this.fromId,
1511 | groupId: this.groupId
1512 | }
1513 | },
1514 | accept: function() {
1515 | r.__protocol.handleFriendRequest(this.sessionKey, this.eventId, this.fromId, this.groupId, 0);
1516 | },
1517 | reject: function() {
1518 | r.__protocol.handleFriendRequest(this.sessionKey, this.eventId, this.fromId, this.groupId, 1);
1519 | },
1520 | block: function() {
1521 | r.__protocol.handleFriendRequest(this.sessionKey, this.eventId, this.fromId, this.groupId, 2);
1522 | },
1523 | }
1524 | return self.r;
1525 | } ()),
1526 | MemberJoinRequestEvent: (function self() {
1527 | self.r = function(json, sessionKey) {
1528 | this.sessionKey = sessionKey;
1529 | this.eventId = json.eventId;
1530 | this.fromId = json.fromId;
1531 | this.groupId = json.groupId;
1532 | this.groupName = json.groupName;
1533 | this.nickname = json.nick;
1534 | }
1535 | self.r.prototype = {
1536 | type: r.EventTypeConst.NEW_MEMBER_JOIN_REQUEST,
1537 | getEventId: function() {
1538 | return this.eventId;
1539 | },
1540 | getFromId: function() {
1541 | return this.fromId;
1542 | },
1543 | getGroupId: function() {
1544 | return this.groupId;
1545 | },
1546 | getGroupName: function() {
1547 | return this.groupName;
1548 | },
1549 | getNickname: function() {
1550 | return this.nickname;
1551 | },
1552 | toIArg: function() {
1553 | return {
1554 | eventId: this.eventId,
1555 | fromId: this.fromId,
1556 | groupId: this.groupId
1557 | }
1558 | },
1559 | accept: function() {
1560 | r.__protocol.handleFriendRequest(this.sessionKey, this.eventId, this.fromId, this.groupId, 0);
1561 | },
1562 | reject: function() {
1563 | r.__protocol.handleFriendRequest(this.sessionKey, this.eventId, this.fromId, this.groupId, 1);
1564 | },
1565 | ignore: function() {
1566 | r.__protocol.handleFriendRequest(this.sessionKey, this.eventId, this.fromId, this.groupId, 2);
1567 | },
1568 | ignoreAndBlock: function() {
1569 | r.__protocol.handleFriendRequest(this.sessionKey, this.eventId, this.fromId, this.groupId, 3);
1570 | },
1571 | rejectAndBlock: function() {
1572 | r.__protocol.handleFriendRequest(this.sessionKey, this.eventId, this.fromId, this.groupId, 4);
1573 | },
1574 | }
1575 | return self.r;
1576 | } ()),
1577 | };
1578 | //通讯接口,不应包含任何消息处理
1579 | r.__protocol = {
1580 | //发送群组消息,成功返回消息id,失败返回0
1581 | sendGroupMessage: function(sessionKey, target, messageChain, quoteId) {
1582 | try {
1583 | var params = {
1584 | sessionKey: sessionKey,
1585 | target: Number(target),
1586 | messageChain: messageChain
1587 | };
1588 | if (quoteId != null) params.quote = Number(quoteId);
1589 | var result = JSON.parse(r.utils.http.post(r.server + "sendGroupMessage", JSON.stringify(params), [["Content-Type", "text/plain; charset=UTF-8"]]));
1590 | if (result.code == 0) {
1591 | r.Log.i("[" + sessionKey + "] Message have sent(groupId=" + target + ", messageId=" + result.messageId + ")");
1592 | return result.messageId;
1593 | } else {
1594 | r.Log.e("Error while sending group message. (groupId=" + target + ", messageChain=" + messageChain.toString() + ")\n" + result.msg);
1595 | return 0;
1596 | }
1597 | } catch(error) {
1598 | throw error;
1599 | }
1600 | },
1601 | //发送好友消息,成功返回消息id,失败返回0
1602 | sendFriendMessage: function(sessionKey, target, messageChain, quoteId) {
1603 | try {
1604 | var params = {
1605 | sessionKey: sessionKey,
1606 | target: Number(target),
1607 | messageChain: messageChain
1608 | };
1609 | if (quoteId != null) params.quote = Number(quoteId);
1610 | var result = JSON.parse(r.utils.http.post(r.server + "sendFriendMessage", JSON.stringify(params), [["Content-Type", "text/plain; charset=UTF-8"]]));
1611 | if (result.code == 0) {
1612 | r.Log.i("[" + sessionKey + "] Message have sent(friendId=" + target + ", messageId=" + result.messageId + ")");
1613 | return result.messageId;
1614 | } else {
1615 | r.Log.e("Error while sending group message. (groupId=" + target + ", messageChain=" + messageChain.toString() + ")\n" + result.msg);
1616 | return 0;
1617 | }
1618 | } catch(error) {
1619 | throw error;
1620 | }
1621 | },
1622 | //发送临时消息,成功返回消息id,失败返回0
1623 | sendTempMessage: function(sessionKey, target, from, messageChain, quoteId) {
1624 | try {
1625 | var params = {
1626 | sessionKey: sessionKey,
1627 | qq: target,
1628 | group: from,
1629 | messageChain: messageChain
1630 | };
1631 | if (quoteId != null) params.quote = Number(quoteId);
1632 | var p = r.utils.http.post(r.server + "sendTempMessage", JSON.stringify(params), [["Content-Type", "text/plain; charset=UTF-8"]]);
1633 | var result = JSON.parse(p);
1634 | if (result.code == 0) {
1635 | r.Log.i("[" + sessionKey + "] Message have sent(target=" + target + ", messageId=" + result.messageId + ")");
1636 | return result.messageId;
1637 | } else {
1638 | r.Log.e("Error while sending temp message. (target=" + target + ", messageChain=" + messageChain.toString() + ")\n" + result.msg);
1639 | return 0;
1640 | }
1641 | } catch(e) {
1642 | r.Log.e("Error while sending temp message. (target=" + target + ", messageChain=" + messageChain.toString() + ")\n" + e);
1643 | return 0;
1644 | }
1645 | },
1646 | //撤回,成功返回消息id,失败返回0
1647 | recall: function(sessionKey, target) {
1648 | try {
1649 | var params = {
1650 | sessionKey: sessionKey,
1651 | target: Number(target)
1652 | };
1653 | var p = r.utils.http.post(r.server + "recall", JSON.stringify(params), [["Content-Type", "text/plain; charset=UTF-8"]]);
1654 | var result = JSON.parse(p);
1655 | if (result.code == 0) {
1656 | r.Log.i("Message have recalled(messageId=" + target + ")");
1657 | return target;
1658 | } else {
1659 | r.Log.e("Error while recalling a message. (messageId=" + target + ")\n" + result.msg);
1660 | return 0;
1661 | }
1662 | } catch(e) {
1663 | r.Log.e("Error while recalling a message. (messageId=" + target + ")\n" + e);
1664 | return 0;
1665 | }
1666 | },
1667 | //发送好友消息,成功返回消息id,失败返回0
1668 | /*getCachedMessage: function(sessionKey, messageId) {
1669 | try {
1670 | var p = r.utils.http.get(r.server + "messageFromId?sessionKey=" + sessionKey + "&id=" + messageId);
1671 | var result = JSON.parse(p);
1672 | if (result.code == 5) {
1673 | r.Log.e("Message is not cached or messageid is invaild. " + result.msg + "(messageId=" + messageId + ")");
1674 | return new r.MessageChain();
1675 | } else {
1676 | return r.MessageChain._build(result.messageChain);
1677 | }
1678 | } catch(e) {
1679 | r.Log.e("Error while fetching a cached message.(messageId=" + messageId + ")\n" + e);
1680 | return new r.MessageChain();
1681 | }
1682 | },*/
1683 | //获取好友列表,失败返回空Array
1684 | getFriendList: function(sessionKey) {
1685 | try {
1686 | var p = r.utils.http.get(r.server + "friendList?sessionKey=" + sessionKey);
1687 | if (p.substr(0, 1) != "[") {
1688 | r.Log.e("Error while fetching friend list: " + JSON.parse(p).msg);
1689 | return [];
1690 | } else {
1691 | return eval("(" + p + ")");
1692 | }
1693 | } catch(e) {
1694 | r.Log.e("Error while fetching friend list: " + e);
1695 | }
1696 | },
1697 | //获取群组列表,失败返回空Array
1698 | getGroupList: function(sessionKey) {
1699 | try {
1700 | var p = r.utils.http.get(r.server + "groupList?sessionKey=" + sessionKey);
1701 | if (p.substr(0, 1) != "[") {
1702 | return [];
1703 | r.Log.e("Error while fetching group list: " + JSON.parse(p).msg);
1704 | } else {
1705 | return eval("(" + p + ")");
1706 | }
1707 | } catch(e) {
1708 | r.Log.e("Error while fetching group list: " + e);
1709 | }
1710 | },
1711 | //获取群成员列表,失败返回空Array
1712 | getGroupMemberList: function(sessionKey, id) {
1713 | try {
1714 | var p = r.utils.http.get(r.server + "memberList?sessionKey=" + sessionKey + "&target=" + id);
1715 | if (p.substr(0, 1) != "[") {
1716 | return [];
1717 | r.Log.e("Error while fetching group member list(groupId=" + id + "): " + JSON.parse(p).msg);
1718 | } else {
1719 | return eval("(" + p + ")");
1720 | }
1721 | } catch(e) {
1722 | r.Log.e("Error while fetching group member list: " + e);
1723 | }
1724 | },
1725 | mute: function(sessionKey, group, target, time) {
1726 | try {
1727 | var params = {
1728 | sessionKey: sessionKey,
1729 | target: Number(group),
1730 | memberId: Number(target),
1731 | time: Number(Math.min(Math.max(0, time), 2591999))
1732 | };
1733 | var p = r.utils.http.post(r.server + "mute", JSON.stringify(params), [["Content-Type", "text/plain; charset=UTF-8"]]);
1734 | var result = JSON.parse(p);
1735 | if (result.code == 0) {
1736 | r.Log.i("Group mute member(groupId=" + group + ", target=" + target + ", time=" + time + "s)");
1737 | } else {
1738 | r.Log.e("Error while calling mute group member(groupId=" + group + ", target=" + target + ", time=" + time + "s)\n" + result.msg);
1739 | }
1740 | } catch(e) {
1741 | r.Log.e("Error while calling mute group member(groupId=" + group + ", target=" + target + ", time=" + time + "s)\n" + e);
1742 | }
1743 | },
1744 | unmute: function(sessionKey, group, target) {
1745 | try {
1746 | var params = {
1747 | sessionKey: sessionKey,
1748 | target: Number(group),
1749 | memberId: Number(target)
1750 | };
1751 | var p = r.utils.http.post(r.server + "unmute", JSON.stringify(params), [["Content-Type", "text/plain; charset=UTF-8"]]);
1752 | var result = JSON.parse(p);
1753 | if (result.code == 0) {
1754 | r.Log.i("Group unmute member(groupId=" + group + ", target=" + target + ")");
1755 | } else {
1756 | r.Log.e("Error while calling unmute group member(groupId=" + group + ", target=" + target + ")\n" + result.msg);
1757 | }
1758 | } catch(e) {
1759 | r.Log.e("Error while calling unmute group member(groupId=" + group + ", target=" + target + ")\n" + e);
1760 | }
1761 | },
1762 | muteAll: function(sessionKey, group) {
1763 | try {
1764 | var params = {
1765 | sessionKey: sessionKey,
1766 | target: Number(group)
1767 | };
1768 | var p = r.utils.http.post(r.server + "muteAll", JSON.stringify(params), [["Content-Type", "text/plain; charset=UTF-8"]]);
1769 | var result = JSON.parse(p);
1770 | if (result.code == 0) {
1771 | r.Log.i("Group mute all(groupId=" + group + ")");
1772 | } else {
1773 | r.Log.e("Error while calling mute group all(groupId=" + group + ")\n" + result.msg);
1774 | }
1775 | } catch(e) {
1776 | r.Log.e("Error while calling mute group all(groupId=" + group + ")\n" + e);
1777 | }
1778 | },
1779 | unmuteAll: function(sessionKey, group) {
1780 | try {
1781 | var params = {
1782 | sessionKey: sessionKey,
1783 | target: Number(group)
1784 | };
1785 | var p = r.utils.http.post(r.server + "unmuteAll", JSON.stringify(params), [["Content-Type", "text/plain; charset=UTF-8"]]);
1786 | var result = JSON.parse(p);
1787 | if (result.code == 0) {
1788 | r.Log.i("Group unmute all(groupId=" + group + ")");
1789 | } else {
1790 | r.Log.e("Error while calling unmute group all(groupId)=" + group + ")\n" + result.msg);
1791 | }
1792 | } catch(e) {
1793 | r.Log.e("Error while calling unmute group all(groupId=" + group + ")\n" + e);
1794 | }
1795 | },
1796 | kick: function(sessionKey, group, target, msg) {
1797 | try {
1798 | var params = {
1799 | sessionKey: sessionKey,
1800 | target: Number(group),
1801 | memberId: Number(target),
1802 | msg: msg == null ? "您已被移除群聊": String(msg)
1803 | };
1804 | var p = r.utils.http.post(r.server + "kick", JSON.stringify(params), [["Content-Type", "text/plain; charset=UTF-8"]]);
1805 | var result = JSON.parse(p);
1806 | if (result.code == 0) {
1807 | r.Log.i("Group kick member(groupId=" + group + ", target=" + target + ")");
1808 | } else {
1809 | r.Log.e("Error while calling kicl group member(groupId=" + group + ", target=" + target + ")\n" + result.msg);
1810 | }
1811 | } catch(e) {
1812 | r.Log.e("Error while calling kick group member(groupId=" + group + ", target=" + target + ")\n" + e);
1813 | }
1814 | },
1815 | handleFriendRequest: function(sessionKey, eventId, fromId, groupId, isAccept, msg) {
1816 | try {
1817 | var params = {
1818 | sessionKey: sessionKey,
1819 | eventId: eventId,
1820 | fromId: fromId,
1821 | groupId: groupId,
1822 | operate: isAccept,
1823 | message: (msg == null ? "": msg)
1824 | }
1825 | var p = r.utils.http.post(r.server + "/resp/newFriendRequestEvent", JSON.stringify(params), [["Content-Type", "text/plain; charset=UTF-8"]]);
1826 | var result = JSON.parse(p);
1827 | if (result.code == 0) {
1828 | r.Log.i(((isAccept == 0) ? "Accepted": "Rejected") + "a new friend request.(qq=" + fromId + ((groupId == 0) ? "": (", from=" + groupId)) + ")");
1829 | } else {
1830 | r.Log.e("Error while handling new friend request(qq=" + fromId + ((groupId == 0) ? "": (", from=" + groupId)) + ")\n" + result.msg);
1831 | }
1832 | } catch(e) {
1833 | r.Log.e("Error while handling new friend request(qq=" + fromId + ((groupId == 0) ? "": (", from=" + groupId)) + ")\n" + e);
1834 | }
1835 | },
1836 | handleMemberJoinRequest: function(sessionKey, eventId, fromId, groupId, isAccept, msg) {
1837 | try {
1838 | var params = {
1839 | sessionKey: sessionKey,
1840 | eventId: eventId,
1841 | fromId: fromId,
1842 | groupId: groupId,
1843 | operate: isAccept,
1844 | message: (msg == null ? "": msg)
1845 | };
1846 | var p = r.utils.http.post(r.server + "/resp/memberJoinRequestEvent", JSON.stringify(params), [["Content-Type", "text/plain; charset=UTF-8"]]);
1847 | var result = JSON.parse(p);
1848 | if (result.code == 0) {
1849 | r.Log.i(((isAccept == 0) ? "Accepted": "Rejected") + "a member join request.(qq=" + fromId + ", group=" + groupId + ")");
1850 | } else {
1851 | r.Log.e("Error while handling member join request(qq=" + fromId + ", group=" + groupId + ")\n" + result.msg);
1852 | }
1853 | } catch(e) {
1854 | r.Log.e("Error while handling member join request(qq=" + fromId + ", group=" + groupId + ")\n" + e);
1855 | }
1856 | },
1857 | };
1858 | r.utils = {
1859 | http: {
1860 | getInputStream: function(url, headers) {
1861 | try {
1862 | var urlConnect = new java.net.URL(url);
1863 | var connection = urlConnect.openConnection();
1864 | if (headers != null) {
1865 | for (var i in headers) {
1866 | connection.setRequestProperty(headers[i][0], headers[i][1]);
1867 | }
1868 | }
1869 | connection.setDoInput(true);
1870 | connection.connect();
1871 | return [connection.getContentLength(), connection.getInputStream()];
1872 | } catch(e) {
1873 | return [0, 0];
1874 | }
1875 | },
1876 | post: function(url, param, headers) {
1877 | //r.Log.i("POST: " + url + "\nparams: " + _toSource(param));
1878 | var result = "";
1879 | var bufferedReader = null;
1880 | var printWriter = null;
1881 | try {
1882 | var urlConnect = new java.net.URL(url);
1883 | var connection = urlConnect.openConnection();
1884 | for (var i in headers) {
1885 | connection.setRequestProperty(headers[i][0], headers[i][1]);
1886 | }
1887 | connection.setConnectTimeout(12000);
1888 | connection.setDoOutput(true);
1889 | connection.setDoInput(true);
1890 | printWriter = new java.io.PrintWriter(connection.getOutputStream());
1891 | printWriter.print(param);
1892 | printWriter.flush();
1893 | bufferedReader = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
1894 | var line;
1895 | while ((line = bufferedReader.readLine()) != null && !java.lang.Thread.currentThread().isInterrupted()) {
1896 | result += line;
1897 | }
1898 | if (bufferedReader != null) bufferedReader.close();
1899 | if (printWriter != null) printWriter.close();
1900 | } catch(error) {
1901 | if (bufferedReader != null) bufferedReader.close();
1902 | if (printWriter != null) printWriter.close();
1903 | if (! (/InterruptedException/i).test(error.toString())) throw "Error while posting " + url + " : " + error;
1904 | }
1905 | return result;
1906 | },
1907 | get: function(url, headers) {
1908 | var result = "";
1909 | var bufferedReader = null;
1910 | try {
1911 | var urlConnect = new java.net.URL(url);
1912 | var connection = urlConnect.openConnection();
1913 | for (var i in headers) {
1914 | connection.setRequestProperty(headers[i][0], headers[i][1]);
1915 | }
1916 | connection.setConnectTimeout(12000);
1917 | connection.setDoInput(true);
1918 | bufferedReader = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
1919 | var line;
1920 | while ((line = bufferedReader.readLine()) != null && !java.lang.Thread.currentThread().isInterrupted()) {
1921 | result += (line + "\n");
1922 | }
1923 | if (bufferedReader != null) bufferedReader.close();
1924 | } catch(error) {
1925 | if (bufferedReader != null) bufferedReader.close();
1926 | if (! (/InterruptedException/i).test(error.toString())) throw "Error while grtting " + url + " : " + error;
1927 | }
1928 | return result;
1929 | },
1930 | },
1931 | file: {
1932 | STRING: 1,
1933 | STREAM: 2,
1934 | create: function(storage) {
1935 | storage = storage.split(java.io.File.separator);
1936 | if ((/\./i).test(storage[storage.length - 1]) && !(/^\./i).test(storage[storage.length - 1])) {
1937 | var path = "";
1938 | for (var i in storage) path += ((i == storage.length - 1) ? ("") : (storage[i]) + ((i == storage.length - 1) ? ("") : (java.io.File.separator)));
1939 | var file = path + storage[storage.length - 1];
1940 | var pathF = new java.io.File(path);
1941 | if (!pathF.isDirectory() || !pathF.exists()) pathF.mkdirs();
1942 | var fileF = new java.io.File(file);
1943 | if (!fileF.isFile() || !fileF.exists()) fileF.createNewFile();
1944 | } else {
1945 | var path = "";
1946 | for (var i in storage) path += ((storage[i]) + ((i == storage.length - 1) ? ("") : (java.io.File.separator)));
1947 | var file = new java.io.File(path);
1948 | if (!file.isDirectory() || !file.exists()) file.mkdirs();
1949 | }
1950 | },
1951 | remove: function(storage) {
1952 | var path = new java.io.File(storage);
1953 | if (path.exists()) path.delete();
1954 | },
1955 | read: function(path, mode) {
1956 | var file = new java.io.File(path);
1957 | if (file.exists()) {
1958 | try {
1959 | var inputStream = new java.io.FileInputStream(file);
1960 | if (mode == this.STREAM) {
1961 | return inputStream;
1962 | return new java.io.ByteArrayInputStream(byteArray);
1963 | } else {
1964 | var inputStreamReader = new java.io.InputStreamReader(inputStream);
1965 | var bufferedReader = new java.io.BufferedReader(inputStreamReader);
1966 | var stringBuffer = new java.lang.StringBuffer();
1967 | var line = null;
1968 | while ((line = bufferedReader.readLine()) != null && !java.lang.Thread.currentThread().isInterrupted()) {
1969 | stringBuffer.append(line);
1970 | stringBuffer.append("\n");
1971 | }
1972 | inputStreamReader.close();
1973 | return stringBuffer.toString();
1974 | }
1975 | } catch(error) {
1976 | if (! (/InterruptedException/i).test(error.toString())) throw error;
1977 | return "";
1978 | }
1979 | } else {
1980 | throw ("File not exist: " + path);
1981 | return "";
1982 | }
1983 | },
1984 | writeString: function(path, string, isCover) {
1985 | try {
1986 | var file = new java.io.File(path);
1987 | if (!file.exists()) {
1988 | file.createNewFile();
1989 | isCover = true;
1990 | }
1991 | if (isCover == false) {
1992 | return;
1993 | }
1994 | var fileWriter = new java.io.FileWriter(file);
1995 | fileWriter.write(string);
1996 | fileWriter.close();
1997 | } catch(error) {
1998 | if (! (/InterruptedException/i).test(error.toString())) throw error;
1999 | }
2000 | },
2001 | writeStream: function(path, inputStream, isCover, isInputStreamClose) {
2002 | try {
2003 | var file = new java.io.File(path);
2004 | if (!file.exists()) {
2005 | file.createNewFile();
2006 | isCover = true;
2007 | }
2008 | if (isCover == false) {
2009 | if (isInputStreamClose) inputStream.close();
2010 | return;
2011 | }
2012 | var buffer = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 4096);
2013 | var outputStream = new java.io.FileOutputStream(file);
2014 | var len = -1;
2015 | while ((len = inputStream.read(buffer)) != -1 && !java.lang.Thread.currentThread().isInterrupted()) {
2016 | outputStream.write(buffer, 0, len);
2017 | }
2018 | if (isInputStreamClose) inputStream.close();
2019 | outputStream.flush();
2020 | outputStream.close();
2021 | } catch(error) {
2022 | if (! (/InterruptedException/i).test(error.toString())) throw error;
2023 | }
2024 | },
2025 | append: function(path, appendString) {
2026 | try {
2027 | var randomAccessFile = new java.io.RandomAccessFile(path, "rw");
2028 | randomAccessFile.seek(randomAccessFile.length());
2029 | randomAccessFile.write(java.lang.String(appendString).getBytes());
2030 | randomAccessFile.close();
2031 | } catch(error) {
2032 | if (! (/InterruptedException/i).test(error.toString())) throw error;
2033 | }
2034 | }
2035 | },
2036 | rsync: (function() {
2037 | var r = function(func) {
2038 | this.i_loop_times = 1;
2039 | this.i_interval = 0;
2040 | this.i_corun_count = 1;
2041 | this.i_flag = (function(length) {
2042 | var string = "0123456789abcde";
2043 | var stringBuffer = new java.lang.StringBuffer();
2044 | for (var i = 0; i < length; i++) {
2045 | stringBuffer.append(string.charAt(Math.round(Math.random() * (string.length - 1))));
2046 | }
2047 | return stringBuffer.toString();
2048 | } (5));
2049 | this.i_name = "RsyncThreadGroup-unnamed@" + this.i_flag;
2050 | this.i_func = func == null ? new Function() : func;
2051 | this.threads = [];
2052 | }
2053 | r.prototype = {
2054 | __runnable_function: function() {
2055 | try {
2056 | var lt = this.i_loop_times;
2057 | while (lt != 0 && !java.lang.Thread.currentThread().isInterrupted()) {
2058 | this.i_func(this, Number(String(java.lang.Thread.currentThread().getName()).split("-")[2]));
2059 | if (this.i_interval > 0) this.sleep(this.i_interval);
2060 | if (lt > 0) lt--;
2061 | }
2062 | } catch(error) {
2063 | if (! (/InterruptedException/i).test(error.toString())) {
2064 | r.Log.e(error);
2065 | }
2066 | }
2067 | },
2068 |
2069 | run: function(obj, isForce) {
2070 | if (this._isRunning() && !isForce) throw ("Thread " + this.i_name + " is running.");
2071 | if (obj != null) this.i_func = obj;
2072 | if (this.threads.length != 0) this.threads.splice(0, this.threads.length);
2073 | const self = this;
2074 | for (var i = 0; i < this.i_corun_count; i++) {
2075 | var t = new java.lang.Thread(new java.lang.Runnable({
2076 | run: function() {
2077 | self.__runnable_function();
2078 | },
2079 | }));
2080 | t.setName(this.i_name + "-" + i);
2081 | this.threads.push(t);
2082 | t.start();
2083 | }
2084 | return this;
2085 | },
2086 | loop: function(obj, times, interval) {
2087 | this.loop_times(times == null ? -1 : times);
2088 | this.interval(interval == null ? 0 : interval);
2089 | return this.run(obj);
2090 | },
2091 | corun: function(obj, count) {
2092 | this.co_count(count == null ? 1 : count);
2093 | return this.run(obj);
2094 | },
2095 |
2096 | _isRunning: function() {
2097 | for (var i in this.threads) {
2098 | if (this.threads[i].getState() != java.lang.Thread.State.TERMINATED) {
2099 | return true;
2100 | }
2101 | }
2102 | return false;
2103 | },
2104 |
2105 | _containsThread: function(id) {
2106 | for (var i in this.threads) {
2107 | if (this.threads[i].getId() == id) return true;
2108 | }
2109 | return false;
2110 | },
2111 |
2112 | flag: function(v) {
2113 | if (v != null) {
2114 | if (this._containsThread(java.lang.Thread.currentThread().getId())) {
2115 | throw "Changing its own property in self thread is not permitted.";
2116 | };
2117 | this.i_name = "RsyncThreadGroup-" + v.replace(/(\t|\s|\r|\n|\-)/gi, "") + "@" + this.i_flag;
2118 | return this;
2119 | } else {
2120 | return this.i_name;
2121 | }
2122 | },
2123 | interval: function(v) {
2124 | if (typeof(v) == "number") {
2125 | if (this._containsThread(java.lang.Thread.currentThread().getId())) {
2126 | throw "Changing its own property in self thread is not permitted.";
2127 | };
2128 | this.i_interval = v;
2129 | return this;
2130 | } else {
2131 | return this.i_interval;
2132 | }
2133 | },
2134 | co_count: function(v) {
2135 | if (typeof(v) == "number") {
2136 | if (this._containsThread(java.lang.Thread.currentThread().getId())) {
2137 | throw "Changing its own property in self thread is not permitted.";
2138 | };
2139 | this.i_corun_count = v;
2140 | return this;
2141 | } else {
2142 | return this.i_co_count;
2143 | }
2144 | },
2145 | loop_times: function(v) {
2146 | if (typeof(v) == "number") {
2147 | if (this._containsThread(java.lang.Thread.currentThread().getId())) {
2148 | throw "Changing its own property in self thread is not permitted.";
2149 | };
2150 | this.i_loop_times = v;
2151 | return this;
2152 | } else {
2153 | return this.i_loop_times;
2154 | }
2155 |
2156 | },
2157 | _func: function(v) {
2158 | if (this._containsThread(java.lang.Thread.currentThread().getId())) {
2159 | throw "Changing its own property in self thread is not permitted.";
2160 | }
2161 | this.i_func = v;
2162 | return this;
2163 | },
2164 | sleep: function(v) {
2165 | var times = (v > 100) ? (v - (v % 100)) / 100 + 1 : 1;
2166 | var t = v;
2167 | while (times > 0 && !java.lang.Thread.currentThread().isInterrupted()) {
2168 | if (t > 100) {
2169 | java.lang.Thread.sleep(100);
2170 | t -= 100;
2171 | times--;
2172 | } else {
2173 | java.lang.Thread.sleep(t);
2174 | times--;
2175 | }
2176 | }
2177 | },
2178 | stop: function(afk) {
2179 | for (var i in this.threads) {
2180 | if (this.threads[i].getState() != java.lang.Thread.State.TERMINATED) {
2181 | this.threads[i].interrupt();
2182 | if (java.lang.Thread.currentThread().getId() == this.threads[i].getId()) {
2183 | throw new java.lang.InterruptedException(this.threads[i].getName() + " interrupted.");
2184 | }
2185 | }
2186 | }
2187 | if(afk != null) afk();
2188 | },
2189 | restart: function() {
2190 | this.stop(() => this.run(null, true));
2191 | }
2192 | };
2193 | r.interval = function(n) {
2194 | var a = new this();
2195 | a.interval(n);
2196 | return a;
2197 | };
2198 | r.loop_times = function(n) {
2199 | var a = new this();
2200 | a.loop_times(n);
2201 | return a;
2202 | };
2203 | r.co_count = function(n) {
2204 | var a = new this();
2205 | a.co_count(n);
2206 | return a;
2207 | };
2208 | r.flag = function(n) {
2209 | var a = new this();
2210 | a.flag(n);
2211 | return a;
2212 | };
2213 | r.run = function(obj) {
2214 | var a = new this(obj);
2215 | a.run();
2216 | return a;
2217 | };
2218 | r.corun = function(obj, count) {
2219 | var a = new this(obj);
2220 | a.co_count(count == null ? 1 : count);
2221 | a.run();
2222 | return a;
2223 | };
2224 | r.loop = function(obj, times, interval) {
2225 | var a = new this(obj);
2226 | a.loop_times(times == null ? -1 : times);
2227 | a.interval(interval == null ? 0 : interval);
2228 | a.run();
2229 | return a;
2230 | };
2231 | return r;
2232 | } ()),
2233 |
2234 | };
2235 | r.Log = {
2236 | v: function(msg) {
2237 | if (r.host == r.ANDROID_AUTOJS) {
2238 | console.verbose(msg);
2239 | } else {
2240 | java.lang.System.out.println("[" + (new java.text.SimpleDateFormat("yyyy.MM.dd hh:mm:ss")).format((new Date()).getTime()) + "][V] " + String(msg));
2241 | }
2242 |
2243 | },
2244 | w: function(msg) {
2245 | if (r.host == r.ANDROID_AUTOJS) {
2246 | console.warn(msg);
2247 | } else {
2248 | java.lang.System.out.println("[" + (new java.text.SimpleDateFormat("yyyy.MM.dd hh:mm:ss")).format((new Date()).getTime()) + "][\u001B[33mW\u001B[0m] " + String(msg));
2249 | }
2250 |
2251 | },
2252 | i: function(msg) {
2253 | if (r.host == r.ANDROID_AUTOJS) {
2254 | console.info(msg);
2255 | } else {
2256 | java.lang.System.out.println("[" + (new java.text.SimpleDateFormat("yyyy.MM.dd hh:mm:ss")).format((new Date()).getTime()) + "][\u001B[32mI\u001B[0m] " + String(msg));
2257 | }
2258 |
2259 | },
2260 | e: function(msg) {
2261 | if (r.host == r.ANDROID_AUTOJS) {
2262 | console.error(msg);
2263 | } else {
2264 | java.lang.System.out.println("[" + (new java.text.SimpleDateFormat("yyyy.MM.dd hh:mm:ss")).format((new Date()).getTime()) + "][\u001B[31mE\u001B[0m] In thread " + java.lang.Thread.currentThread().getName() + " : " + (function() {
2265 | if (msg instanceof Error) {
2266 | return "Error: " + msg.toString() + "(" + msg.lineNumber + ")";
2267 | } else {
2268 | return msg;
2269 | }
2270 | } ()) + "\u001B[0m");
2271 | }
2272 |
2273 | },
2274 | };
2275 |
2276 | return r;
2277 | } ()
2278 |
--------------------------------------------------------------------------------
/source/wrapper.js:
--------------------------------------------------------------------------------
1 | const scope = this;
2 |
3 | var host = java.lang.System.getProperty("os.name"), ajs = false;
4 | if("context" in scope) {host = "Android_AutoJS"; ajs = true; console.show();}
5 |
6 | var http_get = function(url) {
7 | var result = [];
8 | var bufferedReader = null;
9 | try {
10 | var urlConnect = new java.net.URL(url);
11 | var connection = urlConnect.openConnection();
12 | connection.setDoInput(true);
13 | bufferedReader = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
14 | var line;
15 | while ((line = bufferedReader.readLine()) != null) {
16 | result.push(line);
17 | }
18 | if (bufferedReader != null) bufferedReader.close();
19 | } catch (error) {
20 | if (bufferedReader != null) bufferedReader.close();
21 | throw error;
22 | }
23 | return result.join("\n");
24 | }
25 | var readStdinLine = function() {
26 | var is = new java.io.InputStreamReader(java.lang.System.in);
27 | var br = new java.io.BufferedReader(is);
28 | var r = br.readLine();
29 | return r;
30 | }
31 | var log = function(str){
32 | if(ajs) {
33 | console.log(str);
34 | } else {
35 | java.lang.System.out.println(str);
36 | }
37 | }
38 |
39 | //实现core版本后将会开放版本选择
40 | /*var prompt = "请选择 Mirai RhinoJS SDK 版本!\n它们的异同请在项目readme中查看。"
41 | var iflag = false;
42 | var input, options = ["core", "http", "ws"];
43 | log(prompt);
44 | while(!iflag) {
45 | if(ajs) {
46 | input = options[dialogs.select(prompt, options)];
47 | } else {
48 | input = readStdinLine();
49 | }
50 | for(var i in options) {
51 | if(input == options[i]) iflag = true;
52 | }
53 | if(!iflag) log("无效选择,请重试!");
54 | }*/
55 |
56 | var input = "http";
57 | scope["Mirai"] = eval("(" + http_get("https://raw.githubusercontent.com/StageGuard/mirai-rhinojs-sdk/master/source/MiraiQQBot." + input + ".js") + ")");
58 |
59 | delete host;
60 | delete http_get;
61 | delete log;
62 | delete input;
63 | delete readStdinLine;
64 |
65 | Mirai.init(scope);
--------------------------------------------------------------------------------
/static/poke.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/StageGuard/mirai-rhinojs-sdk/6d0a997b2cb29c1fba1c044d5f37335845cb5ffa/static/poke.png
--------------------------------------------------------------------------------