You've already forked discord-bot
mirror of
https://github.com/t2linux/discord-bot.git
synced 2026-04-30 13:49:21 -07:00
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import * as files from 'fs';
|
|
|
|
export interface Entry {
|
|
channel: string;
|
|
emoji: string;
|
|
role: string;
|
|
}
|
|
|
|
export class Data {
|
|
private entries: Array<Entry>;
|
|
|
|
public constructor() {
|
|
if (!files.existsSync('data.json')) {
|
|
files.writeFileSync('data.json', '[]');
|
|
}
|
|
|
|
this.entries = JSON.parse(files.readFileSync('data.json').toString());
|
|
}
|
|
|
|
public hasChannel(channel: string): boolean {
|
|
return this.entries.filter(entry => entry.channel === channel).length !== 0;
|
|
}
|
|
|
|
public getChannel(channel: string): Array<Entry> {
|
|
return this.entries.filter(entry => entry.channel === channel);
|
|
}
|
|
|
|
public hasEmoji(channel: string, emoji: string): boolean {
|
|
return this.entries.filter(entry => entry.channel === channel && entry.emoji === emoji).length !== 0;
|
|
}
|
|
|
|
public getRole(channel: string, emoji: string): string {
|
|
return this.entries.filter(entry => entry.channel === channel && entry.emoji === emoji)[0].role;
|
|
}
|
|
|
|
public removeEmoji(channel: string, emoji: string): void {
|
|
this.entries = this.entries.filter(entry => !(entry.channel === channel && entry.emoji === emoji));
|
|
|
|
files.writeFileSync('data.json', JSON.stringify(this.entries));
|
|
}
|
|
|
|
public get(): Array<Entry> {
|
|
return this.entries;
|
|
}
|
|
|
|
public addEmoji(channel: string, emoji: string, role: string): void {
|
|
this.entries.push({
|
|
channel,
|
|
emoji,
|
|
role
|
|
});
|
|
|
|
files.writeFileSync('data.json', JSON.stringify(this.entries));
|
|
}
|
|
} |