第一章:基于 SpringBoot 快速搭建QQ机器人,并监听群事件
第一章:基于 SpringBoot 快速搭建QQ机器人
- 前言:知识与储备
- 这个QQ机器人能干什么?
- 第一步:搭建Maven项目环境
- 第二步:编写pom文件
- 第三步:编写启动类
- 第四步:创建配置文件
- 第五步:编写一个监听器并监听群消息
- 第六步:启动项目
- 可能遇到的问题:
- 滑块验证
- 遇到其他问题可加QQ群进行讨论
- 参考文档
前言:知识与储备
根据框架来实现一个QQ机器人、阅读这篇文章你需要Java基础以及SpringBoot(方便快速集成一些框架)和Maven的基础。
详细参考此文档:https://www.yuque.com/simpler-robot/simpler-robot-doc/ehy6dz
这个QQ机器人能干什么?
他可以监听并发送或者回复好友消息和群消息(比如群的禁言、At群成员等等 … )
此框架并没有具体的功能,你需要自己写代码来实现你所需的功能。
第一步:搭建Maven项目环境
然后点击 完成
第二步:编写pom文件
<?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>org.example</groupId><artifactId>springboot-robot</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><spring-framework.version>5.3.16</spring-framework.version><java.version>8</java.version><simbot.version>3.0.0.preview.8.1</simbot.version><simbot-component-tcg.version>3.0.0.0.preview.3.1</simbot-component-tcg.version><simbot-component-mirai.version>3.0.0.0.preview.2.2</simbot-component-mirai.version></properties><!-- Spring Boot 相关。此处选择使用parent对Spring进行版本控制 --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><!-- Spring Boot 版本 --><version>2.6.6</version><relativePath/> <!-- lookup parent from repository --></parent><dependencies><!-- 引入你所需要的Spring Boot依赖。这里假设你需要使用 web 相关功能 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- simbot-spring-boot-starter 库 --><dependency><groupId>love.forte.simbot.boot</groupId><artifactId>simboot-core-spring-boot-starter</artifactId><version>${simbot.version}</version></dependency><!-- 腾讯频道组件 --><dependency><groupId>love.forte.simbot.component</groupId><artifactId>simbot-component-tencent-guild-boot</artifactId><version>${simbot-component-tcg.version}</version></dependency><!-- mirai组件 --><dependency><groupId>love.forte.simbot.component</groupId><artifactId>simbot-component-mirai-boot</artifactId><version>${simbot-component-mirai.version}</version></dependency></dependencies><!-- 或许还需要其他依赖... --><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
第三步:编写启动类
package com.ityifan;import love.forte.simboot.autoconfigure.EnableSimbot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** @author Fan_yoo* @date 2022/6/3*/
@EnableSimbot
@SpringBootApplication
public class SpringBootRoBotApplication {public static void main(String[] args) {SpringApplication.run(SpringBootRoBotApplication.class, args);}
}
目前包结构如下图:
第四步:创建配置文件
第五步:编写一个监听器并监听群消息
package com.ityifan.listener;import love.forte.simboot.annotation.Listener;
import love.forte.simbot.event.GroupMessageEvent;
import org.springframework.stereotype.Component;/*** @author Fan_yoo* @date 2022/6/3*/
@Component
public class GroupListener {/*** 复读群成员消息 你说什么我复读什么* @param event 群事件*/@Listenerpublic void repeat(GroupMessageEvent event){// 获取群成员的消息// getPlainText()为文本消息final String message = event.getMessageContent().getPlainText();//发送消息event.getGroup().sendBlocking(message);}}
目前包结构:
第六步:启动项目
运行启动器的main方法即可
可能遇到的问题:
滑块验证
遇到其他问题可加QQ群进行讨论
QQ交流群连接:
群聊与艺术:https://www.yuque.com/simpler-robot/simpler-robot-doc/xklly8
参考文档
参考文档:https://www.yuque.com/simpler-robot/simpler-robot-doc/xygygt
ityifan 禁止转载
第一章:基于 SpringBoot 快速搭建QQ机器人,并监听群事件相关推荐
- 基于springboot 快速搭建简单前后端分离项目-后台框架
目录 1.新建project 2.选择依赖 3.简单配置 4.数据库准备 5.完成后台逻辑代码 5.1创建java实体对象 5.2创建repository 5.3单元测试 5.4编写controlle ...
- 基于Nonebot2搭建QQ机器人(一)机器人环境配置
目录 一.Nonebot2介绍 二.Nonebot2安装 1.bot.py文件的配置 2..env文件的配置 3.env.dev文件配置 4.env.pord配置 三.go-cqhttp介绍 四.go ...
- Jeecg-Boot 一款基于SpringBoot 快速开发平台
Jeecg-Boot 一款基于SpringBoot 快速开发平台 Jeecg-Boot 是一款基于SpringBoot+代码生成器的快速开发平台!采用前后端分离架构:SpringBoot,Mybati ...
- 基于Mirai框架的QQ机器人使用文档----郑大科协2021招新群
目录 1. 引言 1.1 编写目的 1.2 项目背景 1.3 参考链接 2. 使用说明 2.1 关于插件 2.2 自动功能 2.3 交互功能 2.4 插件链接 3. 出错与恢复 3.1 自动功能出错 ...
- SpringBoot快速搭建
文章目录 SpringBoot快速搭建 @SpringBootApplication @Configuration @EnableAutoConfiguration SpringFactoriesLo ...
- 基于 Jenkins 快速搭建持续集成环境--转
源地址:http://www.ibm.com/developerworks/cn/java/j-lo-jenkins/ 持续集成是一种软件开发实践,对于提高软件开发效率并保障软件开发质量提供了理论基础 ...
- 基于 Jenkins 快速搭建持续集成环境
持续集成概述 什么是持续集成 随着软件开发复杂度的不断提高,团队开发成员间如何更好地协同工作以确保软件开发的质量已经慢慢成为开发过程中不可回避的问题.尤其是近些年来,敏捷(Agile) 在软件工程领域 ...
- 如何基于Docker快速搭建Elasticsearch集群?
如何基于Docker快速搭建Elasticsearch集群? Elasticsearch 作为一个搜索引擎,我们对它的基本要求就是存储海量数据并且可以在非常短的时间内查询到我们想要的信息.所以第一步 ...
- ssm如何支持热部署_IntelliJ IDEA基于SpringBoot如何搭建SSM开发环境
之前给大家在博文中讲过如何通过eclipse快速搭建SSM开发环境,但相对而言还是有些麻烦的,今天小编给大家介绍下如何使用IntelliJ IDEA基于SpringBoot来更快速地搭建SSM开发环境 ...
最新文章
- ls命令显示结果图解
- css3毛玻璃模糊效果
- python multiprocessing lock_python多进程Lock锁
- 51单片机控制步进电机的c语言程序,用AT89C51单片机控制步进电机的汇编源程序...
- 10.10 traceroute:追踪数据传输路由状况
- Matlab 字符串比较
- 写代码三年,月薪不到一万,是不是很失败?
- DPDK报文收发 run to completion, pipeline
- cordova 安装ssl证书_超详细cordova环境配置(windows)及实例
- Video和Audio标签的使用
- CS229 Lecture 1
- 简单无迹kalman的matlab程序,卡尔曼滤波原理及应用——MATLAB仿真
- 澳洲墨尔本大学的计算机专业,墨尔本大学计算机专业排名澳洲第一,申请条件又有变化了!...
- 消费券或可让消费增速超过8%
- OA系统实施:理清OA需求很关键
- 嵌入式常用裸机编程框架
- C++ windy数
- C++中“map和set”相关内容整理分析
- 小米生态链的战投启示
- 大学毕业5年后拉开大家差距的原因