This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from takejohn/feature/75-loki
LokiJS 対応 (#75)
- Loading branch information
Showing
29 changed files
with
734 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,3 +133,6 @@ dist | |
|
||
# Font file | ||
*.ttf | ||
|
||
# LokiJS database file | ||
database.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Client } from 'discord.js'; | ||
|
||
/** | ||
* 機能の1単位を表すオブジェクト | ||
*/ | ||
export abstract class Feature { | ||
private loading = false; | ||
|
||
private unloading = false; | ||
|
||
async load(client: Client<boolean>) { | ||
if (!this.loading) { | ||
this.loading = true; | ||
const dependencies = this.dependencies; | ||
// この機能をロードする前に依存先の機能をロードする | ||
if (dependencies != null) { | ||
await Promise.all( | ||
dependencies.map((dependency) => { | ||
dependency.usedBy.push(this); | ||
return dependency.load(client); | ||
}), | ||
); | ||
} | ||
console.log(`Loading ${this.name} feature`); | ||
await this.onLoad(client); | ||
} | ||
} | ||
|
||
async unload() { | ||
if (!this.unloading) { | ||
this.unloading = true; | ||
// 依存元の機能をアンロードした後にこの機能をアンロードする | ||
await Promise.all(this.usedBy.map((dependency) => dependency.unload())); | ||
console.log(`Unloading ${this.name} feature`); | ||
await this.onUnload(); | ||
} | ||
} | ||
|
||
name: string; | ||
|
||
/** | ||
* この機能の依存先の機能 | ||
*/ | ||
dependencies?: Feature[]; | ||
|
||
private usedBy: Feature[] = []; | ||
|
||
/** | ||
* 読み込まれた時の処理 | ||
*/ | ||
onLoad(client: Client<boolean>): PromiseLike<void> | void { | ||
// デフォルトでは何もしない | ||
} | ||
|
||
/** | ||
* クライアントにログインしたときの処理 | ||
*/ | ||
onClientReady(client: Client<true>): PromiseLike<void> | void { | ||
// デフォルトでは何もしない | ||
} | ||
|
||
/** | ||
* 終了したときの処理 | ||
*/ | ||
onUnload(): PromiseLike<void> | void { | ||
// デフォルトでは何もしない | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.