1
1
mirror of https://gitlab.com/ceda_ei/Quadnite-Bot synced 2025-12-03 17:30:04 +01:00

Compare commits

..

3 Commits

Author SHA1 Message Date
610fadefcc Add /info 2019-02-12 23:58:22 +05:30
4481e94624 Add /wiki, /arch_wiki 2019-02-12 19:02:38 +05:30
87fa5eb60c Add /feedback 2019-02-12 13:10:01 +05:30
7 changed files with 122 additions and 3 deletions

5
bot.js
View File

@@ -1,7 +1,8 @@
const Telegraf = require("telegraf"); const Telegraf = require("telegraf");
const { BOT_API_KEY } = process.env; 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 bot = new Telegraf(BOT_API_KEY); const bot = new Telegraf(BOT_API_KEY);
@@ -18,6 +19,6 @@ const data = [
Promise.all(data) Promise.all(data)
.then(data => .then(data =>
commands(bot, data)); commands(bot, data, FEEDBACK_ID, axios));
bot.launch(); bot.launch();

15
commands/feedback.js Normal file
View File

@@ -0,0 +1,15 @@
module.exports = (feedback_id) => (ctx) => {
const message = ctx.message.text.replace(/^[^ ]+/, "");
if (message) {
ctx.forwardMessage(feedback_id);
return "Thanks for the feedback";
} else {
return "To send feedback type in /feedback followed by the feedback";
}
};

View File

@@ -4,7 +4,12 @@ const words_fun = require("./words");
const is = require("./is"); const is = require("./is");
const weebify = require("./weebify"); const weebify = require("./weebify");
const absurdify = require("./absurdify"); const absurdify = require("./absurdify");
module.exports = (bot, [ questions, kys, insults, commands_list, words ]) => { const feedback = require("./feedback");
const media_wiki = require("./media_wiki");
const info = require("./info");
module.exports = (bot, [ questions, kys, insults, commands_list, words ],
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)()));
@@ -47,5 +52,13 @@ module.exports = (bot, [ questions, kys, insults, commands_list, words ]) => {
"Markdown"})); "Markdown"}));
bot.command("weebify", (ctx) => ctx.reply(weebify()(ctx))); bot.command("weebify", (ctx) => ctx.reply(weebify()(ctx)));
bot.command("absurdify", (ctx) => ctx.reply(absurdify()(ctx))); bot.command("absurdify", (ctx) => ctx.reply(absurdify()(ctx)));
bot.command("feedback", (ctx) => ctx.reply(feedback(feedback_id)(ctx)));
bot.command("wiki", (ctx) => media_wiki(axios,
"https://en.wikipedia.org/w/api.php")(ctx).then(x => ctx.reply(x,
{parse_mode: "HTML"})));
bot.command("arch_wiki", (ctx) => media_wiki(axios,
"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"}));
}; };

36
commands/info.js Normal file
View File

@@ -0,0 +1,36 @@
module.exports = () => (ctx) => {
let text = "";
const msg = ctx.message;
text += `Message ID: \`${msg.message_id}\`\n`;
text += `Chat ID: \`${msg.chat.id}\`\n`;
text += `User ID: \`${msg.from.id}\`\n`;
if (msg.reply_to_message) {
const reply = msg.reply_to_message;
text += "\n*Reply to*\n";
text += `Message ID: \`${reply.message_id}\`\n`;
text += `Chat ID: \`${reply.chat.id}\`\n`;
text += `User ID: \`${reply.from.id}\`\n`;
if (reply.forward_from || reply.forward_from_chat) {
const forward = reply.forward_from ? reply.forward_from
:reply.forward_from_chat;
text += "\n*Forward from*\n";
if (reply.forward_from)
text += "User ID: ";
else
text += "Channel ID: ";
text += `\`${forward.id}\`\n`;
text += "Message Date: `";
const date = new Date(reply.forward_date);
text += date.toUTCString();
text += "`";
}
}
return text;
};

22
commands/media_wiki.js Normal file
View File

@@ -0,0 +1,22 @@
module.exports = (axios, url) => (ctx) => {
const message = ctx.message.text.replace(/^[^ ]+/, "");
if (message) {
return axios.get(`${url}?action=opensearch&format=json&search=`
+ `${encodeURIComponent(message)}`)
.then((res) => {
const names = res.data[1];
const urls = res.data[3];
if (names.length == 0)
return "No results found";
return "Results\n\n" + names.map((val, index) =>
`<a href="${urls[index]}">${val}</a>`).join("\n");
});
} else
return Promise.resolve("Missing search query.");
};

View File

@@ -22,6 +22,7 @@
}, },
"homepage": "https://gitlab.com/ceda_ei/Quadnite-Bot#readme", "homepage": "https://gitlab.com/ceda_ei/Quadnite-Bot#readme",
"dependencies": { "dependencies": {
"axios": "^0.18.0",
"telegraf": "^3.27.1" "telegraf": "^3.27.1"
} }
} }

View File

@@ -1,16 +1,46 @@
dependencies: dependencies:
axios: 0.18.0
telegraf: 3.27.1 telegraf: 3.27.1
packages: packages:
/@types/node/10.12.24: /@types/node/10.12.24:
dev: false dev: false
resolution: resolution:
integrity: sha512-GWWbvt+z9G5otRBW8rssOFgRY87J9N/qbhqfjMZ+gUuL6zoL+Hm6gP/8qQBG4jjimqdaNLCehcVapZ/Fs2WjCQ== integrity: sha512-GWWbvt+z9G5otRBW8rssOFgRY87J9N/qbhqfjMZ+gUuL6zoL+Hm6gP/8qQBG4jjimqdaNLCehcVapZ/Fs2WjCQ==
/axios/0.18.0:
dependencies:
follow-redirects: 1.6.1
is-buffer: 1.1.6
dev: false
resolution:
integrity: sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=
/debug/3.1.0:
dependencies:
ms: 2.0.0
dev: false
resolution:
integrity: sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
/debug/4.1.1: /debug/4.1.1:
dependencies: dependencies:
ms: 2.1.1 ms: 2.1.1
dev: false dev: false
resolution: resolution:
integrity: sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw== integrity: sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
/follow-redirects/1.6.1:
dependencies:
debug: 3.1.0
dev: false
engines:
node: '>=4.0'
resolution:
integrity: sha512-t2JCjbzxQpWvbhts3l6SH1DKzSrx8a+SsaVf4h6bG4kOXUuPYS/kg2Lr4gQSb7eemaHqJkOThF1BGyjlUkO1GQ==
/is-buffer/1.1.6:
dev: false
resolution:
integrity: sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
/ms/2.0.0:
dev: false
resolution:
integrity: sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=
/ms/2.1.1: /ms/2.1.1:
dev: false dev: false
resolution: resolution:
@@ -47,4 +77,5 @@ registry: 'https://registry.npmjs.org/'
shrinkwrapMinorVersion: 9 shrinkwrapMinorVersion: 9
shrinkwrapVersion: 3 shrinkwrapVersion: 3
specifiers: specifiers:
axios: ^0.18.0
telegraf: ^3.27.1 telegraf: ^3.27.1