几个问题: #1017
Replies: 3 comments 7 replies
-
If you are trying to add this feature to your plugins (I mean the plugins you written by yourself) only, it is very straightforward to just add a check in every event listener before doing your own processing. If you are trying to block some people from using others' plugins, you could add a filter which is on the top of the configuration page of every plugin. Re: the order between I think you have misunderstanding here, when you are trying to invoke the Also, this means you could trigger the ctx.on('message', async (session) => {
+ ctx.emit('before-attach-user', session, userFields);
const databaseUser = await ctx.database.getUser('onebot', session.userId);
const sessionUser = await session.getUser(session.userId);
console.log('plugin B')
}) |
Beta Was this translation helpful? Give feedback.
-
Like this? ctx.on('message', async (session) => {
const checkAuthority = await ctx.database.xxxxx
if (checkAuthority) // handle plugin
else return "No authority"
}) |
Beta Was this translation helpful? Give feedback.
-
before-attach-user 属于中间件工作流,不会影响其他事件。因为只有中间件里才存在「Koishi 试图从数据库获取频道 / 用户信息前触发」的逻辑。
你需要手动处理每一个相关的事件。一个完整的 Koishi 项目通常有上百个事件,显然绝大部分事件都与这个 before-attach-user 无关。 |
Beta Was this translation helpful? Give feedback.
-
before-attach-user 事件是什么时候被调用
我创建了一个插件 A,增加了一个 attach-user 事件
插件 B,监听 message 事件
收到消息后的输出
我对文档的理解是应该先输出
before attach-user
,再输出plugin B
其他
我应该如何实现在处理所有事件之前(例如用户消息,加群退群),查询数据库判断用户是否有使用权限,如果有权限,则继续后续逻辑和插件,如果无权限,则返回“无权限”的消息提示,停止后续的处理。
Beta Was this translation helpful? Give feedback.
All reactions