Demo Bot: Complete code refactoring. WIP.
This commit is contained in:
11
bots/lib/bot/handlers/base.ts
Normal file
11
bots/lib/bot/handlers/base.ts
Normal 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
|
||||
}
|
19
bots/lib/bot/handlers/demo.ts
Normal file
19
bots/lib/bot/handlers/demo.ts
Normal 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(() => {})
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user