Пример #1
0
const run = async () => {
  mainStory.info('gqlUpdate', 'Introspecting...');
  const result = await gqlServer.runIntrospect();
  let filePath = path.join(outputPath, 'gqlSchema.json');
  mainStory.info('gqlUpdate', `Writing ${chalk.cyan(filePath)}...`);
  fs.writeFileSync(filePath, JSON.stringify(result, null, 2));
  filePath = path.join(outputPath, 'gqlSchema.graphql');
  mainStory.info('gqlUpdate', `Writing ${chalk.cyan(filePath)}...`);
  fs.writeFileSync(filePath, gqlServer.getSchemaShorthand());
  mainStory.info('gqlUpdate', 'Done!');
};
Пример #2
0
 files.forEach(file => {
     try {
         let filter = require(path.resolve(__dirname, 'userfilters', file)); //eslint-disable-line global-require
         if (filter.enabled) {
             userfilters.push(filter.check);
             story.debug('UserFilters', `Loaded userfilter ${filter.name}`);
         } else story.debug('UserFilters', `Skipping ${filter.name} since it's disabled.`);
     } catch (e) {
         story.warn('UserFilters', 'Failed to load userfilter.', {attach: e});
     }
 });
Пример #3
0
 cleverbot.write(data.message.replace(`@${plugged.getSelf().username}`, '').trim(), (resp) => {
     story.debug('cleverbot', resp.message);
     plugged.sendChat(utils.replace(langfile.cleverbot.format, {
         username: data.username,
         message: resp.message
     }));
 });
Пример #4
0
 redis.hget('user:roles', data.id).then(perm => {
     perm = parseInt(perm, 10);
     if (config.options.bouncerPlus ? (perm > 1) : (perm > 2)) {
         let split = data.message.trim().split(' ');
         if (split.length === 2) {
             let pos = parseInt(split[1]);
             if (!isNaN(pos) && pos > 0 && pos < 51) {
                 config.lockskip.movePos = pos;
                 plugged.sendChat(utils.replace(langfile.skip.lockskippos, {
                     username: data.username,
                     pos
                 }), 30);
                 story.info('locksippos', `${utils.userLogString(data.username, data.id)} set Lockskippos to ${pos}`);
                 //noinspection JSUnresolvedFunction
                 redis.hset('meta:config', 'lockskip:move_pos', pos);
             } else plugged.sendChat(utils.replace(langfile.error.argument, {
                 username: data.username,
                 cmd: 'LockSkipPos'
             }), 20);
         } else plugged.sendChat(utils.replace(langfile.error.argument, {
             username: data.username,
             cmd: 'LockSkipPos'
         }), 20);
     }
 });
Пример #5
0
 redis.del(`media:history:${mid}`).then(r => {
     if (r === 1) {
         plugged.sendChat(utils.replace(langfile.skip.history.remove, {username: data.username}));
         story.info('History', `${utils.userLogString(data.username, data.id)} removed ${mid} from the history.`);
     }
     else plugged.sendChat(utils.replace(langfile.error.argument, {
         cmd: 'RemoveHistory',
         username: data.username
     }));
 });
Пример #6
0
const mutate = ({
  description,
  environment,
  mutationOptions: mutationOptions0,
  onFailure,
  onSuccess,
  onFinish,
}: {|
  description: string,
  environment: Object,
  mutationOptions: Object,
  input?: Object,
  onFailure?: (failure: Object) => void,
  onSuccess?: (response: Object) => void,
  onFinish?: () => void,
|}) => {
  const story = mainStory.child({
    src: 'views',
    title: description,
  });
  let mutationOptions = mutationOptions0;
  mutationOptions = setIn(
    mutationOptions,
    ['variables', 'input', 'storyId'],
    story.storyId
  );
  commitMutation(environment, {
    ...mutationOptions,
    onCompleted: response => {
      story.debug('views', 'Transaction result:', {
        attach: response,
        attachLevel: 'trace',
      });
      tearDown(story);
      if (onSuccess) onSuccess(response);
      if (onFinish) onFinish();
    },
    onError: err => {
      const error = err.message || new Error('Mutation failed');
      story.error('views', 'Transaction error:', { attach: error });
      tearDown(story);
      if (onFailure) {
        onFailure(err);
      } else {
        notify({
          title: _t('error_Changes could not be saved'),
          msg: _t('error_Is the server running?'),
          type: 'error',
          icon: 'save',
        });
      }
      if (onFinish) onFinish();
    },
  });
};
Пример #7
0
 redis.hget('user:roles', data.id).then(perm => {
     perm = parseInt(perm, 10);
     if (config.options.bouncerPlus ? (perm > 1) : (perm > 2)) {
         config.soundcloudGuard.block = !config.soundcloudGuard.block;
         if (config.soundcloudGuard.block) plugged.sendChat(utils.replace(langfile.soundcloudGuard.blockEnabled, {username: data.username}), 60);
         else plugged.sendChat(utils.replace(langfile.soundcloudGuard.blockDisabled, {username: data.username}), 60);
         //noinspection JSUnresolvedFunction
         redis.hset('meta:config', 'soundcloudguard:block:enabled', (config.soundcloudGuard.block ? 1 : 0));
         story.info('soundcloudblock', `${utils.userLogString(data.username, data.id)}: --> ${config.soundcloudGuard.block.toString()}`);
     }
 });
Пример #8
0
 redis.hget('user:roles', data.id).then(perm => {
     perm = parseInt(perm, 10);
     if (config.options.bouncerPlus ? (perm > 1) : (perm > 2)) {
         config.cleverbot.enabled = !config.cleverbot.enabled;
         if (config.cleverbot.enabled) plugged.sendChat(utils.replace(langfile.cleverbot.enabled, {username: data.username}), 30);
         else plugged.sendChat(utils.replace(langfile.cleverbot.disabled, {username: data.username}), 30);
         //noinspection JSUnresolvedFunction
         redis.hset('meta:config', 'cleverbot:enabled', (config.cleverbot.enabled ? 1 : 0));
         story.info('cleverbot', `${utils.userLogString(data.username, data.id)}: --> ${config.cleverbot.enabled.toString()}`);
     }
 });
Пример #9
0
 redis.hget('user:roles', data.id).then(perm => {
     perm = parseInt(perm, 10);
     if (config.options.bouncerPlus ? (perm > 1) : (perm > 2)) {
         config.state.lockdown = !config.state.lockdown;
         if (config.state.lockdown) plugged.sendChat(utils.replace(langfile.lockdown.enabled, {username: data.username}), 60);
         else plugged.sendChat(utils.replace(langfile.lockdown.disabled, {username: data.username}), 60);
         //noinspection JSUnresolvedFunction
         redis.hset('meta:config', 'state:lockdown', (config.state.lockdown ? 1 : 0));
         story.info('lockdown', `${utils.userLogString(data.username, data.id)}: --> ${config.state.lockdown}`);
     }
 });
Пример #10
0
 redis.scard('meta:data:rdjskip:votes').then(card => {
     if (card + 1 >= config.rdjskip.votes) {
         plugged.sendChat(utils.replace(langfile.rdjskip.skip, {username: data.username}));
         story.info('skip', `${utils.userLogString(data.username, data.id)}: ${utils.mediatitlelog(media)} played by ${utils.userLogString(plugged.getUserByID(booth.dj))}`);
     } else {
         //noinspection JSUnresolvedFunction
         redis.sadd('meta:data:rdjskip:votes', data.id).then(() => {
             plugged.sendChat(utils.replace(langfile.rdjskip.default, {username: data.username}));
         });
     }
 });
Пример #11
0
const writeSomeLogs = () => {
  // Some example logs (including a circular reference)
  const longArray = [];
  for (let i = 0; i < 750; i++) {
    longArray.push(i);
  }
  const someInfo = {
    appName: 'Storyboard example',
    upSince: new Date(),
    dontShow: 'hidden',
    loginRequiredForLogs: true,
    nested: {
      configOptions: {
        foo: undefined,
        bar: null,
        values: [1, 2],
      },
    },
    shortBuffer: Buffer.from([0, 1, 2, 3]),
    longBuffer: Buffer.from(longArray),
  };
  someInfo.nested.configOptions.mainInfo = someInfo;
  mainStory.debug('server', 'Example info:', {
    attach: someInfo,
    attachLevel: 'TRACE',
    ignoreKeys: ['dontShow'],
  });
  mainStory.debug('server', 'A message with an undefined attachment', { attach: undefined });
  mainStory.warn('server', 'Example warning');
  mainStory.error('server', 'Example error', { attach: new Error('EXAMPLE error message') });
  setInterval(() => {
    mainStory.debug('server', `t: ${chalk.blue(new Date().toISOString())}`);
  }, 60000);

  const story = mainStory.child({ title: 'Example child story' });
  story.info('Info');
  story.warn('Warn');
  story.error('Error!');
  story.close();
};
Пример #12
0
 fs.readdir(path.resolve(__dirname, 'userfilters'), (err, files) => {
     if (err) {
         story.fatal('UserFilters', 'Cannot load userfilters', {attach: err});
         userfilters.push(Promise.resolve);
     } else {
         if (files.length === 0) userfilters.push(Promise.resolve);
         else {
             files.forEach(file => {
                 try {
                     let filter = require(path.resolve(__dirname, 'userfilters', file)); //eslint-disable-line global-require
                     if (filter.enabled) {
                         userfilters.push(filter.check);
                         story.debug('UserFilters', `Loaded userfilter ${filter.name}`);
                     } else story.debug('UserFilters', `Skipping ${filter.name} since it's disabled.`);
                 } catch (e) {
                     story.warn('UserFilters', 'Failed to load userfilter.', {attach: e});
                 }
             });
         }
         story.info('UserFilters', `Loaded ${userfilters.length} userfilters.`);
     }
 });
Пример #13
0
 const mutateAndGetPayload = async mutationArgs => {
   const { id: globalId, storyId } = mutationArgs;
   const story = mainStory.child({
     src: 'gql',
     title: `Mutation: ${name} ${globalId || ''}`,
     extraParents: storyId,
   });
   try {
     return mutate(type, op, mutationArgs, options, story);
   } finally {
     story.close();
   }
 };
Пример #14
0
 }).spread(song => {
     //noinspection JSCheckFunctionSignatures,JSUnresolvedFunction
     song.updateAttributes({
         isBanned: true,
         banReason: (split.length === 2 ? undefined : utils.blacklistReason(_.rest(split, 2).join(' ').trim()))
     });
     //noinspection JSCheckFunctionSignatures
     redis.set(`media:blacklist:${song.format}:${song.cid}`, (split.length === 2 ? 1 : _.rest(split, 2).join(' ').trim()));
     plugged.sendChat(utils.replace(langfile.blacklist.idbl.default, {
         username: data.username,
         song: utils.songtitle(song.author, song.title)
     }), 30);
     story.info('blacklist', `${utils.userLogString(data.username, data.id)} added ${utils.songtitle(song.author, song.title)}[${song.format}:${song.cid}] to the blacklist`);
 });
Пример #15
0
 function handleAsCommand() {
     //noinspection JSUnresolvedFunction
     if ((data.message).startsWith(config.options.commandPrefix)) {
         //noinspection JSUnresolvedFunction
         let split = S(data.message).chompLeft(config.options.commandPrefix).s.split(' ');
         if (commands[split[0].toLowerCase()]) {
             commands[split[0].toLowerCase()].handler(data);
             story.info('command', `${utils.userLogString(data.username, data.id)}: ${split[0]} [${data.message}]`);
         }
     } else {
         //noinspection JSUnresolvedFunction
         if ((data.message).startsWith(config.customcommands.trigger) && config.customcommands.enabled) {
             //noinspection JSUnresolvedFunction
             let splt = S(data.message).chompLeft(config.customcommands.trigger).s.split(' ');
             if (customcommands[splt[0].toLowerCase()]) {
                 customcommands[splt[0].toLowerCase()].handler(data);
                 story.info('customcommand', `${utils.userLogString(data.username, data.id)}: ${splt[0]} [${data.message}]`);
             }
             sendToCleverbot();
         }
         sendToCleverbot();
     }
 }
Пример #16
0
 redis.hget('user:roles', data.id).then(perm => {
     perm = parseInt(perm, 10);
     if (config.options.bouncerPlus ? (perm > 1) : (perm > 2)) {
         if (!config.state.eventmode) {
             config.timeguard.enabled = !config.timeguard.enabled;
             if (config.timeguard.enabled) plugged.sendChat(utils.replace(langfile.skip.timeguard.enabled, {username: data.username}), 60);
             else plugged.sendChat(utils.replace(langfile.skip.timeguard.disabled, {username: data.username}), 60);
             //noinspection JSUnresolvedFunction
             redis.hset('meta:config', 'timeguard:enabled', (config.timeguard.enabled ? 1 : 0));
             story.info('timeguard', `${utils.userLogString(data.username, data.id)}: --> ${config.timeguard.enabled.toString()}`);
         } else plugged.sendChat(utils.replace(langfile.error.eventmode, {
             username: data.username,
             cmd: 'Timeguard'
         }));
     }
 });
Пример #17
0
 }).catch(filter => {
     story.debug('Chatfilters', '', {attach: filter});
     plugged.deleteMessage(data.cid);
     if (filter.points > 0) {
         //noinspection JSUnresolvedFunction
         redis.hincrby('spam:user:spampoints', data.id, filter.points).then(points => {
             if (points > config.chatfilter.spam.points) {
                 redis.set(`user:mute:${data.id}`, 1).then(() => {
                     redis.set(`user:mute:${data.id}:violation`, 0);
                     //noinspection JSUnresolvedFunction
                     redis.expire(`user:mute:${data.id}`, config.chatfilter.spam.muteDuration);
                 });
                 plugged.sendChat(utils.replace(chatfilter.resolveMsg(filter.type).mute, {username: data.username}));
             } else plugged.sendChat(utils.replace(chatfilter.resolveMsg(filter.type).warn, {username: data.username}));
         });
     }
 });
Пример #18
0
 redis.exists('meta:state:skipable').then(ex => {
     perm = parseInt(perm, 10);
     let booth = utils.clone(plugged.getBooth());
     let media = utils.clone(plugged.getMedia());
     if (perm > 1 && ex === 0) {
         plugged.sendChat(utils.replace(langfile.skip.default, {username: data.username}), 70);
         plugged.skipDJ(booth.dj);
         redis.set('meta:state:skipable', 1, 'EX', 2);
         setTimeout(() => {
             let split = data.message.trim().split(' ');
             if (langfile.skip.reasons[split[1]]) {
                 plugged.sendChat(utils.replace(langfile.skip.reasons[split[1]], {
                     username: plugged.getUserByID(booth.dj).username,
                     song: utils.songtitle(media.author, media.title)
                 }), 60);
             }
         }, 4 * 1000);
         story.info('skip', `${utils.userLogString(data.username, data.id)}: ${utils.mediatitlelog(media)} played by ${utils.userLogString(plugged.getUserByID(booth.dj))}`);
     } else if (perm === 1 && ex === 0 && config.rdjskip.enabled) {
         //noinspection JSUnresolvedFunction
         redis.sismember('meta:data:rdjskip:votes', data.id).then(is => {
             if (is === 0) {
                 redis.get('meta:data:staff:active').then(active => {
                     active = parseInt(active, 10);
                     if (active <= config.rdjskip.maxStaffActive) {
                         //noinspection JSUnresolvedFunction
                         redis.scard('meta:data:rdjskip:votes').then(card => {
                             if (card + 1 >= config.rdjskip.votes) {
                                 plugged.sendChat(utils.replace(langfile.rdjskip.skip, {username: data.username}));
                                 story.info('skip', `${utils.userLogString(data.username, data.id)}: ${utils.mediatitlelog(media)} played by ${utils.userLogString(plugged.getUserByID(booth.dj))}`);
                             } else {
                                 //noinspection JSUnresolvedFunction
                                 redis.sadd('meta:data:rdjskip:votes', data.id).then(() => {
                                     plugged.sendChat(utils.replace(langfile.rdjskip.default, {username: data.username}));
                                 });
                             }
                         });
                     }
                 });
             }
         });
     }
 });
Пример #19
0
 handler: (data)=> {
     data = data[0];
     if (data.moderatorID !== plugged.getSelf().id) {
         redis.hget('user:roles' , data.moderatorID).then(perm => {
             perm = parseInt(perm, 10);
             if (perm > 2) {
                 redis.hset('user:roles', data.id, data.role);
                 db.models.User.update({sRole: data.role}, {where: {id: data.id}});
             } else {
                 //noinspection JSUnresolvedFunction
                 redis.hget('user:roles', data.id).then(permlvl => {
                     permlvl = parseInt(permlvl, 10);
                     let role = utils.role(permlvl);
                     if (role === plugged.USERROLE.NONE) plugged.removeStaff(data.id);
                     else plugged.addStaff(data.id, role);
                     plugged.sendChat(utils.replace(langfile.setstaff.noPower, {username: data.moderator}), 60);
                 });
             }
         });
         story.info('promote', `${utils.userLogString(data.moderator, data.moderatorID)}: ${utils.userLogString(data.username, data.id)} --> ${utils.rolename(data.role)}`);
     }
 }
Пример #20
0
 handler:  (err) =>{
     story.error('Error', 'The connection dropped unexpectedly', {attach: err});
     process.exit(1);
 }
Пример #21
0
import { mainStory, config, addListener } from 'storyboard';
import consoleListener from 'storyboard-listener-console';
// import fileListener from 'storyboard-listener-file';
import wsServerListener from 'storyboard-listener-ws-server';

import createHttpServer from './httpServer';
import db from './db';
import writeSomeLogs from './writeSomeLogs';

config({ filter: '*:*' });
addListener(consoleListener);
// addListener(fileListener);

// Initialise our server
mainStory.info('server', 'Initialising server...');
const httpServer = createHttpServer();

// Allow remote access to server logs via WebSockets
// (asking for credentials)
addListener(wsServerListener, {
  httpServer,
  // authenticate: ({ login }) => login !== 'unicorn',
});

// Initialise our fake database
db.init();

writeSomeLogs();

process.on('SIGINT', () => process.exit());
Пример #22
0
 }).catch(err => {
     story.warn('web', 'Error getting CustomCommands', {attach: err});
     res.status(500).end();
 });
Пример #23
0
 setInterval(() => {
   mainStory.debug('server', `t: ${chalk.blue(new Date().toISOString())}`);
 }, 60000);
Пример #24
0
 }).catch((err)=> {
     next({code: 5200});
     story.warn('SQL-Error', '', {attach: err});
 });
Пример #25
0
    handler: (data) => {
        if (data.id !== plugged.getSelf().id) {
            if (config.state.lockdown) {
                //noinspection JSUnresolvedFunction
                redis.hget('user:roles', data.id).then(perm => {
                    perm = parseInt(perm, 10);
                    if (perm < 1) plugged.removeChatMessage(data.cid);
                    else handleAsCommand();
                });
            } else {
                //noinspection JSUnresolvedFunction
                redis.exists(`user:mute:${data.id}`).then(exm => {
                    if (exm === 1) {
                        plugged.removeChatMessage(data.cid);
                        //noinspection JSUnresolvedFunction
                        if (!(data.message).startsWith(config.options.commandPrefix)) {
                            //noinspection JSUnresolvedFunction
                            redis.incr(`user:mute:${data.id}:violation`).then(() => {
                                redis.get(`user:mute:${data.id}:violation`).then(val => {
                                    if (parseInt(val, 10) > config.chatfilter.spam.muteViolation) {
                                        plugged.muteUser(data.id, plugged.MUTEDURATION.LONG, plugged.BANREASON.SPAMMING, err => {
                                            if (!err) plugged.sendChat(utils.replace(langfile.chatfilter.spam.hardMute, {username: data.username}), 60);
                                        });
                                    }
                                });
                            });
                        }
                    } else if (config.chatfilter.enabled) {
                        //noinspection JSUnresolvedFunction
                        redis.hget('user:roles', data.id).then(role => {
                            role = parseInt(role);
                            if (role < config.chatfilter.ignorerole) {
                                return Promise.all(chatfilter.filters.map(e => e(data)));
                            }
                            return Promise.resolve();
                        }).then(() => {
                            handleAsCommand();
                        }).catch(filter => {
                            story.debug('Chatfilters', '', {attach: filter});
                            plugged.deleteMessage(data.cid);
                            if (filter.points > 0) {
                                //noinspection JSUnresolvedFunction
                                redis.hincrby('spam:user:spampoints', data.id, filter.points).then(points => {
                                    if (points > config.chatfilter.spam.points) {
                                        redis.set(`user:mute:${data.id}`, 1).then(() => {
                                            redis.set(`user:mute:${data.id}:violation`, 0);
                                            //noinspection JSUnresolvedFunction
                                            redis.expire(`user:mute:${data.id}`, config.chatfilter.spam.muteDuration);
                                        });
                                        plugged.sendChat(utils.replace(chatfilter.resolveMsg(filter.type).mute, {username: data.username}));
                                    } else plugged.sendChat(utils.replace(chatfilter.resolveMsg(filter.type).warn, {username: data.username}));
                                });
                            }
                        });
                    } else handleAsCommand();
                });
            }
            //noinspection JSUnresolvedFunction
            if (!(data.message).includes('[AFK]')) {
                db.models.User.update({
                    lastActive: new Date(),
                    wlRemoves: 0,
                    afkLevel: 'active'
                }, {where: {id: data.id}});
            }
        }
        story.info('chat', `${data.username}[${data.id}]: ${data.message}`);
        webSockUpdate({m: data.message, u: {id: data.id, n: plugged.getUserByID(data.id).username}, cid: data.cid});

        function handleAsCommand() {
            //noinspection JSUnresolvedFunction
            if ((data.message).startsWith(config.options.commandPrefix)) {
                //noinspection JSUnresolvedFunction
                let split = S(data.message).chompLeft(config.options.commandPrefix).s.split(' ');
                if (commands[split[0].toLowerCase()]) {
                    commands[split[0].toLowerCase()].handler(data);
                    story.info('command', `${utils.userLogString(data.username, data.id)}: ${split[0]} [${data.message}]`);
                }
            } else {
                //noinspection JSUnresolvedFunction
                if ((data.message).startsWith(config.customcommands.trigger) && config.customcommands.enabled) {
                    //noinspection JSUnresolvedFunction
                    let splt = S(data.message).chompLeft(config.customcommands.trigger).s.split(' ');
                    if (customcommands[splt[0].toLowerCase()]) {
                        customcommands[splt[0].toLowerCase()].handler(data);
                        story.info('customcommand', `${utils.userLogString(data.username, data.id)}: ${splt[0]} [${data.message}]`);
                    }
                    sendToCleverbot();
                }
                sendToCleverbot();
            }
        }

        function sendToCleverbot() {
            //noinspection JSUnresolvedFunction
            if (config.cleverbot.enabled && (data.message).includes(`@${plugged.getSelf().username}`)) {
                cleverbot(data);
            }
        }
    }
Пример #26
0
 return (err, req, res, next)=> {
     var payload;
     switch (err.code) {
         case 301 || 302:
             if (req.method === 'GET') {
                 res.status(err.code).redirect(err.location);
             } else {
                 err.code = 400;
                 payload = {
                     message: 'The requested resource is ot available under this uri. Please use the uri specified in the location variable',
                     error: 'location_invalid',
                     location: err.location
                 };
                 err.err_context = 'Error<ApiLocationError>'
             }
             break;
         case 401:
             payload = {
                 message: 'Token invalid. Please supply a valid token.',
                 error: 'invalid_token'
             };
             break;
         case 403:
             payload = {
                 message: 'Insufficient Permission. The Token you supplied does not have the permission to access this resource.',
                 error: 'insufficient_permission'
             };
             break;
         case 404:
             payload = {
                 message: 'The requested resource could not be found.',
                 error: 'not_found'
             };
             break;
         case 429:
             payload = {
                 message: `You've exceeded the ratelimit for this key. You will have to wait ${err.wait} ms before you make any further request. Any further request will lead to blacklisting your ip for up to 48 hours.`,
                 error: 'rate_limit_exceeded',
                 wait: err.wait
             };
             break;
         case 4006:
             err.code = 400;
             payload = {
                 message: 'Invalid Origin Header',
                 error: 'invalid_origin_header'
             };
             break;
         case 4007:
             err.code = 400;
             payload = {
                 message: 'The given origin is not allowed to access this endpoint.',
                 error: 'origin_not_allowed'
             };
             break;
         case 4404:
             err.code = 404;
             payload = {
                 message: 'The requested endpoint does not exist or is not reachable with this method',
                 error: 'invalid_endpoint'
             };
             break;
         case 5200:
             err.code = 500;
             payload = {
                 message: 'The server encountered an error querying the database. Please try again later!',
                 error: 'database'
             };
             break;
         case 5900:
             err.code = 500;
             payload = {
                 message: 'There was an error in the application providing this api.',
                 error: 'code_internal'
             };
             break;
         default:
             err.code = 500;
             payload = {
                 message: 'The server encountered an unknown error.',
                 error: 'unknown'
             };
             story.error('http', 'A route threw an unknown error.', {attach: err});
             break;
     }
     res.status(err.code).json({
         data: payload,
         context: err.err_context || 'Error<ApiError>',
         time: new Date(),
         warnings: req.warnings
     });
 }
Пример #27
0
 }).catch(err=> {
     next();
     story.error('sql', 'auth', {attach: err});
 })
Пример #28
0
let plugged = require('./client'),
    utils = require('./utils');

let cleverbot = null,
    ready = false;

try {
    let Cleverbot = require('cleverbot-node'); //eslint-disable-line global-require
    cleverbot = new Cleverbot;
    Cleverbot.prepare(() => {
        story.info('cleverbot', 'Cleverbot loaded and ready.');
        ready = true;
    });
} catch (e) {
    cleverbot = null;
    story.info('cleverbot', 'Unable to load cleverbot-integration.');
    story.debug('cleverbot', 'Unable to load cleverbot-integration.', {attach: e});
}

module.exports = (data) => {
    if (cleverbot && ready && config.cleverbot.enabled) {
        cleverbot.write(data.message.replace(`@${plugged.getSelf().username}`, '').trim(), (resp) => {
            story.debug('cleverbot', resp.message);
            plugged.sendChat(utils.replace(langfile.cleverbot.format, {
                username: data.username,
                message: resp.message
            }));
        });
    }
};
Пример #29
0
/* eslint-env browser */
import moment from 'moment';
import { mainStory, addListener } from 'storyboard';
import wsClient from 'storyboard-listener-ws-client';
import browserExtension from 'storyboard-listener-browser-extension';
import React from 'react';
import ReactDOM from 'react-dom';
import createRelayEnvironment from './gral/relay';
import App from './components/aaApp';
import _t from '../translate';

addListener(wsClient);
addListener(browserExtension);

mainStory.info('startup', 'Launching...');

// Process bootstrap: set up language and delete prerendered styles
_t.setLocales(window.AppBootstrap.locales);
moment.locale(window.AppBootstrap.lang);
const preRenderedStyles = document.getElementById('preRenderedStyles');
if (preRenderedStyles) {
  document.getElementsByTagName('head')[0].removeChild(preRenderedStyles);
}

// Bootstrap relay
const relayEnvironment = createRelayEnvironment(window.AppBootstrap.relayData);

ReactDOM.render(
  <App relayEnvironment={relayEnvironment} />,
  document.getElementById('mady-app')
Пример #30
0
 Cleverbot.prepare(() => {
     story.info('cleverbot', 'Cleverbot loaded and ready.');
     ready = true;
 });