文章目录

  • 建议结合新版教程看
  • 写在前面的的话
    • 免责声明
    • 你需要提前会的东西
    • 我们要使用的框架
  • 首先我们先下载一个Demo
    • 文件配置
      • Demo里面的的目录结构
      • 在配置文件中加上你小号的QQ名字和密码
  • 我们加完mybatis之后的目录结构
    • maven里面的配置
    • 为了防止SQL注入问题我们用德鲁伊连接池
    • mybatis配置文件
    • 建立数据库
    • Mybatis的映射文件
    • Mybatis的mapper层
    • mybatis的增删改查
      • pojo层
    • 工具类
      • 机器人的Talk(根据关键词从数据里面查询 如果查询到了就返回数据)
      • 机器人的Study学习功能
      • 机器人的删除功能
    • 使用工具的模块类All_method
    • 这位更是重量级---- MyGropListen 群聊天监听
    • 一切的开始---启动类
  • 首次登陆的时候出现滑动验证的问题咋办
    • 第一次的时候会弹出来一个弹窗
  • 机器人效果
  • 上传到Linux服务器 并且运行

建议结合新版教程看

https://blog.csdn.net/qq_47431361/article/details/127365789

写在前面的的话

这是一个非常简单的聊天机器人的教程
本来我是不想写的(因为我是懒狗)
但是我在网上找不到类似的教程所以就自己打算写一个
这个机器人我只完成了最简单的功能

  • 学习
  • 根据关键词来产生回复
  • 复读
    还有很多其他的功能可以开发 但是因为我是懒狗所以我打算让我可爱的学弟去进行开发

    如果你发现你的机器人群聊只能发送短字符并且机器人的私聊功能没有问题
    那么你的机器人是被腾讯给风控了
    这是正常的
    解决方法是 你自己上机器人的QQ号多水群就行了
    过一段时间风控就被解除了

免责声明

我不是大佬 我的水平也很低
里面实现的功能也是非常简单的功能(复杂的我也不会)
我从开始做到做完也就花了两天时间 对这个框架的很多功能也不是很了解
我的很多功能也是用很多的方法来实现的
如果你有更好的方法希望你也能写一篇教程让我也学习一下

你需要提前会的东西

  • 最基本的MySQL
  • 一点点Linux的使用经验
  • 最简单的Mybatis的使用
  • 一点点使用Spring这种框架的经验(不会也没什么问题)

我们要使用的框架

我希望你在看这篇教程之前先提前看一下教学视频 起码看一下二十多分钟的
<<稍微短一点的视频>>
这个是框架的地址里面已经包含的有教程
框架地址
这里是写框架的老哥录的教学视频 可以说是非常详细了
这里是链接地址
如果你懒得看这个长的 起码你得看一下这个教学视频
稍微短一点的视频
这里面所提供的资料足够你自己完成一个机器人的开发了
但是这篇文章是面向纯纯的小白的所以会更加详细一点

首先我们先下载一个Demo

在教学视频里面已经嗦了Demo在哪下 为了避免小白找不到Demo在哪下我直接把这个Demo的下载链接贴到这里了

Demo地址

文件配置

Demo里面的的目录结构


视频里面已经对监听器里面的功能已经嗦的很明白了
而且demo里面已经打了很多很多的注释去解释功能了 你们看一下就知道怎么用了

在配置文件中加上你小号的QQ名字和密码


为了避免不必要的问题我建议你

在这两个文件里面都配置好
因为我实在不知道还有什么能嗦的所以我下面会讲怎么用Mybatis

我们加完mybatis之后的目录结构


maven里面的配置

因为要用一点新的东西 所以要在
这个里面加一点点东西
因为我是懒狗所以我就不细嗦了
我直接把我的maven配置给放在这里了

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>simbot.example</groupId><artifactId>simbot-mirai-demo</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><simbot.version>2.3.4</simbot.version></properties><dependencies><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.10</version></dependency><!-- Mybatis核心 --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.7</version></dependency><!-- junit测试 --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.0.5.RELEASE</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webflux</artifactId><version>2.3.11.RELEASE</version></dependency><!-- MySql --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version></dependency><!-- 连接池 --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.0.11</version></dependency><!--简化bean代码的工具包--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional><version>1.18.20</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.6.4</version></dependency><!-- mybatis-plus插件依赖 --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus</artifactId><version>3.1.1</version></dependency><!-- 使用 mirai 组件。 --><dependency><groupId>love.forte.simple-robot</groupId><artifactId>component-mirai</artifactId><version>${simbot.version}</version><!--vv--></dependency><!-- 定时任务模块 --><dependency><groupId>love.forte.simple-robot.time-task</groupId><artifactId>time-task-quartz</artifactId><version>${simbot.version}</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.75</version><scope>test</scope></dependency></dependencies><build><resources><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.yml</include><include>**/*.xml</include><include>**/*.tld</include><include>**/*.**</include></includes><filtering>false</filtering></resource><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.yml</include><include>**/*.xml</include><include>**/*.tld</include></includes><filtering>false</filtering></resource></resources><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>2.5.3</version><configuration><!-- main方法所在类。 --><mainClass>love.simbot.example.SimbotExampleApplication</mainClass></configuration><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></project>

为了防止SQL注入问题我们用德鲁伊连接池


我们整一个druid文件夹 创建一个MyDruid

package love.simbot.example.druid;import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.ibatis.datasource.DataSourceFactory;
import org.apache.ibatis.datasource.pooled.PooledDataSourceFactory;import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Properties;public class MyDruid  implements DataSourceFactory {private Properties props;@Overridepublic DataSource getDataSource() {DruidDataSource dds = new DruidDataSource();dds.setDriverClassName(this.props.getProperty("driver"));dds.setUrl(this.props.getProperty("url"));dds.setUsername(this.props.getProperty("username"));dds.setPassword(this.props.getProperty("password"));try {dds.init();} catch (SQLException e) {e.printStackTrace();}return dds;}@Overridepublic void setProperties(Properties props) {this.props = props;}}

mybatis配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><environments default="development"><!-- mybatis的配置环境 --><environment id="development"><!-- 事物管理配置 --><transactionManager type="JDBC" /><!-- 数据源的选择 --><dataSource type="love.simbot.example.druid.MyDruid"><!-- 数据库链接的配置 --><property name="com.mysql.jdbc.Driver"/><property name="url"value="jdbc:mysql://你数据库地址:3306/你的库名?characterEncoding=utf-8&amp;createDatabaseIfNotExist=true&amp;useSSL=false"/><property name="username" value="你数据库的名字"/><property name="password" value="你数据库的密码"/></dataSource></environment></environments><!--引入映射文件--><mappers><mapper resource="mybatis/KVmapper.xml"/></mappers></configuration>

建立数据库



建立表这个就没什么值得细嗦的了
实在不会建表就直接右键建就完事了

Mybatis的映射文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="love.simbot.example.mybatis.mapper.Key_Value_Mapper"><insert id="insertKV">insert into kv values(NULL,#{key},#{value});</insert><delete id="deleteKV">delete  from kv where id=#{id}</delete><select id="get_One_KV_ByKey" resultType="love.simbot.example.mybatis.pojo.Key_Value">SELECT * FROM kv WHERE `key`=#{key}</select><select id="get_Some_KV_ByKey" resultType="love.simbot.example.mybatis.pojo.Key_Value">SELECT * FROM kv WHERE `key`=#{key}</select></mapper>

Mybatis的mapper层

package love.simbot.example.mybatis.mapper;import love.simbot.example.mybatis.pojo.Key_Value;
import org.apache.ibatis.annotations.Param;import java.util.ArrayList;public interface  Key_Value_Mapper  {int insertKV(@Param("key")String key,@Param("value")String value);Key_Value get_One_KV_ByKey(@Param("key")String key);ArrayList<Key_Value> get_Some_KV_ByKey(@Param("key")String key);int deleteKV(@Param("id")int id);}

mybatis的增删改查

因为我是懒狗(主要原因) 而且我感觉没什么写改的必要 所以我没写改的方法

pojo层

package love.simbot.example.mybatis.pojo;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("Key_Value")
public class Key_Value {@TableId(type = IdType.AUTO)private int id;private String key;public String value;}

工具类

机器人的Talk(根据关键词从数据里面查询 如果查询到了就返回数据)

这个Talk是根据机器人对于群聊监听获得的字符串然后跟数据库里面的key进行匹配
如果匹配到了就返回匹配到的value
如果匹配到了多个key就随机返回一个value
比如说数据库里面有这样的k v
k1 v1
k1 v2
如果接收到了k1 他会从数据库里面拿到两个字符串 v1 v2
然后随机返回一个String类型

package love.simbot.example.mybatis.controller;import love.simbot.example.mybatis.mapper.Key_Value_Mapper;
import love.simbot.example.mybatis.pojo.Key_Value;import java.io.IOException;
import java.util.ArrayList;public class Talk {Key_Value_Mapper userMapper;public Talk( Key_Value_Mapper userMapper) {this.userMapper=userMapper;}public String QQbot_Talk(String key) throws IOException {ArrayList<Key_Value> some_kv_byKey = userMapper.get_Some_KV_ByKey(key);int size = some_kv_byKey.size();if (size ==0){return "0";}else if(size ==1){Key_Value key_value = some_kv_byKey.get(size-1);return key_value.getValue();}else {final double d = Math.random();final int i = (int)(d*size);Key_Value key_value = some_kv_byKey.get(i);return key_value.getValue();}}
}

机器人的Study学习功能

package love.simbot.example.mybatis.controller;import love.simbot.example.mybatis.mapper.Key_Value_Mapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;import java.io.IOException;
import java.io.InputStream;public class Study  {Key_Value_Mapper userMapper=null;public Study(Key_Value_Mapper userMapper) {this.userMapper = userMapper;}public String QQbot_Study(String key, String value) throws IOException {int i = userMapper.insertKV(key, value);if (i ==0){return "学习失败";}else {return "学习完毕";}}}

机器人的删除功能

因为我是懒狗 所以虽然做了删除功能的模块但是我没有装到机器人里面

package love.simbot.example.mybatis.controller;import love.simbot.example.mybatis.mapper.Key_Value_Mapper;
import love.simbot.example.mybatis.pojo.Key_Value;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;public class Delete_Study {Key_Value_Mapper key_value_mapper=null;public Delete_Study(Key_Value_Mapper key_value_mapper) {this.key_value_mapper = key_value_mapper;}public ArrayList<Key_Value> QQbot_Delete_What_you_want(String key) throws IOException {ArrayList<Key_Value> some_kv_byKey = key_value_mapper.get_Some_KV_ByKey(key);return some_kv_byKey;
}public String QQbot_Delete_By_Id(int id){int i = key_value_mapper.deleteKV(id);return  "id为:"+String.valueOf(i)+"的信息已经被删除力";}}

使用工具的模块类All_method

这里面有一个检测是否是url的一个方法 本来我打算做一个talk检测图片然后如果是图片的话就发送图片 但是这个功能完成了一半我就没往下面写了
如果问为什么的话
答案只有一个
那就是我是懒狗

package love.simbot.example.mybatis.controller;import love.simbot.example.mybatis.mapper.Key_Value_Mapper;
import love.simbot.example.mybatis.pojo.Key_Value;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class All_method {InputStream is = Resources.getResourceAsStream("mybatis-config.xml");//创建SqlSessionFactoryBuilder对象SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();//通过核心配置文件所对应的字节输入流创建工厂类SqlSessionFactory,生产SqlSession对象SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(is);//创建SqlSession对象,此时通过SqlSession对象所操作的sql都必须手动提交或回滚事务
//SqlSession sqlSession = sqlSessionFactory.openSession();
//创建SqlSession对象,此时通过SqlSession对象所操作的sql都会自动提交SqlSession sqlSession = sqlSessionFactory.openSession(true);//通过代理模式创建UserMapper接口的代理实现类对象Key_Value_Mapper userMapper = sqlSession.getMapper(Key_Value_Mapper.class);public All_method() throws IOException {}
//调用UserMapper接口中的方法,就可以根据UserMapper的全类名匹配元素文件,通过调用的方法名匹配public String study(String key,String value) throws IOException {Study study = new Study(userMapper);return study.QQbot_Study(key, value);}public ArrayList<Key_Value> select_By_key(String key){ArrayList<Key_Value> some_kv_byKey = userMapper.get_Some_KV_ByKey(key);return some_kv_byKey;}public String talk(String key) throws IOException {Talk talk = new Talk(userMapper);return talk.QQbot_Talk(key);}public String delete_By_Id(int id){Delete_Study delete_study = new Delete_Study(userMapper);return delete_study.QQbot_Delete_By_Id(id);}public static boolean isUrl(String urls) {String regex = "(ht|f)tp(s?)\\:\\/\\/[0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\.\\?\\,\\'\\/\\\\&%\\+\\$#_=]*)?";Pattern pat = Pattern.compile(regex);Matcher mat = pat.matcher(urls.trim());boolean result = mat.matches();return result;}}

这位更是重量级---- MyGropListen 群聊天监听

package love.simbot.example.listener;import catcode.CatCodeUtil;
import catcode.Neko;
import love.forte.common.ioc.annotation.Beans;
import love.forte.simbot.annotation.Filter;
import love.forte.simbot.annotation.OnGroup;
import love.forte.simbot.annotation.OnPrivate;
import love.forte.simbot.api.message.MessageContent;
import love.forte.simbot.api.message.containers.GroupAccountInfo;
import love.forte.simbot.api.message.containers.GroupInfo;
import love.forte.simbot.api.message.events.GroupMsg;
import love.forte.simbot.api.message.events.PrivateMsg;
import love.forte.simbot.api.sender.MsgSender;
import love.forte.simbot.api.sender.Sender;
import love.forte.simbot.filter.MatchType;
import love.simbot.example.mybatis.controller.All_method;
import love.simbot.example.mybatis.pojo.Key_Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import java.io.IOException;
import java.util.ArrayList;
import java.util.List;/*** 群消息监听的示例类。* 所有需要被管理的类都需要标注 {@link Beans} 注解。* @author ForteScarlet*/
@Beans
public class MyGroupListen {final static String IMG="图片的url地址";private  All_method all_method;{try {all_method = new All_method();} catch (IOException e) {e.printStackTrace();}}/** log */private static final Logger LOG = LoggerFactory.getLogger(MyGroupListen.class);/*** 此监听函数代表,收到消息的时候,将消息的各种信息打印出来。** 此处使用的是模板注解 {@link OnGroup}, 其代表监听一个群消息。** 由于你监听的是一个群消息,因此你可以通过 {@link GroupMsg} 作为参数来接收群消息内容。** <p>* 注意! 假如你发现你群消息发不出去(或者只有一些很短的消息能发出去)且没有任何报错,* 但是尝试后,发现 <b>私聊</b> 一切正常,能够发送,那么这是 <b>正常现象</b>!** 参考:**/@OnGrouppublic void onGroupMsg(GroupMsg groupMsg,MsgSender sender) {// 打印此次消息中的 纯文本消息内容。// 纯文本消息中,不会包含任何特殊消息(例如图片、表情等)。System.out.println(groupMsg.getText());String text = groupMsg.getText();String talk;try {talk = all_method.talk(text);boolean url = all_method.isUrl(talk);System.out.println("触发了查询关键词"+talk);System.out.println("".equals(talk)==false);System.out.println("0".equals(talk)==false);if (url){if ("".equals(talk)==false&&"0".equals(talk)==false) {CatCodeUtil util = CatCodeUtil.INSTANCE;String img = util.getStringTemplate().image(IMG);sender.SENDER.sendGroupMsg(groupMsg, "图片" + talk);}}else {String t=talk;if ("".equals(talk)==false&&"0".equals(talk)==false){sender.SENDER.sendGroupMsg(groupMsg,t);}}} catch (IOException e) {System.out.println("未找到关键词");}// 打印此次消息中的 消息内容。// 消息内容会包含所有的消息内容,也包括特殊消息。特殊消息使用CAT码进行表示。// 需要注意的是,绝大多数情况下,getMsg() 的效率低于甚至远低于 getText()System.out.println(groupMsg.getMsg());// 获取此次消息中的 消息主体。// messageContent代表消息主体,其中通过可以获得 msg, 以及特殊消息列表。// 特殊消息列表为 List<Neko>, 其中,Neko是CAT码的封装类型。MessageContent msgContent = groupMsg.getMsgContent();// 打印消息主体System.out.println(msgContent);// 打印消息主体中的所有图片的链接(如果有的话)List<Neko> imageCats = msgContent.getCats("image");System.out.println("img counts: " + imageCats.size());for (Neko image : imageCats) {System.out.println("Img url: " + image.get("url"));}// 获取发消息的人。GroupAccountInfo accountInfo = groupMsg.getAccountInfo();// 打印发消息者的账号与昵称。System.out.println(accountInfo.getAccountCode());System.out.println(accountInfo.getAccountNickname());// 获取群信息GroupInfo groupInfo = groupMsg.getGroupInfo();// 打印群号与名称System.out.println(groupInfo.getGroupCode());System.out.println(groupInfo.getGroupName());}@OnGroup@Filter(value="nana学习",trim=true,matchType = MatchType.CONTAINS)public void study(GroupMsg groupMsg, MsgSender sender) {String text = groupMsg.getText();String[] split = text.split("\\s+");String key=split[1];String value=split[2];System.out.println("图片是"+value);MessageContent msgContent = groupMsg.getMsgContent();List<Neko> imageCats = msgContent.getCats("image");System.out.println("img counts: " + imageCats.size());//        for (Neko image : imageCats) {//            System.out.println("Img url: " + image.get("url"));
//        }
//        if (imageCats!=null){//            for (Neko imageCat : imageCats) {//                try {//                    all_method.study(key,imageCat.get("url"));
//                } catch (IOException e) {//                    sender.SENDER.sendGroupMsg(groupMsg,"图片学习出问题 ");
//                    e.printStackTrace();
//                }
//                sender.SENDER.sendGroupMsg(groupMsg,"图片学习完成");
//            }
//        }else{try {all_method.study(key,value);} catch (IOException e){sender.SENDER.sendGroupMsg(groupMsg,"学习出问题 ");e.printStackTrace();}sender.SENDER.sendGroupMsg(groupMsg,"学习完成");// sender.SENDER.sendGroupMsg(groupMsg,groupMsg.getMsgContent());
//        }}@OnGroup@Filter(value="hi",trim=true,matchType = MatchType.CONTAINS)public void hello(GroupMsg groupMsg, MsgSender sender) {sender.SENDER.sendGroupMsg(groupMsg,"我接收到了hi ");// sender.SENDER.sendGroupMsg(groupMsg,groupMsg.getMsgContent());}@OnGroup@Filter(value="测试复读",trim=true,matchType = MatchType.CONTAINS)public void replyPrivateMsg1(GroupMsg privateMsg,  MsgSender sender) {// 获取消息正文。String text = privateMsg.getText();System.out.println(text);// 向 privateMsg 的账号发送消息,消息为当前接收到的消息。sender.SENDER.sendGroupMsg(privateMsg, text);System.out.println("发送完毕");}final String ac="测试回复";@OnGroup@Filter(value=ac,trim=true,matchType = MatchType.CONTAINS,atBot = true)public void img(GroupMsg privateMsg, MsgSender sender) {CatCodeUtil util= CatCodeUtil.INSTANCE;String img= util.getStringTemplate().image(IMG);sender.SENDER.sendGroupMsg(privateMsg,"图片"+img);}final static String IMG1="https://image.16pic.com/00/53/26/16pic_5326745_s.jpg?imageView2/0/format/png";@OnGroup@Filter(value="图片test",trim=true,matchType = MatchType.CONTAINS)public void Grop_msg(GroupMsg privateMsg, MsgSender sender) {CatCodeUtil util= CatCodeUtil.INSTANCE;String img= util.getStringTemplate().image(IMG1);sender.SENDER.sendGroupMsg(privateMsg,"图片"+img);}}

一切的开始—启动类

package love.simbot.example;import love.forte.common.configuration.Configuration;
import love.forte.simbot.annotation.SimbotApplication;
import love.forte.simbot.annotation.SimbotResource;
import love.forte.simbot.api.sender.BotSender;
import love.forte.simbot.bot.Bot;
import love.forte.simbot.core.SimbotApp;
import love.forte.simbot.core.SimbotContext;
import love.forte.simbot.core.SimbotProcess;
import org.jetbrains.annotations.NotNull;import java.time.LocalDateTime;/*** simbot 启动类。* <p>* 此处的注解配置了两个配置文件:* <ul>*     <li>simbot.yml</li>*     <li>simbot-dev.yml</li>* </ul>* 其中,{@code simbot-dev.yml} 是一个测试环境的配置文件,只有当启动参数中存在 {@code --Sdev} 的时候才会被使用。* 如果你不需要一些特殊的配置文件,那么可以直接使用 {@code @SimbotApplication}.* <p>* 默认情况下,默认的配置文件名称为 {@code simbot.yml} 或 {@code simbot.properties}** @author ForteScarlet*/
@SimbotApplication({@SimbotResource(value = "simbot.yml", orIgnore = true),@SimbotResource(value = "simbot-dev.yml", orIgnore = true, command = "dev"),
})
// @SimbotApplication
public class SimbotExampleApplication implements SimbotProcess {public static void main(String[] args) {/*run方法的第一个参数是一个标注了@SimbotApplication注解的启动类。第二个参数是main方法得到的启动参数。*/SimbotApp.run(SimbotExampleApplication.class, args);}/**** 启动后*/@Overridepublic void post(@NotNull SimbotContext context) {Bot bot = context.getBotManager().getDefaultBot();BotSender sender = bot.getSender();sender.SENDER.sendPrivateMsg("发送的qq号","已经启动完毕了 当前启动时间是"+ LocalDateTime.now());}/**** 启动前*/@Overridepublic void pre(@NotNull Configuration config) {}
}

你点一下这个小三角机器人就开始运行了

首次登陆的时候出现滑动验证的问题咋办

Github地址

第一次的时候会弹出来一个弹窗

你把弹窗里面的请求码地址放到这里面 然后点击下一步
会出现一个滑动验证码
你滑动之后在看那个弹窗
弹窗里面会有一个四位数的数字
你再把数字给再输进到这里面

然后你再点击下一步就好了 你这个电脑的信息就已经写进一个文件夹里面了
等你打成jar包之后这些信息都会带进去
也就是说你这个jar包以后无论在哪跑腾讯服务器都会认为这个QQ号登陆的就是在你验证的这个电脑上面 也就不用再重复搞这个验证了

机器人效果

登陆成功效果




上传到Linux服务器 并且运行


如何用Java写一个聊天机器人相关推荐

  1. [译] 如何用 Python 写一个 Discord 机器人

    原文地址:How to write a Discord bot in Python 原文作者:Junpei Shimotsu 译文出自:掘金翻译计划 本文永久链接:github.com/xitu/go ...

  2. 如何用Java写一个斗地主(一)

    如何用Java写一个斗地主(一) 序言 正文 创建卡牌 打乱牌序 发牌 课后吐槽 序言 作为一名大三的普普通通大学生,被实习老师(?)强迫下,第一次开始写CSDN的博客,如果写的不好,请多多包涵咯. ...

  3. 如何用java写一个年日历

    如何用java写一个年日历 没啥难的,话不多说上代码

  4. c语言编写对答机器人_来,你也可以用 C 语言写一个聊天机器人

    来,你也可以用 C 语言写一个聊天机器人 你是不是一直在面对着枯燥的 C 语言特性.摸索着前人写过的各种算法,不是因为自己的兴趣,而是依靠自身的毅力,学得很苦吧. 好吧,我们找一个好玩一点的东西,一起 ...

  5. 利用itchat写一个聊天机器人

    利用itchat写一个聊天机器人 聊天机器人 图灵机器人 需要的库 **自动回复私聊消息** **自动回复群聊消息** 结语: 聊天机器人 偶然在CSDN上看到大佬用20行教你写一个聊天机器人,觉得甚 ...

  6. python自动聊天机器人设置回复延迟_用Python 写一个聊天机器人陪你聊天(文尾有彩蛋)...

    一.工具简介 1--Python.写代码的工具: 2--itchat库.第三方库,用来登录微信,接收并回复微信好友信息: 3--图灵机器人.第三方接口,我们本次使用的机器人: 二.代码解析 1.准备 ...

  7. C/S架构网络聊天软件——Java Chat Application 用java做一个聊天机器人

    Fighting! 一.C/S概念 1.1 什么是C/S 1.2 C/S与B/S的区别 二.主页面 三.介绍 四.特征 五.jServer 六.jMessenger 七.使用代码 7.1 导入项目后报 ...

  8. 手机java做贪吃蛇_如何用Java写一个贪吃蛇游戏

    这是一位拓胜学员用Java写贪吃蛇游戏的心得:今天课程设计终于结束了自己学java没以前学C+那么用功了觉得我学习在哪里都是个开口向上的抛物线,现在应该在右半边吧,好了进入正题. 写java贪吃蛇也是 ...

  9. 如何用java写一个九九乘法表。

    在java中写一个九九乘法表,我们只需要用一个for循环嵌套就可以了,我们先写一个for循环嵌套格式, for(;;){for(;;) 然后我们知道内循环和外循环所控制行和列,我们可以看出来九九乘法表 ...

最新文章

  1. 京东王笑松:7FRESH是“无界零售”理论的业务践行
  2. 程序员2004下载地址
  3. 【Matlab】绘制3D 3维图
  4. 服务器系统由32位的吗,云服务器有Windows32位系统吗
  5. type python3_详解Python3中的Sequence type的使用
  6. [转] Vuex入门(2)—— state,mapState,...mapState对象展开符详解
  7. httpclient base64 文件上传_文件上传下载
  8. C++实现拓扑排序(vector模拟邻接表存储,栈实现)
  9. datatables 更新选中行 的一行数据
  10. Opencv ORC——文字定位与切割
  11. jvisualvm 工具使用
  12. JavaScript - 360浏览器默认使用极速模式打开网页
  13. [Evolutionary Algorithm] 进化算法简介
  14. 嵌入式Linux驱动笔记(四)------USB键盘驱动程序
  15. [推荐]《人一生要读的60本书》
  16. 设计模式---外观(Facade)模式
  17. 台式计算机屏幕扩展,台式机屏幕如何扩展
  18. 51单片机-PWM调速(直流电机,智能小车的电机调速)
  19. 路演活动平台,怎么报名参加创业路演?
  20. gps wifi信号测试软件,搜星+WiFi+EMI 导航平板信号性能横评

热门文章

  1. 荣耀v6平板怎么升级鸿蒙系统,荣耀平板V6如何进行手机克隆?教你轻松导入重要数据...
  2. linux双显卡配置_Linux系统怎么配置双显卡?,linux配置显卡
  3. JavaScript笔记6(数组,foreach(),slice(),splice(),数组的剩余方法,函数的方法call和apply ,arguments,Date对象,Math,字符串的相关方法)
  4. c语言有参有类最小公倍数,【C语言】写一个函数,并调用该函数求两个整数的最大公约数和最小公倍数...
  5. 图像配准系列之“Sift特征点+薄板样条变换+FFD变换”配准方法
  6. Linux杀死java项目进程
  7. python对文件读写操作
  8. 相册照片不小心删了怎么恢复?恢复秘诀
  9. Python学习六:面向对象编程(上)
  10. Vue生命周期函数是什么?Vue生命周期函数有什么用? ∠( °ω°)/ 前端知识