new commands update for the bot

This commit is contained in:
VinceC
2024-11-07 17:28:00 -06:00
parent 7b431e0406
commit 2b577c5be1
9 changed files with 865 additions and 324 deletions

58
src/tests/test.js Normal file
View File

@@ -0,0 +1,58 @@
// src/test.js
const PlayerService = require('./services/PlayerService');
async function testPlayerService() {
console.log('Testing PlayerService...');
const playerService = new PlayerService();
try {
// Test user lookup
console.log('\nTesting user lookup...');
const userData = await playerService.findUserByUsername('uthcowboys');
console.log('User data received:', !!userData);
console.log('Success:', userData?.success);
if (userData && userData.success) {
const playerData = JSON.parse(userData.player_data);
console.log('\nBasic user info:');
console.log('Username:', playerData.username);
console.log('Level:', playerData.profile?.level);
console.log('Country:', playerData.profile?.country);
// Test matches
console.log('\nRecent matches:');
const matches = Object.values(playerData.matches || {})
.sort((a, b) => new Date(b.start_time) - new Date(a.start_time))
.slice(0, 3);
matches.forEach(match => {
console.log(`- ${match.game_name} (${match.game_mode}): ${match.score} on ${new Date(match.start_time).toLocaleDateString()}`);
});
// Test stats
console.log('\nGame stats:');
const games = playerData.stats?.games || {};
Object.entries(games).forEach(([gameName, gameData]) => {
console.log(`\n${gameName}:`);
Object.entries(gameData).forEach(([mode, stats]) => {
if (mode !== 'Overall') {
console.log(` ${mode}:`);
console.log(` Matches: ${stats.matches}`);
console.log(` Win Rate: ${stats.win_rate}`);
}
});
});
}
} catch (error) {
console.error('Test failed:', error);
}
}
// Run tests
console.log('Starting tests...\n');
testPlayerService().then(() => {
console.log('\nTests completed.');
}).catch(error => {
console.error('Tests failed:', error);
});

69
src/tests/testcommands.js Normal file
View File

@@ -0,0 +1,69 @@
// src/testCommands.js
const CommandHandler = require('./commands/CommandHandler');
const PlayerService = require('./services/PlayerService');
// Mock Discord interaction
class MockInteraction {
constructor(commandName, options = {}) {
this.commandName = commandName;
this.deferred = false;
this.replied = false;
this.options = {
getString: (name) => options[name]
};
}
async deferReply() {
this.deferred = true;
console.log('Interaction deferred');
}
async reply(content) {
this.replied = true;
console.log('Reply sent:', content);
}
async editReply(content) {
console.log('Edit reply:', content);
if (content.embeds) {
console.log('\nEmbed fields:');
content.embeds.forEach(embed => {
console.log('Title:', embed.data.title);
console.log('Description:', embed.data.description);
if (embed.data.fields) {
embed.data.fields.forEach(field => {
console.log(`${field.name}: ${field.value}`);
});
}
});
}
}
}
async function testCommands() {
console.log('Testing commands...\n');
const playerService = new PlayerService();
const commandHandler = new CommandHandler(playerService);
// Test finduser command
console.log('Testing /finduser command...');
const findUserInteraction = new MockInteraction('finduser', {
username: 'uthcowboys'
});
await commandHandler.handleFindUser(findUserInteraction);
// Test matchhistory command
console.log('\nTesting /matchhistory command...');
const matchHistoryInteraction = new MockInteraction('matchhistory', {
username: 'uthcowboys'
});
await commandHandler.handleMatchHistory(matchHistoryInteraction);
}
// Run tests
testCommands().then(() => {
console.log('\nCommand tests completed.');
}).catch(error => {
console.error('Command tests failed:', error);
});