Merge branch 'master' of https://git.trj.tw/mtfos/mtfosbot
This commit is contained in:
commit
fa11f24e3a
@ -9,6 +9,7 @@ class WS {
|
|||||||
constructor () {
|
constructor () {
|
||||||
/** @type {WebSocket} */
|
/** @type {WebSocket} */
|
||||||
this.ws = null
|
this.ws = null
|
||||||
|
this.join = []
|
||||||
}
|
}
|
||||||
|
|
||||||
runBot () {
|
runBot () {
|
||||||
@ -64,20 +65,32 @@ class WS {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// release pool connection
|
// release pool connection
|
||||||
await db.replace()
|
await db.release()
|
||||||
|
|
||||||
|
this.joinChannel = []
|
||||||
if (result !== null && result.rowCount > 0) {
|
if (result !== null && result.rowCount > 0) {
|
||||||
for (let row of result.rows) {
|
for (let row of result.rows) {
|
||||||
if ('name' in row) {
|
if ('name' in row) {
|
||||||
this.ws.send('JOIN #' + row.name)
|
this.ws.send('JOIN #' + row.name)
|
||||||
|
this.join.push(row.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendMsg (channel = null, message = null) {
|
||||||
|
if (this.ws === null || !('send' in this.ws) || typeof this.ws.send !== 'function') return null
|
||||||
|
if (channel === null || typeof channel !== 'string' || channel.trim().length === 0) return null
|
||||||
|
if (message === null || typeof message !== 'string' || message.trim().length === 0) return null
|
||||||
|
if (this.join.indexOf(channel) === -1) return null
|
||||||
|
this.ws.send(`PRIVMSG #${channel} :${message}`)
|
||||||
|
}
|
||||||
|
|
||||||
joinChannel (channel = null) {
|
joinChannel (channel = null) {
|
||||||
|
if (this.ws === null || !('send' in this.ws) || typeof this.ws.send !== 'function') return null
|
||||||
if (channel === null || typeof channel !== 'string' || channel.trim().length === 0) return null
|
if (channel === null || typeof channel !== 'string' || channel.trim().length === 0) return null
|
||||||
this.ws.send(`JOIN #${channel.trim()}`)
|
this.ws.send(`JOIN #${channel.trim()}`)
|
||||||
|
this.join.push(channel.trim())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,14 +31,6 @@ const msgSplit = async function (ws, msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendMsg = async (ws, channel = null, msg = null) => {
|
|
||||||
if (!ws || !('send' in ws) || typeof ws.send !== 'function') return null
|
|
||||||
if (channel === null || typeof channel !== 'string' || channel.trim().length === 0) return null
|
|
||||||
if (msg === null || typeof msg !== 'string' || msg.trim().length === 0) return null
|
|
||||||
ws.send(`PRIVMSG #${channel} :${msg}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
msgSplit,
|
msgSplit
|
||||||
sendMsg
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user