mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +02:00
feat: switched to .env
This commit is contained in:
1 parent
03ec2397a5
commit
d40708f878
9 files changed
+37
-18
No files matched your search
+1
-1
@@ -1,3 +1,3 @@
|
||||
config.json
|
||||
node_modules
|
||||
package-lock.json
|
||||
.env
|
||||
@@ -12,7 +12,7 @@ yarn
|
||||
|
||||
### Configuring
|
||||
|
||||
Clone `config.template.json` to `config.json` and add your own Discord token and Wargaming application id. Also, replace entries in the `discord.json` file to match constants from your Discord server.
|
||||
Add an `.env` file to the root of the project with your `DISCORD_TOKEN` and `b001f1746167d1f1102720ff336a1f9b`
|
||||
|
||||
### Running
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"discord_token": "",
|
||||
"wargaming_application_id": ""
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
"@faker-js/faker": "^7.6.0",
|
||||
"@types/node": "^18.15.11",
|
||||
"discord.js": "^14.9.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.0.4"
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
|
||||
|
||||
@@ -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
@@ -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);
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -187,6 +187,11 @@ discord.js@^14.9.0:
|
||||
undici "^5.21.0"
|
||||
ws "^8.13.0"
|
||||
|
||||
dotenv@^16.0.3:
|
||||
version "16.0.3"
|
||||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07"
|
||||
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==
|
||||
|
||||
fast-deep-equal@^3.1.3:
|
||||
version "3.1.3"
|
||||
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
|
||||
|
||||
Reference in new issue
Block a user