Skip to content

Commit c170fd3

Browse files
author
cmd1152
committed
:(
1 parent d83255d commit c170fd3

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

HackChat-BotLib.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ class Client {
105105
if (hc.cmd == "info" && hc.type == "whisper" && typeof hc.from == "string") {
106106
hc.nick = hc.from;
107107
hc.msg = hc.text.substring(hc.from.length+12);
108+
hc.cmd = hc.type;
109+
delete hc.type;
110+
}
111+
if (hc.cmd == "info" && /^([a-zA-Z0-9_]{1,24}) invited you to/.test(hc.text)) {
112+
let inv = hc.text.match(/^([a-zA-Z0-9_]{1,24}) invited you to/);
113+
return this.onmessage(
114+
event.data,
115+
{
116+
cmd: 'invite',
117+
nick: inv[1],
118+
to: hc.text.substring(inv[1].length + 17)
119+
}
120+
)
121+
}
122+
if (hc.cmd == "updateMessage") {
123+
let updateBy = this.users.find((user)=>{
124+
return user.userid == hc.userid;
125+
})
126+
hc.nick = updateBy.nick;
127+
hc.trip = updateBy.trip;
108128
}
109129
this.onmessage(event.data,hc);
110130
}
@@ -177,6 +197,14 @@ class Client {
177197
return user.nick == nick;
178198
})
179199
}
200+
invite(nick,to) {
201+
let pack = {
202+
cmd: 'invite',
203+
nick: nick
204+
}
205+
if (to) pack.to = to;
206+
this._send(pack);
207+
}
180208
whisper(to,text) {
181209
this._send({
182210
cmd: 'whisper',

test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ let client = new Client("wss://hack.chat/chat-ws");
33
let join_channel = "your-channel";
44

55
client.onjoin = () => {
6-
client.join({ //发送加入数据包
6+
client.join({
77
channel: join_channel,
88
nick: 'my_bot',
99
password: '123456'
1010
})
11-
//也可以读取 client.joined 判断有没有加入频道
1211
}
1312

1413
client.onmessage = (raw, json) => {
@@ -26,4 +25,10 @@ client.onjoined = () => {
2625
}
2726

2827
client.ping = 10000;
28+
client.onchangechannel = (channel) => {
29+
client.close("被踢出或者移动到了"+channel);
30+
}
2931

32+
client.onclose = (reason) => {
33+
console.log(`连接断开`,reason)
34+
}

0 commit comments

Comments
 (0)