Skip to content

Commit eb6357b

Browse files
committed
Bug fixes, writing an entire API client for GD, removal of gd.js
Fixes the info command, brevity cleanup, as well as username fixes and etcetera Signed-off-by: SuperDev <supernova@supers0ft.us>
1 parent 8f954e1 commit eb6357b

6 files changed

Lines changed: 388 additions & 112 deletions

File tree

commands/queue/info.js

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const {searchQueue} = require("../../utils/queue");
22
const modes = require("../../modes.json");
3-
const GD = require('gd.js');
3+
const logConsole = require("../../logger");
4+
const {getGJLevels21, getGJUsers20} = require("../../utils/gd");
5+
const axios = require('axios');
46

57
module.exports = {
68
name: '!info',
@@ -9,9 +11,9 @@ module.exports = {
911
tags: [],
1012
params: true,
1113
async execute(client, channel, tags, username, message, parameters) {
12-
console.log("message params: " + message)
13-
const result = searchQueue(parameters); // Assuming `parameters` is an array and levelId is the first element.
14-
const gd = new GD();
14+
const levelId = extractLevelId(message);
15+
const result = searchQueue(levelId); // Assuming `parameters` is an array and levelId is the first element.
16+
console.log("level id: " + levelId);
1517

1618
if (typeof result === 'string') {
1719
// If `searchQueue` returned a string (levelId not found), pass it directly to the `client.say()` function.
@@ -20,10 +22,37 @@ module.exports = {
2022
if (modes.gd === false) {
2123
client.say(channel, `Level: ${result.levelId}, User: ${result.username}, found in queue.`);
2224
} else if (modes.gd === true) {
23-
const level = await gd.levels.search({query: parameters});
24-
const creator = await gd.users.get(level.creator.accountID);
25-
client.say(channel, `${level.name} | ${creator.username} | ${result.levelId}, Requested by: ${result.username}`);
25+
const levelData = await getGJLevels21(`${levelId}`, 1, 0); // Replace 'str', 0, 1 with actual values
26+
const levelName = levelData[0].levelName; // access the levelName property of the returned object
27+
const levelAuthorPlayerID = levelData[0].playerID
28+
29+
const userData = await getGJUsers20(levelAuthorPlayerID);
30+
const userName = userData[0].userName;
31+
32+
// console.log(`creator: ${userName}`);
33+
// console.log(`level name: ${levelName}`);
34+
35+
// console.log(`Level data: ${JSON.stringify(levelData)}`);
36+
37+
client.say(channel, `${levelName} | ${userName} | ${result.levelId}, Requested by: ${result.username}`);
2638
}
2739
}
2840
},
29-
};
41+
};
42+
43+
// Extract the level ID from the command message
44+
/**
45+
* Extracts the level ID from a given message.
46+
*
47+
* @param {string} message - The message containing the level ID.
48+
* @return {number|null} - The extracted level ID, or null if it doesn't meet the criteria.
49+
*/
50+
function extractLevelId(message) {
51+
const levelId = message.match(/\d+/); // Match the first group of digits
52+
53+
if (levelId && levelId[0].length >= 3 && levelId[0].length <= 9) {
54+
return parseInt(levelId[0], 10);
55+
}
56+
57+
return null;
58+
}

commands/queue/request.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
if (hasReachedRequestLimit(username, isSubscriber)) {
1414
client.say(channel, `Sorry, you have reached your request limit of ${isSubscriber ? limits.subscriberRequestLimit : limits.viewerRequestLimit} level(s).`);
1515
} else {
16-
addLevelToQueue(levelId, isSubscriber, username, client);
16+
addLevelToQueue(levelId, isSubscriber, tags.username, client);
1717
}
1818
} else {
1919
client.say(channel, 'Invalid level ID. Please provide a level ID between 3 and 9 characters.');
@@ -29,11 +29,10 @@ module.exports = {
2929
* @return {number|null} - The extracted level ID, or null if it doesn't meet the criteria.
3030
*/
3131
function extractLevelId(message) {
32-
const levelId = message;
33-
const isNumeric = /^\d+$/.test(levelId); // Check if levelId is numeric
32+
const levelId = message.match(/\d+/); // Match the first group of digits
3433

35-
if (levelId && levelId.length >= 3 && levelId.length <= 9 && isNumeric) {
36-
return parseInt(levelId, 10);
34+
if (levelId && levelId[0].length >= 3 && levelId[0].length <= 9) {
35+
return parseInt(levelId[0], 10);
3736
}
3837

3938
return null;

handlers/messageHandler.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const logConsole = require("../logger");
2-
31
function handleMessage(client) {
42
return (channel, tags, message, self) => {
53
// Ignore echoed messages.
@@ -10,16 +8,12 @@ function handleMessage(client) {
108
const commandName = splitMessage[0].trim();
119
const parameters = message.substr(commandName.length).trim();
1210

13-
// console.log('User tags:', tags);
14-
1511
// If this command exists:
1612
if (client.commands.has(commandName)) {
1713
const command = client.commands.get(commandName);
1814

1915
if(command.tags && command.tags.length > 0) {
20-
2116
const hasPermission = command.tags.some(tag => tags.badges && tag in tags.badges);
22-
2317
if (!hasPermission) {
2418
return;
2519
}
@@ -28,7 +22,7 @@ function handleMessage(client) {
2822
if (command.params && parameters.length > 0) {
2923
command.execute(client, channel, tags, message, parameters);
3024
} else if (!command.params) {
31-
command.execute(client, channel, tags, message);
25+
command.execute(client, channel, tags, message, parameters);
3226
}
3327
} else {
3428
logConsole(`Command not found: ${commandName}`);

package-lock.json

Lines changed: 2 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
"name": "gd-levelreqbot",
33
"author": "Supernova3339",
44
"main": "main.js",
5-
"version": "1.0.6",
5+
"version": "1.0.7",
66
"dependencies": {
77
"axios": "^1.7.2",
88
"figlet": "^1.7.0",
99
"fs": "^0.0.1-security",
10-
"gd.js": "^0.2.13",
1110
"node-fetch": "^3.3.2",
1211
"tmi.js": "^1.8.5"
1312
},

0 commit comments

Comments
 (0)