Demo Bot: Complete code refactoring. WIP.

This commit is contained in:
John Livingston
2021-12-08 15:29:34 +01:00
parent 2c72f3bf2f
commit 42988a5d04
9 changed files with 218 additions and 159 deletions

View File

@ -0,0 +1,11 @@
import type { BotRoom } from '../room'
export abstract class BotHandler {
constructor (
protected readonly room: BotRoom
) {
this.init()
}
protected abstract init (): void
}

View File

@ -0,0 +1,19 @@
import type { XMPPUser } from '../types'
import { BotHandler } from './base'
export class BotHandlerDemo extends BotHandler {
protected init (): void {
const room = this.room
room.on('room_join', (user: XMPPUser) => {
if (user.isMe) {
return
}
if (!room.isOnline()) {
return
}
room.sendGroupchat(
`Hello ${user.nick}! I'm the DemoBot, I'm here to demonstrate the chatroom.`
).catch(() => {})
})
}
}