1 |
import { TextChannel } from "discord.js"; |
import { TextChannel } from "discord.js"; |
2 |
import { existsSync, readFile, rm } from "fs"; |
import { existsSync, readFile, rm } from "fs"; |
3 |
import { writeFile } from "fs/promises"; |
import { writeFile } from "fs/promises"; |
4 |
|
import path from "path"; |
5 |
import MessageEmbed from "../client/MessageEmbed"; |
import MessageEmbed from "../client/MessageEmbed"; |
6 |
import { fetchEmoji } from "../utils/Emoji"; |
import { fetchEmoji } from "../utils/Emoji"; |
7 |
import Service from "../utils/structures/Service"; |
import Service from "../utils/structures/Service"; |
15 |
} |
} |
16 |
|
|
17 |
export default class StartupManager extends Service { |
export default class StartupManager extends Service { |
18 |
|
lockfile = path.join(process.env.SUDO_PREFIX ?? (__dirname + '/../../'), 'tmp/lock'); |
19 |
|
|
20 |
async createLockFile(data: RestartLockFileData) { |
async createLockFile(data: RestartLockFileData) { |
21 |
await writeFile(`${__dirname}/../../tmp/lock`, JSON.stringify(data)); |
await writeFile(this.lockfile, JSON.stringify(data)); |
22 |
} |
} |
23 |
|
|
24 |
async boot() { |
async boot() { |
25 |
if (existsSync(`${__dirname}/../../tmp/lock`)) { |
if (existsSync(this.lockfile)) { |
26 |
readFile(`${__dirname}/../../tmp/lock`, async (err, data) => { |
readFile(this.lockfile, async (err, data) => { |
27 |
const { date, message_id, channel_id, guild_id } = <RestartLockFileData> await JSON.parse(data.toString()); |
const { date, message_id, channel_id, guild_id } = <RestartLockFileData> await JSON.parse(data.toString()); |
28 |
|
|
29 |
console.warn(yellow('Lockfile detected - ' + new Date(date).toLocaleString())); |
console.warn(yellow('Lockfile detected - ' + new Date(date).toLocaleString())); |
30 |
|
|
31 |
await rm(`${__dirname}/../../tmp/lock`, () => console.log('Lockfile removed')); |
await rm(this.lockfile, () => console.log('Lockfile removed')); |
32 |
|
|
33 |
try { |
try { |
34 |
const guild = await this.client.guilds.fetch(guild_id); |
const guild = await this.client.guilds.fetch(guild_id); |