All and specify lookup

This commit is contained in:
2023-09-20 14:55:06 +07:00
parent 668738e5e7
commit 817f27b85b
2 changed files with 31 additions and 2 deletions

View File

@@ -24,6 +24,10 @@ interface ReturnData {
let latestReturnData: ReturnData = {};
function sendJsonResponse(data: any) {
return new Response(JSON.stringify(data));
}
async function main() {
if (!ConfigProvider.isReady()) return;
@@ -31,6 +35,7 @@ async function main() {
let newData: ReturnData = {};
for (let [key, value] of Object.entries(ConfigProvider.getConfig().users)) {
key = key.toLowerCase();
newData[key] = {};
// Discord
@@ -74,7 +79,28 @@ async function main() {
const server = Bun.serve({
port: 3000,
async fetch(request: Request) {
return new Response(JSON.stringify(latestReturnData));
let url = new URL(request.url);
let user = url.searchParams.get('user');
if (!user || user === null) {
if (!ConfigProvider.getConfig().global.lookup_all)
return sendJsonResponse({ success: false, message: 'Lookup all is disabled' });
return sendJsonResponse({
success: true,
data: latestReturnData
});
}
user = user.toLowerCase();
if (!latestReturnData[user]) return sendJsonResponse({ success: false, message: 'Unable to find user' });
const userData = latestReturnData[user];
return sendJsonResponse({
success: true,
data: userData
});
}
});

View File

@@ -3,6 +3,7 @@ import { Client, Events, GatewayIntentBits } from 'discord.js';
export interface Config {
global: {
lookup_all: boolean;
discord_guild_id?: string;
discord_bot_token?: string;
steam_api_key?: string;
@@ -14,7 +15,9 @@ export interface Config {
class ConfigProvider {
private config: Config = {
global: {},
global: {
lookup_all: false
},
users: {}
};
private ready = false;