Better structure

This commit is contained in:
Sudo Space 2024-08-30 21:37:08 +03:30
parent aa6f2d5ca7
commit 78dd58f109
3 changed files with 7 additions and 5 deletions

View file

@ -1,8 +1,7 @@
import { Composer } from "grammy"; import { Composer } from "grammy";
import Archive from "models/archive";
const commands = new Composer(); const commands = new Composer();
const env = process.env;
commands.command("start", (ctx) => { commands.command("start", (ctx) => {
ctx.reply("Welcome to my magical mailbox 🪄"); ctx.reply("Welcome to my magical mailbox 🪄");

View file

@ -5,6 +5,7 @@ import Archive from "models/archive";
const messages = new Composer(); const messages = new Composer();
const env = process.env; const env = process.env;
// 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();
@ -31,6 +32,7 @@ messages.on("message", async (ctx, next) => {
} }
}); });
// Handle messaging
messages.on("message", async (ctx) => { messages.on("message", async (ctx) => {
try { try {
const msg = await ctx.api.copyMessage(env.admin!, ctx.from.id, ctx.msgId); const msg = await ctx.api.copyMessage(env.admin!, ctx.from.id, ctx.msgId);
@ -44,6 +46,7 @@ messages.on("message", async (ctx) => {
} }
}); });
// Handle reaction on messages
messages.on("message_reaction", async (ctx) => { messages.on("message_reaction", async (ctx) => {
try { try {
const record: any = await Archive.findOne({ const record: any = await Archive.findOne({

View file

@ -4,16 +4,16 @@ import database from "database";
const Archive = database.define("Archive", { const Archive = database.define("Archive", {
msgId: { msgId: {
type: DataTypes.STRING, type: DataTypes.INTEGER,
primaryKey: true, primaryKey: true,
allowNull: false, allowNull: false,
}, },
senderId: { senderId: {
type: DataTypes.STRING, type: DataTypes.INTEGER,
allowNull: false, allowNull: false,
}, },
senderMsgId: { senderMsgId: {
type: DataTypes.STRING, type: DataTypes.INTEGER,
allowNull: false, allowNull: false,
}, },
}); });