Disallow insult / kys on bot

This commit is contained in:
Ceda EI 2019-02-12 03:09:42 +05:30
parent 71809ed109
commit b6edbb8b3b
2 changed files with 24 additions and 6 deletions

View File

@ -4,12 +4,24 @@ const is = require("./is");
module.exports = (bot, [ questions, kys, insults, commands_list ]) => { module.exports = (bot, [ questions, kys, insults, commands_list ]) => {
bot.command("question", (ctx) => ctx.reply(random(questions)())); bot.command("question", (ctx) => ctx.reply(random(questions)()));
bot.telegram.getMe()
.then(bot_user => {
const default_text = (command, text) => `Do you want to ${text} yourself?\n` console.log(bot_user);
+ `If no, reply to someone with /${command} to kill them or run /${command} username/name.\n` const default_text = (command, text) => `Do you want to ${text} `
+ `You can suggest more /${command} replies using /feedback`; + `yourself?\nIf no, reply to someone with /${command} to kill`
bot.command("insult", (ctx) => ctx.reply(insults_fun(random, insults, default_text("insult", "insult"))(ctx))); + ` them or run /${command} username/name.\nYou can suggest `
bot.command("kys", (ctx) => ctx.reply(insults_fun(random, kys, default_text("kys", "kill"))(ctx))); + `more /${command} replies using /feedback`;
bot.command("insult", (ctx) => ctx.reply(insults_fun(random,
insults, default_text("insult", "insult"), "Watch who you talk"
+ " to.", ["@" + bot_user.username, bot_user.firstName])(ctx)));
bot.command("kys", (ctx) => ctx.reply(insults_fun(random, kys,
default_text("kys", "kill"), "I can't be killed.",
["@" + bot_user.username, bot_user.firstName])(ctx)));
});
bot.command("commands", (ctx) => ctx.reply(commands_list.join("\n"))); bot.command("commands", (ctx) => ctx.reply(commands_list.join("\n")));
bot.command("is", (ctx) => ctx.reply(is(random)(ctx))); bot.command("is", (ctx) => ctx.reply(is(random)(ctx)));

View File

@ -1,9 +1,11 @@
module.exports = (random, kys, default_text) => (ctx) => { module.exports = (random, kys, default_text, bot_text, excluded_names) => (ctx) => {
if (ctx.message.reply_to_message) { if (ctx.message.reply_to_message) {
const { from } = ctx.message.reply_to_message; const { from } = ctx.message.reply_to_message;
const name = from.username ? "@" + from.username : from.firstName; const name = from.username ? "@" + from.username : from.firstName;
if (name == excluded_names[0])
return bot_text;
return random(kys)().replace(/##name##/g, name); return random(kys)().replace(/##name##/g, name);
} else { } else {
@ -12,6 +14,10 @@ module.exports = (random, kys, default_text) => (ctx) => {
if (text_array.length > 1) { if (text_array.length > 1) {
const name = text_array[1]; const name = text_array[1];
if (excluded_names.includes(name)
|| excluded_names.includes("@" + name))
return bot_text;
return random(kys)().replace(/##name##/g, name); return random(kys)().replace(/##name##/g, name);
} else } else