How to use monochrome-bot - 10 common examples

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 / 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 / jisho_search.js View on Github external
chapterForEmojiName[STROKE_ORDER_EMOTE] =
      strokeOrderNavigationChapterInformation.navigationChapter;
  }

  /* Create the examples (E) chapter */

  const examplesNavigationChapter = createNavigationChapterInformationForExamples(
    authorName,
    word,
  );

  chapterForEmojiName[EXAMPLES_EMOTE] = examplesNavigationChapter;

  /* Create the navigation. */

  return new Navigation(authorId, true, JISHO_EMOTE, chapterForEmojiName);
}
github mistval / kotoba / bot / src / discord / jisho_search.js View on Github external
authorId,
  crossPlatformResponseData,
) {
  const chapterForEmojiName = {};

  /* Create the Jisho (J) chapter */

  const word = crossPlatformResponseData.searchPhrase;
  const discordContents = JishoDiscordContentFormatter.formatJishoDataBig(
    crossPlatformResponseData,
    true,
    true,
    authorName,
  );

  const jishoNavigationChapter = NavigationChapter.fromContent(discordContents);
  chapterForEmojiName[JISHO_EMOTE] = jishoNavigationChapter;

  /* Create the Kanji (K) chapter */

  const kanjiNavigationChapterInformation = createNavigationChapterInformationForKanji(
    authorName,
    word,
    msg.prefix,
  );

  if (kanjiNavigationChapterInformation.hasAnyPages) {
    chapterForEmojiName[KANJI_EMOTE] =
      kanjiNavigationChapterInformation.navigationChapter;
  }

  /* Create the stroke order (S) chapter */
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');
  }
}