New shit for wordbyword

master
guilevi 2021-11-06 01:42:07 +01:00
parent 604fe3fd10
commit 6f9113a463
6 changed files with 44 additions and 6 deletions

BIN
.DS_Store vendored

Binary file not shown.

BIN
modules/.DS_Store vendored

Binary file not shown.

View File

@ -1,5 +1,6 @@
const printf = require('printf') const printf = require('printf')
const isStringInt = require('is-string-int'); const isStringInt = require('is-string-int');
const levenshtein = require('fast-levenshtein')
module.exports = function (bot, api) { module.exports = function (bot, api) {
bot.currentWBW = ""; bot.currentWBW = "";
@ -12,19 +13,27 @@ module.exports = function (bot, api) {
} else { } else {
if (isStringInt(args[1])) { if (isStringInt(args[1])) {
let story = await api.db.get('select * from WBWStories where story_id=?', parseInt(args[1])) let story = await api.db.get('select * from WBWStories where story_id=?', parseInt(args[1]))
if(!story) { if (!story) {
return api.respond(message, api.strings.WBW_INVALID_ID) return api.respond(message, api.strings.WBW_INVALID_ID)
} else { } else {
return api.respond(message, story.story_text) return api.respond(message, story.story_text)
} }
} else { } else {
let lastUser = await api.db.get('select value from BotState where key="last_wbw"'); let lastUser = await api.db.get('select value from BotState where key="last_wbw"');
if (message.author.id == lastUser.value) { if (message.author.id == lastUser.value && bot.currentWBW != "") {
return api.respond(message, printf(api.strings.WBW_LAST_USER)) let lastWord = (bot.currentWBW.indexOf(" ") == bot.currentWBW.lastIndexOf(" ")) ? bot.currentWBW : bot.currentWBW.slice(bot.currentWBW.slice(0,-1).lastIndexOf(' ') + 1);
console.log(args[1], lastWord, levenshtein.get(args[1], lastWord))
if (levenshtein.get(args[1], lastWord) <= 3) {
bot.currentWBW = bot.currentWBW.replace(new RegExp(lastWord + "([^" + lastWord + "]*)$"), args[1] + "$1 ");
api.respond(message, printf(api.strings.WBW_REPLACED, lastWord, args[1]))
} else {
return api.respond(message, printf(api.strings.WBW_TOO_DIFFERENT))
}
} else { } else {
bot.currentWBW += args[1] + ' '; bot.currentWBW += args[1] + ' ';
api.respond(message, printf(api.strings.WBW_NEW_WORD)) api.respond(message, printf(api.strings.WBW_NEW_WORD))
api.speak(message.member.voice.channel, bot.currentWBW) let toSay = bot.currentWBW.indexOf(".") == -1 ? bot.currentWBW : bot.currentWBW.slice(bot.currentWBW.lastIndexOf('.') + 2);
api.speak(message.member.voice.channel, toSay)
await api.db.run('update BotState set value=? where key="last_wbw"', message.author.id); await api.db.run('update BotState set value=? where key="last_wbw"', message.author.id);
} }
} }

27
package-lock.json generated
View File

@ -12,6 +12,7 @@
"@google-cloud/text-to-speech": "^3.1.3", "@google-cloud/text-to-speech": "^3.1.3",
"discord.js": "^12.5.3", "discord.js": "^12.5.3",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"fast-levenshtein": "^3.0.0",
"google-tts-api": "^2.0.2", "google-tts-api": "^2.0.2",
"is-string-int": "^1.0.1", "is-string-int": "^1.0.1",
"microsoft-cognitiveservices-speech-sdk": "^1.16.0", "microsoft-cognitiveservices-speech-sdk": "^1.16.0",
@ -730,11 +731,24 @@
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
"integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="
}, },
"node_modules/fast-levenshtein": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-3.0.0.tgz",
"integrity": "sha512-hKKNajm46uNmTlhHSyZkmToAc56uZJwYq7yrciZjqOxnlfQwERDQJmHPUp7m1m9wx8vgOe8IaCKZ5Kv2k1DdCQ==",
"dependencies": {
"fastest-levenshtein": "^1.0.7"
}
},
"node_modules/fast-text-encoding": { "node_modules/fast-text-encoding": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/fast-text-encoding/-/fast-text-encoding-1.0.3.tgz", "resolved": "https://registry.npmjs.org/fast-text-encoding/-/fast-text-encoding-1.0.3.tgz",
"integrity": "sha512-dtm4QZH9nZtcDt8qJiOH9fcQd1NAgi+K1O2DbE6GG1PPCK/BWfOH3idCTRQ4ImXRUOyopDEgDEnVEE7Y/2Wrig==" "integrity": "sha512-dtm4QZH9nZtcDt8qJiOH9fcQd1NAgi+K1O2DbE6GG1PPCK/BWfOH3idCTRQ4ImXRUOyopDEgDEnVEE7Y/2Wrig=="
}, },
"node_modules/fastest-levenshtein": {
"version": "1.0.12",
"resolved": "https://registry.npmjs.org/fastest-levenshtein/-/fastest-levenshtein-1.0.12.tgz",
"integrity": "sha512-On2N+BpYJ15xIC974QNVuYGMOlEVt4s0EOI3wwMqOmK1fdDY+FN/zltPV8vosq4ad4c/gJ1KHScUn/6AWIgiow=="
},
"node_modules/follow-redirects": { "node_modules/follow-redirects": {
"version": "1.13.3", "version": "1.13.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz",
@ -2760,11 +2774,24 @@
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
"integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="
}, },
"fast-levenshtein": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-3.0.0.tgz",
"integrity": "sha512-hKKNajm46uNmTlhHSyZkmToAc56uZJwYq7yrciZjqOxnlfQwERDQJmHPUp7m1m9wx8vgOe8IaCKZ5Kv2k1DdCQ==",
"requires": {
"fastest-levenshtein": "^1.0.7"
}
},
"fast-text-encoding": { "fast-text-encoding": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/fast-text-encoding/-/fast-text-encoding-1.0.3.tgz", "resolved": "https://registry.npmjs.org/fast-text-encoding/-/fast-text-encoding-1.0.3.tgz",
"integrity": "sha512-dtm4QZH9nZtcDt8qJiOH9fcQd1NAgi+K1O2DbE6GG1PPCK/BWfOH3idCTRQ4ImXRUOyopDEgDEnVEE7Y/2Wrig==" "integrity": "sha512-dtm4QZH9nZtcDt8qJiOH9fcQd1NAgi+K1O2DbE6GG1PPCK/BWfOH3idCTRQ4ImXRUOyopDEgDEnVEE7Y/2Wrig=="
}, },
"fastest-levenshtein": {
"version": "1.0.12",
"resolved": "https://registry.npmjs.org/fastest-levenshtein/-/fastest-levenshtein-1.0.12.tgz",
"integrity": "sha512-On2N+BpYJ15xIC974QNVuYGMOlEVt4s0EOI3wwMqOmK1fdDY+FN/zltPV8vosq4ad4c/gJ1KHScUn/6AWIgiow=="
},
"follow-redirects": { "follow-redirects": {
"version": "1.13.3", "version": "1.13.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz",

View File

@ -13,6 +13,7 @@
"@google-cloud/text-to-speech": "^3.1.3", "@google-cloud/text-to-speech": "^3.1.3",
"discord.js": "^12.5.3", "discord.js": "^12.5.3",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"fast-levenshtein": "^3.0.0",
"google-tts-api": "^2.0.2", "google-tts-api": "^2.0.2",
"is-string-int": "^1.0.1", "is-string-int": "^1.0.1",
"microsoft-cognitiveservices-speech-sdk": "^1.16.0", "microsoft-cognitiveservices-speech-sdk": "^1.16.0",

View File

@ -9,8 +9,9 @@
"TOO_MANY_ARGUMENTS": "too many arguments for command.", "TOO_MANY_ARGUMENTS": "too many arguments for command.",
"CURRENT_STORY": "Here's the current story: %s", "CURRENT_STORY": "Here's the current story: %s",
"NO_STORY": "No story in progress at the moment.", "NO_STORY": "No story in progress at the moment.",
"WBW_LAST_USER": "You were the last user to add a word to the story. Wait for someone else to add another one.", "WBW_REPLACED": "Replaced %s with %s",
"WBW_NEW_WORD": "Added to story. It now reads:", "WBW_TOO_DIFFERENT": "This word is too different from the last word.",
"WBW_NEW_WORD": "Added to story.",
"WBW_RESET": "The story has been reset.", "WBW_RESET": "The story has been reset.",
"WBW_INVALID_ID": "No story with that ID." "WBW_INVALID_ID": "No story with that ID."
} }