feat: presence (#345)

* presence

* from event presence and refactoring

* refine presence api

* add tests and more comments

* sss

---------

Co-authored-by: SrIzan10 <66965250+SrIzan10@users.noreply.github.com>
This commit is contained in:
Jacob Nguyen
2023-12-27 11:11:32 -06:00
committed by GitHub
parent efe49391e8
commit 7458befe8a
10 changed files with 219 additions and 18 deletions

View File

@@ -6,9 +6,19 @@ import assert from 'assert';
import { createRequire } from 'node:module';
import type { ImportPayload, Wrapper } from '../types/core';
import type { Module } from '../types/core-modules';
import { existsSync } from 'fs';
import { fileURLToPath } from 'node:url';
export const shouldHandle = (path: string, fpath: string) => {
const newPath = new URL(fpath+extname(path), path).href;
return {
exists: existsSync(fileURLToPath(newPath)),
path: newPath
}
}
export type ModuleResult<T> = Promise<ImportPayload<T>>;
/**
* Import any module based on the absolute path.
* This can accept four types of exported modules
@@ -66,6 +76,7 @@ const isSkippable = (filename: string) => {
const validExtensions = ['.js', '.cjs', '.mts', '.mjs', '.cts', '.ts', ''];
return filename[0] === '!' || !validExtensions.includes(extname(filename));
};
async function deriveFileInfo(dir: string, file: string) {
const fullPath = join(dir, file);
return {
@@ -74,6 +85,7 @@ async function deriveFileInfo(dir: string, file: string) {
base: basename(file),
};
}
async function* readPaths(dir: string): AsyncGenerator<string> {
try {
const files = await readdir(dir);
@@ -118,6 +130,8 @@ export function loadConfig(wrapper: Wrapper | 'file'): Wrapper {
eventsPath = makePath('events');
console.log('Events path is set to', eventsPath);
}
return {
defaultPrefix: config.defaultPrefix,
commands: commandsPath,