feat: switched to .env

This commit is contained in:
TresAbhi committed 2023-04-20 14:09:22 +00:00
1 parent 03ec2397a5
commit d40708f878
9 files changed
+37 -18

No files matched your search

+6 -7
View File
@@ -1,4 +1,3 @@
import discord from '../../discord.json' assert { type: 'json' };
import {
CacheType,
Collection,
@@ -8,8 +7,11 @@ import {
Routes,
SlashCommandBuilder,
} from 'discord.js';
import { config } from 'dotenv';
import { readdirSync } from 'fs';
import config from '../../config.json' assert { type: 'json' };
import discord from '../../discord.json' assert { type: 'json' };
config();
export interface CommandRegistry {
data: SlashCommandBuilder;
@@ -19,7 +21,7 @@ export interface CommandRegistry {
const commandCollection = new Collection<string, CommandRegistry>();
const commands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
const commandFolders = readdirSync('src/commands/');
const rest = new REST().setToken(config.discord_token);
const rest = new REST().setToken(process.env.DISCORD_TOKEN!);
for (const file of commandFolders) {
const command = (await import(`../commands/${file}`)) as CommandRegistry;
@@ -31,10 +33,7 @@ try {
console.log(`Started refreshing ${commands.length} command(s).`);
const data = (await rest.put(
Routes.applicationGuildCommands(
discord.client_id,
discord.guild_id,
),
Routes.applicationGuildCommands(discord.client_id, discord.guild_id),
{ body: commands },
)) as { length: number };
+5 -3
View File
@@ -4,10 +4,12 @@ import {
EmbedBuilder,
SlashCommandBuilder,
} from 'discord.js';
import config from '../../config.json' assert { type: 'json' };
import { config } from 'dotenv';
import discord from '../../discord.json' assert { type: 'json' };
import AccountList from '../types/accountList.js';
config();
const SERVER_NAMES = { com: 'North America', eu: 'Europe', asia: 'Asia' };
export async function execute(
@@ -17,13 +19,13 @@ export async function execute(
const server = interaction.options.getString('server')!;
const serverName = SERVER_NAMES[server as keyof typeof SERVER_NAMES];
const players = (await fetch(
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${config.wargaming_application_id}&search=${ign}`,
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${process.env.WARGAMING_APPLICATION_ID}&search=${ign}`,
).then((response) => response.json())) as AccountList;
if (players?.data?.[0].nickname === ign) {
// good match
const clanData = (await fetch(
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${config.wargaming_application_id}&account_id=${players.data[0].account_id}&extra=clan`,
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${process.env.WARGAMING_APPLICATION_ID}&account_id=${players.data[0].account_id}&extra=clan`,
).then((response) => response.json())) as {
data: { [key: number]: { clan: { tag: string } | null } };
};
+6 -2
View File
@@ -1,8 +1,12 @@
import { Client, GatewayIntentBits } from 'discord.js';
import config from '../config.json' assert { type: 'json' };
import { config } from 'dotenv';
import guildMemberAdd from './behaviors/guildMemberAdd.js';
import interactionCreate from './behaviors/interactionCreate.js';
import ready from './behaviors/ready.js';
import tokenRequirements from './utilities/tokenRequirements.js';
config();
tokenRequirements();
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers],
@@ -12,4 +16,4 @@ client.on('error', console.error);
client.on('ready', ready);
client.on('guildMemberAdd', guildMemberAdd);
client.on('interactionCreate', interactionCreate);
client.login(config.discord_token);
client.login(process.env.DISCORD_TOKEN);
+12
View File
@@ -0,0 +1,12 @@
import { config } from 'dotenv';
config();
export default function tokenRequirements() {
if (!process.env.DISCORD_TOKEN) {
throw new Error('DISCORD_TOKEN is not defined');
}
if (!process.env.WARGAMING_APPLICATION_ID) {
throw new Error('WARGAMING_APPLICATION_ID is not defined');
}
}