bonktools 3.2.0 → 4.1.1

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.
@@ -1,109 +0,0 @@
1
- /**
2
- * Logger utility for BonkBot
3
- */
4
-
5
- // Log levels
6
- const LOG_LEVELS = {
7
- DEBUG: 0,
8
- INFO: 1,
9
- WARN: 2,
10
- ERROR: 3,
11
- NONE: 4,
12
- };
13
-
14
- /**
15
- * Logger class for consistent logging throughout the library
16
- */
17
- class Logger {
18
- /**
19
- * Create a new logger
20
- * @param {string} name - Name of the logger (typically the module name)
21
- * @param {number} level - Minimum log level to display (defaults to WARN)
22
- */
23
- constructor(name, level = LOG_LEVELS.WARN) {
24
- this.name = name;
25
- this.level = level;
26
- }
27
-
28
- /**
29
- * Set the log level
30
- * @param {number} level - New log level
31
- */
32
- setLevel(level) {
33
- this.level = level;
34
- }
35
-
36
- /**
37
- * Format a log message
38
- * @param {string} level - Log level name
39
- * @param {string} message - Log message
40
- * @returns {string} Formatted log message
41
- * @private
42
- */
43
- _format(level, message) {
44
- return `[${level}] [${this.name}] ${message}`;
45
- }
46
-
47
- /**
48
- * Log a debug message
49
- * @param {string} message - Message to log
50
- * @param {any} [data] - Optional data to include
51
- */
52
- debug(message, data) {
53
- if (this.level <= LOG_LEVELS.DEBUG) {
54
- const formattedMessage = this._format("DEBUG", message);
55
- console.debug(formattedMessage, data !== undefined ? data : "");
56
- }
57
- }
58
-
59
- /**
60
- * Log an info message
61
- * @param {string} message - Message to log
62
- * @param {any} [data] - Optional data to include
63
- */
64
- info(message, data) {
65
- if (this.level <= LOG_LEVELS.INFO) {
66
- const formattedMessage = this._format("INFO", message);
67
- console.info(formattedMessage, data !== undefined ? data : "");
68
- }
69
- }
70
-
71
- /**
72
- * Log a warning message
73
- * @param {string} message - Message to log
74
- * @param {any} [data] - Optional data to include
75
- */
76
- warn(message, data) {
77
- if (this.level <= LOG_LEVELS.WARN) {
78
- const formattedMessage = this._format("WARN", message);
79
- console.warn(formattedMessage, data !== undefined ? data : "");
80
- }
81
- }
82
-
83
- /**
84
- * Log an error message
85
- * @param {string} message - Message to log
86
- * @param {Error|any} [error] - Optional error or data to include
87
- */
88
- error(message, error) {
89
- if (this.level <= LOG_LEVELS.ERROR) {
90
- const formattedMessage = this._format("ERROR", message);
91
- console.error(formattedMessage, error !== undefined ? error : "");
92
- }
93
- }
94
- }
95
-
96
- /**
97
- * Create a new logger instance
98
- * @param {string} name - Name of the logger
99
- * @param {number} level - Minimum log level
100
- * @returns {Logger} New logger instance
101
- */
102
- function createLogger(name, level = LOG_LEVELS.INFO) {
103
- return new Logger(name, level);
104
- }
105
-
106
- module.exports = {
107
- LOG_LEVELS,
108
- createLogger,
109
- };
@@ -1,130 +0,0 @@
1
- /**
2
- * Validation utilities for BonkBot
3
- */
4
-
5
- /**
6
- * Validates account configuration
7
- * @param {Object} account - Account configuration object
8
- * @returns {Object} Validated account object with defaults applied
9
- * @throws {Error} If required fields are missing
10
- */
11
- function validateAccount(account = {}) {
12
- // Clone to avoid modifying the original
13
- const validatedAccount = { ...account };
14
-
15
- // Set default guest status if not provided
16
- if (validatedAccount.guest === undefined) {
17
- validatedAccount.guest = true;
18
- }
19
-
20
- // If not a guest, username and password are required
21
- if (!validatedAccount.guest) {
22
- if (!validatedAccount.username) {
23
- throw new Error("Username is required for non-guest accounts");
24
- }
25
- if (!validatedAccount.password) {
26
- throw new Error("Password is required for non-guest accounts");
27
- }
28
- } else {
29
- // For guests, generate a random username if not provided
30
- if (!validatedAccount.username) {
31
- validatedAccount.username = `BonkBot-${Math.random()
32
- .toString()
33
- .substr(2, 5)}`;
34
- }
35
- }
36
-
37
- return validatedAccount;
38
- }
39
-
40
- /**
41
- * Validates room configuration
42
- * @param {Object} options - Room configuration options
43
- * @returns {Object} Validated room options with defaults applied
44
- */
45
- function validateRoomOptions(options = {}) {
46
- return {
47
- roomname:
48
- options.roomname ||
49
- `BonkBot Room ${Math.random().toString().substr(2, 5)}`,
50
- maxplayers: options.maxplayers || 8,
51
- roompassword: options.roompassword || "",
52
- basecolor: options.basecolor !== undefined ? options.basecolor : 0,
53
- skin: options.skin,
54
- peerid: options.peerid || generatePeerID(),
55
- };
56
- }
57
-
58
- /**
59
- * Validates join room options
60
- * @param {Object} options - Join room options
61
- * @throws {Error} If required fields are missing
62
- * @returns {Object} Validated join options
63
- */
64
- function validateJoinOptions(options = {}) {
65
- if (!options.address) {
66
- throw new Error("Room address is required to join a room");
67
- }
68
-
69
- return {
70
- address: options.address,
71
- roompassword: options.roompassword || "",
72
- basecolor: options.basecolor !== undefined ? options.basecolor : 16448250,
73
- skin: options.skin,
74
- peerid: options.peerid || generatePeerID(),
75
- };
76
- }
77
-
78
- /**
79
- * Generates a random peer ID
80
- * @returns {string} Random peer ID
81
- */
82
- function generatePeerID() {
83
- return Math.random().toString(36).substr(2, 10) + "v00000";
84
- }
85
-
86
- /**
87
- * Validates that a value is a non-empty string
88
- * @param {any} value - Value to validate
89
- * @param {string} name - Name of the parameter for error messages
90
- * @throws {Error} If validation fails
91
- */
92
- function validateString(value, name) {
93
- if (typeof value !== "string" || value.trim() === "") {
94
- throw new Error(`${name} must be a non-empty string`);
95
- }
96
- }
97
-
98
- /**
99
- * Validates that a value is a number
100
- * @param {any} value - Value to validate
101
- * @param {string} name - Name of the parameter for error messages
102
- * @throws {Error} If validation fails
103
- */
104
- function validateNumber(value, name) {
105
- if (typeof value !== "number" || isNaN(value)) {
106
- throw new Error(`${name} must be a number`);
107
- }
108
- }
109
-
110
- /**
111
- * Validates that a value is a boolean
112
- * @param {any} value - Value to validate
113
- * @param {string} name - Name of the parameter for error messages
114
- * @throws {Error} If validation fails
115
- */
116
- function validateBoolean(value, name) {
117
- if (typeof value !== "boolean") {
118
- throw new Error(`${name} must be a boolean`);
119
- }
120
- }
121
-
122
- module.exports = {
123
- validateAccount,
124
- validateRoomOptions,
125
- validateJoinOptions,
126
- validateString,
127
- validateNumber,
128
- validateBoolean,
129
- generatePeerID,
130
- };