Open
[WIP] Add complete context system for Bot commands and handlers#30
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original prompt
概述
为 Bot 的命令和 CallbackQuery handler 添加一套完整的 会话上下文(Context)系统,支持:
PrivateContext)与群聊上下文(GroupContext)类型区分ContextFilterAttribute标记 handler 所需的 Mode,实现多步骤交互路由需要新建的文件
1. 配置类
XinjingDaily.Bot.Infrastructure/Configs/ContextConfig.cs在
AppSettings中新增字段:2. Redis DTO
XinjingDaily.Bot.Infrastructure/Bot/Context/ContextRedisDto.cs3. Attribute
XinjingDaily.Bot.Infrastructure/Attribute/ContextFilterAttribute.cs4. 懒加载 Store
XinjingDaily.Bot.Infrastructure/Bot/Context/LazyContextStore.cs实现要点:
Func<Task<ContextRedisDto>>加载函数,不执行 IOIsLoaded、IsDirty属性EnsureLoadedAsync():首次调用触发 IO,后续直接返回GetModeAsync()、SetModeAsync(string)、ClearModeAsync()GetAsync<T>(string)、SetAsync<T>(string, T)(超过 2000 字符时抛出InvalidOperationException)、TryGetAsync<T>(string, Action<T?>)、RemoveAsync(string)、ClearAsync()ExportDto():未加载或无脏数据时返回 nullMarkClean()、SerializeData()、GetMode()(同步,仅在已加载时有效)、GetDbId()5. PrivateContext
XinjingDaily.Bot.Infrastructure/Bot/Context/PrivateContext.cs6. GroupContext
XinjingDaily.Bot.Infrastructure/Bot/Context/GroupContext.cs