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