Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EpokTarren committed Apr 10, 2021
0 parents commit 5e59b19
Show file tree
Hide file tree
Showing 23 changed files with 2,402 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "prettier"],
"ignorePatterns": ["**/*.js", "node_modules/*"],
"rules": {
"linebreak-style": ["off"],
"semi": ["error", "always"],
"prettier/prettier": ["error"],
"@typescript-eslint/no-var-requires": ["off"]
}
}
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2

- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Lint
run: yarn lint

- name: Build
run: yarn build
43 changes: 43 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Documentation

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node_version: '12'
registry-url: 'https://registry.npmjs.org'
- run: yarn install --frozen-lockfile
- run: yarn build

- name: Generate Documentation
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
run: |
cd $GITHUB_WORKSPACE
yarn run docs
git clone "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" temp -b docs
cd temp
rm -rf /collections/_classes/
rm -rf /collections/_interfaces/
mv ../docs/README.md index.md
mv ../docs/modules.md modules.md
mv ../docs/classes collections/_classes/
mv ../docs/interfaces collections/_interfaces/
git add .
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git commit -m "Built documentation for ${GITHUB_SHA}" || true
git push origin docs
21 changes: 21 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node_version: '12'
registry-url: 'https://registry.npmjs.org'
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
docs/
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"singleQuote": true,
"useTabs": true,
"endOfLine": "auto",
"printWidth": 100
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.0.0 - 2020-04-10

Initial release.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 EpokTarren

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# MashuJS
MashuJS is a command handler for [discord.js](https://discord.js.org/#/) written in typescript for [astolto](https://github.com/EpokTarren/astolto).

# Getting started
The client provided is an extension of discord.js [client](https://discord.js.org/#/docs/main/stable/class/Client) that has a handler attached.


```sh
npm install mashujs discord.js
# with yarn
yarn add mashujs discord.js
```

Initialise a client and pass it to a handler
```js
const { Client } = require("mashujs");
const { resolve } = require("path");

const client = new Client({
disableMentions: 'everyone',
dir: resolve(__dirname, 'commands'),
owners: ['your id'],
prefix: 'a;',
enableHelp: true,
errorChannel: 'Some channel id',
});

client.login('your bot token');
```

Simple example command
```js
const { Command } = require('mashujs');

module.exports = new Command({
run: (message, args)=>{
message.channel.send(Math.random() > 0.5 ? 'owo' : 'uwu');
},
name: 'uwu',
description: 'Randomly sends either owo or uwu.',
detailed: 'Randomly sends uwu or owo with a 50/50 chance of either of the two occuring.'
aliases: ['owo'],
category: 'Fun',
hidden: false,
guildOnly: false,
exmaples: [(p)=>`${p}owo`, (p)=>`${p}uwu`]
permissions: ['SEND_MESSAGE'],
botPermissions: ['SEND_MESSAGE'],
});
```

You can set some enviorment variables to change the styling of output
```js
process.env.HELPFOOTER; // Footer text for help command
process.env.HELPFOOTERICON; // Footer icon for help command
process.env.MASHUCOLOR; // Default color for built in commands default "0xff80cc"
process.env.MASHUERRORCOLOR; // Error color for built in error logging default "0xff8080"
```

# Docs generation
Default `.mashurc.json` config can be generated by running
```sh
npx mashujs --new
```
After that edit your config.

## Properties
- `prefix`, Prefix to use when generating examples.
- `input`, Path to command locations.
- `output`, Path to docs folder.
- `readme`, Path to the readme.md for the bot as a whole and will export as index.md.
- `descriptions`, Will include a description beneath the title if one exists in the command categories folder as README.md.
- `descriptionReplacer`, Replace build path with src path to locate README files, ["build", "src"]
- `titles`, Wheter or not to include jekyll titles.
- `permalink`, Wheter or not to include jekyll permalinks.
- `layout`, Jekyll layout for command pages.
- `homeHeader`, Jekyll header options for index.md such as; "layout: home".

# License
MashuJS is licensed under [MIT](./LICENSE).
42 changes: 42 additions & 0 deletions docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const { readdirSync, readFileSync, writeFileSync } = require('fs');
const { resolve } = require('path');

const fixMD = (md) =>
md
.replace(/\.md/g, '/')
.replace(/]\(/g, '](/')
.replace(/\.\.\//g, '')
.replace(/\/README\//g, '/');

function processFiles(path) {
const content = readFileSync(path).toString('utf-8');
const name = content.match(/ [^ ]+\n/)[0].trim();
const dir = path.match(/[^\\/]+(?=[\\/].+\.md)/g).pop();
const header = `---\ntitle: ${name}\nlayout: default\npermalink: /${dir}/${name.toLowerCase()}/\n---\n`;
writeFileSync(path, header + fixMD(content));
}

const classPath = resolve(__dirname, 'docs', 'classes');
readdirSync(classPath)
.map((file) => resolve(classPath, file))
.forEach(processFiles);

const interfacePath = resolve(__dirname, 'docs', 'interfaces');
readdirSync(interfacePath)
.map((file) => resolve(interfacePath, file))
.forEach(processFiles);

const modulePath = resolve(__dirname, 'docs', 'modules.md');
writeFileSync(
modulePath,
'---\ntitle: Modules\npermalink: /modules/\nlayout: default\n---\n' +
fixMD(readFileSync(modulePath).toString('utf-8'))
);

const readmePath = resolve(__dirname, 'docs', 'README.md');
writeFileSync(
readmePath,
'---\ntitle: Home\nlayout: default\n---\n' + fixMD(readFileSync(readmePath).toString())
);

console.log('Docs generated.');
51 changes: 51 additions & 0 deletions mashurc.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "A .mashurc config file",
"description": "A configuration file for MashuJS(https://github.com/EpokTarren/mashu) documentation generation",
"type": "object",
"properties": {
"prefix": {
"description": "Prefix to use when generating examples.",
"type": "string"
},
"input": {
"description": "Path to command locations.",
"type": "string"
},
"output": {
"description": "Path to docs folder.",
"type": "string"
},
"readme": {
"description": "Path to the readme.md for the bot as a whole and will export as index.md.",
"type": "string"
},
"descriptions": {
"description": "Will include a description beneath the title if one exists in the command categories folder as README.md.",
"type": "boolean"
},
"descriptionReplacer": {
"description": "Replace build path with src path to locate README files, [\"build\", \"src\"]",
"type": "array",
"maxItems": 2,
"minItems": 2
},
"titles": {
"description": "Wheter or not to include jekyll titles.",
"type": "boolean"
},
"permalink": {
"description": "Wheter or not to include jekyll permalinks.",
"type": "boolean"
},
"layout": {
"description": "Jekyll layout for command pages.",
"type": "string"
},
"homeHeader": {
"description": "Jekyll header options for index.md such as; \"layout: home\".",
"type": "string"
}
},
"required": ["prefix", "input", "output"]
}
46 changes: 46 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "mashujs",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": "dist/exportDocs.js",
"license": "MIT",
"scripts": {
"build": "tsc && npx prettier --write dist/",
"prepare": "tsc && npx prettier --write dist/",
"docs": "npx typedoc && node docs.js",
"lint": "eslint src"
},
"files": [
"dist/*",
"mashurc.schema.json"
],
"repository": {
"type": "git",
"url": "https://github.com/EpokTarren/mashu.git"
},
"homepage": "https://mashu.tarren.moe/",
"bugs": {
"url": "https://github.com/EpokTarren/mashu/issues",
"email": "[email protected]"
},
"author": {
"name": "Tarren",
"email": "[email protected]",
"url": "http://tarren.moe"
},
"dependencies": {},
"devDependencies": {
"@types/node": "^14.14.37",
"@typescript-eslint/eslint-plugin": "^4.20.0",
"@typescript-eslint/parser": "^4.20.0",
"discord.js": "^12.5.3",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"prettier": "^2.2.1",
"typedoc": "^0.20.35",
"typedoc-plugin-markdown": "^3.6.1",
"typescript": "^4.2.3"
}
}
17 changes: 17 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as Discord from 'discord.js';
import { Handler, HandlerOptions } from './handler';

export type ClientOptions = Discord.ClientOptions & HandlerOptions;

export class Client extends Discord.Client {
readonly handler: Handler;

constructor(options: ClientOptions) {
super(options);
this.handler = new Handler(options, this);
}
}

export interface Message extends Discord.Message {
client: Client;
}
Loading

0 comments on commit 5e59b19

Please sign in to comment.