Skip to content

Commit

Permalink
change coding syntax formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
fakuzatsu committed Mar 30, 2024
1 parent 4c5251f commit 6668098
Show file tree
Hide file tree
Showing 38 changed files with 256 additions and 422 deletions.
57 changes: 23 additions & 34 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,19 @@ const client = new Client({
const eventFolderPath = path.join(__dirname, "events");
const eventFiles = fs
.readdirSync(eventFolderPath)
.filter((file) => file.endsWith(".js"));
.filter(file => file.endsWith(".js"));

for (const file of eventFiles) {
const filePath = path.join(eventFolderPath, file);
const event = require(filePath);

if (event.once) {
if (event.once)
client.once(event.name, (...args) => event.execute(...args, client));
} else {
else
client.on(
event.name,
async (...args) => await event.execute(...args, client),
);
}
}

// Define Collection of Commands, Slash Commands and cooldowns
Expand All @@ -103,18 +102,17 @@ for (const folder of commandFolders) {
const folderPath = path.join(commandFolderPath, folder);
const commandFiles = fs
.readdirSync(folderPath)
.filter((file) => file.endsWith(".js"));
.filter(file => file.endsWith(".js"));

for (const file of commandFiles) {
const filePath = path.join(folderPath, file);
const command = require(filePath);
if ("data" in command && "execute" in command) {
if ("data" in command && "execute" in command)
client.commands.set(command.data.name, command);
} else {
else
console.log(
`[WARNING] the command at ${filePath} is missing a required "data" or "execute" property.`,
);
}
}
}

Expand All @@ -127,18 +125,17 @@ for (const module of slashCommands) {
const modulePath = path.join(slashCommandsFolderPath, module);
const commandFiles = fs
.readdirSync(modulePath)
.filter((file) => file.endsWith(".js"));
.filter(file => file.endsWith(".js"));

for (const commandFile of commandFiles) {
const filePath = path.join(modulePath, commandFile);
const command = require(filePath);
if ("data" in command && "execute" in command) {
if ("data" in command && "execute" in command)
client.slashCommands.set(command.data.name, command);
} else {
else
console.log(
`[WARNING] the slash-command at ${filePath} is missing a required "data" or "execute" property.`,
);
}
}
}

Expand All @@ -153,20 +150,17 @@ const autocompleteInteractions = fs.readdirSync(autocompleteFolderPath);

for (const module of autocompleteInteractions) {
const modulePath = path.join(autocompleteFolderPath, module);
const files = fs
.readdirSync(modulePath)
.filter((file) => file.endsWith(".js"));
const files = fs.readdirSync(modulePath).filter(file => file.endsWith(".js"));

for (const interactionFile of files) {
const filePath = path.join(modulePath, interactionFile);
const interaction = require(filePath);
if ("execute" in interaction) {
if ("execute" in interaction)
client.autocompleteInteractions.set(interaction.name, interaction);
} else {
else
console.log(
`[WARNING] the autocomplete interaction at ${filePath} is missing a required "execute" property.`,
);
}
}
}

Expand All @@ -181,9 +175,7 @@ const contextMenus = fs.readdirSync(contextMenusFolderPath);

for (const folder of contextMenus) {
const folderPath = path.join(contextMenusFolderPath, folder);
const files = fs
.readdirSync(folderPath)
.filter((file) => file.endsWith(".js"));
const files = fs.readdirSync(folderPath).filter(file => file.endsWith(".js"));

for (const file of files) {
const filePath = path.join(folderPath, file);
Expand All @@ -206,7 +198,7 @@ for (const module of buttonCommands) {
const modulePath = path.join(buttonCommandsFolderPath, module);
const commandFiles = fs
.readdirSync(modulePath)
.filter((file) => file.endsWith(".js"));
.filter(file => file.endsWith(".js"));

for (const commandFile of commandFiles) {
const filePath = path.join(modulePath, commandFile);
Expand All @@ -224,7 +216,7 @@ for (const module of modalCommands) {
const modulePath = path.join(modalCommandsFolderPath, module);
const commandFiles = fs
.readdirSync(modulePath)
.filter((file) => file.endsWith(".js"));
.filter(file => file.endsWith(".js"));

for (const commandFile of commandFiles) {
const filePath = path.join(modulePath, commandFile);
Expand All @@ -246,7 +238,7 @@ for (const module of selectMenus) {
const modulePath = path.join(selectMenusFolderPath, module);
const commandFiles = fs
.readdirSync(modulePath)
.filter((file) => file.endsWith(".js"));
.filter(file => file.endsWith(".js"));

for (const commandFile of commandFiles) {
const filePath = path.join(modulePath, commandFile);
Expand All @@ -260,20 +252,18 @@ for (const module of selectMenus) {
const rest = new REST({ version: "9" }).setToken(token);

const commandJsonData = [
...Array.from(client.slashCommands.values()).map((c) => c.data.toJSON()),
...Array.from(client.contextCommands.values()).map((c) => c.data),
...Array.from(client.slashCommands.values()).map(c => c.data.toJSON()),
...Array.from(client.contextCommands.values()).map(c => c.data),
];

(async () => {
try {
console.log("Started refreshing application (/) commands.");

let route;
if (process.env.NODE_ENV === "production") {
if (process.env.NODE_ENV === "production")
route = Routes.applicationCommands(client_id);
} else {
route = Routes.applicationGuildCommands(client_id, test_guild_id);
}
else route = Routes.applicationGuildCommands(client_id, test_guild_id);

await rest.put(route, { body: commandJsonData });

Expand All @@ -294,17 +284,16 @@ for (const folder of triggerFolders) {
const triggersPath = path.join(triggersFolderPath, folder);
const triggerFiles = fs
.readdirSync(triggersPath)
.filter((file) => file.endsWith(".js"));
.filter(file => file.endsWith(".js"));
for (const file of triggerFiles) {
const filePath = path.join(triggersPath, file);
const trigger = require(filePath);
if ("data" in trigger && "execute" in trigger) {
if ("data" in trigger && "execute" in trigger)
client.triggers.set(trigger.data.name, trigger);
} else {
else
console.log(
`[WARNING] the reaction at ${filePath} is missing a required "data" or "execute" property.`,
);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion dex/ability.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function getAbilityIdFromAbilityName(abilityString) {
if (!abilityString) throw Error(`Bad ability string: ${abilityString}`);

const abilityId = abilityNames.labelDataArray.findIndex(
(e) => e.wordDataArray[0].str === abilityString,
e => e.wordDataArray[0].str === abilityString,
);

if (abilityId === -1) throw Error(`Bad ability string: ${abilityString}`);
Expand Down
6 changes: 2 additions & 4 deletions dex/egggroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ function getEggGroupNameById(eggGroupId = 0) {

function createPokemonByEggGroupMap(pokemonMap, currentPokemon) {
// Use sets so I don't have to handle duplicates, looking at you Unown
if (pokemonMap[currentPokemon.egg_group1] === undefined) {
if (pokemonMap[currentPokemon.egg_group1] === undefined)
pokemonMap[currentPokemon.egg_group1] = new Set();
}

if (pokemonMap[currentPokemon.egg_group2] === undefined) {
if (pokemonMap[currentPokemon.egg_group2] === undefined)
pokemonMap[currentPokemon.egg_group2] = new Set();
}

pokemonMap[currentPokemon.egg_group1].add(currentPokemon.id);
pokemonMap[currentPokemon.egg_group2].add(currentPokemon.id);
Expand Down
20 changes: 6 additions & 14 deletions dex/evolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const {
} = require("./evolutionConstants");

function getEvolutionMethodDetail(methodId, methodParameter = 0, level) {
if (methodId === -1) {
return -1;
}
if (methodId === -1) return -1;
if (
!Number.isInteger(methodId) ||
methodId < 0 ||
Expand Down Expand Up @@ -37,14 +35,11 @@ function getEvolutionMethodDetail(methodId, methodParameter = 0, level) {
}

function getEvolutionTree(pokemonId = 0, fromRoot = true) {
if (!Number.isInteger(pokemonId) || pokemonId < 0) {
if (!Number.isInteger(pokemonId) || pokemonId < 0)
throw new Error(`Bad pokemon ID: ${pokemonId}`);
}

const pokemon = EvolutionData[pokemonId];
if (!pokemon) {
throw new Error(`Bad pokemon ID: ${pokemonId}`);
}
if (!pokemon) throw new Error(`Bad pokemon ID: ${pokemonId}`);

const startPokemonId = fromRoot ? pokemon.path[0] : pokemonId;

Expand All @@ -53,7 +48,7 @@ function getEvolutionTree(pokemonId = 0, fromRoot = true) {
const evolutionTree = {
pokemonId: startPokemonId,
evolutionDetails: getEvolutionDetails(startPokemonId),
evolvesInto: evolution.targets.map((nextStagePokemonId) =>
evolvesInto: evolution.targets.map(nextStagePokemonId =>
getEvolutionTree(nextStagePokemonId, false),
),
};
Expand All @@ -71,9 +66,7 @@ function checkEvolutionPath(evolutionData, originalPokemonId) {
function getEvolutionDetails(pokemonId) {
const evolutionDetails = EvolutionData[pokemonId].ar;

if (!evolutionDetails) {
return null;
}
if (!evolutionDetails) return null;

for (let i = 0; i < evolutionDetails.length; i++) {
const evolutionData = evolutionDetails[i];
Expand All @@ -99,15 +92,14 @@ function getEvolutionDetails(pokemonId) {
levels.push(level);
}
}
if (methodIds.length > 0) {
if (methodIds.length > 0)
return {
methodIds,
methodParameters,
monsNos,
formNos,
levels,
};
}
}
return null;
}
Expand Down
5 changes: 2 additions & 3 deletions dex/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ const { PersonalTable } = require(global.gameDataFolder);
const FORM_MAP = PersonalTable.Personal.reduce(createFormMap, {});

function createFormMap(formMap, currentPokemon) {
if (!Array.isArray(formMap[currentPokemon.monsno])) {
if (!Array.isArray(formMap[currentPokemon.monsno]))
formMap[currentPokemon.monsno] = [];
}

formMap[currentPokemon.monsno].push(currentPokemon.id);
return formMap;
Expand Down Expand Up @@ -44,7 +43,7 @@ function getGrassKnotPower(weightkg) {

function getPokemonIdFromMonsNoAndForm(monsno, formno) {
return PersonalTable.Personal.find(
(e) => e.monsno === monsno && FORM_MAP[e.monsno][formno] === e.id,
e => e.monsno === monsno && FORM_MAP[e.monsno][formno] === e.id,
)?.id;
}

Expand Down
4 changes: 2 additions & 2 deletions dex/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ function getItemIdFromItemName(itemName) {
if (!itemName) throw Error(`Bad item name: ${itemName}`);
if (itemName === "King's Rock")
return itemNames.labelDataArray.findIndex(
(e) => e.wordDataArray[0]?.str === "King’s Rock",
e => e.wordDataArray[0]?.str === "King’s Rock",
);
const index = itemNames.labelDataArray.findIndex(
(e) => e.wordDataArray[0]?.str === itemName,
e => e.wordDataArray[0]?.str === itemName,
);
if (index === -1) throw Error(`Bad item name: ${itemName}`);
return index;
Expand Down
47 changes: 17 additions & 30 deletions dex/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function getEncounterObject(encounter) {
function containsAllTOD(todEncounters) {
const desiredEncounterTypes = ["Morning", "Day", "Night"];

const hasAllEncounterTypes = desiredEncounterTypes.every((type) =>
todEncounters.some((encounter) => encounter.method === type),
const hasAllEncounterTypes = desiredEncounterTypes.every(type =>
todEncounters.some(encounter => encounter.method === type),
);
return hasAllEncounterTypes;
}
Expand All @@ -30,16 +30,14 @@ function combineEncounterTypes(encounterData) {
const combinedEncounters = {};
const todEncounters = {};

encounterData.forEach((encounter) => {
encounterData.forEach(encounter => {
const { isTOD, isBadArea } = checkIsBadArea(encounter);

const key = `${encounter.name}_${encounter.method}`;
if (isTOD && !isBadArea) {
if (!todEncounters[encounter.name]) {
if (!todEncounters[encounter.name])
todEncounters[encounter.name] = [getEncounterObject(encounter)];
} else {
todEncounters[encounter.name].push(getEncounterObject(encounter));
}
else todEncounters[encounter.name].push(getEncounterObject(encounter));
} else if (!combinedEncounters[key] && !isBadArea) {
combinedEncounters[key] = getEncounterObject(encounter);
} else if (!isBadArea) {
Expand Down Expand Up @@ -89,17 +87,15 @@ function checkIsBadArea(encounter) {
encounter.name = "Old Chateau";
encounter.chance = parseFloat(encounter.chance) / 9;
}
if (isInside && isMorning) {
encounter.method = "Walking";
}
if (isInside && isMorning) encounter.method = "Walking";
return { isTOD, isBadArea };
}

function addTODEncounters(todEncounters, combinedEncounters) {
for (const locationKey of Object.keys(todEncounters)) {
const combinedValues = Object.values(combinedEncounters);
const routeIndex = combinedValues.findLastIndex(
(enc) => enc.name === locationKey,
enc => enc.name === locationKey,
);

if (containsAllTOD(todEncounters[locationKey])) {
Expand All @@ -114,22 +110,16 @@ function addTODEncounters(todEncounters, combinedEncounters) {
);
}
} else if (routeIndex !== -1) {
todEncounters[locationKey].forEach((encounter) => {
todEncounters[locationKey].forEach(encounter => {
const routeKey = `${encounter.name}_${encounter.method}`;
if (!combinedEncounters[routeKey]) {
combinedEncounters[routeKey] = encounter;
} else {
combinedEncounters[routeKey].chance += parseFloat(encounter.chance);
}
if (!combinedEncounters[routeKey]) combinedEncounters[routeKey] = encounter;
else combinedEncounters[routeKey].chance += parseFloat(encounter.chance);
});
} else {
todEncounters[locationKey].forEach((encounter) => {
todEncounters[locationKey].forEach(encounter => {
const routeKey = `${encounter.name}_${encounter.method}`;
if (!combinedEncounters[routeKey]) {
combinedEncounters[routeKey] = encounter;
} else {
combinedEncounters[routeKey].chance += parseFloat(encounter.chance);
}
if (!combinedEncounters[routeKey]) combinedEncounters[routeKey] = encounter;
else combinedEncounters[routeKey].chance += parseFloat(encounter.chance);
});
}
}
Expand All @@ -138,15 +128,12 @@ function addTODEncounters(todEncounters, combinedEncounters) {
function getRoutesFromPokemonId(pokemonId) {
const pokemonName = getPokemonName(pokemonId);
let routes = [];
if (pokemonLocations[pokemonId] && staticLocations[pokemonName]) {
if (pokemonLocations[pokemonId] && staticLocations[pokemonName])
routes = pokemonLocations[pokemonId].concat(staticLocations[pokemonName]);
} else if (pokemonLocations[pokemonId]) {
routes = pokemonLocations[pokemonId];
} else {
routes = staticLocations[pokemonName] || [];
}
else if (pokemonLocations[pokemonId]) routes = pokemonLocations[pokemonId];
else routes = staticLocations[pokemonName] || [];

const locationRates = routes.map((route) => {
const locationRates = routes.map(route => {
let method = ENC_TYPES[route.encounterType] ?? route.encounterType;
let chance = route.encounterRate;
if (chance === "morning") {
Expand Down
Loading

0 comments on commit 6668098

Please sign in to comment.