diff --git a/src/action/SaveMessage.ts b/src/action/SaveMessage.ts index 30f2a4f..1be073e 100644 --- a/src/action/SaveMessage.ts +++ b/src/action/SaveMessage.ts @@ -75,10 +75,9 @@ export default class SaveMessage extends Action { */ private async saveNewMessage(user: Record, chat: Record): Promise { - - console.log(chat); const message = new Messages(); const insert = message.insert(); + insert .set("type", this.context.type) .set("user_id", user.id) diff --git a/src/action/SaveUserAndChat.ts b/src/action/SaveUserAndChat.ts index b086d34..4968710 100644 --- a/src/action/SaveUserAndChat.ts +++ b/src/action/SaveUserAndChat.ts @@ -39,12 +39,11 @@ export default class SaveUserAndChat extends Action { const contextUser = this.context.newChatMember || this.context.leftChatMember || this.context.user; const user = await UserHelper.getByTelegramId(contextUser.getId()); - const userId = user === null ? await UserHelper.createUser(contextUser) : user.id; + const userId = user?.id ?? await UserHelper.createUser(contextUser); const chat = await ChatHelper.getByTelegramId(this.context.chat.getId()); - const chatId = chat === null ? await ChatHelper.createChat(this.context.chat) : chat!.id; + const chatId = chat?.id ?? await ChatHelper.createChat(this.context.chat); - console.log("Chat:", chat, "ChatId:", chatId); UserHelper.updateUser(contextUser); ChatHelper.updateChat(this.context.chat); diff --git a/src/command/Macro.ts b/src/command/Macro.ts index 37c74ef..e46ad25 100644 --- a/src/command/Macro.ts +++ b/src/command/Macro.ts @@ -104,7 +104,6 @@ export default class Macro extends Command { const content = result[0].content; const replyToMessage = this.context.message.getReplyToMessage(); - console.log(replyToMessage); if (replyToMessage) { replyToMessage.reply(content, { parseMode : "HTML" }); diff --git a/src/helper/Chat.ts b/src/helper/Chat.ts index 58f6daf..a5af9b7 100644 --- a/src/helper/Chat.ts +++ b/src/helper/Chat.ts @@ -11,6 +11,7 @@ import Chats from "../model/Chats.js"; import ChatConfigs from "../model/ChatConfigs.js"; +import Log from "./Log.js"; export default class ChatHelper { @@ -102,7 +103,6 @@ export default class ChatHelper { */ public static async createChat(chat: Record): Promise { - console.log("Abc"); const title = chat.getTitle() || chat.getUsername() || (`${chat.getFirstName()} ${chat.getLastName()}`).trim(); const newChat = new Chats(); newChat @@ -112,15 +112,23 @@ export default class ChatHelper { .set("type", chat.getType()) .set("joined", 1); - const result = await newChat.execute(); - const chatId = result.insertId; + try { - const newChatConfig = new ChatConfigs(); - newChatConfig - .insert() - .set("chat_id", chatId); + const result = await newChat.execute(); + const chatId = result.insertId; + + const newChatConfig = new ChatConfigs(); + newChatConfig + .insert() + .set("chat_id", chatId); - newChatConfig.execute(); + await newChatConfig.execute(); + return chatId; + + } catch (err) { + Log.error(err); + return null; + } } /**