ProjHyperai icon indicating copy to clipboard operation
ProjHyperai copied to clipboard

ActiveBots模块(是的,我起名字提笔就来

Open d3ara1n opened this issue 3 years ago • 0 comments

动机

使用一套规则来运行时构建自动回复,该功能无需插件,但可以被插件扩展。

实现

  1. 外置规则文件运行时解析,通过触发器决定该 Reply 的生效时机。不同的触发器为 Reply 提供了不同的上下文(IRuleContext)。
  2. 运行时也可以用 RuleBuilder 构建 Rule,用 ReplyBuilder 构建具体的 Reply,当然可以继续套娃。
  3. 外置规则使用 xaml 语法。

外置规则示例

<Rule Name="Default">
	<!-- Context : IRuleContext, 不同事件会有不同类型的 Context, 提供不同的可用字段 -->
	<Reply Target="{Binding Context.Group">
		<Reply.Trigger>
			<EventTrigger On="GroupMessageEventArgs">
				<EventTrigger.Condition>
					<SpecificSender Field="Identity" Value="10000"/>
					<TextFullMatch Text="!ping" Input="{Binding Context.Message,Converter={builtin:Converters MessageChainFormatter}}"/>
				</EventTrigger.Condition>
			</EventTrigger>
		</Reply.Trigger>

		<Quote TargetId="{Binding Context.Message,Converter={builtin:Converters MessageChain2MessageIdConverter}}"/>
		<Plain Text="pong!"/>
	</Reply>
	<!-- ReplyBuilder 可以运行时用 fluent api 构建一个 Reply -->
	<Reply>
		<Reply.Trigger>
			<GithubIssueUpdateTrigger Repository="theGravityLab/ProjHyperai" IssueId="13" On="Close"/>
		</Reply.Trigger>
		<!-- Reply.Message 是默认容器,可以省略不写 -->
		<Reply.Message>
			<Plain Text="Github Issue #"/>
			<Plain Text="{Binding Context.IssueId}"/>
			<Plain Text=" closed."/>
		</Reply.Message>
		<Reply.Target>
			<Group Identity="114114514"/>
		</Reply.Target>
	</Reply>
</Rule>

d3ara1n avatar Aug 04 '20 21:08 d3ara1n