2021-06-21 19:15:23 +02:00
|
|
|
function joinUsers(users) {
|
|
|
|
|
|
|
|
if (users.length == 1)
|
|
|
|
return users[0];
|
|
|
|
return users.slice(0, users.length - 1).join(", ")
|
|
|
|
+ ` and ${users[users.length - 1]}`;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-27 18:40:34 +02:00
|
|
|
module.exports = (forms, getGif) => (ctx) => {
|
2021-06-21 19:15:23 +02:00
|
|
|
|
|
|
|
const message = ctx.message.text.replace(/^[^ ]+\s*/, "")
|
|
|
|
.match(/^((@\w+(\s+|$))*)(.*)/);
|
|
|
|
const users = message[1].trim().split(" ").filter(i => i.length);
|
2021-07-09 09:52:01 +02:00
|
|
|
const rtm = ctx.message.reply_to_message;
|
2024-01-24 20:08:35 +01:00
|
|
|
if (rtm && !rtm.is_topic_message)
|
2021-07-09 09:52:01 +02:00
|
|
|
users.push(rtm.from.username ? "@" + rtm.from.username
|
|
|
|
: rtm.from.first_name);
|
2021-06-21 19:15:23 +02:00
|
|
|
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);
|
|
|
|
|
2024-09-30 06:35:45 +02:00
|
|
|
return getGif()
|
2021-09-27 18:40:34 +02:00
|
|
|
.then(gif => ctx.replyWithAnimation(gif.data.url, {caption: reply}));
|
2021-06-21 19:15:23 +02:00
|
|
|
|
|
|
|
};
|