-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 fix route path of command system, add missed command event. #50
Merged
Conversation
This file contains 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
YunYouJun
requested changes
Jul 6, 2022
Released in Could you test it? |
// file command-test.ts
// ...
async function app() {
await mirai.link(qq);
mirai.on('message', (msg) => {
// eslint-disable-next-line no-console
// console.log(msg)
});
mirai.api.command.register("test", ['command', 'alias'], 'test command interface', 'test <args>...');
mirai.on("CommandExecutedEvent", (data) => {
if (data.name == 'test' || data.name == 'command' || data.name == 'alias') {
console.log(data);
if (data.friend != null) {
mirai.api.sendFriendMessage(data.args, data.friend.id);
}
else if (data.member != null) {
mirai.api.sendGroupMessage(data.args, data.member.group.id);
}
else {
mirai.logger.debug(data.args);
}
}
});
mirai.listen();
}
app(); yeah, here is my test code and runtime result is below: # ./mcl --boot-only
## after run ts-node command-test.ts
> help
# ...
◆ test <args>...
## result for send friend message:
2022-07-08 09:59:13 V/Bot.*********: Event: net.mamoe.mirai.api.http.command.CommandExecutedEvent@46b5fda1
2022-07-08 09:59:13 V/Bot.*********: 杯弓蛇影(*********) -> #test qq friend cmd test
2022-07-08 09:59:13 V/Bot.*********: Friend(*********) <- qqfriendcmdtest
## result for send group member message:
2022-07-08 09:59:37 V/Bot.*********: [Test(*********)] 测试名(*********) -> #test qq member cmd test
2022-07-08 09:59:37 V/Bot.*********: Event: net.mamoe.mirai.api.http.command.CommandExecutedEvent@c7e430e
2022-07-08 09:59:38 V/Bot.*********: Group(*********) <- qqmembercmdtest
## result for console command:
> test 123 456 test
2022-07-08 09:59:50 V/Bot.*********: Event: net.mamoe.mirai.api.http.command.CommandExecutedEvent@66a92375 # yarn upgrade
yarn upgrade v1.22.19
warning package.json: No license field
warning No license field
warning No license field
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Rebuilding all packages...
success Saved lockfile.
warning No license field
success Saved 62 new dependencies.
info Direct dependencies
├─ @types/js-yaml@4.0.5
├─ @types/jsdom@16.2.14
├─ @types/node@18.0.3
├─ fs@0.0.1-security
├─ js-yaml@4.1.0
├─ jsdom@20.0.0
└─ mirai-ts@2.4.0
...
# ts-node command-test.ts
[mirai-api-http] [info] [http] Address: http://localhost:8080
[mirai-api-http] [info] [http] Session: itmOgxPM
[mirai-api-http] [success] 验证成功
[mirai-api-http] [info] [websocket] [all](消息与事件) ws://localhost:8080
[mirai-api-http] [info] [ws] Session: NnnVOlAR
## result for send friend message:
{
type: 'CommandExecutedEvent',
name: 'test',
friend: { id: 000000000, nickname: '杯弓蛇影', remark: '****' },
member: null,
args: [
{ type: 'Plain', text: 'qq' },
{ type: 'Plain', text: 'friend' },
{ type: 'Plain', text: 'cmd' },
{ type: 'Plain', text: 'test' }
],
reply: [AsyncFunction (anonymous)]
}
## result for send group member message:
{
type: 'CommandExecutedEvent',
name: 'test',
friend: null,
member: {
id: 000000000,
memberName: '测试名',
specialTitle: '',
permission: 'OWNER',
joinTimestamp: 1529044925,
lastSpeakTimestamp: 1657245577,
muteTimeRemaining: 0,
group: { id: 000000000, name: 'Test', permission: 'MEMBER' }
},
args: [
{ type: 'Plain', text: 'qq' },
{ type: 'Plain', text: 'member' },
{ type: 'Plain', text: 'cmd' },
{ type: 'Plain', text: 'test' }
],
reply: [AsyncFunction (anonymous)]
}
## result for console command:
{
type: 'CommandExecutedEvent',
name: 'test',
friend: null,
member: null,
args: [
{ type: 'Plain', text: '123' },
{ type: 'Plain', text: '456' },
{ type: 'Plain', text: 'test' }
],
reply: [AsyncFunction (anonymous)]
}
[mirai-api-http] [debug] [
{ type: 'Plain', text: '123' },
{ type: 'Plain', text: '456' },
{ type: 'Plain', text: 'test' }
] so I think it works fine, if you needed, i can send runtime picture (I used text rather than image, beacuse there isn't suitable gallery website. |
That's ok. Have fun! |
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.
想要尝试一下command相关的接口,发现现在的支持有问题
根据源文件 mirai-http-api paths.kt ,mirai-api-http 的 comand 的接口路由现在是
cmd
开始,下面有cmd/register
和cmd/execute
,修改于15个月前而 mirai-ts 的实现中,相关接口仍然写的是
command/register
和command/send
,所以修复了路由,同时把Command.send
接口名字也改成了Command.execute
保证一致另外
EventMap
中缺乏CommandExecute
事件,导致 mirai-api-http 转发的接口调用事件(参考mirai-http-api api event)没法直接监听,所以补上了这部分。