Add word by word
This commit is contained in:
BIN
modules/.DS_Store
vendored
BIN
modules/.DS_Store
vendored
Binary file not shown.
38
modules/wordbyword/index.js
Normal file
38
modules/wordbyword/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const printf = require('printf')
|
||||
const isStringInt = require('is-string-int');
|
||||
|
||||
module.exports = function (bot, api) {
|
||||
bot.currentWBW = "";
|
||||
api.registerCommand('wbw', async (args, message) => {
|
||||
if (args.length == 1) {
|
||||
return api.respond(message, bot.currentWBW ? printf(api.strings.CURRENT_STORY, bot.currentWBW) : printf(api.strings.NO_STORY));
|
||||
}
|
||||
if (args.length > 2) {
|
||||
return api.respond(message, printf(api.strings.TOO_MANY_ARGUMENTS));
|
||||
} else {
|
||||
if (isStringInt(args[1])) {
|
||||
let story = await api.db.get('select * from WBWStories where story_id=?', parseInt(args[1]))
|
||||
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"');
|
||||
console.log(lastUser.value, message.author.id);
|
||||
if (message.author.id == lastUser.value) {
|
||||
return api.respond(message, printf(api.strings.WBW_LAST_USER))
|
||||
} else {
|
||||
bot.currentWBW += args[1] + ' ';
|
||||
api.respond(message, printf(api.strings.WBW_NEW_WORD, bot.currentWBW))
|
||||
await api.db.run('update BotState set value=? where key="last_wbw"', message.author.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
api.registerCommand('newwbw', async (args, message) => {
|
||||
await api.db.run('insert into WBWStories (story_text) values(?)', bot.currentWBW);
|
||||
bot.currentWBW = '';
|
||||
api.respond(message, printf(api.strings.WBW_RESET))
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user