1st
This commit is contained in:
commit
ed602b2643
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
node_modules
|
||||||
51
commands/dofus/almanax.js
Normal file
51
commands/dofus/almanax.js
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
const dofusdude = require('dofusdude-js');
|
||||||
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('almanax')
|
||||||
|
.setDescription("Offrande du jour de l'Almanax !"),
|
||||||
|
async execute(interaction) {
|
||||||
|
await interaction.deferReply();
|
||||||
|
const api = new dofusdude.AlmanaxApi()
|
||||||
|
const language = 'fr'; // {String} code
|
||||||
|
const date = new Date(); // {Date} yyyy-mm-dd
|
||||||
|
date.setHours(date.getHours()+1);
|
||||||
|
console.log(date.toISOString());
|
||||||
|
const dateFormatted = date.toISOString().slice(0,10);
|
||||||
|
api.getAlmanaxDate(language, dateFormatted, (error, data, response) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
console.log('Dofusdude API called successfully.');
|
||||||
|
// interaction.editReply('Item du jour : ' + data.tribute.item.name + ' x' + data.tribute.quantity);
|
||||||
|
|
||||||
|
interaction.editReply({ embeds:
|
||||||
|
[returnEmbeddedAlmanax(
|
||||||
|
dateFormatted,
|
||||||
|
data.tribute.item.name,
|
||||||
|
data.tribute.quantity,
|
||||||
|
data.bonus.type.name,
|
||||||
|
data.bonus.description,
|
||||||
|
data.tribute.item.image_urls.sd
|
||||||
|
)]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function returnEmbeddedAlmanax(date, itemName, quantity, bonusName, bonusDesc, imgUrl) {
|
||||||
|
console.log(date)
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setTitle('Almanax du ' + date.slice(8,10) + '/' + date.slice(5,7) + '/' + date.slice(0,4))
|
||||||
|
.setURL('https://www.krosmoz.com/fr/almanax/' + date)
|
||||||
|
.setThumbnail(imgUrl)
|
||||||
|
.addFields(
|
||||||
|
{ name: 'Offrande du jour', value: itemName+' x'+quantity},
|
||||||
|
{ name : bonusName, value: bonusDesc}
|
||||||
|
)
|
||||||
|
return embed;
|
||||||
|
}
|
||||||
10
commands/general/ping.js
Normal file
10
commands/general/ping.js
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('ping')
|
||||||
|
.setDescription('Replies with Pong!'),
|
||||||
|
async execute(interaction) {
|
||||||
|
await interaction.reply('Pong!');
|
||||||
|
},
|
||||||
|
};
|
||||||
82
commands/general/roll.js
Normal file
82
commands/general/roll.js
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
const { AttachmentBuilder, EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('roll')
|
||||||
|
.setDescription('Lance un dé!')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('jet')
|
||||||
|
.setDescription('Jet du dé (par ex: 2d6)')
|
||||||
|
.setRequired(true)),
|
||||||
|
async execute(interaction) {
|
||||||
|
await interaction.deferReply();
|
||||||
|
|
||||||
|
// dice argument
|
||||||
|
let jet = interaction.options.getString('jet');
|
||||||
|
|
||||||
|
// REGEX FORMAT DICE RULE (i.e. 4d6, 10d12, 9d10, 10d5...)
|
||||||
|
const diceRule = /^\d+d\d+$/;
|
||||||
|
|
||||||
|
// dice format check
|
||||||
|
if (!diceRule.test(jet)){
|
||||||
|
interaction.editReply("Désolé, mais le format du jet est dégueulasse...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// getting dice values
|
||||||
|
let dice = jet.split('d');
|
||||||
|
let nbDice = dice[0];
|
||||||
|
let typeDice = dice[1];
|
||||||
|
|
||||||
|
// negative or null dice values check
|
||||||
|
if (nbDice <= 0 || typeDice <= 0) {
|
||||||
|
interaction.editReply("Désolé, mais le format du jet est dégueulasse... (comment ça zéro ?)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructing path to the image
|
||||||
|
let pathThumbnail = "";
|
||||||
|
if (typeDice == 4 || typeDice == 6 || typeDice == 8 || typeDice == 10 || typeDice == 12) {
|
||||||
|
pathThumbnail = 'dice_icons/d' + typeDice.toString() + '.png'
|
||||||
|
} else {
|
||||||
|
pathThumbnail = 'dice_icons/default.png'
|
||||||
|
}
|
||||||
|
// attachment of the image
|
||||||
|
const file = new AttachmentBuilder(pathThumbnail, { name : 'dice.png' });
|
||||||
|
|
||||||
|
// initializing result vars
|
||||||
|
let result = 0;
|
||||||
|
let resultText = "";
|
||||||
|
for (let i = 0 ; i < nbDice ; i++) {
|
||||||
|
let tmp = getRandomInt(typeDice)
|
||||||
|
result += tmp;
|
||||||
|
resultText += tmp.toString()
|
||||||
|
if (i != nbDice-1) {
|
||||||
|
resultText += ' + '
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// replying embeded message
|
||||||
|
interaction.editReply({ embeds:
|
||||||
|
[
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setTitle("Lancer de dé")
|
||||||
|
.setURL("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
||||||
|
.setThumbnail('attachment://dice.png') // trouver la bonne image
|
||||||
|
.addFields(
|
||||||
|
{ name: "Vous avez lancé...", value: jet.toString() },
|
||||||
|
{ name: "Vos jets :", value: resultText },
|
||||||
|
{ name: "Votre résultat est...", value: result.toString() }
|
||||||
|
)
|
||||||
|
// .setImage('attachment://'+file)
|
||||||
|
], files: [file]
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// get random integer from 1 to max included
|
||||||
|
function getRandomInt(max) {
|
||||||
|
return Math.floor(Math.random() * (max-1))+1;
|
||||||
|
}
|
||||||
11
commands/general/server.js
Normal file
11
commands/general/server.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('server')
|
||||||
|
.setDescription('Provides information about the server.'),
|
||||||
|
async execute(interaction) {
|
||||||
|
// interaction.guild is the object representing the Guild in which the command was run
|
||||||
|
await interaction.reply(`This server is ${interaction.guild.name} and has ${interaction.guild.memberCount} members.`);
|
||||||
|
},
|
||||||
|
};
|
||||||
12
commands/general/user.js
Normal file
12
commands/general/user.js
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('user')
|
||||||
|
.setDescription('Provides information about the user.'),
|
||||||
|
async execute(interaction) {
|
||||||
|
// interaction.user is the object representing the User who ran the command
|
||||||
|
// interaction.member is the GuildMember object, which represents the user in the specific guild
|
||||||
|
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`);
|
||||||
|
},
|
||||||
|
};
|
||||||
5
config.json
Normal file
5
config.json
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"token": "MTIwMjI0ODUwMzMwMTI1OTI2NA.Gpj0rd.rOFeed3bKqNnAXQuZ9xIlcSLI8HNrEoe_EUjh8",
|
||||||
|
"clientId": "1202248503301259264",
|
||||||
|
"guildId": "947864126422646794"
|
||||||
|
}
|
||||||
46
deploy-commands.js
Normal file
46
deploy-commands.js
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
const { REST, Routes } = require('discord.js');
|
||||||
|
const { clientId, guildId, token } = require('./config.json');
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
|
||||||
|
const commands = [];
|
||||||
|
// Grab all the command folders from the commands directory you created earlier
|
||||||
|
const foldersPath = path.join(__dirname, 'commands');
|
||||||
|
const commandFolders = fs.readdirSync(foldersPath);
|
||||||
|
|
||||||
|
for (const folder of commandFolders) {
|
||||||
|
// Grab all the command files from the commands directory you created earlier
|
||||||
|
const commandsPath = path.join(foldersPath, folder);
|
||||||
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||||
|
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const filePath = path.join(commandsPath, file);
|
||||||
|
const command = require(filePath);
|
||||||
|
if ('data' in command && 'execute' in command) {
|
||||||
|
commands.push(command.data.toJSON());
|
||||||
|
} else {
|
||||||
|
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct and prepare an instance of the REST module
|
||||||
|
const rest = new REST().setToken(token);
|
||||||
|
|
||||||
|
// and deploy your commands!
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
console.log(`Started refreshing ${commands.length} application (/) commands.`);
|
||||||
|
|
||||||
|
// The put method is used to fully refresh all commands in the guild with the current set
|
||||||
|
const data = await rest.put(
|
||||||
|
Routes.applicationGuildCommands(clientId, guildId),
|
||||||
|
{ body: commands },
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
|
||||||
|
} catch (error) {
|
||||||
|
// And of course, make sure you catch and log any errors!
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
})();
|
||||||
BIN
dice_icons/d10.png
Normal file
BIN
dice_icons/d10.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
BIN
dice_icons/d12.png
Normal file
BIN
dice_icons/d12.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
dice_icons/d4.png
Normal file
BIN
dice_icons/d4.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
BIN
dice_icons/d6.png
Normal file
BIN
dice_icons/d6.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.0 KiB |
BIN
dice_icons/d8.png
Normal file
BIN
dice_icons/d8.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
BIN
dice_icons/default.png
Normal file
BIN
dice_icons/default.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.7 KiB |
26
events/interactionCreate.js
Normal file
26
events/interactionCreate.js
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
const { Events } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: Events.InteractionCreate,
|
||||||
|
async execute(interaction) {
|
||||||
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
|
const command = interaction.client.commands.get(interaction.commandName);
|
||||||
|
|
||||||
|
if (!command) {
|
||||||
|
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await command.execute(interaction);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
if (interaction.replied || interaction.deferred) {
|
||||||
|
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||||
|
} else {
|
||||||
|
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
50
events/midnightAlmanax.js
Normal file
50
events/midnightAlmanax.js
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
const { Events, Client, Intents } = require('discord.js');
|
||||||
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
const cron = require('cron');
|
||||||
|
const dofusdude = require('dofusdude-js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: Events.ClientReady,
|
||||||
|
once: true,
|
||||||
|
execute(client) {
|
||||||
|
const job = new cron.CronJob('55 23 * * *', () => {
|
||||||
|
|
||||||
|
// Example: sending a message to a specific channel
|
||||||
|
|
||||||
|
const api = new dofusdude.AlmanaxApi()
|
||||||
|
const language = 'fr'; // {String} code
|
||||||
|
const newDate = new Date();
|
||||||
|
newDate.setDate(newDate.getDate()+1);
|
||||||
|
newDate.setHours(newDate.getHours()+1);
|
||||||
|
const date = newDate.toISOString().slice(0,10); // {Date} yyyy-mm-dd
|
||||||
|
api.getAlmanaxDate(language, date, (error, data, response) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
console.log('Dofusdude API called successfully.');
|
||||||
|
const channelId = '1202247793356316685';
|
||||||
|
const channel = client.channels.cache.get(channelId);
|
||||||
|
if (channel) {
|
||||||
|
channel.send({ embeds:
|
||||||
|
[new EmbedBuilder()
|
||||||
|
.setTitle('Almanax du ' + date.slice(8,10) + '/' + date.slice(5,7) + '/' + date.slice(0,4))
|
||||||
|
.setURL('https://www.krosmoz.com/fr/almanax/' + date)
|
||||||
|
.setThumbnail(data.tribute.item.image_urls.sd)
|
||||||
|
.addFields(
|
||||||
|
{ name: 'Offrande de demain', value: data.tribute.item.name+' x'+data.tribute.quantity},
|
||||||
|
{ name: data.bonus.type.name, value: data.bonus.description }
|
||||||
|
)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.error('Channel not found!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
job.start();
|
||||||
|
|
||||||
|
console.log(`Daily Dofus API Call done.`);
|
||||||
|
},
|
||||||
|
};
|
||||||
9
events/ready.js
Normal file
9
events/ready.js
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
const { Events } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: Events.ClientReady,
|
||||||
|
once: true,
|
||||||
|
execute(client) {
|
||||||
|
console.log(`Ready! Logged in as ${client.user.tag}`);
|
||||||
|
},
|
||||||
|
};
|
||||||
38
index.js
Normal file
38
index.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
const { Client, Collection, GatewayIntentBits } = require('discord.js');
|
||||||
|
const { token } = require('./config.json');
|
||||||
|
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||||
|
|
||||||
|
client.commands = new Collection();
|
||||||
|
const foldersPath = path.join(__dirname, 'commands');
|
||||||
|
const commandFolders = fs.readdirSync(foldersPath);
|
||||||
|
|
||||||
|
for (const folder of commandFolders) {
|
||||||
|
const commandsPath = path.join(foldersPath, folder);
|
||||||
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const filePath = path.join(commandsPath, file);
|
||||||
|
const command = require(filePath);
|
||||||
|
if ('data' in command && 'execute' in command) {
|
||||||
|
client.commands.set(command.data.name, command);
|
||||||
|
} else {
|
||||||
|
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const eventsPath = path.join(__dirname, 'events');
|
||||||
|
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
|
for (const file of eventFiles) {
|
||||||
|
const filePath = path.join(eventsPath, file);
|
||||||
|
const event = require(filePath);
|
||||||
|
if (event.once) {
|
||||||
|
client.once(event.name, (...args) => event.execute(...args));
|
||||||
|
} else {
|
||||||
|
client.on(event.name, (...args) => event.execute(...args));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client.login(token);
|
||||||
1647
package-lock.json
generated
Normal file
1647
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
16
package.json
Normal file
16
package.json
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"name": "meridianbot",
|
||||||
|
"version": "1.1.0",
|
||||||
|
"description": "Meridian Discord Bot",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "test"
|
||||||
|
},
|
||||||
|
"author": "veko",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"cron": "^3.1.6",
|
||||||
|
"discord.js": "^14.14.1",
|
||||||
|
"dofusdude-js": "^0.8.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user