1 |
import { Guild } from "discord.js"; |
2 |
import DiscordClient from "../client/Client"; |
3 |
|
4 |
export default class History { |
5 |
static get(user_id: string | number, guild: Guild, callback?: (data: any) => void) { |
6 |
DiscordClient.client.db.all('SELECT * FROM history WHERE guild_id = ? AND user_id = ? ORDER BY id DESC', [guild.id, user_id], (err: any, data: any) => { |
7 |
if (err) { |
8 |
console.log(err); |
9 |
} |
10 |
|
11 |
callback !== undefined ? callback(data) : undefined; |
12 |
}); |
13 |
} |
14 |
|
15 |
static create(user_id: string | number, guild: Guild, type: string, mod: string | number, reason: string | null, callback?: (data: any) => void) { |
16 |
DiscordClient.client.db.get('INSERT INTO history(type, user_id, guild_id, date, mod_id, reason) VALUES(?, ?, ?, ?, ?, ?)', [type, user_id, guild.id, new Date().toISOString(), mod, reason], (err: any) => { |
17 |
if (err) { |
18 |
console.log(err); |
19 |
} |
20 |
|
21 |
DiscordClient.client.db.get("SELECT * FROM history WHERE type = ? AND user_id = ? AND guild_id = ? ORDER BY id DESC LIMIT 0, 1", [type, user_id, guild.id], (err: any, data: any) => { |
22 |
if (err) { |
23 |
console.log(err); |
24 |
} |
25 |
|
26 |
callback !== undefined ? callback(data) : undefined; |
27 |
}); |
28 |
}); |
29 |
} |
30 |
}; |