How to use the monochrome-bot.FulfillmentError 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 / bot / src / common / quiz / deck_loader.js View on Github external
async function tryFetchRawFromPastebin(pastebinUri) {
  /* Uncomment for testing
  return `FULL NAME: n
SHORT NAME: n
INSTRUCTIONS: fgrg
--QuestionsStart--
犬,f,
1日,いちにち/ついたち,first of the month/one day
太陽,たいよう`; */
  try {
    const response = await axios.get(pastebinUri);
    return response.data;
  } catch (err) {
    throw new FulfillmentError({
      publicMessage: 'There was an error downloading the deck from that URI. Check that the URI is correct and try again.',
      logDescription: 'Pastebin fetch error',
      err,
    });
  }
}
github mistval / kotoba / bot / 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 new FulfillmentError({
      publicMessage: message,
      logDescription: 'Game mode disable',
    });
  }
}
github mistval / kotoba / bot / 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 new FulfillmentError({
      publicMessage: message,
      logDescription: 'Review deck not found',
    });
  }

  return deck;
}
github mistval / kotoba / bot / 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 new FulfillmentError({
      publicMessage: message,
      logDescription: 'Session in progress',
    });
  }
}
github mistval / kotoba / bot / 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 new FulfillmentError({
    publicMessage: 'There are no commands to show help for. Perhaps the server admins disabled all my commands in this channel.',
    logDescription: 'No commands to display',
  });
}
github mistval / kotoba / bot / src / common / quiz / deck_loader.js View on Github external
function throwParsePublicError(errorReason, lineIndex, uri) {
  throw new FulfillmentError({
    publicMessage: `Error parsing deck data at <${uri}> line ${lineIndex + 1}: ${errorReason}`,
    logDescription: 'Community deck validation error',
  });
}
github mistval / kotoba / bot / 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 new FulfillmentError({
      publicMessage: message,
      logDescription: 'Internet decks disabled',
    });
  }
}
github mistval / kotoba / bot / src / discord_commands / random.js View on Github external
if (retriesRemaining <= 0) {
    throw new FulfillmentError({
      publicMessage: jishoNotRespondingResponse,
      logDescription: `Failed to get a random word ${NUMBER_OF_RETRIES} times`,
      logLevel: 'error',
    });
  }

  const word = getRandomWord(suffix);

  let jishoData;
  try {
    jishoData = await jishoWordSearch(word);
  } catch (err) {
    throw new FulfillmentError({
      publicMessage: jishoNotRespondingResponse,
      logDescription: 'Jisho request error',
      err,
    });
  }

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

  const navigation = jishoSearch.createNavigationForJishoResults(
    msg,
    msg.author.username,
    msg.author.id,
    jishoData,
  );