Skip to content

Commit

Permalink
Merge branch 'master' into statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Glazelf committed May 13, 2024
2 parents 5c48358 + fc68ad0 commit 65f3038
Show file tree
Hide file tree
Showing 100 changed files with 1,029 additions and 853 deletions.
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ updates:
assignees: ["glazelf"]
schedule:
interval: "weekly"
day: "tuesday"
time: "06:00"
- package-ecosystem: "gitsubmodule"
directory: "/"
assignees: ["glazelf"]
schedule:
interval: "daily"
time: "06:00"
23 changes: 12 additions & 11 deletions affairs/birthday.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
module.exports = async (client) => {
const logger = require('../util/logger');
// Import globals
let globalVars = require('../events/ready');
try {
const getRandomGif = require("../util/getRandomGif");
const cron = require("cron");
const timezone = 'utc';
const time = '05 00 06 * * *'; // Sec Min Hour, 8am CEST
const guildID = globalVars.ShinxServerID;
const channelID = globalVars.eventChannelID;
const guildID = client.globalVars.ShinxServerID;
const channelID = client.globalVars.eventChannelID;
const Discord = require("discord.js");
const api_user = require('../database/dbServices/user.api');
const gifTags = ["birthday"];
if (client.user.id != globalVars.NinigiID) return;
if (client.user.id != client.globalVars.NinigiID) return;
// Create cron job
new cron.CronJob(time, async () => {
let guild = await client.guilds.fetch(guildID);
if (!guild) return;
let birthdayRoleID = "744719808058228796";
const birthdayRole = guild.roles.cache.find(role => role.id === birthdayRoleID);
const birthdayRole = await guild.roles.fetch(birthdayRoleID, { force: true });
if (!birthdayRole) return;
let yesterdayCuties = birthdayRole.members;
yesterdayCuties.forEach(cutie => cutie.roles.remove(birthdayRole));
const cuties = [];
let cuties = [];
let cutiesUsernames = [];
await guild.members.fetch();
// For every member check
for (m in [...guild.members.cache.values()]) {
Expand All @@ -32,7 +32,8 @@ module.exports = async (client) => {
let now = new Date();
// Birthdays are stored as string DDMM instead of being seperated by a -
if (now.getDate() === parseInt(birthday.substring(0, 2)) && (now.getMonth() + 1) === parseInt(birthday.substring(2))) {
cuties.push(member.user.username);
cuties.push(member.user.toString());
cutiesUsernames.push(member.user.username);
await member.roles.add(birthdayRole);
};
};
Expand All @@ -43,14 +44,14 @@ module.exports = async (client) => {
const randomGif = await getRandomGif(gifTags);
// Create embed
const gifEmbed = new Discord.EmbedBuilder()
.setColor(globalVars.embedColor)
.setDescription(`Today is ${cuties.join(' and ')}'s birthday, everyone!`)
.setColor(client.globalVars.embedColor)
.setDescription(`Today is ${cutiesUsernames.join(' and ')}'s birthday, everyone!`)
.setImage(randomGif);
channel.send({ embeds: [gifEmbed] });
channel.send({ embeds: [gifEmbed], content: cuties.join(' ') });
}, timeZone = timezone, start = true);

} catch (e) {
// Log error
logger(e, client);
};
};
};
10 changes: 4 additions & 6 deletions affairs/stan.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
const api_history = require('../database/dbServices/history.api');
module.exports = async (client) => {
const logger = require('../util/logger');
// Import globals
let globalVars = require('../events/ready');
try {
const Discord = require("discord.js");
const getRandomGif = require("../util/getRandomGif");
const cron = require("cron");
const timezone = 'utc';
const time = '00 00 18 * * *'; // Sec Min Hour
const gifTags = ['pokemon', 'geass', 'dragon', 'game'];
const guildID = globalVars.ShinxServerID;
const guildID = client.globalVars.ShinxServerID;

if (client.user.id != globalVars.NinigiID) return;
if (client.user.id != client.globalVars.NinigiID) return;
// Create cronjob
new cron.CronJob(time, async () => {
let guild = await client.guilds.fetch(guildID);
Expand All @@ -30,10 +28,10 @@ module.exports = async (client) => {
const randomGif = await getRandomGif(gifTags);
if (!randomGif) return;

let channel = guild.channels.cache.find(channel => channel.id === globalVars.eventChannelID);
let channel = guild.channels.cache.find(channel => channel.id === client.globalVars.eventChannelID);

const gifEmbed = new Discord.EmbedBuilder()
.setColor(globalVars.embedColor)
.setColor(client.globalVars.embedColor)
.setDescription(`Today's most stannable person is ${candidateRandom.username}, everyone!`)
.setImage(randomGif);
channel.send({
Expand Down
109 changes: 109 additions & 0 deletions commands/api/dictionary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const Discord = require("discord.js");
exports.run = async (client, interaction, logger, ephemeral = true) => {
try {
const sendMessage = require('../../util/sendMessage');
const axios = require("axios");
let api = "https://api.dictionaryapi.dev/api/v2/";

let ephemeralArg = interaction.options.getBoolean("ephemeral");
if (ephemeralArg !== null) ephemeral = ephemeralArg;
await interaction.deferReply({ ephemeral: ephemeral });
let dictionaryEmbed = new Discord.EmbedBuilder()
.setColor(client.globalVars.embedColor);

let inputWord = interaction.options.getString("word");
let inputWordType = interaction.options.getString("wordtype");

try {
// Sometimes API doesn't respond when a word doesn't exist, sometimes it errors properly. Timeout is to catch both.
wordStatus = await Promise.race([
axios.get(`${api}entries/en/${inputWord}`),
new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), 5000))
]);
wordStatus = wordStatus.data;
} catch (error) {
let errorEmbed = new Discord.EmbedBuilder()
.setColor('#FF0000')
.setTitle("Error")
.setDescription("Word not found.");
return sendMessage({ client: client, interaction: interaction, embeds: errorEmbed, ephemeral: ephemeral });
};

let wordMeaning;
outerLoop:
for (let i = 0; i < wordStatus.length; i++) {
if (inputWordType) {
for (let meaning of wordStatus[i].meanings) {
if (meaning.partOfSpeech.toLowerCase() === inputWordType.toLowerCase()) {
wordMeaning = meaning;
break outerLoop;
};
};
};
};
if (!wordMeaning) wordMeaning = wordStatus[0].meanings[0];

let wordPhoneticString = "";
if (wordStatus[0].phonetics) {
// Would be cool if this could be attached as a voice notes but this feature is blocked for bots
let wordPhoneticsArray = wordStatus[0].phonetics.filter(phonetic => phonetic.text && phonetic.text.length > 0);
let wordPhoneticsArrayAudio = wordPhoneticsArray.filter(phonetic => phonetic.audio && phonetic.audio.length > 0); // Prefer entries with audio available
if (wordPhoneticsArrayAudio.length > 0) {
wordPhoneticString = `[${wordPhoneticsArrayAudio[0].text}](<${wordPhoneticsArrayAudio[0].audio}>)`;
} else if (wordPhoneticsArray.length > 0) {
wordPhoneticString = wordPhoneticsArray[0].text;
};
} else if (wordStatus[0].phonetic) {
wordPhoneticString = wordStatus[0].phonetic;
};
let wordStatusTitle = wordStatus[0].word;
await wordMeaning.definitions.forEach(definition => {
let wordDefinition = definition.definition;
let wordExample = definition.example;
let wordSynonyms = definition.synonyms;
let wordAntonyms = definition.antonyms;
let wordDefinitionString = "";
if (wordExample) wordDefinitionString += `Example: ${wordExample}\n`;
if (wordSynonyms.length > 0) wordDefinitionString += `Synonyms: ${wordSynonyms.join(', ')}\n`;
if (wordAntonyms.length > 0) wordDefinitionString += `Antonyms: ${wordAntonyms.join(', ')}\n`;
if (wordDefinitionString.length == 0) wordDefinitionString = "No example, synonyms or antonyms found.";
dictionaryEmbed.addFields([{ name: definition.definition, value: wordDefinitionString, inline: false }]);
});
let wordType = wordMeaning.partOfSpeech;
let wordSourceUrls = wordStatus[0].sourceUrls;

dictionaryEmbed
.setTitle(`${wordStatusTitle}, ${wordType}`)
.setURL(wordSourceUrls[0]);
if (wordPhoneticString.length > 0) dictionaryEmbed.setDescription(wordPhoneticString);
return sendMessage({ client: client, interaction: interaction, embeds: dictionaryEmbed, ephemeral: ephemeral });

} catch (e) {
// Log error
logger(e, client, interaction);
};
};

module.exports.config = {
name: "dictionary",
description: `Get definition of a word.`,
options: [{
name: "word",
type: Discord.ApplicationCommandOptionType.String,
description: "Specify word to look up.",
required: true
}, {
name: "wordtype",
type: Discord.ApplicationCommandOptionType.String,
description: "Select type of word.",
choices: [
{ name: "noun", value: "noun" },
{ name: "verb", value: "verb" },
{ name: "adjective", value: "adjective" }
]
}, {
name: "ephemeral",
type: Discord.ApplicationCommandOptionType.Boolean,
description: "Whether the reply will be private."
}]
};
6 changes: 3 additions & 3 deletions commands/api/dqm3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Discord = require("discord.js");
exports.run = async (client, interaction, logger, globalVars, ephemeral = true) => {
exports.run = async (client, interaction, logger, ephemeral = true) => {
try {
const sendMessage = require('../../util/sendMessage');
const getWikiURL = require('../../util/getWikiURL');
Expand All @@ -23,7 +23,7 @@ exports.run = async (client, interaction, logger, globalVars, ephemeral = true)
if (detailedArg === true) detailed = true;

let dqm3Embed = new Discord.EmbedBuilder()
.setColor(globalVars.embedColor);
.setColor(client.globalVars.embedColor);
switch (interaction.options.getSubcommand()) {
case "monster":
inputID = interaction.options.getString("monster");
Expand Down Expand Up @@ -330,4 +330,4 @@ module.exports.config = {
description: "Whether the reply will be private."
}]
}]
};
};
4 changes: 2 additions & 2 deletions commands/api/genshin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Discord = require("discord.js");
exports.run = async (client, interaction, logger, globalVars, ephemeral = true) => {
exports.run = async (client, interaction, logger, ephemeral = true) => {
try {
const sendMessage = require('../../util/sendMessage');
const axios = require("axios");
Expand All @@ -14,7 +14,7 @@ exports.run = async (client, interaction, logger, globalVars, ephemeral = true)
let response;
let buttonArray = [];
let giEmbed = new Discord.EmbedBuilder()
.setColor(globalVars.embedColor);
.setColor(client.globalVars.embedColor);
switch (interaction.options.getSubcommand()) {
case "character":
giAPI += `characters/`;
Expand Down
4 changes: 2 additions & 2 deletions commands/api/helldivers2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Discord = require("discord.js");
exports.run = async (client, interaction, logger, globalVars, ephemeral = true) => {
exports.run = async (client, interaction, logger, ephemeral = true) => {
try {
const sendMessage = require('../../util/sendMessage');
const axios = require("axios");
Expand All @@ -12,7 +12,7 @@ exports.run = async (client, interaction, logger, globalVars, ephemeral = true)
let defenseString = "Defense";
await interaction.deferReply({ ephemeral: ephemeral });
let helldiversEmbed = new Discord.EmbedBuilder()
.setColor(globalVars.embedColor);
.setColor(client.globalVars.embedColor);

switch (interaction.options.getSubcommand()) {
case "planet":
Expand Down
44 changes: 6 additions & 38 deletions commands/api/monsterhunter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const Discord = require("discord.js");
exports.run = async (client, interaction, logger, globalVars, ephemeral = true) => {
exports.run = async (client, interaction, logger, ephemeral = true) => {
try {
const sendMessage = require('../../util/sendMessage');
const randomNumber = require('../../util/randomNumber');
const capitalizeString = require('../../util/capitalizeString');
const isAdmin = require('../../util/isAdmin');
const getMonster = require('../../util/mh/getMonster');
const getQuests = require('../../util/mh/getQuests');
const monstersJSON = require("../../submodules/monster-hunter-DB/monsters.json");
const questsJSON = require("../../submodules/monster-hunter-DB/quests.json");
const elementEmotes = require('../../objects/monsterhunter/elementEmotes.json');
Expand All @@ -18,7 +19,7 @@ exports.run = async (client, interaction, logger, globalVars, ephemeral = true)

let buttonArray = [];
let mhEmbed = new Discord.EmbedBuilder()
.setColor(globalVars.embedColor);
.setColor(client.globalVars.embedColor);

switch (interaction.options.getSubcommand()) {
// Specific quest
Expand Down Expand Up @@ -56,42 +57,9 @@ exports.run = async (client, interaction, logger, globalVars, ephemeral = true)
break;
// All quests from a game
case "quests":
let gameName = interaction.options.getString("game").toLowerCase();
// Add quests matching game title to an array
let questsTotal = questsJSON.quests.filter(quest => quest.game == gameName);
if (questsTotal.length == 0) return sendMessage({ client: client, interaction: interaction, content: "Could not find any quests for that game. If you are certain this game exists the quest list may still be a work in progress." });
// Sort by difficulty
questsTotal = questsTotal.sort(compare);
mhEmbed
.setColor(globalVars.embedColor)
.setTitle(`${gameName} Quests`);
let totalQuests = questsTotal.length;
let pageLength = 25;
let currentPage = 1; // Load page 1 on command use
let questsPaged = questsTotal.reduce((questsTotal, item, index) => {
const chunkIndex = Math.floor(index / pageLength);
// start a new chunk
if (!questsTotal[chunkIndex]) questsTotal[chunkIndex] = [];

questsTotal[chunkIndex].push(item);
return questsTotal;
}, []);
let totalPages = questsPaged.length;

questsPaged[currentPage - 1].forEach(quest => {
let questTitle = `${quest.difficulty}${quest.name}`;
if (quest.isKey) questTitle += ` 🔑`;
mhEmbed.addFields([{ name: `${questTitle}`, value: `${quest.objective} in ${quest.map}`, inline: false }]);
});
let startIndex = currentPage + pageLength * currentPage;
let endIndex = startIndex + pageLength - 1;
mhEmbed.setFooter({ text: `Page ${currentPage}/${totalPages}` });
// Function to sort by difficulty
function compare(a, b) {
if (a.difficulty > b.difficulty) return -1;
if (a.difficulty < b.difficulty) return 1;
return 0;
};
let gameName = interaction.options.getString("game");
let questsMessageObject = await getQuests({ client: client, interaction: interaction, gameName: gameName, page: 1 });
return sendMessage({ client: client, interaction: interaction, embeds: questsMessageObject.embeds, components: questsMessageObject.components, ephemeral: ephemeral });
break;
// Monsters
case "monster":
Expand Down
4 changes: 2 additions & 2 deletions commands/api/persona5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Discord = require("discord.js");
exports.run = async (client, interaction, logger, globalVars, ephemeral) => {
exports.run = async (client, interaction, logger, ephemeral) => {
try {
const sendMessage = require('../../util/sendMessage');
const fs = require("fs");
Expand All @@ -26,7 +26,7 @@ exports.run = async (client, interaction, logger, globalVars, ephemeral) => {
// Imports itemMapRoyal; object including all item names mapped to item type/descriptions
eval(fs.readFileSync("submodules/persona5_calculator/data/ItemDataRoyal.js", "utf8"));
let p5Embed = new Discord.EmbedBuilder()
.setColor(globalVars.embedColor);
.setColor(client.globalVars.embedColor);

switch (interaction.options.getSubcommand()) {
case "persona":
Expand Down
Loading

0 comments on commit 65f3038

Please sign in to comment.