diff --git a/.gitignore b/.gitignore index 1633564..5bc97cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ node_modules/ -config.json auth.json test.js /.idea/ diff --git a/bot.js b/bot.js index 46ad075..67ee7cb 100644 --- a/bot.js +++ b/bot.js @@ -1,4 +1,4 @@ -const logger = require('./src/util/log/log'); +const logger = require('./src/util/ts/log/log'); const client = {test: 'e', config: {logLevel: 1}}; const log = logger(client); log(); \ No newline at end of file diff --git a/src/json/config.json b/src/json/config.json new file mode 100644 index 0000000..f622a86 --- /dev/null +++ b/src/json/config.json @@ -0,0 +1,16 @@ +{ + "log": { + "suffix": ">>", + "defaultLevel": 1, + "colors": { + "error": "", + "warn": "", + "success": "", + "notice": "", + "primary": "", + "secondary": "", + "altprimary": "", + "altsecondary": "" + } + } +} \ No newline at end of file diff --git a/src/util/json/config.json b/src/util/json/config.json new file mode 100644 index 0000000..a765b93 --- /dev/null +++ b/src/util/json/config.json @@ -0,0 +1,16 @@ +{ + "log": { + "suffix": ">>", + "defaultLevel": 1, + "colors": { + "error": "", + "warn": "", + "success": "", + "notice": "", + "primary": "", + "secondary": "", + "altprimary": "", + "altsecondary": "" + } + } +} diff --git a/src/util/log/log.js b/src/util/log/log.js deleted file mode 100644 index b13195d..0000000 --- a/src/util/log/log.js +++ /dev/null @@ -1,5 +0,0 @@ -const getLevel = require('./getlevel'); - -module.exports = client => (message, level, source, color) => { - -}; \ No newline at end of file diff --git a/src/util/log/getlevel.js b/src/util/ts/log/getlevel.ts similarity index 70% rename from src/util/log/getlevel.js rename to src/util/ts/log/getlevel.ts index ea338ca..5e87455 100644 --- a/src/util/log/getlevel.js +++ b/src/util/ts/log/getlevel.ts @@ -1,9 +1,8 @@ -const config = require('../../json/config.json'); -const levels = require('./levels.json'); +import config = require('../../../json/config.json'); +import levels = require('./levels.json'); const validStrings = Object.keys(levels); -const getLevel = (level) => { - console.log(level) +const getLevel = (level: string | number): number => { if (typeof level === 'number') { if (level <= 0) {return 0;} if (level > 3) {return 3;} @@ -12,6 +11,4 @@ const getLevel = (level) => { const levelM = `${level}`.trim().toUpperCase(); return validStrings.includes(levelM) ? levels[levelM] : typeof config.log.defaultLevel === 'number' ? getLevel(config.log.defaultLevel) : 1; } -}; - -module.exports = getLevel; \ No newline at end of file +}; \ No newline at end of file diff --git a/src/util/log/levels.json b/src/util/ts/log/levels.json similarity index 100% rename from src/util/log/levels.json rename to src/util/ts/log/levels.json diff --git a/src/util/ts/log/log.ts b/src/util/ts/log/log.ts new file mode 100644 index 0000000..5649f43 --- /dev/null +++ b/src/util/ts/log/log.ts @@ -0,0 +1,25 @@ +import {Client} from "discord.js"; + +function color() {}; + +export const log = (client: Client) => (log: any | LogOptionsObject = "Test Log", options?: LogOptionsObject) => { + +}; + +export interface LogOptionsObject { + message?: any, + level?: string | number, + source?: string | { + text?: string, + color?: Color + }, + color?: Color, + suffix?: string +} + +export interface ColorObject { + type: "hex" | "default", + color: string +} + +export type Color = string | ColorObject; \ No newline at end of file diff --git a/src/util/log/types.js b/src/util/ts/log/types.ts similarity index 100% rename from src/util/log/types.js rename to src/util/ts/log/types.ts diff --git a/src/util/util/ts/log/getlevel.d.ts b/src/util/util/ts/log/getlevel.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/src/util/util/ts/log/getlevel.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/util/util/ts/log/getlevel.js b/src/util/util/ts/log/getlevel.js new file mode 100644 index 0000000..546d6b9 --- /dev/null +++ b/src/util/util/ts/log/getlevel.js @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const config = require("../../../json/config.json"); +const levels = require("./levels.json"); +const validStrings = Object.keys(levels); +const getLevel = (level) => { + if (typeof level === 'number') { + if (level <= 0) { + return 0; + } + if (level > 3) { + return 3; + } + return Math.floor(level); + } + else { + const levelM = `${level}`.trim().toUpperCase(); + return validStrings.includes(levelM) ? levels[levelM] : typeof config.log.defaultLevel === 'number' ? getLevel(config.log.defaultLevel) : 1; + } +}; diff --git a/src/util/util/ts/log/levels.json b/src/util/util/ts/log/levels.json new file mode 100644 index 0000000..003f413 --- /dev/null +++ b/src/util/util/ts/log/levels.json @@ -0,0 +1,5 @@ +{ + "TOP": 0, + "STANDARD": 1, + "VERBOSE": 2 +} diff --git a/src/util/util/ts/log/log.d.ts b/src/util/util/ts/log/log.d.ts new file mode 100644 index 0000000..3d68c67 --- /dev/null +++ b/src/util/util/ts/log/log.d.ts @@ -0,0 +1,17 @@ +import { Client } from "discord.js"; +export declare const log: (client: Client) => (log?: any | LogOptionsObject, options?: LogOptionsObject) => void; +export interface LogOptionsObject { + message?: any; + level?: string | number; + source?: string | { + text?: string; + color?: Color; + }; + color?: Color; + suffix?: string; +} +export interface ColorObject { + type: "hex" | "default"; + color: string; +} +export declare type Color = string | ColorObject; diff --git a/src/util/util/ts/log/log.js b/src/util/util/ts/log/log.js new file mode 100644 index 0000000..5ee2fef --- /dev/null +++ b/src/util/util/ts/log/log.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.log = void 0; +function color() { } +; +const log = (client) => (log = "Test Log", options) => { +}; +exports.log = log; diff --git a/src/util/util/ts/log/types.d.ts b/src/util/util/ts/log/types.d.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/util/util/ts/log/types.js b/src/util/util/ts/log/types.js new file mode 100644 index 0000000..e69de29