Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from kyranet/dev
Browse files Browse the repository at this point in the history
First Smii release
  • Loading branch information
kyranet authored May 24, 2018
2 parents 96f4bf9 + 514505d commit 10c5024
Show file tree
Hide file tree
Showing 16 changed files with 609 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
config.mjs
*.heapsnapshot
*.log
bwd/
26 changes: 26 additions & 0 deletions config.mjs.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Remove `.example` from the file extension to configure Smii

export const CLIENT_OPTIONS = {
commandEditing: true,
commandLogging: false,
commandMessageLifetime: 200,
consoleEvents: { verbose: true },
customPromptDefaults: { limit: 5 },
messageCacheLifetime: 200,
messageCacheMaxSize: 25,
messageSweepInterval: 100,
prefix: 's.',
presence: { status: 'online', activity: { type: 'LISTENING', name: 'Smii, help' } },
regexPrefix: /smii(,|!)/i,
typing: true,
pieceDefaults: {
commands: { deletable: true },
monitors: { ignoreOthers: false }
}
};

export const TOKEN = '< BOT TOKEN GOES HERE >';
export const SIZES = {
WIDTH: 1500,
HEIGTH: 1500
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
{
"name": "smii",
"version": "0.0.1",
"version": "1.0.0",
"description": "Canvas-Constructor helper bot",
"main": "src/Smii.mjs",
"scripts": {
"test": "eslint src"
"lint": "eslint --fix src",
"pm2:delete": "pm2 delete Smii",
"pm2:logs": "pm2 logs Smii --lines=200",
"pm2:restart": "pm2 restart Smii",
"pm2:start-harmony": "pm2 start src/Smii.mjs --node-args=\"--experimental-modules --harmony --harmony-bigint\" --name=\"Smii\"",
"pm2:start": "pm2 start src/Smii.mjs --node-args=\"--experimental-modules\" --name=\"Smii\"",
"pm2:stop": "pm2 stop Smii",
"start": "node --experimental-modules src/Smii.mjs",
"test": "eslint src",
"update": "npm i"
},
"repository": {
"type": "git",
Expand All @@ -17,6 +26,11 @@
"discord.js",
"klasa"
],
"contributors": [
"kyranet",
"yorkaargh"
],
"private": true,
"author": "kyraNET",
"license": "MIT",
"bugs": {
Expand Down
19 changes: 3 additions & 16 deletions src/Smii.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
import { TOKEN } from '../config.mjs';
import Smii from './lib/Smii';
import { CLIENT_OPTIONS, TOKEN } from '../config.mjs';
import { Smii } from './index';

new Smii({
commandEditing: true,
commandLogging: false,
commandMessageLifetime: 200,
consoleEvents: { verbose: true },
customPromptDefaults: { limit: 5 },
messageCacheLifetime: 200,
messageCacheMaxSize: 25,
messageSweepInterval: 100,
prefix: 's.',
presence: { status: 'online', activity: { type: 'LISTENING', name: 'Smii, help' } },
regexPrefix: /smii(,|!)/i,
typing: true
}).login(TOKEN);
new Smii(CLIENT_OPTIONS).login(TOKEN);
34 changes: 34 additions & 0 deletions src/commands/Admin/update.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Command as KlasaCommand, util } from 'klasa';

export default class Command extends KlasaCommand {

constructor(...args) {
super(...args, {
aliases: ['pull'],
description: 'Update the bot',
guarded: true,
permissionLevel: 10,
usage: '[branch:string]'
});
}

async run(message, [branch = 'master']) {
const pullResponse = await util.exec(`git pull origin ${branch}`);
const response = await message.channel.sendCode('prolog', [pullResponse.stdout, pullResponse.stderr || '✔'].join('\n-=-=-=-\n'));
if (!await this.isCurrentBranch(branch)) {
const switchResponse = await message.channel.send(`Switching to ${branch}...`);
const checkoutResponse = await util.exec(`git checkout ${branch}`);
await switchResponse.edit([checkoutResponse.stdout, checkoutResponse.stderr || '✔'].join('\n-=-=-=-\n'), { code: 'prolog' });
if ('reboot' in message.flags) return this.store.get('reboot').run(message);
} else if (!pullResponse.stdout.includes('Already up-to-date.') && ('reboot' in message.flags)) {
return this.store.get('reboot').run(message);
}
return response;
}

async isCurrentBranch(branch) {
const { stdout } = await util.exec('git symbolic-ref --short HEAD');
return stdout === `refs/heads/${branch}\n` || stdout === `${branch}\n`;
}

}
13 changes: 9 additions & 4 deletions src/commands/Canvas/canvas.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Command } from 'klasa';
import { Command as KlasaCommand, Stopwatch, util as KlasaUtil } from 'klasa';
import { Canvas } from 'canvas-constructor';
import { inspect } from 'util';

export default class extends Command {
export default class Command extends KlasaCommand {

constructor(...args) {
super(...args, {
Expand All @@ -16,12 +17,16 @@ export default class extends Command {
}

async run(message, [code]) {
const sw = new Stopwatch(5);
try {
let output = await this.client.evaluator.parse(code);
sw.stop();
if (output instanceof Canvas) output = await output.toBufferAsync();
return message.channel.sendFile(output, 'output.png');
if (output instanceof Buffer) return message.channel.sendFile(output, 'output.png', `\`✔\` \`⏱ ${sw}\``);
return message.channel.send(`\`✔\` \`⏱ ${sw}\`\n${KlasaUtil.codeBlock('js', inspect(output, false, 0, false))}`);
} catch (error) {
return message.sendCode('', error.toString());
if (sw.running) sw.stop();
throw `\`❌\` \`⏱ ${sw}\`\n${KlasaUtil.codeBlock('', error)}`;
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/index.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import Smii from './lib/Smii';

import Init from './lib/Canvas/Data/Init';
import Argument from './lib/Canvas/Parser/Argument';
import ArgumentParser from './lib/Canvas/Parser/ArgumentParser';
import Evaluator from './lib/Canvas/Parser/Evaluator';
import Method from './lib/Canvas/Parser/Method';
import PropertyMap from './lib/Canvas/Parser/PropertyMap';

import * as Constants from './lib/Canvas/Util/Constants';
import * as Util from './lib/Canvas/Util/Util';
import * as ValidateError from './lib/Canvas/Util/ValidateError';

export {
Smii,

Init,
Argument,
ArgumentParser,
Evaluator,
Method,
PropertyMap,
Constants,
Util,
ValidateError
Expand Down
Loading

0 comments on commit 10c5024

Please sign in to comment.