Skip to content

Commit

Permalink
[PATCH] auth.json -> dotenv
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsundso committed Dec 27, 2023
1 parent 49bf600 commit 642b278
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 81 deletions.
35 changes: 35 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Bot Websites
topGGToken="" # https://top.gg/ Access Token
DBToken="" # https://discord.bots.gg/ Access Token
DBListToken="" # https://discordbotlist.com Access Token

# Internals
postgresToken="" # PostgreSQL DataBase Token
useRedis="" # Whether to use Redis or not (true/false)
redisToken="" # Redis DataBase Token
socketToken="" # WebSocket Token
DATABASE_URL="" # DataBase Connection String
Token="" # Bot Token

# Client
ownerID="" # Bot Owner ID
clientID="" # Bot Client ID
mainID="" # Bot Main Client ID (Several functions are disabled if this is not the main client)
secret="" # Bot Secret

# Webhooks
guildActionWebhookID="" # Guild Action Webhook ID (Bot is added and removed from Guilds)
dmWebhookID="" # DM Webhook ID (Bot receives DMs)

guildActionWebhookToken="" # Guild Action Webhook Token (Bot is added and removed from Guilds)
dmWebhookToken="" # DM Webhook ID (Bot receives DMs)

# Anti-Virus
promptAPIToken="" # https://apilayer.com/ Access Token
VTToken="" # https://virustotal.com/ Access Token
ip2whoisToken="" # https://ip2whois.com/ Access Token
spamhausToken="" # https://spamhaus.org/ Access Token
kasperskyToken="" # https://kaspersky.com/ Access Token
safeBrowsingToken="" # https://developers.google.com/safe-browsing/ Access Token
fishToken="" # https://fishfish.gg/ Access Token
phishToken="" # https://api.fishfish.gg/docs/ Access Token
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "module",
"version": "1.6.61",
"version": "1.6.62",
"scripts": {
"start": "node --max-old-space-size=8192 ./dist/index.js",
"build": "npx tsc",
Expand All @@ -19,6 +19,7 @@
"client@latest": "link:prisma/client@latest",
"discord-api-types": "^0.37.65",
"discord.js": "^14.14.1",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"fastify": "^4.24.3",
"glob": "^10.3.10",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/BaseClient/Client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Discord from 'discord.js';
import * as DiscordCore from '@discordjs/core';
import auth from '../auth.json' assert { type: 'json' };

const client = new Discord.Client({
shards: 'auto',
Expand Down Expand Up @@ -56,7 +55,7 @@ const client = new Discord.Client({
},
});

await client.login(auth.token);
await client.login(process.env.Token);

export const API = new DiscordCore.API(client.rest);
export default client;
3 changes: 1 addition & 2 deletions src/BaseClient/ClientHelperModules/cache/urls/fishFish.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fetch from 'node-fetch';
import * as Jobs from 'node-schedule';
import auth from '../../../../auth.json' assert { type: 'json' };

/**
* Interface for the FishFish cache module.
Expand Down Expand Up @@ -40,7 +39,7 @@ const self: FishFish = {
const authRes = await fetch('https://api.fishfish.gg/v1/users/@me/tokens', {
method: 'POST',
headers: {
authorization: auth.fishToken,
authorization: process.env.fishToken ?? '',
},
});
if (!authRes.ok) throw new Error('Failed to create FishFish Session');
Expand Down
3 changes: 1 addition & 2 deletions src/BaseClient/ClientHelperModules/refreshToken.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import auth from '../../auth.json' assert { type: 'json' };
import DataBase from '../DataBase.js';
import * as Client from '../Client.js';

Expand All @@ -11,7 +10,7 @@ import * as Client from '../Client.js';
export default async (refreshtoken: string) => {
const res = await Client.API.oauth2.refreshToken({
client_id: Client.default.user?.id as string,
client_secret: auth.secret,
client_secret: process.env.secret ?? '',
grant_type: 'refresh_token',
refresh_token: refreshtoken,
});
Expand Down
12 changes: 7 additions & 5 deletions src/BaseClient/ClientHelperModules/stp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import auth from '../../auth.json' assert { type: 'json' };

interface R {
[key: string]: unknown | R;
}
Expand All @@ -26,7 +24,11 @@ export default (expression: string, obj: R) => {
return decided as string;
};

return expression
.replace(/{{\s?([^{}\s]*)\s?}}/g, replace)
.replace(RegExp(auth.token, 'g'), 'TOKEN');
expression = expression.replace(/{{\s?([^{}\s]*)\s?}}/g, replace);

Object.values(process.env).forEach((s) => {
expression = expression.replace(new RegExp(`${s}`, 'g'), '*');
});

return expression;
};
3 changes: 1 addition & 2 deletions src/BaseClient/Socket.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import io from 'socket.io-client';
import auth from '../auth.json' assert { type: 'json' };

export default io('https://api.ayakobot.com', {
transports: ['websocket'],
auth: {
reason: 'botClient',
code: auth.socketToken,
code: process.env.socketToken ?? '',
},
});
3 changes: 1 addition & 2 deletions src/Commands/SlashCommands/info/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Discord from 'discord.js';
import fetch from 'node-fetch';
import * as ch from '../../../BaseClient/ClientHelper.js';
import * as CT from '../../../Typings/Typings.js';
import auth from '../../../auth.json' assert { type: 'json' };

const month = 2629743000;

Expand Down Expand Up @@ -142,7 +141,7 @@ const getMemberEmbed = (

const getBotInfo = async (bot: Discord.User, language: CT.Language) => {
const res = await fetch(`https://top.gg/api/bots/${bot.id}`, {
headers: { Authorization: auth.topGGtoken },
headers: { Authorization: process.env.topGGtoken ?? '' },
})
.then(
(r) => r.json() as Promise<CT.TopGGResponse<true> | CT.TopGGResponse<false>> | Promise<null>,
Expand Down
5 changes: 2 additions & 3 deletions src/Events/guildEvents/guildCreate/log.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type * as Discord from 'discord.js';
import client from '../../../BaseClient/Client.js';
import * as CT from '../../../Typings/Typings.js';
import auth from '../../../auth.json' assert { type: 'json' };

export default async (guild: Discord.Guild) => {
const webhook = await client.fetchWebhook(
auth.guildActionWebhook.id,
auth.guildActionWebhook.token,
process.env.guildActionWebhookID ?? '',
process.env.guildActionWebhookToken ?? '',
);

webhook?.send({
Expand Down
5 changes: 2 additions & 3 deletions src/Events/guildEvents/guildDelete/log.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type * as Discord from 'discord.js';
import client from '../../../BaseClient/Client.js';
import * as CT from '../../../Typings/Typings.js';
import auth from '../../../auth.json' assert { type: 'json' };

export default async (guild: Discord.Guild | undefined) => {
const webhook = await client.fetchWebhook(
auth.guildActionWebhook.id,
auth.guildActionWebhook.token,
process.env.guildActionWebhookID ?? '',
process.env.guildActionWebhookToken ?? '',
);

webhook?.send({
Expand Down
17 changes: 9 additions & 8 deletions src/Events/messageEvents/messageCreate/antivirus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { API } from '../../../BaseClient/Client.js';
import * as ch from '../../../BaseClient/ClientHelper.js';
import * as CT from '../../../Typings/Typings.js';
import * as VirusVendorsTypings from '../../../Typings/VirusVendorsTypings.js';
import auth from '../../../auth.json' assert { type: 'json' };

type VendorType = 'Kaspersky' | 'Google Safe Browsing' | 'PromptAPI' | 'VirusTotal';

Expand Down Expand Up @@ -298,7 +297,7 @@ const inSinkingYachts = (u: string) => ch.cache.sinkingYachts.cache.has(cleanURL
const inSpamHaus = async (u: string) => {
const res = await fetch(`https://apibl.spamhaus.net/lookup/v1/dbl/${cleanURL(u)}`, {
headers: {
Authorization: `Bearer ${auth.spamhausToken}`,
Authorization: `Bearer ${process.env.spamhausToken}`,
'Content-Type': 'application/json',
},
});
Expand All @@ -308,7 +307,7 @@ const inSpamHaus = async (u: string) => {

const ageCheck = async (u: string) => {
const res = await fetch(`https://api.promptapi.com/whois/query?domain=${cleanURL(u)}`, {
headers: { apikey: auth.promptAPIToken },
headers: { apikey: process.env.promptAPIToken ?? '' },
});

if (!res.ok) return { triggers: false };
Expand All @@ -331,7 +330,7 @@ const inVT = async (u: string) => {
const urlsRes = await fetch('https://www.virustotal.com/api/v3/urls', {
method: 'POST',
headers: {
'x-apikey': auth.VTtoken,
'x-apikey': process.env.VTToken ?? '',
},
body,
});
Expand All @@ -357,7 +356,7 @@ const getAnalyses = async (
Jobs.scheduleJob(new Date(Date.now() + 5000 * i), async () => {
const res = await fetch(`https://www.virustotal.com/api/v3/analyses/${id}`, {
headers: {
'x-apikey': auth.VTtoken,
'x-apikey': process.env.VTToken ?? '',
},
});
if (!res.ok) return resolve((await res.text()) as string);
Expand Down Expand Up @@ -388,7 +387,9 @@ const getSeverity = (result: VirusVendorsTypings.VirusTotalAnalyses | false) =>

const inGoogleSafeBrowsing = async (u: string) => {
const res = await fetch(
`https://safebrowsing.googleapis.com/v4/threatMatches:find?key=${auth.safeBrowsingToken}`,
`https://safebrowsing.googleapis.com/v4/threatMatches:find?key=${
process.env.safeBrowsingToken ?? ''
}`,
{
method: 'POST',
body: JSON.stringify({
Expand Down Expand Up @@ -429,7 +430,7 @@ const reportFishFish = (u: string) => {
fetch('https://yuri.bots.lostluma.dev/phish/report', {
method: 'POST',
headers: {
authorization: auth.phishToken,
authorization: process.env.phishToken ?? '',
},
body: JSON.stringify({
url: u,
Expand Down Expand Up @@ -477,7 +478,7 @@ const inKaspersky = async (u: string) => {
`https://opentip.kaspersky.com/api/v1/search/domain?request=${cleanURL(u)}`,
{
headers: {
'x-api-key': auth.kasperskyKey,
'x-api-key': process.env.kasperskyToken ?? '',
},
},
);
Expand Down
4 changes: 1 addition & 3 deletions src/Events/messageEvents/messageCreate/commandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import * as stringSimilarity from 'string-similarity';
import client from '../../../BaseClient/Client.js';
import * as ch from '../../../BaseClient/ClientHelper.js';
import * as CT from '../../../Typings/Typings.js';
import auth from '../../../auth.json' assert { type: 'json' };

// eslint-disable-next-line no-console
const { log } = console;

export default async (msg: Discord.Message) => {
Expand Down Expand Up @@ -109,7 +107,7 @@ const guildCommand = async (msg: Discord.Message<true>) => {
}

if (command.thisGuildOnly?.length && command.thisGuildOnly?.includes(msg.guildId)) return;
if (command.type === 'owner' && msg.author.id !== auth.ownerID) return;
if (command.type === 'owner' && msg.author.id !== process.env.ownerID) return;
if (command.dmOnly) return;

const language = await ch.getLanguage(msg.guildId);
Expand Down
5 changes: 2 additions & 3 deletions src/Events/messageEvents/messageCreate/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import fetch from 'node-fetch';
import * as os from 'os';
import util from 'util';
import * as ch from '../../../BaseClient/ClientHelper.js';
import auth from '../../../auth.json' assert { type: 'json' };
import antiraid from '../../guildEvents/guildMemberAdd/antiraid.js';

// eslint-disable-next-line no-unused-expressions
Expand All @@ -15,13 +14,13 @@ os.arch;
// eslint-disable-next-line no-unused-expressions
antiraid;

const reg = new RegExp(auth.token, 'g');
const reg = new RegExp(process.env.Token ?? '', 'g');

// eslint-disable-next-line no-console
const { log } = console;

export default async (msg: Discord.Message<true>) => {
if (msg.author.id !== auth.ownerID) return;
if (msg.author.id !== process.env.ownerID) return;
if (!msg.content.startsWith('eval')) return;

const args = msg.content.split(/\s+/g);
Expand Down
7 changes: 3 additions & 4 deletions src/Events/readyEvents/timedFiles/websiteFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Jobs from 'node-schedule';
import { AutoPoster } from 'topgg-autoposter';
import client from '../../../BaseClient/Client.js';
import * as ch from '../../../BaseClient/ClientHelper.js';
import auth from '../../../auth.json' assert { type: 'json' };

const APIDiscordBotList = 'https://discordbotlist.com/api/v1/bots/650691698409734151/stats';
const APIDiscordBots = 'https://discord.bots.gg/api/v1/bots/650691698409734151/stats';
Expand All @@ -27,7 +26,7 @@ export default async () => {
}),
headers: {
'Content-Type': 'application/json',
Authorization: auth.DBToken,
Authorization: process.env.DBToken ?? '',
},
}).catch(() => null);

Expand All @@ -39,10 +38,10 @@ export default async () => {
}),
headers: {
'Content-Type': 'application/json',
Authorization: auth.DBListToken,
Authorization: process.env.DBListToken ?? '',
},
}).catch(() => null);
});

AutoPoster(auth.topGGtoken, client);
AutoPoster(process.env.topGGtoken ?? '', client);
};
37 changes: 0 additions & 37 deletions src/auth.example.json

This file was deleted.

3 changes: 3 additions & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* eslint-disable no-console */
import DotENV from 'dotenv';
import sms from 'source-map-support';
import client from './BaseClient/Client.js';
import * as ch from './BaseClient/ClientHelper.js';
import { getReady } from './Events/readyEvents/ready.js';

DotENV.config();

sms.install({
handleUncaughtExceptions: process.argv.includes('--debug'),
environment: 'node',
Expand Down
Loading

0 comments on commit 642b278

Please sign in to comment.