Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

discord.js-akinator

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord.js-akinator - npm Package Compare versions

Comparing version 3.0.2 to 3.1.0

LICENSE

4

package.json
{
"name": "discord.js-akinator",
"version": "3.0.2",
"version": "3.1.0",
"description": "A Discord.js v13 Module that allows you to Create an Akinator Command for Your Discord Bot within Seconds of Installation.",

@@ -19,3 +19,3 @@ "main": "src/index.js",

"author": "WillTDA",
"license": "ISC",
"license": "Apache-2.0",
"dependencies": {

@@ -22,0 +22,0 @@ "@vitalets/google-translate-api": "^7.0.0",

@@ -7,32 +7,18 @@ <h1 align="center">

UPDATE 3.0.0 - Lots of New Changes! (and some breaking, so be careful!)
[![NPM](https://nodei.co/npm/discord.js-akinator.png)](https://npmjs.com/package/discord.js-akinator)
New Features Include:
[![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://discord.gg/P2g24jp)
## <u>FULL TRANSLATION (100+ New Languages!)</u>
## Features
Discord.js Akinator no longer relies on other Akinator API servers to translate, as they are all slow and laggy apart from the European one. Also, they would only translate the questions and nothing else!
- 🌎 <b>100+ Languages Supported!</b> | Lightning fast translation has been made possible by Google Translate and hard-coded mappings!
By utilising Google Translate and creating hard-coded translation mappings, OVER 100 NEW LANGUAGES are now supported! Also, every piece of text is now translatable, not just the questions!
- ▶️ <b>Buttons!</b> | Don't want to type out responses to questions? This package gives you the option to use discord's buttons to easily click your answer of choice!
## <u>BUTTONS!</u>
- 🙋 <b>Child Mode!</b> | Want to filter out NSFW questions? You can choose to enable Akinator's Child Mode to keep your games squeaky clean!
With this new option, you can choose to use the new discord buttons!
- ⚡️ <b>Quick & Easy Setup</b> | This package was built with the intentions of working out-of-the-box. Only one parameter is required at least!
Do keep in mind that it is `false` by default.
## Install Package
## <u>CHILD MODE!</u>
Want to filter out NSFW questions? Simply set this option to `true`!
Again, this will default to `false`.
## <u>NO CLIENT PARAMETER NEEDED!</u>
The package no longer requires you to pass in a `Discord.Client` object to function.
Just pass in the `Discord.Message` and it'll handle the rest!
# Install Package
Let's take a look at how you can install this package into your Discord Bot Project.

@@ -46,7 +32,7 @@

For versions earlier than 3.0.0, you'll need discord.js v12. However it is recommended you update to patch bugs and security vulnerabilities, as well as getting the newest features from this package!
For versions earlier than 3.0.0, you'll need discord.js v12. However it is recommended you update to patch bugs and security vulnerabilities, as well as get the newest features from this package!
`npm i discord.js@12 --save`
# Example Code
## Example Code

@@ -68,2 +54,3 @@ ```js

const childMode = false; //Whether to use Akinator's Child Mode
const gameType = "character"; //The Type of Akinator Game to Play. ("animal", "character" or "object")
const useButtons = true; //Whether to use Discord's Buttons

@@ -76,2 +63,3 @@

childMode: childMode, //Defaults to "false"
gameType: gameType, //Defaults to "character"
useButtons: useButtons //Defaults to "false"

@@ -85,3 +73,3 @@ });

# Contributors
## Contributors

@@ -92,4 +80,6 @@ - [ChaosArising (Josh_#9733)](https://github.com/ChaosArising) (Providing compatibility for Discord.js v13)

# Need Help or Find Any Bugs? Join Our Discord Server!
## Contact Us
https://discord.gg/P2g24jp
- 👋 Need Help? [Join Our Discord Server](https://discord.gg/P2g24jp)!
- 👾 Found a Bug, or Inaccurate Translations? [Open an Issue](https://github.com/WillTDA/Discord.js-Akinator-Package-Dev/issues), or Fork and [Submit a Pull Request](https://github.com/WillTDA/Discord.js-Akinator-Package-Dev/pulls) on our [GitHub Repository](https://github.com/WillTDA/Discord.js-Akinator-Package-Dev)!

@@ -6,3 +6,3 @@ const Discord = require("discord.js");

* @param {Discord.Client} client The Discord Client.
* @param {Discord.Message} message The Message Sent by the User.
* @param {any} input The Message Sent by the User.
* @param {Discord.Message} botMessage The Message for the Bot to Send, also the message which will contain the buttons (Max. 8). MUST BE AN EMBED!

@@ -13,10 +13,10 @@ * @param {MessageButton[]} buttons An Array of Buttons.

module.exports = async function (client, message, botMessage, buttons, time) {
module.exports = async function (client, input, botMessage, buttons, time) {
//check all our params exist
if (!client) return console.log("Button Menu Error: No Client Provided!")
if (!message) return console.log("Button Menu Error: No Message Provided!")
if (!input) return console.log("Button Menu Error: No Message Provided!")
if (!botMessage) return console.log("Button Menu Error: No Bot Message Provided!")
if (!buttons) return console.log("Button Menu Error: No Buttons Provided!")
if (!time) return console.log("Button Menu Error: No Time Provided!")
//sort buttons into rows of four, as to build our menu
let buttonRow = new MessageActionRow()

@@ -46,7 +46,7 @@ let buttonRow2 = new MessageActionRow()

// create our collector
const filter = (i) => i.user == message.author.id;
const filter = (i) => i.user == input.author.id;
let selection;
await message.channel.awaitMessageComponent({
await botMessage.channel.awaitMessageComponent({
filter: filter,

@@ -53,0 +53,0 @@ time: 60000,

@@ -5,3 +5,3 @@ const Discord = require("discord.js");

const translate = require("./translate");
const input = require("./input");
const awaitInput = require("./input");
const games = new Set();

@@ -41,3 +41,3 @@ const attemptingGuess = new Set();

*
* Simply pass in the Discord Message Sent by the User to Setup the Game.
* Simply pass in the Discord Message or CommandInteraction Sent by the User to Setup the Game.
*

@@ -48,8 +48,10 @@ * __Game Options__

* - `childMode` - Whether to use Akinator's Child Mode.
* - `gameType` - The Type of Akinator Game to Play. (`animal`, `character` or `object`)
* - `useButtons` - Whether to use Discord's Buttons.
*
* @param {Discord.Message} message The Message Sent by the User.
* @param {Discord.Message | Discord.CommandInteraction} input The Message Sent by the User.
* @param {object} options The Options for the Game.
* @param {string} [options.language="en"] The Language of the Game. Defaults to "en".
* @param {boolean} [options.childMode=false] Whether to use Akinator's Child Mode. Defaults to "false".
* @param {"character" | "animal" | "object"} [options.gameType="character"] The Type of Akinator Game to Play. Defaults to "character".
* @param {boolean} [options.useButtons=false] Whether to use Discord's Buttons. Defaults to "false".

@@ -68,6 +70,7 @@ * @returns {Promise<Discord.Message>} Discord.js Akinator Game

*
* //Defining options
* //Example options
*
* const language = "en"; //The Language of the Game
* const childMode = false; //Whether to use Akinator's Child Mode
* const gameType = "character"; //The Type of Akinator Game to Play. ("animal", "character" or "object")
* const useButtons = true; //Whether to use Discord's Buttons

@@ -80,2 +83,3 @@ *

* childMode: childMode, //Defaults to "false"
* gameType: gameType, //Defaults to "character"
* useButtons: useButtons //Defaults to "false"

@@ -87,3 +91,4 @@ * });

module.exports = async function (message, options = {}) {
module.exports = async function (input, options = {}) {
let inputData = {};
try {

@@ -93,28 +98,43 @@ // configuring game options if not specified

options.childMode = options.childMode || false;
options.gameType = options.gameType || "character";
options.useButtons = options.useButtons || false;
options.language = options.language.toLowerCase();
options.gameType = options.gameType.toLowerCase();
// error handling
if (!message) return console.log("Discord.js Akinator Error: Message was not Provided.\nNeed Help? Join Our Discord Server at 'https://discord.gg/P2g24jp'");
if (!message instanceof Discord.Message) return console.log("Discord.js Akinator Error: Message Provided was Invalid.\nNeed Help? Join Our Discord Server at 'https://discord.gg/P2g24jp'");
if (!message.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: options.language "${options.language}" Not Found. Example: "en" or "fr" or "es".\nNeed Help? Join Our Discord Server at 'https://discord.gg/P2g24jp'`);
if (!options.useButtons) options.useButtons = false;
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 the input is not a Discord.Message or CommandInteraction, return an error
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}" Not Found. Examples are: "en" or "fr" or "es".\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}" Not Found. Choose from: "animal", "character" or "object".\nNeed Help? Join Our Discord Server at 'https://discord.gg/P2g24jp'`);
try {
inputData.client = input.client,
inputData.guild = input.guild,
inputData.author = input.author ? input.author : input.user,
inputData.channel = input.channel
} catch {
return console.log("Discord.js Akinator Error: Failed to Parse Input for Use.\nJoin Our Discord Server for Support at 'https://discord.gg/P2g24jp'");
}
// defining for easy use
let usertag = message.author.tag
let avatar = message.author.displayAvatarURL()
let usertag = inputData.author.tag
let avatar = inputData.author.displayAvatarURL()
// check if a game is being hosted by the player
if (games.has(message.author.id)) {
if (games.has(inputData.author.id)) {
let alreadyPlayingEmbed = new Discord.MessageEmbed()
.setAuthor(usertag, avatar)
.setTitle(`❌ ${await translate("You're already playing!", options.language)}`)
.setDescription(`**${await translate("You're already playing a game of Akinator. Type `S` or `Stop` to cancel your game.", options.language)}**`)
.setDescription(`**${await translate(`You're already playing a game of Akinator. ${!options.useButtons ? `Type \`S\` or \`Stop\`` : `Press the \`Stop\` button on the previous game's message`} to cancel your game.`, options.language)}**`)
.setColor("RED")
return message.channel.send({ embeds: [alreadyPlayingEmbed] })
if (input.user) return input.reply({ embeds: [alreadyPlayingEmbed] })
else return input.channel.send({ embeds: [alreadyPlayingEmbed] })
}
// adding the player into the game
games.add(message.author.id)
games.add(inputData.author.id)

@@ -127,4 +147,7 @@ let startingEmbed = new Discord.MessageEmbed()

let startingMessage = await message.channel.send({ embeds: [startingEmbed] })
let startingMessage;
if (input.user) startingMessage = await input.reply({ embeds: [startingEmbed] })
else startingMessage = await input.channel.send({ embeds: [startingEmbed] })
// get translation object for the language

@@ -134,3 +157,4 @@ let translations = require(`${__dirname}/translations/${options.language}.json`);

// starts the game
let aki = new Aki("en", options.childMode)
let gameTypeRegion = options.gameType == "animal" ? "en_animals" : options.gameType == "character" ? "en" : "en_objects";
let aki = new Aki(gameTypeRegion, options.childMode)
await aki.start();

@@ -145,3 +169,3 @@

.setTitle(translations.gameEnded)
.setDescription(`**${message.author.username}, ${translations.gameEndedDesc}**`)
.setDescription(`**${inputData.author.username}, ${translations.gameEndedDesc}**`)
.setColor("RANDOM")

@@ -158,11 +182,13 @@

await startingMessage.delete();
let akiMessage = await message.channel.send({ embeds: [akiEmbed] });
if (input.user) await input.deleteReply();
else await startingMessage.delete();
let akiMessage = await inputData.channel.send({ embeds: [akiEmbed] });
// if message was deleted, quit the player from the game
message.client.on("messageDelete", async deletedMessage => {
inputData.client.on("messageDelete", async deletedMessage => {
if (deletedMessage.id == akiMessage.id) {
notFinished = false;
games.delete(message.author.id)
attemptingGuess.delete(message.guild.id)
games.delete(inputData.author.id)
attemptingGuess.delete(inputData.guild.id)
await aki.win()

@@ -179,4 +205,4 @@ return;

if (((aki.progress >= 95 && (stepsSinceLastGuess >= 10 || hasGuessed == false)) || aki.currentStep >= 78) && (!attemptingGuess.has(message.guild.id))) {
attemptingGuess.add(message.guild.id)
if (((aki.progress >= 95 && (stepsSinceLastGuess >= 10 || hasGuessed == false)) || aki.currentStep >= 78) && (!attemptingGuess.has(inputData.guild.id))) {
attemptingGuess.add(inputData.guild.id)
await aki.win();

@@ -198,7 +224,7 @@

await input(options.useButtons, message, akiMessage, true, translations, options.language)
await awaitInput(options.useButtons, inputData, akiMessage, true, translations, options.language)
.then(async response => {
if (response === null) {
notFinished = false;
games.delete(message.author.id)
games.delete(inputData.author.id)
akiMessage.edit({ embeds: [noResEmbed], components: [] })

@@ -210,3 +236,3 @@ return;

attemptingGuess.delete(message.guild.id)
attemptingGuess.delete(inputData.guild.id)

@@ -218,3 +244,3 @@ // if they answered yes

.setTitle(translations.wellPlayed)
.setDescription(`**${message.author.username}, ${translations.guessedRightOneMoreTime}**`)
.setDescription(`**${inputData.author.username}, ${translations.guessedRightOneMoreTime}**`)
.addField(translations.character, `**${await translate(aki.answers[0].name, options.language)}**`, true)

@@ -227,3 +253,3 @@ .addField(translations.ranking, `**#${aki.answers[0].ranking}**`, true)

notFinished = false;
games.delete(message.author.id)
games.delete(inputData.author.id)
return;

@@ -237,3 +263,3 @@

.setTitle(`Well Played!`)
.setDescription(`**${message.author.username}, ${translations.defeated}**`)
.setDescription(`**${inputData.author.username}, ${translations.defeated}**`)
.setColor("RANDOM")

@@ -243,3 +269,3 @@ if (options.useButtons) await response.update({ embeds: [finishedGameDefeated], components: [] })

notFinished = false;
games.delete(message.author.id)
games.delete(inputData.author.id)
} else {

@@ -269,3 +295,3 @@ if (options.useButtons) await response.update({ embeds: [guessEmbed], components: [] })

await input(options.useButtons, message, akiMessage, false, translations, options.language)
await awaitInput(options.useButtons, inputData, akiMessage, false, translations, options.language)
.then(async response => {

@@ -275,3 +301,3 @@ if (response === null) {

notFinished = false;
games.delete(message.author.id)
games.delete(inputData.author.id)
return akiMessage.edit({ embeds: [noResEmbed], components: [] })

@@ -318,7 +344,7 @@ }

} else if (answer == "s" || answer == translations.stop.toLowerCase()) {
games.delete(message.author.id)
games.delete(inputData.author.id)
let stopEmbed = new Discord.MessageEmbed()
.setAuthor(usertag, avatar)
.setTitle(translations.gameEnded)
.setDescription(`**${message.author.username}, ${translations.gameForceEnd}**`)
.setDescription(`**${inputData.author.username}, ${translations.gameForceEnd}**`)
.setColor("RANDOM")

@@ -337,4 +363,4 @@ await aki.win()

// log any errors that come
attemptingGuess.delete(message.guild.id)
games.delete(message.guild.id)
attemptingGuess.delete(inputData.guild.id)
games.delete(inputData.guild.id)
if (e == "DiscordAPIError: Unknown Message") return;

@@ -341,0 +367,0 @@ else if (e == "DiscordAPIError: Cannot send an empty message") return console.log("Discord.js Akinator Error: Discord.js v13 or Higher is Required.\nNeed Help? Join Our Discord Server at 'https://discord.gg/P2g24jp'");

@@ -7,3 +7,3 @@ const buttonMenu = require("./buttonMenu");

* @param {boolean} useButtons If true, use buttons. If false, use text input
* @param {Discord.Message} message The Message Sent by the User.
* @param {any} input The Message Sent by the User.
* @param {Discord.Message} botMessage The Message for the Bot to Send, also the message which will contain the buttons (Max. 8). MUST BE AN EMBED!

@@ -13,3 +13,3 @@ *

module.exports = async function input(useButtons, message, botMessage, isGuessFilter, translations, language) {
module.exports = async function awaitInput(useButtons, input, botMessage, isGuessFilter, translations, language) {
//check if useButtons is true. If so, use buttons. If not, use text input

@@ -69,3 +69,3 @@ if (useButtons) {

let choice = await buttonMenu(message.client, message, botMessage, answerTypes, 60000);
let choice = await buttonMenu(input.client, input, botMessage, answerTypes, 60000);
if (!choice) return null;

@@ -78,3 +78,3 @@ else return choice;

filter = x => {
return (x.author.id === message.author.id && ([
return (x.author.id === input.author.id && ([
"y",

@@ -88,3 +88,3 @@ translations.yes.toLowerCase(),

filter = x => {
return (x.author.id === message.author.id && ([
return (x.author.id === input.author.id && ([
"y",

@@ -109,3 +109,3 @@ translations.yes.toLowerCase(),

}
let response = await message.channel.awaitMessages({
let response = await input.channel.awaitMessages({
filter: filter,

@@ -112,0 +112,0 @@ max: 1,

{
"gameEnded": "Permainan berakhir",
"gameEndedDesc": "Permainan anda telah berakhir kerana 1 minit tidak aktif.",
"question": "Mempersoalkan",
"gameEnded": "Permainan telah berakhir",
"gameEndedDesc": "Permainan anda telah berakhir kerana anda tidak aktif selama 1 minit.",
"question": "Soalan",
"progress": "Kemajuan",
"pleaseType": "Sila taipkan ...",
"stopTip": "Anda juga boleh menaip \"S\" atau \"berhenti\" untuk menamatkan permainan anda",
"stopTip": "Anda juga boleh menaip \"S\" atau \"Stop\" untuk menamatkan permainan anda",
"yes": "Ya.",
"no": "Tidak",
"dontKnow": "Tidak tahu",
"dontKnowNoComma": "DONT TAHU",
"dontKnowNoComma": "TIDAK TAHU",
"probably": "Mungkin",
"probablyNot": "Mungkin tidak",
"back": "BACK",
"back": "Kembali",
"stop": "Berhenti",
"thinking": "Berfikir ...",
"thinking": "Sedang Berfikir ...",
"isThisYourCharacter": "Adakah ini watak anda?",
"ranking": "Kedudukan",
"noOfQuestions": "Bilangan soalan",
"wellPlayed": "Baik dimainkan!",
"guessedRightOneMoreTime": "Saya meneka dengan betul sekali lagi!",
"wellPlayed": "Anda telah bermain dengan baik!",
"guessedRightOneMoreTime": "Saya telah meneka dengan betul sekali lagi!",
"character": "Watak",
"defeated": "Bravo! Anda telah mengalahkan saya ...",
"gameForceEnd": "Permainan anda berjaya berakhir!"
}
"defeated": "Tahniah! Anda telah mengalahkan saya ...",
"gameForceEnd": "Permainan anda telah berakhir dengan jayanya!"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc