',
].join('')
- } else if (userName) {
- let rooms = await bot.Room.findAll()
+ } else if (info.userName) {
+ let rooms = await wechaty.Room.findAll()
rooms = rooms.sort((a, b) => a.id > b.id ? 1 : -1)
let roomHtml = `The rooms I have joined are as follows: `
@@ -128,7 +179,7 @@ async function rootHandler (_req: Request, res: Response) {
roomHtml = roomHtml + `
`
html = [
- ` OSSChat v${VERSION} User ${userName} logined.
`,
+ ` OSSChat v${VERSION} User ${info.userName} logined.
`,
FORM_HTML,
roomHtml,
].join('')
@@ -138,24 +189,5 @@ async function rootHandler (_req: Request, res: Response) {
}
- const htmlHead = `
-
-
-
-
-
-
- `
-
- const htmlFoot = `
-
- `
-
- res.end(
- [
- htmlHead,
- html,
- htmlFoot,
- ].join('\n')
- )
+ return html
}
diff --git a/src/start-bot.ts b/src/start-bot.ts
index 08c504a..022b5d8 100644
--- a/src/start-bot.ts
+++ b/src/start-bot.ts
@@ -1,5 +1,4 @@
import {
- Wechaty,
Contact,
} from 'wechaty'
@@ -12,11 +11,12 @@ import {
import {
Wtmp,
} from './wtmp'
+import { HAWechaty } from './ha-wechaty'
-export async function startBot (wechaty: Wechaty): Promise {
- log.verbose('startBot', 'startBot(%s)', wechaty)
+export async function startBot (haWechaty: HAWechaty): Promise {
+ log.verbose('startBot', 'startBot(%s)', haWechaty)
- wechaty
+ haWechaty
.on('scan', './handlers/on-scan')
.on('error', './handlers/on-error')
.on('friendship', './handlers/on-friendship')
@@ -33,14 +33,14 @@ export async function startBot (wechaty: Wechaty): Promise {
}
const ONE_HOUR = 60 * 60 * 1000
setInterval(heartbeat('💖'), ONE_HOUR)
- wechaty.on('login', heartbeat(`🙋 (${wechaty.name()})`))
- wechaty.on('ready', heartbeat(`💪 (${wechaty.name()})`))
- wechaty.on('logout', heartbeat(`😪 (${wechaty.name()})`))
+ haWechaty.on('login', heartbeat(`🙋 (${haWechaty.name()})`))
+ haWechaty.on('ready', heartbeat(`💪 (${haWechaty.name()})`))
+ haWechaty.on('logout', heartbeat(`😪 (${haWechaty.name()})`))
const wtmp = Wtmp.instance()
const loginWtmp = (user: Contact) => wtmp.login(user.name())
const logoutWtmp = (user: Contact) => wtmp.logout(user.name())
- wechaty.on('login', loginWtmp)
- wechaty.on('logout', logoutWtmp)
+ haWechaty.on('login', loginWtmp)
+ haWechaty.on('logout', logoutWtmp)
}
diff --git a/src/start-finis.ts b/src/start-finis.ts
index 0476248..23c76ed 100644
--- a/src/start-finis.ts
+++ b/src/start-finis.ts
@@ -1,5 +1,7 @@
import { finis } from 'finis'
-import { Wechaty } from 'wechaty'
+import {
+ Contact,
+} from 'wechaty'
import {
Chatops,
@@ -9,6 +11,7 @@ import {
VERSION,
debug,
} from './config'
+import { HAWechaty } from './ha-wechaty'
const BOT_NAME = 'OSSChat'
@@ -16,16 +19,16 @@ const LOGIN_ANNOUNCEMENT = `Der! I just got online!\n${BOT_NAME} v${VERSION}`
// const LOGOUT_ANNOUNCEMENT = `Der! I'm going to offline now, see you, bye!\nOSSChat v${VERSION}`
const EXIT_ANNOUNCEMENT = `Der! I'm going to exit now, see you, bye!\n${BOT_NAME} v${VERSION}`
-let bot: undefined | Wechaty
+let bot: undefined | HAWechaty
-export async function startFinis (wechaty: Wechaty): Promise {
+export async function startFinis (haWechaty: HAWechaty): Promise {
if (bot) {
throw new Error('startFinis should only init once')
}
- bot = wechaty
+ bot = haWechaty
- bot.on('login', _ => Chatops.instance().say(LOGIN_ANNOUNCEMENT))
- bot.on('logout', user => log.info('RestartReporter', 'startFinis() bot %s logout', user))
+ bot.on('login', async function () { await Chatops.instance().say(LOGIN_ANNOUNCEMENT) })
+ bot.on('logout', function (user: Contact) { log.info('RestartReporter', 'startFinis() bot %s logout', user) })
}
/**
diff --git a/src/typings.d.ts b/src/typings.d.ts
new file mode 100644
index 0000000..6b8c4c2
--- /dev/null
+++ b/src/typings.d.ts
@@ -0,0 +1 @@
+declare module 'flatten-array'
diff --git a/tests/fixtures/smoke-testing.ts b/tests/fixtures/smoke-testing.ts
index 2006662..c237398 100644
--- a/tests/fixtures/smoke-testing.ts
+++ b/tests/fixtures/smoke-testing.ts
@@ -1,18 +1,19 @@
#!/usr/bin/env ts-node
-import { getWechaty } from '../../src/get-wechaty'
+import { getHAWechaty } from '../../src/get-wechaty'
import { startBot } from '../../src/start-bot'
import { startFinis } from '../../src/start-finis'
process.env.WECHATY_PUPPET = 'wechaty-puppet-mock'
+process.env.WECHATY_PUPPET_MOCK_TOKEN = 'mock-token'
async function main () {
- const bot = getWechaty()
+ const haBot = getHAWechaty()
await Promise.all([
- bot.start(),
- startBot(bot),
- startFinis(bot),
+ haBot.start(),
+ startBot(haBot),
+ startFinis(haBot),
])
return 0