mirror of
https://github.com/cassoule/flopobot_v2.git
synced 2026-03-18 21:40:27 +01:00
APO first tests
This commit is contained in:
13
index.js
13
index.js
@@ -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
|
||||
|
||||
25
utils.js
25
utils.js
@@ -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))
|
||||
}
|
||||
Reference in New Issue
Block a user