This commit is contained in:
Ceda EI 2020-11-20 21:50:55 +05:30
commit 472c7489f9
4 changed files with 55 additions and 5 deletions

48
commands/expand.js Normal file
View File

@ -0,0 +1,48 @@
function expand(words, text) {
const letters = text.trim().toLowerCase().split("");
// Build a dictionary with lowercase letters as keys
const dict = {};
words.forEach(word => {
if (word == "")
return;
const initial = word.split("")[0].toLowerCase();
if (initial in dict)
dict[initial].push(word);
else
dict[initial] = [word];
});
return letters.map((letter) => {
if (!(letter.toLowerCase() in dict))
return letter;
const wordsWithLetter = dict[letter.toLowerCase()];
const word = wordsWithLetter[Math.floor(Math.random() * wordsWithLetter.length)];
return word;
}).reduce((acc, cur) => acc + " " + cur).replace(/\s{2,}/g, " ");
}
module.exports = (words = []) => (ctx) => {
words = words.filter(i => ! i.match(/'s$/));
const message = ctx.message.text.replace(/^[^ ]+/, "");
if (message) {
return expand(words, message);
} else {
if (ctx.message.reply_to_message)
return expand(words, ctx.message.reply_to_message.text);
else
return "Need text to expand. Send /expand text or reply to a "
+ "message with /expand";
}
};

View File

@ -7,9 +7,9 @@ const absurdify = require("./absurdify");
const feedback = require("./feedback");
const media_wiki = require("./media_wiki");
const info = require("./info");
const expand = require("./expand");
module.exports = (bot, [ questions, kys, insults, commands_list, words ],
feedback_id, axios) => {
module.exports = (bot, [ questions, kys, insults, commands_list, words ], feedback_id, axios) => {
bot.command("question", (ctx) => ctx.reply(random(questions)()));
bot.command("word", (ctx) => ctx.reply(random(words)()));
@ -60,6 +60,7 @@ module.exports = (bot, [ questions, kys, insults, commands_list, words ],
"https://wiki.archlinux.org/api.php")(ctx).then(x => ctx.reply(x,
{parse_mode: "HTML"})));
bot.command("info", (ctx) => ctx.reply(info()(ctx), {parse_mode: "Markdown"}));
bot.command("expand", (ctx) => ctx.reply(expand(words)(ctx)));
bot.command("start", (ctx) => ctx.reply("Hi! I'm Octanite. Sibling of @quadnite_bot. My creator @ceda_ei created me as 'another option' to users who want the bot in their groups to have privacy mode enabled. \n\nPrivacy mode? Wut is that?\n- Well basically disabling privacy mode enables a bot to read all the messages. @quadnite_bot has that disabled. Enabling privacy mode causes the bot to not recieve messages at some times. To circumvet that, you need to append @octanite_bot to your commands or simply use @quadnite_bot. \n\n[P.S. - My creator doesn't store any messages or personal data. It's safe to use any of the two bots.]\nTo give feedback, use /feedback"));
};

View File

@ -3,17 +3,17 @@ module.exports = (random, kys, default_text, bot_text, excluded_names) => (ctx)
if (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.first_name;
if (name == excluded_names[0])
return bot_text;
return random(kys)().replace(/##name##/g, name);
} else {
const text_array = ctx.message.text.split(" ");
const text_array = ctx.message.text.split(" ").trim();
if (text_array.length > 1) {
const name = text_array[1];
const name = text_array.slice(1).reduce((i, j) => i + " " + j);
if (excluded_names.includes(name)
|| excluded_names.includes("@" + name))
return bot_text;

View File

@ -21,3 +21,4 @@ should - Should <your question>
help - Need help? Go here
feedback - Send feedback, suggestion for kys, insult text
rate - Rate me on TGDR
expand - Expands a given abbreviation