import * as Sphinx from 'sphinx-bot' import { finalAction } from '../controllers/actions' import { models } from '../models' import * as path from 'path' const msg_types = Sphinx.MSG_TYPE const constants = require(path.join(__dirname, '../../config/constants.json')) let initted = false export function init() { if(initted) return initted = true console.log('INIT WELCOME BOT') const client = new Sphinx.Client() client.login('_', finalAction) client.on(msg_types.MESSAGE, async (message: Sphinx.Message) => { const arr = message.content.split(' ') if (arr.length < 2) return if (arr[0]!=='/welcome') return const cmd = arr[1] switch (cmd) { case 'setmessage': if (arr.length < 3) return console.log("setmsg", arr[2]) const chat = await models.Chat.findOne({where:{uuid:message.channel.id}}) if(!chat) return const chatBot = await models.ChatBot.findOne({where:{ chatID: chat.id, botPrefix:'/welcome', botType:constants.bot_types.builtin }}) if(!chatBot) return await chatBot.update({meta:arr[2]}) const resEmbed = new Sphinx.MessageEmbed() .setAuthor('WelcomeBot') .setDescription('Your welcome message has been updated') message.channel.send({ embed:resEmbed }) return default: const embed = new Sphinx.MessageEmbed() .setAuthor('WelcomeBot') .setTitle('Bot Commands:') .addFields([ { name: 'Set welcome message', value: '/welcome setmessage {MESSAGE}' }, { name: 'Help', value: '/welcome help' } ]) .setThumbnail(botSVG) message.channel.send({ embed }) return } }) } const botSVG = ` `