├── .gitattributes
├── .github
├── ISSUE_TEMPLATE
│ ├── ------.md
│ └── bug_report.md
├── workflows
│ └── main.yml
└── wiki.svg
├── README.md
├── MeowMiraiLib.sln
├── GlobalDefines
├── BaseDefines.cs
├── Sender.cs
├── MessageUtil.cs
├── GenericModel.cs
├── Message.cs
└── SSM.cs
├── ErrorDefine.cs
├── MeowMiraiLib.csproj
├── .editorconfig
├── Global.cs
├── CODE_OF_CONDUCT.md
├── .gitignore
├── ExtendedContextParser
└── EParser.cs
├── Client
├── Client.cs
└── ClientEvent.cs
└── LICENSE
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/------.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: 错误反馈报告
3 | about: 遇到了什么错误?可以反馈给我们呢喵!
4 | title: "[B]"
5 | labels: 出错啦喵!, 这...不对啊喵!!, 需要帮助呢喵~
6 | assignees: ''
7 |
8 | ---
9 |
10 | **问题描述**
11 | 描述你出现的主要问题
12 |
13 | **复现方案**
14 | 复现问题的详细步骤
15 |
16 | **正确的反馈**
17 | 你所期待的正确的程序反馈(不知道可以留空)
18 |
19 | **屏幕截图(错误截图,异常截图)**
20 | 如果可可以的话,粘在这个位置
21 |
22 | **你的版本**
23 | 操作系统:
24 | SDK版本:
25 |
26 | **其他信息**
27 | 如何联系你,如果事情出现新进展如何通知你?
28 | 我对问题有其他意见?
29 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/MeowMiraiLib.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31903.59
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MeowMiraiLib", "MeowMiraiLib.csproj", "{18157A57-204D-423B-AFEF-5895C6D9AD8C}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2FD9692F-3569-45AC-B858-9B3633FDD704}"
9 | ProjectSection(SolutionItems) = preProject
10 | .editorconfig = .editorconfig
11 | EndProjectSection
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Any CPU = Debug|Any CPU
16 | Release|Any CPU = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {18157A57-204D-423B-AFEF-5895C6D9AD8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {18157A57-204D-423B-AFEF-5895C6D9AD8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {18157A57-204D-423B-AFEF-5895C6D9AD8C}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {18157A57-204D-423B-AFEF-5895C6D9AD8C}.Release|Any CPU.Build.0 = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(SolutionProperties) = preSolution
25 | HideSolutionNode = FALSE
26 | EndGlobalSection
27 | GlobalSection(ExtensibilityGlobals) = postSolution
28 | SolutionGuid = {EBE38894-BDF5-40C3-BE99-278614AACEE9}
29 | EndGlobalSection
30 | EndGlobal
31 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with Actions
2 |
3 | name: CI
4 |
5 | # Controls when the workflow will run
6 | on:
7 | # Triggers the workflow on push or pull request events but only for the main branch
8 | workflow_dispatch:
9 | inputs:
10 | Publish:
11 | required: true
12 | type: boolean
13 |
14 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
15 | jobs:
16 | # This workflow contains a single job called "build"
17 | Build:
18 | # The type of runner that the job will run on
19 | runs-on: ubuntu-latest
20 | if: ${{ github.event.inputs.Publish == 'true' }}
21 |
22 | # Steps represent a sequence of tasks that will be executed as part of the job
23 | steps:
24 | # 1.Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
25 | - uses: actions/checkout@v2
26 | # 2.runtime environment
27 | - name: Setup .NET Core
28 | uses: actions/setup-dotnet@v1
29 | with:
30 | dotnet-version: 6.0.x
31 | # 3.build
32 | - name: Build with dotnet
33 | run: dotnet build --configuration Release
34 | #任务2:测试
35 | - name: Test
36 | run: dotnet test --no-build --verbosity normal
37 | #任务3:发布nuget
38 | - name: Publish
39 | uses: brandedoutcast/publish-nuget@v2.5.2
40 | with:
41 | PROJECT_FILE_PATH: MeowMiraiLib.csproj #确定发布项目名
42 | NUGET_KEY: ${{secrets.NUGET_API_KEY}} #使用专用key
43 |
--------------------------------------------------------------------------------
/GlobalDefines/BaseDefines.cs:
--------------------------------------------------------------------------------
1 | /*本类定义了基类逻辑和新基类操作用法, 实现了一些扩展的基类应用, 本类定义一般为最高类, 使用结构体定义数据集合
2 | * -----
3 | * this file is ussd for Base-Arch Logic and Base-Operation usage,
4 | * which is extension for other meta-type,
5 | * this struct(s) will be define in the up-most classes(namespace),
6 | * also mostly will be `struct-class`
7 | */
8 |
9 | namespace MeowMiraiLib
10 | {
11 | ///
12 | /// 信息返回Id
13 | ///
14 | public struct MessageId
15 | {
16 | ///
17 | /// 信息返回id
18 | ///
19 | ///
20 | ///
21 | public MessageId(long id, Client c)
22 | {
23 | Id = id;
24 | C = c;
25 | }
26 | ///
27 | /// 信息Id
28 | ///
29 | public long Id { get; set; }
30 | ///
31 | /// 信息对应的端
32 | ///
33 | public Client C { get; set; }
34 | ///
35 | /// 撤回这条信息
36 | ///
37 | ///
38 | public readonly bool ReCall() => new Msg.Recall(Id).Send(C) == 0;
39 | ///
40 | /// 延时 x 秒撤回消息
41 | ///
42 | /// 秒钟数
43 | ///
44 | public readonly bool ReCall(int second)
45 | {
46 | System.Threading.Tasks.Task.Delay(1000 * second).GetAwaiter().GetResult();
47 | return ReCall();
48 | }
49 | ///
50 | /// 打印MsgId
51 | ///
52 | ///
53 | public readonly override string ToString() => $"MsgId:{Id}";
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/.github/wiki.svg:
--------------------------------------------------------------------------------
1 |
70 |
--------------------------------------------------------------------------------
/ErrorDefine.cs:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * 本类用来定义错误列表的内容, 错误列表可以在 https://github.com/DavidSciMeow/MeowMiraiLib/wiki/AP.-3-%E9%94%99%E8%AF%AF%E5%88%97%E8%A1%A8 查询
4 | * --------------------------
5 | * this file is mainly for defines the Error String,
6 | * for detail please click https://github.com/DavidSciMeow/MeowMiraiLib/wiki/AP.-3-%E9%94%99%E8%AF%AF%E5%88%97%E8%A1%A8
7 | */
8 |
9 | namespace MeowMiraiLib
10 | {
11 | ///
12 | /// 错误列表
13 | ///
14 | public static class ErrorDefine
15 | {
16 | ///
17 | /// 没有实例化URL(为空)
18 | ///
19 | public const string E0001 = "[0001] InitPhase : No Url Specific.";
20 | ///
21 | /// ECP端已经启动解析方案
22 | ///
23 | public const string E0002 = "[0002] ECPInitPhase : Task Already Start.";
24 | ///
25 | /// 全局端未定义
26 | ///
27 | public const string E0003 = "[0003] ECPInitPhase : Global Client is Null.";
28 |
29 | ///
30 | /// 信息不符合标准要求
31 | ///
32 | public const string E0012 = "[0012] ParserPhase : Message Typo Error in ";
33 | ///
34 | /// 没有符合的信息类型
35 | ///
36 | public const string E0013 = "[0013] ParserPhase : Message Error in ";
37 |
38 | ///
39 | /// 没有最佳的发送选项
40 | ///
41 | public const string E1000 = "[1000] ContextualSender::SendMsgBack Func : SenderId and GroupId isn't Fit.";
42 | ///
43 | /// 上下文消息段数字位置超过队列长度
44 | ///
45 | public const string E1010 = "[1010] ContextualSender::GetPlainMsgAt : Number set is over or less than queue length.";
46 |
47 | ///
48 | /// 全局发送端未定义
49 | ///
50 | public const string E2000 = "[2000] GlobalErr : Global ConClient NotSet.";
51 |
52 | ///
53 | /// ECP端正在使用全局端作为消息接收器
54 | ///
55 | public const string E99999 = "[---1] ECPInitPhase : ECP is Using Global Client As Interpreter Input";
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/MeowMiraiLib.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | annotations
6 | 8.1.2
7 | DavidSciMeow
8 | Electronicute
9 | MeowMiraiLib
10 | Electronicute @2022
11 | https://github.com/DavidSciMeow/MeowMiraiLib
12 | https://github.com/DavidSciMeow/MeowMiraiLib
13 | git
14 | zh
15 | AGPL-3.0-only
16 | True
17 | True
18 |
19 | True
20 | A Csharp - MiraiQQ(HTTPAPI) Backend Development Kit
21 | Electronicute.MeowMiraiLib
22 | portable
23 | True
24 | README.md
25 | False
26 | alter the `Action` in CSMHelper To `Func`
27 | MiraiQQBot, Mirai, QQBot, Tencent, SDK
28 | Electronicute.MeowMiraiLib
29 |
30 |
31 |
32 | 1701;1702;1006;1822;2211
33 |
34 |
35 |
36 | 1701;1702;1006;1822;2211
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | True
53 | \
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*.cs]
2 |
3 | # IDE1006: Naming Styles
4 | dotnet_diagnostic.IDE1006.severity = none
5 |
6 | # CA1822: Mark members as static
7 | dotnet_diagnostic.CA1822.severity = none
8 |
9 | # CA2211: Non-constant fields should not be visible
10 | dotnet_diagnostic.CA2211.severity = none
11 | csharp_indent_labels = one_less_than_current
12 | csharp_using_directive_placement = outside_namespace:silent
13 | csharp_prefer_simple_using_statement = true:suggestion
14 | csharp_prefer_braces = true:silent
15 | csharp_style_namespace_declarations = block_scoped:silent
16 | csharp_style_expression_bodied_methods = false:silent
17 | csharp_style_expression_bodied_constructors = false:silent
18 | csharp_style_expression_bodied_operators = false:silent
19 | csharp_style_expression_bodied_properties = true:silent
20 | csharp_style_expression_bodied_indexers = true:silent
21 | csharp_style_expression_bodied_accessors = true:silent
22 | csharp_style_expression_bodied_lambdas = true:silent
23 | csharp_style_expression_bodied_local_functions = false:silent
24 |
25 | [*.{cs,vb}]
26 | #### Naming styles ####
27 |
28 | # Naming rules
29 |
30 | dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
31 | dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
32 | dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
33 |
34 | dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
35 | dotnet_naming_rule.types_should_be_pascal_case.symbols = types
36 | dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
37 |
38 | dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
39 | dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
40 | dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
41 |
42 | # Symbol specifications
43 |
44 | dotnet_naming_symbols.interface.applicable_kinds = interface
45 | dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
46 | dotnet_naming_symbols.interface.required_modifiers =
47 |
48 | dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
49 | dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
50 | dotnet_naming_symbols.types.required_modifiers =
51 |
52 | dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
53 | dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
54 | dotnet_naming_symbols.non_field_members.required_modifiers =
55 |
56 | # Naming styles
57 |
58 | dotnet_naming_style.begins_with_i.required_prefix = I
59 | dotnet_naming_style.begins_with_i.required_suffix =
60 | dotnet_naming_style.begins_with_i.word_separator =
61 | dotnet_naming_style.begins_with_i.capitalization = pascal_case
62 |
63 | dotnet_naming_style.pascal_case.required_prefix =
64 | dotnet_naming_style.pascal_case.required_suffix =
65 | dotnet_naming_style.pascal_case.word_separator =
66 | dotnet_naming_style.pascal_case.capitalization = pascal_case
67 |
68 | dotnet_naming_style.pascal_case.required_prefix =
69 | dotnet_naming_style.pascal_case.required_suffix =
70 | dotnet_naming_style.pascal_case.word_separator =
71 | dotnet_naming_style.pascal_case.capitalization = pascal_case
72 | dotnet_style_operator_placement_when_wrapping = beginning_of_line
73 | tab_width = 4
74 | indent_size = 4
75 | end_of_line = crlf
76 | dotnet_style_coalesce_expression = true:suggestion
77 | dotnet_style_null_propagation = true:suggestion
78 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
79 | dotnet_style_prefer_auto_properties = true:silent
80 | dotnet_style_object_initializer = true:suggestion
81 | dotnet_style_collection_initializer = true:suggestion
82 | dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
83 | dotnet_style_prefer_conditional_expression_over_assignment = true:silent
84 | dotnet_style_prefer_conditional_expression_over_return = true:silent
85 |
--------------------------------------------------------------------------------
/Global.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | /*
5 | * 版本 8.1.0+ 全局设置,
6 | * 包括单端生成(快速发送接收), 全局日志设置等,
7 | * 本页面的编写原则是全局设置, 如果进行更新或者更改请使用VS Ctrl+R命名方案, 防止更改后相关联函数无法获取参数
8 | * 本类置顶于MML内部类, 并且本类不应含有任何内部调用参数类, 也不应含有任何帮助类.
9 | * 更改前请确认全局均需要使用.
10 | * -------------------------------------------
11 | * Version 8.1.0+ Global Setting Class File
12 | * this file intergated Client Interpolation/Initiation (for quick Send/Recieve), Global Logger Setting, etc.
13 | * when editing this page you'll need to confirm the function need to run as 'GLOBAL',
14 | * as if you're unsatisfact with the name I use, Please using VS-Func Ctrl+R Naming rules for preventing the function-name related errors
15 | * this class is topped as innerclass of MML(MeowMiraiLib) and should not contain class like func-generate-class or helper-class
16 | * AS SURE PLEASE CONFIRM FUNCTION YOU ADD IS GLOBALLY USED.
17 | */
18 |
19 |
20 | namespace MeowMiraiLib
21 | {
22 | ///
23 | /// 日志输出
24 | ///
25 | public enum DebugFlag
26 | {
27 | ///
28 | /// Debug模式
29 | ///
30 | Debug = 4,
31 | ///
32 | /// Info模式
33 | ///
34 | Info = 3,
35 | ///
36 | /// 警告模式
37 | ///
38 | Warn = 2,
39 | ///
40 | /// 错误模式
41 | ///
42 | Error = 1,
43 | ///
44 | /// 空日志
45 | ///
46 | None = 0,
47 | }
48 | ///
49 | /// 通用设置
50 | ///
51 | public static class Global
52 | {
53 | ///
54 | /// 是否输出全局日志
55 | ///
56 | /// 4:debug [3:info] 2:warn 1:error
57 | ///
58 | public static DebugFlag G_Debug_Flag { get; set; } = DebugFlag.Info;
59 | ///
60 | /// 全局端
61 | ///
62 | public static Client? G_Client { get; set; } = null;
63 |
64 | ///
65 | /// 日志处理模块
66 | ///
67 | public static class Log
68 | {
69 | ///
70 | /// 全局日志(总输出)
71 | ///
72 | /// 字符串
73 | /// 类型强度
74 | /// 前景色
75 | /// 背景色
76 | public static void GlobalLog(string s, int intsenties, ConsoleColor f = default, ConsoleColor b = default)
77 | {
78 | if ((int)G_Debug_Flag > intsenties)
79 | {
80 | Console.ForegroundColor = f;
81 | Console.BackgroundColor = b;
82 | Console.WriteLine($"[MML {Assembly.GetExecutingAssembly().GetName().Version}] [{DateTime.Now : MM-dd HH:mm:ss}] \n$ {s}");
83 | Console.ForegroundColor = default;
84 | Console.BackgroundColor = default;
85 | }
86 |
87 | }
88 | ///
89 | /// Debug 级别
90 | ///
91 | /// 字符
92 | public static void Debug(string s) => GlobalLog(s, 3, ConsoleColor.White);
93 | ///
94 | /// Info 级别
95 | ///
96 | /// 字符
97 | public static void Info(string s) => GlobalLog(s, 2, ConsoleColor.Blue);
98 | ///
99 | /// Warn 级别
100 | ///
101 | /// 字符
102 | public static void Warn(string s) => GlobalLog(s, 1, ConsoleColor.Yellow);
103 | ///
104 | /// Error 级别
105 | ///
106 | /// 字符
107 | public static void Error(string s) => GlobalLog(s, 0, ConsoleColor.Red);
108 |
109 | }
110 |
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/GlobalDefines/Sender.cs:
--------------------------------------------------------------------------------
1 | /* 本文上下文定义了消息事件的引起者,
2 | * 根据消息方案查询引起者, 本类类内继承顺序不允许调换.
3 | * ------------------------------
4 | * this file defines the 'message sender'
5 | * by use of identify the sender,
6 | * and do not alter the order of the class
7 | */
8 |
9 | using System;
10 | using System.Collections.Generic;
11 | using System.Diagnostics.CodeAnalysis;
12 | using System.Runtime;
13 |
14 | namespace MeowMiraiLib.Msg.Sender
15 | {
16 | ///
17 | /// 消息引起者定义
18 | ///
19 | public class Sender : IEquatable
20 | {
21 | ///
22 | /// 消息位定义
23 | ///
24 | public long id { get; set; }
25 |
26 | ///
27 | public bool Equals(Sender? other) => id == other.id;
28 | ///
29 | public override bool Equals(object obj) => Equals(obj as Sender);
30 |
31 | ///
32 | public override int GetHashCode() => id.GetHashCode();
33 | }
34 |
35 | ///
36 | /// 群信息句柄
37 | ///
38 | public class GroupMessageSender : Sender, IEquatable
39 | {
40 | ///
41 | /// 成员名称
42 | ///
43 | public string memberName { get; set; }
44 | ///
45 | /// 成员头衔
46 | ///
47 | public string specialTitle { get; set; }
48 | ///
49 | /// 成员群权限
50 | ///
51 | public string permission { get; set; }
52 | ///
53 | /// 入群时间
54 | ///
55 | public long joinTimestamp { get; set; }
56 | ///
57 | /// 上次发言时间
58 | ///
59 | public long lastSpeakTimestamp { get; set; }
60 | ///
61 | /// 剩余禁言时间
62 | ///
63 | public long muteTimeRemaining { get; set; }
64 | ///
65 | /// 群信息
66 | ///
67 | public Group group { get; set; }
68 | ///
69 | /// 群信息句柄群信息类
70 | ///
71 | public class Group
72 | {
73 | ///
74 | /// 群号
75 | ///
76 | public long id { get; set; }
77 | ///
78 | /// 群名
79 | ///
80 | public string name { get; set; }
81 | ///
82 | /// 在群里的权限
83 | ///
84 | public string permission { get; set; }
85 | }
86 |
87 | ///
88 | public bool Equals(GroupMessageSender? other) => (id == other.id) && (group.id == other.group.id);
89 | ///
90 | public override bool Equals(object obj) => Equals(obj as GroupMessageSender);
91 | ///
92 | public override int GetHashCode() => id.GetHashCode() ^ group.id.GetHashCode();
93 |
94 | }
95 | ///
96 | /// 临时信息句柄
97 | ///
98 | public class TempMessageSender : GroupMessageSender { }
99 | ///
100 | /// 同步群信息
101 | ///
102 | public class GroupSyncMessageSender : GroupMessageSender { }
103 | ///
104 | /// 同步群临时信息
105 | ///
106 | public class TempSyncMessageSender : TempMessageSender { }
107 |
108 | ///
109 | /// 好友信息好友句柄
110 | ///
111 | public class FriendMessageSender : Sender
112 | {
113 | ///
114 | /// 好友昵称
115 | ///
116 | public string nickname { get; set; }
117 | ///
118 | /// 好友备注
119 | ///
120 | public string remark { get; set; }
121 | }
122 | ///
123 | /// 陌生人信息句柄
124 | ///
125 | public class StrangerMessageSender : FriendMessageSender { }
126 | ///
127 | /// 同步好友信息
128 | ///
129 | public class FriendSyncMessageSender : FriendMessageSender { }
130 | ///
131 | /// 同步陌生人消息
132 | ///
133 | public class StrangerSyncMessageSender : StrangerMessageSender { }
134 |
135 | ///
136 | /// 其他客户端信息句柄
137 | ///
138 | public class OtherClientMessageSender : Sender
139 | {
140 | ///
141 | /// 平台句柄
142 | ///
143 | public string platform { get; set; }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, religion, or sexual identity
10 | and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | * Demonstrating empathy and kindness toward other people
21 | * Being respectful of differing opinions, viewpoints, and experiences
22 | * Giving and gracefully accepting constructive feedback
23 | * Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | * Focusing on what is best not just for us as individuals, but for the
26 | overall community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | * The use of sexualized language or imagery, and sexual attention or
31 | advances of any kind
32 | * Trolling, insulting or derogatory comments, and personal or political attacks
33 | * Public or private harassment
34 | * Publishing others' private information, such as a physical or email
35 | address, without their explicit permission
36 | * Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | davidtennant405@outlook.com.
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series
86 | of actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or
93 | permanent ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within
113 | the community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.0, available at
119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120 |
121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct
122 | enforcement ladder](https://github.com/mozilla/diversity).
123 |
124 | [homepage]: https://www.contributor-covenant.org
125 |
126 | For answers to common questions about this code of conduct, see the FAQ at
127 | https://www.contributor-covenant.org/faq. Translations are available at
128 | https://www.contributor-covenant.org/translations.
129 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | bld/
24 | [Bb]in/
25 | [Oo]bj/
26 | [Ll]og/
27 |
28 | # Visual Studio 2015/2017 cache/options directory
29 | .vs/
30 | # Uncomment if you have tasks that create the project's static files in wwwroot
31 | #wwwroot/
32 |
33 | # Visual Studio 2017 auto generated files
34 | Generated\ Files/
35 |
36 | # MSTest test Results
37 | [Tt]est[Rr]esult*/
38 | [Bb]uild[Ll]og.*
39 |
40 | # NUNIT
41 | *.VisualState.xml
42 | TestResult.xml
43 |
44 | # Build Results of an ATL Project
45 | [Dd]ebugPS/
46 | [Rr]eleasePS/
47 | dlldata.c
48 |
49 | # Benchmark Results
50 | BenchmarkDotNet.Artifacts/
51 |
52 | # .NET Core
53 | project.lock.json
54 | project.fragment.lock.json
55 | artifacts/
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_h.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *_wpftmp.csproj
81 | *.log
82 | *.vspscc
83 | *.vssscc
84 | .builds
85 | *.pidb
86 | *.svclog
87 | *.scc
88 |
89 | # Chutzpah Test files
90 | _Chutzpah*
91 |
92 | # Visual C++ cache files
93 | ipch/
94 | *.aps
95 | *.ncb
96 | *.opendb
97 | *.opensdf
98 | *.sdf
99 | *.cachefile
100 | *.VC.db
101 | *.VC.VC.opendb
102 |
103 | # Visual Studio profiler
104 | *.psess
105 | *.vsp
106 | *.vspx
107 | *.sap
108 |
109 | # Visual Studio Trace Files
110 | *.e2e
111 |
112 | # TFS 2012 Local Workspace
113 | $tf/
114 |
115 | # Guidance Automation Toolkit
116 | *.gpState
117 |
118 | # ReSharper is a .NET coding add-in
119 | _ReSharper*/
120 | *.[Rr]e[Ss]harper
121 | *.DotSettings.user
122 |
123 | # JustCode is a .NET coding add-in
124 | .JustCode
125 |
126 | # TeamCity is a build add-in
127 | _TeamCity*
128 |
129 | # DotCover is a Code Coverage Tool
130 | *.dotCover
131 |
132 | # AxoCover is a Code Coverage Tool
133 | .axoCover/*
134 | !.axoCover/settings.json
135 |
136 | # Visual Studio code coverage results
137 | *.coverage
138 | *.coveragexml
139 |
140 | # NCrunch
141 | _NCrunch_*
142 | .*crunch*.local.xml
143 | nCrunchTemp_*
144 |
145 | # MightyMoose
146 | *.mm.*
147 | AutoTest.Net/
148 |
149 | # Web workbench (sass)
150 | .sass-cache/
151 |
152 | # Installshield output folder
153 | [Ee]xpress/
154 |
155 | # DocProject is a documentation generator add-in
156 | DocProject/buildhelp/
157 | DocProject/Help/*.HxT
158 | DocProject/Help/*.HxC
159 | DocProject/Help/*.hhc
160 | DocProject/Help/*.hhk
161 | DocProject/Help/*.hhp
162 | DocProject/Help/Html2
163 | DocProject/Help/html
164 |
165 | # Click-Once directory
166 | publish/
167 |
168 | # Publish Web Output
169 | *.[Pp]ublish.xml
170 | *.azurePubxml
171 | # Note: Comment the next line if you want to checkin your web deploy settings,
172 | # but database connection strings (with potential passwords) will be unencrypted
173 | *.pubxml
174 | *.publishproj
175 |
176 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
177 | # checkin your Azure Web App publish settings, but sensitive information contained
178 | # in these scripts will be unencrypted
179 | PublishScripts/
180 |
181 | # NuGet Packages
182 | *.nupkg
183 | # The packages folder can be ignored because of Package Restore
184 | **/[Pp]ackages/*
185 | # except build/, which is used as an MSBuild target.
186 | !**/[Pp]ackages/build/
187 | # Uncomment if necessary however generally it will be regenerated when needed
188 | #!**/[Pp]ackages/repositories.config
189 | # NuGet v3's project.json files produces more ignorable files
190 | *.nuget.props
191 | *.nuget.targets
192 |
193 | # Microsoft Azure Build Output
194 | csx/
195 | *.build.csdef
196 |
197 | # Microsoft Azure Emulator
198 | ecf/
199 | rcf/
200 |
201 | # Windows Store app package directories and files
202 | AppPackages/
203 | BundleArtifacts/
204 | Package.StoreAssociation.xml
205 | _pkginfo.txt
206 | *.appx
207 |
208 | # Visual Studio cache files
209 | # files ending in .cache can be ignored
210 | *.[Cc]ache
211 | # but keep track of directories ending in .cache
212 | !*.[Cc]ache/
213 |
214 | # Others
215 | ClientBin/
216 | ~$*
217 | *~
218 | *.dbmdl
219 | *.dbproj.schemaview
220 | *.jfm
221 | *.pfx
222 | *.publishsettings
223 | orleans.codegen.cs
224 |
225 | # Including strong name files can present a security risk
226 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
227 | #*.snk
228 |
229 | # Since there are multiple workflows, uncomment next line to ignore bower_components
230 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
231 | #bower_components/
232 |
233 | # RIA/Silverlight projects
234 | Generated_Code/
235 |
236 | # Backup & report files from converting an old project file
237 | # to a newer Visual Studio version. Backup files are not needed,
238 | # because we have git ;-)
239 | _UpgradeReport_Files/
240 | Backup*/
241 | UpgradeLog*.XML
242 | UpgradeLog*.htm
243 | ServiceFabricBackup/
244 | *.rptproj.bak
245 |
246 | # SQL Server files
247 | *.mdf
248 | *.ldf
249 | *.ndf
250 |
251 | # Business Intelligence projects
252 | *.rdl.data
253 | *.bim.layout
254 | *.bim_*.settings
255 | *.rptproj.rsuser
256 |
257 | # Microsoft Fakes
258 | FakesAssemblies/
259 |
260 | # GhostDoc plugin setting file
261 | *.GhostDoc.xml
262 |
263 | # Node.js Tools for Visual Studio
264 | .ntvs_analysis.dat
265 | node_modules/
266 |
267 | # Visual Studio 6 build log
268 | *.plg
269 |
270 | # Visual Studio 6 workspace options file
271 | *.opt
272 |
273 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
274 | *.vbw
275 |
276 | # Visual Studio LightSwitch build output
277 | **/*.HTMLClient/GeneratedArtifacts
278 | **/*.DesktopClient/GeneratedArtifacts
279 | **/*.DesktopClient/ModelManifest.xml
280 | **/*.Server/GeneratedArtifacts
281 | **/*.Server/ModelManifest.xml
282 | _Pvt_Extensions
283 |
284 | # Paket dependency manager
285 | .paket/paket.exe
286 | paket-files/
287 |
288 | # FAKE - F# Make
289 | .fake/
290 |
291 | # JetBrains Rider
292 | .idea/
293 | *.sln.iml
294 |
295 | # CodeRush personal settings
296 | .cr/personal
297 |
298 | # Python Tools for Visual Studio (PTVS)
299 | __pycache__/
300 | *.pyc
301 |
302 | # Cake - Uncomment if you are using it
303 | # tools/**
304 | # !tools/packages.config
305 |
306 | # Tabs Studio
307 | *.tss
308 |
309 | # Telerik's JustMock configuration file
310 | *.jmconfig
311 |
312 | # BizTalk build output
313 | *.btp.cs
314 | *.btm.cs
315 | *.odx.cs
316 | *.xsd.cs
317 |
318 | # OpenCover UI analysis results
319 | OpenCover/
320 |
321 | # Azure Stream Analytics local run output
322 | ASALocalRun/
323 |
324 | # MSBuild Binary and Structured Log
325 | *.binlog
326 |
327 | # NVidia Nsight GPU debugger configuration file
328 | *.nvuser
329 |
330 | # MFractors (Xamarin productivity tool) working folder
331 | .mfractor/
332 |
333 | # Local History for Visual Studio
334 | .localhistory/
335 | /MeowMiraiLibX.sln
336 | MultiContext/ContextualBase.cs
337 | MultiContext/ContextualDefines.cs
338 |
--------------------------------------------------------------------------------
/ExtendedContextParser/EParser.cs:
--------------------------------------------------------------------------------
1 | using MeowMiraiLib.Msg.Sender;
2 | using MeowMiraiLib.Msg.Type;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Threading.Tasks;
6 |
7 |
8 | namespace MeowMiraiLib.Extended
9 | {
10 | ///
11 | /// 将信息数组当作纯文本
12 | ///
13 | public enum TreatAsText
14 | {
15 | ///
16 | /// 字面量
17 | ///
18 | Yes
19 | }
20 | ///
21 | /// 将信息数组当作文本并进行分割
22 | ///
23 | public enum TreatAsTextArray
24 | {
25 | ///
26 | /// 字面量
27 | ///
28 | Yes
29 | }
30 | ///
31 | /// 将信息数组作为信息数组
32 | ///
33 | public enum TreatAsMessage
34 | {
35 | ///
36 | /// 字面量
37 | ///
38 | Yes
39 | }
40 |
41 | ///
42 | /// 信息队列模式
43 | ///
44 | public class MUQueue
45 | {
46 | private List Q { get; set; } = new();
47 | ///
48 | /// 队列内长
49 | ///
50 | public int Length { get => Q.Count; }
51 |
52 | ///
53 | /// 入队信息队列
54 | ///
55 | ///
56 | public void Enqueue(Message[] msgs)
57 | {
58 | lock(Q)
59 | {
60 | Q.Add(msgs);
61 | }
62 | }
63 | ///
64 | /// 清理队列头部元素
65 | ///
66 | public void Outqueue()
67 | {
68 | lock (Q)
69 | {
70 | Q.RemoveAt(0);
71 | }
72 | }
73 | ///
74 | /// 返回队列头部元素
75 | ///
76 | public Message[] Dequeue()
77 | {
78 | Message[] ret = this[0];
79 | Outqueue();
80 | return ret;
81 | }
82 | ///
83 | /// 清理头部元素
84 | ///
85 | public void Cleanqueue()
86 | {
87 | lock (Q)
88 | {
89 | Q.Clear();
90 | }
91 | }
92 |
93 |
94 | ///
95 | /// 获得队列元素
96 | ///
97 | /// 队列元素次序
98 | ///
99 | public Message[] this[int x]
100 | {
101 | get
102 | {
103 | return Q[x];
104 | }
105 | }
106 | ///
107 | /// 获得队列元素,将元素作为纯信息数组
108 | ///
109 | /// 队列元素次序
110 | /// 将元素作为纯信息数组
111 | ///
112 | public Message[] this[int x, TreatAsMessage para = TreatAsMessage.Yes]
113 | {
114 | get
115 | {
116 | _ = para;
117 | return Q[x];
118 | }
119 | }
120 | ///
121 | /// 获得队列元素:将元素作为纯字符串
122 | ///
123 | /// 队列元素次序
124 | /// 将元素作为纯字符串
125 | ///
126 | public string this[int x, TreatAsText para = TreatAsText.Yes]
127 | {
128 | get
129 | {
130 | _ = para;
131 | return Q[x].MGetPlainString();
132 | }
133 | }
134 | ///
135 | /// 获得队列元素:将元素作为纯字符串
136 | ///
137 | /// 队列元素次序
138 | /// 将元素使用默认(空格)分割字符
139 | ///
140 | public string[]? this[int x, TreatAsTextArray para = TreatAsTextArray.Yes]
141 | {
142 | get
143 | {
144 | _ = para;
145 | return Q[x].MGetPlainStringSplit();
146 | }
147 | }
148 | ///
149 | /// 获得队列元素:将元素作为纯字符串
150 | ///
151 | /// 队列元素次序
152 | /// 将元素使用提交的分割方案分割字符
153 | /// 使用分割的字符串
154 | ///
155 | public string[]? this[int x, TreatAsTextArray para = TreatAsTextArray.Yes, string splitor = " "]
156 | {
157 | get
158 | {
159 | _ = para;
160 | return Q[x].MGetPlainStringSplit();
161 | }
162 | }
163 | }
164 |
165 | ///
166 | /// Extended Context Parser
167 | ///
168 | public class ECP
169 | {
170 | ///
171 | /// Inner Client
172 | ///
173 | public Client PonClient { get; private set; }
174 | ///
175 | /// Client Queue Generation
176 | ///
177 | public Task? ClientRectifyAction { get; private set; }
178 |
179 | ///
180 | /// 信息交互队列
181 | ///
182 | public Queue<(Sender Sender, Message[] Msg)> MsgQ { get; private set; } = new();
183 | ///
184 | /// Message Sets
185 | ///
186 | public Dictionary Sets { get; private set; } = new();
187 |
188 | ///
189 | /// 接收信息
190 | ///
191 | public delegate void MessageRecieve(Sender s, MUQueue o);
192 | ///
193 | /// 接收到信息
194 | ///
195 | public event MessageRecieve _OnMessageRecieve;
196 |
197 | ///
198 | /// 使用全局端解析
199 | ///
200 | public ECP() : this(Global.G_Client)
201 | {
202 | if(Global.G_Client is null)
203 | {
204 | Global.Log.Error(ErrorDefine.E0003);
205 | throw new(ErrorDefine.E0003);
206 | }
207 | else
208 | {
209 | Global.Log.Info(ErrorDefine.E99999);
210 | }
211 | }
212 | ///
213 | /// 使用自定义端解析
214 | ///
215 | /// Client
216 | public ECP(Client PonClient)
217 | {
218 | this.PonClient = PonClient;
219 | PonClient.OnFriendMessageReceive += (s, e) => MsgQ.Enqueue(new(s, e));
220 | PonClient.OnGroupMessageReceive += (s, e) => MsgQ.Enqueue(new(s, e));
221 | }
222 |
223 | ///
224 | /// 开始解析
225 | ///
226 | public void Start()
227 | {
228 | if((ClientRectifyAction is null) || (ClientRectifyAction.Status is not TaskStatus.Running))
229 | {
230 | ClientRectifyAction = Task.Run(() =>
231 | {
232 | while (true)
233 | {
234 | Task.Delay(1).GetAwaiter().GetResult();//强制确保CPU时间片分配
235 | if (MsgQ.TryDequeue(out var s))//新信息入队
236 | {
237 | if (Sets.TryGetValue(s.Sender, out var muq))//含有信息结构体, 入队
238 | {
239 | muq.Enqueue(s.Msg);
240 | _OnMessageRecieve.Invoke(s.Sender, muq);
241 | }
242 | else //不含信息结构体,新建
243 | {
244 | var nmuq = new MUQueue();
245 | nmuq.Enqueue(s.Msg);
246 | Sets.TryAdd(s.Sender, nmuq);
247 | _OnMessageRecieve.Invoke(s.Sender, nmuq);
248 | }
249 | }
250 | }
251 | });
252 | }
253 | else
254 | {
255 | Global.Log.Warn(ErrorDefine.E0002);
256 | }
257 | }
258 | }
259 | }
260 |
--------------------------------------------------------------------------------
/Client/Client.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json.Linq;
2 | using System;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 | using WebSocket4Net;
6 |
7 | /*
8 | * 开发标准客户端文件
9 | * 本文件生成了基础的客户端定义,用于构建一个快速重写的Mirai Websocket客户端,
10 | * 在更改本文件的源码之前,您需要详细了解相关的构造,
11 | * 本文件为分部类定义文件,共有三部分组成,Client,ClientEvent,ClientParser,其中:
12 | * Client 负责定义客户端内部接口和基础方法,
13 | * ClientEvent 文件负责定义用户(程序员)可重写的方法,
14 | * ClientParser 用于解释Mirai后端传送的事件和操作.
15 | * -------------------------------------------
16 | * Development Standard Client File
17 | * this file generated the client definition, it's for quickly compile Mirai-Websocket-Client
18 | * before change the source code of whole client, you need to have a look what inside of it.
19 | * this file is a partial-class-define-file, which means it'd have three part.
20 | * the first part is file 'Client', this file defines internal interface and basic method for enterprise dev-peoples
21 | * the second part is file 'ClientEvent' this file defines User-able(programmer) function/method/event
22 | * the third part is file 'ClientParser' this file defines the interpreter for Mirai-backend strings, and converted into Csharp Class and Event.
23 | */
24 |
25 | namespace MeowMiraiLib
26 | {
27 | ///
28 | /// 建造一个客户端
29 | ///
30 | public partial class Client
31 | {
32 | ///
33 | /// 地址
34 | ///
35 | public string url { get; }
36 | ///
37 | /// 客户端Websocket
38 | ///
39 | public WebSocket ws { get; }
40 | ///
41 | /// 会话进程号
42 | ///
43 | public string session { get; private set; }
44 | ///
45 | /// 重连标识
46 | ///
47 | public int reconnect { get; private set; }
48 | ///
49 | /// 生成一个端(原始方法)
50 | ///
51 | /// 地址
52 | /// 全调试输出
53 | /// 事件调试输出
54 | /// 0为不进行重连,-1为一直尝试重连,n(n>0)为尝试n次
55 | public Client(string url, int reconnect = -1)
56 | {
57 | this.url = url;
58 | this.reconnect = reconnect;
59 | ws = new(url);
60 | ws.Opened += (s, e) =>
61 | {
62 | Console.WriteLine($"[MeowMiraiLib-SocketWatchdog] - Socket Opened -");
63 | _OnServeiceConnected?.Invoke(e.ToString());
64 | };
65 | ws.Error += (s, e) =>
66 | {
67 | _OnServeiceError?.Invoke(e.Exception);
68 | Console.WriteLine($"[MeowMiraiLib-SocketWatchdog] - Socket Error , Running to Close or Reconnect -");
69 | Console.WriteLine($"{e.Exception}");
70 | ws.Close();//当客户端出错时,拒绝链接并关闭socket 置socket到Close阶段
71 | };
72 | ws.Closed += (s, e) =>
73 | {
74 | _OnServiceDropped?.Invoke(e.ToString());
75 | Console.WriteLine($"[MeowMiraiLib-SocketWatchdog] - Socket Closed -");
76 | while (reconnect == -1 || reconnect --> 0)
77 | {
78 | if (ws.State is WebSocketState.Open)
79 | {
80 | Console.WriteLine($"[MeowMiraiLib-SocketWatchdog] - Reconnect Complete-");
81 | return;
82 | }
83 | else
84 | {
85 | if (ws.State is not (WebSocketState.Connecting or WebSocketState.Closing))
86 | {
87 | Console.WriteLine($"[MeowMiraiLib-SocketWatchdog] - Tryin Reconnecting");
88 | ws.Open();
89 | }
90 | Console.WriteLine($"[MeowMiraiLib-SocketWatchdog] - Trying To Reconnect (in 5 second)-");
91 | Task.Delay(5 * 1000).GetAwaiter().GetResult();
92 | }
93 | }
94 | };
95 | ws.MessageReceived += Ws_MessageReceived;
96 | }
97 | ///
98 | /// 生成一个端(含有VerifyKey)
99 | ///
100 | /// 地址
101 | /// 端口
102 | /// 验证
103 | /// 登陆的机器人qq
104 | /// 登陆类型,建议默认all,否则无法同时解析推送事件和消息,仅限高级用户
105 | /// 全调试输出
106 | /// 事件调试输出
107 | /// 0为不进行重连,-1为一直尝试重连,n(n>0)为尝试n次
108 | public Client(string ip, int port, string verifyKey, long qq, string type = "all", int reconnect = -1)
109 | : this($"ws://{ip}:{port}/{type}?verifyKey={verifyKey}&qq={qq}", reconnect) { }
110 | ///
111 | /// 生成一个端(不含VerifyKey)
112 | ///
113 | /// 地址
114 | /// 端口
115 | /// 登陆的机器人qq
116 | /// 登陆类型,建议默认all,否则无法同时解析推送事件和消息,仅限高级用户
117 | /// 全调试输出
118 | /// 事件调试输出
119 | /// 0为不进行重连,-1为一直尝试重连,n(n>0)为尝试n次
120 | public Client(string ip, int port, long qq, string type = "all", int reconnect = -1)
121 | : this($"ws://{ip}:{port}/{type}?qq={qq}", reconnect) { }
122 | ///
123 | /// 发送并且等待回值
124 | ///
125 | /// 发送的字段
126 | /// 同步字段
127 | /// 超时取消,默认20s(秒)
128 | ///
129 | public async Task<(bool isTimedOut,JObject? Return)> SendAndWaitResponse(string json, int? syncId = null, int TimeOut = 10)
130 | {
131 | using var cancelTokenSource = new CancellationTokenSource(TimeOut * 1000);
132 | var ts = Task.Run(async () =>
133 | {
134 | if (ws is null)
135 | {
136 | Console.WriteLine($"[MeowMiraiLib-SocketWatchdog * Sending with NetFlaws] - Socket Closed -");
137 | ws.Close();
138 | if(ws.State is not WebSocketState.Open)
139 | {
140 | Console.WriteLine($"[MeowMiraiLib-SocketWatchdog * Sending with NetFlaws] - Trying Reconnect Socket -");
141 | ws.Open();
142 | if(ws.State is WebSocketState.Open)
143 | {
144 | Console.WriteLine($"[MeowMiraiLib-SocketWatchdog * Sending with NetFlaws] - Reconnect Complete -");
145 | }
146 | }
147 | }
148 | ws?.Send(json);
149 | while (true)
150 | {
151 | if (cancelTokenSource.IsCancellationRequested)
152 | {
153 | return null;
154 | }
155 | await Task.Delay(1);
156 | if (SSMRequestList.Count != 0)
157 | {
158 | if (SSMRequestList.TryDequeue(out JObject ssm) && ssm != null)
159 | {
160 | if (ssm["syncId"].ToObject() == syncId)
161 | {
162 | return ssm;
163 | }
164 | else
165 | {
166 | SSMRequestList.Enqueue(ssm);
167 | }
168 | }
169 | }
170 | }
171 | }, cancelTokenSource.Token);
172 |
173 | if (ts.Wait(TimeSpan.FromMilliseconds(TimeOut * 1000)))
174 | {
175 | return (false, await ts);
176 | }
177 | else
178 | {
179 | return (true, null);
180 | }
181 | }
182 | ///
183 | /// 链接
184 | ///
185 | ///
186 | public void Connect()
187 | {
188 | if (string.IsNullOrEmpty(url))
189 | {
190 | Global.Log.Error(ErrorDefine.E0001);
191 | throw new(ErrorDefine.E0001);
192 | }
193 | else
194 | {
195 | ws.Open();
196 | }
197 | }
198 | ///
199 | /// 异步链接
200 | ///
201 | ///
202 | public Task ConnectAsync()
203 | {
204 | if (string.IsNullOrEmpty(url))
205 | {
206 | Global.Log.Error(ErrorDefine.E0001);
207 | throw new(ErrorDefine.E0001);
208 | }
209 | else
210 | {
211 | return ws.OpenAsync();
212 | }
213 | }
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/GlobalDefines/MessageUtil.cs:
--------------------------------------------------------------------------------
1 | using MeowMiraiLib.GenericModel;
2 | using MeowMiraiLib.Msg;
3 | using MeowMiraiLib.Msg.Sender;
4 | using MeowMiraiLib.Msg.Type;
5 | using System.Collections.Generic;
6 | using System.Text;
7 |
8 | /*
9 | * 本文件是快速信息编写类的基础文件,
10 | * 本类的编写为纯帮助类, 目的是加速软件开发速度和正确使用功能,
11 | * 大部分功能已经在此实现, 您可以提交PR进行增设功能
12 | * --------------------------
13 | * This File is for quick implement function (helper-class) File,
14 | * It's mainly for more quick program-writing and correctly use internal function .
15 | * The most majority function is already complete in doc.
16 | * You can also trigger a Pull-Request to insert function.
17 | */
18 |
19 | namespace MeowMiraiLib
20 | {
21 | ///
22 | /// 信息类的扩展方法
23 | ///
24 | public static class MessageUtil
25 | {
26 | /*caller Util*/
27 | ///
28 | /// 获取信息的字符串表示
29 | ///
30 | ///
31 | ///
32 | public static string MGetPlainString(this Message[] array)
33 | {
34 | StringBuilder sb = new();
35 | foreach (var i in array)
36 | {
37 | if (i is Plain)
38 | {
39 | sb.Append((i as Plain).text);
40 | }
41 | }
42 | return sb.ToString();
43 | }
44 | ///
45 | /// 获取命令形式的扩展
46 | ///
47 | ///
48 | /// 分隔符
49 | ///
50 | public static string[] MGetPlainStringSplit(this Message[] array, string splitor = " ")
51 | => MGetPlainString(array).Trim().Split(splitor);
52 | ///
53 | /// 获得信息内可能的图片地址
54 | /// 通过测试数组长度来确定是否含有图片
55 | ///
56 | ///
57 | /// 返回一个(bool,string)的结构来判断(是否闪图,图片地址)
58 | public static (bool _isFlashMessage, string url)[] MGetEachImageUrl(this Message[] array)
59 | {
60 | List<(bool, string)> l = new();
61 | foreach (var i in array)
62 | {
63 | if (i is Image)
64 | {
65 | var url = (i as Image).url;
66 | l.Add((false, url));
67 | }
68 | else if (i is FlashImage)
69 | {
70 | var url = (i as FlashImage).url;
71 | l.Add((true, url));
72 | }
73 | }
74 | return l.ToArray();
75 | }
76 |
77 | /*Sender Util*/
78 | ///
79 | /// 将信息发送给好友
80 | ///
81 | /// 信息序列
82 | /// 目标
83 | /// 要发送的端
84 | /// 是否回复某条
85 | public static MessageId SendToFriend(this Message[] array, long target, Client? c = null, long? quote = null) => new FriendMessage(target, array, quote).Send(c);
86 | ///
87 | /// 将信息发送给群
88 | ///
89 | /// 信息序列
90 | /// 目标
91 | /// 要发送的端
92 | /// 是否回复某条
93 | public static MessageId SendToGroup(this Message[] array, long target, Client? c = null, long? quote = null) => new GroupMessage(target, array, quote).Send(c);
94 | ///
95 | /// 将信息发送给临时聊天
96 | ///
97 | /// 信息序列
98 | /// 目标
99 | /// 发起临时聊天的群号
100 | /// 要发送的端
101 | /// 是否回复某条
102 | public static MessageId SendToTemp(this Message[] array, long target, long group, Client? c = null, long? quote = null) => new TempMessage(target, group, array, quote).Send(c);
103 |
104 | /*GenericModel util*/
105 | ///
106 | /// 给好友发送信息
107 | ///
108 | /// 好友列表的好友
109 | /// 信息组
110 | /// 端
111 | /// 引用
112 | ///
113 | public static MessageId SendMessage(this QQFriend friend, Message[] array, Client? c = null, long? quote = null) => new FriendMessage(friend.id, array, quote).Send(c);
114 | ///
115 | /// 给好友发信息(使用Sender定义)
116 | ///
117 | /// Sender定义
118 | /// 信息数组
119 | /// 端
120 | /// 回复类型
121 | ///
122 | public static MessageId SendMessage(this FriendMessageSender friend, Message[] array, Client? c = null, long? quote = null) => new FriendMessage(friend.id, array, quote).Send(c);
123 |
124 | ///
125 | /// 给好友发送信息(简写逻辑)
126 | ///
127 | /// 简写逻辑写法
128 | /// 端
129 | /// 引用
130 | ///
131 | public static MessageId SendMessage(this (QQFriend friend, Message[] array) a, Client? c = null, long? quote = null) => new FriendMessage(a.friend.id, a.array, quote).Send(c);
132 | ///
133 | /// 给好友发送信息(简写逻辑/使用Sender)
134 | ///
135 | /// 简写逻辑写法
136 | /// 端
137 | /// 引用
138 | ///
139 | public static MessageId SendMessage(this (FriendMessageSender friend, Message[] array) a, Client? c = null, long? quote = null) => new FriendMessage(a.friend.id, a.array, quote).Send(c);
140 |
141 | ///
142 | /// 给某群发送信息
143 | ///
144 | /// 群
145 | /// 信息组
146 | /// 端
147 | /// 引用
148 | ///
149 | public static MessageId SendMessage(this QQGroup g, Message[] array, Client? c = null, long? quote = null) => new GroupMessage(g.id, array, quote).Send(c);
150 | ///
151 | /// 给某群发送信息(使用Sender)
152 | ///
153 | /// 群
154 | /// 信息组
155 | /// 端
156 | /// 引用
157 | ///
158 | public static MessageId SendMessage(this GroupMessageSender g, Message[] array, Client? c = null, long? quote = null) => new GroupMessage(g.group.id, array, quote).Send(c);
159 |
160 | ///
161 | /// 给某群发送信息(简写逻辑)
162 | ///
163 | /// 简写逻辑写法
164 | /// 端
165 | /// 引用
166 | ///
167 | public static MessageId SendMessage(this (QQGroup g, Message[] array) a, Client? c = null, long? quote = null) => new GroupMessage(a.g.id, a.array, quote).Send(c);
168 | ///
169 | /// 给群发信息(使用Sender定义)
170 | ///
171 | /// 组定义
172 | /// 端
173 | /// 回复
174 | ///
175 | public static MessageId SendMessage(this (GroupMessageSender g, Message[] array) a, Client? c = null, long? quote = null) => new GroupMessage(a.g.group.id, a.array, quote).Send(c);
176 |
177 | ///
178 | /// 给某群成员(非好友)发送信息
179 | ///
180 | /// 群
181 | /// 信息组
182 | /// 端
183 | /// 引用
184 | ///
185 | public static MessageId SendMessage(this QQGroupMember gm, Message[] array, Client? c = null, long? quote = null) => new TempMessage(gm.id, gm.group.id, array, quote).Send(c);
186 | ///
187 | /// 给某群成员(非好友)发送信息(简写逻辑)
188 | ///
189 | /// 简写逻辑写法
190 | /// 端
191 | /// 引用
192 | ///
193 | public static MessageId SendMessage(this (QQGroupMember gm, Message[] array) a, Client? c = null, long? quote = null) => new TempMessage(a.gm.id, a.gm.group.id, a.array, quote).Send(c);
194 |
195 |
196 |
197 |
198 |
199 |
200 | ///
201 | /// 获取群列表内的某个群的群员列表
202 | ///
203 | /// 群
204 | /// 端
205 | ///
206 | public static QQGroupMember[]? GetMemberList(this QQGroup gp, Client? c = null) => new MemberList(gp.id).Send(c);
207 |
208 | }
209 | }
210 |
--------------------------------------------------------------------------------
/GlobalDefines/GenericModel.cs:
--------------------------------------------------------------------------------
1 | /* 本类是关于收发的Json格式对位解析的模块
2 | * 其内容和 https://github.com/project-mirai/mirai-api-http/blob/master/docs/api/API.md 内的响应内容完全一致
3 | * 本文件用于储存一切Mirai触发的回送事件,请勿修改内部的包含类或者使用反射修改类内内容,
4 | * 在逻辑设计上, 原则上本类内文件必须继承ReturnObject以适应类的功能,请勿外部使用接口多继承修改类内行为
5 | * ----------
6 | * Generic PostJson Model
7 | * this file still follow the `response` section of https://github.com/project-mirai/mirai-api-http/blob/master/docs/api/API.md
8 | * this file is using for Mirai-ReturnValue Handling
9 | * also don't use reflection of Extension to alter the classes that already sealed
10 | * in logic applie-ments all class must inhert `ReturnObject` class to infer the class defines
11 | */
12 |
13 | namespace MeowMiraiLib.GenericModel
14 | {
15 |
16 | ///
17 | /// Generic Return Object
18 | ///
19 | public class ReturnObject
20 | {
21 | ///
22 | /// 返回Newtonsoft打印的字符串
23 | ///
24 | ///
25 | public override string ToString()
26 | {
27 | return Newtonsoft.Json.JsonConvert.SerializeObject(this);
28 | }
29 | }
30 | ///
31 | /// 短成员类
32 | ///
33 | public sealed class QQGroupMemberShort : ReturnObject
34 | {
35 | ///
36 | /// 短成员QQ号
37 | ///
38 | public long id { get; }
39 | ///
40 | /// 短成员昵称
41 | ///
42 | public string memberName { get; }
43 | ///
44 | /// 短成员权限
45 | ///
46 | public string permission { get; }
47 | ///
48 | /// 引用短成员的群类
49 | ///
50 | public QQGroup group { get; }
51 | ///
52 | /// 生成一个短成员
53 | ///
54 | ///
55 | ///
56 | ///
57 | ///
58 | public QQGroupMemberShort(long id, string memberName, string permission, QQGroup group)
59 | {
60 | this.id = id;
61 | this.memberName = memberName;
62 | this.permission = permission;
63 | this.group = group;
64 | }
65 | }
66 | ///
67 | /// QQ好友(列表)
68 | ///
69 | public sealed class QQFriend : ReturnObject
70 | {
71 | ///
72 | /// QQ号
73 | ///
74 | public long id { get; }
75 | ///
76 | /// 昵称
77 | ///
78 | public string nickname { get; }
79 | ///
80 | /// 标记
81 | ///
82 | public string remark { get; }
83 | ///
84 | /// 实例化一个好友
85 | ///
86 | /// QQ号
87 | /// 昵称
88 | /// 备注
89 | public QQFriend(long id, string nickname, string remark)
90 | {
91 | this.id = id;
92 | this.nickname = nickname;
93 | this.remark = remark;
94 | }
95 |
96 | ///
97 | /// 朝本好友(非好友)发送一个群消息
98 | ///
99 | /// 端
100 | /// 信息
101 | ///
102 | public MessageId SendMessage(Client c, Msg.Type.Message[] msg) => MessageUtil.SendMessage((this, msg), c);
103 | }
104 | ///
105 | /// 群(列表)
106 | ///
107 | public sealed class QQGroup : ReturnObject
108 | {
109 | ///
110 | /// 群号
111 | ///
112 | public long id { get; }
113 | ///
114 | /// 群名
115 | ///
116 | public string name { get; }
117 | ///
118 | /// 群中权限
119 | ///
120 | public string permission { get; }
121 | ///
122 | /// 实例化一个群
123 | ///
124 | /// 群号
125 | /// 群名
126 | /// Bot群权限
127 | public QQGroup(long id, string name, string permission)
128 | {
129 | this.id = id;
130 | this.name = name;
131 | this.permission = permission;
132 | }
133 |
134 | ///
135 | /// 朝本群发送一个群消息
136 | ///
137 | /// 端
138 | /// 信息
139 | ///
140 | public MessageId SendMessage(Client c, Msg.Type.Message[] msg) => MessageUtil.SendMessage((this, msg), c);
141 | }
142 | ///
143 | /// 群成员(列表)
144 | ///
145 | public sealed class QQGroupMember : ReturnObject
146 | {
147 | ///
148 | /// 群员QQ号
149 | ///
150 | public long id { get; }
151 | ///
152 | /// 群员名
153 | ///
154 | public string memberName { get; }
155 | ///
156 | /// 群员权限
157 | ///
158 | public string permission { get; }
159 | ///
160 | /// 群头衔
161 | ///
162 | public string specialTitle { get; }
163 | ///
164 | /// 加入时间戳
165 | ///
166 | public long joinTimestamp { get; }
167 | ///
168 | /// 最后一次发言时间戳
169 | ///
170 | public long lastSpeakTimestamp { get; }
171 | ///
172 | /// 禁言剩余时间
173 | ///
174 | public long muteTimeRemaining { get; }
175 | ///
176 | /// QQ群(列表)
177 | ///
178 | public QQGroup group { get; }
179 |
180 | ///
181 | /// 生成一个群成员(列表)
182 | ///
183 | ///
184 | ///
185 | ///
186 | ///
187 | ///
188 | ///
189 | ///
190 | ///
191 | public QQGroupMember(long id, string memberName, string specialTitle,
192 | string permission, long joinTimestamp, long lastSpeakTimestamp,
193 | long muteTimeRemaining, QQGroup group)
194 | {
195 | this.id = id;
196 | this.memberName = memberName;
197 | this.specialTitle = specialTitle;
198 | this.permission = permission;
199 | this.joinTimestamp = joinTimestamp;
200 | this.lastSpeakTimestamp = lastSpeakTimestamp;
201 | this.muteTimeRemaining = muteTimeRemaining;
202 | this.group = group;
203 | }
204 | ///
205 | /// 朝本群友(非好友)发送一个群消息
206 | ///
207 | /// 端
208 | /// 信息
209 | ///
210 | public MessageId SendMessage(Client c, Msg.Type.Message[] msg) => MessageUtil.SendMessage((this, msg), c);
211 | }
212 | ///
213 | /// 获取Bot资料
214 | ///
215 | public sealed class QQProfile : ReturnObject
216 | {
217 | ///
218 | /// 昵称
219 | ///
220 | public string nickname { get; }
221 | ///
222 | /// 电子邮件
223 | ///
224 | public string email { get; }
225 | ///
226 | /// 年龄
227 | ///
228 | public int age { get; }
229 | ///
230 | /// QQ等级
231 | ///
232 | public long level { get; }
233 | ///
234 | /// 签名
235 | ///
236 | public string sign { get; }
237 | ///
238 | /// 性别(UNKNOWN, MALE, FEMALE)
239 | ///
240 | public string sex { get; }
241 | }
242 | ///
243 | /// 群公告返回类
244 | ///
245 | public sealed class QQAno : ReturnObject
246 | {
247 | ///
248 | /// 群信息
249 | ///
250 | public QQGroup group { get; }
251 | ///
252 | /// 群公告内容
253 | ///
254 | public string content { get; }
255 | ///
256 | /// 发送者账号
257 | ///
258 | public long senderId { get; }
259 | ///
260 | /// 唯一识别码
261 | ///
262 | public string fid { get; }
263 | ///
264 | /// 是否全部确认
265 | ///
266 | public bool allConfirmed { get; }
267 | ///
268 | /// 已经确认的人数
269 | ///
270 | public long confirmedMembersCount { get; }
271 | ///
272 | /// 发布时间
273 | ///
274 | public long publicationTime { get; }
275 |
276 | ///
277 | /// 删除这个公告
278 | ///
279 | /// 端
280 | ///
281 | public bool Delete(Client c) => new Msg.Anno_delete(group.id, fid).Send(c) == 0;
282 | }
283 | ///
284 | /// 群设置返回类
285 | ///
286 | public sealed class QQGConf : ReturnObject
287 | {
288 | ///
289 | /// 群名
290 | ///
291 | public string name { get; }
292 | ///
293 | /// 群置顶公告
294 | ///
295 | public string announcement { get; }
296 | ///
297 | /// 坦白说开启状态
298 | ///
299 | public bool confessTalk { get; }
300 | ///
301 | /// 是否允许群成员邀请
302 | ///
303 | public bool allowMemberInvite { get; }
304 | ///
305 | /// 是否自动同意入群
306 | ///
307 | public bool autoApprove { get; }
308 | ///
309 | /// 匿名聊天是否开启
310 | ///
311 | public bool anonymousChat { get; }
312 | ///
313 | /// 是否开启全员禁言
314 | ///
315 | public bool muteAll { get; }
316 | }
317 | }
318 |
--------------------------------------------------------------------------------
/Client/ClientEvent.cs:
--------------------------------------------------------------------------------
1 | using MeowMiraiLib.Msg.Sender;
2 | using MeowMiraiLib.Msg.Type;
3 | using System;
4 |
5 | /*
6 | * 所有后台引起事件文件
7 | * 本文件用于存储对标Mirai-HTTP-API EventType内的所有事件实例 以及 Socket/Client事件的定义
8 | * 逻辑上本文件展示的所有事件均交由开发者自己覆盖和反写, 但不允许更改Parser内的对应事件解析方案
9 | * 在 WebSocket 链接成功后客户端会进行输出 "Connected" 如果想覆盖本事件请重新编辑 ClientParser.cs 内的 Ws_Opened 方法.
10 | * -----------------
11 | * This File is using to present all Mirai-Backend Event
12 | * This file is an one to one mapping of Mirai-HTTP-API EventType file, and Socket/Client Event defines
13 | * logically all event inside this file is responsable to dev-people,
14 | * but restricted to alter any function/method that written in 'ClientParser.cs' File
15 | * When Websocket connected then screen will print one single-line text of 'Connected',
16 | * if you want change this settings then, you can edit the 'ClientParser.cs' File -> 'Ws_Opened' function/method to achieve this goal.
17 | */
18 |
19 | namespace MeowMiraiLib
20 | {
21 | public partial class Client
22 | {
23 | /*--Type of Service--*/
24 |
25 | ///
26 | /// Websocket端链接成功信息
27 | ///
28 | public delegate void ServiceConnected(string e);
29 | ///
30 | /// 接收到Websocket端链接成功信息
31 | ///
32 | public event ServiceConnected _OnServeiceConnected;
33 | ///
34 | /// Websocket端错误信息
35 | ///
36 | public delegate void ServiceError(Exception e);
37 | ///
38 | /// 接收到Websocket端错误信息
39 | ///
40 | public event ServiceError _OnServeiceError;
41 | ///
42 | /// Websocket端链接关闭信息
43 | ///
44 | public delegate void ServiceDropped(string e);
45 | ///
46 | /// 接收到Websocket端链接关闭信息
47 | ///
48 | public event ServiceDropped _OnServiceDropped;
49 | ///
50 | /// 后端传送其他客户端上线通知
51 | ///
52 | /// 客户端上线通知句柄
53 | public delegate void OtherClientOnlineEvent(Event.OtherClientOnlineEvent e);
54 | ///
55 | /// 接收到后端传送其他客户端上线通知
56 | ///
57 | public event OtherClientOnlineEvent _OnClientOnlineEvent;
58 | ///
59 | /// 后端传送其他客户端下线通知
60 | ///
61 | /// 客户端下线通知句柄
62 | public delegate void OtherClientOfflineEvent(Event.OtherClientOfflineEvent e);
63 | ///
64 | /// 接收到后端传送其他客户端下线通知
65 | ///
66 | public event OtherClientOfflineEvent _OnOtherClientOfflineEvent;
67 | ///
68 | /// 后端传送命令被执行通知
69 | ///
70 | /// 命令被执行通知句柄
71 | public delegate void CommandExecutedEvent(Event.CommandExecutedEvent e);
72 | ///
73 | /// 接收到后端传送命令被执行通知
74 | ///
75 | public event CommandExecutedEvent _OnCommandExecutedEvent;
76 | ///
77 | /// 后端传送命令未知解析
78 | ///
79 | /// 命令被执行通知句柄
80 | public delegate void UnknownEvent(string e);
81 | ///
82 | /// 接收到后端传送未知命令
83 | ///
84 | public event UnknownEvent _OnUnknownEvent;
85 |
86 | /*--Type of Message--*/
87 | ///
88 | /// 接收到好友私聊信息
89 | ///
90 | /// 信息发送者参数句柄
91 | /// 信息内容
92 | public delegate void FriendMessage(FriendMessageSender s, Message[] e);
93 | ///
94 | /// 接收到好友私聊信息
95 | ///
96 | public event FriendMessage OnFriendMessageReceive;
97 | ///
98 | /// 接收到群聊信息
99 | ///
100 | /// 信息发送者参数句柄
101 | /// 信息内容
102 | public delegate void GroupMessage(GroupMessageSender s, Message[] e);
103 | ///
104 | /// 接收到群聊信息
105 | ///
106 | public event GroupMessage OnGroupMessageReceive;
107 | ///
108 | /// 接收到临时信息
109 | ///
110 | /// 信息发送者参数句柄
111 | /// 信息内容
112 | public delegate void TempMessage(TempMessageSender s, Message[] e);
113 | ///
114 | /// 接收到临时信息
115 | ///
116 | public event TempMessage OnTempMessageReceive;
117 | ///
118 | /// 接收到陌生人信息
119 | ///
120 | /// 信息发送者参数句柄
121 | /// 信息内容
122 | public delegate void StrangerMessage(StrangerMessageSender s, Message[] e);
123 | ///
124 | /// 接收到陌生人信息
125 | ///
126 | public event StrangerMessage OnStrangerMessageReceive;
127 | ///
128 | /// 接收到其他类型信息
129 | ///
130 | /// 信息发送者参数句柄
131 | /// 信息内容
132 | public delegate void OtherClientMessage(OtherClientMessageSender s, Message[] e);
133 | ///
134 | /// 接收到其他类型信息
135 | ///
136 | public event OtherClientMessage OnOtherMessageReceive;
137 | ///
138 | /// 接收到同步好友消息
139 | ///
140 | /// 同步好友消息接收者句柄
141 | /// 信息内容
142 | public delegate void FriendSyncMessage(FriendSyncMessageSender s, Message[] e);
143 | ///
144 | /// 接收到同步好友消息
145 | ///
146 | public event FriendSyncMessage OnFriendSyncMessageReceive;
147 | ///
148 | /// 接收到同步群消息
149 | ///
150 | /// 同步群消息接收者句柄
151 | /// 信息内容
152 | public delegate void GroupSyncMessage(GroupSyncMessageSender s, Message[] e);
153 | ///
154 | /// 接收到同步群消息
155 | ///
156 | public event GroupSyncMessage OnGroupSyncMessageReceive;
157 | ///
158 | /// 接收到同步群临时消息
159 | ///
160 | /// 同步群临时接收者句柄
161 | /// 信息内容
162 | public delegate void TempSyncMessage(TempSyncMessageSender s, Message[] e);
163 | ///
164 | /// 接收到同步群临时消息
165 | ///
166 | public event TempSyncMessage OnTempSyncMessageReceive;
167 | ///
168 | /// 接收到同步陌生人消息
169 | ///
170 | /// 同步陌生人接收者句柄
171 | /// 信息内容
172 | public delegate void StrangerSyncMessage(StrangerSyncMessageSender s, Message[] e);
173 | ///
174 | /// 接收到同步陌生人消息
175 | ///
176 | public event StrangerSyncMessage OnStrangerSyncMessageReceive;
177 |
178 | /*--Type of Event--*/
179 | ///
180 | /// Mirai后台证实QQ上线
181 | ///
182 | /// Bot上线句柄
183 | public delegate void BotOnlineEvent(Event.BotOnlineEvent e);
184 | ///
185 | /// Mirai后台证实QQ上线
186 | ///
187 | public event BotOnlineEvent OnEventBotOnlineEvent;
188 | ///
189 | /// Mirai后台证实QQ主动离线
190 | ///
191 | /// 主动离线QQ句柄
192 | public delegate void BotOfflineEventActive(Event.BotOfflineEventActive e);
193 | ///
194 | /// Mirai后台证实QQ主动离线
195 | ///
196 | public event BotOfflineEventActive OnEventBotOfflineEventActive;
197 | ///
198 | /// Mirai后台证实QQ被挤下线
199 | ///
200 | /// 被挤下线QQ句柄
201 | public delegate void BotOfflineEventForce(Event.BotOfflineEventForce e);
202 | ///
203 | /// Mirai后台证实QQ被挤下线
204 | ///
205 | public event BotOfflineEventForce OnEventBotOfflineEventForce;
206 | ///
207 | /// Mirai后台证实QQ由于网络问题掉线
208 | ///
209 | /// 掉线QQ的句柄
210 | public delegate void BotOfflineEventDropped(Event.BotOfflineEventDropped e);
211 | ///
212 | /// Mirai后台证实QQ由于网络问题掉线
213 | ///
214 | public event BotOfflineEventDropped OnEventBotOfflineEventDropped;
215 | ///
216 | /// Mirai后台证实QQ重新连接完毕
217 | ///
218 | /// 链接成功的QQ句柄
219 | public delegate void BotReloginEvent(Event.BotReloginEvent e);
220 | ///
221 | /// Mirai后台证实QQ重新连接完毕
222 | ///
223 | public event BotReloginEvent OnEventBotReloginEvent;
224 | ///
225 | /// 好友的输入状态改变
226 | ///
227 | /// 好友输入状态改变句柄
228 | public delegate void FriendInputStatusChangedEvent(Event.FriendInputStatusChangedEvent e);
229 | ///
230 | /// 好友输入状态改变了
231 | ///
232 | public event FriendInputStatusChangedEvent OnEventFriendInputStatusChangedEvent;
233 | ///
234 | /// 好友的昵称改变
235 | ///
236 | /// 好友昵称改变句柄
237 | public delegate void FriendNickChangedEvent(Event.FriendNickChangedEvent e);
238 | ///
239 | /// 好友昵称改变了
240 | ///
241 | public event FriendNickChangedEvent OnEventFriendNickChangedEvent;
242 | ///
243 | /// Bot在群里的权限被改变
244 | ///
245 | /// 权限改变句柄
246 | public delegate void BotGroupPermissionChangeEvent(Event.BotGroupPermissionChangeEvent e);
247 | ///
248 | /// Bot在群里的权限被改变了
249 | ///
250 | public event BotGroupPermissionChangeEvent OnEventBotGroupPermissionChangeEvent;
251 | ///
252 | /// Bot被禁言
253 | ///
254 | /// 禁言句柄
255 | public delegate void BotMuteEvent (Event.BotMuteEvent e);
256 | ///
257 | /// Bot被禁言了
258 | ///
259 | public event BotMuteEvent OnEventBotMuteEvent;
260 | ///
261 | /// Bot被解除禁言
262 | ///
263 | /// 解除禁言句柄
264 | public delegate void BotUnmuteEvent (Event.BotUnmuteEvent e);
265 | ///
266 | /// Bot被解除禁言了
267 | ///
268 | public event BotUnmuteEvent OnEventBotUnmuteEvent;
269 | ///
270 | /// Bot加入新群
271 | ///
272 | /// 自身入群句柄
273 | public delegate void BotJoinGroupEvent(Event.BotJoinGroupEvent e);
274 | ///
275 | /// Bot加入了一个新群
276 | ///
277 | public event BotJoinGroupEvent OnEventBotJoinGroupEvent;
278 | ///
279 | /// Bot主动退群
280 | ///
281 | /// 退群句柄
282 | public delegate void BotLeaveEventActive(Event.BotLeaveEventActive e);
283 | ///
284 | /// Bot主动退出一个群
285 | ///
286 | public event BotLeaveEventActive OnEventBotLeaveEventActive;
287 | ///
288 | /// Bot因群主解散群而退出群
289 | ///
290 | /// 退群句柄
291 | public delegate void BotLeaveEventDisband(Event.BotLeaveEventDisband e);
292 | ///
293 | /// Bot因群主解散群而退出群
294 | ///
295 | public event BotLeaveEventDisband OnEventBotLeaveEventDisband;
296 | ///
297 | /// Bot被群踢出
298 | ///
299 | /// 被群踢出句柄
300 | public delegate void BotLeaveEventKick(Event.BotLeaveEventKick e);
301 | ///
302 | /// Bot被群踢出
303 | ///
304 | public event BotLeaveEventKick OnEventBotLeaveEventKick;
305 | ///
306 | /// 群员撤回信息
307 | ///
308 | /// 群员撤回信息句柄
309 | public delegate void GroupRecallEvent(Event.GroupRecallEvent e);
310 | ///
311 | /// 群员撤回了信息
312 | ///
313 | public event GroupRecallEvent OnEventGroupRecallEvent;
314 | ///
315 | /// 好友撤回信息
316 | ///
317 | /// 撤回信息句柄
318 | public delegate void FriendRecallEvent (Event.FriendRecallEvent e);
319 | ///
320 | /// 好友撤回了信息
321 | ///
322 | public event FriendRecallEvent OnEventFriendRecallEvent;
323 | ///
324 | /// 戳一戳事件
325 | ///
326 | /// 戳一戳句柄
327 | public delegate void NudgeEvent(Event.NudgeEvent e);
328 | ///
329 | /// 收到戳一戳信息
330 | ///
331 | public event NudgeEvent OnEventNudgeEvent;
332 | ///
333 | /// 群名改变信息
334 | ///
335 | /// 群名改变句柄
336 | public delegate void GroupNameChangeEvent(Event.GroupNameChangeEvent e);
337 | ///
338 | /// 某个群名改变了
339 | ///
340 | public event GroupNameChangeEvent OnEventGroupNameChangeEvent;
341 | ///
342 | /// 某个群的入群公告改变
343 | ///
344 | /// 群公告改变句柄
345 | public delegate void GroupEntranceAnnouncementChangeEvent(Event.GroupEntranceAnnouncementChangeEvent e);
346 | ///
347 | /// 某个群的入群公告改变了
348 | ///
349 | public event GroupEntranceAnnouncementChangeEvent OnEventGroupEntranceAnnouncementChangeEvent;
350 | ///
351 | /// 群全员禁言
352 | ///
353 | /// 全员禁言状态句柄
354 | public delegate void GroupMuteAllEvent(Event.GroupMuteAllEvent e);
355 | ///
356 | /// 某个群更改了全员禁言状态
357 | ///
358 | public event GroupMuteAllEvent OnEventGroupMuteAllEvent;
359 | ///
360 | /// 群匿名聊天
361 | ///
362 | /// 全群匿名状态句柄
363 | public delegate void GroupAllowAnonymousChatEvent(Event.GroupAllowAnonymousChatEvent e);
364 | ///
365 | /// 某个群更改了匿名聊天状态
366 | ///
367 | public event GroupAllowAnonymousChatEvent OnEventGroupAllowAnonymousChatEvent;
368 | ///
369 | /// 群坦白说
370 | ///
371 | /// 群坦白说状态句柄
372 | public delegate void GroupAllowConfessTalkEvent(Event.GroupAllowConfessTalkEvent e);
373 | ///
374 | /// 某个群更改了坦白说的状态
375 | ///
376 | public event GroupAllowConfessTalkEvent OnEventGroupAllowConfessTalkEvent;
377 | ///
378 | /// 群员邀请好友加群
379 | ///
380 | /// 群员邀请加群句柄
381 | public delegate void GroupAllowMemberInviteEvent(Event.GroupAllowMemberInviteEvent e);
382 | ///
383 | /// 某个群员邀请好友加群
384 | ///
385 | public event GroupAllowMemberInviteEvent OnEventGroupAllowMemberInviteEvent;
386 | ///
387 | /// 新人入群
388 | ///
389 | /// 新人入群句柄
390 | public delegate void MemberJoinEvent(Event.MemberJoinEvent e);
391 | ///
392 | /// 某群有新人入群了
393 | ///
394 | public event MemberJoinEvent OnEventMemberJoinEvent;
395 | ///
396 | /// 某人被踢(不是Bot)
397 | ///
398 | /// 被踢句柄
399 | public delegate void MemberLeaveEventKick(Event.MemberLeaveEventKick e);
400 | ///
401 | /// 某群把某人踢出了(不是Bot)
402 | ///
403 | public event MemberLeaveEventKick OnEventMemberLeaveEventKick;
404 | ///
405 | /// 成员主动退群
406 | ///
407 | /// 群员主动离群句柄
408 | public delegate void MemberLeaveEventQuit(Event.MemberLeaveEventQuit e);
409 | ///
410 | /// 某群有成员主动退群了
411 | ///
412 | public event MemberLeaveEventQuit OnEventMemberLeaveEventQuit;
413 | ///
414 | /// 群名片改动
415 | ///
416 | /// 群名片改动句柄
417 | public delegate void MemberCardChangeEvent(Event.MemberCardChangeEvent e);
418 | ///
419 | /// 某群有人的群名片改动了
420 | ///
421 | public event MemberCardChangeEvent OnEventCardChangeEvent;
422 | ///
423 | /// 群头衔改动
424 | ///
425 | /// 头衔改动句柄
426 | public delegate void MemberSpecialTitleChangeEvent(Event.MemberSpecialTitleChangeEvent e);
427 | ///
428 | /// 某群有某个群主改动了某人头衔
429 | ///
430 | public event MemberSpecialTitleChangeEvent OnEventSpecialTitleChangeEvent;
431 | ///
432 | /// 某个成员权限改变
433 | ///
434 | ///
435 | public delegate void MemberPermissionChangeEvent(Event.MemberPermissionChangeEvent e);
436 | ///
437 | /// 某群有某个成员权限被改变了(不是Bot)
438 | ///
439 | public event MemberPermissionChangeEvent OnEventPermissionChangeEvent;
440 | ///
441 | /// 群成员被禁言
442 | ///
443 | /// 成员禁言句柄
444 | public delegate void MemberMuteEvent(Event.MemberMuteEvent e);
445 | ///
446 | /// 某群的某个群成员被禁言
447 | ///
448 | public event MemberMuteEvent OnEventMemberMuteEvent;
449 | ///
450 | /// 群成员被取消禁言
451 | ///
452 | /// 成员取消禁言句柄
453 | public delegate void MemberUnmuteEvent(Event.MemberUnmuteEvent e);
454 | ///
455 | /// 某群的某个群成员被取消禁言
456 | ///
457 | public event MemberUnmuteEvent OnEventMemberUnmuteEvent;
458 | ///
459 | /// 成员称号改变
460 | ///
461 | /// 称号改变句柄
462 | public delegate void MemberHonorChangeEvent(Event.MemberHonorChangeEvent e);
463 | ///
464 | /// 某群的某个成员的群称号改变
465 | ///
466 | public event MemberHonorChangeEvent OnEventMemberHonorChangeEvent;
467 | ///
468 | /// 新好友请求
469 | ///
470 | /// 好友请求句柄
471 | public delegate void NewFriendRequestEvent(Event.NewFriendRequestEvent e);
472 | ///
473 | /// 接收到新好友请求
474 | ///
475 | public event NewFriendRequestEvent OnEventNewFriendRequestEvent;
476 | ///
477 | /// 用户入群申请
478 | ///
479 | /// 用户入群申请句柄
480 | public delegate void MemberJoinRequestEvent(Event.MemberJoinRequestEvent e);
481 | ///
482 | /// 接收到用户入群申请
483 | ///
484 | public event MemberJoinRequestEvent OnEventMemberJoinRequestEvent;
485 | ///
486 | /// Bot被邀请入群
487 | ///
488 | /// 被邀请入群句柄
489 | public delegate void BotInvitedJoinGroupRequestEvent(Event.BotInvitedJoinGroupRequestEvent e);
490 | ///
491 | /// 接收到Bot被邀请入群申请
492 | ///
493 | public event BotInvitedJoinGroupRequestEvent OnEventBotInvitedJoinGroupRequestEvent;
494 | }
495 | }
496 |
--------------------------------------------------------------------------------
/GlobalDefines/Message.cs:
--------------------------------------------------------------------------------
1 | /* 消息类型定义文件
2 | * 本文件和 https://github.com/project-mirai/mirai-api-http/blob/master/docs/api/MessageType.md 文件形成一对一映射关系
3 | * 所有消息类都会派生自基类 Message, 除了闪照派生自Image类外, 其他所有类均为密封类(最终类), 防止不正常的继承关系
4 | * 理论上来讲, 如果官方不更改解析操作, 除了Mirai码, 其他消息会由 ClientParser 进行解析并且形成一个 Message[] 数组
5 | * 关于信息类的类构造的操作类的标准文件以及Mirai码, 请访问: https://github.com/mamoe/mirai/blob/dev/docs/Messages.md
6 | * ------------------------------
7 | * Message Type Defines File
8 | * this file is one to one match of website: https://github.com/project-mirai/mirai-api-http/blob/master/docs/api/MessageType.md
9 | * all class is directed inherit/derive from Base-class Message, except the class "FlashImage" is from Image.
10 | * all class is sealed(final)-class, due to prevent unexpect relation of inherit/derive
11 | * theoretically, if not officially alter the parser pattern,
12 | * except 'Mirai Code', all other message will be parsing into an Array of message as 'Message[]'
13 | * for more of message and classes standard or Mirai Code, Visit website: https://github.com/mamoe/mirai/blob/dev/docs/Messages.md
14 | */
15 |
16 | namespace MeowMiraiLib.Msg.Type
17 | {
18 | ///
19 | /// 信息类的公开定义
20 | ///
21 | public class Message
22 | {
23 | ///
24 | /// 信息类型
25 | ///
26 | public string type { get; protected set; }
27 | }
28 | ///
29 | /// 源类型(永远为信息链的第一个元素)
30 | ///
31 | public sealed class Source : Message
32 | {
33 | ///
34 | /// 消息的识别号,用于引用回复
35 | ///
36 | public long id { get; }
37 | ///
38 | /// 时间戳
39 | ///
40 | public long time { get; }
41 | ///
42 | /// 源类型(永远为信息链的第一个元素)
43 | ///
44 | ///
45 | ///
46 | public Source(long id, long time)
47 | {
48 | this.id = id;
49 | this.time = time;
50 | this.type = nameof(Source);
51 | }
52 | }
53 | ///
54 | /// 回复类信息
55 | ///
56 | public sealed class Quote : Message
57 | {
58 | ///
59 | /// 被引用回复的原消息的messageId
60 | ///
61 | public long id { get; }
62 | ///
63 | /// 被引用回复的原消息所接收的群号,当为好友消息时为0
64 | ///
65 | public long groupId { get; }
66 | ///
67 | /// 被引用回复的原消息的发送者的QQ号
68 | ///
69 | public long senderId { get; }
70 | ///
71 | /// 被引用回复的原消息的接收者者的QQ号(或群号)
72 | ///
73 | public long targetId { get; }
74 | ///
75 | /// 被引用回复的原消息的消息链对象
76 | ///
77 | public Message[] origin { get; }
78 | ///
79 | /// 回复类信息
80 | ///
81 | ///
82 | ///
83 | ///
84 | ///
85 | ///
86 | public Quote(long id, long groupId, long senderId, long targetId, Message[] origin)
87 | {
88 | this.id = id;
89 | this.groupId = groupId;
90 | this.senderId = senderId;
91 | this.targetId = targetId;
92 | this.origin = origin;
93 | this.type = nameof(Quote);
94 | }
95 | }
96 | ///
97 | /// @类信息
98 | ///
99 | public sealed class At : Message
100 | {
101 | ///
102 | /// 群员QQ号
103 | ///
104 | public long target { get; }
105 | ///
106 | /// At时显示的文字,发送消息时无效,自动使用群名片
107 | ///
108 | public string display { get; }
109 | ///
110 | /// @类信息
111 | ///
112 | ///
113 | ///
114 | public At(long target, string display)
115 | {
116 | this.target = target;
117 | this.display = display;
118 | this.type = nameof(At);
119 | }
120 | }
121 | ///
122 | /// @全体类信息
123 | ///
124 | public sealed class AtAll : Message
125 | {
126 | ///
127 | /// @全体类信息
128 | ///
129 | public AtAll()
130 | {
131 | this.type = nameof(AtAll);
132 | }
133 | }
134 | ///
135 | /// 小图脸
136 | ///
137 | public sealed class Face : Message
138 | {
139 | ///
140 | /// QQ表情编号,可选,优先高于name
141 | ///
142 | public long faceId { get; }
143 | ///
144 | /// QQ表情拼音,可选
145 | ///
146 | public string name { get; }
147 | ///
148 | /// 小图脸
149 | ///
150 | /// QQ表情编号,可选,优先高于name
151 | /// QQ表情拼音,可选
152 | public Face(long faceId, string name)
153 | {
154 | this.faceId = faceId;
155 | this.name = name;
156 | this.type = nameof(Face);
157 | }
158 | }
159 | ///
160 | /// 文字消息
161 | ///
162 | public sealed class Plain : Message
163 | {
164 | ///
165 | /// 文字
166 | ///
167 | public string text { get; }
168 | ///
169 | /// 文字消息
170 | ///
171 | /// 文字
172 | public Plain(string text)
173 | {
174 | this.text = text;
175 | this.type = nameof(Plain);
176 | }
177 | }
178 | ///
179 | /// 图片信息
180 | ///
181 | public class Image : Message
182 | {
183 | ///
184 | /// 图片的imageId,群图片与好友图片格式不同。不为空时将忽略url属性
185 | ///
186 | public string? imageId { get; } = null;
187 | ///
188 | /// 图片的URL,发送时可作网络图片的链接;接收时为腾讯图片服务器的链接,可用于图片下载
189 | ///
190 | public string? url { get; } = null;
191 | ///
192 | /// 图片的路径,发送本地图片,路径相对于 JVM 工作路径(默认是当前路径,可通过 -Duser.dir=...指定),也可传入绝对路径。
193 | ///
194 | public string? path { get; } = null;
195 | ///
196 | /// 图片的 Base64 编码
197 | ///
198 | public string? base64 { get; } = null;
199 | ///
200 | /// 图片信息(构造参数任选其一,出现多个参数时,按照imageId > url > path > base64的优先级)
201 | ///
202 | /// 图片的imageId,群图片与好友图片格式不同。不为空时将忽略url属性
203 | /// 图片的URL,发送时可作网络图片的链接;接收时为腾讯图片服务器的链接,可用于图片下载
204 | /// 图片的路径,发送本地图片,路径相对于 JVM 工作路径(默认是当前路径,可通过 -Duser.dir=...指定),也可传入绝对路径。
205 | /// 图片的 Base64 编码
206 | public Image(string imageId = null, string url = null, string path = null, string base64 = null)
207 | {
208 | this.imageId = imageId;
209 | this.url = url;
210 | this.path = path;
211 | this.base64 = base64;
212 | this.type = nameof(Image);
213 | }
214 | }
215 | ///
216 | /// 闪照图片信息
217 | ///
218 | public sealed class FlashImage : Image
219 | {
220 | ///
221 | /// 闪照图片(构造参数任选其一,出现多个参数时,按照imageId > url > path > base64的优先级)
222 | ///
223 | /// 图片的imageId,群图片与好友图片格式不同。不为空时将忽略url属性
224 | /// 图片的URL,发送时可作网络图片的链接;接收时为腾讯图片服务器的链接,可用于图片下载
225 | /// 图片的路径,发送本地图片,路径相对于 JVM 工作路径(默认是当前路径,可通过 -Duser.dir=...指定),也可传入绝对路径。
226 | /// 图片的 Base64 编码
227 | public FlashImage(string imageId = null, string url = null, string path = null, string base64 = null) : base(imageId, url, path, base64)
228 | {
229 | this.type = nameof(FlashImage);
230 | }
231 | }
232 | ///
233 | /// 语音信息
234 | ///
235 | public sealed class Voice : Message
236 | {
237 | ///
238 | /// 语音的voiceId,不为空时将忽略url属性
239 | ///
240 | public string voiceId { get; } = null;
241 | ///
242 | /// 语音的URL,发送时可作网络语音的链接;接收时为腾讯语音服务器的链接,可用于语音下载
243 | ///
244 | public string url { get; } = null;
245 | ///
246 | /// 语音的路径,发送本地语音,路径相对于 JVM 工作路径(默认是当前路径,可通过 -Duser.dir=...指定),也可传入绝对路径。
247 | ///
248 | public string path { get; } = null;
249 | ///
250 | /// 语音的 Base64 编码
251 | ///
252 | public string base64 { get; } = null;
253 | ///
254 | /// 返回的语音长度, 发送消息时可以不传
255 | ///
256 | public long length { get; }
257 | ///
258 | /// 语音信息(构造参数任选其一,出现多个参数时,按照voiceId > url > path > base64的优先级)
259 | ///
260 | /// 语音的voiceId,不为空时将忽略url属性
261 | /// 语音的URL,发送时可作网络语音的链接;接收时为腾讯语音服务器的链接,可用于语音下载
262 | /// 语音的路径,发送本地语音,路径相对于 JVM 工作路径(默认是当前路径,可通过 -Duser.dir=...指定),也可传入绝对路径。
263 | /// 语音的 Base64 编码
264 | /// 返回的语音长度, 发送消息时可以不传
265 | public Voice(string voiceId = null, string url = null, string path = null, string base64 = null, long length = 0)
266 | {
267 | this.voiceId = voiceId;
268 | this.url = url;
269 | this.path = path;
270 | this.base64 = base64;
271 | this.length = length;
272 | this.type = nameof(Voice);
273 | }
274 | }
275 | ///
276 | /// XML信息
277 | ///
278 | public sealed class Xml : Message
279 | {
280 | ///
281 | /// XML文本
282 | ///
283 | public string xml { get; }
284 | ///
285 | /// XML信息
286 | ///
287 | /// XML文本
288 | public Xml(string xml)
289 | {
290 | this.xml = xml;
291 | this.type = nameof(Xml);
292 | }
293 | }
294 | ///
295 | /// Json信息
296 | ///
297 | public sealed class Json : Message
298 | {
299 | ///
300 | /// Json文本
301 | ///
302 | public string json { get; }
303 | ///
304 | /// Json信息
305 | ///
306 | /// Json文本
307 | public Json(string json)
308 | {
309 | this.json = json;
310 | this.type = nameof(Json);
311 | }
312 | }
313 | ///
314 | /// 应用消息
315 | ///
316 | public sealed class App : Message
317 | {
318 | ///
319 | /// 内容
320 | ///
321 | public string content { get; }
322 | ///
323 | /// 应用消息
324 | ///
325 | /// 内容
326 | public App(string content)
327 | {
328 | this.content = content;
329 | this.type = nameof(App);
330 | }
331 | }
332 | ///
333 | /// 窗口震动(戳一戳)
334 | ///
335 | public sealed class Poke : Message
336 | {
337 | ///
338 | /// 戳一戳的类型
339 | /// "Poke": 戳一戳 "ShowLove": 比心 "Like": 点赞 "Heartbroken": 心碎 "SixSixSix": 666 "FangDaZhao": 放大招
340 | ///
341 | public string name { get; }
342 | ///
343 | /// 窗口震动(戳一戳)
344 | ///
345 | /// 戳一戳的类型 {"Poke": 戳一戳 "ShowLove": 比心 "Like": 点赞 "Heartbroken": 心碎 "SixSixSix": 666 "FangDaZhao": 放大招}
346 | public Poke(string name)
347 | {
348 | this.name = name;
349 | this.type = nameof(Poke);
350 | }
351 | }
352 | ///
353 | /// 骰子信息
354 | ///
355 | public sealed class Dice : Message
356 | {
357 | ///
358 | /// 数值
359 | ///
360 | public int value { get; }
361 | ///
362 | /// 骰子信息
363 | ///
364 | /// 数值
365 | public Dice(int value)
366 | {
367 | this.value = value;
368 | this.type = nameof(Dice);
369 | }
370 | }
371 | ///
372 | /// 音乐分享信息
373 | ///
374 | public sealed class MusicShare : Message
375 | {
376 | ///
377 | /// 类型
378 | ///
379 | public string kind { get; }
380 | ///
381 | /// 标题
382 | ///
383 | public string title { get; }
384 | ///
385 | /// 概括
386 | ///
387 | public string summary { get; }
388 | ///
389 | /// 跳转路径
390 | ///
391 | public string jumpUrl { get; }
392 | ///
393 | /// 封面路径
394 | ///
395 | public string pictureUrl { get; }
396 | ///
397 | /// 音乐路径
398 | ///
399 | public string musicUrl { get; }
400 | ///
401 | /// 简介
402 | ///
403 | public string brief { get; }
404 | ///
405 | /// 生成音乐分享
406 | ///
407 | /// 类型
408 | /// 标题
409 | /// 概括
410 | /// 跳转路径
411 | /// 封面路径
412 | /// 音乐路径
413 | /// 简介
414 | public MusicShare(string kind, string title, string summary, string jumpUrl, string pictureUrl, string musicUrl, string brief)
415 | {
416 | this.kind = kind;
417 | this.title = title;
418 | this.summary = summary;
419 | this.jumpUrl = jumpUrl;
420 | this.pictureUrl = pictureUrl;
421 | this.musicUrl = musicUrl;
422 | this.brief = brief;
423 | this.type = nameof(MusicShare);
424 | }
425 | }
426 | ///
427 | /// 转发信息
428 | ///
429 | public sealed class ForwardMessage : Message
430 | {
431 | ///
432 | /// 转发信息节点
433 | ///
434 | public class Node
435 | {
436 | ///
437 | /// 引用缓存中其他对话上下文的消息作为节点
438 | ///
439 | public struct MessageReferenceNode
440 | {
441 | ///
442 | /// 引用的 messageId
443 | ///
444 | public long messageId { get; }
445 | ///
446 | /// 引用的上下文目标,群号、好友账号
447 | ///
448 | public long target { get; }
449 | ///
450 | /// 引用缓存中其他对话上下文的消息作为节点
451 | ///
452 | /// 引用的 messageId
453 | /// 引用的上下文目标,群号、好友账号
454 | public MessageReferenceNode(long messageId, long target)
455 | {
456 | this.messageId = messageId;
457 | this.target = target;
458 | }
459 | }
460 |
461 | ///
462 | /// 发送人QQ号
463 | ///
464 | public long senderId { get; }
465 | ///
466 | /// 时间
467 | ///
468 | public long time { get; }
469 | ///
470 | /// 显示名称
471 | ///
472 | public string senderName { get; }
473 | ///
474 | /// 转发的消息数组
475 | ///
476 | public Message[] messageChain { get; }
477 | ///
478 | /// 转发的消息数组
479 | ///
480 | public long messageId { get; }
481 | ///
482 | /// 引用缓存中其他对话上下文的消息作为节点
483 | ///
484 | public MessageReferenceNode messageRef { get; }
485 | ///
486 | /// 源ID
487 | ///
488 | public long sourceId { get; }
489 |
490 |
491 | ///
492 | /// 转发消息节点
493 | ///
494 | /// 发送人QQ号
495 | /// 时间
496 | /// 显示名称
497 | /// 转发的消息数组
498 | /// 源ID
499 | public Node(long senderId, long time, string senderName, Message[] messageChain, long sourceId)
500 | {
501 | this.senderId = senderId;
502 | this.time = time;
503 | this.senderName = senderName;
504 | this.messageChain = messageChain;
505 | this.sourceId = sourceId;
506 | }
507 | ///
508 | /// 转发消息节点(只使用消息messageId)
509 | ///
510 | /// 发送人QQ号
511 | /// 时间
512 | /// 显示名称
513 | /// 消息messageId
514 | /// 源ID
515 | public Node(long senderId, long time, string senderName, long messageId, long sourceId)
516 | {
517 | this.senderId = senderId;
518 | this.time = time;
519 | this.senderName = senderName;
520 | this.messageId = messageId;
521 | this.sourceId = sourceId;
522 | }
523 | ///
524 | /// 转发消息节点(使用其他对话上下文的消息作为节点)
525 | ///
526 | /// 发送人QQ号
527 | /// 时间
528 | /// 显示名称
529 | /// 引用缓存中其他对话上下文的消息作为节点
530 | /// 源ID
531 | public Node(long senderId, long time, string senderName, MessageReferenceNode messageRef, long sourceId)
532 | {
533 | this.senderId = senderId;
534 | this.time = time;
535 | this.senderName = senderName;
536 | this.messageRef = messageRef;
537 | this.sourceId = sourceId;
538 | }
539 | }
540 | ///
541 | /// 消息节点列表
542 | ///
543 | public Node[] nodeList { get; }
544 | ///
545 | /// 转发消息
546 | ///
547 | /// 转发的节点
548 | public ForwardMessage(Node[] nodeList)
549 | {
550 | this.nodeList = nodeList;
551 | this.type = nameof(ForwardMessage);
552 | }
553 | }
554 | ///
555 | /// 文件信息
556 | ///
557 | public sealed class File : Message
558 | {
559 | ///
560 | /// 文件识别ID
561 | ///
562 | public string id { get; }
563 | ///
564 | /// 文件名
565 | ///
566 | public string name { get; }
567 | ///
568 | /// 文件大小
569 | ///
570 | public long size { get; }
571 | ///
572 | /// 文件信息
573 | ///
574 | /// 文件识别ID
575 | /// 文件名
576 | /// 文件大小
577 | public File(string id, string name, long size)
578 | {
579 | this.id = id;
580 | this.name = name;
581 | this.size = size;
582 | this.type = nameof(File);
583 | }
584 | }
585 | ///
586 | /// Mirai代码
587 | ///
588 | public sealed class MiraiCode : Message
589 | {
590 | ///
591 | /// Mirai代码
592 | ///
593 | public string code { get; }
594 | ///
595 | /// Mirai码
596 | /// 关于Mirai码的对照: https://github.com/mamoe/mirai/blob/dev/docs/Messages.md
597 | ///
598 | /// 代码
599 | public MiraiCode(string code)
600 | {
601 | this.code = code;
602 | }
603 | }
604 | ///
605 | /// 商城表情
606 | ///
607 | public sealed class MarketFace : Message
608 | {
609 | ///
610 | /// 商城表情唯一标识
611 | ///
612 | public int id { get; }
613 | ///
614 | /// 表情显示名称
615 | ///
616 | public string name { get; }
617 | ///
618 | /// 构造一个商城表情
619 | /// 目前商城表情仅支持接收和转发,不支持构造发送
620 | ///
621 | /// 商城表情唯一标识
622 | /// 表情显示名称
623 | public MarketFace(int id, string name)
624 | {
625 | this.id = id;
626 | this.name = name;
627 | }
628 | }
629 | }
630 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | SPDX identifier
2 | AGPL-3.0-only
3 |
4 | License text
5 | GNU AFFERO GENERAL PUBLIC LICENSE
6 |
7 | Version 3, 19 November 2007
8 | Copyright (C) 2007 Free Software Foundation, Inc.
9 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
10 |
11 | Preamble
12 | The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
13 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.
14 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
15 | Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
16 | A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
17 | The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
18 | An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
19 | The precise terms and conditions for copying, distribution and modification follow.
20 |
21 | TERMS AND CONDITIONS
22 |
23 | 0. Definitions.
24 | "This License" refers to version 3 of the GNU Affero General Public License.
25 | "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
26 | "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
27 | To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
28 | A "covered work" means either the unmodified Program or a work based on the Program.
29 | To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
30 | To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
31 | An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
32 |
33 | 1. Source Code.
34 | The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
35 | A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
36 | The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
37 | The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those
38 | subprograms and other parts of the work.
39 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
40 | The Corresponding Source for a work in source code form is that same work.
41 |
42 | 2. Basic Permissions.
43 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
44 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
45 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
46 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
47 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
48 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
49 |
50 | 4. Conveying Verbatim Copies.
51 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
52 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
53 |
54 | 5. Conveying Modified Source Versions.
55 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
56 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
57 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
58 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
59 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
60 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
61 |
62 | 6. Conveying Non-Source Forms.
63 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
64 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
65 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
66 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
67 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
68 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
69 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
70 | A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
71 | "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
72 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
73 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
74 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
75 |
76 | 7. Additional Terms.
77 | "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
78 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
79 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
80 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
81 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
82 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
83 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
84 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
85 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
86 | All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
87 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
88 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
89 |
90 | 8. Termination.
91 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
92 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
93 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
94 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
95 |
96 | 9. Acceptance Not Required for Having Copies.
97 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
98 |
99 | 10. Automatic Licensing of Downstream Recipients.
100 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
101 | An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
102 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
103 |
104 | 11. Patents.
105 | A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
106 | A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
107 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
108 | In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
109 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent
110 | license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
111 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
112 | A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
113 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
114 |
115 | 12. No Surrender of Others' Freedom.
116 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may
117 | not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
118 |
119 | 13. Remote Network Interaction; Use with the GNU General Public License.
120 | Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.
121 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License.
122 |
123 | 14. Revised Versions of this License.
124 | The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
125 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation.
126 | If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
127 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
128 |
129 | 15. Disclaimer of Warranty.
130 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
131 |
132 | 16. Limitation of Liability.
133 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
134 |
135 | 17. Interpretation of Sections 15 and 16.
136 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS
137 |
138 | How to Apply These Terms to Your New Programs
139 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
140 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
141 |
142 | Copyright (C) 2021 DavidSciMeow
143 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
144 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
145 | You should have received a copy of the GNU Affero General Public License along with this program. If not, see .
146 | Also add information on how to contact you by electronic and paper mail.
147 | If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
148 | You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see .
149 |
--------------------------------------------------------------------------------
/GlobalDefines/SSM.cs:
--------------------------------------------------------------------------------
1 | using MeowMiraiLib.Msg.Type;
2 | using System;
3 | using Newtonsoft.Json;
4 | using Newtonsoft.Json.Linq;
5 | using System.Threading.Tasks;
6 | using MeowMiraiLib.GenericModel;
7 |
8 | /*
9 | * 本文件是发送信息的标准定义文件,
10 | * 文件内容与 https://github.com/project-mirai/mirai-api-http/blob/master/docs/api/API.md 和 https://github.com/project-mirai/mirai-api-http/blob/master/docs/adapter/WebsocketAdapter.md 一一对应
11 | * 发送定义为 SSM (Socket Sendable Message) 类,
12 | * 版本 8.1.0 更改了标准发送的Client类为可选, 如果您默认不传入则使用全局端进行发送, 方便编写程序.
13 | * --------------------------
14 | * this file is by define message send function/method
15 | * this file is one to one match to website https://github.com/project-mirai/mirai-api-http/blob/master/docs/api/API.md and https://github.com/project-mirai/mirai-api-http/blob/master/docs/adapter/WebsocketAdapter.md
16 | * Sender function/method defines class is SSM (Socket Sendable Message) class.
17 | * version 8.1.0+ alters the Basic Code in Func:SendAsync Client now is [Optional],
18 | * if you leave blank, the program will using the Global-Client to deliver the Message. using this trick for Easy Edit Program.
19 | */
20 |
21 | namespace MeowMiraiLib.Msg
22 | {
23 | #region 消息合成类
24 | ///
25 | /// 资料类逻辑处理类
26 | ///
27 | public abstract class ProfileClassGeneral : SSM
28 | {
29 | ///
30 | /// 获取资料
31 | ///
32 | /// 要发送到的客户端
33 | /// 同步的id(默认自动生成)
34 | /// 超时取消,默认10s(秒)
35 | ///
36 | public QQProfile Send(Client? c = null, int? syncid = null, int TimeOut = 10) => SendAsync(c, syncid, TimeOut).GetAwaiter().GetResult();
37 | ///
38 | /// 获取资料
39 | ///
40 | /// 要发送到的客户端
41 | /// 同步的id(默认自动生成)
42 | /// 超时取消,默认10s(秒)
43 | ///
44 | public Task SendAsync(Client? c = null, int? syncid = null, int TimeOut = 10)
45 | {
46 | return Task.Run(async () =>
47 | {
48 | var (a, b) = await base.OSendAsync(c, syncid, TimeOut);
49 | if (!a)
50 | {
51 | return JsonConvert.DeserializeObject(b["data"].ToString());
52 | }
53 | else
54 | {
55 | return null;
56 | }
57 | });
58 | }
59 | }
60 | ///
61 | /// 信息类合并逻辑类
62 | ///
63 | public abstract class MessageTypoGeneral : SSM
64 | {
65 | ///
66 | /// 发送信息
67 | ///
68 | /// 要发送到的客户端
69 | /// 同步的id(默认自动生成)
70 | /// 超时取消,默认10s(秒)
71 | ///
72 | public MessageId Send(Client? c = null, int? syncid = null, int TimeOut = 10) => SendAsync(c, syncid, TimeOut).GetAwaiter().GetResult();
73 | ///
74 | /// 发送信息
75 | ///
76 | /// 要发送到的客户端
77 | /// 同步的id(默认自动生成)
78 | /// 超时取消,默认10s(秒)
79 | ///
80 | public Task SendAsync(Client? c = null, int? syncid = null, int TimeOut = 10)
81 | {
82 | return Task.Run(async () =>
83 | {
84 | var (a, b) = await base.OSendAsync(c, syncid, TimeOut);
85 | if (!a)
86 | {
87 | return new MessageId(JsonConvert.DeserializeObject(b?["data"]?["messageId"]?.ToString() ?? "-1"), c);
88 | }
89 | else
90 | {
91 | return new MessageId(-1, c);
92 | }
93 | });
94 | }
95 | }
96 | ///
97 | /// 确认类型消息合成类
98 | ///
99 | public abstract class ConfirmationTypoGeneral : SSM
100 | {
101 | ///
102 | /// 发送
103 | ///
104 | /// 要发送到的客户端
105 | /// 同步的id(默认自动生成)
106 | /// 超时取消,默认10s(秒)
107 | ///
108 | public int Send(Client? c = null, int? syncid = null, int TimeOut = 10) => SendAsync(c, syncid, TimeOut).GetAwaiter().GetResult();
109 | ///
110 | /// 发送
111 | ///
112 | /// 要发送到的客户端
113 | /// 同步的id(默认自动生成)
114 | /// 超时取消,默认10s(秒)
115 | ///
116 | public Task SendAsync(Client? c = null, int? syncid = null, int TimeOut = 10)
117 | {
118 | return Task.Run(async () =>
119 | {
120 | var (a, b) = await base.OSendAsync(c, syncid, TimeOut);
121 | if (!a)
122 | {
123 | return JsonConvert.DeserializeObject(b["data"]["code"].ToString());
124 | }
125 | else
126 | {
127 | return -1;
128 | }
129 | });
130 | }
131 | }
132 | #endregion
133 |
134 | ///
135 | /// Socket Send Message (命令报文)
136 | ///
137 | public class SSM
138 | {
139 | ///
140 | /// 同步id
141 | ///
142 | public int? syncId { get; protected set; }
143 | ///
144 | /// 命令字段
145 | ///
146 | public string command { get; protected set; }
147 | ///
148 | /// 子命令字段
149 | ///
150 | public string? subCommand { get; protected set; } = null;
151 | ///
152 | /// 内容
153 | ///
154 | public dynamic content { get; protected set; }
155 | ///
156 | /// Session标识
157 | ///
158 | public string session { get; protected set; }
159 |
160 | private string PackMsg(int? syncid = null)
161 | {
162 | string s;
163 | if (syncid != null)
164 | {
165 | syncId = syncid;
166 | }
167 | else
168 | {
169 | syncId = new Random().Next(int.MaxValue);
170 | }
171 | if (content is SMessage)
172 | {
173 | s = JsonConvert.SerializeObject(this, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
174 | }
175 | else
176 | {
177 | s = JsonConvert.SerializeObject(new { syncId, session, command, subCommand, content }, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
178 | }
179 | return s;
180 | }
181 | ///
182 | /// 发送信息
183 | ///
184 | /// 要发送到的客户端
185 | /// 同步的id(默认自动生成)
186 | /// 超时取消,默认10s(秒)
187 | ///
188 | public (bool isTimedOut, JObject? Return) OSend(Client? c = null, int? syncid = null, int TimeOut = 10) => OSendAsync(c, syncid, TimeOut).GetAwaiter().GetResult();
189 | ///
190 | /// 异步发送信息
191 | ///
192 | /// 要发送到的客户端
193 | /// 同步的id(默认自动生成)
194 | /// 超时取消,默认10s(秒)
195 | ///
196 | public async Task<(bool isTimedOut, JObject? Return)> OSendAsync(Client? c = null, int? syncid = null, int TimeOut = 10)
197 | {
198 | if (c is null)
199 | {
200 | if (Global.G_Client is null)
201 | {
202 | Global.Log.Error(ErrorDefine.E2000);
203 | throw new(ErrorDefine.E2000);
204 | }
205 | else
206 | {
207 | session = Global.G_Client.session;
208 | var ms = PackMsg(syncid);
209 | return await Global.G_Client.SendAndWaitResponse(ms, syncId, TimeOut);
210 | }
211 | }
212 | else
213 | {
214 | session = c.session;
215 | var ms = PackMsg(syncid);
216 | return await c.SendAndWaitResponse(ms, syncId, TimeOut);
217 | }
218 | }
219 | ///
220 | /// 逻辑模式获取消息
221 | ///
222 | /// 逻辑模式
223 | /// 要发送到的客户端
224 | /// 同步的id(默认自动生成)
225 | /// 超时取消,默认10s(秒)
226 | ///
227 | protected T Send(Client? c = null, int? syncid = null, int TimeOut = 10) => SendAsync(c, syncid, TimeOut).GetAwaiter().GetResult();
228 | ///
229 | /// 异步逻辑模式发送信息
230 | ///
231 | /// 逻辑模式
232 | /// 要发送到的客户端
233 | /// 同步的id(默认自动生成)
234 | /// 超时取消,默认10s(秒)
235 | ///
236 | protected async Task SendAsync(Client? c = null, int? syncid = null, int TimeOut = 10)
237 | {
238 | if (c is null)
239 | {
240 | if (Global.G_Client is null)
241 | {
242 | Global.Log.Error(ErrorDefine.E2000);
243 | throw new(ErrorDefine.E2000);
244 | }
245 | else
246 | {
247 | session = Global.G_Client.session;
248 | var ms = PackMsg(syncid);
249 | var (a, b) = await Global.G_Client.SendAndWaitResponse(ms, syncId, TimeOut);
250 | if (!a)
251 | {
252 | return JsonConvert.DeserializeObject(b["data"]["data"].ToString());
253 | }
254 | else
255 | {
256 | return default;
257 | }
258 | }
259 | }
260 | else
261 | {
262 | session = c.session;
263 | var ms = PackMsg(syncid);
264 | var (a, b) = await c.SendAndWaitResponse(ms, syncId, TimeOut);
265 | if (!a)
266 | {
267 | return JsonConvert.DeserializeObject(b["data"]["data"].ToString());
268 | }
269 | else
270 | {
271 | return default;
272 | }
273 | }
274 | }
275 | }
276 |
277 | ///
278 | /// 发送的QQ信息
279 | ///
280 | public class SMessage
281 | {
282 | ///
283 | /// 目标
284 | ///
285 | public long? target { get; } = null;
286 | ///
287 | /// 备用字段,目标
288 | ///
289 | public long? qq { get; } = null;
290 | ///
291 | /// 群目标
292 | ///
293 | public long? group { get; } = null;
294 | ///
295 | /// 引用字段,回复字段
296 | ///
297 | public long? quote { get; } = null;
298 | ///
299 | /// 信息链
300 | ///
301 | public Message[] messageChain;
302 | ///
303 | /// 构造一个SendableMessage
304 | ///
305 | /// 发送目标
306 | /// 群
307 | /// 信息链
308 | /// 引用字段
309 | public SMessage(long qq, long group, Message[] messageChain, long? quote = null)
310 | {
311 | this.qq = qq;
312 | this.group = group;
313 | this.quote = quote;
314 | this.messageChain = messageChain;
315 | }
316 | ///
317 | /// 构造一个SendableMessage
318 | ///
319 | /// 目标
320 | /// 信息链
321 | /// 引用字段
322 | /// 发送目标(备用)
323 | /// 群
324 | public SMessage(long target, Message[] messageChain,
325 | long? quote = null, long? qq = null, long? group = null)
326 | {
327 | this.target = target;
328 | this.quote = quote;
329 | this.messageChain = messageChain;
330 | this.qq = qq;
331 | this.group = group;
332 | }
333 | }
334 |
335 | #region 获取插件信息 && 缓存操作
336 | ///
337 | /// 获取插件信息
338 | ///
339 | public sealed class About : SSM
340 | {
341 | ///
342 | /// 获取插件信息
343 | ///
344 | public About()
345 | {
346 | command = "about";
347 | }
348 | }
349 | ///
350 | /// 通过MessageId获取消息
351 | ///
352 | public sealed class MessageFromId : SSM
353 | {
354 | ///
355 | /// 通过MessageId获取消息
356 | ///
357 | /// 信息id
358 | public MessageFromId(long id)
359 | {
360 | command = "messageFromId";
361 | content = new
362 | {
363 | sessionKey = session,
364 | id
365 | };
366 | }
367 | }
368 | #endregion
369 |
370 | #region 获取账号信息
371 | ///
372 | /// 获取好友列表
373 | ///
374 | public sealed class FriendList : SSM
375 | {
376 | ///
377 | /// 获取好友列表
378 | ///
379 | public FriendList()
380 | {
381 | command = "friendList";
382 | content = new
383 | {
384 | sessionKey = session
385 | };
386 | }
387 | ///
388 | public QQFriend[] Send(Client? c = null, int? syncid = null, int TimeOut = 10) => SendAsync(c, syncid, TimeOut).GetAwaiter().GetResult();
389 | ///
390 | public Task SendAsync(Client? c = null, int? syncid = null, int TimeOut = 10) => base.SendAsync(c, syncid, TimeOut);
391 | }
392 | ///
393 | /// 获取群列表
394 | ///
395 | public sealed class GroupList : SSM
396 | {
397 | ///
398 | /// 获取群列表
399 | ///
400 | public GroupList()
401 | {
402 | command = "groupList";
403 | content = new
404 | {
405 | sessionKey = session
406 | };
407 | }
408 | ///
409 | public QQGroup[]? Send(Client? c = null, int? syncid = null, int TimeOut = 10) => SendAsync(c, syncid, TimeOut).GetAwaiter().GetResult();
410 | ///
411 | public Task SendAsync(Client? c = null, int? syncid = null, int TimeOut = 10) => base.SendAsync(c, syncid, TimeOut);
412 | }
413 | ///
414 | /// 获取群员列表
415 | ///
416 | public sealed class MemberList : SSM
417 | {
418 | ///
419 | /// 获取群员列表
420 | ///
421 | /// 目标群
422 | public MemberList(long target)
423 | {
424 | command = "memberList";
425 | content = new
426 | {
427 | sessionKey = session,
428 | target
429 | };
430 | }
431 | ///
432 | public QQGroupMember[]? Send(Client? c = null, int? syncid = null, int TimeOut = 10) => SendAsync(c, syncid, TimeOut).GetAwaiter().GetResult();
433 | ///
434 | public Task SendAsync(Client? c = null, int? syncid = null, int TimeOut = 10) => base.SendAsync(c, syncid, TimeOut);
435 | }
436 | ///
437 | /// 获取bot资料
438 | ///
439 | public sealed class BotProfile : ProfileClassGeneral
440 | {
441 | ///
442 | /// 获取bot资料
443 | ///
444 | public BotProfile()
445 | {
446 | command = "botProfile";
447 | content = new
448 | {
449 | sessionKey = session
450 | };
451 | }
452 | }
453 | ///
454 | /// 获取某个好友的资料
455 | ///
456 | public sealed class FriendProfile : ProfileClassGeneral
457 | {
458 | ///
459 | /// 获取某个好友的资料
460 | ///
461 | /// 好友QQ
462 | public FriendProfile(long qq)
463 | {
464 | command = "friendProfile";
465 | content = new
466 | {
467 | sessionKey = session,
468 | target = qq
469 | };
470 | }
471 | }
472 | ///
473 | /// 获取某个群友的资料
474 | ///
475 | public sealed class MemberProfile : ProfileClassGeneral
476 | {
477 | ///
478 | /// 获取群友资料
479 | ///
480 | /// 群号
481 | /// 群员QQ
482 | public MemberProfile(long qqgroup, long qq)
483 | {
484 | command = "memberProfile";
485 | content = new
486 | {
487 | sessionKey = session,
488 | target = qqgroup,
489 | memberId = qq
490 | };
491 | }
492 | }
493 | ///
494 | /// 获取某个QQ用户的资料
495 | ///
496 | public sealed class UserProfile : ProfileClassGeneral
497 | {
498 | ///
499 | /// 获取某个QQ用户的资料
500 | ///
501 | public UserProfile(long target)
502 | {
503 | command = "userProfile";
504 | content = new
505 | {
506 | sessionKey = session,
507 | target,
508 | };
509 | }
510 | }
511 | #endregion
512 |
513 | #region 消息发送与撤回
514 | ///
515 | /// 发送好友信息
516 | ///
517 | public sealed class FriendMessage : MessageTypoGeneral
518 | {
519 | ///
520 | /// 发送好友信息
521 | ///
522 | /// 可选,发送消息目标好友的QQ号
523 | /// 消息链,是一个消息对象构成的数组
524 | /// 引用一条消息的messageId进行回复
525 | public FriendMessage(long target, Message[] messageChain, long? quote = null)
526 | {
527 | command = "sendFriendMessage";
528 | content = new SMessage(target, messageChain, quote);
529 | }
530 | }
531 | ///
532 | /// 发送群信息
533 | ///
534 | public sealed class GroupMessage : MessageTypoGeneral
535 | {
536 | ///
537 | /// 发送群信息
538 | ///
539 | /// 可选,发送消息目标群的群号
540 | /// 消息链,是一个消息对象构成的数组
541 | /// 引用一条消息的messageId进行回复
542 | public GroupMessage(long target, Message[] messageChain, long? quote = null)
543 | {
544 | command = "sendGroupMessage";
545 | content = new SMessage(target, messageChain, quote);
546 | }
547 | }
548 | ///
549 | /// 发送临时信息
550 | ///
551 | public sealed class TempMessage : MessageTypoGeneral
552 | {
553 | ///
554 | /// 发送临时消息
555 | ///
556 | /// 临时会话对象QQ号
557 | /// 临时会话群号
558 | /// 消息链,是一个消息对象构成的数组
559 | /// 引用一条消息的messageId进行回复
560 | public TempMessage(long qq, long group, Message[] messageChain, long? quote = null)
561 | {
562 | command = "sendTempMessage";
563 | content = new SMessage(qq, group, messageChain, quote);
564 | }
565 | }
566 | ///
567 | /// 发送戳一戳
568 | ///
569 | public sealed class SendNudge : ConfirmationTypoGeneral
570 | {
571 | ///
572 | /// 发送戳一戳
573 | ///
574 | /// 戳一戳的目标, QQ号, 可以为 bot QQ号
575 | /// 戳一戳接受主体(上下文), 戳一戳信息会发送至该主体, 为群号/好友QQ号
576 | /// 上下文类型, 可选值 Friend, Group, Stranger
577 | public SendNudge(long target, long subject, string kind)
578 | {
579 | command = "sendNudge";
580 | content = new
581 | {
582 | sessionKey = session,
583 | target,
584 | subject,
585 | kind
586 | };
587 | }
588 | }
589 | ///
590 | /// 撤回消息
591 | ///
592 | public sealed class Recall : ConfirmationTypoGeneral
593 | {
594 | ///
595 | /// 撤回消息
596 | ///
597 | /// 撤回消息的MessageId
598 | public Recall(long target)
599 | {
600 | command = "recall";
601 | content = new
602 | {
603 | sessionKey = session,
604 | target
605 | };
606 | }
607 | }
608 | #endregion
609 |
610 | #region 文件操作
611 | ///
612 | /// 查看文件列表
613 | ///
614 | public sealed class File_list : SSM
615 | {
616 | ///
617 | /// 查看文件列表
618 | ///
619 | /// 文件夹id, 空串为根目录
620 | /// 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
621 | /// 群号或好友QQ号
622 | /// 群号
623 | /// 好友QQ号
624 | /// 是否携带下载信息,额外请求,无必要不要携带(置空null
625 | /// 分页偏移
626 | /// 分页大小
627 | public File_list(string id, string path, long target, long group, long qq, bool? withDownloadInfo, long offset, long size)
628 | {
629 | command = "file_list";
630 | content = new
631 | {
632 | sessionKey = session,
633 | id,
634 | path,
635 | target,
636 | group,
637 | qq,
638 | withDownloadInfo,
639 | offset,
640 | size
641 | };
642 | }
643 | }
644 | ///
645 | /// 获取文件信息
646 | ///
647 | public sealed class File_info : SSM
648 | {
649 | ///
650 | /// 获取文件信息
651 | ///
652 | /// 文件id,空串为根目录
653 | /// 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
654 | /// 群号或好友QQ号
655 | /// 群号
656 | /// 好友QQ号
657 | /// 是否携带下载信息,额外请求,无必要不要携带
658 | public File_info(string id, string path, long target, long group, long qq, bool? withDownloadInfo)
659 | {
660 | command = "file_info";
661 | content = new
662 | {
663 | sessionKey = session,
664 | id,
665 | path,
666 | target,
667 | group,
668 | qq,
669 | withDownloadInfo
670 | };
671 | }
672 | }
673 | ///
674 | /// 创建文件夹
675 | ///
676 | public sealed class File_mkdir : SSM
677 | {
678 | ///
679 | /// 创建文件夹
680 | ///
681 | /// 父目录id,空串为根目录
682 | /// 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
683 | /// 群号或好友QQ号
684 | /// 群号
685 | /// 好友QQ号
686 | /// 新建文件夹名
687 | public File_mkdir(string id, string path, long target, long group, long qq, string directoryName)
688 | {
689 | command = "file_mkdir";
690 | content = new
691 | {
692 | sessionKey = session,
693 | id,
694 | path,
695 | target,
696 | group,
697 | qq,
698 | directoryName
699 | };
700 | }
701 | }
702 | ///
703 | /// 删除文件
704 | ///
705 | public sealed class File_delete : SSM
706 | {
707 | ///
708 | /// 删除文件
709 | ///
710 | /// 删除文件id
711 | /// 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
712 | /// 群号或好友QQ号
713 | /// 群号
714 | /// 好友QQ号
715 | public File_delete(string id, string path, long target, long group, long qq)
716 | {
717 | command = "file_delete";
718 | content = new
719 | {
720 | sessionKey = session,
721 | id,
722 | path,
723 | target,
724 | group,
725 | qq
726 | };
727 | }
728 | }
729 | ///
730 | /// 移动文件
731 | ///
732 | public sealed class File_move : SSM
733 | {
734 | ///
735 | /// 移动文件
736 | ///
737 | /// 移动文件id
738 | /// 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
739 | /// 群号或好友QQ号
740 | /// 群号
741 | /// 好友QQ号
742 | /// 移动目标文件夹id
743 | /// 移动目标文件路径, 文件夹允许重名, 不保证准确, 准确定位使用 moveTo
744 | public File_move(string id, string path, long target, long group, long qq, string moveTo, string moveToPath)
745 | {
746 | command = "file_move";
747 | content = new
748 | {
749 | sessionKey = session,
750 | id,
751 | path,
752 | target,
753 | group,
754 | qq,
755 | moveTo,
756 | moveToPath
757 | };
758 | }
759 | }
760 | ///
761 | /// 重命名文件
762 | ///
763 | public sealed class File_rename : SSM
764 | {
765 | ///
766 | /// 重命名文件
767 | ///
768 | /// 重命名文件id
769 | /// 文件夹路径, 文件夹允许重名, 不保证准确, 准确定位使用 id
770 | /// 群号或好友QQ号
771 | /// 群号
772 | /// 好友QQ号
773 | /// 新文件名
774 | public File_rename(string id, string path, long target, long group, long qq, string renameTo)
775 | {
776 | command = "file_rename";
777 | content = new
778 | {
779 | sessionKey = session,
780 | id,
781 | path,
782 | target,
783 | group,
784 | qq,
785 | renameTo
786 | };
787 | }
788 | }
789 | #endregion
790 |
791 | #region 账号管理
792 | ///
793 | /// 删除好友
794 | ///
795 | public sealed class DeleteFriend : ConfirmationTypoGeneral
796 | {
797 | ///
798 | /// 删除好友
799 | ///
800 | /// 目标好友
801 | public DeleteFriend(long target)
802 | {
803 | command = "deleteFriend";
804 | content = new
805 | {
806 | sessionKey = session,
807 | target
808 | };
809 | }
810 | }
811 | #endregion
812 |
813 | #region 群管理
814 | ///
815 | /// 禁言群成员
816 | ///
817 | public sealed class Mute : ConfirmationTypoGeneral
818 | {
819 | ///
820 | /// 禁言群成员
821 | ///
822 | /// 指定群的群号
823 | /// 指定群员QQ号
824 | /// 禁言时长,单位为秒,最多30天(2592000),默认为0
825 | public Mute(long target, long memberId, long time)
826 | {
827 | command = "mute";
828 | content = new
829 | {
830 | sessionKey = session,
831 | target,
832 | memberId,
833 | time
834 | };
835 | }
836 | }
837 | ///
838 | /// 解除群成员禁言
839 | ///
840 | public sealed class Unmute : ConfirmationTypoGeneral
841 | {
842 | ///
843 | /// 解除群成员禁言
844 | ///
845 | /// 指定群的群号
846 | /// 指定群员QQ号
847 | public Unmute(long target, long memberId)
848 | {
849 | command = "unmute";
850 | content = new
851 | {
852 | sessionKey = session,
853 | target,
854 | memberId
855 | };
856 | }
857 | }
858 | ///
859 | /// 移除群成员
860 | ///
861 | public sealed class Kick : ConfirmationTypoGeneral
862 | {
863 | ///
864 | /// 移除群成员
865 | ///
866 | /// 指定群的群号
867 | /// 指定群员QQ号
868 | /// 移除后拉黑,默认为 false
869 | /// 信息
870 | public Kick(long target, long memberId, bool block = false, string msg = "您已被移出群聊")
871 | {
872 | command = "kick";
873 | content = new
874 | {
875 | sessionKey = session,
876 | target,
877 | memberId,
878 | block,
879 | msg
880 | };
881 | }
882 | }
883 | ///
884 | /// 退群
885 | ///
886 | public sealed class Quit : ConfirmationTypoGeneral
887 | {
888 | ///
889 | /// 退群
890 | ///
891 | /// 目标群
892 | public Quit(long target)
893 | {
894 | command = "quit";
895 | content = new
896 | {
897 | sessionKey = session,
898 | target
899 | };
900 | }
901 | }
902 | ///
903 | /// 全体禁言
904 | ///
905 | public sealed class MuteAll : ConfirmationTypoGeneral
906 | {
907 | ///
908 | /// 全体禁言
909 | ///
910 | /// 指定群的群号
911 | public MuteAll(long target)
912 | {
913 | command = "muteAll";
914 | content = new
915 | {
916 | sessionKey = session,
917 | target
918 | };
919 | }
920 | }
921 | ///
922 | /// 取消全体禁言
923 | ///
924 | public sealed class UnmuteAll : ConfirmationTypoGeneral
925 | {
926 | ///
927 | /// 取消全体禁言
928 | ///
929 | /// 指定群的群号
930 | public UnmuteAll(long target)
931 | {
932 | command = "unmuteAll";
933 | content = new
934 | {
935 | sessionKey = session,
936 | target
937 | };
938 | }
939 | }
940 | ///
941 | /// 设置群精华消息
942 | ///
943 | public sealed class SetEssence : ConfirmationTypoGeneral
944 | {
945 | ///
946 | /// 设置群精华消息
947 | ///
948 | /// 精华消息的messageId
949 | public SetEssence(long target)
950 | {
951 | command = "setEssence";
952 | content = new
953 | {
954 | sessionKey = session,
955 | target
956 | };
957 | }
958 | }
959 | ///
960 | /// 获取群设置
961 | ///
962 | public sealed class GroupConfig_Get : SSM
963 | {
964 | ///
965 | /// 获取群设置
966 | ///
967 | /// 指定群的群号
968 | public GroupConfig_Get(long target)
969 | {
970 | command = "groupConfig";
971 | subCommand = "get";
972 | content = new
973 | {
974 | sessionKey = session,
975 | target
976 | };
977 | }
978 | ///
979 | public QQGConf Send(Client c, int? syncid = null, int TimeOut = 10) => SendAsync(c, syncid, TimeOut).GetAwaiter().GetResult();
980 | ///
981 | public Task SendAsync(Client c, int? syncid = null, int TimeOut = 10) =>
982 | Task.Run(async () =>
983 | {
984 | var (a, b) = await base.OSendAsync(c, syncid, TimeOut);
985 | if (!a)
986 | {
987 | return JsonConvert.DeserializeObject(b["data"]["config"].ToString());
988 | }
989 | else
990 | {
991 | return null;
992 | }
993 | });
994 | }
995 | ///
996 | /// 修改群设置
997 | ///
998 | public sealed class GroupConfig_Update : ConfirmationTypoGeneral
999 | {
1000 | ///
1001 | /// 修改群设置
1002 | ///
1003 | /// 指定群的群号
1004 | /// 群设置类
1005 | public GroupConfig_Update(long target, GroupConfigSet set)
1006 | {
1007 | command = "groupConfig";
1008 | subCommand = "update";
1009 | content = new
1010 | {
1011 | sessionKey = session,
1012 | target,
1013 | config = set
1014 | };
1015 | }
1016 | ///
1017 | /// 群设置类
1018 | ///
1019 | public sealed class GroupConfigSet
1020 | {
1021 | ///
1022 | /// 群名
1023 | ///
1024 | public string name { get; set; }
1025 | ///
1026 | /// 群公告
1027 | ///
1028 | public string announcement { get; set; }
1029 | ///
1030 | /// 坦白说状态
1031 | ///
1032 | public bool confessTalk { get; set; }
1033 | ///
1034 | /// 允许群友邀请
1035 | ///
1036 | public bool allowMemberInvite { get; set; }
1037 | ///
1038 | /// 允许入群自动同意
1039 | ///
1040 | public bool autoApprove { get; set; }
1041 | ///
1042 | /// 允许匿名
1043 | ///
1044 | public bool anonymousChat { get; set; }
1045 | }
1046 | }
1047 | ///
1048 | /// 获取群员资料
1049 | ///
1050 | public sealed class MemberInfo_Get : SSM
1051 | {
1052 | ///
1053 | /// 获取群员资料
1054 | ///
1055 | /// 指定群的群号
1056 | /// 群员QQ号
1057 | public MemberInfo_Get(long target, long memberId)
1058 | {
1059 | command = "memberInfo";
1060 | subCommand = "get";
1061 | content = new
1062 | {
1063 | sessionKey = session,
1064 | target,
1065 | memberId
1066 | };
1067 | }
1068 | ///
1069 | public QQGroupMember? Send(Client? c = null, int? syncid = null, int TimeOut = 10) => SendAsync(c, syncid, TimeOut).GetAwaiter().GetResult();
1070 | ///
1071 | public Task SendAsync(Client? c = null, int? syncid = null, int TimeOut = 10) => base.SendAsync(c, syncid, TimeOut);
1072 | }
1073 | ///
1074 | /// 修改群员设置
1075 | ///
1076 | public sealed class MemberInfo_Update : ConfirmationTypoGeneral
1077 | {
1078 | ///
1079 | /// 修改群员设置
1080 | ///
1081 | /// 指定群的群号
1082 | /// 群员QQ号
1083 | /// 群员资料
1084 | public MemberInfo_Update(long target, long memberId, MemberInfoSet set)
1085 | {
1086 | command = "memberInfo";
1087 | subCommand = "update";
1088 | content = new
1089 | {
1090 | sessionKey = session,
1091 | target,
1092 | memberId,
1093 | config = set
1094 | };
1095 | }
1096 | ///
1097 | /// 群员设置类
1098 | ///
1099 | public sealed class MemberInfoSet
1100 | {
1101 | ///
1102 | /// 群昵称
1103 | ///
1104 | public string name { get; set; }
1105 | ///
1106 | /// 群头衔
1107 | ///
1108 | public string specialTitle { get; set; }
1109 | }
1110 | }
1111 | ///
1112 | /// 修改群员管理员
1113 | ///
1114 | public sealed class MemberAdmin : ConfirmationTypoGeneral
1115 | {
1116 | ///
1117 | /// 修改群员管理员
1118 | ///
1119 | /// 指定群的群号
1120 | /// 群员QQ号
1121 | /// 是否设置为管理员
1122 | public MemberAdmin(long target, long memberId, bool assign)
1123 | {
1124 | command = "memberAdmin";
1125 | content = new
1126 | {
1127 | sessionKey = session,
1128 | target,
1129 | memberId,
1130 | assign
1131 | };
1132 | }
1133 | }
1134 | #endregion
1135 |
1136 | #region 群公告
1137 | ///
1138 | /// 获取群公告
1139 | ///
1140 | public sealed class Anno_list : SSM
1141 | {
1142 | ///
1143 | /// 获取群公告
1144 | ///
1145 | /// 群号
1146 | /// 分页参数
1147 | /// 分页参数,默认10
1148 | public Anno_list(long groupid, long offset = 0, long size = 10)
1149 | {
1150 | command = "anno_list";
1151 | content = new
1152 | {
1153 | sessionKey = session,
1154 | id = groupid,
1155 | offset,
1156 | size
1157 | };
1158 | }
1159 | ///
1160 | public QQAno[]? Send(Client? c = null, int? syncid = null, int TimeOut = 10) => SendAsync(c, syncid, TimeOut).GetAwaiter().GetResult();
1161 | ///
1162 | public Task SendAsync(Client? c = null, int? syncid = null, int TimeOut = 10) => base.SendAsync(c, syncid, TimeOut);
1163 | }
1164 | ///
1165 | /// 发布群公告
1166 | ///
1167 | public sealed class Anno_publish : SSM
1168 | {
1169 | ///
1170 | /// 发布群公告
1171 | ///
1172 | /// 群号
1173 | /// 公告内容
1174 | /// 是否发送给新成员
1175 | /// 是否置顶
1176 | /// 是否显示群成员修改群名片的引导
1177 | /// 是否自动弹出
1178 | /// 是否需要群成员确认
1179 | /// 公告图片url
1180 | /// 公告图片本地路径
1181 | /// 公告图片base64编码
1182 | public Anno_publish(long target, string Content,
1183 | bool sendToNewMember = false, bool pinned = false, bool showEditCard = false, bool showPopup = false, bool requireConfirmation = false,
1184 | string imageUrl = null, string imagePath = null, string imageBase64 = null)
1185 | {
1186 | command = "anno_publish";
1187 | content = new
1188 | {
1189 | sessionKey = session,
1190 | target,
1191 | content = Content,
1192 | sendToNewMember,
1193 | pinned,
1194 | showEditCard,
1195 | showPopup,
1196 | requireConfirmation,
1197 | imageUrl,
1198 | imagePath,
1199 | imageBase64
1200 | };
1201 | }
1202 | ///
1203 | public QQAno? Send(Client? c = null, int? syncid = null, int TimeOut = 10) => SendAsync(c, syncid, TimeOut).GetAwaiter().GetResult();
1204 | ///
1205 | public Task SendAsync(Client? c = null, int? syncid = null, int TimeOut = 10) => base.SendAsync(c, syncid, TimeOut);
1206 | }
1207 | ///
1208 | /// 删除群公告
1209 | ///
1210 | public sealed class Anno_delete : ConfirmationTypoGeneral
1211 | {
1212 | ///
1213 | /// 删除群公告
1214 | ///
1215 | /// 群号
1216 | /// 群公告唯一id
1217 | public Anno_delete(long id, string fid)
1218 | {
1219 | command = "anno_delete";
1220 | content = new
1221 | {
1222 | sessionKey = session,
1223 | id,
1224 | fid,
1225 | };
1226 | }
1227 | }
1228 | #endregion
1229 |
1230 | #region 事件处理
1231 | ///
1232 | /// 处理加好友请求
1233 | ///
1234 | public sealed class Resp_newFriendRequestEvent : SSM
1235 | {
1236 | ///
1237 | /// 处理加好友请求
1238 | ///
1239 | ///
1240 | ///
1241 | ///
1242 | /// 0同意,1拒绝,2添加至黑名单
1243 | ///
1244 | public Resp_newFriendRequestEvent(long eventId, long fromId, long groupId, int operate, string message)
1245 | {
1246 | command = "resp_newFriendRequestEvent";
1247 | content = new
1248 | {
1249 | sessionKey = session,
1250 | eventId,
1251 | fromId,
1252 | groupId,
1253 | operate,
1254 | message
1255 | };
1256 | }
1257 | }
1258 | ///
1259 | /// 用户加群
1260 | ///
1261 | public sealed class Resp_memberJoinRequestEvent : SSM
1262 | {
1263 | ///
1264 | /// 用户加群
1265 | ///
1266 | ///
1267 | ///
1268 | ///
1269 | /// 0同意,1拒绝,2忽略,3拒绝并黑名单,4忽略并黑名单
1270 | ///
1271 | public Resp_memberJoinRequestEvent(long eventId, long fromId, long groupId, int operate, string message)
1272 | {
1273 | command = "resp_memberJoinRequestEvent";
1274 | content = new
1275 | {
1276 | sessionKey = session,
1277 | eventId,
1278 | fromId,
1279 | groupId,
1280 | operate,
1281 | message
1282 | };
1283 | }
1284 | }
1285 | ///
1286 | /// Bot被邀请入群
1287 | ///
1288 | public sealed class Resp_botInvitedJoinGroupRequestEvent : SSM
1289 | {
1290 | ///
1291 | /// Bot被邀请入群
1292 | ///
1293 | ///
1294 | ///
1295 | ///
1296 | /// 0同意,1拒绝
1297 | ///
1298 | public Resp_botInvitedJoinGroupRequestEvent(long eventId, long fromId, long groupId, int operate, string message)
1299 | {
1300 | command = "resp_botInvitedJoinGroupRequestEvent";
1301 | content = new
1302 | {
1303 | sessionKey = session,
1304 | eventId,
1305 | fromId,
1306 | groupId,
1307 | operate,
1308 | message
1309 | };
1310 | }
1311 | }
1312 | #endregion
1313 | }
1314 |
--------------------------------------------------------------------------------