/[sudobot]/trunk/src/services/StartupManager.ts
ViewVC logotype

Diff of /trunk/src/services/StartupManager.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 226 by rakin, Mon Jul 29 17:29:06 2024 UTC revision 393 by rakin, Mon Jul 29 17:29:59 2024 UTC
# Line 1  Line 1 
1    /**
2    * This file is part of SudoBot.
3    *
4    * Copyright (C) 2021-2022 OSN Inc.
5    *
6    * SudoBot is free software; you can redistribute it and/or modify it
7    * under the terms of the GNU Affero General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10    *
11    * SudoBot is distributed in the hope that it will be useful, but
12    * WITHOUT ANY WARRANTY; without even the implied warranty of
13    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14    * GNU Affero General Public License for more details.
15    *
16    * You should have received a copy of the GNU Affero General Public License
17    * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18    */
19    
20  import { TextChannel } from "discord.js";  import { TextChannel } from "discord.js";
21  import { existsSync, readFile, rm } from "fs";  import { existsSync, readFile, rm } from "fs";
22  import { writeFile } from "fs/promises";  import { writeFile } from "fs/promises";
23  import DiscordClient from "../client/Client";  import path from "path";
24  import MessageEmbed from "../client/MessageEmbed";  import MessageEmbed from "../client/MessageEmbed";
25  import { fetchEmoji } from "../utils/Emoji";  import { fetchEmoji } from "../utils/Emoji";
26  import Service from "../utils/structures/Service";  import Service from "../utils/structures/Service";
27  import { timeProcess, yellow } from "../utils/util";  import { yellow } from "../utils/util";
28    
29  export interface RestartLockFileData {  export interface RestartLockFileData {
30      date: string;      date: string;
# Line 15  export interface RestartLockFileData { Line 34  export interface RestartLockFileData {
34  }  }
35    
36  export default class StartupManager extends Service {  export default class StartupManager extends Service {
37        lockfile = path.join(process.env.SUDO_PREFIX ?? (__dirname + '/../../'), 'tmp/lock');
38    
39      async createLockFile(data: RestartLockFileData) {      async createLockFile(data: RestartLockFileData) {
40          await writeFile(`${__dirname}/../../tmp/lock`, JSON.stringify(data));          await writeFile(this.lockfile, JSON.stringify(data));
41      }      }
42    
43      async boot() {      async boot() {
44          if (existsSync(`${__dirname}/../../tmp/lock`)) {          if (existsSync(this.lockfile)) {
45              readFile(`${__dirname}/../../tmp/lock`, async (err, data) => {              readFile(this.lockfile, async (err, data) => {
46                  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());
47    
48                  console.warn(yellow('Lockfile detected - ' + new Date(date).toLocaleString()));                  console.warn(yellow('Lockfile detected - ' + new Date(date).toLocaleString()));
49    
50                  await rm(`${__dirname}/../../tmp/lock`, () => console.log('Lockfile removed'));                  await rm(this.lockfile, () => console.log('Lockfile removed'));
51    
52                  try {                  try {
53                      const guild = await this.client.guilds.fetch(guild_id);                      const guild = await this.client.guilds.fetch(guild_id);

Legend:
Removed from v.226  
changed lines
  Added in v.393

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26