You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
49 lines
1.3 KiB
// import * as SphinxBot from '../../../sphinx-bot'
|
|
import * as SphinxBot from 'sphinx-bot'
|
|
import * as MotherBot from './mother'
|
|
import * as WelcomeBot from './welcome'
|
|
import * as BitcoinBot from './btc'
|
|
import {Msg} from '../network/interfaces'
|
|
import * as path from 'path'
|
|
import { models } from '../models'
|
|
|
|
const constants = require(path.join(__dirname, '../../config/constants.json'))
|
|
|
|
async function init(){
|
|
MotherBot.init()
|
|
|
|
const builtInBots = await models.ChatBot.findAll({where:{
|
|
botType: constants.bot_types.builtin
|
|
}})
|
|
if(!(builtInBots && builtInBots.length)) return
|
|
|
|
builtInBots.forEach(b=>{
|
|
if(b.botPrefix==='/welcome') WelcomeBot.init()
|
|
if(b.botPrefix==='/btc') BitcoinBot.init()
|
|
})
|
|
}
|
|
|
|
function builtinBotEmit(msg:Msg){
|
|
const m = <SphinxBot.Message>{
|
|
channel:{
|
|
id: msg.chat.uuid,
|
|
send:function(){},
|
|
},
|
|
reply:function(){},
|
|
content: msg.message.content,
|
|
type: msg.type,
|
|
member: {
|
|
id:'_',
|
|
nickname: msg.sender.alias,
|
|
roles:[]
|
|
}
|
|
}
|
|
if(msg.sender.role===constants.chat_roles.owner) {
|
|
if(m.member) m.member.roles=[{
|
|
name:'Admin'
|
|
}]
|
|
}
|
|
SphinxBot._emit('message', m)
|
|
}
|
|
|
|
export {init,builtinBotEmit}
|
|
|