mirror of
https://github.com/YuzuZensai/Kiroku.git
synced 2026-09-13 18:59:14 +00:00
First releases
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import fs from 'fs';
|
||||
import { Client, Events, GatewayIntentBits } from 'discord.js';
|
||||
|
||||
export interface Config {
|
||||
global: {
|
||||
discord_guild_id?: string;
|
||||
discord_bot_token?: string;
|
||||
steam_api_key?: string;
|
||||
};
|
||||
users: {
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
class ConfigProvider {
|
||||
private config: Config = {
|
||||
global: {},
|
||||
users: {}
|
||||
};
|
||||
private ready = false;
|
||||
|
||||
constructor() {
|
||||
try {
|
||||
let data = fs.readFileSync('./config.json', 'utf8');
|
||||
this.config = JSON.parse(data);
|
||||
this.ready = true;
|
||||
} catch (err) {
|
||||
console.error('[ConfigProvider]', err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public getConfig(): Config {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public isReady(): boolean {
|
||||
return this.ready;
|
||||
}
|
||||
}
|
||||
|
||||
export default new ConfigProvider();
|
||||
@@ -0,0 +1,50 @@
|
||||
import { Client, Events, GatewayIntentBits } from 'discord.js';
|
||||
|
||||
import ConfigProvider from './ConfigProvider';
|
||||
|
||||
class DiscordProvider {
|
||||
private client: Client;
|
||||
private guildId: string = '';
|
||||
private ready: boolean = false;
|
||||
|
||||
constructor() {
|
||||
this.client = new Client({
|
||||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildPresences]
|
||||
});
|
||||
|
||||
this.client.once(Events.ClientReady, (client) => {
|
||||
console.log('[DiscordProvider]', `Ready! Logged in as ${client.user.tag}`);
|
||||
this.ready = true;
|
||||
});
|
||||
|
||||
const token = ConfigProvider.getConfig().global.discord_bot_token;
|
||||
const guild_id = ConfigProvider.getConfig().global.discord_guild_id;
|
||||
|
||||
if (!token || !guild_id) {
|
||||
console.error('[DiscordProvider]', 'Missing token or guild_id in config.json');
|
||||
return;
|
||||
}
|
||||
|
||||
this.guildId = guild_id;
|
||||
|
||||
this.client.login(token);
|
||||
}
|
||||
|
||||
public async getUser(id: string) {
|
||||
const user = this.client.users.cache.get(id) || (await this.client.users.fetch(id));
|
||||
return user;
|
||||
}
|
||||
|
||||
public async getPresence(id: string) {
|
||||
const guild = this.client.guilds.cache.get(this.guildId) || (await this.client.guilds.fetch(this.guildId));
|
||||
const member = guild.members.cache.get(id) || (await guild.members.fetch(id));
|
||||
const presence = member.presence;
|
||||
return presence;
|
||||
}
|
||||
|
||||
public get isReady(): boolean {
|
||||
return this.ready;
|
||||
}
|
||||
}
|
||||
|
||||
export default new DiscordProvider();
|
||||
@@ -0,0 +1,32 @@
|
||||
import SteamAPI from 'steamapi';
|
||||
|
||||
import ConfigProvider from './ConfigProvider';
|
||||
|
||||
class SteamProvider {
|
||||
private client: SteamAPI;
|
||||
private ready: boolean = false;
|
||||
|
||||
constructor() {
|
||||
this.client = new SteamAPI('dummy');
|
||||
const token = ConfigProvider.getConfig().global.steam_api_key;
|
||||
|
||||
if (!token) {
|
||||
console.error('[SteamProvider]', 'Missing steam_api_key in config');
|
||||
return;
|
||||
}
|
||||
|
||||
this.client = new SteamAPI(token);
|
||||
this.ready = true;
|
||||
}
|
||||
|
||||
public async getProfile(id: string) {
|
||||
let profile = await this.client.getUserSummary(id);
|
||||
return profile;
|
||||
}
|
||||
|
||||
public get isReady(): boolean {
|
||||
return this.ready;
|
||||
}
|
||||
}
|
||||
|
||||
export default new SteamProvider();
|
||||
Reference in New Issue
Block a user