Skip to content

Commit 9ae0363

Browse files
author
cmd1152
committed
:(
1 parent f951a02 commit 9ae0363

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

HackChat-BotLib.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,15 @@ class Client {
129129
if (this.cmdstart !== false) {
130130
let originText = hc.text;
131131
if (hc.cmd == "whisper") originText = hc.msg; //前面有扩展;
132+
if (!originText) return;
132133
if (originText.startsWith(this.cmdstart)) {
133134
let originCmd = originText.substring(this.cmdstart.length).split(" ");
134135
let runcmd = originCmd.shift();
135136
this._COMMAND(
136137
runcmd,
137138
originCmd,
138139
this.selNick(hc.nick),
139-
hc.cmd == "whisper"?(text,e=false)=>{this.whisper(hc.nick,`${e?"\x00\n":""}${text}`)}:(text,e)=>{this.chat(`${e?"":`@{hc.nick} `}${text}`)},
140+
hc.cmd == "whisper"?(text,e=false)=>{this.whisper(hc.nick,`${e?"\x00\n":""}${text}`)}:(text,e)=>{this.chat(`${e?"":`@${hc.nick} `}${text}`)},
140141
hc.cmd == "whisper"
141142
)
142143
}
@@ -257,7 +258,7 @@ class Client {
257258
_COMMAND(cmd, args, info, back, whisper) {
258259
if (this.command[cmd]) {
259260
try {
260-
back(this.command[cmd].run(args,info,back,whisper));
261+
this.command[cmd].run(args,info,back,whisper);
261262
} catch (e) {
262263
back(`命令执行出错:${e.message}`);
263264
}

test.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ client.onjoined = () => {
1919
}
2020

2121
client.onmessage = (raw, json) => {
22-
if (json.cmd == "chat" && json.text.includes("6") && json.nick !== client.nick) {
23-
let id = client.getcustomId()
24-
client.chat(client.reply(json),id);
25-
["我注意到","你说了", "一句“6”",",","最近你", "过得如何?"].forEach((t,i)=>{
26-
setTimeout(()=>{
27-
client.updatemessage(id,'append',t);
28-
},i*3000)
29-
})
22+
console.log(json);
23+
}
24+
25+
client.cmdstart = ":";
26+
client.command = {
27+
test: {
28+
run: function(args, info, back, whisper) {
29+
back(`用户信息:\n\`\`\`\n${JSON.stringify(info)}\n\`\`\`\n是私信调用:${whisper}\n命令参数:${args.join(" ")} (长度:${args.length})`);
30+
}
3031
}
3132
}

0 commit comments

Comments
 (0)