io.uouo.wechat.MyBot Maven / Gradle / Ivy
The newest version!
package io.uouo.wechat;
import io.uouo.wechat.api.annotation.Bind;
import io.uouo.wechat.api.constant.Config;
import io.uouo.wechat.api.enums.AccountType;
import io.uouo.wechat.api.enums.MsgType;
import io.uouo.wechat.api.model.WeChatMessage;
import io.uouo.wechat.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
/**
* 我的小机器人
*
* @author biezhi
* @since 2018/1/19
*/
@Slf4j
public class MyBot extends WeChatBot {
public MyBot(Config config) {
super(config);
}
/**
* 绑定群聊信息
*
* @param message
*/
@Bind(msgType = MsgType.ALL, accountType = AccountType.TYPE_GROUP)
public void groupMessage(WeChatMessage message) {
log.info("接收到群 [{}] 的消息: {}", message.getName(), message.getText());
// this.api().sendText(message.getFromUserName(), "自动回复: " + message.getText());
}
/**
* 绑定私聊消息
*
* @param message
*/
@Bind(msgType = {MsgType.TEXT, MsgType.VIDEO, MsgType.IMAGE, MsgType.EMOTICONS}, accountType = AccountType.TYPE_FRIEND)
public void friendMessage(WeChatMessage message) {
if (StringUtils.isNotEmpty(message.getName())) {
log.info("接收到好友 [{}] 的消息: {}", message.getName(), message.getText());
// this.api().sendText(message.getFromUserName(), "自动回复: " + message.getText());
// this.api().sendFile("战斗型美少女", "/Users/biezhi/Desktop/Hot_Spots_blade2.0.4_alpha1.html");
}
}
/**
* 好友验证消息
*
* @param message
*/
@Bind(msgType = MsgType.ADD_FRIEND)
public void addFriend(WeChatMessage message) {
log.info("收到好友验证消息: {}", message.getText());
if (message.getText().contains("java")) {
// this.api().verify(message.getRaw().getRecommend());
}
}
public static void main(String[] args) {
new MyBot(Config.me().autoLogin(true).showTerminal(true)).start();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy