discord-logify 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 txuli
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # Discord Logify
2
+
3
+ A lightweight Discord logger that captures and forwards server events to webhooks for easy monitoring and auditing
4
+
5
+ ## 🚀 Features
6
+
7
+ - Multiple predefined log levels (Info, Alert, Error)
8
+ - Customizable log levels with colors and tags
9
+ - Automatic log sending to Discord
10
+ - Buffer system to optimize message delivery
11
+ - CLI for configuration management
12
+
13
+ ## 📦 Installation
14
+
15
+ ```bash
16
+ npm install discord-logify
17
+ ```
18
+
19
+ ## ⚙️ Configuration
20
+
21
+ ### Environment Variables
22
+
23
+ Create a `.env` file in the root of your project:
24
+
25
+ ```env
26
+ WEBHOOK_ID=YOUR_WEBHOOK_ID
27
+ WEBHOOK_TOKEN=YOUR_WEBHOOK_TOKEN
28
+ ```
29
+
30
+ ## 💻 Usage
31
+
32
+ ### Import and Create Instance
33
+
34
+ ```typescript
35
+ import { log } from 'discord-logify';
36
+
37
+ const logger = new log();
38
+ ```
39
+
40
+ ### Predefined Log Levels
41
+
42
+ ```typescript
43
+ // Information log
44
+ logger.Info('Application started successfully');
45
+
46
+ // Warning log
47
+ logger.Alert('Warning: Slow connection detected');
48
+
49
+ // Error log
50
+ logger.Error('Error processing request');
51
+ ```
52
+
53
+ ### Custom Log Levels
54
+
55
+ ```typescript
56
+ // Add a custom log level
57
+ logger.addLogLevel('debug', '\x1b[35m', '[DEBUG]');
58
+
59
+ // Use the custom level
60
+ logger.Log('Debug message', 'debug');
61
+ ```
62
+
63
+ ## 🎨 ANSI Color Codes
64
+
65
+ - `\x1b[31m` - Red (Error)
66
+ - `\x1b[33m` - Yellow (Warning)
67
+ - `\x1b[36m` - Cyan (Info)
68
+ - `\x1b[35m` - Magenta
69
+ - `\x1b[32m` - Green
70
+ - `\x1b[0m` - Reset
71
+
72
+ ## 🛠️ CLI
73
+
74
+ ### Add a Log Level
75
+
76
+ ```bash
77
+ logify add-log "prefix" -c "color_code" -t "[TAG]"
78
+ ```
79
+
80
+ Example:
81
+ ```bash
82
+ logify add-log "debug" -c "\x1b[35m" -t "[DEBUG]"
83
+ ```
84
+
85
+ ## 📁 Configuration File
86
+
87
+ Custom log levels are stored in `logger-config.json`:
88
+
89
+ ```json
90
+ {
91
+ "debug": {
92
+ "color": "\x1b[35m",
93
+ "prefix": "debug",
94
+ "text": "[DEBUG]"
95
+ }
96
+ }
97
+ ```
98
+
99
+ ## 🔄 How It Works
100
+
101
+ 1. Messages are added to a buffer
102
+ 2. After 1 second of inactivity, logs are sent to Discord
103
+ 3. Subsequent messages edit the previous message to reduce spam
104
+ 4. Logs are also displayed in the console with colors
105
+
106
+ ## 📝 Complete Example
107
+
108
+ ```typescript
109
+ import { log } from 'discord-logify';
110
+
111
+ const logger = new log();
112
+
113
+ // Add a custom level
114
+ logger.addLogLevel('success', '\x1b[32m', '[SUCCESS]');
115
+
116
+ // Use different log levels
117
+ logger.Info('Server started on port 3000');
118
+ logger.Log('User authenticated successfully', 'success');
119
+ logger.Alert('RAM usage at 80%');
120
+ logger.Error('Database connection failed');
121
+ ```
122
+
123
+ ## 🤝 Contributing
124
+
125
+ Contributions are welcome! Please:
126
+
127
+ 1. Fork the repository
128
+ 2. Create a feature branch (`git checkout -b feature/AmazingFeature`)
129
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
130
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
131
+ 5. Open a Pull Request
132
+
133
+ ## 📄 License
134
+
135
+ ISC
136
+
137
+ ## 👤 Author
138
+
139
+ **txuli**
140
+
141
+ - GitHub: [@txuli](https://github.com/txuli)
142
+
143
+ ## 🐛 Report Bugs
144
+
145
+ If you find a bug, please open an issue at:
146
+ https://github.com/txuli/discord-logify/issues
147
+
148
+ ---
149
+
150
+ ⭐ If you like this project, give it a star on GitHub!
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // bin/cli.ts
27
+ var import_commander = require("commander");
28
+
29
+ // src/index.ts
30
+ var import_node_fs2 = __toESM(require("fs"), 1);
31
+ var import_node_path2 = __toESM(require("path"), 1);
32
+ var import_config = require("dotenv/config");
33
+
34
+ // src/webhook.ts
35
+ var import_node_fs = __toESM(require("fs"), 1);
36
+ var import_node_path = __toESM(require("path"), 1);
37
+ var import_discord = require("discord.js");
38
+ console.log(process.env.WEBHOOK_ID);
39
+ var webhookClient = new import_discord.WebhookClient({ id: process.env.WEBHOOK_ID ?? "", token: process.env.WEBHOOK_TOKEN ?? "" });
40
+ var route = import_node_path.default.join(process.cwd(), ".env");
41
+ async function send(log2) {
42
+ const msg = await webhookClient.send({
43
+ content: "```ansi\n" + log2 + "\n```",
44
+ username: "log"
45
+ });
46
+ return msg.id;
47
+ }
48
+ async function edit(id, log2) {
49
+ webhookClient.editMessage(id, {
50
+ content: "```js\nconsole.log('hola')\n```"
51
+ });
52
+ }
53
+ function setup(id, token) {
54
+ if (import_node_fs.default.existsSync(route)) {
55
+ import_node_fs.default.appendFile(route, `
56
+ WEBHOOK_ID=${id}
57
+ WEBHOOK_TOKEN=${token}`, function(err) {
58
+ if (err) return false;
59
+ return true;
60
+ });
61
+ } else {
62
+ import_node_fs.default.writeFileSync(route, `
63
+ WEBHOOK_ID=${id}
64
+ WEBHOOK_TOKEN=${token}`);
65
+ }
66
+ return true;
67
+ }
68
+
69
+ // src/index.ts
70
+ var buffer = [];
71
+ var timer = null;
72
+ var lastMessageId = null;
73
+ var timeOut = 1e3;
74
+ var log = class {
75
+ configPath = import_node_path2.default.join(process.cwd(), "logger-config.json");
76
+ level = /* @__PURE__ */ new Map([]);
77
+ constructor() {
78
+ this.loadFromFile();
79
+ }
80
+ loadFromFile() {
81
+ if (import_node_fs2.default.existsSync(this.configPath)) {
82
+ const data = import_node_fs2.default.readFileSync(this.configPath, "utf-8");
83
+ const parsedData = JSON.parse(data);
84
+ this.level = new Map(Object.entries(parsedData));
85
+ }
86
+ }
87
+ date() {
88
+ const d = /* @__PURE__ */ new Date();
89
+ const day = String(d.getDate()).padStart(2, "0");
90
+ const month = String(d.getMonth() + 1).padStart(2, "0");
91
+ const year = d.getFullYear();
92
+ const hour = String(d.getHours()).padStart(2, "0");
93
+ const min = String(d.getMinutes()).padStart(2, "0");
94
+ const sec = String(d.getSeconds()).padStart(2, "0");
95
+ return `[${day}/${month}/${year} ${hour}:${min}:${sec}]`;
96
+ ;
97
+ }
98
+ Info(msg) {
99
+ process.stdout.write(`${this.date()} \x1B[36m[INFO]\x1B[0m ${msg}
100
+ `);
101
+ buffer.push(`${this.date()} \x1B[36m[INFO]\x1B[0m ${msg}
102
+ `);
103
+ this.sendMessage();
104
+ }
105
+ Alert(msg) {
106
+ process.stdout.write(`${this.date()} \x1B[33m[WARN]\x1B[0m ${msg}
107
+ `);
108
+ buffer.push(`${this.date()} \x1B[33m[WARN]\x1B[0m ${msg}
109
+ `);
110
+ this.sendMessage();
111
+ }
112
+ Error(msg) {
113
+ process.stdout.write(`${this.date()} \x1B[31m[ERROR]\x1B[0m ${msg}
114
+ `);
115
+ buffer.push(`${this.date()} \x1B[31m[ERROR]\x1B[0m ${msg}
116
+ `);
117
+ this.sendMessage();
118
+ }
119
+ Log(msg, prefix) {
120
+ const selected = this.level.get(prefix);
121
+ process.stdout.write(`${this.date()} ${selected?.color}${selected?.text}\x1B[0m ${msg}
122
+ `);
123
+ buffer.push(`${this.date()} ${selected?.color}${selected?.text}\x1B[0m ${msg}
124
+ `);
125
+ this.sendMessage();
126
+ }
127
+ addLogLevel(prefix, logColor, logTag) {
128
+ this.level.set(prefix, { color: logColor, prefix, text: logTag });
129
+ import_node_fs2.default.writeFileSync(this.configPath, JSON.stringify(Object.fromEntries(this.level)), "utf-8");
130
+ }
131
+ async sendMessage() {
132
+ if (timer) clearTimeout(timer);
133
+ timer = setTimeout(async () => {
134
+ const payload = buffer.join("");
135
+ buffer = [];
136
+ if (!payload) return;
137
+ if (lastMessageId) {
138
+ await edit(lastMessageId, payload);
139
+ } else {
140
+ lastMessageId = await send(payload);
141
+ }
142
+ }, timeOut);
143
+ }
144
+ };
145
+ var logger = new log();
146
+ logger.Alert("aaa");
147
+
148
+ // bin/cli.ts
149
+ var program = new import_commander.Command();
150
+ var logger2 = new log();
151
+ program.name("logger-cli").description("CLI for managing custom logs");
152
+ program.command("add-log").description("Add a personalized log").argument("<logName>", "logs name").requiredOption("-c, --color <string>").requiredOption("-t, --logTag <string>").action((logName, options) => {
153
+ logger2.addLogLevel(logName, options.color, options.logTag);
154
+ });
155
+ program.command("setup").description("setup the webhook").argument("<id>", "webhook id").requiredOption("-t, --token <string>").action((id, options) => {
156
+ const isCreated = setup(id, options.token);
157
+ if (isCreated) {
158
+ console.log("created Succesfully");
159
+ } else {
160
+ console.error("something went wrong");
161
+ }
162
+ });
163
+ program.parse();
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ log,
4
+ setup
5
+ } from "../chunk-TOOEN2B7.js";
6
+
7
+ // bin/cli.ts
8
+ import { Command } from "commander";
9
+ var program = new Command();
10
+ var logger = new log();
11
+ program.name("logger-cli").description("CLI for managing custom logs");
12
+ program.command("add-log").description("Add a personalized log").argument("<logName>", "logs name").requiredOption("-c, --color <string>").requiredOption("-t, --logTag <string>").action((logName, options) => {
13
+ logger.addLogLevel(logName, options.color, options.logTag);
14
+ });
15
+ program.command("setup").description("setup the webhook").argument("<id>", "webhook id").requiredOption("-t, --token <string>").action((id, options) => {
16
+ const isCreated = setup(id, options.token);
17
+ if (isCreated) {
18
+ console.log("created Succesfully");
19
+ } else {
20
+ console.error("something went wrong");
21
+ }
22
+ });
23
+ program.parse();
@@ -0,0 +1,123 @@
1
+ // src/index.ts
2
+ import fs2 from "fs";
3
+ import path2 from "path";
4
+ import "dotenv/config";
5
+
6
+ // src/webhook.ts
7
+ import fs from "fs";
8
+ import path from "path";
9
+ import { WebhookClient } from "discord.js";
10
+ console.log(process.env.WEBHOOK_ID);
11
+ var webhookClient = new WebhookClient({ id: process.env.WEBHOOK_ID ?? "", token: process.env.WEBHOOK_TOKEN ?? "" });
12
+ var route = path.join(process.cwd(), ".env");
13
+ async function send(log2) {
14
+ const msg = await webhookClient.send({
15
+ content: "```ansi\n" + log2 + "\n```",
16
+ username: "log"
17
+ });
18
+ return msg.id;
19
+ }
20
+ async function edit(id, log2) {
21
+ webhookClient.editMessage(id, {
22
+ content: "```js\nconsole.log('hola')\n```"
23
+ });
24
+ }
25
+ function setup(id, token) {
26
+ if (fs.existsSync(route)) {
27
+ fs.appendFile(route, `
28
+ WEBHOOK_ID=${id}
29
+ WEBHOOK_TOKEN=${token}`, function(err) {
30
+ if (err) return false;
31
+ return true;
32
+ });
33
+ } else {
34
+ fs.writeFileSync(route, `
35
+ WEBHOOK_ID=${id}
36
+ WEBHOOK_TOKEN=${token}`);
37
+ }
38
+ return true;
39
+ }
40
+
41
+ // src/index.ts
42
+ var buffer = [];
43
+ var timer = null;
44
+ var lastMessageId = null;
45
+ var timeOut = 1e3;
46
+ var log = class {
47
+ configPath = path2.join(process.cwd(), "logger-config.json");
48
+ level = /* @__PURE__ */ new Map([]);
49
+ constructor() {
50
+ this.loadFromFile();
51
+ }
52
+ loadFromFile() {
53
+ if (fs2.existsSync(this.configPath)) {
54
+ const data = fs2.readFileSync(this.configPath, "utf-8");
55
+ const parsedData = JSON.parse(data);
56
+ this.level = new Map(Object.entries(parsedData));
57
+ }
58
+ }
59
+ date() {
60
+ const d = /* @__PURE__ */ new Date();
61
+ const day = String(d.getDate()).padStart(2, "0");
62
+ const month = String(d.getMonth() + 1).padStart(2, "0");
63
+ const year = d.getFullYear();
64
+ const hour = String(d.getHours()).padStart(2, "0");
65
+ const min = String(d.getMinutes()).padStart(2, "0");
66
+ const sec = String(d.getSeconds()).padStart(2, "0");
67
+ return `[${day}/${month}/${year} ${hour}:${min}:${sec}]`;
68
+ ;
69
+ }
70
+ Info(msg) {
71
+ process.stdout.write(`${this.date()} \x1B[36m[INFO]\x1B[0m ${msg}
72
+ `);
73
+ buffer.push(`${this.date()} \x1B[36m[INFO]\x1B[0m ${msg}
74
+ `);
75
+ this.sendMessage();
76
+ }
77
+ Alert(msg) {
78
+ process.stdout.write(`${this.date()} \x1B[33m[WARN]\x1B[0m ${msg}
79
+ `);
80
+ buffer.push(`${this.date()} \x1B[33m[WARN]\x1B[0m ${msg}
81
+ `);
82
+ this.sendMessage();
83
+ }
84
+ Error(msg) {
85
+ process.stdout.write(`${this.date()} \x1B[31m[ERROR]\x1B[0m ${msg}
86
+ `);
87
+ buffer.push(`${this.date()} \x1B[31m[ERROR]\x1B[0m ${msg}
88
+ `);
89
+ this.sendMessage();
90
+ }
91
+ Log(msg, prefix) {
92
+ const selected = this.level.get(prefix);
93
+ process.stdout.write(`${this.date()} ${selected?.color}${selected?.text}\x1B[0m ${msg}
94
+ `);
95
+ buffer.push(`${this.date()} ${selected?.color}${selected?.text}\x1B[0m ${msg}
96
+ `);
97
+ this.sendMessage();
98
+ }
99
+ addLogLevel(prefix, logColor, logTag) {
100
+ this.level.set(prefix, { color: logColor, prefix, text: logTag });
101
+ fs2.writeFileSync(this.configPath, JSON.stringify(Object.fromEntries(this.level)), "utf-8");
102
+ }
103
+ async sendMessage() {
104
+ if (timer) clearTimeout(timer);
105
+ timer = setTimeout(async () => {
106
+ const payload = buffer.join("");
107
+ buffer = [];
108
+ if (!payload) return;
109
+ if (lastMessageId) {
110
+ await edit(lastMessageId, payload);
111
+ } else {
112
+ lastMessageId = await send(payload);
113
+ }
114
+ }, timeOut);
115
+ }
116
+ };
117
+ var logger = new log();
118
+ logger.Alert("aaa");
119
+
120
+ export {
121
+ setup,
122
+ log
123
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ log: () => log
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_node_fs = __toESM(require("fs"), 1);
37
+ var import_node_path = __toESM(require("path"), 1);
38
+ var log = class {
39
+ configPath = import_node_path.default.join(process.cwd(), "logger-config.json");
40
+ level = /* @__PURE__ */ new Map([]);
41
+ constructor() {
42
+ this.loadFromFile();
43
+ }
44
+ loadFromFile() {
45
+ if (import_node_fs.default.existsSync(this.configPath)) {
46
+ const data = import_node_fs.default.readFileSync(this.configPath, "utf-8");
47
+ const parsedData = JSON.parse(data);
48
+ this.level = new Map(Object.entries(parsedData));
49
+ }
50
+ }
51
+ date() {
52
+ const d = /* @__PURE__ */ new Date();
53
+ const day = String(d.getDate()).padStart(2, "0");
54
+ const month = String(d.getMonth() + 1).padStart(2, "0");
55
+ const year = d.getFullYear();
56
+ const hour = String(d.getHours()).padStart(2, "0");
57
+ const min = String(d.getMinutes()).padStart(2, "0");
58
+ const sec = String(d.getSeconds()).padStart(2, "0");
59
+ return `[${day}/${month}/${year} ${hour}:${min}:${sec}]`;
60
+ ;
61
+ }
62
+ Info(msg) {
63
+ process.stdout.write(`${this.date()} \x1B[36m[INFO]\x1B[0m ${msg}
64
+ `);
65
+ }
66
+ Alert(msg) {
67
+ process.stdout.write(`${this.date()} \x1B[33m[WARN]\x1B[0m ${msg}
68
+ `);
69
+ }
70
+ Error(msg) {
71
+ process.stdout.write(`${this.date()} \x1B[31m[ERROR]\x1B[0m ${msg}
72
+ `);
73
+ }
74
+ Log(msg, prefix) {
75
+ const log2 = this.level.get(prefix);
76
+ process.stdout.write(
77
+ `${this.date()} ${log2?.color ? `${log2.color}${log2.text}\x1B[0m` : ""} ${msg}
78
+ `
79
+ );
80
+ }
81
+ addLogLevel(prefix, logColor, logTag) {
82
+ this.level.set(prefix, { color: "\x1B[" + logColor + "m", prefix, text: "[" + logTag + "]" });
83
+ import_node_fs.default.writeFileSync(this.configPath, JSON.stringify(Object.fromEntries(this.level)), "utf-8");
84
+ }
85
+ };
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ log
89
+ });
@@ -0,0 +1,19 @@
1
+ type logLevel = {
2
+ color: string;
3
+ prefix: string;
4
+ text: string;
5
+ };
6
+ declare class log {
7
+ private configPath;
8
+ private level;
9
+ constructor();
10
+ private loadFromFile;
11
+ private date;
12
+ Info(msg: string): void;
13
+ Alert(msg: string): void;
14
+ Error(msg: string): void;
15
+ Log(msg: string, prefix: string): void;
16
+ addLogLevel(prefix: string, logColor: string, logTag: string): void;
17
+ }
18
+
19
+ export { log, type logLevel };
@@ -0,0 +1,12 @@
1
+ type logLevel = {
2
+ color: string;
3
+ prefix: string;
4
+ };
5
+ declare class log {
6
+ private level;
7
+ Info(msg: string): void;
8
+ Alert(msg: string): void;
9
+ Error(msg: string): void;
10
+ }
11
+
12
+ export { log, type logLevel };
@@ -0,0 +1,19 @@
1
+ type logLevel = {
2
+ color: string;
3
+ prefix: string;
4
+ text: string;
5
+ };
6
+ declare class log {
7
+ private configPath;
8
+ private level;
9
+ constructor();
10
+ private loadFromFile;
11
+ private date;
12
+ Info(msg: string): void;
13
+ Alert(msg: string): void;
14
+ Error(msg: string): void;
15
+ Log(msg: string, prefix: string): void;
16
+ addLogLevel(prefix: string, logColor: string, logTag: string): void;
17
+ }
18
+
19
+ export { log, type logLevel };
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ // src/index.ts
2
+ import fs from "fs";
3
+ import path from "path";
4
+ var log = class {
5
+ configPath = path.join(process.cwd(), "logger-config.json");
6
+ level = /* @__PURE__ */ new Map([]);
7
+ constructor() {
8
+ this.loadFromFile();
9
+ }
10
+ loadFromFile() {
11
+ if (fs.existsSync(this.configPath)) {
12
+ const data = fs.readFileSync(this.configPath, "utf-8");
13
+ const parsedData = JSON.parse(data);
14
+ this.level = new Map(Object.entries(parsedData));
15
+ }
16
+ }
17
+ date() {
18
+ const d = /* @__PURE__ */ new Date();
19
+ const day = String(d.getDate()).padStart(2, "0");
20
+ const month = String(d.getMonth() + 1).padStart(2, "0");
21
+ const year = d.getFullYear();
22
+ const hour = String(d.getHours()).padStart(2, "0");
23
+ const min = String(d.getMinutes()).padStart(2, "0");
24
+ const sec = String(d.getSeconds()).padStart(2, "0");
25
+ return `[${day}/${month}/${year} ${hour}:${min}:${sec}]`;
26
+ ;
27
+ }
28
+ Info(msg) {
29
+ process.stdout.write(`${this.date()} \x1B[36m[INFO]\x1B[0m ${msg}
30
+ `);
31
+ }
32
+ Alert(msg) {
33
+ process.stdout.write(`${this.date()} \x1B[33m[WARN]\x1B[0m ${msg}
34
+ `);
35
+ }
36
+ Error(msg) {
37
+ process.stdout.write(`${this.date()} \x1B[31m[ERROR]\x1B[0m ${msg}
38
+ `);
39
+ }
40
+ Log(msg, prefix) {
41
+ const log2 = this.level.get(prefix);
42
+ process.stdout.write(
43
+ `${this.date()} ${log2?.color ? `${log2.color}${log2.text}\x1B[0m` : ""} ${msg}
44
+ `
45
+ );
46
+ }
47
+ addLogLevel(prefix, logColor, logTag) {
48
+ this.level.set(prefix, { color: "\x1B[" + logColor + "m", prefix, text: "[" + logTag + "]" });
49
+ fs.writeFileSync(this.configPath, JSON.stringify(Object.fromEntries(this.level)), "utf-8");
50
+ }
51
+ };
52
+ export {
53
+ log
54
+ };
package/dist/index.mjs ADDED
@@ -0,0 +1,30 @@
1
+ // src/index.ts
2
+ var log = class {
3
+ level = /* @__PURE__ */ new Map([]);
4
+ Info(msg) {
5
+ process.stdout.write(`${date()} \x1B[33m[INFO]\x1B[0m ${msg}
6
+ `);
7
+ }
8
+ Alert(msg) {
9
+ process.stdout.write(`${date()} \x1B[33m[WARN]\x1B[0m ${msg}
10
+ `);
11
+ }
12
+ Error(msg) {
13
+ process.stdout.write(`${date()} \x1B[31m[ERROR]\x1B[0m ${msg}
14
+ `);
15
+ }
16
+ };
17
+ function date() {
18
+ const d = /* @__PURE__ */ new Date();
19
+ const day = String(d.getDate()).padStart(2, "0");
20
+ const month = String(d.getMonth() + 1).padStart(2, "0");
21
+ const year = d.getFullYear();
22
+ const hour = String(d.getHours()).padStart(2, "0");
23
+ const min = String(d.getMinutes()).padStart(2, "0");
24
+ const sec = String(d.getSeconds()).padStart(2, "0");
25
+ return `[${day}/${month}/${year} ${hour}:${min}:${sec}]`;
26
+ ;
27
+ }
28
+ export {
29
+ log
30
+ };
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ log: () => log
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+ var import_node_fs2 = __toESM(require("fs"), 1);
37
+ var import_node_path2 = __toESM(require("path"), 1);
38
+ var import_config = require("dotenv/config");
39
+
40
+ // src/webhook.ts
41
+ var import_node_fs = __toESM(require("fs"), 1);
42
+ var import_node_path = __toESM(require("path"), 1);
43
+ var import_discord = require("discord.js");
44
+ console.log(process.env.WEBHOOK_ID);
45
+ var webhookClient = new import_discord.WebhookClient({ id: process.env.WEBHOOK_ID ?? "", token: process.env.WEBHOOK_TOKEN ?? "" });
46
+ var route = import_node_path.default.join(process.cwd(), ".env");
47
+ async function send(log2) {
48
+ const msg = await webhookClient.send({
49
+ content: "```ansi\n" + log2 + "\n```",
50
+ username: "log"
51
+ });
52
+ return msg.id;
53
+ }
54
+ async function edit(id, log2) {
55
+ webhookClient.editMessage(id, {
56
+ content: "```js\nconsole.log('hola')\n```"
57
+ });
58
+ }
59
+
60
+ // src/index.ts
61
+ var buffer = [];
62
+ var timer = null;
63
+ var lastMessageId = null;
64
+ var timeOut = 1e3;
65
+ var log = class {
66
+ configPath = import_node_path2.default.join(process.cwd(), "logger-config.json");
67
+ level = /* @__PURE__ */ new Map([]);
68
+ constructor() {
69
+ this.loadFromFile();
70
+ }
71
+ loadFromFile() {
72
+ if (import_node_fs2.default.existsSync(this.configPath)) {
73
+ const data = import_node_fs2.default.readFileSync(this.configPath, "utf-8");
74
+ const parsedData = JSON.parse(data);
75
+ this.level = new Map(Object.entries(parsedData));
76
+ }
77
+ }
78
+ date() {
79
+ const d = /* @__PURE__ */ new Date();
80
+ const day = String(d.getDate()).padStart(2, "0");
81
+ const month = String(d.getMonth() + 1).padStart(2, "0");
82
+ const year = d.getFullYear();
83
+ const hour = String(d.getHours()).padStart(2, "0");
84
+ const min = String(d.getMinutes()).padStart(2, "0");
85
+ const sec = String(d.getSeconds()).padStart(2, "0");
86
+ return `[${day}/${month}/${year} ${hour}:${min}:${sec}]`;
87
+ ;
88
+ }
89
+ Info(msg) {
90
+ process.stdout.write(`${this.date()} \x1B[36m[INFO]\x1B[0m ${msg}
91
+ `);
92
+ buffer.push(`${this.date()} \x1B[36m[INFO]\x1B[0m ${msg}
93
+ `);
94
+ this.sendMessage();
95
+ }
96
+ Alert(msg) {
97
+ process.stdout.write(`${this.date()} \x1B[33m[WARN]\x1B[0m ${msg}
98
+ `);
99
+ buffer.push(`${this.date()} \x1B[33m[WARN]\x1B[0m ${msg}
100
+ `);
101
+ this.sendMessage();
102
+ }
103
+ Error(msg) {
104
+ process.stdout.write(`${this.date()} \x1B[31m[ERROR]\x1B[0m ${msg}
105
+ `);
106
+ buffer.push(`${this.date()} \x1B[31m[ERROR]\x1B[0m ${msg}
107
+ `);
108
+ this.sendMessage();
109
+ }
110
+ Log(msg, prefix) {
111
+ const selected = this.level.get(prefix);
112
+ process.stdout.write(`${this.date()} ${selected?.color}${selected?.text}\x1B[0m ${msg}
113
+ `);
114
+ buffer.push(`${this.date()} ${selected?.color}${selected?.text}\x1B[0m ${msg}
115
+ `);
116
+ this.sendMessage();
117
+ }
118
+ addLogLevel(prefix, logColor, logTag) {
119
+ this.level.set(prefix, { color: logColor, prefix, text: logTag });
120
+ import_node_fs2.default.writeFileSync(this.configPath, JSON.stringify(Object.fromEntries(this.level)), "utf-8");
121
+ }
122
+ async sendMessage() {
123
+ if (timer) clearTimeout(timer);
124
+ timer = setTimeout(async () => {
125
+ const payload = buffer.join("");
126
+ buffer = [];
127
+ if (!payload) return;
128
+ if (lastMessageId) {
129
+ await edit(lastMessageId, payload);
130
+ } else {
131
+ lastMessageId = await send(payload);
132
+ }
133
+ }, timeOut);
134
+ }
135
+ };
136
+ var logger = new log();
137
+ logger.Alert("aaa");
138
+ // Annotate the CommonJS export names for ESM import in node:
139
+ 0 && (module.exports = {
140
+ log
141
+ });
@@ -0,0 +1,20 @@
1
+ type logLevel = {
2
+ color: string;
3
+ prefix: string;
4
+ text: string;
5
+ };
6
+ declare class log {
7
+ private configPath;
8
+ private level;
9
+ constructor();
10
+ private loadFromFile;
11
+ private date;
12
+ Info(msg: string): void;
13
+ Alert(msg: string): void;
14
+ Error(msg: string): void;
15
+ Log(msg: string, prefix: string): void;
16
+ addLogLevel(prefix: string, logColor: string, logTag: string): void;
17
+ private sendMessage;
18
+ }
19
+
20
+ export { log, type logLevel };
@@ -0,0 +1,20 @@
1
+ type logLevel = {
2
+ color: string;
3
+ prefix: string;
4
+ text: string;
5
+ };
6
+ declare class log {
7
+ private configPath;
8
+ private level;
9
+ constructor();
10
+ private loadFromFile;
11
+ private date;
12
+ Info(msg: string): void;
13
+ Alert(msg: string): void;
14
+ Error(msg: string): void;
15
+ Log(msg: string, prefix: string): void;
16
+ addLogLevel(prefix: string, logColor: string, logTag: string): void;
17
+ private sendMessage;
18
+ }
19
+
20
+ export { log, type logLevel };
@@ -0,0 +1,6 @@
1
+ import {
2
+ log
3
+ } from "../chunk-TOOEN2B7.js";
4
+ export {
5
+ log
6
+ };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "discord-logify",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Advanced logging system that sends logs to Discord via webhooks",
6
+ "keywords": [
7
+ "discord",
8
+ "logger",
9
+ "logging",
10
+ "webhook",
11
+ "discord-logger",
12
+ "discord-webhook"
13
+ ],
14
+ "bin": {
15
+ "logify": "./dist/cli.js"
16
+ },
17
+ "homepage": "https://github.com/txuli/discord-logify#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/txuli/discord-logify/issues"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/txuli/discord-logify.git"
24
+ },
25
+ "license": "ISC",
26
+ "author": "txuli",
27
+ "main": "dist/index.js",
28
+ "module": "dist/index.mjs",
29
+ "types": "dist/index.d.ts",
30
+ "files": [
31
+ "dist",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "scripts": {
36
+ "test": "echo \"Error: no test specified\" && exit 1",
37
+ "build": "tsup src/index.ts bin/cli.ts --format esm,cjs --dts",
38
+ "prepublishOnly": "npm run build"
39
+ },
40
+ "devDependencies": {
41
+ "@eslint/js": "^9.39.2",
42
+ "eslint": "^9.39.2",
43
+ "prettier": "^3.8.1",
44
+ "tsup": "^8.5.1",
45
+ "typescript": "^5.9.3"
46
+ },
47
+ "dependencies": {
48
+ "commander": "^13.1.0",
49
+ "discord.js": "^14.25.1",
50
+ "dotenv": "^17.2.4"
51
+ }
52
+ }