Merge branch 'master' of https://gitlab.com/ceda_ei/Quadnite-Bot
This commit is contained in:
@@ -9,8 +9,9 @@ const media_wiki = require("./media_wiki");
|
||||
const info = require("./info");
|
||||
const expand = require("./expand");
|
||||
const roleplay = require("./roleplay");
|
||||
const suggest = require("./suggest");
|
||||
|
||||
module.exports = (bot, [ questions, kys, insults, commands_list, words, roleplay_data ], feedback_id, axios) => {
|
||||
module.exports = (bot, [ questions, kys, insults, commands_list, words, roleplay_data ], feedback_id, apiToken, ugokiRoot, axios) => {
|
||||
|
||||
bot.command("question", (ctx) => ctx.reply(random(questions)()));
|
||||
bot.command("word", (ctx) => ctx.reply(random(words)()));
|
||||
@@ -63,9 +64,40 @@ module.exports = (bot, [ questions, kys, insults, commands_list, words, roleplay
|
||||
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"));
|
||||
bot.command("donate", (ctx) => ctx.reply("Thanks for considering to donate."
|
||||
+ " To support the development and hosting of Quadnite Bot, you can "
|
||||
+ "donate here: https://liberapay.com/ceda_ei/"));
|
||||
|
||||
function getGetGif(command) {
|
||||
|
||||
const alias = roleplay_data[command].alias;
|
||||
if (alias)
|
||||
return getGetGif(alias);
|
||||
|
||||
return () => axios.get(
|
||||
`category/${command}/gif`,
|
||||
{
|
||||
baseURL: ugokiRoot
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function getForms(name) {
|
||||
|
||||
if (roleplay_data[name].forms)
|
||||
return roleplay_data[name].forms;
|
||||
return getForms(roleplay_data[name].alias);
|
||||
|
||||
}
|
||||
|
||||
// Add all roleplay commands
|
||||
Object.keys(roleplay_data).map(command =>
|
||||
bot.command(command, ctx => roleplay(roleplay_data[command].forms, roleplay_data[command].gifs)(ctx)));
|
||||
bot.command(command,
|
||||
(ctx) => roleplay(getForms(command), getGetGif(command))(ctx)
|
||||
)
|
||||
);
|
||||
|
||||
bot.command("suggest", (ctx) => suggest(axios, apiToken, ugokiRoot)(ctx));
|
||||
|
||||
};
|
||||
|
||||
@@ -8,9 +8,8 @@ function joinUsers(users) {
|
||||
}
|
||||
|
||||
|
||||
module.exports = (forms, gifs) => (ctx) => {
|
||||
module.exports = (forms, getGif) => (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);
|
||||
@@ -39,6 +38,7 @@ module.exports = (forms, gifs) => (ctx) => {
|
||||
reply = forms.none
|
||||
.replace("{}", user);
|
||||
|
||||
ctx.replyWithAnimation(gif, {caption: reply});
|
||||
getGif()
|
||||
.then(gif => ctx.replyWithAnimation(gif.data.url, {caption: reply}));
|
||||
|
||||
};
|
||||
|
||||
84
commands/suggest.js
Normal file
84
commands/suggest.js
Normal file
@@ -0,0 +1,84 @@
|
||||
const ffmpeg = require("fluent-ffmpeg");
|
||||
const fs = require("fs");
|
||||
const FormData = require("form-data");
|
||||
|
||||
function ugokiUpload(axios, ugokiRoot, ctx, category, path) {
|
||||
|
||||
const form = new FormData();
|
||||
form.append("file", fs.createReadStream(path));
|
||||
return axios.post(`new_suggestion/${category}`, form,
|
||||
{ headers: form.getHeaders(), baseURL: ugokiRoot })
|
||||
.then(() => {
|
||||
|
||||
ctx.reply("Suggestion added.");
|
||||
fs.unlink(path, () => {});
|
||||
|
||||
})
|
||||
.catch((err) => {
|
||||
|
||||
console.error(err);
|
||||
if (err.response && err.response.status == 404)
|
||||
ctx.reply("Category doesn't exist");
|
||||
else if (err.response && err.response.status == 409)
|
||||
ctx.reply("Already suggested / added.");
|
||||
else
|
||||
ctx.reply("No clue what the hell happened but adding suggestion failed.");
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
module.exports = (axios, apiToken, ugokiRoot) => (ctx) => {
|
||||
|
||||
const category = ctx.message.text.split(" ")[1];
|
||||
const reply = ctx.message.reply_to_message;
|
||||
|
||||
if (category && reply && reply.animation) {
|
||||
|
||||
return ctx.telegram.getFile(reply.animation.file_id)
|
||||
.then(resp => {
|
||||
|
||||
return axios({
|
||||
method: "get",
|
||||
url: `https://api.telegram.org/file/bot${apiToken}/${resp.file_path}`,
|
||||
responseType: "stream"
|
||||
})
|
||||
.then(async (response) => {
|
||||
|
||||
let stream = response.data;
|
||||
let path = `data/${resp.file_unique_id}`;
|
||||
const writer = fs.createWriteStream(path);
|
||||
if (!resp.file_path.match(/\.gif$/)) {
|
||||
|
||||
await stream.pipe(writer);
|
||||
stream = ffmpeg(path)
|
||||
.on("error", function () {
|
||||
|
||||
fs.unlink(path, () => {});
|
||||
ctx.reply("Something went wrong processing the gif");
|
||||
|
||||
|
||||
})
|
||||
.on("end", function () {
|
||||
|
||||
fs.unlink(path, () => {});
|
||||
ugokiUpload(axios, ugokiRoot, ctx, category, path + ".gif");
|
||||
|
||||
})
|
||||
.output(path + ".gif")
|
||||
.outputFormat("gif")
|
||||
.run();
|
||||
|
||||
} else
|
||||
ugokiUpload(axios, ugokiRoot, category, ctx, path);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
} else
|
||||
ctx.reply("Reply to a gif with /suggest [category] "
|
||||
+ "to suggest it to be used for [category]");
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user