Correcting the logic of editing messages feature and its logical mistake

This commit is contained in:
Sudo Space 2024-08-31 16:58:42 +03:30
parent f3f1a0c96e
commit e6e708d427
3 changed files with 16 additions and 4 deletions

View file

@ -5,13 +5,15 @@ import Archive from "models/archive";
const edits = new Composer();
const env = process.env;
edits.on("edit:text", async (ctx, next) => {
edits.on("edit:text", async (ctx) => {
try {
const record: any = await Archive.findOne({
where: { senderMsgId: ctx.msgId },
});
const receiverId =
ctx.chat.id == record.receiverId ? record.senderId : record.receiverId;
await ctx.api.editMessageText(
env.admin!,
receiverId,
record.msgId,
ctx.editedMessage?.text!
);
@ -25,7 +27,9 @@ edits.on("edit:caption", async (ctx, next) => {
const record: any = await Archive.findOne({
where: { senderMsgId: ctx.msgId },
});
await ctx.api.editMessageCaption(env.admin!, record.msgId, {
const receiverId =
ctx.chat.id == record.receiverId ? record.senderId : record.receiverId;
await ctx.api.editMessageCaption(receiverId, record.msgId, {
caption: ctx.editedMessage?.caption,
});
} catch (err) {

View file

@ -9,7 +9,7 @@ const env = process.env;
messages.on("message", async (ctx, next) => {
try {
const isSenderBlocked = await BlockList.findOne({
where: { senderId: ctx.chatId },
where: { senderId: ctx.from.id },
});
if (isSenderBlocked) {
return ctx.reply("Sorry, You aren't allowed to send message 💔");
@ -38,10 +38,12 @@ messages.on("message", async (ctx, next) => {
reply_parameters: { message_id: record.senderMsgId },
}
);
const receiverId = ctx.from.id != +env.admin! ? env.admin : record.senderId;
await Archive.create({
msgId: msg.message_id,
senderId: ctx.from.id,
senderMsgId: ctx.msgId,
receiverId: receiverId,
});
} catch (err) {
return ctx.reply("Oops, something wrong 😢");
@ -52,10 +54,12 @@ messages.on("message", async (ctx, next) => {
messages.on("message", async (ctx) => {
try {
const msg = await ctx.api.copyMessage(env.admin!, ctx.from.id, ctx.msgId);
const receiverId = ctx.from.id != +env.admin! ? env.admin : ctx.from.id;
await Archive.create({
msgId: msg.message_id,
senderId: ctx.from.id,
senderMsgId: ctx.msgId,
receiverId: receiverId,
});
} catch (err) {
return ctx.reply("Oops, something wrong 😢");

View file

@ -16,6 +16,10 @@ const Archive = database.define("Archive", {
type: DataTypes.INTEGER,
allowNull: false,
},
receiverId: {
type: DataTypes.INTEGER,
allowNull: false,
},
});
export default Archive;