New shit for wordbyword
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const printf = require('printf')
|
||||
const isStringInt = require('is-string-int');
|
||||
const levenshtein = require('fast-levenshtein')
|
||||
|
||||
module.exports = function (bot, api) {
|
||||
bot.currentWBW = "";
|
||||
@@ -12,19 +13,27 @@ module.exports = function (bot, api) {
|
||||
} else {
|
||||
if (isStringInt(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)
|
||||
} else {
|
||||
return api.respond(message, story.story_text)
|
||||
}
|
||||
} else {
|
||||
let lastUser = await api.db.get('select value from BotState where key="last_wbw"');
|
||||
if (message.author.id == lastUser.value) {
|
||||
return api.respond(message, printf(api.strings.WBW_LAST_USER))
|
||||
if (message.author.id == lastUser.value && bot.currentWBW != "") {
|
||||
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 {
|
||||
bot.currentWBW += args[1] + ' ';
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user