+4
-5
@@ -13,9 +13,8 @@ // Minimal Echo Bot | ||
| async function log(ctx, next) { | ||
| const from = ctx.from; | ||
| let message = ctx.message?.text || ctx.channelPost?.text || undefined; | ||
| const from = ctx.from || ctx.chat; | ||
| const name = | ||
| from.last_name === undefined | ||
| ? from.first_name | ||
| : `${from.first_name} ${from.last_name}`; | ||
| `${from.first_name || ""} ${from.last_name || ""}`.trim() || ctx.chat.title; | ||
| console.log( | ||
| `From: ${name} (@${from.username}) ID: ${from.id}\nMessage: ${ctx.message.text}` | ||
| `From: ${name} (@${from.username}) ID: ${from.id}\nMessage: ${message}` | ||
| ); | ||
@@ -22,0 +21,0 @@ await next(); |
+5
-10
| /*! | ||
| * grammyLog | ||
| * grammYLog | ||
| * Copyright(c) 2023 | ||
@@ -10,4 +10,2 @@ * | ||
| // Log | ||
| /* | ||
@@ -19,13 +17,10 @@ PLUGIN CODE | ||
| async function log(ctx, next) { | ||
| const from = ctx.from; | ||
| let message = ctx.message?.text || ctx.channelPost?.text || undefined; | ||
| const from = ctx.from || ctx.chat; | ||
| const name = | ||
| from.last_name === undefined | ||
| ? from.first_name | ||
| : `${from.first_name} ${from.last_name}`; | ||
| `${from.first_name || ""} ${from.last_name || ""}`.trim() || ctx.chat.title; | ||
| console.log( | ||
| `From: ${name} (@${from.username}) ID: ${from.id}\nMessage: ${ctx.message.text}` | ||
| `From: ${name} (@${from.username}) ID: ${from.id}\nMessage: ${message}` | ||
| ); | ||
| await next(); | ||
| } | ||
| bot.use(log); |
+1
-1
| { | ||
| "name": "grammylog", | ||
| "version": "1.0.3", | ||
| "version": "1.0.4", | ||
| "description": "Logging plugin for the grammY framework!", | ||
@@ -5,0 +5,0 @@ "directories": { |
+10
-5
@@ -0,1 +1,7 @@ | ||
| /* | ||
| GrammYLog Template | ||
| */ | ||
| require("dotenv").config(); | ||
@@ -11,9 +17,8 @@ const { Bot } = require("grammy"); | ||
| async function log(ctx, next) { | ||
| const from = ctx.from; | ||
| let message = ctx.message?.text || ctx.channelPost?.text || undefined; | ||
| const from = ctx.from || ctx.chat; | ||
| const name = | ||
| from.last_name === undefined | ||
| ? from.first_name | ||
| : `${from.first_name} ${from.last_name}`; | ||
| `${from.first_name || ""} ${from.last_name || ""}`.trim() || ctx.chat.title; | ||
| console.log( | ||
| `From: ${name} (@${from.username}) ID: ${from.id}\nMessage: ${ctx.message.text}` | ||
| `From: ${name} (@${from.username}) ID: ${from.id}\nMessage: ${message}` | ||
| ); | ||
@@ -20,0 +25,0 @@ await next(); |
4949
4.37%77
-2.53%