Skip to content

Commit e4faf5f

Browse files
✨ auto curse
1 parent 8d7387c commit e4faf5f

File tree

8 files changed

+87
-7
lines changed

8 files changed

+87
-7
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
- [x] 自动拉人进群
1212
- [x] 群新增成员监听并发送欢迎语
1313
- [x] 图灵AI自动回复
14-
- [x] 自动同意添加好友
14+
- [x] 根据验证信息自动同意添加好友
15+
- [x] 自动骂人
1516

1617
## Show
1718

@@ -42,6 +43,12 @@ autoReply: # 自动回复配置
4243
- Bot567
4344
prefix: 【~(≧▽≦)~】 # 自动回复小尾巴
4445

46+
autoCurse: # 自动骂人配置
47+
enable: true # 是否启用
48+
fire: false # 是否火力全开, 拉黑必备
49+
nickNames: # 骂人名单
50+
- SomePeple
51+
4552
autoVerify: # 自动添加好友验证
4653
enable: true # 是否启用
4754
passMessage: # 验证信息包含以下列表时自动通过

src/main/java/io/github/biezhi/wechat/MyBot.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package io.github.biezhi.wechat;
22

3+
import io.github.biezhi.wechat.ai.shadiao.ShadiaoApi;
34
import io.github.biezhi.wechat.ai.tuling.Tuling;
45
import io.github.biezhi.wechat.api.annotation.Bind;
56
import io.github.biezhi.wechat.api.constant.Config;
7+
import io.github.biezhi.wechat.api.constant.custom.AutoCurse;
68
import io.github.biezhi.wechat.api.constant.custom.AutoVerify;
79
import io.github.biezhi.wechat.api.constant.custom.LoverPrattle;
810
import io.github.biezhi.wechat.api.enums.AccountType;
@@ -107,6 +109,10 @@ public void friendMessage(WeChatMessage message) {
107109
if (autoReplyLover(message)) {
108110
autoReplyByAI(message);
109111
}
112+
if (autoCurse(message)) {
113+
this.api()
114+
.sendText(message.getFromUserName(), ShadiaoApi.curse(customConfig().getAutoCurse().isFire()));
115+
}
110116
/*if (message.getText().equals("拉我进群")) {
111117
this.api().inviteJoinGroup(message.getFromUserName(), this.config().groupUserName());
112118
}*/
@@ -115,9 +121,14 @@ public void friendMessage(WeChatMessage message) {
115121
}
116122
}
117123

118-
private boolean autoReplyLover(WeChatMessage message) {
119-
return message.getFromUserName().equals(customConfig().getLoverPrattle().getLoverUserName())
120-
&& customConfig().getAutoReply().getEnable();
124+
private boolean autoCurse(WeChatMessage message) {
125+
AutoCurse autoCurse = customConfig().getAutoCurse();
126+
return autoCurse.isEnable() && autoCurse.getUserNameSet().contains(message.getFromUserName());
127+
}
128+
129+
private boolean autoReplyLover(WeChatMessage message) {
130+
return customConfig().getAutoReply().getEnable()
131+
&& message.getFromUserName().equals(customConfig().getLoverPrattle().getLoverUserName());
121132
}
122133

123134
/**
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.github.biezhi.wechat.ai.shadiao;
2+
3+
import okhttp3.Request;
4+
5+
import java.io.IOException;
6+
7+
import static io.github.biezhi.wechat.prattle.PrattleInfoReqUtil.okHttpClient;
8+
9+
/**
10+
* @author ybd
11+
* @date 19-7-9
12+
* @contact yangbingdong1994@gmail.com
13+
*/
14+
public class ShadiaoApi {
15+
16+
/**
17+
* 骂人宝典...
18+
*/
19+
public static String curse(boolean fire) {
20+
try {
21+
Request request = new Request.Builder().url("https://nmsl.shadiao.app/api.php" + (fire ? "" : "?level=min"))
22+
.build();
23+
return okHttpClient.newCall(request).execute().body().string();
24+
} catch (IOException e) {
25+
throw new RuntimeException(e);
26+
}
27+
}
28+
}

src/main/java/io/github/biezhi/wechat/api/WeChatApiImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,16 @@ private void initCustomConfig() {
217217

218218
Set<String> nickNames = customConfig().getAutoReply().getNickNames();
219219
Set<String> userNameSet = customConfig().getAutoReply().getUserNameSet();
220-
for (Account account : groupList) {
220+
Set<String> curseNickNames = customConfig().getAutoCurse().getNickNames();
221+
Set<String> curseUserNameSet = customConfig().getAutoCurse().getUserNameSet();
222+
for (Account account : groupList) {
221223
if (nickNames.contains(account.getNickName())) {
222224
log.info("Auto reply [{}] matched, username: {}", account.getNickName(), account.getUserName());
223225
userNameSet.add(account.getUserName());
224-
break;
225226
}
227+
if (curseNickNames.contains(account.getNickName())) {
228+
curseUserNameSet.add(account.getUserName());
229+
}
226230
}
227231

228232
LoverPrattle loverPrattle = customConfig().getLoverPrattle();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.github.biezhi.wechat.api.constant.custom;
2+
3+
import lombok.Data;
4+
5+
import java.util.HashSet;
6+
import java.util.Set;
7+
8+
/**
9+
* @author ybd
10+
* @date 19-7-9
11+
* @contact yangbingdong1994@gmail.com
12+
*/
13+
@Data
14+
public class AutoCurse {
15+
private boolean enable = false;
16+
17+
private boolean fire = false;
18+
19+
private Set<String> nickNames;
20+
21+
public Set<String> userNameSet = new HashSet<>();
22+
}

src/main/java/io/github/biezhi/wechat/api/constant/custom/CustomConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ public class CustomConfig {
1717
private AutoReply autoReply;
1818

1919
private AutoVerify autoVerify;
20+
21+
private AutoCurse autoCurse;
2022
}

src/main/java/io/github/biezhi/wechat/prattle/PrattleInfoReqUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* @contact yangbingdong1994@gmail.com
2222
*/
2323
public class PrattleInfoReqUtil {
24-
private static OkHttpClient okHttpClient;
24+
public static OkHttpClient okHttpClient;
2525
static {
2626
OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS)
2727
.writeTimeout(30, TimeUnit.SECONDS)

src/main/resources/config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ autoReply:
1414
- Bot567
1515
prefix: 【~(≧▽≦)~】
1616

17+
autoCurse:
18+
enable: false
19+
fire: false
20+
nickNames:
21+
- NoPeple
22+
1723
autoVerify:
1824
enable: true
1925
passMessage:

0 commit comments

Comments
 (0)