mirror of
https://github.com/YuzuZensai/Kiroku.git
synced 2026-01-31 14:57:39 +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 = {};
|
let latestReturnData: ReturnData = {};
|
||||||
|
|
||||||
|
function sendJsonResponse(data: any) {
|
||||||
|
return new Response(JSON.stringify(data));
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (!ConfigProvider.isReady()) return;
|
if (!ConfigProvider.isReady()) return;
|
||||||
|
|
||||||
@@ -31,6 +35,7 @@ async function main() {
|
|||||||
let newData: ReturnData = {};
|
let newData: ReturnData = {};
|
||||||
|
|
||||||
for (let [key, value] of Object.entries(ConfigProvider.getConfig().users)) {
|
for (let [key, value] of Object.entries(ConfigProvider.getConfig().users)) {
|
||||||
|
key = key.toLowerCase();
|
||||||
newData[key] = {};
|
newData[key] = {};
|
||||||
|
|
||||||
// Discord
|
// Discord
|
||||||
@@ -74,7 +79,28 @@ async function main() {
|
|||||||
const server = Bun.serve({
|
const server = Bun.serve({
|
||||||
port: 3000,
|
port: 3000,
|
||||||
async fetch(request: Request) {
|
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 {
|
export interface Config {
|
||||||
global: {
|
global: {
|
||||||
|
lookup_all: boolean;
|
||||||
discord_guild_id?: string;
|
discord_guild_id?: string;
|
||||||
discord_bot_token?: string;
|
discord_bot_token?: string;
|
||||||
steam_api_key?: string;
|
steam_api_key?: string;
|
||||||
@@ -14,7 +15,9 @@ export interface Config {
|
|||||||
|
|
||||||
class ConfigProvider {
|
class ConfigProvider {
|
||||||
private config: Config = {
|
private config: Config = {
|
||||||
global: {},
|
global: {
|
||||||
|
lookup_all: false
|
||||||
|
},
|
||||||
users: {}
|
users: {}
|
||||||
};
|
};
|
||||||
private ready = false;
|
private ready = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user