Refactor
This commit is contained in:
parent
b93a261972
commit
e636e4a136
3 changed files with 17 additions and 30 deletions
|
@ -18,19 +18,15 @@ commands.command("start", (ctx) => {
|
|||
});
|
||||
|
||||
commands.command("block", async (ctx) => {
|
||||
if (ctx.chatId != +env.admin!) {
|
||||
return ctx.reply("You are not owner");
|
||||
}
|
||||
if (!ctx.msg.reply_to_message) {
|
||||
if (ctx.chatId != +env.admin!) return ctx.reply("You are not owner");
|
||||
if (!ctx.msg.reply_to_message)
|
||||
return ctx.reply("Please reply on a message to block it sender");
|
||||
}
|
||||
try {
|
||||
const record: any = await Archive.findOne({
|
||||
where: { msgId: ctx.msg.reply_to_message.message_id },
|
||||
});
|
||||
if (record.senderId == +env.admin!) {
|
||||
if (record.senderId == +env.admin!)
|
||||
return ctx.reply("Owner can't block itself");
|
||||
}
|
||||
const isSenderBlocked = await BlockList.findOne({
|
||||
where: { senderId: record.senderId },
|
||||
});
|
||||
|
@ -41,24 +37,20 @@ commands.command("block", async (ctx) => {
|
|||
return ctx.reply("The sender blocked before");
|
||||
}
|
||||
} catch (err) {
|
||||
return ctx.reply("Oops, something wrong 😢");
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
|
||||
commands.command("unblock", async (ctx) => {
|
||||
if (ctx.chatId != +env.admin!) {
|
||||
return ctx.reply("You are not owner");
|
||||
}
|
||||
if (!ctx.msg.reply_to_message) {
|
||||
if (ctx.chatId != +env.admin!) return ctx.reply("You are not owner");
|
||||
if (!ctx.msg.reply_to_message)
|
||||
return ctx.reply("Please reply on a message to make unblock it sender");
|
||||
}
|
||||
try {
|
||||
const record: any = await Archive.findOne({
|
||||
where: { msgId: ctx.msg.reply_to_message.message_id },
|
||||
});
|
||||
if (record.senderId == +env.admin!) {
|
||||
if (record.senderId == +env.admin!)
|
||||
return ctx.reply("Owner is free forever");
|
||||
}
|
||||
const isSenderBlocked = await BlockList.findOne({
|
||||
where: { senderId: record.senderId },
|
||||
});
|
||||
|
@ -69,7 +61,7 @@ commands.command("unblock", async (ctx) => {
|
|||
return ctx.reply("The sender is already free");
|
||||
}
|
||||
} catch (err) {
|
||||
return ctx.reply("Oops, something wrong 😢");
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ import { Composer } from "grammy";
|
|||
import Archive from "models/archive";
|
||||
|
||||
const edits = new Composer();
|
||||
const env = process.env;
|
||||
|
||||
edits.on("edit:text", async (ctx) => {
|
||||
try {
|
||||
|
@ -18,7 +17,7 @@ edits.on("edit:text", async (ctx) => {
|
|||
ctx.editedMessage?.text!
|
||||
);
|
||||
} catch (err) {
|
||||
return ctx.reply("Oops, something wrong 😢");
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -33,7 +32,7 @@ edits.on("edit:caption", async (ctx, next) => {
|
|||
caption: ctx.editedMessage?.caption,
|
||||
});
|
||||
} catch (err) {
|
||||
return ctx.reply("Oops, something wrong 😢");
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -11,21 +11,17 @@ messages.on("message", async (ctx, next) => {
|
|||
const isSenderBlocked = await BlockList.findOne({
|
||||
where: { senderId: ctx.from.id },
|
||||
});
|
||||
if (isSenderBlocked) {
|
||||
if (isSenderBlocked)
|
||||
return ctx.reply("Sorry, You aren't allowed to send message 💔");
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
else next();
|
||||
} catch (err) {
|
||||
return ctx.reply("Oops, something wrong 😢");
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
|
||||
// Handle reply messages
|
||||
messages.on("message", async (ctx, next) => {
|
||||
if (!ctx.msg.reply_to_message) {
|
||||
return next();
|
||||
}
|
||||
if (!ctx.msg.reply_to_message) return next();
|
||||
try {
|
||||
const record: any = await Archive.findOne({
|
||||
where: { msgId: ctx.msg.reply_to_message.message_id },
|
||||
|
@ -46,7 +42,7 @@ messages.on("message", async (ctx, next) => {
|
|||
receiverId: receiverId,
|
||||
});
|
||||
} catch (err) {
|
||||
return ctx.reply("Oops, something wrong 😢");
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -62,7 +58,7 @@ messages.on("message", async (ctx) => {
|
|||
receiverId: receiverId,
|
||||
});
|
||||
} catch (err) {
|
||||
return ctx.reply("Oops, something wrong 😢");
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -78,7 +74,7 @@ messages.on("message_reaction", async (ctx) => {
|
|||
ctx.messageReaction.new_reaction
|
||||
);
|
||||
} catch (err) {
|
||||
return ctx.reply("Oops, something wrong 😢");
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue