Skip to content

Commit

Permalink
🎉 5.0.0 - Remove gameType to comply with API. Adds GitHub CODEOWNER…
Browse files Browse the repository at this point in the history
…S and BmaC link
  • Loading branch information
WillTDA committed Apr 27, 2024
1 parent 97bc8f1 commit 5bd623e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# learn more: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
* @WillTDA
2 changes: 2 additions & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# learn more: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository
buy_me_a_coffee: willtda
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.github/
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@

<center style="margin-bottom:1rem;">A Discord.js v14 module that allows you to create an Akinator command for your discord bot in a matter of seconds.</center>

[![NPM](https://nodei.co/npm/discord.js-akinator.png)](https://npmjs.com/package/discord.js-akinator)
<div align="center">

[![Downloads](https://img.shields.io/npm/dt/discord.js-akinator?logo=npm&style=flat-square)](https://npmjs.com/package/discord.js-akinator) [![Discord Server](https://img.shields.io/discord/667479986214666272?logo=discord&logoColor=white&style=flat-square)](https://diamonddigital.dev/discord)
![license](https://img.shields.io/npm/l/discord.js-akinator?style=flat-square)
[![version](https://img.shields.io/npm/v/discord.js-akinator?style=flat-square)](https://npmjs.com/package/discord.js-akinator)
[![gzipped size](https://img.shields.io/bundlejs/size/discord.js-akinator?style=flat-square)](https://npmjs.com/package/discord.js-akinator)
[![downloads](https://img.shields.io/npm/dt/discord.js-akinator?style=flat-square)](https://npmjs.com/package/discord.js-akinator)
![last commit](https://img.shields.io/github/last-commit/WillTDA/Discord.js-Akinator?style=flat-square)

<a href="https://www.buymeacoffee.com/willtda" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
[![discord](https://img.shields.io/discord/667479986214666272?logo=discord&logoColor=white&style=flat-square)](https://diamonddigital.dev/discord)
[![buy me a coffee](https://img.shields.io/badge/-Buy%20Me%20a%20Coffee-ffdd00?logo=Buy%20Me%20A%20Coffee&logoColor=000000&style=flat-square)](https://www.buymeacoffee.com/willtda)

</div>

<br />

## Features

Expand Down Expand Up @@ -56,7 +65,6 @@ client.on("ready", () => {

const language = "en"; //The language of the game. Defaults to "en".
const childMode = false; //Whether to use Akinator's Child Mode. Defaults to "false".
const gameType = "character"; //The type of Akinator game to be played. ("animal", "character" or "object"). Defaults to "character".
const useButtons = true; //Whether to use Discord's buttons instead of message input for answering questions. Defaults to "true".
const embedColor = "#1F1E33"; //The color of the message embeds. Defaults to "Random".
const translationCachingOptions = {
Expand All @@ -75,7 +83,6 @@ client.on("interactionCreate", async interaction => {
akinator(interaction, {
language: language,
childMode: childMode,
gameType: gameType,
useButtons: useButtons,
embedColor: embedColor,
translationCaching: translationCachingOptions
Expand All @@ -96,7 +103,6 @@ client.on("messageCreate", async message => {
akinator(message, {
language: language,
childMode: childMode,
gameType: gameType,
useButtons: useButtons,
embedColor: embedColor,
translationCaching: translationCachingOptions
Expand All @@ -114,8 +120,10 @@ Special thanks to [many people](https://github.com/WillTDA/Discord.js-Akinator/g
- 👋 Need help? [Join our Discord Server](https://diamonddigital.dev/discord)!

- 👾 Found a bug, or inaccurate translations? [Open an issue](https://github.com/WillTDA/Discord.js-Akinator/issues), or fork and [submit a pull request](https://github.com/WillTDA/Discord.js-Akinator/pulls) on our [GitHub repository](https://github.com/WillTDA/Discord.js-Akinator)!
<hr>
<center>
<a href="https://diamonddigital.dev/"><strong>Created and maintained by</strong>
<img align="center" style="width:25%;height:auto" src="https://diamonddigital.dev/img/png/ddd_logo_text_transparent.png" alt="Diamond Digital Development Logo"></a>
</center>

---

<a href="https://diamonddigital.dev/">
<strong>Created and maintained by</strong>
<img align="center" alt="Diamond Digital Development Logo" src="https://diamonddigital.dev/img/png/ddd_logo_text_transparent.png" style="width:25%;height:auto" />
</a>
12 changes: 4 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function getButtonReply(interaction) {
* @typedef {object} gameOptions
* @prop {string} [options.language="en"] The language of the game. Defaults to `en`.
* @prop {boolean} [options.childMode=false] Whether to use Akinator's Child Mode. Defaults to `false`.
* @prop {"character" | "animal" | "object"} [options.gameType="character"] The type of Akinator game to be played. Defaults to `character`.
* @prop {boolean} [options.useButtons=true] Whether to use Discord's buttons instead of message input for answering questions. Defaults to `true`.
* @prop {Discord.ColorResolvable} [options.embedColor="Random"] The color of the message embeds. Defaults to `Random`.
* @prop {object} [translationCaching={}] The options for translation caching.
Expand Down Expand Up @@ -54,7 +53,6 @@ module.exports = async function (input, options) {
//configuring game options if not specified
options.language = options.language || "en";
options.childMode = options.childMode !== undefined ? options.childMode : false;
options.gameType = options.gameType || "character";
options.useButtons = options.useButtons !== undefined ? options.useButtons : true;
options.embedColor = Discord.resolveColor(options.embedColor || "Random");

Expand All @@ -64,14 +62,12 @@ module.exports = async function (input, options) {
options.translationCaching.path = options.translationCaching.path || "./translationCache";

options.language = options.language.toLowerCase();
options.gameType = options.gameType.toLowerCase();

//error handling
if (!input) return console.log("Discord.js Akinator Error: Message or CommandInteraction was not provided.\nNeed help? Join our Discord server at 'https://discord.gg/P2g24jp'");
if (!input.client) return console.log("Discord.js Akinator Error: Message or CommandInteration provided was invalid.\nNeed help? Join our Discord server at 'https://discord.gg/P2g24jp'");
if (!input.guild) return console.log("Discord.js Akinator Error: Cannot be used in Direct Messages.\nNeed help? Join our Discord server at 'https://discord.gg/P2g24jp'");
if (!fs.existsSync(`${__dirname}/translations/${options.language}.json`)) return console.log(`Discord.js Akinator Error: Language "${options.language}" cannot be found. Examples: "en", "fr", "es", etc.\nNeed help? Join our Discord server at 'https://discord.gg/P2g24jp'`);
if (!["animal", "character", "object"].includes(options.gameType)) return console.log(`Discord.js Akinator Error: Game type "${options.gameType}" cannot be found. Choose from: "animal", "character" or "object".\nNeed help? Join our Discord server at 'https://discord.gg/P2g24jp'`);

try {
inputData.client = input.client,
Expand Down Expand Up @@ -109,7 +105,7 @@ module.exports = async function (input, options) {
}

//starts the game
let aki = new Aki({ region: options.gameType, childMode: options.childMode });
let aki = new Aki({ region: "en", childMode: options.childMode }); // set to en region, translation is handled later
let akiData = await aki.start();

let notFinished = true;
Expand Down Expand Up @@ -149,8 +145,8 @@ module.exports = async function (input, options) {

if (aki.guess?.id_base_proposition) { //if the algorithm has guessed the answer
let guessEmbed = {
title: `${await translate(`I'm ${Math.round(aki.progress)}% sure your ${options.gameType} is...`, options.language, options.translationCaching)}`,
description: `**${aki.guess.name_proposition}**\n${await translate(aki.guess.description_proposition, options.language, options.translationCaching)}\n\n${options.gameType == "animal" ? translations.isThisYourAnimal : options.gameType == "character" ? translations.isThisYourCharacter : translations.isThisYourObject} ${!options.useButtons ? `**(Type Y/${translations.yes} or N/${translations.no})**` : ""}`,
title: `${await translate(`I'm ${Math.round(aki.progress)}% sure your character is...`, options.language, options.translationCaching)}`,
description: `**${aki.guess.name_proposition}**\n${await translate(aki.guess.description_proposition, options.language, options.translationCaching)}\n\n${translations.isThisYourCharacter} ${!options.useButtons ? `**(Type Y/${translations.yes} or N/${translations.no})**` : ""}`,
color: options.embedColor,
image: { url: aki.guess.photo },
author: { name: usertag, icon_url: avatar },
Expand Down Expand Up @@ -182,7 +178,7 @@ module.exports = async function (input, options) {
color: options.embedColor,
author: { name: usertag, icon_url: avatar },
fields: [
{ name: translations[options.gameType], value: `**${aki.guess.name_proposition}**`, inline: true },
{ name: "Character", value: `**${aki.guess.name_proposition}**`, inline: true },
//{ name: translations.ranking, value: `**#${aki.answers[0].ranking}**`, inline: true }, //NO LONGER SUPPORTED
{ name: translations.noOfQuestions, value: `**${aki.currentStep}**`, inline: true }
]
Expand Down
2 changes: 1 addition & 1 deletion src/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const translator = require("@kreisler/js-google-translate-free");
*/

module.exports = async function translate(string, language, cachingOptions) {
if (!string) return console.log("Discord.js Akinator Translator: No String Provided!")
if (!string) return;
if (!language) return console.log("Discord.js Akinator Translator: No Language Provided!")
if (!cachingOptions) return console.log("Discord.js Akinator Translator: No Caching Options Provided!")
if (language === "en") return string; //the string will always be given in english so give the same text back
Expand Down

0 comments on commit 5bd623e

Please sign in to comment.