├── .gitignore ├── .run └── Run Mirai Console.run.xml ├── LICENSE ├── README.md ├── build.gradle.kts ├── conf └── callApi │ └── conf.json ├── gradle.properties ├── gradle └── wrapper │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts ├── src └── main │ ├── java │ └── io │ │ └── github │ │ └── gdpl2112 │ │ └── mirai │ │ └── p1 │ │ ├── CallApiPlugin.java │ │ ├── CallTemplate.java │ │ ├── CommandLine0.kt │ │ ├── Conf.java │ │ ├── Converter.java │ │ ├── ManagerConf.java │ │ ├── Parse.java │ │ ├── Worker.java │ │ ├── rest │ │ └── RestController0.java │ │ └── services │ │ ├── DgSerializer.java │ │ ├── ScriptService.java │ │ └── script │ │ ├── BaseMessageScriptContext.java │ │ ├── BaseScriptUtils.java │ │ ├── ScriptContext.java │ │ └── ScriptUtils.java │ └── resources │ ├── META-INF │ └── services │ │ └── net.mamoe.mirai.console.plugin.jvm.JvmPlugin │ └── static │ ├── css │ └── libs │ │ ├── bootstarp@5.1.3_min.css │ │ └── http_cdn.jsdelivr.net_npm_bootstrap@4.6.2_dist_css_bootstrap.css │ ├── index.html │ └── js │ ├── index.js │ └── libs │ ├── axios.js │ ├── http_cdn.jsdelivr.net_npm_bootstrap@4.6.2_dist_js_bootstrap.bundle.js │ ├── http_cdn.jsdelivr.net_npm_bootstrap@5.1.3_dist_js_bootstrap.bundle.js │ ├── http_cdn.jsdelivr.net_npm_jquery@3.5.1_dist_jquery.slim.min.js │ ├── jq3.6.js │ └── vue.js └── updataLog ├── expression.md ├── img.png ├── v1.5.md ├── v1.6.md ├── v1.7.md ├── v1.8.md ├── v2.4.md └── v2.8.md /.gitignore: -------------------------------------------------------------------------------- 1 | # User-specific stuff 2 | .idea/ 3 | 4 | *.iml 5 | *.ipr 6 | *.iws 7 | 8 | # IntelliJ 9 | out/ 10 | # mpeltonen/sbt-idea plugin 11 | .idea_modules/ 12 | 13 | # JIRA plugin 14 | atlassian-ide-plugin.xml 15 | 16 | # Compiled class file 17 | *.class 18 | 19 | # Log file 20 | *.log 21 | 22 | # BlueJ files 23 | *.ctxt 24 | 25 | # Package Files # 26 | *.jar 27 | *.war 28 | *.nar 29 | *.ear 30 | *.zip 31 | *.tar.gz 32 | *.rar 33 | 34 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 35 | hs_err_pid* 36 | 37 | *~ 38 | 39 | # temporary files which can be created if a process still has a handle open of a deleted file 40 | .fuse_hidden* 41 | 42 | # KDE directory preferences 43 | .directory 44 | 45 | # Linux trash folder which might appear on any partition or disk 46 | .Trash-* 47 | 48 | # .nfs files are created when an open file is removed but is still being accessed 49 | .nfs* 50 | 51 | # General 52 | .DS_Store 53 | .AppleDouble 54 | .LSOverride 55 | 56 | # Icon must end with two \r 57 | Icon 58 | 59 | # Thumbnails 60 | ._* 61 | 62 | # Files that might appear in the root of a volume 63 | .DocumentRevisions-V100 64 | .fseventsd 65 | .Spotlight-V100 66 | .TemporaryItems 67 | .Trashes 68 | .VolumeIcon.icns 69 | .com.apple.timemachine.donotpresent 70 | 71 | # Directories potentially created on remote AFP share 72 | .AppleDB 73 | .AppleDesktop 74 | Network Trash Folder 75 | Temporary Items 76 | .apdisk 77 | 78 | # Windows thumbnail cache files 79 | Thumbs.db 80 | Thumbs.db:encryptable 81 | ehthumbs.db 82 | ehthumbs_vista.db 83 | 84 | # Dump file 85 | *.stackdump 86 | 87 | # Folder config file 88 | [Dd]esktop.ini 89 | 90 | # Recycle Bin used on file shares 91 | $RECYCLE.BIN/ 92 | 93 | # Windows Installer files 94 | *.cab 95 | *.msi 96 | *.msix 97 | *.msm 98 | *.msp 99 | 100 | # Windows shortcuts 101 | *.lnk 102 | 103 | .gradle 104 | build/ 105 | 106 | # Ignore Gradle GUI config 107 | gradle-app.setting 108 | 109 | # Cache of project 110 | .gradletasknamecache 111 | 112 | **/build/ 113 | 114 | # Common working directory 115 | run/ 116 | 117 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 118 | !gradle-wrapper.jar 119 | 120 | 121 | # Local Test Launch point 122 | src/test/kotlin/RunTerminal.kt 123 | 124 | # Mirai console files with direct bootstrap 125 | /config 126 | /data 127 | /plugins 128 | /bots 129 | 130 | # Local Test Launch Point working directory 131 | /debug-sandbox 132 | ### Java template 133 | # Compiled class file 134 | *.class 135 | 136 | # Log file 137 | *.log 138 | 139 | # BlueJ files 140 | *.ctxt 141 | 142 | # Mobile Tools for Java (J2ME) 143 | .mtj.tmp/ 144 | 145 | # Package Files # 146 | *.jar 147 | *.war 148 | *.nar 149 | *.ear 150 | *.zip 151 | *.tar.gz 152 | *.rar 153 | 154 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 155 | hs_err_pid* 156 | replay_pid* 157 | 158 | ### JetBrains template 159 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 160 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 161 | 162 | # User-specific stuff 163 | .idea/**/workspace.xml 164 | .idea/**/tasks.xml 165 | .idea/**/usage.statistics.xml 166 | .idea/**/dictionaries 167 | .idea/**/shelf 168 | 169 | # AWS User-specific 170 | .idea/**/aws.xml 171 | 172 | # Generated files 173 | .idea/**/contentModel.xml 174 | 175 | # Sensitive or high-churn files 176 | .idea/**/dataSources/ 177 | .idea/**/dataSources.ids 178 | .idea/**/dataSources.local.xml 179 | .idea/**/sqlDataSources.xml 180 | .idea/**/dynamic.xml 181 | .idea/**/uiDesigner.xml 182 | .idea/**/dbnavigator.xml 183 | 184 | # Gradle 185 | .idea/**/gradle.xml 186 | .idea/**/libraries 187 | 188 | # Gradle and Maven with auto-import 189 | # When using Gradle or Maven with auto-import, you should exclude module files, 190 | # since they will be recreated, and may cause churn. Uncomment if using 191 | # auto-import. 192 | # .idea/artifacts 193 | # .idea/compiler.xml 194 | # .idea/jarRepositories.xml 195 | # .idea/modules.xml 196 | # .idea/*.iml 197 | # .idea/modules 198 | # *.iml 199 | # *.ipr 200 | 201 | # CMake 202 | cmake-build-*/ 203 | 204 | # Mongo Explorer plugin 205 | .idea/**/mongoSettings.xml 206 | 207 | # File-based project format 208 | *.iws 209 | 210 | # IntelliJ 211 | out/ 212 | 213 | # mpeltonen/sbt-idea plugin 214 | .idea_modules/ 215 | 216 | # JIRA plugin 217 | atlassian-ide-plugin.xml 218 | 219 | # Cursive Clojure plugin 220 | .idea/replstate.xml 221 | 222 | # SonarLint plugin 223 | .idea/sonarlint/ 224 | 225 | # Crashlytics plugin (for Android Studio and IntelliJ) 226 | com_crashlytics_export_strings.xml 227 | crashlytics.properties 228 | crashlytics-build.properties 229 | fabric.properties 230 | 231 | # Editor-based Rest Client 232 | .idea/httpRequests 233 | 234 | # Android studio 3.1+ serialized cache file 235 | .idea/caches/build_file_checksums.ser 236 | 237 | ### Example user template template 238 | ### Example user template 239 | 240 | # IntelliJ project files 241 | .idea 242 | *.iml 243 | out 244 | gen 245 | ### Gradle template 246 | .gradle 247 | **/build/ 248 | !src/**/build/ 249 | 250 | # Ignore Gradle GUI config 251 | gradle-app.setting 252 | 253 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 254 | !gradle-wrapper.jar 255 | 256 | # Avoid ignore Gradle wrappper properties 257 | !gradle-wrapper.properties 258 | 259 | # Cache of project 260 | .gradletasknamecache 261 | 262 | # Eclipse Gradle plugin generated files 263 | # Eclipse Core 264 | .project 265 | # JDT-specific (Eclipse Java Development Tools) 266 | .classpath 267 | 268 | ### Kotlin template 269 | # Compiled class file 270 | *.class 271 | 272 | # Log file 273 | *.log 274 | 275 | # BlueJ files 276 | *.ctxt 277 | 278 | # Mobile Tools for Java (J2ME) 279 | .mtj.tmp/ 280 | 281 | # Package Files # 282 | *.jar 283 | *.war 284 | *.nar 285 | *.ear 286 | *.zip 287 | *.tar.gz 288 | *.rar 289 | 290 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 291 | hs_err_pid* 292 | replay_pid* 293 | 294 | -------------------------------------------------------------------------------- /.run/Run Mirai Console.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 16 | 21 | 23 | true 24 | true 25 | false 26 | false 27 | 28 | 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 自定义 调用 API 插件 2 | 3 | [下载](https://github.com/gdpl2112/MiraiCallApiPlugin/releases) 4 | 5 | ~~### 插件依赖于插件[lib-tts](https://github.com/gdpl2112/lib-tts/releases/)~~ 6 | 7 | #### [表达式](./updataLog/expression.md) 8 | 9 | ### 10 | 11 | 启动后生成配置文件 12 | 13 | ```json 14 | { 15 | //忽略https证书 16 | "ignoreVerify": true, 17 | //权限类型 有 console all 当为 console 时只能从命令调用 all 则所有都可以 18 | "permType": "console", 19 | //输入 参数分隔符 20 | "splitChar": " ", 21 | //网页管理的端口 22 | "port": 20042, 23 | //全局代理ip 24 | "proxyIp": null, 25 | //全局代理port 26 | "proxyPort": 0, 27 | //网页管理的密码 28 | "passwd": "123456", 29 | //api 调用模板 30 | "templates": [ 31 | ] 32 | } 33 | ``` 34 | 35 | ### templates 如何配置 36 | 37 | 示例涩图配置 38 | 39 | ```json 40 | 41 | { 42 | "permType": "all", 43 | "splitChar": " ", 44 | "templates": [ 45 | { 46 | "err": "调用失败", 47 | "out": "", 48 | "outArgs": [ 49 | "pic[0]" 50 | ], 51 | "proxyIp": "", 52 | "proxyPort": 0, 53 | "sw": true, 54 | "touch": "随机图片", 55 | "url": "http://api.iw233.cn/api.php?sort=cat&type=json" 56 | } 57 | ] 58 | } 59 | ``` 60 | 61 | - $1 $2 即参数1 参数2 outArgs 指定返回的 数据为 参数N 62 | - $qid 表示发送者id 63 | - $gid 表示所处群id 64 | 65 | 转换后内部通过转换成message 66 | 67 | 见 [详情表达式](https://github.com/gdpl2112/MiraiCallApiPlugin#%E8%A1%A8%E8%BE%BE%E5%BC%8F) 68 | 69 | 配置后 在群聊/好友 发送 随机图片 即可触发 70 | 71 | ### 复杂的返回参数 72 | 73 |
74 | 75 | 以下是 https://api.vvhan.com/api/weather?city=徐州&type=week 该 API 返回的数据 76 | 77 | 78 | ```json 79 | { 80 | "data": { 81 | "yesterday": { 82 | "date": "30日星期三", 83 | "high": "高温 4℃", 84 | "fx": "西南风", 85 | "low": "低温 -1℃", 86 | "fl": "", 87 | "type": "雨夹雪" 88 | }, 89 | "city": "西安", 90 | "forecast": [ 91 | { 92 | "date": "31日星期四", 93 | "high": "高温 7℃", 94 | "fengli": "", 95 | "low": "低温 -6℃", 96 | "fengxiang": "西南风", 97 | "type": "小雪" 98 | }, 99 | { 100 | "date": "1日星期五", 101 | "high": "高温 7℃", 102 | "fengli": "", 103 | "low": "低温 -4℃", 104 | "fengxiang": "东北风", 105 | "type": "多云" 106 | }, 107 | { 108 | "date": "2日星期六", 109 | "high": "高温 7℃", 110 | "fengli": "", 111 | "low": "低温 -3℃", 112 | "fengxiang": "西南风", 113 | "type": "多云" 114 | }, 115 | { 116 | "date": "3日星期天", 117 | "high": "高温 10℃", 118 | "fengli": "", 119 | "low": "低温 -1℃", 120 | "fengxiang": "南风", 121 | "type": "多云" 122 | }, 123 | { 124 | "date": "4日星期一", 125 | "high": "高温 8℃", 126 | "fengli": "", 127 | "low": "低温 -3℃", 128 | "fengxiang": "东北风", 129 | "type": "多云" 130 | } 131 | ], 132 | "ganmao": "昼夜温差很大,易发生感冒,请注意适当增减衣服,加强自我防护避免感冒。", 133 | "wendu": "2" 134 | }, 135 | "status": 1000, 136 | "desc": "OK" 137 | } 138 | ``` 139 | 140 |
141 | 142 | - 配置后 在群聊/好友 发送 未来天气 <城市名> 即可触发 143 | 144 |
145 | 配置文件 146 | 147 | ```json 148 | 149 | { 150 | "permType": "all", 151 | "splitChar": " ", 152 | "templates": [ 153 | { 154 | "out": "$1:$2\n$3:$4\n$5:$6\n", 155 | "outArgs": [ 156 | "data.forecast[0].date", 157 | "data.forecast[0].type", 158 | "data.forecast[1].date", 159 | "data.forecast[1].type", 160 | "data.forecast[2].date", 161 | "data.forecast[2].type" 162 | ], 163 | "touch": "未来天气", 164 | "url": "https://api.vvhan.com/api/weather?city=$1&type=week", 165 | "err": "天气查询失败" 166 | } 167 | ] 168 | } 169 | ``` 170 | 171 |
172 | 173 | ### 最后送上实用配置 174 | 175 |
176 | 配置文件 177 | 178 | ```json 179 | { 180 | "passwd": "123456", 181 | "permType": "all", 182 | "port": 20042, 183 | "proxyIp": null, 184 | "proxyPort": 0, 185 | "splitChar": " ", 186 | "templates": [ 187 | { 188 | "err": "天气查询失败", 189 | "out": "\n$1:$2\n$3:$4\n$5:$6\n", 190 | "outArgs": [ 191 | "data.forecast[0].date", 192 | "data.forecast[0].type", 193 | "data.forecast[1].date", 194 | "data.forecast[1].type", 195 | "data.forecast[2].date", 196 | "data.forecast[2].type" 197 | ], 198 | "proxyIp": "", 199 | "proxyPort": 0, 200 | "sw": true, 201 | "touch": "未来天气", 202 | "url": "https://api.vvhan.com/api/weather?city=$1&type=week" 203 | }, 204 | { 205 | "err": "调用失败", 206 | "out": "", 207 | "outArgs": [ 208 | "pic[0]" 209 | ], 210 | "proxyIp": "", 211 | "proxyPort": 0, 212 | "sw": true, 213 | "touch": "随机图片", 214 | "url": "http://api.iw233.cn/api.php?sort=cat&type=json" 215 | }, 216 | { 217 | "err": "调用失败", 218 | "out": "", 219 | "outArgs": [ 220 | "$url" 221 | ], 222 | "proxyIp": "", 223 | "proxyPort": 0, 224 | "sw": true, 225 | "touch": "需要ta吗", 226 | "url": "https://ovooa.com/API/face_need/?QQ=$number" 227 | }, 228 | { 229 | "err": "调用失败", 230 | "out": "", 231 | "outArgs": [ 232 | "[]" 233 | ], 234 | "proxyIp": "", 235 | "proxyPort": 0, 236 | "sw": true, 237 | "touch": "快手图集", 238 | "url": "http://kloping.top/api/search/parseImgs?url=$1&type=ks" 239 | }, 240 | { 241 | "err": "调用失败", 242 | "out": "", 243 | "outArgs": [ 244 | "data.[]" 245 | ], 246 | "proxyIp": "", 247 | "proxyPort": 0, 248 | "sw": true, 249 | "touch": "堆糖搜图", 250 | "url": "http://kloping.top/api/search/pic?keyword=$1&num=3&type=duit" 251 | }, 252 | { 253 | "err": "调用失败", 254 | "out": "", 255 | "outArgs": [ 256 | "data[0].media_name", 257 | "data[0].author_name", 258 | "data[0].imgUrl", 259 | "data[0].songUrl" 260 | ], 261 | "proxyIp": "", 262 | "proxyPort": 0, 263 | "sw": true, 264 | "touch": "酷狗点歌", 265 | "url": "http://kloping.top/api/search/song?keyword=$1&type=kugou&n=2" 266 | }, 267 | { 268 | "err": null, 269 | "out": "\n$1", 270 | "outArgs": [ 271 | "$all" 272 | ], 273 | "proxyIp": "", 274 | "proxyPort": 0, 275 | "sw": true, 276 | "touch": "/ping", 277 | "url": "https://xian.txma.cn/API/sping.php?url=$1" 278 | }, 279 | { 280 | "err": null, 281 | "out": "id:$1\n来自群$2\n的$3\n时间:$call(http://kloping.top/stamp2time?stamp=$4&time=)\n昵称:$5\n信息:$6\n剩余捡起次数:$7", 282 | "outArgs": [ 283 | "id", 284 | "gid", 285 | "sid", 286 | "time", 287 | "name", 288 | "message", 289 | "state" 290 | ], 291 | "proxyIp": "", 292 | "proxyPort": 0, 293 | "sw": true, 294 | "touch": "/捡瓶子", 295 | "url": "http://kloping.top/api/pickUpBottle" 296 | } 297 | ] 298 | } 299 | ``` 300 | 301 |
302 | 303 | ### 更多 帮助请查看 [releases](https://github.com/gdpl2112/MiraiCallApiPlugin/releases) -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java") 3 | 4 | val kotlinVersion = "1.7.22" 5 | kotlin("jvm") version kotlinVersion 6 | kotlin("plugin.serialization") version kotlinVersion 7 | id("net.mamoe.mirai-console") version "2.16.0" 8 | } 9 | 10 | group = "io.github.gdpl2112" 11 | version = "3.5.1" 12 | 13 | repositories { 14 | maven("https://repo1.maven.org/maven2/") 15 | maven("https://s01.oss.sonatype.org/content/repositories/snapshots") 16 | mavenLocal() 17 | mavenCentral() 18 | } 19 | 20 | mirai { 21 | noTestCore = true 22 | setupConsoleTestRuntime { 23 | // 移除 mirai-core 依赖 24 | classpath = classpath.filter { 25 | !it.nameWithoutExtension.startsWith("mirai-core-jvm") 26 | } 27 | } 28 | } 29 | 30 | dependencies { 31 | testImplementation(kotlin("test")) 32 | 33 | // compileOnly("net.mamoe:mirai-core:2.15.0") 34 | testConsoleRuntime("top.mrxiaom.mirai:overflow-core:1.0.4") 35 | // compileOnly("net.mamoe:mirai-console-compiler-common:2.15.0") 36 | // implementation(platform("net.mamoe:mirai-bom:2.15.0")) 37 | // testImplementation("net.mamoe:mirai-core-mock:2.15.0") 38 | testImplementation("net.mamoe:mirai-logging-slf4j:2.15.0") 39 | 40 | implementation(platform("org.slf4j:slf4j-parent:2.0.6")) 41 | testImplementation("org.slf4j:slf4j-simple") 42 | 43 | // compileOnly("io.github.Kloping:SpringTool:0.5.8") 44 | // compileOnly("io.github.Kloping:spt-web:0.2.0") 45 | 46 | implementation("org.xerial:sqlite-jdbc:3.36.0.3") 47 | 48 | implementation("io.github.Kloping:SpringTool:0.5.8") 49 | implementation("io.github.Kloping:spt-web:0.2.0") 50 | } 51 | 52 | -------------------------------------------------------------------------------- /conf/callApi/conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "passwd":"123456", 3 | "permType":"all", 4 | "port":20042, 5 | "proxyIp":null, 6 | "proxyPort":0, 7 | "splitChar":" ", 8 | "templates":[ 9 | { 10 | "err":"天气查询失败", 11 | "out":"\n$1:$2\n$3:$4\n$5:$6\n", 12 | "outArgs":["data.forecast[0].date","data.forecast[0].type","data.forecast[1].date","data.forecast[1].type","data.forecast[2].date","data.forecast[2].type"], 13 | "proxyIp":"", 14 | "proxyPort":0, 15 | "sw":true, 16 | "touch":"未来天气", 17 | "url":"https://api.vvhan.com/api/weather?city=$1&type=week" 18 | }, 19 | { 20 | "err":"调用失败", 21 | "out":"", 22 | "outArgs":["pic[0]"], 23 | "proxyIp":"", 24 | "proxyPort":0, 25 | "sw":true, 26 | "touch":"随机图片", 27 | "url":"http://api.iw233.cn/api.php?sort=cat&type=json" 28 | }, 29 | { 30 | "err":"调用失败", 31 | "out":"", 32 | "outArgs":["$url"], 33 | "proxyIp":"", 34 | "proxyPort":0, 35 | "sw":true, 36 | "touch":"需要ta吗", 37 | "url":"https://ovooa.com/API/face_need/?QQ=$number" 38 | }, 39 | { 40 | "err":"调用失败", 41 | "out":"", 42 | "outArgs":["[]"], 43 | "proxyIp":"", 44 | "proxyPort":0, 45 | "sw":true, 46 | "touch":"快手图集", 47 | "url":"http://kloping.top/api/search/parseImgs?url=$1&type=ks" 48 | }, 49 | { 50 | "err":"调用失败", 51 | "out":"", 52 | "outArgs":["data.[]"], 53 | "proxyIp":"", 54 | "proxyPort":0, 55 | "sw":true, 56 | "touch":"堆糖搜图", 57 | "url":"http://kloping.top/api/search/pic?keyword=$1&num=3&type=duit" 58 | }, 59 | { 60 | "err":"调用失败", 61 | "out":"", 62 | "outArgs":["data[0].media_name","data[0].author_name","data[0].imgUrl","data[0].songUrl"], 63 | "proxyIp":"", 64 | "proxyPort":0, 65 | "sw":true, 66 | "touch":"酷狗点歌", 67 | "url":"http://kloping.top/api/search/song?keyword=$1&type=kugou&n=2" 68 | }, 69 | { 70 | "err":null, 71 | "out":"\n$1", 72 | "outArgs":["$all"], 73 | "proxyIp":"", 74 | "proxyPort":0, 75 | "sw":true, 76 | "touch":"/ping", 77 | "url":"https://xian.txma.cn/API/sping.php?url=$1" 78 | }, 79 | { 80 | "err":null, 81 | "out":"id:$1\n来自群$2\n的$3\n时间:$call(http://kloping.top/stamp2time?stamp=$4&time=)\n昵称:$5\n信息:$6\n剩余捡起次数:$7", 82 | "outArgs":["id","gid","sid","time","name","message","state"], 83 | "proxyIp":"", 84 | "proxyPort":0, 85 | "sw":true, 86 | "touch":"/捡瓶子", 87 | "url":"http://kloping.top/api/pickUpBottle" 88 | } 89 | ] 90 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.4.2-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 87 | 88 | # Use the maximum available, or set MAX_FD != -1 to use that value. 89 | MAX_FD=maximum 90 | 91 | warn () { 92 | echo "$*" 93 | } >&2 94 | 95 | die () { 96 | echo 97 | echo "$*" 98 | echo 99 | exit 1 100 | } >&2 101 | 102 | # OS specific support (must be 'true' or 'false'). 103 | cygwin=false 104 | msys=false 105 | darwin=false 106 | nonstop=false 107 | case "$( uname )" in #( 108 | CYGWIN* ) cygwin=true ;; #( 109 | Darwin* ) darwin=true ;; #( 110 | MSYS* | MINGW* ) msys=true ;; #( 111 | NONSTOP* ) nonstop=true ;; 112 | esac 113 | 114 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 115 | 116 | 117 | # Determine the Java command to use to start the JVM. 118 | if [ -n "$JAVA_HOME" ] ; then 119 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 120 | # IBM's JDK on AIX uses strange locations for the executables 121 | JAVACMD=$JAVA_HOME/jre/sh/java 122 | else 123 | JAVACMD=$JAVA_HOME/bin/java 124 | fi 125 | if [ ! -x "$JAVACMD" ] ; then 126 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 127 | 128 | Please set the JAVA_HOME variable in your environment to match the 129 | location of your Java installation." 130 | fi 131 | else 132 | JAVACMD=java 133 | if ! command -v java >/dev/null 2>&1 134 | then 135 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 136 | 137 | Please set the JAVA_HOME variable in your environment to match the 138 | location of your Java installation." 139 | fi 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 147 | # shellcheck disable=SC3045 148 | MAX_FD=$( ulimit -H -n ) || 149 | warn "Could not query maximum file descriptor limit" 150 | esac 151 | case $MAX_FD in #( 152 | '' | soft) :;; #( 153 | *) 154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 155 | # shellcheck disable=SC3045 156 | ulimit -n "$MAX_FD" || 157 | warn "Could not set maximum file descriptor limit to $MAX_FD" 158 | esac 159 | fi 160 | 161 | # Collect all arguments for the java command, stacking in reverse order: 162 | # * args from the command line 163 | # * the main class name 164 | # * -classpath 165 | # * -D...appname settings 166 | # * --module-path (only if needed) 167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 168 | 169 | # For Cygwin or MSYS, switch paths to Windows format before running java 170 | if "$cygwin" || "$msys" ; then 171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 173 | 174 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 175 | 176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 177 | for arg do 178 | if 179 | case $arg in #( 180 | -*) false ;; # don't mess with options #( 181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 182 | [ -e "$t" ] ;; #( 183 | *) false ;; 184 | esac 185 | then 186 | arg=$( cygpath --path --ignore --mixed "$arg" ) 187 | fi 188 | # Roll the args list around exactly as many times as the number of 189 | # args, so each arg winds up back in the position where it started, but 190 | # possibly modified. 191 | # 192 | # NB: a `for` loop captures its iteration list before it begins, so 193 | # changing the positional parameters here affects neither the number of 194 | # iterations, nor the values presented in `arg`. 195 | shift # remove old arg 196 | set -- "$@" "$arg" # push replacement arg 197 | done 198 | fi 199 | 200 | 201 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 202 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 203 | 204 | # Collect all arguments for the java command; 205 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 206 | # shell script including quotes and variable substitutions, so put them in 207 | # double quotes to make sure that they get re-expanded; and 208 | # * put everything else in single quotes, so that it's not re-expanded. 209 | 210 | set -- \ 211 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 212 | -classpath "$CLASSPATH" \ 213 | org.gradle.wrapper.GradleWrapperMain \ 214 | "$@" 215 | 216 | # Stop when "xargs" is not available. 217 | if ! command -v xargs >/dev/null 2>&1 218 | then 219 | die "xargs is not available" 220 | fi 221 | 222 | # Use "xargs" to parse quoted args. 223 | # 224 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 225 | # 226 | # In Bash we could simply go: 227 | # 228 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 229 | # set -- "${ARGS[@]}" "$@" 230 | # 231 | # but POSIX shell has neither arrays nor command substitution, so instead we 232 | # post-process each arg (as a line of input to sed) to backslash-escape any 233 | # character that might be a shell metacharacter, then use eval to reverse 234 | # that process (while maintaining the separation between arguments), and wrap 235 | # the whole thing up as a single "set" statement. 236 | # 237 | # This will of course break if any of these variables contains a newline or 238 | # an unmatched quote. 239 | # 240 | 241 | eval "set -- $( 242 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 243 | xargs -n1 | 244 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 245 | tr '\n' ' ' 246 | )" '"$@"' 247 | 248 | exec "$JAVACMD" "$@" 249 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "MiraiCallApiPlugin" -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/CallApiPlugin.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1; 2 | 3 | import io.github.gdpl2112.mirai.p1.services.ScriptService; 4 | import io.github.kloping.initialize.FileInitializeValue; 5 | import kotlin.coroutines.CoroutineContext; 6 | import net.mamoe.mirai.console.MiraiConsoleImplementation; 7 | import net.mamoe.mirai.console.command.CommandManager; 8 | import net.mamoe.mirai.console.extension.PluginComponentStorage; 9 | import net.mamoe.mirai.console.plugin.jvm.JavaPlugin; 10 | import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescriptionBuilder; 11 | import net.mamoe.mirai.event.EventHandler; 12 | import net.mamoe.mirai.event.GlobalEventChannel; 13 | import net.mamoe.mirai.event.SimpleListenerHost; 14 | import net.mamoe.mirai.event.events.*; 15 | import net.mamoe.mirai.message.data.*; 16 | import org.jetbrains.annotations.NotNull; 17 | 18 | import java.io.File; 19 | 20 | /** 21 | * @author github.kloping 22 | */ 23 | public class CallApiPlugin extends JavaPlugin { 24 | 25 | public static final CallApiPlugin INSTANCE = new CallApiPlugin(); 26 | 27 | public static Conf conf = null; 28 | 29 | public CallApiPlugin() { 30 | super(new JvmPluginDescriptionBuilder("io.github.Kloping.mirai.p1.CallApiPlugin", "3.5.1") 31 | .info("调用自定义API插件").build()); 32 | } 33 | 34 | @Override 35 | public void onDisable() { 36 | super.onDisable(); 37 | } 38 | 39 | @Override 40 | public void onEnable() { 41 | super.onEnable(); 42 | loadConf(); 43 | GlobalEventChannel.INSTANCE.registerListenerHost(new ScriptService()); 44 | GlobalEventChannel.INSTANCE.registerListenerHost(new SimpleListenerHost() { 45 | @Override 46 | public void handleException(@NotNull CoroutineContext context, @NotNull Throwable exception) { 47 | super.handleException(context, exception); 48 | } 49 | 50 | @EventHandler 51 | public void onMessage(GroupMessageEvent event) { 52 | onMessage0(event); 53 | } 54 | 55 | @EventHandler 56 | public void onMessage(GroupMessageSyncEvent event) { 57 | onMessage0(event); 58 | } 59 | 60 | @EventHandler 61 | public void onMessage(FriendMessageEvent event) { 62 | onMessage0(event); 63 | } 64 | 65 | @EventHandler 66 | public void onMessage(FriendMessageSyncEvent event) { 67 | onMessage0(event); 68 | } 69 | 70 | private void onMessage0(MessageEvent event) { 71 | if (!conf.getPermType().equals(Conf.ALL)) 72 | return; 73 | if (event.getMessage().size() > 1) { 74 | String text = toText(event.getMessage()); 75 | Message message = Worker.call(text, event.getSubject().getId(), event.getSender().getId(),event.getBot()); 76 | if (message != null) { 77 | event.getSubject().sendMessage(message); 78 | } 79 | } 80 | } 81 | }); 82 | CommandManager.INSTANCE.registerCommand(CommandLine0.INSTANCE, true); 83 | } 84 | 85 | private String toText(MessageChain m) { 86 | StringBuilder sb = new StringBuilder(); 87 | for (SingleMessage singleMessage : m) { 88 | if (singleMessage instanceof PlainText) { 89 | sb.append(((PlainText) singleMessage).getContent()); 90 | } else if (singleMessage instanceof At) { 91 | sb.append("[@").append(((At) singleMessage).getTarget()).append("]"); 92 | } 93 | } 94 | return sb.toString(); 95 | } 96 | 97 | @Override 98 | public void onLoad(PluginComponentStorage storage) { 99 | super.onLoad(storage); 100 | } 101 | 102 | public static File CONF_FILE; 103 | 104 | public static void loadConf() { 105 | conf = new Conf(); 106 | String path = MiraiConsoleImplementation.getInstance().getRootPath().toFile().getAbsolutePath(); 107 | CONF_FILE = new File(path, "conf/callApi/conf.json"); 108 | CONF_FILE.getParentFile().mkdirs(); 109 | 110 | conf = FileInitializeValue.getValue(CONF_FILE.getAbsolutePath(), conf, true); 111 | conf = FileInitializeValue.putValues(CONF_FILE.getAbsolutePath(), conf, true); 112 | 113 | Worker.init(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/CallTemplate.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1; 2 | 3 | /** 4 | * @author github.kloping 5 | */ 6 | public class CallTemplate { 7 | public Boolean sw = true; 8 | public String touch; 9 | public String url; 10 | public String out; 11 | public String[] outArgs; 12 | public String err; 13 | private String proxyIp; 14 | private Integer proxyPort; 15 | 16 | public String getProxyIp() { 17 | if (proxyIp == null) return ""; 18 | return proxyIp; 19 | } 20 | 21 | public void setProxyIp(String proxyIp) { 22 | this.proxyIp = proxyIp; 23 | } 24 | 25 | public Integer getProxyPort() { 26 | if (proxyPort == null) return 0; 27 | return proxyPort; 28 | } 29 | 30 | public void setProxyPort(Integer proxyPort) { 31 | this.proxyPort = proxyPort; 32 | } 33 | 34 | public String[] getOutArgs() { 35 | return outArgs; 36 | } 37 | 38 | public void setOutArgs(String[] outArgs) { 39 | this.outArgs = outArgs; 40 | } 41 | 42 | public String getTouch() { 43 | return touch; 44 | } 45 | 46 | public void setTouch(String touch) { 47 | this.touch = touch; 48 | } 49 | 50 | public String getUrl() { 51 | return url; 52 | } 53 | 54 | public void setUrl(String url) { 55 | this.url = url; 56 | } 57 | 58 | public String getOut() { 59 | return out; 60 | } 61 | 62 | public void setOut(String out) { 63 | this.out = out; 64 | } 65 | 66 | public String getErr() { 67 | return err; 68 | } 69 | 70 | public void setErr(String err) { 71 | this.err = err; 72 | } 73 | 74 | public Boolean getSw() { 75 | return sw; 76 | } 77 | 78 | public void setSw(Boolean sw) { 79 | this.sw = sw; 80 | } 81 | 82 | public void reverseSw() { 83 | if (sw == null) sw = true; 84 | this.sw = !sw; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/CommandLine0.kt: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1 2 | 3 | import io.github.kloping.initialize.FileInitializeValue 4 | import net.mamoe.mirai.console.ConsoleFrontEndImplementation 5 | import net.mamoe.mirai.console.command.CommandSender 6 | import net.mamoe.mirai.console.command.java.JCompositeCommand 7 | 8 | /** 9 | * @author github.kloping 10 | */ 11 | class CommandLine0 private constructor() : JCompositeCommand(CallApiPlugin.INSTANCE, "callApi") { 12 | companion object { 13 | @JvmField 14 | val INSTANCE = CommandLine0() 15 | } 16 | 17 | @OptIn(ConsoleFrontEndImplementation::class) 18 | @Description("重载配置") 19 | @SubCommand("reload") 20 | suspend fun CommandSender.callApiReload() { 21 | CallApiPlugin.loadConf() 22 | sendMessage("重载完成") 23 | } 24 | 25 | @Description("开关某一API") 26 | @SubCommand("switch") 27 | suspend fun CommandSender.switchApi(@Name("触发词") str: String) { 28 | for (template in CallApiPlugin.conf.templates) { 29 | if (template.touch.equals(str.trim())) { 30 | template.reverseSw() 31 | FileInitializeValue.putValues(CallApiPlugin.CONF_FILE.absolutePath, CallApiPlugin.conf, true) 32 | sendMessage("\"${template.touch}\"目前处于\"${template.sw}\"状态") 33 | return 34 | } 35 | } 36 | sendMessage("未发现该API") 37 | } 38 | 39 | @Description("某一API权限控制") 40 | @SubCommand("set") 41 | suspend fun CommandSender.callApiSetPer( 42 | @Name("触发词") str: String, 43 | @Name("id") id: String, 44 | @Name("布尔值") k: Boolean 45 | ) { 46 | ManagerConf.INSTANCE.setStateByTouchAndId(str, id, k); 47 | sendMessage("当前触发词: '${str}'在id: '${id}'状态为${k}") 48 | } 49 | 50 | @Description("某一API权限查询") 51 | @SubCommand("get") 52 | suspend fun CommandSender.callApiGetPer( 53 | @Name("触发词") str: String, 54 | @Name("id") id: String, 55 | ) { 56 | val k = ManagerConf.INSTANCE.getStateByTouchAndIdDefault(str, id, true) 57 | sendMessage("当前触发词: '${str}'在id: '${id}'状态为${k}") 58 | } 59 | 60 | @Description("某一API存在的所有id同时操作权限控制") 61 | @SubCommand("setAll") 62 | suspend fun CommandSender.callApiSetAllPer( 63 | @Name("触发词") str: String, 64 | @Name("布尔值") k: Boolean 65 | ) { 66 | ManagerConf.INSTANCE.setStateByTouch(str, k) 67 | sendMessage("当前触发词: '${str}'在id状态为${k}") 68 | } 69 | 70 | @Description("某一id存在的所有触发词同时操作权限控制") 71 | @SubCommand("swAll") 72 | suspend fun CommandSender.callApiSwAll( 73 | @Name("id") ids: String, 74 | @Name("布尔值") k: Boolean 75 | ) { 76 | for (template in CallApiPlugin.conf.templates) { 77 | ManagerConf.INSTANCE.setStateByTouchAndId(template.touch, ids, k) 78 | } 79 | sendMessage("当前触发词: '${ids}'的触发状态为${k}") 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/Conf.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * @author github.kloping 8 | */ 9 | public class Conf { 10 | public static final String ALL = "all"; 11 | public static final String CONSOLE = "console"; 12 | private String splitChar = " "; 13 | private String permType = ALL; 14 | private List templates = new ArrayList<>(); 15 | private String proxyIp; 16 | private Integer proxyPort; 17 | private Integer port = 20042; 18 | private String passwd = "123456"; 19 | private Boolean ignoreVerify = true; 20 | 21 | public Boolean getIgnoreVerify() { 22 | return ignoreVerify; 23 | } 24 | 25 | public void setIgnoreVerify(Boolean ignoreVerify) { 26 | this.ignoreVerify = ignoreVerify; 27 | } 28 | 29 | public String getPasswd() { 30 | return passwd; 31 | } 32 | 33 | public void setPasswd(String passwd) { 34 | this.passwd = passwd; 35 | } 36 | 37 | public Integer getPort() { 38 | return port; 39 | } 40 | 41 | public void setPort(Integer port) { 42 | this.port = port; 43 | } 44 | 45 | public String getProxyIp() { 46 | return proxyIp; 47 | } 48 | 49 | public void setProxyIp(String proxyIp) { 50 | this.proxyIp = proxyIp; 51 | } 52 | 53 | public Integer getProxyPort() { 54 | return proxyPort; 55 | } 56 | 57 | public void setProxyPort(Integer proxyPort) { 58 | this.proxyPort = proxyPort; 59 | } 60 | 61 | public String getSplitChar() { 62 | return splitChar; 63 | } 64 | 65 | public void setSplitChar(String splitChar) { 66 | this.splitChar = splitChar; 67 | } 68 | 69 | public String getPermType() { 70 | return permType; 71 | } 72 | 73 | public void setPermType(String permType) { 74 | this.permType = permType; 75 | } 76 | 77 | public List getTemplates() { 78 | return templates; 79 | } 80 | 81 | public void setTemplates(List templates) { 82 | this.templates = templates; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/Converter.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONArray; 5 | import com.alibaba.fastjson.JSONObject; 6 | import io.github.kloping.io.ReadUtils; 7 | import io.github.kloping.number.NumberUtils; 8 | import net.mamoe.mirai.Bot; 9 | import net.mamoe.mirai.contact.Friend; 10 | import net.mamoe.mirai.contact.Group; 11 | import net.mamoe.mirai.contact.Member; 12 | import org.jsoup.Connection; 13 | import org.jsoup.nodes.Document; 14 | 15 | import java.util.concurrent.atomic.AtomicReference; 16 | 17 | /** 18 | * @author github.kloping 19 | */ 20 | public class Converter { 21 | public static final String QID = "$qid"; 22 | public static final String QID0 = "\\$qid"; 23 | 24 | public static final String QNAME = "$qname"; 25 | public static final String QNAME0 = "\\$qname"; 26 | 27 | public static final String MNAME = "$mname"; 28 | public static final String MNAME0 = "\\$mname"; 29 | 30 | public static final String GNAME = "$gname"; 31 | public static final String GNAME0 = "\\$gname"; 32 | 33 | public static final String GID = "$gid"; 34 | public static final String GID0 = "\\$gid"; 35 | 36 | public static final String CHAR0 = "\\$%s"; 37 | 38 | public static final String ALL = "$all"; 39 | 40 | public static final String PAR_URL = "$url"; 41 | 42 | public static final String PAR_NUMBER = "$number"; 43 | public static final String PAR_NUMBER0 = "\\$number"; 44 | 45 | public static String filterId(String url, Bot bot, long gid, long qid, String... args) { 46 | if (url == null) return url; 47 | if (url.contains(QID)) { 48 | url = url.replaceAll(QID0, String.valueOf(qid)); 49 | } 50 | if (url.contains(GID)) { 51 | url = url.replaceAll(GID0, String.valueOf(gid)); 52 | } 53 | if (url.contains(PAR_NUMBER)) { 54 | StringBuilder nums = new StringBuilder(); 55 | for (String arg : args) { 56 | nums.append(NumberUtils.findNumberFromString(arg)); 57 | } 58 | url = url.replaceAll(PAR_NUMBER0, String.valueOf(nums.toString())); 59 | } 60 | if (url.contains(QNAME)) { 61 | Friend friend = bot.getFriend(qid); 62 | if (friend != null) { 63 | url = url.replaceAll(QNAME0, friend.getNick()); 64 | } else { 65 | Member member = bot.getGroup(gid).getMembers().get(qid); 66 | if (member != null) 67 | url = url.replaceAll(QNAME0, member.getNick()); 68 | } 69 | } 70 | if (url.contains(MNAME)) { 71 | Member member = bot.getGroup(gid).getMembers().get(qid); 72 | if (member != null) 73 | url = url.replaceAll(MNAME0, member.getNameCard()); 74 | } 75 | if (url.contains(GNAME)) { 76 | Group group = bot.getGroup(gid); 77 | if (group != null) 78 | url = url.replaceAll(GNAME0, group.getName()); 79 | } 80 | return url; 81 | } 82 | 83 | public static Object get(Connection t1, String t0, AtomicReference doc0) throws Exception { 84 | if (t0.equals(ALL)) { 85 | return ReadUtils.readAll(t1.execute().bodyStream(), "utf-8"); 86 | } 87 | if (doc0.get() == null) { 88 | doc0.set(t1.get()); 89 | } 90 | if (t0.equals(PAR_URL)) { 91 | return doc0.get().location(); 92 | } 93 | return get0(doc0.get().body().text(), t0); 94 | } 95 | 96 | /** 97 | * get from json 98 | * 99 | * @param t1 json 100 | * @param t0 表达式 101 | * @return 102 | * @throws Exception 103 | */ 104 | public static Object get0(String t1, String t0) throws Exception { 105 | JSON j0 = (JSON) JSON.parse(t1); 106 | t0 = t0.trim(); 107 | String s0 = null; 108 | for (String s : t0.trim().split("\\.")) { 109 | if (!s.isEmpty()) { 110 | s0 = s; 111 | break; 112 | } 113 | } 114 | Object o = null; 115 | if (s0.matches("\\[\\d*]")) { 116 | JSONArray arr = (JSONArray) j0; 117 | String sts = s0.substring(1, s0.length() - 1); 118 | if (sts.isEmpty()) { 119 | o = arr; 120 | t0 = t0.replaceFirst("\\[]", ""); 121 | } else { 122 | Integer st = Integer.parseInt(sts); 123 | o = arr.get(st); 124 | int len = 4; 125 | if (t0.length() >= len) t0 = t0.substring(len); 126 | else t0 = t0.substring(len - 1); 127 | } 128 | } else if (s0.matches(".*?\\[\\d+]")) { 129 | int i = s0.indexOf("["); 130 | int i1 = s0.indexOf("]"); 131 | String st0 = s0.substring(0, i); 132 | Integer st = Integer.parseInt(s0.substring(i + 1, s0.length() - 1)); 133 | JSONObject jo = (JSONObject) j0; 134 | o = jo.getJSONArray(st0).get(st); 135 | if (t0.length() > s0.length()) t0 = t0.substring(s0.length()); 136 | else t0 = null; 137 | } else { 138 | JSONObject jo = (JSONObject) j0; 139 | o = jo.get(s0); 140 | int len = s0.length() + 1; 141 | if (t0.length() >= len) t0 = t0.substring(len); 142 | else t0 = t0.substring(len - 1); 143 | } 144 | if (t0 != null && t0.length() > 0) { 145 | return get0(JSON.toJSONString(o), t0); 146 | } else { 147 | return o; 148 | } 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/ManagerConf.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1; 2 | 3 | import java.sql.*; 4 | 5 | /** 6 | * @author github.kloping 7 | */ 8 | public class ManagerConf { 9 | private static Connection getConnection() throws SQLException { 10 | Connection connection = DriverManager.getConnection("jdbc:sqlite:./conf/callApi/switch.db"); 11 | return connection; 12 | } 13 | 14 | public static ManagerConf INSTANCE = new ManagerConf(); 15 | 16 | public ManagerConf() { 17 | try { 18 | Class.forName("org.sqlite.JDBC"); 19 | Connection connection = getConnection(); 20 | Statement statement = connection.createStatement(); 21 | statement.executeUpdate("CREATE TABLE IF NOT EXISTS sw(touch VARCHAR(50),id VARCHAR(20),k BLOB);"); 22 | statement.close(); 23 | connection.close(); 24 | } catch (Exception e) { 25 | e.printStackTrace(); 26 | } 27 | 28 | } 29 | 30 | public Boolean getStateByTouchAndIdDefault(String touch, String id, Boolean k) { 31 | Boolean a = query(String.format("SELECT k FROM sw WHERE touch='%s' AND id='%s'", touch, id)); 32 | if (a == null) { 33 | update(String.format("INSERT INTO sw VALUES ('%s', '%s', %s);", touch, id, k)); 34 | return k; 35 | } 36 | return a; 37 | } 38 | 39 | public void setStateByTouchAndId(String touch, String id, boolean k) { 40 | getStateByTouchAndIdDefault(touch, id, k); 41 | update(String.format("UPDATE sw SET k=%s WHERE touch='%s' AND id='%s';", k, touch, id)); 42 | } 43 | 44 | public void setStateByTouch(String touch, boolean k) { 45 | update(String.format("UPDATE sw SET k=%s WHERE touch='%s';", k, touch)); 46 | } 47 | 48 | public Integer update(String sql) { 49 | try { 50 | Connection connection = getConnection(); 51 | Statement statement = connection.createStatement(); 52 | int i = statement.executeUpdate(sql); 53 | statement.close(); 54 | connection.close(); 55 | return i; 56 | } catch (SQLException e) { 57 | e.printStackTrace(); 58 | return -1; 59 | } 60 | } 61 | 62 | public Boolean query(String sql) { 63 | try { 64 | Connection connection = getConnection(); 65 | Statement statement = connection.createStatement(); 66 | ResultSet rs = statement.executeQuery(sql); 67 | Boolean k = null; 68 | if (rs.next()) { 69 | k = rs.getBoolean("k"); 70 | } 71 | statement.close(); 72 | connection.close(); 73 | return k; 74 | } catch (SQLException e) { 75 | e.printStackTrace(); 76 | return null; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/Parse.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import io.github.kloping.io.ReadUtils; 5 | import io.github.kloping.url.UrlUtils; 6 | import net.mamoe.mirai.contact.Contact; 7 | import net.mamoe.mirai.contact.Friend; 8 | import net.mamoe.mirai.contact.Group; 9 | import net.mamoe.mirai.message.data.*; 10 | import net.mamoe.mirai.utils.ExternalResource; 11 | 12 | import java.io.ByteArrayInputStream; 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.net.URL; 16 | import java.util.*; 17 | import java.util.regex.Matcher; 18 | import java.util.regex.Pattern; 19 | 20 | 21 | /** 22 | * @author github.kloping 23 | */ 24 | public class Parse { 25 | private static final Pattern PATTER_FACE = Pattern.compile(""); 26 | private static final Pattern PATTER_PIC = Pattern.compile("^]+?>|^]+?>"); 27 | private static final Pattern PATTER_URL = Pattern.compile("^]+>|^]+?>"); 28 | private static final Pattern PATTER_AT = Pattern.compile("|"); 29 | private static final Pattern PATTER_MUSIC = Pattern.compile("|"); 30 | private static final Pattern PATTER_VOICE = Pattern.compile(""); 31 | public static final Pattern[] PATTERNS = {PATTER_FACE, PATTER_PIC, PATTER_URL, PATTER_AT, PATTER_VOICE, PATTER_MUSIC}; 32 | 33 | private static final String BASE64 = "base64,"; 34 | 35 | private static final Map FACES = new HashMap<>(); 36 | private static final Map ATS = new HashMap<>(); 37 | 38 | public static List aStart(String line) { 39 | List list = new ArrayList<>(); 40 | List olist = new ArrayList<>(); 41 | a1b2c3(list, line); 42 | for (String s : list) { 43 | int i = line.indexOf(s); 44 | if (i > 0) { 45 | olist.add(line.substring(0, i)); 46 | } 47 | olist.add(s); 48 | line = line.substring(i + s.length()); 49 | } 50 | if (!line.isEmpty()) 51 | olist.add(line); 52 | return olist; 53 | } 54 | 55 | public static void a1b2c3(List list, String line) { 56 | if (list == null || line == null || line.isEmpty()) return; 57 | Map nm = getNearestOne(line, PATTER_FACE, PATTER_PIC, PATTER_URL, PATTER_AT, PATTER_VOICE, PATTER_MUSIC); 58 | if (nm.isEmpty()) { 59 | list.add(line); 60 | return; 61 | } 62 | int n = nm.keySet().iterator().next(); 63 | String v = nm.get(n); 64 | String[] ss = new String[2]; 65 | ss[0] = line.substring(0, line.indexOf(v)); 66 | ss[1] = line.substring(line.indexOf(v) + v.length(), line.length()); 67 | if (!ss[0].isEmpty()) { 68 | list.add(ss[0]); 69 | line = line.substring(ss[0].length()); 70 | } 71 | line = ss[1]; 72 | list.add(v); 73 | a1b2c3(list, line); 74 | return; 75 | } 76 | 77 | public static Map getNearestOne(final String line, Pattern... patterns) { 78 | try { 79 | Map map = new LinkedHashMap<>(); 80 | for (Pattern pattern : patterns) { 81 | Matcher matcher = pattern.matcher(line); 82 | if (matcher.find()) { 83 | String l1 = matcher.group(); 84 | int i1 = line.indexOf(l1); 85 | map.put(i1, l1); 86 | } 87 | } 88 | Map result1 = new LinkedHashMap<>(); 89 | map.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEachOrdered(x -> result1.put(x.getKey(), x.getValue())); 90 | return result1; 91 | } catch (Exception e) { 92 | e.printStackTrace(); 93 | return null; 94 | } 95 | } 96 | 97 | public static MessageChain getMessageFromString(String str, Contact contact) { 98 | if (str == null || str.isEmpty() || contact == null) return null; 99 | MessageChainBuilder builder = new MessageChainBuilder(); 100 | append(str, builder, contact); 101 | MessageChain message = builder.build(); 102 | return message; 103 | } 104 | 105 | private static List append(String sb, MessageChainBuilder builder, Contact contact) { 106 | List lls = aStart(sb); 107 | for (Object o : lls) { 108 | String str = o.toString(); 109 | boolean k = (str.startsWith("<") || str.startsWith("[")) && !str.matches("\\[.+]请使用最新版手机QQ体验新功能"); 110 | if (k) { 111 | String ss = str.replace("<", "").replace(">", ""); 112 | int i1 = ss.indexOf(":"); 113 | String s1 = ss.substring(0, i1); 114 | String s2 = ss.substring(i1 + 1); 115 | switch (s1) { 116 | case "Pic": 117 | case "pic": 118 | builder.append(createImage(contact, s2)); 119 | break; 120 | case "Face": 121 | case "face": 122 | builder.append(getFace(Integer.parseInt(s2))); 123 | break; 124 | case "At": 125 | case "at": 126 | builder.append(getAt(Long.parseLong(s2))); 127 | break; 128 | case "Voice": 129 | case "Audio": 130 | builder.append(createVoiceMessageInGroup(s2, contact.getId(), contact)); 131 | break; 132 | case "Music": 133 | case "music": 134 | builder.append(createMusic(contact, s2)); 135 | break; 136 | default: 137 | break; 138 | } 139 | } else { 140 | builder.append(str); 141 | } 142 | } 143 | return lls; 144 | } 145 | 146 | private static Message createMusic(Contact contact, String s2) { 147 | String[] ss = s2.split(","); 148 | MusicKind kind = MusicKind.valueOf(ss[0]); 149 | MusicShare share = new MusicShare(kind 150 | , ss[1] 151 | , ss[2] 152 | , ss[3] 153 | , ss[4] 154 | , ss[5] 155 | ); 156 | return share; 157 | } 158 | 159 | private static Face getFace(int parseInt) { 160 | if (FACES.containsKey(parseInt)) { 161 | return FACES.get(parseInt); 162 | } else { 163 | Face face = new Face(parseInt); 164 | FACES.put(parseInt, face); 165 | return face; 166 | } 167 | } 168 | 169 | public static At getAt(long id) { 170 | if (ATS.containsKey(id)) { 171 | return ATS.get(id); 172 | } else { 173 | At at = new At(id); 174 | ATS.put(id, at); 175 | return at; 176 | } 177 | } 178 | 179 | public static Message createImage(Contact group, String path) { 180 | Message image = null; 181 | try { 182 | if (path.startsWith("http")) { 183 | image = Contact.uploadImage(group, new ByteArrayInputStream(ReadUtils.readAll(new URL(path).openStream()))); 184 | } else if (path.startsWith("{")) { 185 | image = Image.fromId(path); 186 | } else if (path.contains(BASE64)) { 187 | image = Contact.uploadImage(group, new ByteArrayInputStream(getBase64Data(path))); 188 | } else if (path.startsWith("[") && path.endsWith("]")) { 189 | image = createForwardMessageByPic(group, (String[]) JSON.parseArray(path).toArray(new String[0])); 190 | } else { 191 | image = Contact.uploadImage(group, new File(path)); 192 | } 193 | } catch (Exception e) { 194 | System.err.println(path + "加载失败"); 195 | e.printStackTrace(); 196 | } 197 | return image; 198 | } 199 | 200 | public static byte[] getBase64Data(String base64) { 201 | int i = base64.indexOf(BASE64); 202 | String base64Str = base64.substring(i + BASE64.length()); 203 | byte[] bytes = Base64.getDecoder().decode(base64Str); 204 | return bytes; 205 | } 206 | 207 | public static Message createVoiceMessageInGroup(String url, long id, Contact contact) { 208 | ExternalResource resource = null; 209 | try { 210 | byte[] bytes = UrlUtils.getBytesFromHttpUrl(url); 211 | resource = ExternalResource.create(bytes); 212 | if (contact instanceof Group) { 213 | return ((Group) contact).uploadAudio(resource); 214 | } else if (contact instanceof Friend) { 215 | return ((Friend) contact).uploadAudio(resource); 216 | } 217 | } catch (Exception e) { 218 | e.printStackTrace(); 219 | return null; 220 | } finally { 221 | if (resource != null) { 222 | try { 223 | resource.close(); 224 | } catch (IOException e) { 225 | e.printStackTrace(); 226 | } 227 | } 228 | } 229 | return null; 230 | } 231 | 232 | public static Message createForwardMessageByPic(Contact contact, String[] picUrl) { 233 | ForwardMessageBuilder builder = new ForwardMessageBuilder(contact); 234 | for (String s : picUrl) { 235 | builder.add(contact.getId(), contact.getBot().getNick(), createImage(contact, s)); 236 | } 237 | return builder.build(); 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/Worker.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import io.github.kloping.MySpringTool.StarterApplication; 5 | import io.github.kloping.MySpringTool.StarterObjectApplication; 6 | import io.github.kloping.MySpringTool.annotations.CommentScan; 7 | import io.github.kloping.little_web.conf.TomcatConfig; 8 | import io.github.kloping.reg.MatcherUtils; 9 | import net.mamoe.mirai.Bot; 10 | import net.mamoe.mirai.message.data.Message; 11 | import net.mamoe.mirai.message.data.PlainText; 12 | import org.jsoup.Connection; 13 | import org.jsoup.nodes.Document; 14 | 15 | import javax.net.ssl.*; 16 | import java.io.IOException; 17 | import java.net.URL; 18 | import java.security.KeyManagementException; 19 | import java.security.NoSuchAlgorithmException; 20 | import java.security.NoSuchProviderException; 21 | import java.security.cert.CertificateException; 22 | import java.security.cert.X509Certificate; 23 | import java.util.concurrent.atomic.AtomicReference; 24 | 25 | import static io.github.gdpl2112.mirai.p1.CallApiPlugin.conf; 26 | import static io.github.gdpl2112.mirai.p1.Converter.*; 27 | import static io.github.gdpl2112.mirai.p1.Parse.getMessageFromString; 28 | 29 | /** 30 | * @author github.kloping 31 | */ 32 | @CommentScan(path = "io.github.gdpl2112.mirai.p1.rest") 33 | public class Worker { 34 | public static boolean inited = false; 35 | 36 | static void init() { 37 | if (inited) return; 38 | inited = true; 39 | if (conf.getIgnoreVerify()){ 40 | try { 41 | SSLContext sslcontext = SSLContext.getInstance("SSL", "SunJSSE"); 42 | sslcontext.init(null, new TrustManager[]{new X509TrustManager() { 43 | @Override 44 | public void checkClientTrusted(X509Certificate[] certificates, String authType) throws CertificateException { 45 | } 46 | 47 | @Override 48 | public void checkServerTrusted(X509Certificate[] ax509certificate, String s) throws CertificateException { 49 | } 50 | 51 | @Override 52 | public X509Certificate[] getAcceptedIssuers() { 53 | return null; 54 | } 55 | }}, new java.security.SecureRandom()); 56 | 57 | HostnameVerifier ignoreHostnameVerifier = new HostnameVerifier() { 58 | @Override 59 | public boolean verify(String s, SSLSession sslsession) { 60 | System.out.println("WARNING: Hostname is not matched for cert."); 61 | return true; 62 | } 63 | }; 64 | 65 | HttpsURLConnection.setDefaultHostnameVerifier(ignoreHostnameVerifier); 66 | HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext.getSocketFactory()); 67 | } catch (NoSuchAlgorithmException e) { 68 | e.printStackTrace(); 69 | } catch (NoSuchProviderException e) { 70 | e.printStackTrace(); 71 | } catch (KeyManagementException e) { 72 | e.printStackTrace(); 73 | } 74 | } 75 | startWeb(); 76 | } 77 | 78 | private static void startWeb() { 79 | TomcatConfig config = new TomcatConfig(); 80 | config.setName("callApi-web"); 81 | config.setPort(conf.getPort()); 82 | StarterObjectApplication application = new StarterObjectApplication(); 83 | application.SCAN_LOADER = Worker.class.getClassLoader(); 84 | application.PRE_SCAN_RUNNABLE.add(() -> { 85 | application.INSTANCE.getContextManager().append(config); 86 | application.INSTANCE.getContextManager().append("callApi-servlet0", "servletName"); 87 | }); 88 | StarterApplication.logger = application.logger; 89 | application.run0(Worker.class); 90 | application.logger.info("服务启动成功 请访问 http://localhost:" + conf.getPort() + "/?key=" + conf.getPasswd()); 91 | } 92 | 93 | public static Message call(String text, long gid, long qid, Bot bot) { 94 | try { 95 | Conf conf = CallApiPlugin.conf; 96 | String[] ss = text.split(conf.getSplitChar()); 97 | String first = ss[0]; 98 | for (CallTemplate template : conf.getTemplates()) { 99 | if (template.touch.equals(first)) { 100 | if (!template.sw) continue; 101 | if (!enable(template, gid, qid)) continue; 102 | String[] ss0 = new String[ss.length - 1]; 103 | System.arraycopy(ss, 1, ss0, 0, ss0.length); 104 | Connection connection = doc(bot, gid, qid, template, ss0); 105 | if (connection == null) return null; 106 | return parse(connection, template, bot, gid, qid); 107 | } 108 | } 109 | } catch (Exception e) { 110 | e.printStackTrace(); 111 | } 112 | return null; 113 | } 114 | 115 | private static boolean enable(CallTemplate template, long gid, long qid) { 116 | if (gid == qid) { 117 | return ManagerConf.INSTANCE.getStateByTouchAndIdDefault(template.touch, "f" + qid, true); 118 | } else { 119 | return ManagerConf.INSTANCE.getStateByTouchAndIdDefault(template.touch, "g" + gid, true); 120 | } 121 | } 122 | 123 | private static Message parse(Connection connection, CallTemplate template, Bot bot, long gid, long qid) { 124 | Message message = null; 125 | String end = template.out; 126 | try { 127 | int i = 1; 128 | AtomicReference doc0 = new AtomicReference<>(); 129 | for (String outArg : template.outArgs) { 130 | Object o0 = get(connection, outArg, doc0); 131 | if (o0 != null) { 132 | String o1 = o0.toString(); 133 | try { 134 | JSON json = (JSON) JSON.parse(o1); 135 | } catch (Exception e) { 136 | System.err.println("json parse error."); 137 | } 138 | end = end.replaceFirst(String.format(CHAR0, i++), o1); 139 | } 140 | } 141 | end = filterId(end, bot, gid, qid); 142 | end = filterCall(end, template); 143 | } catch (Exception e) { 144 | if (e instanceof NullPointerException) { 145 | e.printStackTrace(); 146 | }else e.printStackTrace(); 147 | if (template.err != null && !template.err.isEmpty()) { 148 | end = template.err; 149 | } else { 150 | end = "调用失败"; 151 | } 152 | } 153 | try { 154 | message = getMessageFromString(end, bot.getAsFriend()); 155 | } catch (Exception e) { 156 | e.printStackTrace(); 157 | if (template.err != null && !template.err.isEmpty()) { 158 | end = template.err; 159 | } else { 160 | end = "调用失败"; 161 | } 162 | message = new PlainText(end); 163 | } 164 | return message; 165 | } 166 | 167 | public static Connection doc(Bot bot, long gid, long qid, CallTemplate template, String... args) throws Exception { 168 | int i = 1; 169 | String url = template.url; 170 | for (String arg : args) { 171 | url = url.replaceFirst(String.format(CHAR0, i++), arg); 172 | } 173 | url = filterId(url, bot, gid, qid, args); 174 | url = filterCall(url, template); 175 | try { 176 | return getConnection(url, template); 177 | } catch (IOException e) { 178 | e.printStackTrace(); 179 | } 180 | return null; 181 | } 182 | 183 | private static String filterCall(String url, CallTemplate template) throws Exception { 184 | for (String s : MatcherUtils.matcherAll(url, "\\$call.?(.+)")) { 185 | String ex = s.substring(s.indexOf("call") + 4, s.indexOf("(")); 186 | String u0 = s.substring(s.indexOf("(") + 1, s.lastIndexOf(")")); 187 | String body = getConnection(u0, template).get().body().text(); 188 | if (ex.isEmpty()) url = url.replace(s, body); 189 | else url = url.replace(s, get0(body, ex).toString()); 190 | } 191 | return url; 192 | } 193 | 194 | public static Connection getConnection(String url, CallTemplate template) throws Exception { 195 | Connection connection = org.jsoup.Jsoup.connect(url).ignoreContentType(true).ignoreHttpErrors(true).header("Host", new URL(url).getHost()).userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.50"); 196 | connection.timeout(60000); 197 | if (template.getProxyIp() != null && template.getProxyPort() != null && !template.getProxyIp().isEmpty()) { 198 | connection.proxy(template.getProxyIp(), template.getProxyPort()); 199 | } else if (conf.getProxyIp() != null && conf.getProxyPort() != null && !conf.getProxyIp().isEmpty()) { 200 | connection.proxy(conf.getProxyIp(), conf.getProxyPort()); 201 | } 202 | return connection; 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/rest/RestController0.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1.rest; 2 | 3 | import io.github.gdpl2112.mirai.p1.CallApiPlugin; 4 | import io.github.gdpl2112.mirai.p1.CallTemplate; 5 | import io.github.kloping.initialize.FileInitializeValue; 6 | import io.github.kloping.little_web.annotations.RequestMethod; 7 | import io.github.kloping.little_web.annotations.RequestParm; 8 | import io.github.kloping.little_web.annotations.WebRestController; 9 | 10 | import javax.servlet.http.Cookie; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import java.io.IOException; 14 | import java.util.Iterator; 15 | 16 | /** 17 | * @author github.kloping 18 | */ 19 | @WebRestController 20 | public class RestController0 { 21 | public RestController0() { 22 | System.out.println(getClass().getSimpleName() + "=>created"); 23 | } 24 | 25 | private boolean verify(HttpServletRequest request) { 26 | if (request.getCookies() == null) { 27 | return false; 28 | } 29 | for (Cookie cookie : request.getCookies()) { 30 | if ("key".equals(cookie.getName())) { 31 | if (cookie.getValue().equals(CallApiPlugin.conf.getPasswd())) { 32 | return true; 33 | } 34 | } 35 | } 36 | return false; 37 | } 38 | 39 | @RequestMethod("/") 40 | public void index(@RequestParm("key") String key, HttpServletResponse response) throws IOException { 41 | if (key != null && key.equals(CallApiPlugin.conf.getPasswd())) { 42 | Cookie cookie = new Cookie("key", key); 43 | response.addCookie(cookie); 44 | response.sendRedirect("/index.html"); 45 | } else { 46 | response.sendRedirect("https://www.baidu.com"); 47 | } 48 | } 49 | 50 | @RequestMethod("/get_data") 51 | public Object getAll(HttpServletRequest request) { 52 | if (!verify(request)) return null; 53 | return CallApiPlugin.conf.getTemplates(); 54 | } 55 | 56 | @RequestMethod("/delete") 57 | public Object delete(@RequestParm("touch") String touch, HttpServletRequest request) { 58 | if (!verify(request)) return null; 59 | Iterator iterator = CallApiPlugin.conf.getTemplates().iterator(); 60 | while (iterator.hasNext()) { 61 | if (iterator.next().touch.equals(touch)) { 62 | iterator.remove(); 63 | CallApiPlugin.conf = FileInitializeValue.putValues(CallApiPlugin.CONF_FILE.getAbsolutePath(), CallApiPlugin.conf, true); 64 | return getAll(request); 65 | } 66 | } 67 | return getAll(request); 68 | } 69 | 70 | @RequestMethod("/append") 71 | public Object append( 72 | @RequestParm("touch") String touch, 73 | @RequestParm("out") String out, 74 | @RequestParm("outArgs") String outArgs, 75 | @RequestParm("url") String url, 76 | @RequestParm("proxy") String proxy, HttpServletRequest request) { 77 | if (!verify(request)) return null; 78 | boolean modify = false; 79 | CallTemplate template = null; 80 | for (CallTemplate confTemplate : CallApiPlugin.conf.getTemplates()) { 81 | if (confTemplate.getTouch().equals(touch)) { 82 | template = confTemplate; 83 | modify = true; 84 | break; 85 | } 86 | } 87 | if (template == null) { 88 | template = new CallTemplate(); 89 | template.setTouch(touch); 90 | } 91 | template.setOut(out); 92 | template.setOutArgs(outArgs.split(",|;")); 93 | template.setUrl(url); 94 | if (proxy != null && !proxy.isEmpty()) { 95 | template.setProxyIp(proxy.split(":")[0]); 96 | template.setProxyPort(Integer.valueOf(proxy.split(":")[1])); 97 | } 98 | if (!modify) CallApiPlugin.conf.getTemplates().add(template); 99 | CallApiPlugin.conf = FileInitializeValue.putValues(CallApiPlugin.CONF_FILE.getAbsolutePath(), CallApiPlugin.conf, true); 100 | return getAll(request); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/services/DgSerializer.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1.services; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import io.github.kloping.arr.ArrSerializer; 5 | import io.github.kloping.io.ReadUtils; 6 | import io.github.kloping.url.UrlUtils; 7 | import net.mamoe.mirai.Bot; 8 | import net.mamoe.mirai.contact.Contact; 9 | import net.mamoe.mirai.contact.Friend; 10 | import net.mamoe.mirai.contact.Group; 11 | import net.mamoe.mirai.message.data.*; 12 | import net.mamoe.mirai.utils.ExternalResource; 13 | 14 | import java.io.ByteArrayInputStream; 15 | import java.io.File; 16 | import java.io.IOException; 17 | import java.net.URL; 18 | import java.util.*; 19 | import java.util.regex.Matcher; 20 | import java.util.regex.Pattern; 21 | 22 | 23 | /** 24 | * @author github.kloping 25 | */ 26 | public class DgSerializer { 27 | private static final Pattern PATTER_FACE = Pattern.compile(""); 28 | private static final Pattern PATTER_PIC = Pattern.compile("^]+?>"); 29 | private static final Pattern PATTER_URL = Pattern.compile("^]+>"); 30 | private static final Pattern PATTER_AT = Pattern.compile(""); 31 | private static final Pattern PATTER_MUSIC = Pattern.compile(""); 32 | private static final Pattern PATTER_VOICE = Pattern.compile(""); 33 | private static final Pattern PATTER_MIRAI_FACE = Pattern.compile("\\[mirai:face:.*?]"); 34 | private static final Pattern PATTER_MIRAI_IMAGE = Pattern.compile("\\[mirai:image:.*?]"); 35 | 36 | public static final Pattern[] PATTERNS = {PATTER_FACE, PATTER_PIC, PATTER_URL, PATTER_AT, PATTER_VOICE, PATTER_MUSIC, PATTER_MIRAI_FACE, PATTER_MIRAI_IMAGE}; 37 | 38 | private static final String BASE64 = "base64,"; 39 | 40 | public static final Map MARKET_FACE_MAP = new HashMap<>(); 41 | 42 | public static MessageChain stringDeserializeToMessageChain(String str, Bot bot, Contact contact) { 43 | if (str == null || str.isEmpty() || bot == null) return null; 44 | MessageChainBuilder builder = new MessageChainBuilder(); 45 | goToFormat(str, builder, bot, contact); 46 | MessageChain message = builder.build(); 47 | return message; 48 | } 49 | 50 | private static List goToFormat(String sb, MessageChainBuilder builder, Bot bot, Contact contact) { 51 | List allElements = getAllElements(sb); 52 | for (Object o : allElements) { 53 | String str = o.toString(); 54 | boolean k = (str.startsWith("<") || str.startsWith("[")) && !str.matches("\\[.+]请使用最新版手机QQ体验新功能"); 55 | if (k) { 56 | Message msg = null; 57 | String ss = str.replaceAll("[<>\\[\\]]", ""); 58 | int i1 = ss.indexOf(":"); 59 | String s1 = ss.substring(0, i1); 60 | String s2 = ss.substring(i1 + 1); 61 | switch (s1.toLowerCase()) { 62 | case "pic": 63 | msg = createImage(contact, bot, s2); 64 | break; 65 | case "face": 66 | msg = new Face(Integer.parseInt(s2)); 67 | break; 68 | case "at": 69 | long tid = -1L; 70 | if (s2.contains("?")) tid = contact.getId(); 71 | else tid = Long.parseLong(s2); 72 | msg = new At(tid); 73 | break; 74 | case "voice": 75 | case "audio": 76 | msg = createVoiceMessageInGroup(s2, bot.getId(), contact); 77 | break; 78 | case "music": 79 | msg = createMusic(bot, s2); 80 | break; 81 | case "marketface": 82 | msg = MARKET_FACE_MAP.get(Integer.parseInt(s2)); 83 | break; 84 | case "mirai": 85 | String type = s2.substring(0, s2.indexOf(":")); 86 | String c0 = s2.substring(s2.indexOf(":") + 1, s2.length()); 87 | if (type.equals("face")) 88 | msg = new Face(Integer.parseInt(c0)); 89 | else if (type.equals("image")) 90 | msg = createImage(contact, bot, c0); 91 | break; 92 | default: 93 | msg = new PlainText(s2); 94 | break; 95 | } 96 | if (msg != null) builder.append(msg); 97 | } else { 98 | builder.append(str); 99 | } 100 | } 101 | return allElements; 102 | } 103 | 104 | public static List getAllElements(String line) { 105 | List list = new ArrayList<>(); 106 | List olist = new ArrayList<>(); 107 | algorithmFill(list, line); 108 | for (String s : list) { 109 | int i = line.indexOf(s); 110 | if (i > 0) { 111 | olist.add(line.substring(0, i)); 112 | } 113 | olist.add(s); 114 | line = line.substring(i + s.length()); 115 | } 116 | if (!line.isEmpty()) olist.add(line); 117 | return olist; 118 | } 119 | 120 | public static void algorithmFill(List list, String line) { 121 | if (list == null || line == null || line.isEmpty()) return; 122 | Map nm = getNearestOne(line, PATTERNS); 123 | if (nm.isEmpty()) { 124 | list.add(line); 125 | return; 126 | } 127 | int n = nm.keySet().iterator().next(); 128 | String v = nm.get(n); 129 | String[] ss = new String[2]; 130 | ss[0] = line.substring(0, line.indexOf(v)); 131 | ss[1] = line.substring(line.indexOf(v) + v.length(), line.length()); 132 | if (!ss[0].isEmpty()) { 133 | list.add(ss[0]); 134 | line = line.substring(ss[0].length()); 135 | } 136 | line = ss[1]; 137 | list.add(v); 138 | algorithmFill(list, line); 139 | return; 140 | } 141 | 142 | public static Map getNearestOne(final String line, Pattern... patterns) { 143 | try { 144 | Map map = new LinkedHashMap<>(); 145 | for (Pattern pattern : patterns) { 146 | Matcher matcher = pattern.matcher(line); 147 | if (matcher.find()) { 148 | String l1 = matcher.group(); 149 | int i1 = line.indexOf(l1); 150 | map.put(i1, l1); 151 | } 152 | } 153 | Map result1 = new LinkedHashMap<>(); 154 | map.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEachOrdered(x -> result1.put(x.getKey(), x.getValue())); 155 | return result1; 156 | } catch (Exception e) { 157 | e.printStackTrace(); 158 | return null; 159 | } 160 | } 161 | 162 | private static Message createMusic(Bot contact, String vals) { 163 | String[] ss = vals.split(","); 164 | MusicKind kind = MusicKind.valueOf(ss[0]); 165 | MusicShare share = new MusicShare(kind, ss[1], ss[2], ss[3], ss[4], ss[5]); 166 | return share; 167 | } 168 | 169 | public static Message createImage(Contact contact, Bot bot, String path) { 170 | Message image = null; 171 | try { 172 | if (path.startsWith("http")) { 173 | image = Contact.uploadImage(bot.getAsFriend(), new ByteArrayInputStream(ReadUtils.readAll(new URL(path).openStream()))); 174 | } else if (path.startsWith("{")) { 175 | image = Image.fromId(path); 176 | } else if (path.contains(BASE64)) { 177 | image = Contact.uploadImage(bot.getAsFriend(), new ByteArrayInputStream(getBase64Data(path))); 178 | } else if (path.startsWith("[") && path.endsWith("]")) { 179 | image = createForwardMessageByPic(contact, bot, (String[]) JSON.parseArray(path).toArray(new String[0])); 180 | } else { 181 | image = Contact.uploadImage(bot.getAsFriend(), new File(path)); 182 | } 183 | } catch (Exception e) { 184 | System.err.println(path + "加载失败"); 185 | e.printStackTrace(); 186 | } 187 | if (image != null) return image; 188 | else return null; 189 | } 190 | 191 | public static byte[] getBase64Data(String base64) { 192 | int i = base64.indexOf(BASE64); 193 | String base64Str = base64.substring(i + BASE64.length()); 194 | byte[] bytes = Base64.getDecoder().decode(base64Str); 195 | return bytes; 196 | } 197 | 198 | public static Message createVoiceMessageInGroup(String url, long id, Contact contact) { 199 | ExternalResource resource = null; 200 | try { 201 | byte[] bytes = UrlUtils.getBytesFromHttpUrl(url); 202 | resource = ExternalResource.create(bytes); 203 | if (contact instanceof Group) { 204 | return ((Group) contact).uploadAudio(resource); 205 | } else if (contact instanceof Friend) { 206 | return ((Friend) contact).uploadAudio(resource); 207 | } else return new PlainText(url); 208 | } catch (Exception e) { 209 | e.printStackTrace(); 210 | return null; 211 | } finally { 212 | if (resource != null) { 213 | try { 214 | resource.close(); 215 | } catch (IOException e) { 216 | e.printStackTrace(); 217 | } 218 | } 219 | } 220 | } 221 | 222 | public static Message createForwardMessageByPic(Contact contact, Bot bot, String[] picUrl) { 223 | ForwardMessageBuilder builder = new ForwardMessageBuilder(contact); 224 | for (String s : picUrl) builder.add(bot.getId(), bot.getBot().getNick(), createImage(contact, bot, s)); 225 | return builder.build(); 226 | } 227 | 228 | public static final ArrSerializer ARR_SERIALIZER = new ArrSerializer(); 229 | 230 | static { 231 | ARR_SERIALIZER.add(new ArrSerializer.Rule(Image.class) { 232 | @Override 233 | public String serializer(Image o) { 234 | return String.format("", o.getImageId()); 235 | } 236 | }); 237 | ARR_SERIALIZER.add(new ArrSerializer.Rule(At.class) { 238 | @Override 239 | public String serializer(At o) { 240 | return String.format("", o.getTarget()); 241 | } 242 | }); 243 | ARR_SERIALIZER.add(new ArrSerializer.Rule(Face.class) { 244 | @Override 245 | public String serializer(Face o) { 246 | return String.format("", o.getId()); 247 | } 248 | }); 249 | ARR_SERIALIZER.add(new ArrSerializer.Rule(PlainText.class) { 250 | @Override 251 | public String serializer(PlainText o) { 252 | String touch = o.getContent(); 253 | String regx = "<.*?>"; 254 | Pattern pattern = Pattern.compile(regx); 255 | Matcher matcher = pattern.matcher(touch); 256 | while (matcher.find()) { 257 | touch = touch.replace(matcher.group(), "\\" + matcher.group()); 258 | } 259 | return touch; 260 | } 261 | }); 262 | ARR_SERIALIZER.add(new ArrSerializer.Rule<Audio>(Audio.class) { 263 | @Override 264 | public String serializer(Audio o) { 265 | return String.format("<audio:%s>", o.getFilename()); 266 | } 267 | }); 268 | ARR_SERIALIZER.add(new ArrSerializer.Rule<MusicShare>(MusicShare.class) { 269 | @Override 270 | public String serializer(MusicShare o) { 271 | return String.format("<music:%s>", o.getMusicUrl()); 272 | } 273 | }); 274 | ARR_SERIALIZER.add(new ArrSerializer.Rule<MarketFace>(MarketFace.class) { 275 | @Override 276 | public String serializer(MarketFace o) { 277 | MARKET_FACE_MAP.put(o.getId(), o); 278 | return String.format("<marketface:%s>", o.getId()); 279 | } 280 | }); 281 | // ARR_SERIALIZER.add(new ArrSerializer.Rule<QuoteReply>(QuoteReply.class) { 282 | // @Override 283 | // public String serializer(QuoteReply o) { 284 | // return String.format("<qr:%s>", AllMessage.latest(0, o.getSource().getInternalIds())); 285 | // } 286 | // }); 287 | ARR_SERIALIZER.setMode(1); 288 | } 289 | 290 | public static String messageChainSerializeToString(MessageChain chain) { 291 | return ARR_SERIALIZER.serializer(chain); 292 | } 293 | } 294 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/services/ScriptService.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1.services; 2 | 3 | import io.github.gdpl2112.mirai.p1.services.script.BaseMessageScriptContext; 4 | import io.github.gdpl2112.mirai.p1.services.script.BaseScriptUtils; 5 | import io.github.gdpl2112.mirai.p1.services.script.ScriptContext; 6 | import io.github.kloping.common.Public; 7 | import io.github.kloping.file.FileUtils; 8 | import io.github.kloping.judge.Judge; 9 | import io.github.kloping.url.UrlUtils; 10 | import kotlin.coroutines.CoroutineContext; 11 | import net.mamoe.mirai.Bot; 12 | import net.mamoe.mirai.contact.Contact; 13 | import net.mamoe.mirai.contact.User; 14 | import net.mamoe.mirai.event.EventHandler; 15 | import net.mamoe.mirai.event.SimpleListenerHost; 16 | import net.mamoe.mirai.event.events.*; 17 | import net.mamoe.mirai.message.data.ForwardMessageBuilder; 18 | import net.mamoe.mirai.message.data.Image; 19 | import net.mamoe.mirai.message.data.Message; 20 | import net.mamoe.mirai.message.data.MessageChain; 21 | import org.jetbrains.annotations.NotNull; 22 | import org.jetbrains.annotations.Nullable; 23 | 24 | import javax.script.ScriptEngine; 25 | import javax.script.ScriptEngineManager; 26 | import java.io.ByteArrayInputStream; 27 | import java.io.File; 28 | import java.util.HashMap; 29 | import java.util.Map; 30 | 31 | /** 32 | * @author github.kloping 33 | */ 34 | public class ScriptService extends SimpleListenerHost { 35 | public ScriptService() { 36 | System.setProperty("nashorn.args", "--no-deprecation-warning"); 37 | } 38 | 39 | @Override 40 | public void handleException(@NotNull CoroutineContext context, @NotNull Throwable exception) { 41 | exception.printStackTrace(); 42 | } 43 | 44 | public static final ScriptEngineManager SCRIPT_ENGINE_MANAGER = new ScriptEngineManager(); 45 | public static final String[] NOT_PRINTS = {"未开启", "NOT OPEN", "not open", "exit", "end", "stop"}; 46 | 47 | public static Map<String, ScriptException> exceptionMap = new HashMap<>(); 48 | 49 | private File jsFile = new File("./conf/callApi/script.js"); 50 | 51 | private String getScriptCode(long bid) { 52 | return FileUtils.getStringFromFile(jsFile.getAbsolutePath()); 53 | } 54 | 55 | @EventHandler 56 | public void onMessage(@NotNull MessageEvent event) { 57 | if (event instanceof MessagePreSendEvent) return; 58 | if (event instanceof MessagePostSendEvent) return; 59 | final String code = getScriptCode(event.getBot().getId()); 60 | if (Judge.isEmpty(code.trim())) return; 61 | Public.EXECUTOR_SERVICE.submit(() -> { 62 | try { 63 | ScriptEngine javaScript = SCRIPT_ENGINE_MANAGER.getEngineByName("JavaScript"); 64 | javaScript.put("context", new BaseMessageScriptContext(event)); 65 | javaScript.put("utils", new BaseScriptUtils(event.getBot().getId())); 66 | String msg = toMsg(event.getMessage()); 67 | javaScript.put("msg", msg); 68 | javaScript.eval(code); 69 | } catch (Throwable e) { 70 | onException(event.getBot(), e); 71 | } 72 | }); 73 | } 74 | 75 | private String toMsg(MessageChain chain) { 76 | String msg = DgSerializer.messageChainSerializeToString(chain); 77 | return msg; 78 | } 79 | 80 | @EventHandler 81 | public void onEvent(BotEvent event) { 82 | if (event instanceof MessageEvent) return; 83 | if (event instanceof MessagePreSendEvent) return; 84 | if (event instanceof MessagePostSendEvent) return; 85 | if (event instanceof BotOnlineEvent) return; 86 | if (event instanceof BotOfflineEvent) return; 87 | final String code = getScriptCode(event.getBot().getId()); 88 | if (Judge.isEmpty(code.trim())) return; 89 | Public.EXECUTOR_SERVICE.submit(() -> { 90 | try { 91 | ScriptEngine javaScript = SCRIPT_ENGINE_MANAGER.getEngineByName("JavaScript"); 92 | javaScript.put("context", new BasebBotEventScriptContext(event)); 93 | javaScript.put("event", event); 94 | javaScript.put("utils", new BaseScriptUtils(event.getBot().getId())); 95 | javaScript.put("msg", event.toString()); 96 | javaScript.eval(code); 97 | } catch (Throwable e) { 98 | onException(event.getBot(), e); 99 | } 100 | }); 101 | } 102 | 103 | public static void onException(Bot bot, Throwable e) { 104 | if (e instanceof javax.script.ScriptException) { 105 | String e1 = e.getMessage(); 106 | for (String e0 : NOT_PRINTS) { 107 | if (e1.contains(e0)) return; 108 | } 109 | } 110 | e.printStackTrace(); 111 | String err = io.github.kloping.MySpringTool.PartUtils.getExceptionLine(e); 112 | err = e + err; 113 | Long bid = bot.getId(); 114 | ScriptException se = new ScriptException(err, System.currentTimeMillis(), bid); 115 | exceptionMap.put(bid.toString(), se); 116 | System.err.println(String.format("%s Bot 脚本 执行失败", bot.getId())); 117 | } 118 | 119 | public static class BasebBotEventScriptContext implements ScriptContext { 120 | private BotEvent event; 121 | 122 | public BasebBotEventScriptContext(BotEvent userEvent) { 123 | this.event = userEvent; 124 | } 125 | 126 | @Override 127 | public MessageChain getRaw() { 128 | return null; 129 | } 130 | 131 | @Override 132 | public void send(String str) { 133 | 134 | } 135 | 136 | @Override 137 | public void send(Message message) { 138 | 139 | } 140 | 141 | @Override 142 | public Bot getBot() { 143 | return event.getBot(); 144 | } 145 | 146 | @Override 147 | public User getSender() { 148 | return null; 149 | } 150 | 151 | @Override 152 | public Contact getSubject() { 153 | return null; 154 | } 155 | 156 | @Override 157 | public ForwardMessageBuilder forwardBuilder() { 158 | return new ForwardMessageBuilder(event.getBot().getAsFriend()); 159 | } 160 | 161 | @Override 162 | public Message deSerialize(String msg) { 163 | return DgSerializer.stringDeserializeToMessageChain(msg, event.getBot(), event.getBot().getAsFriend()); 164 | } 165 | 166 | @Override 167 | public MessageChain getMessageChainById(int id) { 168 | return null; 169 | } 170 | 171 | @Override 172 | public Image uploadImage(String url) { 173 | try { 174 | byte[] bytes = UrlUtils.getBytesFromHttpUrl(url); 175 | Image image = Contact.uploadImage(event.getBot().getAsFriend(), new ByteArrayInputStream(bytes)); 176 | return image; 177 | } catch (Exception e) { 178 | e.printStackTrace(); 179 | return null; 180 | } 181 | } 182 | 183 | @Override 184 | public String getType() { 185 | return event.getClass().getSimpleName(); 186 | } 187 | } 188 | 189 | @Nullable 190 | public static MessageChain getSingleMessages(int id, BotEvent event) { 191 | return null; 192 | } 193 | 194 | public static class ScriptException { 195 | private String msg; 196 | private Long time; 197 | private Long qid; 198 | 199 | public ScriptException(String msg, Long time, Long qid) { 200 | this.msg = msg; 201 | this.time = time; 202 | this.qid = qid; 203 | } 204 | 205 | public String getMsg() { 206 | return msg; 207 | } 208 | 209 | public Long getTime() { 210 | return time; 211 | } 212 | 213 | public Long getQid() { 214 | return qid; 215 | } 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/services/script/BaseMessageScriptContext.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1.services.script; 2 | 3 | import io.github.gdpl2112.mirai.p1.services.DgSerializer; 4 | import io.github.kloping.url.UrlUtils; 5 | import net.mamoe.mirai.Bot; 6 | import net.mamoe.mirai.contact.Contact; 7 | import net.mamoe.mirai.contact.User; 8 | import net.mamoe.mirai.event.events.FriendMessageEvent; 9 | import net.mamoe.mirai.event.events.GroupMessageEvent; 10 | import net.mamoe.mirai.event.events.GroupMessageSyncEvent; 11 | import net.mamoe.mirai.event.events.MessageEvent; 12 | import net.mamoe.mirai.message.data.ForwardMessageBuilder; 13 | import net.mamoe.mirai.message.data.Image; 14 | import net.mamoe.mirai.message.data.Message; 15 | import net.mamoe.mirai.message.data.MessageChain; 16 | 17 | import java.io.ByteArrayInputStream; 18 | 19 | 20 | public class BaseMessageScriptContext implements ScriptContext { 21 | private MessageEvent event; 22 | 23 | public BaseMessageScriptContext(MessageEvent event) { 24 | this.event = event; 25 | } 26 | 27 | @Override 28 | public Bot getBot() { 29 | return event.getBot(); 30 | } 31 | 32 | @Override 33 | public MessageChain getRaw() { 34 | return event.getMessage(); 35 | } 36 | 37 | @Override 38 | public Message deSerialize(String msg) { 39 | return DgSerializer.stringDeserializeToMessageChain(msg, event.getBot(), event.getSubject()); 40 | } 41 | 42 | @Override 43 | public void send(String str) { 44 | Message msg = DgSerializer.stringDeserializeToMessageChain(str, event.getBot(), event.getSubject()); 45 | event.getSubject().sendMessage(msg); 46 | } 47 | 48 | @Override 49 | public void send(Message message) { 50 | event.getSubject().sendMessage(message); 51 | } 52 | 53 | @Override 54 | public ForwardMessageBuilder forwardBuilder() { 55 | return new ForwardMessageBuilder(getSubject()); 56 | } 57 | 58 | @Override 59 | public MessageChain getMessageChainById(int id) { 60 | return null; 61 | } 62 | 63 | @Override 64 | public User getSender() { 65 | return event.getSender(); 66 | } 67 | 68 | @Override 69 | public Contact getSubject() { 70 | return event.getSubject(); 71 | } 72 | 73 | @Override 74 | public Image uploadImage(String url) { 75 | try { 76 | byte[] bytes = UrlUtils.getBytesFromHttpUrl(url); 77 | Image image = Contact.uploadImage(event.getBot().getAsFriend(), new ByteArrayInputStream(bytes)); 78 | return image; 79 | } catch (Exception e) { 80 | e.printStackTrace(); 81 | return null; 82 | } 83 | } 84 | 85 | @Override 86 | public String getType() { 87 | return event instanceof GroupMessageEvent || event instanceof GroupMessageSyncEvent ? "group" : event instanceof FriendMessageEvent ? "friend" : "Unknown"; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/services/script/BaseScriptUtils.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1.services.script; 2 | 3 | import io.github.gdpl2112.mirai.p1.services.DgSerializer; 4 | import io.github.kloping.map.MapUtils; 5 | import io.github.kloping.url.UrlUtils; 6 | import net.mamoe.mirai.message.data.MessageChain; 7 | import org.jsoup.Jsoup; 8 | 9 | import java.io.IOException; 10 | import java.lang.reflect.Constructor; 11 | import java.util.*; 12 | 13 | public class BaseScriptUtils implements ScriptUtils { 14 | private long bid; 15 | 16 | public BaseScriptUtils(long bid) { 17 | this.bid = bid; 18 | } 19 | 20 | public static final Map<Long, Map<String, Object>> BID_2_VARIABLES = new HashMap<>(); 21 | 22 | @Override 23 | public String requestGet(String url) { 24 | return UrlUtils.getStringFromHttpUrl(url); 25 | } 26 | 27 | @Override 28 | public String requestPost(String url, String data) { 29 | try { 30 | return Jsoup.connect(url).ignoreContentType(true).ignoreHttpErrors(true).requestBody(data).post().body().wholeText(); 31 | } catch (IOException e) { 32 | return e.getLocalizedMessage(); 33 | } 34 | } 35 | 36 | @Override 37 | public String serialize(MessageChain chain) { 38 | return DgSerializer.messageChainSerializeToString(chain); 39 | } 40 | 41 | @Override 42 | public Object get(String name) { 43 | return getValueOrDefault(BID_2_VARIABLES, bid, name, null); 44 | } 45 | 46 | @Override 47 | public Object set(String name, Object value) { 48 | Object ov = getValueOrDefault(BID_2_VARIABLES, bid, name, null); 49 | MapUtils.append(BID_2_VARIABLES, bid, name, value, HashMap.class); 50 | return ov; 51 | } 52 | 53 | @Override 54 | public Integer clear() { 55 | int i = 0; 56 | Map<String, Object> sizeMap = BID_2_VARIABLES.get(bid); 57 | if (sizeMap != null) { 58 | i = sizeMap.size(); 59 | sizeMap.clear(); 60 | } 61 | return i; 62 | } 63 | 64 | @Override 65 | public Object del(String name) { 66 | Map<String, Object> sizeMap = BID_2_VARIABLES.get(bid); 67 | if (sizeMap != null) { 68 | Object oa = sizeMap.get(name); 69 | sizeMap.remove(name); 70 | return oa; 71 | } 72 | return null; 73 | } 74 | 75 | @Override 76 | public List<Map.Entry<String, Object>> list() { 77 | if (BID_2_VARIABLES.containsKey(bid)) 78 | return new LinkedList<>(BID_2_VARIABLES.get(bid).entrySet()); 79 | return new ArrayList<>(); 80 | } 81 | 82 | @Override 83 | public <T> T newObject(String name, Object... args) { 84 | try { 85 | Class cla = Class.forName(name); 86 | List<Class> list = new ArrayList<>(); 87 | for (Object arg : args) { 88 | list.add(arg.getClass()); 89 | } 90 | Constructor constructor = cla.getDeclaredConstructor(list.toArray(new Class[0])); 91 | return (T) constructor.newInstance(args); 92 | } catch (Exception e) { 93 | e.printStackTrace(); 94 | return null; 95 | } 96 | } 97 | 98 | 99 | public static final <T, K1, K2> T getValueOrDefault(Map<K1, Map<K2, T>> map, K1 k1, K2 k2, T def) { 100 | if (map.containsKey(k1)) { 101 | Map<K2, T> m2 = map.get(k1); 102 | if (m2.containsKey(k2)) { 103 | return m2.get(k2); 104 | } else { 105 | m2.put(k2, def); 106 | map.put(k1, m2); 107 | return def; 108 | } 109 | } else { 110 | Map<K2, T> m2 = new HashMap<>(); 111 | m2.put(k2, def); 112 | map.put(k1, m2); 113 | return def; 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/services/script/ScriptContext.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1.services.script; 2 | 3 | import io.github.gdpl2112.mirai.p1.services.DgSerializer; 4 | import io.github.kloping.url.UrlUtils; 5 | import net.mamoe.mirai.Bot; 6 | import net.mamoe.mirai.contact.Contact; 7 | import net.mamoe.mirai.contact.User; 8 | import net.mamoe.mirai.message.data.*; 9 | 10 | import java.io.ByteArrayInputStream; 11 | 12 | /** 13 | * script 交互对象 14 | * 预设脚本环境变量: context 15 | * 16 | * @author github.kloping 17 | */ 18 | public interface ScriptContext { 19 | /** 20 | * 获取bot 21 | * 22 | * @return 23 | */ 24 | Bot getBot(); 25 | 26 | /** 27 | * 获取元数据 28 | * 29 | * @return 30 | */ 31 | MessageChain getRaw(); 32 | 33 | /** 34 | * 发送字符串 35 | * 36 | * @param str 37 | */ 38 | void send(String str); 39 | 40 | /** 41 | * 发送至所在环境 42 | * 43 | * @param message 44 | */ 45 | void send(Message message); 46 | 47 | /** 48 | * 获得一个 Builder 49 | * 50 | * @return 51 | */ 52 | default MessageChainBuilder builder() { 53 | return new MessageChainBuilder(); 54 | } 55 | 56 | /** 57 | * 获得一个 转发行 58 | * 59 | * @return 60 | */ 61 | ForwardMessageBuilder forwardBuilder(); 62 | 63 | /** 64 | * 创建音乐分享消息 65 | * 66 | * @param kind 67 | * @param title 68 | * @param summer 69 | * @param jumUrl 70 | * @param picUrl 71 | * @param url 72 | * @return 73 | */ 74 | default MusicShare createMusicShare(String kind, String title, String summer, String jumUrl, String picUrl, String url) { 75 | return new MusicShare(MusicKind.valueOf(kind), title, summer, jumUrl, picUrl, url); 76 | } 77 | 78 | /** 79 | * 上传图片 80 | * 81 | * @param url 82 | * @return 83 | */ 84 | default Image uploadImage(String url) { 85 | try { 86 | byte[] bytes = UrlUtils.getBytesFromHttpUrl(url); 87 | Image image = Contact.uploadImage(getBot().getAsFriend(), new ByteArrayInputStream(bytes)); 88 | return image; 89 | } catch (Exception e) { 90 | e.printStackTrace(); 91 | return null; 92 | } 93 | } 94 | 95 | /** 96 | * 构建 文本 97 | * 98 | * @param text 99 | * @return 100 | */ 101 | default PlainText newPlainText(String text) { 102 | return new PlainText(text); 103 | } 104 | 105 | default SuperFace toSuperFace(int id) { 106 | return SuperFace.from(new Face(id)); 107 | } 108 | 109 | /** 110 | * 反向 str 解析为 Message 111 | * 112 | * @param msg 113 | * @return 114 | */ 115 | default Message deSerialize(String msg) { 116 | return DgSerializer.stringDeserializeToMessageChain(msg, getBot(), getBot().getAsFriend()); 117 | } 118 | 119 | /** 120 | * 从id获取MessageChain 可用于直接发送 <br> 121 | * !! 仅能获取2小时以内的数据 122 | * 123 | * @param id 124 | * @return 125 | */ 126 | MessageChain getMessageChainById(int id); 127 | 128 | /** 129 | * 发送者ID 130 | * 131 | * @return 132 | */ 133 | User getSender(); 134 | 135 | /** 136 | * 发送环境id 一般为 群id 137 | * 138 | * @return 139 | */ 140 | Contact getSubject(); 141 | 142 | /** 143 | * 所处环境 <a href="https://github.com/gdpl2112/dg-bot/blob/master/js-api.md"> 说明</a> 144 | * 145 | * @return 146 | */ 147 | String getType(); 148 | } 149 | -------------------------------------------------------------------------------- /src/main/java/io/github/gdpl2112/mirai/p1/services/script/ScriptUtils.java: -------------------------------------------------------------------------------- 1 | package io.github.gdpl2112.mirai.p1.services.script; 2 | 3 | import net.mamoe.mirai.message.data.Image; 4 | import net.mamoe.mirai.message.data.MessageChain; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * 脚本工具 11 | * 预设脚本变量为: 12 | * utils 13 | * 14 | * @author github.kloping 15 | */ 16 | public interface ScriptUtils { 17 | 18 | /** 19 | * get 请求 20 | * 21 | * @param url 22 | * @return 23 | */ 24 | String requestGet(String url); 25 | 26 | /** 27 | * post 请求 28 | * 29 | * @param url 30 | * @return 31 | */ 32 | String requestPost(String url, String data); 33 | 34 | 35 | /** 36 | * 查询image url 通过image id 37 | * 38 | * @param imageId 39 | * @return 40 | */ 41 | default String queryUrlFromId(String imageId) { 42 | return Image.queryUrl(Image.fromId(imageId)); 43 | } 44 | 45 | /** 46 | * 正向解析mes为定制string 47 | * 48 | * @param chain 49 | * @return 50 | */ 51 | String serialize(MessageChain chain); 52 | 53 | 54 | /** 55 | * 获取变量 56 | * 57 | * @param name 58 | * @return 59 | */ 60 | Object get(String name); 61 | 62 | /** 63 | * 设置变量 64 | * 65 | * @param name 66 | * @param value 67 | * @return 68 | */ 69 | Object set(String name, Object value); 70 | 71 | /** 72 | * 清除当前账号的所有变量 73 | * 74 | * @return 75 | */ 76 | Integer clear(); 77 | 78 | /** 79 | * 删除指定变量 80 | * 81 | * @param name 82 | * @return 83 | */ 84 | Object del(String name); 85 | 86 | /** 87 | * 列出当前bot所有变量 88 | * 89 | * @return 90 | */ 91 | List<Map.Entry<String, Object>> list(); 92 | 93 | /** 94 | * js 创建Java的对象 95 | * 96 | * @param name 类全名 如: java.util.HashMap 97 | * @param args 参数可选 98 | * @param <T> 99 | * @return 100 | */ 101 | <T> T newObject(String name, Object... args); 102 | } 103 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/net.mamoe.mirai.console.plugin.jvm.JvmPlugin: -------------------------------------------------------------------------------- 1 | io.github.gdpl2112.mirai.p1.CallApiPlugin -------------------------------------------------------------------------------- /src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | <!DOCTYPE html> 2 | <html lang="zh-cn"> 3 | <head> 4 | <meta charset="utf-8"> 5 | <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 6 | <script src="/js/libs/axios.js"></script> 7 | <script src="/js/libs/vue.js"></script> 8 | <script src="/js/libs/jq3.6.js"></script> 9 | 10 | <link href="/css/libs/bootstarp@5.1.3_min.css" rel="stylesheet" 11 | crossorigin="anonymous"> 12 | <link rel="stylesheet" href="/css/libs/http_cdn.jsdelivr.net_npm_bootstrap@4.6.2_dist_css_bootstrap.css" 13 | crossorigin="anonymous"> 14 | <style> 15 | body { 16 | margin: 0; 17 | padding: 0; 18 | font-family: "montserrat"; 19 | background-image: linear-gradient(125deg, #2c3e50, #6fe8ec, #2980b9, #ff5fa2, #8e44ad); 20 | background-size: 400%; 21 | animation: bganimation 20s infinite; 22 | } 23 | 24 | @keyframes bganimation { 25 | 0% { 26 | background-position: 0% 50%; 27 | } 28 | 29 | 50% { 30 | background-position: 100% 50%; 31 | } 32 | 33 | 100% { 34 | background-position: 0% 50%; 35 | } 36 | } 37 | </style> 38 | <title>API管理界面</title> 39 | </head> 40 | <body> 41 | <nav class="navbar navbar-expand-lg navbar-light bg-light tm-0" style="background: rgba(255,255,255,0.8)"> 42 | <a class="navbar-brand" href="/"> 43 | <img alt="github" 44 | class="navbar-brand" src="http://kloping.top/icon.jpg" style="opacity: 0.86;max-width: 50px; border-radius: 999px"></a> 45 | <button aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation" 46 | class="navbar-toggler" data-target="#navbarSupportedContent" 47 | data-toggle="collapse" type="button"> 48 | <span class="navbar-toggler-icon"></span> 49 | </button> 50 | 51 | <div class="collapse navbar-collapse" id="navbarSupportedContent"> 52 | <ul class="navbar-nav mr-auto"> 53 | <li class="nav-item active"> 54 | <span class="nav-link">API管理</span> 55 | </li> 56 | <li class="nav-item"> 57 | <a class="nav-link" href="http://kloping.top/">kloping's web</a> 58 | </li> 59 | <li class="nav-item"> 60 | <a class="nav-link" href="https://qm.qq.com/q/xRJqMmNbRC">交流群</a> 61 | </li> 62 | <li class="nav-item"> 63 | <a class="nav-link disabled">更多功能;敬请期待.</a> 64 | </li> 65 | </ul> 66 | <form class="form-inline my-2 my-lg-0"> 67 | <a class="dropdown-item" href="https://github.com/gdpl2112/MiraiCallApiPlugin" target="_blank"> 68 | <img alt="github" loading="lazy" src="https://s.nmxc.ltd/sakurairo_vision/@2.6/display_icon/sora/github.png" 69 | style="opacity: 0.86;max-width: 35px"> 70 | github 开源地址 71 | </a> 72 | </form> 73 | </div> 74 | </nav> 75 | <br> 76 | <hr> 77 | <div class="modal fade" id="appendModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> 78 | <div class="modal-dialog modal-dialog-centered"> 79 | <div class="modal-content"> 80 | <div class="modal-header"> 81 | <h5 class="modal-title" id="exampleModalLabel">添加一个API</h5> 82 | <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="关闭"></button> 83 | </div> 84 | <div class="modal-body"> 85 | <div class="input-group mb-3"> 86 | <span class="input-group-text" id="inputGroup-out">输出格式</span> 87 | <input type="text" class="form-control" aria-label="Sizing example input"> 88 | </div> 89 | <div class="input-group mb-3"> 90 | <span class="input-group-text" id="inputGroup-outArgs">输出参数</span> 91 | <input placeholder="用,分割参数(英文)" type="text" class="form-control" 92 | aria-label="Sizing example input"> 93 | </div> 94 | <div class="input-group mb-3"> 95 | <span class="input-group-text" id="inputGroup-touch">触发词</span> 96 | <input type="text" class="form-control" aria-label="Sizing example input"> 97 | </div> 98 | <div class="input-group mb-3"> 99 | <span class="input-group-text" id="inputGroup-url">网址</span> 100 | <input type="text" class="form-control" aria-label="Sizing example input"> 101 | </div> 102 | <div class="input-group mb-3"> 103 | <span class="input-group-text" id="inputGroup-proxy">代理</span> 104 | <input type="text" class="form-control" aria-label="Sizing example input" 105 | placeholder="可为空 格式为 IP:port"> 106 | </div> 107 | </div> 108 | <div class="modal-footer"> 109 | <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button> 110 | <button type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="submit0()">确定</button> 111 | </div> 112 | </div> 113 | </div> 114 | </div> 115 | <div class="container"> 116 | <div class="row"> 117 | <div class="center-block"> 118 | <div style="text-align: center;"> 119 | <button onclick="add0()" type="button" class="btn btn-primary btn-lg btn-block" data-bs-toggle="modal"> 120 | 添加 121 | </button> 122 | </div> 123 | <br> 124 | <hr> 125 | </div> 126 | </div> 127 | </div> 128 | <div class="container bg-light"> 129 | <div class="row"> 130 | <div id="table_main" class="center-block"> 131 | <div class="container" style="background: rgba(255,255,255,0.8)"> 132 | <hr> 133 | <div class="row"> 134 | <div class="col-8"> 135 | <ul class="list-group"> 136 | <li class="list-group-item disabled" aria-disabled="true">输出格式</li> 137 | <li class="list-group-item disabled" aria-disabled="true">输出参数</li> 138 | <li class="list-group-item disabled" aria-disabled="true">触发词</li> 139 | <li class="list-group-item disabled" aria-disabled="true">地址</li> 140 | <li class="list-group-item disabled" aria-disabled="true">代理</li> 141 | </ul> 142 | </div> 143 | <div class="col-4">操作</div> 144 | </div> 145 | <div v-for="(e) in data" :class="getTrClass()+' row'" style="margin-top: 15px;padding-bottom: 10px;padding-top: 10px;ba"> 146 | <div class="col-8"> 147 | <ul class="list-group"> 148 | <li class="list-group-item" style="overflow:scroll;" v-text="e.out">输出格式</li> 149 | <li class="list-group-item" v-text="getStrArgs(e.outArgs)">输出参数</li> 150 | <li class="list-group-item" v-text="e.touch">触发词</li> 151 | <li class="list-group-item" style="overflow:scroll;" v-text="e.url">地址</li> 152 | <li class="list-group-item" style="overflow:scroll;" v-text="e.proxyIp+':'+e.proxyPort">代理</li> 153 | </ul> 154 | </div> 155 | <div class="col-4"> 156 | <img class="rounded img-fluid img-responsive" :src="getFavicon(e)" style="max-width: 90px"> 157 | <hr> <button v-on:click="delete0(e.touch)" type="button" class="btn btn-danger col">删除</button> 158 | <hr><button v-on:click="modify0(e)" type="button" class="btn btn-primary col">修改</button> 159 | </div> 160 | </div> 161 | </div> 162 | </div> 163 | </div> 164 | </div> 165 | <script> 166 | let e_out = $("#inputGroup-out").next(); 167 | let e_outArgs = $("#inputGroup-outArgs").next(); 168 | let e_touch = $("#inputGroup-touch").next(); 169 | let e_url = $("#inputGroup-url").next(); 170 | let e_proxy = $("#inputGroup-proxy").next(); 171 | function submit0() { 172 | let v1 = encodeURIComponent(e_out.val()) 173 | let v2 = encodeURIComponent(e_outArgs.val()) 174 | let v3 = encodeURIComponent(e_touch.val()) 175 | let v4 = encodeURIComponent(e_url.val()) 176 | let v5 = encodeURIComponent(e_proxy.val()) 177 | let url = "/append?out=" + v1 178 | + "&outArgs=" + v2 179 | + "&touch=" + v3 180 | + "&url=" + v4 181 | + "&proxy=" + v5; 182 | 183 | axios.post(url).then(function (response) { 184 | trIndex = 0; 185 | vm1.data = response.data; 186 | e_out.val("") 187 | e_outArgs.val("") 188 | e_proxy.val("") 189 | e_touch.val("") 190 | e_url.val("") 191 | }).catch(function (err) { 192 | alert(err); 193 | }) 194 | } 195 | 196 | function add0() { 197 | $('#exampleModalLabel').html('添加一个API'); 198 | $('#appendModal').modal('show') 199 | e_out.val("") 200 | e_outArgs.val("") 201 | e_touch.val("") 202 | e_url.val("") 203 | e_proxy.val("") 204 | } 205 | 206 | let trClasses = ["alert-primary", "alert-secondary", "alert-success", "alert-danger", "alert-warning", "alert-info", "alert-light", "alert-dark"]; 207 | let trIndex = 0 208 | 209 | let vm1 = new Vue({ 210 | el: "#table_main", 211 | created: function () { 212 | axios.get("/get_data").then(function (response) { 213 | trIndex = 0; 214 | vm1.data = response.data; 215 | }).catch(function (err) { 216 | alert(err); 217 | }) 218 | }, data: { 219 | data: [], 220 | }, methods: { 221 | getFavicon: function (e) { 222 | let u0 = e.url; 223 | let i0 = u0.substr(8).indexOf("/") 224 | return u0.substr(0, 9 + i0) + "favicon.ico" 225 | }, delete0: function (touch) { 226 | axios.get("/delete?touch=" + touch).then(function (response) { 227 | trIndex = 0; 228 | vm1.data = response.data; 229 | }).catch(function (err) { 230 | alert(err); 231 | }) 232 | }, modify0: function (e) { 233 | e_out.val(e.out) 234 | e_outArgs.val(e.outArgs) 235 | e_touch.val(e.touch) 236 | e_url.val(e.url) 237 | e_proxy.val(e.proxyIp + ':' + e.proxyPort) 238 | $('#exampleModalLabel').html('修改一个API'); 239 | $('#appendModal').modal('show') 240 | }, getTrClass: function () { 241 | return trClasses[trIndex++ % trClasses.length].toString() 242 | }, getStrArgs: function (args) { 243 | let s0 = ""; 244 | for (e0 of args) { 245 | s0 = s0 + "\r\n" + e0; 246 | } 247 | return s0.trim(); 248 | } 249 | } 250 | }); 251 | </script> 252 | <br> 253 | 254 | <script src="/js/libs/http_cdn.jsdelivr.net_npm_jquery@3.5.1_dist_jquery.slim.min.js" crossorigin="anonymous"></script> 255 | <script src="/js/libs/http_cdn.jsdelivr.net_npm_bootstrap@4.6.2_dist_js_bootstrap.bundle.js" 256 | crossorigin="anonymous"></script> 257 | <script src="/js/libs/http_cdn.jsdelivr.net_npm_bootstrap@5.1.3_dist_js_bootstrap.bundle.js" 258 | crossorigin="anonymous"></script> 259 | <script src="/js/index.js"></script> 260 | </body> 261 | </html> -------------------------------------------------------------------------------- /src/main/resources/static/js/index.js: -------------------------------------------------------------------------------- 1 | alert("欢迎使用kloping's插件 自定义调用API插件\n若发现bug请及时反馈\nQQ群:794238572") 2 | -------------------------------------------------------------------------------- /src/main/resources/static/js/libs/axios.js: -------------------------------------------------------------------------------- 1 | /* axios v0.27.2 | (c) 2022 by Matt Zabriskie */ 2 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.axios=t():e.axios=t()}(this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=13)}([function(e,t,n){"use strict";var r,o=n(4),i=Object.prototype.toString,s=(r=Object.create(null),function(e){var t=i.call(e);return r[t]||(r[t]=t.slice(8,-1).toLowerCase())});function a(e){return e=e.toLowerCase(),function(t){return s(t)===e}}function u(e){return Array.isArray(e)}function c(e){return void 0===e}var f=a("ArrayBuffer");function l(e){return null!==e&&"object"==typeof e}function p(e){if("object"!==s(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}var d=a("Date"),h=a("File"),m=a("Blob"),v=a("FileList");function y(e){return"[object Function]"===i.call(e)}var g=a("URLSearchParams");function E(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),u(e))for(var n=0,r=e.length;n<r;n++)t.call(null,e[n],n,e);else for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.call(null,e[o],o,e)}var b,O=(b="undefined"!=typeof Uint8Array&&Object.getPrototypeOf(Uint8Array),function(e){return b&&e instanceof b});e.exports={isArray:u,isArrayBuffer:f,isBuffer:function(e){return null!==e&&!c(e)&&null!==e.constructor&&!c(e.constructor)&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)},isFormData:function(e){return e&&("function"==typeof FormData&&e instanceof FormData||"[object FormData]"===i.call(e)||y(e.toString)&&"[object FormData]"===e.toString())},isArrayBufferView:function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&f(e.buffer)},isString:function(e){return"string"==typeof e},isNumber:function(e){return"number"==typeof e},isObject:l,isPlainObject:p,isUndefined:c,isDate:d,isFile:h,isBlob:m,isFunction:y,isStream:function(e){return l(e)&&y(e.pipe)},isURLSearchParams:g,isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product&&"NativeScript"!==navigator.product&&"NS"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:E,merge:function e(){var t={};function n(n,r){p(t[r])&&p(n)?t[r]=e(t[r],n):p(n)?t[r]=e({},n):u(n)?t[r]=n.slice():t[r]=n}for(var r=0,o=arguments.length;r<o;r++)E(arguments[r],n);return t},extend:function(e,t,n){return E(t,(function(t,r){e[r]=n&&"function"==typeof t?o(t,n):t})),e},trim:function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")},stripBOM:function(e){return 65279===e.charCodeAt(0)&&(e=e.slice(1)),e},inherits:function(e,t,n,r){e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,n&&Object.assign(e.prototype,n)},toFlatObject:function(e,t,n){var r,o,i,s={};t=t||{};do{for(o=(r=Object.getOwnPropertyNames(e)).length;o-- >0;)s[i=r[o]]||(t[i]=e[i],s[i]=!0);e=Object.getPrototypeOf(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:s,kindOfTest:a,endsWith:function(e,t,n){e=String(e),(void 0===n||n>e.length)&&(n=e.length),n-=t.length;var r=e.indexOf(t,n);return-1!==r&&r===n},toArray:function(e){if(!e)return null;var t=e.length;if(c(t))return null;for(var n=new Array(t);t-- >0;)n[t]=e[t];return n},isTypedArray:O,isFileList:v}},function(e,t,n){"use strict";var r=n(0);function o(e,t,n,r,o){Error.call(this),this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o)}r.inherits(o,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code,status:this.response&&this.response.status?this.response.status:null}}});var i=o.prototype,s={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED"].forEach((function(e){s[e]={value:e}})),Object.defineProperties(o,s),Object.defineProperty(i,"isAxiosError",{value:!0}),o.from=function(e,t,n,s,a,u){var c=Object.create(i);return r.toFlatObject(e,c,(function(e){return e!==Error.prototype})),o.call(c,e.message,t,n,s,a),c.name=e.name,u&&Object.assign(c,u),c},e.exports=o},function(e,t,n){"use strict";var r=n(1);function o(e){r.call(this,null==e?"canceled":e,r.ERR_CANCELED),this.name="CanceledError"}n(0).inherits(o,r,{__CANCEL__:!0}),e.exports=o},function(e,t,n){"use strict";var r=n(0),o=n(19),i=n(1),s=n(6),a=n(7),u={"Content-Type":"application/x-www-form-urlencoded"};function c(e,t){!r.isUndefined(e)&&r.isUndefined(e["Content-Type"])&&(e["Content-Type"]=t)}var f,l={transitional:s,adapter:(("undefined"!=typeof XMLHttpRequest||"undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process))&&(f=n(8)),f),transformRequest:[function(e,t){if(o(t,"Accept"),o(t,"Content-Type"),r.isFormData(e)||r.isArrayBuffer(e)||r.isBuffer(e)||r.isStream(e)||r.isFile(e)||r.isBlob(e))return e;if(r.isArrayBufferView(e))return e.buffer;if(r.isURLSearchParams(e))return c(t,"application/x-www-form-urlencoded;charset=utf-8"),e.toString();var n,i=r.isObject(e),s=t&&t["Content-Type"];if((n=r.isFileList(e))||i&&"multipart/form-data"===s){var u=this.env&&this.env.FormData;return a(n?{"files[]":e}:e,u&&new u)}return i||"application/json"===s?(c(t,"application/json"),function(e,t,n){if(r.isString(e))try{return(t||JSON.parse)(e),r.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(n||JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){var t=this.transitional||l.transitional,n=t&&t.silentJSONParsing,o=t&&t.forcedJSONParsing,s=!n&&"json"===this.responseType;if(s||o&&r.isString(e)&&e.length)try{return JSON.parse(e)}catch(e){if(s){if("SyntaxError"===e.name)throw i.from(e,i.ERR_BAD_RESPONSE,this,null,this.response);throw e}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:n(27)},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};r.forEach(["delete","get","head"],(function(e){l.headers[e]={}})),r.forEach(["post","put","patch"],(function(e){l.headers[e]=r.merge(u)})),e.exports=l},function(e,t,n){"use strict";e.exports=function(e,t){return function(){for(var n=new Array(arguments.length),r=0;r<n.length;r++)n[r]=arguments[r];return e.apply(t,n)}}},function(e,t,n){"use strict";var r=n(0);function o(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}e.exports=function(e,t,n){if(!t)return e;var i;if(n)i=n(t);else if(r.isURLSearchParams(t))i=t.toString();else{var s=[];r.forEach(t,(function(e,t){null!=e&&(r.isArray(e)?t+="[]":e=[e],r.forEach(e,(function(e){r.isDate(e)?e=e.toISOString():r.isObject(e)&&(e=JSON.stringify(e)),s.push(o(t)+"="+o(e))})))})),i=s.join("&")}if(i){var a=e.indexOf("#");-1!==a&&(e=e.slice(0,a)),e+=(-1===e.indexOf("?")?"?":"&")+i}return e}},function(e,t,n){"use strict";e.exports={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t){t=t||new FormData;var n=[];function o(e){return null===e?"":r.isDate(e)?e.toISOString():r.isArrayBuffer(e)||r.isTypedArray(e)?"function"==typeof Blob?new Blob([e]):Buffer.from(e):e}return function e(i,s){if(r.isPlainObject(i)||r.isArray(i)){if(-1!==n.indexOf(i))throw Error("Circular reference detected in "+s);n.push(i),r.forEach(i,(function(n,i){if(!r.isUndefined(n)){var a,u=s?s+"."+i:i;if(n&&!s&&"object"==typeof n)if(r.endsWith(i,"{}"))n=JSON.stringify(n);else if(r.endsWith(i,"[]")&&(a=r.toArray(n)))return void a.forEach((function(e){!r.isUndefined(e)&&t.append(u,o(e))}));e(n,u)}})),n.pop()}else t.append(s,o(i))}(e),t}},function(e,t,n){"use strict";var r=n(0),o=n(20),i=n(21),s=n(5),a=n(9),u=n(24),c=n(25),f=n(6),l=n(1),p=n(2),d=n(26);e.exports=function(e){return new Promise((function(t,n){var h,m=e.data,v=e.headers,y=e.responseType;function g(){e.cancelToken&&e.cancelToken.unsubscribe(h),e.signal&&e.signal.removeEventListener("abort",h)}r.isFormData(m)&&r.isStandardBrowserEnv()&&delete v["Content-Type"];var E=new XMLHttpRequest;if(e.auth){var b=e.auth.username||"",O=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";v.Authorization="Basic "+btoa(b+":"+O)}var x=a(e.baseURL,e.url);function w(){if(E){var r="getAllResponseHeaders"in E?u(E.getAllResponseHeaders()):null,i={data:y&&"text"!==y&&"json"!==y?E.response:E.responseText,status:E.status,statusText:E.statusText,headers:r,config:e,request:E};o((function(e){t(e),g()}),(function(e){n(e),g()}),i),E=null}}if(E.open(e.method.toUpperCase(),s(x,e.params,e.paramsSerializer),!0),E.timeout=e.timeout,"onloadend"in E?E.onloadend=w:E.onreadystatechange=function(){E&&4===E.readyState&&(0!==E.status||E.responseURL&&0===E.responseURL.indexOf("file:"))&&setTimeout(w)},E.onabort=function(){E&&(n(new l("Request aborted",l.ECONNABORTED,e,E)),E=null)},E.onerror=function(){n(new l("Network Error",l.ERR_NETWORK,e,E,E)),E=null},E.ontimeout=function(){var t=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded",r=e.transitional||f;e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),n(new l(t,r.clarifyTimeoutError?l.ETIMEDOUT:l.ECONNABORTED,e,E)),E=null},r.isStandardBrowserEnv()){var R=(e.withCredentials||c(x))&&e.xsrfCookieName?i.read(e.xsrfCookieName):void 0;R&&(v[e.xsrfHeaderName]=R)}"setRequestHeader"in E&&r.forEach(v,(function(e,t){void 0===m&&"content-type"===t.toLowerCase()?delete v[t]:E.setRequestHeader(t,e)})),r.isUndefined(e.withCredentials)||(E.withCredentials=!!e.withCredentials),y&&"json"!==y&&(E.responseType=e.responseType),"function"==typeof e.onDownloadProgress&&E.addEventListener("progress",e.onDownloadProgress),"function"==typeof e.onUploadProgress&&E.upload&&E.upload.addEventListener("progress",e.onUploadProgress),(e.cancelToken||e.signal)&&(h=function(e){E&&(n(!e||e&&e.type?new p:e),E.abort(),E=null)},e.cancelToken&&e.cancelToken.subscribe(h),e.signal&&(e.signal.aborted?h():e.signal.addEventListener("abort",h))),m||(m=null);var S=d(x);S&&-1===["http","https","file"].indexOf(S)?n(new l("Unsupported protocol "+S+":",l.ERR_BAD_REQUEST,e)):E.send(m)}))}},function(e,t,n){"use strict";var r=n(22),o=n(23);e.exports=function(e,t){return e&&!r(t)?o(e,t):t}},function(e,t,n){"use strict";e.exports=function(e){return!(!e||!e.__CANCEL__)}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t){t=t||{};var n={};function o(e,t){return r.isPlainObject(e)&&r.isPlainObject(t)?r.merge(e,t):r.isPlainObject(t)?r.merge({},t):r.isArray(t)?t.slice():t}function i(n){return r.isUndefined(t[n])?r.isUndefined(e[n])?void 0:o(void 0,e[n]):o(e[n],t[n])}function s(e){if(!r.isUndefined(t[e]))return o(void 0,t[e])}function a(n){return r.isUndefined(t[n])?r.isUndefined(e[n])?void 0:o(void 0,e[n]):o(void 0,t[n])}function u(n){return n in t?o(e[n],t[n]):n in e?o(void 0,e[n]):void 0}var c={url:s,method:s,data:s,baseURL:a,transformRequest:a,transformResponse:a,paramsSerializer:a,timeout:a,timeoutMessage:a,withCredentials:a,adapter:a,responseType:a,xsrfCookieName:a,xsrfHeaderName:a,onUploadProgress:a,onDownloadProgress:a,decompress:a,maxContentLength:a,maxBodyLength:a,beforeRedirect:a,transport:a,httpAgent:a,httpsAgent:a,cancelToken:a,socketPath:a,responseEncoding:a,validateStatus:u};return r.forEach(Object.keys(e).concat(Object.keys(t)),(function(e){var t=c[e]||i,o=t(e);r.isUndefined(o)&&t!==u||(n[e]=o)})),n}},function(e,t){e.exports={version:"0.27.2"}},function(e,t,n){e.exports=n(14)},function(e,t,n){"use strict";var r=n(0),o=n(4),i=n(15),s=n(11);var a=function e(t){var n=new i(t),a=o(i.prototype.request,n);return r.extend(a,i.prototype,n),r.extend(a,n),a.create=function(n){return e(s(t,n))},a}(n(3));a.Axios=i,a.CanceledError=n(2),a.CancelToken=n(29),a.isCancel=n(10),a.VERSION=n(12).version,a.toFormData=n(7),a.AxiosError=n(1),a.Cancel=a.CanceledError,a.all=function(e){return Promise.all(e)},a.spread=n(30),a.isAxiosError=n(31),e.exports=a,e.exports.default=a},function(e,t,n){"use strict";var r=n(0),o=n(5),i=n(16),s=n(17),a=n(11),u=n(9),c=n(28),f=c.validators;function l(e){this.defaults=e,this.interceptors={request:new i,response:new i}}l.prototype.request=function(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},(t=a(this.defaults,t)).method?t.method=t.method.toLowerCase():this.defaults.method?t.method=this.defaults.method.toLowerCase():t.method="get";var n=t.transitional;void 0!==n&&c.assertOptions(n,{silentJSONParsing:f.transitional(f.boolean),forcedJSONParsing:f.transitional(f.boolean),clarifyTimeoutError:f.transitional(f.boolean)},!1);var r=[],o=!0;this.interceptors.request.forEach((function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(o=o&&e.synchronous,r.unshift(e.fulfilled,e.rejected))}));var i,u=[];if(this.interceptors.response.forEach((function(e){u.push(e.fulfilled,e.rejected)})),!o){var l=[s,void 0];for(Array.prototype.unshift.apply(l,r),l=l.concat(u),i=Promise.resolve(t);l.length;)i=i.then(l.shift(),l.shift());return i}for(var p=t;r.length;){var d=r.shift(),h=r.shift();try{p=d(p)}catch(e){h(e);break}}try{i=s(p)}catch(e){return Promise.reject(e)}for(;u.length;)i=i.then(u.shift(),u.shift());return i},l.prototype.getUri=function(e){e=a(this.defaults,e);var t=u(e.baseURL,e.url);return o(t,e.params,e.paramsSerializer)},r.forEach(["delete","get","head","options"],(function(e){l.prototype[e]=function(t,n){return this.request(a(n||{},{method:e,url:t,data:(n||{}).data}))}})),r.forEach(["post","put","patch"],(function(e){function t(t){return function(n,r,o){return this.request(a(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:r}))}}l.prototype[e]=t(),l.prototype[e+"Form"]=t(!0)})),e.exports=l},function(e,t,n){"use strict";var r=n(0);function o(){this.handlers=[]}o.prototype.use=function(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!n&&n.synchronous,runWhen:n?n.runWhen:null}),this.handlers.length-1},o.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},o.prototype.forEach=function(e){r.forEach(this.handlers,(function(t){null!==t&&e(t)}))},e.exports=o},function(e,t,n){"use strict";var r=n(0),o=n(18),i=n(10),s=n(3),a=n(2);function u(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new a}e.exports=function(e){return u(e),e.headers=e.headers||{},e.data=o.call(e,e.data,e.headers,e.transformRequest),e.headers=r.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),r.forEach(["delete","get","head","post","put","patch","common"],(function(t){delete e.headers[t]})),(e.adapter||s.adapter)(e).then((function(t){return u(e),t.data=o.call(e,t.data,t.headers,e.transformResponse),t}),(function(t){return i(t)||(u(e),t&&t.response&&(t.response.data=o.call(e,t.response.data,t.response.headers,e.transformResponse))),Promise.reject(t)}))}},function(e,t,n){"use strict";var r=n(0),o=n(3);e.exports=function(e,t,n){var i=this||o;return r.forEach(n,(function(n){e=n.call(i,e,t)})),e}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t){r.forEach(e,(function(n,r){r!==t&&r.toUpperCase()===t.toUpperCase()&&(e[t]=n,delete e[r])}))}},function(e,t,n){"use strict";var r=n(1);e.exports=function(e,t,n){var o=n.config.validateStatus;n.status&&o&&!o(n.status)?t(new r("Request failed with status code "+n.status,[r.ERR_BAD_REQUEST,r.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n)):e(n)}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?{write:function(e,t,n,o,i,s){var a=[];a.push(e+"="+encodeURIComponent(t)),r.isNumber(n)&&a.push("expires="+new Date(n).toGMTString()),r.isString(o)&&a.push("path="+o),r.isString(i)&&a.push("domain="+i),!0===s&&a.push("secure"),document.cookie=a.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}}},function(e,t,n){"use strict";e.exports=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}},function(e,t,n){"use strict";e.exports=function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}},function(e,t,n){"use strict";var r=n(0),o=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"];e.exports=function(e){var t,n,i,s={};return e?(r.forEach(e.split("\n"),(function(e){if(i=e.indexOf(":"),t=r.trim(e.substr(0,i)).toLowerCase(),n=r.trim(e.substr(i+1)),t){if(s[t]&&o.indexOf(t)>=0)return;s[t]="set-cookie"===t?(s[t]?s[t]:[]).concat([n]):s[t]?s[t]+", "+n:n}})),s):s}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?function(){var e,t=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function o(e){var r=e;return t&&(n.setAttribute("href",r),r=n.href),n.setAttribute("href",r),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return e=o(window.location.href),function(t){var n=r.isString(t)?o(t):t;return n.protocol===e.protocol&&n.host===e.host}}():function(){return!0}},function(e,t,n){"use strict";e.exports=function(e){var t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}},function(e,t){e.exports=null},function(e,t,n){"use strict";var r=n(12).version,o=n(1),i={};["object","boolean","number","function","string","symbol"].forEach((function(e,t){i[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}}));var s={};i.transitional=function(e,t,n){function i(e,t){return"[Axios v"+r+"] Transitional option '"+e+"'"+t+(n?". "+n:"")}return function(n,r,a){if(!1===e)throw new o(i(r," has been removed"+(t?" in "+t:"")),o.ERR_DEPRECATED);return t&&!s[r]&&(s[r]=!0,console.warn(i(r," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(n,r,a)}},e.exports={assertOptions:function(e,t,n){if("object"!=typeof e)throw new o("options must be an object",o.ERR_BAD_OPTION_VALUE);for(var r=Object.keys(e),i=r.length;i-- >0;){var s=r[i],a=t[s];if(a){var u=e[s],c=void 0===u||a(u,s,e);if(!0!==c)throw new o("option "+s+" must be "+c,o.ERR_BAD_OPTION_VALUE)}else if(!0!==n)throw new o("Unknown option "+s,o.ERR_BAD_OPTION)}},validators:i}},function(e,t,n){"use strict";var r=n(2);function o(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");var t;this.promise=new Promise((function(e){t=e}));var n=this;this.promise.then((function(e){if(n._listeners){var t,r=n._listeners.length;for(t=0;t<r;t++)n._listeners[t](e);n._listeners=null}})),this.promise.then=function(e){var t,r=new Promise((function(e){n.subscribe(e),t=e})).then(e);return r.cancel=function(){n.unsubscribe(t)},r},e((function(e){n.reason||(n.reason=new r(e),t(n.reason))}))}o.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},o.prototype.subscribe=function(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]},o.prototype.unsubscribe=function(e){if(this._listeners){var t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}},o.source=function(){var e;return{token:new o((function(t){e=t})),cancel:e}},e.exports=o},function(e,t,n){"use strict";e.exports=function(e){return function(t){return e.apply(null,t)}}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e){return r.isObject(e)&&!0===e.isAxiosError}}])})); 3 | //# sourceMappingURL=axios.min.map -------------------------------------------------------------------------------- /updataLog/expression.md: -------------------------------------------------------------------------------- 1 | ## 表达式介绍 2 | 3 | - 参数表达式 4 | - $d 例如 $1 $2 用来接收 参数1 参数2 5 | - $qname 自动替换为 发送者的资料卡昵称 6 | - $mname 自动替换为 发送者的群聊昵称 获取失败则不替换 7 | - $gname 自动替换为 群名 8 | - $gid 自动替换为 群id 9 | - $qid 自动替换为 发送者qq 10 | - $all 将请求的所有数据当做参数返回 仅用于 输出参数(outArgs) 11 | - $url 将请求的网址当做参数返回 应用于重定向时 仅用于 输出参数(outArgs) 12 | - $number 自动替换为消息中所有数字拼接的字符串 13 | 14 | 15 | - 输出格式表达 16 | - \<Pic:$> 表示为一个图片资源 $ 可为网络地址 本地路径 17 | - 特殊的 当 输入参数为 用JSON表达的数组时 将转化为 forward (转发) 消息 即将数组中每个元素都加载为图片资源并合并转发 18 | - \<At:$> 表示为一个At $ 仅为qq号 否则失败 19 | - \<Face:$> 表示为一个QQ face $仅为face id 20 | - \<Audio:$> 表示为一个语音 $ 可为网络地址 本地路径 21 | - \<Music:$1,$2,$3,$4,$5,$6> 特殊表达 22 | - $1 仅为 MusicKind 枚举中值 23 | - NeteaseCloudMusic 24 | - QQMusic 25 | - MiguMusic 26 | - KugouMusic 27 | - KuwoMusic 28 | - $2 消息卡片标题 29 | - $3 消息卡片内容 30 | - $4 点击卡片跳转网页 URL 31 | - $5 消息卡片图片 URL 32 | - $6 音乐文件 URL 33 | 34 | [高级表达式1](./v2.8.md) 35 | 36 | 部分应用请参考[配置文件](../conf/callApi/conf.json) -------------------------------------------------------------------------------- /updataLog/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gdpl2112/MiraiCallApiPlugin/6bde5cb3d89212851fadad5f2c273133af41ab71/updataLog/img.png -------------------------------------------------------------------------------- /updataLog/v1.5.md: -------------------------------------------------------------------------------- 1 | ## V 1.5 2 | 3 | 此次更新了为插件更新了代理配置 4 | 5 | ```json 6 | 7 | { 8 | "permType": "all", 9 | "splitChar": " ", 10 | //模板全局代理IP 11 | "proxyIp": "localhost", 12 | //模板全局代理port 13 | "proxyPort": 20032, 14 | "templates": [ 15 | { 16 | "out": "<Pic:$1>", 17 | "outArgs": [ 18 | "pic" 19 | ], 20 | "touch": "涩图", 21 | "url": "http://iw233.fgimax2.fgnwctvip.com/API/Ghs.php?type=json", 22 | "err": "涩图调用失败", 23 | //模板局部代理IP 优于 全局 24 | "proxyIp": "localhost", 25 | //模板局部代理prot 优于 全局 26 | "proxyPort": 20032 27 | }, 28 | { 29 | "out": "$1", 30 | "outArgs": [ 31 | "data" 32 | ], 33 | "touch": "星座运势", 34 | "url": "https://api.iyk0.com/xzys/?msg=$1" 35 | }, 36 | { 37 | "out": "<At:$qid>\n$1:$2\n$3:$4\n$5:$6\n", 38 | "outArgs": [ 39 | "data.forecast[0].date", 40 | "data.forecast[0].type", 41 | "data.forecast[1].date", 42 | "data.forecast[1].type", 43 | "data.forecast[2].date", 44 | "data.forecast[2].type" 45 | ], 46 | "touch": "未来天气", 47 | "url": "https://api.vvhan.com/api/weather?city=$1&type=week", 48 | "err": "天气查询失败" 49 | }, 50 | { 51 | "out": "<Audio:$1>", 52 | "outArgs": [ 53 | "mp3" 54 | ], 55 | "touch": "小妲己", 56 | "url": "http://api.weijieyue.cn/api/xiaodaji/api.php?msg=$1" 57 | }, 58 | { 59 | "out": "QQ:$1\n评语:$2\n凶吉:$3\n性格:$4", 60 | "outArgs": [ 61 | "qq", 62 | "pingyu", 63 | "xiongji", 64 | "xingge" 65 | ], 66 | "touch": "QQ凶吉", 67 | "url": "http://api.weijieyue.cn/api/qq/xiongji.php?qq=$qid" 68 | }, 69 | { 70 | "out": "<Pic:$1>", 71 | "outArgs": [ 72 | "pic[0]" 73 | ], 74 | "touch": "随机图片", 75 | "url": "http://api.iw233.cn/api.php?sort=cat&type=json" 76 | } 77 | ] 78 | } 79 | 80 | ``` -------------------------------------------------------------------------------- /updataLog/v1.6.md: -------------------------------------------------------------------------------- 1 | ## V 1.6 2 | 3 | 此次更新 修复局部代理的问题 4 | 5 | 新增参数 $all 示例 6 | 7 | 且仅用于返回参数 8 | 9 | ```json 10 | 11 | { 12 | "permType": "all", 13 | "splitChar": " ", 14 | "templates": [ 15 | { 16 | "out": "$1", 17 | "outArgs": [ 18 | "$all" 19 | ], 20 | "touch": "我在人间凑数的日子", 21 | "url": "https://api.iyk0.com/renjian/" 22 | } 23 | ] 24 | } 25 | 26 | ``` -------------------------------------------------------------------------------- /updataLog/v1.7.md: -------------------------------------------------------------------------------- 1 | ## V 1.7 2 | 3 | 此次更新 移除了图片缓存 4 | 5 | 新增参数 $url 示例 6 | 7 | 即当前(重定向后)的地址作为参数 8 | 9 | 且仅用于返回参数 10 | 11 | ```json 12 | 13 | { 14 | "permType": "all", 15 | "splitChar": " ", 16 | "templates": [ 17 | { 18 | "out": "<Pic:$1>", 19 | "outArgs": [ 20 | "$url" 21 | ], 22 | "touch": "需要我吗", 23 | "url": "https://ovooa.com/API/face_need/?QQ=$qid" 24 | } 25 | ] 26 | } 27 | 28 | ``` -------------------------------------------------------------------------------- /updataLog/v1.8.md: -------------------------------------------------------------------------------- 1 | ## V 1.8 2 | 3 | 此次更新 添加了网页管理界面 且采用了同样的密码设置 4 | 5 | ![img.png](img.png) 6 | 7 | 新增参数 $number 示例 8 | 9 | 即消息中 所有数字作为参数 10 | 11 | 且仅用于输入参数 12 | 13 | 触发 可用 14 | 15 | 需要ta吗 @xx 16 | 17 | ```json 18 | 19 | { 20 | "permType": "all", 21 | "splitChar": " ", 22 | "templates": [ 23 | { 24 | "out": "<Pic:$1>", 25 | "outArgs": [ 26 | "$url" 27 | ], 28 | "touch": "需要ta吗", 29 | "url": "https://ovooa.com/API/face_need/?QQ=$number" 30 | } 31 | ] 32 | } 33 | 34 | ``` -------------------------------------------------------------------------------- /updataLog/v2.4.md: -------------------------------------------------------------------------------- 1 | ## V 2.4 2 | 3 | 新增了API开关命令 4 | 5 | /callApi switch <触发词> # 开关某一API 6 | 7 | 此次更新 支持了 音乐格式 转发 格式的发送 8 | 9 | 完美继承了 [MiraiLsys](https://github.com/Kloping/MiraiLsys) 10 | 子插件 11 | 12 | - Lsys-GetPic 13 | - Lsys-GetSong 14 | - Lsys-PicParser 15 | 16 | [详情见](https://github.com/gdpl2112/MiraiCallApiPlugin/blob/master/conf/callApi/conf.json#L89) 17 | 18 | ```json 19 | 20 | [ 21 | { 22 | "err": "调用失败", 23 | "out": "<Pic:$1>", 24 | "outArgs": [ 25 | //新表达格式 <Pic:$1> 即将其数组所有转为图片并以转发格式发出 26 | "[]" 27 | ], 28 | "proxyIp": "", 29 | "proxyPort": 0, 30 | "sw": true, 31 | "touch": "快手图集", 32 | "url": "http://kloping.top/api/search/parseImgs?url=$1&type=ks" 33 | }, 34 | { 35 | "err": "调用失败", 36 | "out": "<Pic:$1>", 37 | "outArgs": [ 38 | //与上大体相同 39 | "data.[]" 40 | ], 41 | "proxyIp": "", 42 | "proxyPort": 0, 43 | "sw": true, 44 | "touch": "堆糖搜图", 45 | "url": "http://kloping.top/api/search/pic?keyword=$1&num=3&type=duit" 46 | }, 47 | { 48 | "err": "调用失败", 49 | //新表达方式输出为音乐格式 下同 50 | "out": "<Music:KugouMusic,$1,$2,https://www.kugou.com/,$3,$4>", 51 | "outArgs": [ 52 | "data[0].media_name", 53 | "data[0].author_name", 54 | "data[0].imgUrl", 55 | "data[0].songUrl" 56 | ], 57 | "proxyIp": "", 58 | "proxyPort": 0, 59 | "sw": true, 60 | "touch": "酷狗点歌", 61 | "url": "http://kloping.top/api/search/song?keyword=$1&type=kugou&n=2" 62 | }, 63 | { 64 | "err": "调用失败", 65 | "out": "<Music:QQMusic,$1,$2,https://y.qq.com/,$3,$4>", 66 | "outArgs": [ 67 | "data[0].media_name", 68 | "data[0].author_name", 69 | "data[0].imgUrl", 70 | "data[0].songUrl" 71 | ], 72 | "proxyIp": "", 73 | "proxyPort": 0, 74 | "sw": true, 75 | "touch": "QQ点歌", 76 | "url": "http://kloping.top/api/search/song?keyword=$1&type=qq&n=2" 77 | }, 78 | { 79 | "err": "调用失败", 80 | "out": "<Music:NeteaseCloudMusic,$1,$2,https://music.163.com/,$3,$4>", 81 | "outArgs": [ 82 | "data[0].media_name", 83 | "data[0].author_name", 84 | "data[0].imgUrl", 85 | "data[0].songUrl" 86 | ], 87 | "proxyIp": "", 88 | "proxyPort": 0, 89 | "sw": true, 90 | "touch": "网易点歌", 91 | "url": "http://kloping.top/api/search/song?keyword=$1&type=wy&n=2" 92 | } 93 | ] 94 | 95 | ``` -------------------------------------------------------------------------------- /updataLog/v2.8.md: -------------------------------------------------------------------------------- 1 | # V 2.8 2 | 3 | ### 此次更新更新了新高级表达式 4 | 5 | 在地址或输出格式中使用 6 | 7 | $call(url) 或 $call.a.b(url) 8 | 9 | $call(url) 意为 访问url并将返回的值将$call(url)替换 10 | 11 | $call.a.b(url) 意为 访问url并将返回的json以a.b的值将$call.a.b(url)替换 12 | 13 | 应用 14 | 15 | ```json 16 | { 17 | "passwd":"123456", 18 | "permType":"all", 19 | "port":20042, 20 | "proxyIp":null, 21 | "proxyPort":0, 22 | "splitChar":" ", 23 | "templates":[ 24 | { 25 | "err":null, 26 | "out":"id:$1\n来自群$2\n的$3\n时间:$call(http://kloping.top/stamp2time?stamp=$4&time=)\n昵称:$5\n信息:$6\n剩余捡起次数:$7", 27 | "outArgs":["id","gid","sid","time","name","message","state"], 28 | "proxyIp":"", 29 | "proxyPort":0, 30 | "sw":true, 31 | "touch":"/捡瓶子", 32 | "url":"http://kloping.top/api/pickUpBottle" 33 | } 34 | ] 35 | } 36 | ``` 37 | --------------------------------------------------------------------------------