Skip to content

Commit

Permalink
#17 添加文档,新增自响应事件接口,及消息转发主题接口。
Browse files Browse the repository at this point in the history
  • Loading branch information
dydhyhwu committed Sep 6, 2018
1 parent b6e67b2 commit 5e84639
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
17 changes: 17 additions & 0 deletions QQ.Framework/Docs/MessageManage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 接收/回复包

#### 添加一个接收包处理

1. 首先在`Domains/Commands`下对应目录新建Command, 继承`ReceiveCommand<要处理的包类型>`
2. 在新建的Commad上添加`[ReceivePackageCommand(QQCommand.具体你的包名)]`, 这个属性就是包分发的依据,你填写的是什么Command,那么当接收到这个包的时候就会分发给这个类来处理。
3. 构造函数中实例化对应`Packet``QQQEventArgs`
4.`Process`方法中写你的具体逻辑即可。

Tips: 可以参考`Domains/Commands/ReceiveCommands/LoginPingCommand`的写法, 这个是对于Login0x0825包的处理。

#### 添加一个回复包

1. 首先在`Domains/Commands`下对应目录新建Command, 继承`ResponseCommand<要处理的包类型>`
2. 在新建的Commad上添加`[ResponsePacketCommand(QQCommand.具体你的包名)]`, 这个属性就是包分发的依据,你填写的是什么Command,那么当接收到这个包的时候就会分发给这个类来处理。
3. 构造函数中会传入`QQQEventArgs`
4.`Process`方法中写你的具体逻辑即可。
7 changes: 7 additions & 0 deletions QQ.Framework/Docs/add_your_custom_robot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 自定义机器人(非完整版)

1. 新建你的机器人类`YourRoBotClass`, 实现接口`ServerMessageObserver`
2. 构造函数带`ServerMessageSubject`参数, 并在构造函数中添加一行代码`ServerMessageSubject.AddCustomRoBot(this)`
3. 在对应事件实现你想要的功能。

demo待补充, 此处暂未重构完
23 changes: 23 additions & 0 deletions QQ.Framework/Domains/Observers/ServerMessageObserver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace QQ.Framework.Domains.Observers
{
/// <summary>
/// 响应接收到的消息。
/// 可响应的事件均定义在此处,实现个性化机器人需实现此类
/// </summary>
public interface ServerMessageObserver
{
/// <summary>
/// 收到好友消息
/// </summary>
void ReceiveFriendMessage();

/// <summary>
/// 收到群组消息
/// </summary>
void ReceiveGroupMessage();
}
}
36 changes: 36 additions & 0 deletions QQ.Framework/Domains/ServerMessageSubject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text;
using QQ.Framework.Domains.Observers;

namespace QQ.Framework.Domains
{
/// <summary>
/// 服务端主题, 用来转发可处理的消息
/// </summary>
public interface ServerMessageSubject
{
/// <summary>
/// 将自定义机器人加入观察者列表。
/// </summary>
/// <param name="robot"></param>
void AddCustomRoBot(ServerMessageObserver robot);

/// <summary>
/// 将自定义机器人移除观察者列表。
/// 移除后将不能响应收到的信息。
/// </summary>
/// <param name="robot"></param>
void RemoveCustomRoBot(ServerMessageObserver robot);

/// <summary>
/// 收到好友消息
/// </summary>
void ReceiveFriendMessage();

/// <summary>
/// 收到群组消息
/// </summary>
void ReceiveGroupMessage();
}
}
2 changes: 2 additions & 0 deletions QQ.Framework/QQ.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Docs\UMLs\" />
<Folder Include="Domains\Commands\ReceiveCommands\Interactive\" />
<Folder Include="Packets\Models\" />
<Folder Include="Docs\" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ MyUser.cs为本人扩展用户名和密码这里不做上传

源码仅供参考,欢迎吐槽
------------------------------------------
#### 2018-9-6
1. 添加文档
2. 如何添加`Command`[查看](./QQ.Framework/Docs/MessageManage.md)
3. 如何自定义自己的机器人。[查看](./QQ.Framework/Docs/add_your_custom_robot.md)

#### 2018-9-5
1.`Command`提炼为接口, 移除具体`Command`中的重复定义。<br>
2.`Command`处理方法更名为`Process`。<br>
Expand Down

0 comments on commit 5e84639

Please sign in to comment.