APO first tests

This commit is contained in:
Milo
2025-04-24 14:22:07 +02:00
parent c7656e169c
commit 85055e89ff
2 changed files with 37 additions and 1 deletions

View File

@@ -14,7 +14,9 @@ import {
//getOnlineUsersWithRole,
formatTime,
gork,
getRandomHydrateText
getRandomHydrateText,
getAPOUsers,
postAPOBuy
} from './utils.js';
import { getShuffledOptions, getResult } from './game.js';
import { Client, GatewayIntentBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
@@ -506,6 +508,14 @@ client.on('messageCreate', async (message) => {
message.channel.send(`${content}`)
.catch(console.error);
}
else if (message.content.toLowerCase().startsWith('?u')) {
console.log(await getAPOUsers())
}
else if (message.content.toLowerCase().startsWith('?b')) {
const amount = message.content.replace('?b ', '')
console.log(amount)
console.log(await postAPOBuy('650338922874011648', amount))
}
});
// Once bot is ready
@@ -544,6 +554,7 @@ client.once('ready', async () => {
const randomMinute = Math.floor(Math.random() * 60);
const randomHour = Math.floor(Math.random() * (18 - 8 + 1)) + 8;
todaysHydrateCron = `${randomMinute} ${randomHour} * * *`
console.log(todaysHydrateCron)
const guild = await client.guilds.fetch(process.env.GUILD_ID);
const roleId = process.env.VOTING_ROLE_ID; // Set this in your .env file

View File

@@ -162,4 +162,29 @@ export async function gork(messageHistory) {
} else {
return "Pas d'IA"
}
}
export async function getAPOUsers() {
const fetchUrl = process.env.APO_BASE_URL + '/users?serverId=' + (process.env.T12_GUILD_ID ?? process.env.GUILD_ID)
console.log(fetchUrl)
return await fetch(fetchUrl)
.then(response => {
if (!response.ok) {
throw new Error('Error fetching APO users')
}
return response.json()
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
}
export async function postAPOBuy(userId, amount) {
const fetchUrl = process.env.APO_BASE_URL + '/buy?serverId=' + (process.env.T12_GUILD_ID ?? process.env.GUILD_ID) + '&userId=' + userId + '&amount=' + amount
console.log(fetchUrl)
return await fetch(fetchUrl, {
method: 'POST',
})
.then(response => response.status + ': ' + response.statusText + ' - ' + response.ok)
.catch(error => console.log('Post error:', error))
}