Add roleplay commands

This commit is contained in:
Ceda EI 2021-06-21 22:45:23 +05:30
parent 6da0e12171
commit 71e6f6927d
4 changed files with 1198 additions and 2 deletions

3
bot.js
View File

@ -3,6 +3,7 @@ const { BOT_API_KEY, FEEDBACK_ID } = process.env;
const fs = require("fs").promises; const fs = require("fs").promises;
const commands = require("./commands"); const commands = require("./commands");
const axios = require("axios"); const axios = require("axios");
const roleplay = require("./roleplay.json");
const bot = new Telegraf(BOT_API_KEY); const bot = new Telegraf(BOT_API_KEY);
bot.catch((err) => console.log(err)); bot.catch((err) => console.log(err));
@ -20,6 +21,6 @@ const data = [
Promise.all(data) Promise.all(data)
.then(data => .then(data =>
commands(bot, data, FEEDBACK_ID, axios)); commands(bot, [...data, roleplay], FEEDBACK_ID, axios));
bot.launch(); bot.launch();

View File

@ -8,8 +8,9 @@ const feedback = require("./feedback");
const media_wiki = require("./media_wiki"); const media_wiki = require("./media_wiki");
const info = require("./info"); const info = require("./info");
const expand = require("./expand"); const expand = require("./expand");
const roleplay = require("./roleplay");
module.exports = (bot, [ questions, kys, insults, commands_list, words ], feedback_id, axios) => { module.exports = (bot, [ questions, kys, insults, commands_list, words, roleplay_data ], feedback_id, axios) => {
bot.command("question", (ctx) => ctx.reply(random(questions)())); bot.command("question", (ctx) => ctx.reply(random(questions)()));
bot.command("word", (ctx) => ctx.reply(random(words)())); bot.command("word", (ctx) => ctx.reply(random(words)()));
@ -65,4 +66,8 @@ module.exports = (bot, [ questions, kys, insults, commands_list, words ], feedba
+ "chatting with me in private, you are most likely doing it wrong. " + "chatting with me in private, you are most likely doing it wrong. "
+ "Add me to a group for fun. To give feedback, use /feedback")); + "Add me to a group for fun. To give feedback, use /feedback"));
// Add all roleplay commands
Object.keys(roleplay_data).map(command =>
bot.command(command, ctx => roleplay(roleplay_data[command].forms, roleplay_data[command].gifs)(ctx)));
}; };

40
commands/roleplay.js Normal file
View File

@ -0,0 +1,40 @@
function joinUsers(users) {
if (users.length == 1)
return users[0];
return users.slice(0, users.length - 1).join(", ")
+ ` and ${users[users.length - 1]}`;
}
module.exports = (forms, gifs) => (ctx) => {
const gif = gifs[Math.floor(Math.random() * gifs.length)];
const message = ctx.message.text.replace(/^[^ ]+\s*/, "")
.match(/^((@\w+(\s+|$))*)(.*)/);
const users = message[1].trim().split(" ").filter(i => i.length);
const reason = message[4];
let reply = "";
const from = ctx.message.from;
const user = from.username ? "@" + from.username : from.first_name;
if (users.length > 0 && reason.length > 0)
reply = forms.both
.replace("{}", user)
.replace("{}", joinUsers(users))
.replace("{}", reason);
else if (users.length > 0)
reply = forms.others
.replace("{}", user)
.replace("{}", joinUsers(users));
else if (reason.length > 0)
reply = forms.reason
.replace("{}", user)
.replace("{}", reason);
else
reply = forms.none
.replace("{}", user);
ctx.replyWithAnimation(gif, {caption: reply});
};

1150
roleplay.json Normal file

File diff suppressed because it is too large Load Diff