mirror of
https://github.com/YuzuZensai/Kiroku.git
synced 2026-01-06 04:33:18 +00:00
All and specify lookup
This commit is contained in:
28
src/index.ts
28
src/index.ts
@@ -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
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user