Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // dash.ts: https://github.com/y21/dash/blob/master/wasm/frontend/dash.ts
- import { Engine } from './dash';
- const commands = new discord.command.CommandGroup({
- defaultPrefix: '..'
- });
- function removeCodeblock(code: string): string {
- return code.replace(/^```\w*|```$/g, '');
- }
- function codeblock(language: string, code: string) {
- return '```' + language + '\n' + code.substr(0, 1900) + '\n```';
- }
- const engine = new Engine();
- const WASM_URL = 'http://dash.y21_.repl.co/wasm/v3';
- discord.on(discord.Event.MESSAGE_CREATE, async (message) => {
- // initialize js engine if it's not yet ready
- if (!engine.initialized) {
- await engine.init(WASM_URL);
- }
- });
- async function handleEval(
- message: discord.GuildMemberMessage,
- { code }: { code: string }
- ) {
- code = removeCodeblock(code);
- let result;
- let before = await pylon.getCpuTime();
- try {
- result = engine.eval(code);
- } catch (e) {
- result = e.message;
- }
- let now = await pylon.getCpuTime();
- message.reply({
- content: (now - before).toFixed(2) + ' ms' + codeblock('js', result),
- allowedMentions: {}
- });
- }
- const dashGroup = commands.subcommandGroup({
- name: 'eval2'
- });
- dashGroup.default(
- (args) => ({
- code: args.text()
- }),
- handleEval
- );
- dashGroup.on(
- 'run',
- (args) => ({
- code: args.text()
- }),
- handleEval
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement