"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const Sphinx = require("sphinx-bot"); const actions_1 = require("../controllers/actions"); const models_1 = require("../models"); const path = require("path"); const msg_types = Sphinx.MSG_TYPE; const constants = require(path.join(__dirname, '../../config/constants.json')); let initted = false; function init() { if (initted) return; initted = true; const client = new Sphinx.Client(); client.login('_', actions_1.finalAction); client.on(msg_types.MESSAGE, (message) => __awaiter(this, void 0, void 0, function* () { const arr = message.content.split(' '); console.log('message.type', message.type); const isGroupJoin = message.type === constants.message_types.group_join; if (arr.length < 2 && !isGroupJoin) return; if (arr[0] !== '/welcome' && !isGroupJoin) return; const cmd = arr[1]; if (isGroupJoin) { const chat = yield models_1.models.Chat.findOne({ where: { uuid: message.channel.id } }); if (!chat) return; const chatBot = yield models_1.models.ChatBot.findOne({ where: { chatId: chat.id, botPrefix: '/welcome', botType: constants.bot_types.builtin } }); if (!(chatBot && chatBot.meta)) return; const resEmbed = new Sphinx.MessageEmbed() .setAuthor('WelcomeBot') .setDescription(chatBot.meta); message.channel.send({ embed: resEmbed }); return; } switch (cmd) { case 'setmessage': if (arr.length < 3) return; console.log("setmsg", arr[2]); const chat = yield models_1.models.Chat.findOne({ where: { uuid: message.channel.id } }); if (!chat) return; const chatBot = yield models_1.models.ChatBot.findOne({ where: { chatId: chat.id, botPrefix: '/welcome', botType: constants.bot_types.builtin } }); if (!chatBot) return; const meta = arr.slice(2, arr.length).join(' '); yield chatBot.update({ meta }); 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; } })); } exports.init = init; const botSVG = ` `; //# sourceMappingURL=welcome.js.map