├── .gradle
├── 6.1
│ ├── gc.properties
│ ├── fileChanges
│ │ └── last-build.bin
│ ├── fileHashes
│ │ ├── fileHashes.bin
│ │ ├── fileHashes.lock
│ │ └── resourceHashesCache.bin
│ ├── fileContent
│ │ └── fileContent.lock
│ ├── javaCompile
│ │ ├── jarAnalysis.bin
│ │ ├── javaCompile.lock
│ │ ├── taskHistory.bin
│ │ └── classAnalysis.bin
│ └── executionHistory
│ │ ├── executionHistory.bin
│ │ └── executionHistory.lock
├── vcs-1
│ └── gc.properties
├── buildOutputCleanup
│ ├── cache.properties
│ ├── outputFiles.bin
│ └── buildOutputCleanup.lock
└── checksums
│ ├── checksums.lock
│ ├── md5-checksums.bin
│ └── sha1-checksums.bin
├── gradle.properties
├── settings.gradle
├── temp.jpg
├── .idea
├── .gitignore
├── codeStyles
│ ├── codeStyleConfig.xml
│ └── Project.xml
├── compiler.xml
├── vcs.xml
├── misc.xml
├── gradle.xml
├── jarRepositories.xml
└── uiDesigner.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── src
└── main
│ ├── kotlin
│ ├── config
│ │ └── SourceConfig.kt
│ ├── FriendReply.kt
│ ├── utils
│ │ ├── RandomUtils.kt
│ │ ├── JsonUtils.kt
│ │ └── HttpUtils.kt
│ ├── Login.kt
│ ├── modules
│ │ ├── SaucenaoModule.kt
│ │ └── YandereModule.kt
│ ├── RandomPic.kt
│ └── GroupReply.kt
│ └── resources
│ └── example.json
├── .gitignore
├── example.json
├── README.md
├── device.json
├── gradlew.bat
└── gradlew
/.gradle/6.1/gc.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gradle/vcs-1/gc.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gradle/6.1/fileChanges/last-build.bin:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.code.style=official
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'NeoBot'
2 |
3 |
--------------------------------------------------------------------------------
/temp.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/temp.jpg
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.gradle/buildOutputCleanup/cache.properties:
--------------------------------------------------------------------------------
1 | #Thu Jul 09 15:32:11 CST 2020
2 | gradle.version=6.1
3 |
--------------------------------------------------------------------------------
/.gradle/checksums/checksums.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/checksums/checksums.lock
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gradle/checksums/md5-checksums.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/checksums/md5-checksums.bin
--------------------------------------------------------------------------------
/.gradle/6.1/fileHashes/fileHashes.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/6.1/fileHashes/fileHashes.bin
--------------------------------------------------------------------------------
/.gradle/6.1/fileHashes/fileHashes.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/6.1/fileHashes/fileHashes.lock
--------------------------------------------------------------------------------
/.gradle/checksums/sha1-checksums.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/checksums/sha1-checksums.bin
--------------------------------------------------------------------------------
/.gradle/6.1/fileContent/fileContent.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/6.1/fileContent/fileContent.lock
--------------------------------------------------------------------------------
/.gradle/6.1/javaCompile/jarAnalysis.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/6.1/javaCompile/jarAnalysis.bin
--------------------------------------------------------------------------------
/.gradle/6.1/javaCompile/javaCompile.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/6.1/javaCompile/javaCompile.lock
--------------------------------------------------------------------------------
/.gradle/6.1/javaCompile/taskHistory.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/6.1/javaCompile/taskHistory.bin
--------------------------------------------------------------------------------
/.gradle/6.1/javaCompile/classAnalysis.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/6.1/javaCompile/classAnalysis.bin
--------------------------------------------------------------------------------
/.gradle/buildOutputCleanup/outputFiles.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/buildOutputCleanup/outputFiles.bin
--------------------------------------------------------------------------------
/.gradle/6.1/fileHashes/resourceHashesCache.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/6.1/fileHashes/resourceHashesCache.bin
--------------------------------------------------------------------------------
/.gradle/6.1/executionHistory/executionHistory.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/6.1/executionHistory/executionHistory.bin
--------------------------------------------------------------------------------
/.gradle/6.1/executionHistory/executionHistory.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/6.1/executionHistory/executionHistory.lock
--------------------------------------------------------------------------------
/.gradle/buildOutputCleanup/buildOutputCleanup.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyberneurotics/NeoBot/HEAD/.gradle/buildOutputCleanup/buildOutputCleanup.lock
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/kotlin/config/SourceConfig.kt:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | object SourceConfig {
4 | const val SOURCE_YANDERE = "http://yande.re/post.json"
5 | const val SOURCE_KONACHAN = "http://konachan.net/post.json"
6 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jul 09 19:15:49 CST 2020
2 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-all.zip
3 | distributionBase=GRADLE_USER_HOME
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Example user template template
3 | ### Example user template
4 |
5 | # IntelliJ project files
6 | .idea
7 | *.iml
8 | out
9 | .gitignore
10 | .gradle/6.1/vcsMetadata-1/
11 | build/classes/java/
12 | build/generated/
13 | build/kotlin/sessions/
14 | build/tmp/
15 | src/test/
16 | src/main/resources/params.json
17 |
--------------------------------------------------------------------------------
/src/main/kotlin/FriendReply.kt:
--------------------------------------------------------------------------------
1 | import net.mamoe.mirai.message.FriendMessageEvent
2 | import net.mamoe.mirai.message.data.content
3 |
4 | suspend fun friendReply(e:FriendMessageEvent){
5 | val msg = e.message.content
6 |
7 | if(help(e, msg) || updateQA(msg) || checkQA(e) || bullshit(e)){
8 | return
9 | }
10 |
11 | if(getPicSrc(e) || sendPic(e)){
12 | return
13 | }
14 | }
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/main/kotlin/utils/RandomUtils.kt:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import java.util.*
4 |
5 | object RandomUtils {
6 | private val random = Random()
7 |
8 | /**
9 | * 获得一个[0,max)之间的整数。
10 | */
11 | fun getRandomInt(max: Int): Int {
12 | return getRandomInt(0, max)
13 | }
14 |
15 | /**
16 | * 获得一个[min,max)之间的整数。
17 | */
18 | fun getRandomInt(min: Int, max: Int): Int {
19 | return Math.abs(random.nextInt()) % max + min
20 | }
21 | }
--------------------------------------------------------------------------------
/src/main/kotlin/utils/JsonUtils.kt:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import com.alibaba.fastjson.JSON
4 | import com.alibaba.fastjson.JSONObject
5 | import com.alibaba.fastjson.parser.Feature
6 | import java.io.File
7 |
8 |
9 | fun parseJson(path: String) : JSONObject? {
10 | val jsonStr:String = File(path).readText()
11 | val disableDecimalFeature = JSON.DEFAULT_PARSER_FEATURE and Feature.UseBigDecimal.getMask().inv()
12 | val type: Class<*> = JSONObject::class.java
13 | return JSON.parseObject(jsonStr, type, disableDecimalFeature)
14 | }
--------------------------------------------------------------------------------
/example.json:
--------------------------------------------------------------------------------
1 | {
2 | "qqId": 111111,
3 | "password": "111111",
4 |
5 | "proxy": {
6 | "on": true,
7 | "host": "127.0.0.1",
8 | "port": 1080
9 | },
10 |
11 | "getSrc": {
12 | "on": true
13 | },
14 |
15 | "sendPic": {
16 | "on": true,
17 | "recall": {
18 | "on": true,
19 | "millis": 120000
20 | }
21 | },
22 |
23 | "repeat": {
24 | "second": true,
25 | "secondRatio": 0.3,
26 | "third": true,
27 | "thirdRatio": 0.7
28 | },
29 | "replyAt": {
30 | "on": true
31 | },
32 | "qa": {
33 | "on": true
34 | },
35 | "bullshit": {
36 | "on": true,
37 | "defaultWords": 100
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/src/main/resources/example.json:
--------------------------------------------------------------------------------
1 | {
2 | "qqId": 111111,
3 | "password": "111111",
4 |
5 | "proxy": {
6 | "on": true,
7 | "host": "127.0.0.1",
8 | "port": 1080
9 | },
10 |
11 | "getSrc": {
12 | "on": true
13 | },
14 |
15 | "sendPic": {
16 | "on": true,
17 | "recall": {
18 | "on": true,
19 | "millis": 120000
20 | }
21 | },
22 |
23 | "repeat": {
24 | "second": true,
25 | "secondRatio": 0.3,
26 | "third": true,
27 | "thirdRatio": 0.7
28 | },
29 | "replyAt": {
30 | "on": true
31 | },
32 | "qa": {
33 | "on": true
34 | },
35 | "bullshit": {
36 | "on": true,
37 | "defaultWords": 100
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
20 |
21 |
--------------------------------------------------------------------------------
/src/main/kotlin/Login.kt:
--------------------------------------------------------------------------------
1 | import net.mamoe.mirai.Bot
2 | import net.mamoe.mirai.alsoLogin
3 | import net.mamoe.mirai.event.subscribeAlways
4 | import net.mamoe.mirai.join
5 | import net.mamoe.mirai.message.FriendMessageEvent
6 | import net.mamoe.mirai.message.GroupMessageEvent
7 | import utils.parseJson
8 |
9 |
10 | //val qqId = 3250263844L //二号机
11 | //val qqId = 3531714390L //爱酱
12 | //val password = "shiro990805"
13 |
14 | const val jsonPath = "example.json"
15 | var map = parseJson(jsonPath)
16 |
17 | suspend fun main(args: Array) {
18 | val bot = Bot(map?.get("qqId") as Long, map?.get("password") as String){
19 | fileBasedDeviceInfo()
20 | inheritCoroutineContext()
21 | }.alsoLogin()
22 | bot.subscribeAlways { event -> groupReply(event) }
23 | bot.subscribeAlways { event -> friendReply(event) }
24 |
25 | bot.join()
26 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NeoBot
2 | 基于[Mirai](https://github.com/mamoe/mirai) 的QQ机器人,主要功能为发色图(笑)。
3 |
4 | # 功能介绍
5 | 所有功能都在json文件中设置开关与参数
6 | ## 复读
7 | 若群里有两句重复,以一定概率复读。
8 |
9 | ## 回复At
10 | 若群成员@机器人,自动回复
11 |
12 | ## 色图
13 | 匹配如下正则表达式:\\s*[Hh]\\s*([sSqQ])?\\s*(\\d+)?\\s*(aqua)?\\s*(o)?(\\s*([a-zA-Z_!\\?\\(\\)]+))?
14 |
15 | h开头,s/q选择尺度(不填默认s),数字(图片数量),o(是否原图),空格后tag(如final_fantasy)
16 |
17 | e.g. h3, hq10o, hq3 minato_aqua
18 |
19 | 如果怕炸号可以在json文件中选择开启撤回与延迟的时间,每张图片将在发出后指定时间后撤回
20 |
21 | 参考[hentaibot](https://github.com/lywbh/hentai-bot)
22 |
23 | ## 寻找图源
24 | src+[图片]
25 |
26 | 机器人会自动回复图源
27 |
28 | ## QA
29 | 输入 Q问题 A答案 下次输入问题时机器人会自动回复答案
30 |
31 | ## bullshit
32 | 输入 小作文 主题 字数 可以让机器人写一段[生成器](https://github.com/menzi11/BullshitGenerator)生成的狗屁不通的小作文
33 |
34 | # 安装
35 | 1. 安装JDK8+, git clone
36 | 2. 在[example.json](./example.json)中设置QQ号与密码 在[Login.kt](./src/main/kotlin/Login.kt)中设置json地址
37 | 3. 运行[Login.kt](./src/main/kotlin/Login.kt)
38 |
--------------------------------------------------------------------------------
/device.json:
--------------------------------------------------------------------------------
1 | {"display":[77,73,82,65,73,46,54,54,55,57,54,54,46,48,48,49],"product":[109,105,114,97,105],"device":[109,105,114,97,105],"board":[109,105,114,97,105],"brand":[109,97,109,111,101],"model":[109,105,114,97,105],"bootloader":[117,110,107,110,111,119,110],"fingerprint":[109,97,109,111,101,47,109,105,114,97,105,47,109,105,114,97,105,58,49,48,47,77,73,82,65,73,46,50,48,48,49,50,50,46,48,48,49,47,51,48,52,53,48,49,48,58,117,115,101,114,47,114,101,108,101,97,115,101,45,107,101,121,115],"bootId":[65,52,54,49,53,67,66,55,45,52,68,48,66,45,49,68,70,55,45,53,57,48,49,45,54,54,50,56,66,67,51,51,52,56,55,67],"procVersion":[76,105,110,117,120,32,118,101,114,115,105,111,110,32,51,46,48,46,51,49,45,48,73,78,49,53,54,69,56,32,40,97,110,100,114,111,105,100,45,98,117,105,108,100,64,120,120,120,46,120,120,120,46,120,120,120,46,120,120,120,46,99,111,109,41],"baseBand":[],"version":{},"simInfo":[84,45,77,111,98,105,108,101],"osType":[97,110,100,114,111,105,100],"macAddress":[48,50,58,48,48,58,48,48,58,48,48,58,48,48,58,48,48],"wifiBSSID":[48,50,58,48,48,58,48,48,58,48,48,58,48,48,58,48,48],"wifiSSID":[60,117,110,107,110,111,119,110,32,115,115,105,100,62],"imsiMd5":[77,-116,53,-88,-67,51,66,65,39,-111,-125,17,-75,-65,-21,-46],"imei":"608908257368325","apn":[119,105,102,105]}
--------------------------------------------------------------------------------
/src/main/kotlin/modules/SaucenaoModule.kt:
--------------------------------------------------------------------------------
1 | package modules
2 |
3 | import com.alibaba.fastjson.JSON
4 | import utils.HttpUtils.get
5 | import java.io.UnsupportedEncodingException
6 | import java.net.URLEncoder
7 |
8 | class SaucenaoModule {
9 | fun bestMatch(imgUrl: String?): Map {
10 | val result: MutableMap =
11 | HashMap()
12 | if (imgUrl == null || imgUrl.isEmpty()) {
13 | return result
14 | }
15 | var url = baseUrl
16 | url += try {
17 | "?db=999&output_type=2&testmode=1&url=" + URLEncoder.encode(imgUrl, "UTF-8")
18 | } catch (e: UnsupportedEncodingException) {
19 | e.printStackTrace()
20 | return result
21 | }
22 | val response = get(url)
23 | val respJson = JSON.parseObject(response).getJSONArray("results")
24 | if (respJson.isEmpty()) {
25 | return result
26 | }
27 | val dataJson = respJson.getJSONObject(0).getJSONObject("data")
28 | dataJson.forEach { k: String, v: Any? ->
29 | if (v != null) {
30 | val value: String
31 | value = if (v is JSON) {
32 | v.toJSONString()
33 | } else {
34 | v.toString()
35 | }
36 | result[k] = value
37 | }
38 | }
39 | return result
40 | }
41 |
42 | companion object {
43 | private const val baseUrl = "https://saucenao.com/search.php"
44 | }
45 | }
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/main/kotlin/modules/YandereModule.kt:
--------------------------------------------------------------------------------
1 | package modules
2 |
3 | import com.alibaba.fastjson.JSON
4 | import config.SourceConfig
5 | import utils.HttpUtils.get
6 | import utils.RandomUtils
7 | import java.io.IOException
8 | import java.net.URL
9 |
10 | class YandereModule {
11 | enum class Rating {
12 | UNKNOWN, SAFE, QUESTIONABLE, EXPLICIT
13 | }
14 |
15 | fun rating(rating: String): Rating {
16 | var rating = rating
17 | rating = rating.trim { it <= ' ' }
18 | return when (rating) {
19 | "s", "S", "safe" -> Rating.SAFE
20 | "q", "Q", "questionable" -> Rating.QUESTIONABLE
21 | "e", "E", "explicit" -> Rating.EXPLICIT
22 | else -> Rating.UNKNOWN
23 | }
24 | }
25 |
26 | fun randomPic(rating: Rating, orig: Boolean): URL? {
27 | return randomPic(rating, null, orig)
28 | }
29 |
30 | fun randomPic(tags: String?): URL? {
31 | return randomPic(Rating.SAFE, tags, false)
32 | }
33 |
34 | @JvmOverloads
35 | fun randomPic(
36 | rating: Rating = Rating.SAFE,
37 | tags: String? = null,
38 | orig: Boolean = false
39 | ): URL? {
40 | return randomPic(rating, tags, 100, orig)
41 | }
42 |
43 | private fun randomPic(
44 | rating: Rating,
45 | tags: String?,
46 | bound: Int,
47 | orig: Boolean
48 | ): URL? {
49 | var rating = rating
50 | var tags = tags
51 | if (bound == 0) {
52 | return null
53 | }
54 | if (rating == Rating.UNKNOWN) {
55 | rating = Rating.SAFE
56 | }
57 | if (tags == null) {
58 | tags = ""
59 | }
60 | val page = RandomUtils.getRandomInt(bound) + 1
61 | val url =
62 | SourceConfig.SOURCE_YANDERE + "?limit=100&page=" + page + "&tags=" + tags + "%20rating:" + rating.name.toLowerCase()
63 | val response = get(url) ?: return null
64 | //String response = null;
65 | // try {
66 | // response = Jsoup.connect(url).proxy("127.0.0.1", 1080).ignoreContentType(true).get().html();
67 | // } catch (IOException e) {
68 | // e.printStackTrace();
69 | // }
70 | val respArray = JSON.parseArray(response)
71 | if (respArray == null || respArray.isEmpty()) {
72 | return randomPic(rating, tags, bound / 2, orig)
73 | }
74 | val rc = RandomUtils.getRandomInt(respArray.size)
75 | val respJson = respArray.getJSONObject(rc)
76 | return try {
77 | val key = if (orig) "file_url" else "sample_url"
78 | URL(respJson.getString(key))
79 | //return new CQImage(respJson.getString(key));
80 | } catch (e: IOException) {
81 | e.printStackTrace()
82 | null
83 | }
84 | }
85 | }
--------------------------------------------------------------------------------
/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 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
34 |
35 | @rem Find java.exe
36 | if defined JAVA_HOME goto findJavaFromJavaHome
37 |
38 | set JAVA_EXE=java.exe
39 | %JAVA_EXE% -version >NUL 2>&1
40 | if "%ERRORLEVEL%" == "0" goto init
41 |
42 | echo.
43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
44 | echo.
45 | echo Please set the JAVA_HOME variable in your environment to match the
46 | echo location of your Java installation.
47 |
48 | goto fail
49 |
50 | :findJavaFromJavaHome
51 | set JAVA_HOME=%JAVA_HOME:"=%
52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
53 |
54 | if exist "%JAVA_EXE%" goto init
55 |
56 | echo.
57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
58 | echo.
59 | echo Please set the JAVA_HOME variable in your environment to match the
60 | echo location of your Java installation.
61 |
62 | goto fail
63 |
64 | :init
65 | @rem Get command-line arguments, handling Windows variants
66 |
67 | if not "%OS%" == "Windows_NT" goto win9xME_args
68 |
69 | :win9xME_args
70 | @rem Slurp the command line arguments.
71 | set CMD_LINE_ARGS=
72 | set _SKIP=2
73 |
74 | :win9xME_args_slurp
75 | if "x%~1" == "x" goto execute
76 |
77 | set CMD_LINE_ARGS=%*
78 |
79 | :execute
80 | @rem Setup the command line
81 |
82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
83 |
84 | @rem Execute Gradle
85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
86 |
87 | :end
88 | @rem End local scope for the variables with windows NT shell
89 | if "%ERRORLEVEL%"=="0" goto mainEnd
90 |
91 | :fail
92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
93 | rem the _cmd.exe /c_ return code!
94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
95 | exit /b 1
96 |
97 | :mainEnd
98 | if "%OS%"=="Windows_NT" endlocal
99 |
100 | :omega
101 |
--------------------------------------------------------------------------------
/src/main/kotlin/utils/HttpUtils.kt:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import com.alibaba.fastjson.JSONObject
4 | import map
5 | import org.apache.commons.io.FileUtils
6 | import org.apache.http.HttpHost
7 | import org.apache.http.HttpStatus
8 | import org.apache.http.client.config.RequestConfig
9 | import org.apache.http.client.methods.CloseableHttpResponse
10 | import org.apache.http.client.methods.HttpGet
11 | import org.apache.http.impl.client.HttpClients
12 | import org.apache.http.util.EntityUtils
13 | import java.io.BufferedReader
14 | import java.io.File
15 | import java.io.IOException
16 | import java.io.InputStreamReader
17 | import java.net.HttpURLConnection
18 | import java.net.InetSocketAddress
19 | import java.net.Proxy
20 | import java.net.URL
21 |
22 | object HttpUtils {
23 | ///private static final CloseableHttpClient httpClient = HttpClientBuilder.create().build();
24 | private val proxy = map?.get("proxy") as JSONObject
25 | private val httpClient = if(proxy["on"] as Boolean) HttpClients.custom().setDefaultRequestConfig(
26 | RequestConfig.custom().setProxy(
27 | HttpHost(proxy["host"] as String, proxy["port"] as Int, "http")
28 | )
29 | .build()
30 | ).build() else HttpClients.custom().build()
31 |
32 | operator fun get(url: String?): String? {
33 | var httpResponse: CloseableHttpResponse? = null
34 | return try {
35 | httpResponse = httpClient.execute(HttpGet(url))
36 | EntityUtils.toString(httpResponse.entity)
37 | } catch (e: IOException) {
38 | e.printStackTrace()
39 | null
40 | } finally {
41 | if (httpResponse != null) {
42 | try {
43 | httpResponse.close()
44 | } catch (e: IOException) {
45 | e.printStackTrace()
46 | }
47 | }
48 | }
49 | }
50 |
51 | fun httpGet(str: String?): String? {
52 | try {
53 | val url = URL(str)
54 | val proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress("127.0.0.1", 1080))
55 | val conn = url.openConnection(proxy) as HttpURLConnection
56 | conn.requestMethod = "GET"
57 | conn.connect()
58 | val responseCode = conn.responseCode
59 | println("GET Response Code :: $responseCode")
60 | if (responseCode == HttpURLConnection.HTTP_OK) { // success
61 | val `in` = BufferedReader(
62 | InputStreamReader(
63 | conn.inputStream
64 | )
65 | )
66 | var inputLine: String?
67 | val response = StringBuffer()
68 | while (`in`.readLine().also { inputLine = it } != null) {
69 | response.append(inputLine)
70 | }
71 | `in`.close()
72 |
73 | // print result
74 | println(response.toString())
75 | return response.toString()
76 | } else {
77 | println("GET request not worked")
78 | }
79 | } catch (e: IOException) {
80 | e.printStackTrace()
81 | }
82 | return null
83 | }
84 |
85 | fun httpGetImg(imgUrl: String, savePath: String?) {
86 | // 发送get请求
87 | val request = HttpGet(imgUrl)
88 | // lateinit var requestConfig: RequestConfig
89 | val requestConfig = if(((map?.get("proxy") as JSONObject)["on"] as Boolean)){
90 | val host = HttpHost(proxy["host"] as String, proxy["port"] as Int)
91 | RequestConfig.custom()
92 | .setSocketTimeout(60000).setConnectTimeout(60000).setProxy(host).build()
93 | }else{
94 | RequestConfig.custom()
95 | .setSocketTimeout(60000).setConnectTimeout(60000).build()
96 | }
97 |
98 | //设置请求头
99 | request.setHeader(
100 | "User-Agent",
101 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.79 Safari/537.1"
102 | )
103 | request.config = requestConfig
104 | try {
105 | val response = httpClient.execute(request)
106 | if (HttpStatus.SC_OK == response.statusLine.statusCode) {
107 | val entity = response.entity
108 | val `in` = entity.content
109 | FileUtils.copyInputStreamToFile(`in`, File(savePath))
110 | println("下载图片成功:$imgUrl")
111 | }
112 | } catch (e: IOException) {
113 | e.printStackTrace()
114 | throw RuntimeException(e)
115 | } finally {
116 | request.releaseConnection()
117 | }
118 | }
119 | }
--------------------------------------------------------------------------------
/src/main/kotlin/RandomPic.kt:
--------------------------------------------------------------------------------
1 | import com.alibaba.fastjson.JSON
2 | import com.alibaba.fastjson.JSONObject
3 | import kotlinx.coroutines.GlobalScope
4 | import kotlinx.coroutines.delay
5 | import kotlinx.coroutines.launch
6 | import modules.SaucenaoModule
7 | import modules.YandereModule
8 | import net.mamoe.mirai.contact.Contact
9 | import net.mamoe.mirai.message.GroupMessageEvent
10 | import net.mamoe.mirai.message.MessageEvent
11 | import net.mamoe.mirai.message.MessageReceipt
12 | import net.mamoe.mirai.message.data.Image
13 | import net.mamoe.mirai.message.data.content
14 | import net.mamoe.mirai.message.data.queryUrl
15 | import net.mamoe.mirai.message.recall
16 | import utils.HttpUtils
17 | import java.io.File
18 | import java.io.IOException
19 | import java.net.URL
20 | import java.util.*
21 | import java.util.regex.Pattern
22 | import kotlin.collections.ArrayList
23 | import kotlin.collections.HashSet
24 |
25 | private val INVALID = arrayOf("u")
26 | private val groupPattern =
27 | Pattern.compile("\\s*[Hh]\\s*([sSqQ])?\\s*(\\d+)?\\s*(aqua)?\\s*(o)?(\\s*([a-zA-Z_!\\?\\(\\)]+))?")
28 | private val friendPattern =
29 | Pattern.compile("\\s*[Hh]\\s*([sSqQeE])?\\s*(\\d+)?\\s*(aqua)?\\s*(o)?(\\s*([a-zA-Z_!\\?\\(\\)]+))?")
30 |
31 | fun splitMsg(str: String?, pattern: Pattern): Array? {
32 | if (str == null) {
33 | return INVALID
34 | }
35 | val m = pattern.matcher(str)
36 | return if (m.matches()) {
37 | val s1 = if (m.group(1) == null) "" else m.group(1)
38 | val s2 = if (m.group(2) == null) "" else m.group(2)
39 | val s3 = if (m.group(3) == null) "" else m.group(3)
40 | val s4 = if (m.group(4) == null) "" else m.group(4)
41 | val s5 = if (m.group(5) == null) "" else m.group(5).replace("\\s".toRegex(), "")
42 | arrayOf(s1, s2, s3, s4, s5)
43 | } else {
44 | INVALID
45 | }
46 | }
47 |
48 | suspend fun getPicSrc(e: MessageEvent): Boolean {
49 | if(((map?.get("getSrc") as JSONObject)["on"] as Boolean).not()){
50 | return false;
51 | }
52 | if (e.message.content.startsWith("src")) {
53 | val img = e.message[Image] ?: return false
54 | val imgUrl = img.queryUrl()
55 | val saucenaoModule = SaucenaoModule()
56 | val bestMatch: Map = saucenaoModule.bestMatch(imgUrl)
57 | if (bestMatch.isNotEmpty()) {
58 | val sb = StringBuilder()
59 | bestMatch.forEach { (k: String?, v: String?) ->
60 | sb.append(
61 | k
62 | ).append(" --> ").append(v).append("\n")
63 | }
64 | e.reply(sb.toString())
65 | } else {
66 | e.reply("无匹配源")
67 | }
68 | return true
69 | }
70 | return false
71 | }
72 |
73 | suspend fun sendPic(e: MessageEvent): Boolean {
74 | if(((map?.get("sendPic") as JSONObject)["on"] as Boolean).not()){
75 | return false;
76 | }
77 | val msg = e.message.content
78 | val yandereModule = YandereModule()
79 | val rating: YandereModule.Rating
80 | val picNums: Int
81 | val aqua: Boolean
82 | val orig: Boolean
83 | val tag: String
84 | val msgs = splitMsg(msg, if(e is GroupMessageEvent) groupPattern else friendPattern)
85 | if (msgs != null && msgs.contentEquals(INVALID)) {
86 | return false
87 | }
88 | rating = if (msgs!![0].isEmpty()) yandereModule.rating("s") else yandereModule.rating(msgs[0])
89 | picNums = if (msgs[1].isEmpty()) 1 else msgs[1].toInt().coerceAtMost(10)
90 | aqua = msgs[2].isNotEmpty()
91 | orig = msgs[3].isNotEmpty()
92 | tag = msgs[4]
93 |
94 | var imgUrl : URL?
95 | val hashSet = HashSet()
96 | var sent = false
97 | val recall = (map?.get("sendPic") as JSONObject)["recall"] as JSONObject
98 | val receipts = ArrayList>()
99 | val queue: Queue> = LinkedList()
100 |
101 | for (i in 0 until picNums) {
102 | imgUrl = when {
103 | aqua -> {
104 | yandereModule.randomPic(rating, "minato_aqua", orig)
105 | }
106 | tag.isNotEmpty() -> {
107 | yandereModule.randomPic(rating, tag, orig)
108 | }
109 | else -> {
110 | yandereModule.randomPic(rating, orig)
111 | }
112 | }
113 | if(imgUrl == null){
114 | continue
115 | }
116 | if (!hashSet.contains(imgUrl.toString())) {
117 | hashSet.add(imgUrl.toString())
118 | try {
119 | val fileName = "temp.jpg"
120 | HttpUtils.httpGetImg(imgUrl.toString(), fileName)
121 | val r = e.sendImage(File(fileName))
122 | //receipts.add(r)
123 | //queue.add(r)
124 | if((recall["on"] as Boolean) && rating != YandereModule.Rating.SAFE){
125 | GlobalScope.launch {
126 | delay((recall["millis"] as Number).toLong())
127 | r.recall()
128 | }
129 | }
130 |
131 | sent = true
132 | } catch (e: IOException) {
133 | e.printStackTrace()
134 | //recallPics(receipts, rating)
135 | return sent
136 | }
137 | }
138 | }
139 | //recallPics(receipts, rating)
140 | return sent
141 | }
142 |
143 | suspend fun recallPics(receipts: ArrayList>, rating:YandereModule.Rating){
144 | val recall = (map?.get("sendPic") as JSONObject)["recall"] as JSONObject
145 | if((recall["on"] as Boolean).not()) return
146 | if(receipts.isNotEmpty() && rating != YandereModule.Rating.SAFE){
147 | Thread.sleep((recall["millis"] as Number).toLong())
148 | for(r in receipts){
149 | r.recall()
150 | }
151 | }
152 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or 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 UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 | # Determine the Java command to use to start the JVM.
86 | if [ -n "$JAVA_HOME" ] ; then
87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
88 | # IBM's JDK on AIX uses strange locations for the executables
89 | JAVACMD="$JAVA_HOME/jre/sh/java"
90 | else
91 | JAVACMD="$JAVA_HOME/bin/java"
92 | fi
93 | if [ ! -x "$JAVACMD" ] ; then
94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
95 |
96 | Please set the JAVA_HOME variable in your environment to match the
97 | location of your Java installation."
98 | fi
99 | else
100 | JAVACMD="java"
101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
102 |
103 | Please set the JAVA_HOME variable in your environment to match the
104 | location of your Java installation."
105 | fi
106 |
107 | # Increase the maximum file descriptors if we can.
108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
109 | MAX_FD_LIMIT=`ulimit -H -n`
110 | if [ $? -eq 0 ] ; then
111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
112 | MAX_FD="$MAX_FD_LIMIT"
113 | fi
114 | ulimit -n $MAX_FD
115 | if [ $? -ne 0 ] ; then
116 | warn "Could not set maximum file descriptor limit: $MAX_FD"
117 | fi
118 | else
119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
120 | fi
121 | fi
122 |
123 | # For Darwin, add options to specify how the application appears in the dock
124 | if $darwin; then
125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126 | fi
127 |
128 | # For Cygwin or MSYS, switch paths to Windows format before running java
129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132 | JAVACMD=`cygpath --unix "$JAVACMD"`
133 |
134 | # We build the pattern for arguments to be converted via cygpath
135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
136 | SEP=""
137 | for dir in $ROOTDIRSRAW ; do
138 | ROOTDIRS="$ROOTDIRS$SEP$dir"
139 | SEP="|"
140 | done
141 | OURCYGPATTERN="(^($ROOTDIRS))"
142 | # Add a user-defined pattern to the cygpath arguments
143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
145 | fi
146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
147 | i=0
148 | for arg in "$@" ; do
149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
151 |
152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
154 | else
155 | eval `echo args$i`="\"$arg\""
156 | fi
157 | i=`expr $i + 1`
158 | done
159 | case $i in
160 | 0) set -- ;;
161 | 1) set -- "$args0" ;;
162 | 2) set -- "$args0" "$args1" ;;
163 | 3) set -- "$args0" "$args1" "$args2" ;;
164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
170 | esac
171 | fi
172 |
173 | # Escape application args
174 | save () {
175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176 | echo " "
177 | }
178 | APP_ARGS=`save "$@"`
179 |
180 | # Collect all arguments for the java command, following the shell quoting and substitution rules
181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
182 |
183 | exec "$JAVACMD" "$@"
184 |
--------------------------------------------------------------------------------
/src/main/kotlin/GroupReply.kt:
--------------------------------------------------------------------------------
1 |
2 | import com.alibaba.fastjson.JSON
3 | import com.alibaba.fastjson.JSONObject
4 | import net.mamoe.mirai.contact.Member
5 | import net.mamoe.mirai.message.GroupMessageEvent
6 | import net.mamoe.mirai.message.MessageEvent
7 | import net.mamoe.mirai.message.data.*
8 | import utils.parseJson
9 | import java.io.BufferedReader
10 | import java.io.IOException
11 | import java.io.InputStreamReader
12 | import java.util.*
13 | import java.util.regex.Matcher
14 | import java.util.regex.Pattern
15 |
16 | suspend fun groupReply(e:GroupMessageEvent){
17 | map = parseJson(jsonPath)
18 | val msg = e.message.content
19 |
20 | if(help(e, msg) || updateQA(msg) || checkQA(e) || bullshit(e)){
21 | return
22 | }
23 |
24 | if(getPicSrc(e) || sendPic(e)){
25 | return
26 | }
27 |
28 |
29 | if(replyAt(e) || repeatThird(e) || replySecond(e)){
30 | return
31 | }
32 |
33 | }
34 |
35 |
36 | var atReply = arrayOf(
37 | "爬", "外币外币", "外币巴伯", "阿巴阿巴", "?", "¿",
38 | "泥嚎,我很可爱,请亏我全"
39 | )
40 | var repeat = arrayOf("买", "冲", "上号", "🐂")
41 |
42 | suspend fun pic(e:MessageEvent):Boolean{
43 | if(e.message.content.startsWith("pic")){
44 | //val chain = "{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.mirai".parseMiraiCode()
45 | val img = Image("{657740CB-B1E7-3CAB-676A-AD51A3D96D59}.mirai")
46 | img.sendTo(e.subject)
47 | return true
48 | }
49 | return false
50 | }
51 |
52 | suspend fun replyAt(e:MessageEvent): Boolean {
53 | if(((map?.get("replyAt") as JSONObject)["on"] as Boolean).not()){
54 | return false;
55 | }
56 | val at : At = e.message[At] ?: return false
57 | if(at.target == e.bot.selfQQ.id){
58 | e.reply(At(e.sender as Member) + atReply.random())
59 | return true
60 | }
61 | return false
62 | }
63 |
64 | suspend fun replySecond(e: GroupMessageEvent): Boolean{
65 | if(((map?.get("repeat") as JSONObject)["second"] as Boolean).not()){
66 | return false;
67 | }
68 | val ratio = ((map?.get("repeat") as JSONObject)["secondRatio"]) as Double
69 |
70 | val msg = e.message.content
71 | for (str in repeat) {
72 | if (msg.startsWith(str)) {
73 | if (Math.random() < ratio) {
74 | e.reply(str)
75 | return true
76 | }
77 | }
78 | }
79 | return false
80 | }
81 |
82 | fun sameMessage(m1: MessageChain, m2:MessageChain):Boolean{
83 | if(m1.size == 1 || m2.size == 1 || m1.size != m2.size) return false
84 | for(i in 1 until m1.size){
85 | if(m1[i].toString() != m2[i].toString()){
86 | return false
87 | }
88 | }
89 | return true
90 | }
91 |
92 |
93 | var strMap = HashMap()
94 | suspend fun repeatThird(e: GroupMessageEvent): Boolean {
95 | if(((map?.get("repeat") as JSONObject)["third"] as Boolean).not()){
96 | return false
97 | }
98 | val repeat = (map?.get("repeat") as JSONObject)
99 | val ratio = ((map?.get("repeat") as JSONObject)["thirdRatio"]) as Double
100 |
101 | val group = e.group.id
102 | val content = e.message.content
103 | return if (strMap.containsKey(group)) {
104 | val msgChn = strMap[group] ?: return false
105 |
106 | if (sameMessage(e.message, msgChn) && Math.random() < ratio) {
107 | e.reply(msgChn)
108 | strMap.remove(group)
109 | true
110 | } else {
111 | strMap.remove(group)
112 | strMap[group] = e.message
113 | false
114 | }
115 | } else {
116 | strMap[group] = e.message
117 | false
118 | }
119 | }
120 |
121 | suspend fun help(e:MessageEvent, msg: String): Boolean {
122 | if (msg == "help") {
123 | e.reply(
124 | """
125 | 私发色图:h[s/q][number][o] [tag]
126 | p.s []都为可选项 s=safe, q=questionable, number=数量,最大为10, o=原图, tag=搜索标签,如'final_fantasy'
127 | Q问题 A回答 即可让机器人以后自动回答
128 | 小作文 主题 字数 写出某一主题某一字数的小作文 如"小作文 害怕 100" 不加数字默认100字
129 | """.trimIndent()
130 | )
131 | return true
132 | }
133 | return false
134 | }
135 |
136 | var qaPattern = Pattern.compile("[Qq](.+)\\s+[Aa](.+)")
137 | var QA = HashMap()
138 |
139 | fun updateQA(msg: String?): Boolean {
140 | if (msg == null || ((map?.get("qa") as JSONObject)["on"] as Boolean).not()) {
141 | return false
142 | }
143 | val m: Matcher = qaPattern.matcher(msg)
144 | if (m.matches()) {
145 | val q = m.group(1)
146 | val a = m.group(2)
147 | QA.put(q, a)
148 | return true
149 | }
150 | return false
151 | }
152 |
153 | suspend fun checkQA(e:MessageEvent): Boolean {
154 | if(((map?.get("replyAt") as JSONObject)["on"] as Boolean).not()){
155 | return false
156 | }
157 |
158 | val msg = e.message.content
159 | if (QA.containsKey(msg)) {
160 | QA[msg]?.let { e.reply(it) }
161 | return true
162 | }
163 | return false
164 | }
165 |
166 | suspend fun bullshit(e:MessageEvent): Boolean {
167 | if(((map?.get("bullshit") as JSONObject)["on"] as Boolean).not()){
168 | return false
169 | }
170 | val msg = e.message.content
171 | if (msg.startsWith("小作文") || msg.startsWith("作文")) {
172 | val strs = msg.split(" ").toTypedArray()
173 | if (strs.size <= 1) {
174 | return false
175 | }
176 |
177 | //String res = HttpUtils.get("https://suulnnka.github.io/BullshitGenerator/index.html?%E4%B8%BB%E9%A2%98=%E5%AD%A6%E7%94%9F%E4%BC%9A%E9%80%80%E4%BC%9A&%E9%9A%8F%E6%9C%BA%E7%A7%8D%E5%AD%90=2002859472") ;
178 | val theme = strs[1]
179 | val words = if (strs.size >= 3 && strs[2].toIntOrNull() != null) strs[2] else "100"
180 | if (theme == null || theme.isEmpty()) {
181 | return false
182 | }
183 | val command =
184 | "cmd /c python C:\\Users\\shiro\\IdeaProjects\\hentai-bot\\bs\\bs.py $theme C:\\Users\\shiro\\IdeaProjects\\hentai-bot\\bs\\data.json $words"
185 | var p: Process? = null
186 | try {
187 | p = Runtime.getRuntime().exec(command)
188 | p.waitFor()
189 | val bri = BufferedReader(InputStreamReader(p.inputStream, "GB2312"))
190 | var line: String?
191 | val sb = StringBuilder()
192 | while (bri.readLine().also { line = it } != null) {
193 | sb.append(line)
194 | println(line)
195 | }
196 | bri.close()
197 | p.waitFor()
198 | println("Done.")
199 |
200 | e.reply(sb.toString())
201 | p.destroy()
202 | return true
203 | } catch (e: IOException) {
204 | e.printStackTrace()
205 | } catch (e: InterruptedException) {
206 | e.printStackTrace()
207 | }
208 | }
209 | return false
210 | }
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------