How to use the monochrome-bot.PublicError.createWithCustomPublicMessage function in monochrome-bot

To help you get started, we’ve selected a few monochrome-bot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mistval / kotoba / src / discord_commands / quiz.js View on Github external
.replace(/norace/g, '')
      .trim();

    // Hack: manipulate the returned server settings
    if (isNoDelay) {
      serverSettings['quiz/japanese/new_question_delay_after_unanswered'] = 0;
      serverSettings['quiz/japanese/new_question_delay_after_answered'] = 0;
      serverSettings['quiz/japanese/additional_answer_wait_time'] = 0;
    }

    // Delete operation
    if (suffixReplaced.startsWith('delete')) {
      const searchTerm = suffixReplaced.split(' ')[1];
      if (!searchTerm) {
        const message = 'Say **k!quiz delete deckname** to delete a custom quiz deck.';
        throw PublicError.createWithCustomPublicMessage(message, false, 'No deck name provided');
      }
      return deleteInternetDeck(msg, suffixReplaced.split(' ')[1], msg.author.id);
    }

    // Save operation
    if (suffixReplaced === 'save') {
      return quizManager.saveQuiz(msg.channel.id, msg.author.id);
    }

    // Stop operation
    if (suffixReplaced.startsWith('stop') || suffixReplaced.startsWith('end') || suffixReplaced.startsWith('endquiz') || suffixReplaced.startsWith('quit')) {
      return quizManager.stopQuiz(msg.channel.id, msg.author.id, msg.authorIsServerAdmin);
    }

    // Help operation
    if (!suffixReplaced || suffixReplaced === 'help') {
github mistval / kotoba / src / discord_commands / quiz.js View on Github external
function getReviewDeckOrThrow(deck, prefix) {
  if (!deck) {
    const message = {
      embed: {
        title: 'Review deck not found',
        description: `I don\'t remember the session you want to review. Say **${prefix}quiz** to start a new session!`,
        color: constants.EMBED_NEUTRAL_COLOR,
      },
    };
    throw PublicError.createWithCustomPublicMessage(message, false, 'Review deck not found');
  }
  return deck;
}
github mistval / kotoba / src / discord_commands / quiz.js View on Github external
function throwIfSessionInProgressAtLocation(locationId, prefix) {
  if (quizManager.isSessionInProgressAtLocation(locationId)) {
    const message = {
      embed: {
        title: 'Quiz In Progress',
        description: `Only one quiz can run in a channel at a time. Try another channel, or DM. You can stop the currently running quiz by saying **${prefix}quiz stop**`,
        color: constants.EMBED_NEUTRAL_COLOR,
      },
    };
    throw PublicError.createWithCustomPublicMessage(message, false, 'Session in progress');
  }
}
github mistval / kotoba / src / discord_commands / quiz.js View on Github external
function throwIfShutdownScheduled(channelId) {
  if (globals.shutdownScheduled) {
    state.scheduledShutdown.shutdownNotifyChannels.push(channelId);
    throw PublicError.createWithCustomPublicMessage({
        embed: {
          title: 'Scheduled Update',
          description: 'I\'m scheduled to reboot for an update in a few minutes so now\'s a bad time :) Please try again in about three minutes.',
          color: constants.EMBED_WARNING_COLOR,
          footer: {
            icon_url: constants.FOOTER_ICON_URI,
            text: 'I\'m getting an update! Yay!',
          },
        },
      },
      false,
      'Shutdown scheduled',
    );
  }
}
github mistval / kotoba / api / quiz / common / deck_loader.js View on Github external
function throwParsePublicError(errorReason, lineIndex, uri) {
  throw PublicError.createWithCustomPublicMessage(`Error parsing deck data at <${uri}> line ${lineIndex + 1}: ${errorReason}`, false, 'Community deck validation error');
}
github mistval / kotoba / src / discord_commands / quiz.js View on Github external
function throwIfInternetCardsNotAllowed(isDm, session, internetCardsAllowed, prefix) {
  if (!internetCardsAllowed && !isDm && session.containsInternetCards()) {
    const message = {
      embed: {
        title: 'Internet decks disabled',
        description: `That deck contains internet cards, but internet decks are disabled in this channel. You can try in a different channel, or in a DM, or ask a server admin to enable internet decks by saying **${prefix}settings quiz/japanese/internet_decks_enabled enabled**`,
        color: constants.EMBED_NEUTRAL_COLOR,
      },
    };
    throw PublicError.createWithCustomPublicMessage(message, false, 'Internet decks disabled');
  }
}
github mistval / kotoba / src / discord_commands / quiz.js View on Github external
function throwIfGameModeNotAllowed(isDm, gameMode, masteryEnabled, prefix) {
  if (!masteryEnabled && !isDm &&
      (gameMode.isMasteryMode ||
       gameMode.isConquestMode ||
       gameMode.serializationIdentifier === MasteryGameMode.serializationIdentifier ||
       gameMode.serializationIdentifier === ConquestGameMode.serializationIdentifier)) {
    const message = {
      embed: {
        title: 'Game mode disabled',
        description: `That game mode is not enabled in this channel. You can try it in a different channel, or via DM, or ask a server admin to enable the game mode by saying **${prefix}settings quiz/japanese/conquest_and_inferno_enabled enabled**`,
        color: constants.EMBED_NEUTRAL_COLOR,
      },
    };
    throw PublicError.createWithCustomPublicMessage(message, false, 'Game mode disabled');
  }
}
github mistval / kotoba / src / discord_commands / random.js View on Github external
async function getRandomWordRecursive(suffix, msg, retriesRemaining, logger, navigationManager) {
  if (retriesRemaining <= 0) {
    throw PublicError.createWithCustomPublicMessage(
      jishoNotRespondingResponse,
      false,
      `Failed to get a random word ${NUMBER_OF_RETRIES} times`,
    );
  }

  const word = getRandomWord(suffix);

  let jishoData;
  try {
    jishoData = await jishoWordSearch(word);
  } catch (err) {
    throw PublicError.createWithCustomPublicMessage(jishoNotRespondingResponse, false, 'Jisho request error', err);
  }

  if (!jishoData.hasResults) {
    return getRandomWordRecursive(suffix, msg, retriesRemaining - 1, logger, navigationManager);
  }

  return jishoSearch.createNavigationForJishoResults(
    msg,
    msg.author.username,
    msg.author.id,
    jishoData,
    navigationManager,
  );
}
github mistval / kotoba / src / discord_commands / help.js View on Github external
const commandsToDisplayHelpFor = getCommandsForTopLevelHelpInOrder(
    enabledNonHiddenCommands,
    COMMANDS_TO_GENERATE_HELP_FOR,
  );

  const navigation = createNavigationForCommands(commandsToDisplayHelpFor, msg, paginate);
  if (navigation) {
    return monochrome.getNavigationManager().show(
      navigation,
      NAVIGATION_EXPIRATION_TIME_MS,
      msg.channel,
      msg,
    );
  }

  throw PublicError.createWithCustomPublicMessage('There are no commands to show help for. Perhaps the server admins disabled all my commands in this channel.', false, 'No commands to display');
}