🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

grammylog

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grammylog - npm Package Compare versions

Comparing version
1.1.0
to
1.1.1
+8
-27
example/echo.js

@@ -12,2 +12,5 @@ /*

if (!process.env.BOT_TOKEN) {
throw new Error("BOT_TOKEN not found. Please set env variable BOT_TOKEN.");
}
const bot = new Bot(process.env.BOT_TOKEN);

@@ -18,10 +21,8 @@

async function log(ctx, next) {
let message = ctx.message?.text || ctx.channelPost?.text || undefined;
// Console
const from = ctx.from || ctx.chat;
const from = ctx.from;
const name =
`${from.first_name || ""} ${from.last_name || ""}`.trim() || ctx.chat.title;
from.last_name === undefined
? from.first_name
: `${from.first_name} ${from.last_name}`;
const message = (ctx.message && ctx.message.text) || ctx.inlineQuery.query;
console.log(

@@ -31,22 +32,2 @@ `From: ${name} (@${from.username}) ID: ${from.id}\nMessage: ${message}`

// Channel
if (
ctx.message &&
!ctx.message.text.includes("/") &&
process.env.LOG_CHANNEL
) {
await bot.api.sendMessage(
process.env.LOG_CHANNEL,
`<b>From: ${ctx.from.first_name} (@${from.username}) ID: <code>${from.id}</code></b>`,
{ parse_mode: "HTML" }
);
await ctx.api.forwardMessage(
process.env.LOG_CHANNEL,
ctx.chat.id,
ctx.message.message_id
);
}
await next();

@@ -53,0 +34,0 @@ }

+26
-4

@@ -15,7 +15,24 @@ /*!

// Console
async function log(ctx, next) {
let message = ctx.message?.text || ctx.channelPost?.text || undefined;
const from = ctx.from;
const name =
from.last_name === undefined
? from.first_name
: `${from.first_name} ${from.last_name}`;
const message = (ctx.message && ctx.message.text) || ctx.inlineQuery.query;
console.log(
`From: ${name} (@${from.username}) ID: ${from.id}\nMessage: ${message}`
);
// Console
await next();
}
bot.use(log);
// Channel (Might be unstable)
async function log(ctx, next) {
let message = ctx.message?.text || ctx.channelPost?.text || undefined;
const from = ctx.from || ctx.chat;

@@ -25,2 +42,4 @@ const name =

// Console
console.log(

@@ -34,3 +53,4 @@ `From: ${name} (@${from.username}) ID: ${from.id}\nMessage: ${message}`

ctx.message &&
!ctx.message.text.includes("/") &&
(ctx.message.text === undefined || ctx.message.text === null) &&
!ctx.message?.text?.includes("/") &&
process.env.LOG_CHANNEL

@@ -40,3 +60,3 @@ ) {

process.env.LOG_CHANNEL,
`<b>From: ${ctx.from.first_name} (@${from.username}) ID: <code>${from.id}</code></b>`,
`<b>From: ${name} (@${from.username}) ID: <code>${from.id}</code></b>`,
{ parse_mode: "HTML" }

@@ -54,1 +74,3 @@ );

}
bot.use(log);
{
"name": "grammylog",
"version": "1.1.0",
"version": "1.1.1",
"description": "Logging plugin for the grammY framework!",
"directories": {
"example": "example"
"example": "example",
"template": "template"
},

@@ -20,2 +21,3 @@ "author": {

},
"keywords": ["log", "grammY", "plugin", "middleware", "log channel"],
"license": "MIT",

@@ -22,0 +24,0 @@ "devDependencies": {

@@ -5,30 +5,15 @@ # grammYLog

<br>
### v1.1
Added log channel support.
Added log channel support (might be unstable). This should be more convenient than console messages.
This should be more convenient than console messages.
_Note:_ This feature is optional and will only work if you've supplied a log channel ID.
<br>
### Features
Currently the functionality is basic.
1. Log messages received by your bot to console.
2. Log message content as well as first name, last name, username and Telegram ID of the sender.
3. Only text messages are supported. In the case of media messages, limited to the text/captions.
4. For the future, db integrations are possible to implement persistent logs.
It is designed to log messages received.
In the case of media messages, limited to the text/captions.
Along with user details such as: first name + last name (if available), user ID, and username.
I'll be adding more functions such as admin management as well as support for a log channel soon.
For the future, db integrations are possible to implement persistent logs.
<br>
### Usage

@@ -38,4 +23,2 @@

<br>
<details>

@@ -51,6 +34,5 @@

1. Firstly, clone this repo.
2. Then run ```npm i```.
3. Rename .env.example to .env and provide bot token.
4. Run the example with node example/echo

@@ -80,4 +62,2 @@ </details>

<br>
### Contribute

@@ -87,6 +67,4 @@

<br>
### License
MIT ©️ Zubin

@@ -17,10 +17,8 @@ /*

async function log(ctx, next) {
let message = ctx.message?.text || ctx.channelPost?.text || undefined;
// Console
const from = ctx.from || ctx.chat;
const from = ctx.from;
const name =
`${from.first_name || ""} ${from.last_name || ""}`.trim() || ctx.chat.title;
from.last_name === undefined
? from.first_name
: `${from.first_name} ${from.last_name}`;
const message = (ctx.message && ctx.message.text) || ctx.inlineQuery.query;
console.log(

@@ -30,22 +28,2 @@ `From: ${name} (@${from.username}) ID: ${from.id}\nMessage: ${message}`

// Channel
if (
ctx.message &&
!ctx.message.text.includes("/") &&
process.env.LOG_CHANNEL
) {
await bot.api.sendMessage(
process.env.LOG_CHANNEL,
`<b>From: ${ctx.from.first_name} (@${from.username}) ID: <code>${from.id}</code></b>`,
{ parse_mode: "HTML" }
);
await ctx.api.forwardMessage(
process.env.LOG_CHANNEL,
ctx.chat.id,
ctx.message.message_id
);
}
await next();

@@ -52,0 +30,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet