-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc8306e
commit 2a3d3ad
Showing
25 changed files
with
131 additions
and
90 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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import {ApplicationCommandOption, ApplicationCommandTypes} from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { Discord } from "../discord.ts"; | ||
import { Logger } from "../../logging/logger.ts"; | ||
import { isTs } from "../../util/is-ts.ts"; | ||
import { folderExists } from "../../util/folder-exists.ts"; | ||
import { Inflector } from "../../util/inflector.ts"; | ||
import { File } from "../../filesystem/file.ts"; | ||
import { Folder } from "../../filesystem/folder.ts"; | ||
import { Inflector } from "../../utility/inflector.ts"; | ||
|
||
export interface InteractionConfig { | ||
name: string; | ||
|
@@ -14,6 +14,7 @@ export interface InteractionConfig { | |
} | ||
|
||
export class InteractionDispatcher { | ||
private static _interactionsDir = `${Deno.cwd()}/src/interactions`; | ||
private static list: InteractionConfig[] = []; | ||
private static handlers: any = {}; | ||
|
||
|
@@ -57,7 +58,7 @@ export class InteractionDispatcher { | |
public static async add(interaction: InteractionConfig): Promise<void> { | ||
try { | ||
// Import the interaction handler | ||
InteractionDispatcher.handlers[interaction.handler] = await import(`file://${Deno.cwd()}/src/interactions/${interaction.handler}.ts`) | ||
InteractionDispatcher.handlers[interaction.handler] = await import(`file://${InteractionDispatcher._interactionsDir}/${interaction.handler}.ts`) | ||
} catch(e) { | ||
Logger.error(`Could not register interaction handler for "${interaction}": ${e.message}`); | ||
return; | ||
|
@@ -98,29 +99,28 @@ export class InteractionDispatcher { | |
*/ | ||
public static async load(): Promise<void> { | ||
// Create our directory string | ||
const dir = `${Deno.cwd()}/src/interactions`; | ||
Logger.debug(`Loading interactions from "${dir}"...`); | ||
Logger.debug(`Loading interactions from "${InteractionDispatcher._interactionsDir}"...`); | ||
|
||
// Make sure the interactions directory exists | ||
if(!folderExists(dir)) { | ||
Logger.warning(`"${dir}" does not exist, no interactions to load`); | ||
if(!await new Folder(InteractionDispatcher._interactionsDir).exists()) { | ||
Logger.warning(`"${InteractionDispatcher._interactionsDir}" does not exist, no interactions to load`); | ||
return; | ||
} | ||
|
||
// Get a list of all files | ||
const files = await Deno.readDir(dir); | ||
const files = await Deno.readDir(InteractionDispatcher._interactionsDir); | ||
|
||
// Load all interactions | ||
const promiseQueue: Promise<void>[] = []; | ||
for await(const file of files) { | ||
if(!isTs(file.name)) { | ||
if(new File(`${InteractionDispatcher._interactionsDir}/${file.name}`).ext() === 'ts') { | ||
Logger.debug(`File "${file.name}" is not a TS file, skipping...`); | ||
continue; | ||
} | ||
|
||
// Import each file as a module | ||
Logger.debug(`Loading "${file.name}"...`); | ||
const module = await import(`file:///${dir}/${file.name}`); | ||
const module = await import(`file:///${InteractionDispatcher._interactionsDir}/${file.name}`); | ||
|
||
// Make sure module has a "config" exposed | ||
if(!('config' in module)) { | ||
|
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,30 @@ | ||
export class File { | ||
public constructor( | ||
private readonly path: string | ||
) { | ||
} | ||
|
||
public async create(): Promise<void> { | ||
await Deno.create(this.path); | ||
} | ||
|
||
public async exists(): Promise<boolean> { | ||
try { | ||
const target = await Deno.stat(this.path); | ||
return target.isFile; | ||
} catch(e) { | ||
if(e instanceof Deno.errors.NotFound) return false; | ||
throw e; | ||
} | ||
} | ||
|
||
public async delete(): Promise<void> { | ||
await Deno.remove(this.path); | ||
} | ||
|
||
public ext(): string { | ||
const pos = this.path.lastIndexOf("."); | ||
if(pos < 1) return ''; | ||
return this.path.slice(pos + 1); | ||
} | ||
} |
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,16 @@ | ||
export class Folder { | ||
public constructor( | ||
private readonly path: string | ||
) { | ||
} | ||
|
||
public async exists(): Promise<boolean> { | ||
try { | ||
const target = await Deno.stat(this.path); | ||
return target.isDirectory; | ||
} catch(e) { | ||
if(e instanceof Deno.errors.NotFound) return false; | ||
throw e; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Time } from "../common/time.ts"; | ||
import { Configure } from "../common/configure.ts"; | ||
import { Time } from "../utility/time.ts"; | ||
import { Configure } from "../core/configure.ts"; | ||
import { cyan, yellow, red, magenta, bold } from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
|
||
export class Logger { | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { Configure } from "../../common/configure.ts"; | ||
import { Configure } from "../../core/configure.ts"; | ||
|
||
Deno.test("Configure Test", async (t) => { | ||
// Add a test variable and test against it | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Inflector } from "../../util/inflector.ts"; | ||
import { Inflector } from "../../utility/inflector.ts"; | ||
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
|
||
Deno.test("Inflector Test", async (t) => { | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
File renamed without changes.
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.