├── .gitignore ├── images ├── icon.png ├── usage.png ├── result.png ├── embedIcon.png └── settingUp.png ├── .vscode ├── extensions.json ├── tasks.json ├── settings.json └── launch.json ├── .vscodeignore ├── src ├── test │ ├── suite │ │ ├── extension.test.ts │ │ └── index.ts │ └── runTest.ts └── extension.ts ├── out ├── test │ ├── runTest.js.map │ ├── suite │ │ ├── extension.test.js.map │ │ ├── extension.test.js │ │ ├── index.js.map │ │ └── index.js │ └── runTest.js ├── extension.js.map └── extension.js ├── .eslintrc.json ├── tsconfig.json ├── LICENSE ├── CHANGELOG.md ├── README.md └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barelyaiden/discode/HEAD/images/icon.png -------------------------------------------------------------------------------- /images/usage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barelyaiden/discode/HEAD/images/usage.png -------------------------------------------------------------------------------- /images/result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barelyaiden/discode/HEAD/images/result.png -------------------------------------------------------------------------------- /images/embedIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barelyaiden/discode/HEAD/images/embedIcon.png -------------------------------------------------------------------------------- /images/settingUp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barelyaiden/discode/HEAD/images/settingUp.png -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "dbaeumer.vscode-eslint" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | out/test/** 4 | 5 | src/** 6 | .gitignore 7 | .yarnrc 8 | vsc-extension-quickstart.md 9 | **/tsconfig.json 10 | **/.eslintrc.json 11 | **/*.map 12 | **/*.ts 13 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // See https://go.microsoft.com/fwlink/?LinkId=733558 2 | // for the documentation about the tasks.json format 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "watch", 9 | "problemMatcher": "$tsc-watch", 10 | "isBackground": true, 11 | "presentation": { 12 | "reveal": "never" 13 | }, 14 | "group": { 15 | "kind": "build", 16 | "isDefault": true 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "out": false // set this to true to hide the "out" folder with the compiled JS files 5 | }, 6 | "search.exclude": { 7 | "out": true // set this to false to include "out" folder in search results 8 | }, 9 | // Turn off tsc task auto detection since we have the necessary tasks as npm scripts 10 | "typescript.tsc.autoDetect": "off" 11 | } -------------------------------------------------------------------------------- /src/test/suite/extension.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert'; 2 | 3 | // You can import and use all API from the 'vscode' module 4 | // as well as import your extension to test it 5 | import * as vscode from 'vscode'; 6 | // import * as myExtension from '../../extension'; 7 | 8 | suite('Extension Test Suite', () => { 9 | vscode.window.showInformationMessage('Start all tests.'); 10 | 11 | test('Sample test', () => { 12 | assert.strictEqual(-1, [1, 2, 3].indexOf(5)); 13 | assert.strictEqual(-1, [1, 2, 3].indexOf(0)); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /out/test/runTest.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"runTest.js","sourceRoot":"","sources":["../../src/test/runTest.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA6B;AAE7B,6CAAuC;AAEvC,SAAe,IAAI;;QAClB,IAAI;YACH,4DAA4D;YAC5D,yCAAyC;YACzC,MAAM,wBAAwB,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAEnE,0BAA0B;YAC1B,iCAAiC;YACjC,MAAM,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;YAEpE,0DAA0D;YAC1D,MAAM,IAAA,sBAAQ,EAAC,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,CAAC,CAAC;SACjE;QAAC,OAAO,GAAG,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;YACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SAChB;IACF,CAAC;CAAA;AAED,IAAI,EAAE,CAAC"} -------------------------------------------------------------------------------- /out/test/suite/extension.test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"extension.test.js","sourceRoot":"","sources":["../../../src/test/suite/extension.test.ts"],"names":[],"mappings":";;AAAA,iCAAiC;AAEjC,0DAA0D;AAC1D,8CAA8C;AAC9C,iCAAiC;AACjC,kDAAkD;AAElD,KAAK,CAAC,sBAAsB,EAAE,GAAG,EAAE;IAClC,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;IAEzD,IAAI,CAAC,aAAa,EAAE,GAAG,EAAE;QACxB,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"} -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "parserOptions": { 5 | "ecmaVersion": 6, 6 | "sourceType": "module" 7 | }, 8 | "plugins": [ 9 | "@typescript-eslint" 10 | ], 11 | "rules": { 12 | "@typescript-eslint/naming-convention": "warn", 13 | "@typescript-eslint/semi": "warn", 14 | "curly": "warn", 15 | "eqeqeq": "warn", 16 | "no-throw-literal": "warn", 17 | "semi": "off" 18 | }, 19 | "ignorePatterns": [ 20 | "out", 21 | "dist", 22 | "**/*.d.ts" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /out/test/suite/extension.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const assert = require("assert"); 4 | // You can import and use all API from the 'vscode' module 5 | // as well as import your extension to test it 6 | const vscode = require("vscode"); 7 | // import * as myExtension from '../../extension'; 8 | suite('Extension Test Suite', () => { 9 | vscode.window.showInformationMessage('Start all tests.'); 10 | test('Sample test', () => { 11 | assert.strictEqual(-1, [1, 2, 3].indexOf(5)); 12 | assert.strictEqual(-1, [1, 2, 3].indexOf(0)); 13 | }); 14 | }); 15 | //# sourceMappingURL=extension.test.js.map -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "outDir": "out", 6 | "lib": [ 7 | "es6" 8 | ], 9 | "sourceMap": true, 10 | "rootDir": "src", 11 | "strict": true /* enable all strict type-checking options */ 12 | /* Additional Checks */ 13 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 14 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 15 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 16 | }, 17 | "exclude": [ 18 | "node_modules", 19 | ".vscode-test" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/test/runTest.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | 3 | import { runTests } from 'vscode-test'; 4 | 5 | async function main() { 6 | try { 7 | // The folder containing the Extension Manifest package.json 8 | // Passed to `--extensionDevelopmentPath` 9 | const extensionDevelopmentPath = path.resolve(__dirname, '../../'); 10 | 11 | // The path to test runner 12 | // Passed to --extensionTestsPath 13 | const extensionTestsPath = path.resolve(__dirname, './suite/index'); 14 | 15 | // Download VS Code, unzip it and run the integration test 16 | await runTests({ extensionDevelopmentPath, extensionTestsPath }); 17 | } catch (err) { 18 | console.error('Failed to run tests'); 19 | process.exit(1); 20 | } 21 | } 22 | 23 | main(); 24 | -------------------------------------------------------------------------------- /src/test/suite/index.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import * as Mocha from 'mocha'; 3 | import * as glob from 'glob'; 4 | 5 | export function run(): Promise { 6 | // Create the mocha test 7 | const mocha = new Mocha({ 8 | ui: 'tdd', 9 | color: true 10 | }); 11 | 12 | const testsRoot = path.resolve(__dirname, '..'); 13 | 14 | return new Promise((c, e) => { 15 | glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { 16 | if (err) { 17 | return e(err); 18 | } 19 | 20 | // Add files to the test suite 21 | files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); 22 | 23 | try { 24 | // Run the mocha test 25 | mocha.run(failures => { 26 | if (failures > 0) { 27 | e(new Error(`${failures} tests failed.`)); 28 | } else { 29 | c(); 30 | } 31 | }); 32 | } catch (err) { 33 | console.error(err); 34 | e(err); 35 | } 36 | }); 37 | }); 38 | } 39 | -------------------------------------------------------------------------------- /out/test/suite/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/test/suite/index.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,+BAA+B;AAC/B,6BAA6B;AAE7B,SAAgB,GAAG;IAClB,wBAAwB;IACxB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC;QACvB,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,IAAI;KACX,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAEhD,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC3B,IAAI,CAAC,eAAe,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACxD,IAAI,GAAG,EAAE;gBACR,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;aACd;YAED,8BAA8B;YAC9B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAE9D,IAAI;gBACH,qBAAqB;gBACrB,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;oBACpB,IAAI,QAAQ,GAAG,CAAC,EAAE;wBACjB,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,QAAQ,gBAAgB,CAAC,CAAC,CAAC;qBAC1C;yBAAM;wBACN,CAAC,EAAE,CAAC;qBACJ;gBACF,CAAC,CAAC,CAAC;aACH;YAAC,OAAO,GAAG,EAAE;gBACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACnB,CAAC,CAAC,GAAG,CAAC,CAAC;aACP;QACF,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC;AAjCD,kBAiCC"} -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Run Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "args": [ 13 | "--extensionDevelopmentPath=${workspaceFolder}" 14 | ], 15 | "outFiles": [ 16 | "${workspaceFolder}/out/**/*.js" 17 | ], 18 | "preLaunchTask": "${defaultBuildTask}" 19 | }, 20 | { 21 | "name": "Extension Tests", 22 | "type": "extensionHost", 23 | "request": "launch", 24 | "args": [ 25 | "--extensionDevelopmentPath=${workspaceFolder}", 26 | "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" 27 | ], 28 | "outFiles": [ 29 | "${workspaceFolder}/out/test/**/*.js" 30 | ], 31 | "preLaunchTask": "${defaultBuildTask}" 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 barelyaiden 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Release 2.0.1 2 | 3 | - Added additional two webhook slots. 4 | - Removed the "Community Projects" section from the README. 5 | 6 | ## Release 2.0.0 7 | 8 | - Major code and file restructuring. 9 | - Re-added support for generating Hastebin links for longer code. 10 | 11 | ## Release 1.1.3 12 | 13 | - Added support for Discord Canary and PTB webhook links. 14 | - Added "Community Projects" section in the README.md file. 15 | 16 | ## Release 1.1.2 17 | 18 | - Removed Hastebin share feature due to outdated and incompatible modules. 19 | - Upped long code length limit to Discord's maximum message length limit (2000 characters). 20 | - Embed now shows the file name above the code. 21 | 22 | ## Release 1.1.1 23 | 24 | - Hotfix for Release 1.1.0 throwing an error when attempting to share code. 25 | 26 | ## Release 1.1.0 27 | 28 | - "Set a Webhook" command's input boxes don't disappear now if window focus is lost. 29 | - Code longer than 1024 characters is now sent through a Hastebin link. 30 | - Unnecessary whitespace is now removed from selection. 31 | - The embed's footer now has Discode's logo. 32 | - Grammatical fixes. 33 | 34 | ## Release 1.0.0 35 | 36 | - Initial release. 37 | -------------------------------------------------------------------------------- /out/test/suite/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.run = void 0; 4 | const path = require("path"); 5 | const Mocha = require("mocha"); 6 | const glob = require("glob"); 7 | function run() { 8 | // Create the mocha test 9 | const mocha = new Mocha({ 10 | ui: 'tdd', 11 | color: true 12 | }); 13 | const testsRoot = path.resolve(__dirname, '..'); 14 | return new Promise((c, e) => { 15 | glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { 16 | if (err) { 17 | return e(err); 18 | } 19 | // Add files to the test suite 20 | files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); 21 | try { 22 | // Run the mocha test 23 | mocha.run(failures => { 24 | if (failures > 0) { 25 | e(new Error(`${failures} tests failed.`)); 26 | } 27 | else { 28 | c(); 29 | } 30 | }); 31 | } 32 | catch (err) { 33 | console.error(err); 34 | e(err); 35 | } 36 | }); 37 | }); 38 | } 39 | exports.run = run; 40 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /out/test/runTest.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | const path = require("path"); 13 | const vscode_test_1 = require("vscode-test"); 14 | function main() { 15 | return __awaiter(this, void 0, void 0, function* () { 16 | try { 17 | // The folder containing the Extension Manifest package.json 18 | // Passed to `--extensionDevelopmentPath` 19 | const extensionDevelopmentPath = path.resolve(__dirname, '../../'); 20 | // The path to test runner 21 | // Passed to --extensionTestsPath 22 | const extensionTestsPath = path.resolve(__dirname, './suite/index'); 23 | // Download VS Code, unzip it and run the integration test 24 | yield (0, vscode_test_1.runTests)({ extensionDevelopmentPath, extensionTestsPath }); 25 | } 26 | catch (err) { 27 | console.error('Failed to run tests'); 28 | process.exit(1); 29 | } 30 | }); 31 | } 32 | main(); 33 | //# sourceMappingURL=runTest.js.map -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Discode 2 | 3 | A Visual Studio Code extension that allows you to share code to Discord with webhooks. 4 | 5 | *[Make sure to join the official Discode Discord server here!](https://discord.gg/Cm3ADqfPpp)* 6 | 7 | ## Usage 8 | 9 | After installing the extension, open up the Command Palette and under "Discode" use the "Set a Webhook" command. 10 | This command can also be used to update an existing webhook, and while you can configure it in the settings it is generally recommended to do so with the command. 11 | 12 | ![settingUp](images/settingUp.png) 13 | 14 | After you're done setting up, all it takes is to select text, right click and press "Share Code to Discord"! 15 | 16 | ![usage](images/usage.png) 17 | 18 | ![result](images/result.png) 19 | 20 | *You can also use the same command through the Command Palette.* 21 | 22 | ## Extension Settings 23 | 24 | This extension contributes the following settings: 25 | 26 | * `discode.webhook`: The webhook the extension uses to share the code to. 27 | * `discode.webhookSecond`: An additional second webhook. 28 | * `discode.webhookThird`: An additional third webhook. 29 | * `discode.name`: The name that gets set as the embed's author. 30 | * `discode.avatar`: The image that gets set as the embed's author's avatar. 31 | 32 | ## Known Issues 33 | 34 | * None so far! 35 | 36 | ## Release Notes 37 | 38 | ### Release 2.0.1 39 | 40 | * Added additional two webhook slots. 41 | * Removed the "Community Projects" section from the README. 42 | 43 | ### Release 2.0.0 44 | 45 | * Major code and file restructuring. 46 | * Re-added support for generating Hastebin links for longer code. 47 | 48 | ### Release 1.1.3 49 | 50 | * Added support for Discord Canary and PTB webhook links. 51 | * Added "Community Projects" section in the README.md file. 52 | 53 | ### Release 1.1.2 54 | 55 | * Removed Hastebin share feature due to outdated and incompatible modules. 56 | * Upped long code length limit to Discord's maximum message length limit (2000 characters). 57 | * Embed now shows the file name above the code. 58 | 59 | ### Release 1.1.1 60 | 61 | * Hotfix for Release 1.1.0 throwing an error when attempting to share code. 62 | 63 | ### Release 1.1.0 64 | 65 | * "Set a Webhook" command's input boxes don't disappear now if window focus is lost. 66 | * Code longer than 1024 characters is now sent through a Hastebin link. 67 | * Unnecessary whitespace is now removed from selection. 68 | * The embed's footer now has Discode's logo. 69 | * Grammatical fixes. 70 | 71 | ### Release 1.0.0 72 | 73 | * Initial release of Discode. 74 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "discode", 3 | "displayName": "Discode", 4 | "description": "A Visual Studio Code extension that allows you to share code to Discord with webhooks.", 5 | "homepage": "https://github.com/barelyaiden/discode/blob/master/README.md", 6 | "icon": "images/icon.png", 7 | "publisher": "evenaven", 8 | "version": "2.0.1", 9 | "bugs": { 10 | "url": "https://github.com/barelyaiden/discode/issues" 11 | }, 12 | "engines": { 13 | "vscode": "^1.60.0" 14 | }, 15 | "categories": [ 16 | "Other" 17 | ], 18 | "keywords": [ 19 | "discord", 20 | "code", 21 | "discode" 22 | ], 23 | "activationEvents": [ 24 | "onCommand:discode.set", 25 | "onCommand:discode.share" 26 | ], 27 | "main": "./out/extension.js", 28 | "contributes": { 29 | "commands": [ 30 | { 31 | "command": "discode.set", 32 | "title": "Set a Webhook", 33 | "category": "Discode" 34 | }, 35 | { 36 | "command": "discode.setSecond", 37 | "title": "Set a Second Webhook", 38 | "category": "Discode" 39 | }, 40 | { 41 | "command": "discode.setThird", 42 | "title": "Set a Third Webhook", 43 | "category": "Discode" 44 | }, 45 | { 46 | "command": "discode.share", 47 | "title": "Share Code to Discord", 48 | "category": "Discode" 49 | }, 50 | { 51 | "command": "discode.shareSecond", 52 | "title": "Share Code to Discord (Second Webhook)", 53 | "category": "Discode" 54 | }, 55 | { 56 | "command": "discode.shareThird", 57 | "title": "Share Code to Discord (Third Webhook)", 58 | "category": "Discode" 59 | } 60 | ], 61 | "menus": { 62 | "commandPalette": [ 63 | { 64 | "command": "discode.share", 65 | "when": "editorHasSelection" 66 | }, 67 | { 68 | "command": "discode.shareSecond", 69 | "when": "editorHasSelection" 70 | }, 71 | { 72 | "command": "discode.shareThird", 73 | "when": "editorHasSelection" 74 | } 75 | ], 76 | "editor/context": [ 77 | { 78 | "when": "editorHasSelection", 79 | "command": "discode.share", 80 | "group": "z_commands" 81 | }, 82 | { 83 | "when": "editorHasSelection", 84 | "command": "discode.shareSecond", 85 | "group": "z_commands" 86 | }, 87 | { 88 | "when": "editorHasSelection", 89 | "command": "discode.shareThird", 90 | "group": "z_commands" 91 | } 92 | ] 93 | }, 94 | "configuration": { 95 | "title": "Discode", 96 | "properties": { 97 | "discode.webhook": { 98 | "type": "string", 99 | "description": "The webhook used to send the code to.\nMake sure to input a valid Discord webhook link." 100 | }, 101 | "discode.webhookSecond": { 102 | "type": "string", 103 | "description": "An additional second webhook." 104 | }, 105 | "discode.webhookThird": { 106 | "type": "string", 107 | "description": "An additional third webhook." 108 | }, 109 | "discode.name": { 110 | "type": "string", 111 | "description": "The name that appears in the embed that gets sent.\nMake sure it's no longer than 32 characters." 112 | }, 113 | "discode.avatar": { 114 | "type": "string", 115 | "description": "The avatar that appears in the embed that gets sent.\nMake sure the image is of a PNG, JPEG or GIF format." 116 | } 117 | } 118 | } 119 | }, 120 | "scripts": { 121 | "vscode:prepublish": "npm run compile", 122 | "compile": "tsc -p ./", 123 | "watch": "tsc -watch -p ./", 124 | "pretest": "npm run compile && npm run lint", 125 | "lint": "eslint src --ext ts", 126 | "test": "node ./out/test/runTest.js" 127 | }, 128 | "devDependencies": { 129 | "@types/glob": "^7.1.3", 130 | "@types/mocha": "^8.2.2", 131 | "@types/node": "14.x", 132 | "@types/vscode": "^1.60.0", 133 | "@typescript-eslint/eslint-plugin": "^4.26.0", 134 | "@typescript-eslint/parser": "^4.26.0", 135 | "eslint": "^7.27.0", 136 | "glob": "^7.1.7", 137 | "mocha": "^8.4.0", 138 | "typescript": "^4.3.2", 139 | "vscode-test": "^1.5.2" 140 | }, 141 | "repository": { 142 | "type": "git", 143 | "url": "https://github.com/barelyaiden/discode.git" 144 | }, 145 | "dependencies": { 146 | "discord-webhook-node": "^1.1.8", 147 | "eol": "^0.9.1", 148 | "hastebin-save": "^1.2.2" 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /out/extension.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAiC;AACjC,2BAA2B;AAC3B,+DAA+D;AAC/D,MAAM,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAE1C,SAAsB,QAAQ,CAAC,OAAgC;;QAC9D,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;QAErE,SAAe,UAAU,CAAC,KAAK,GAAG,CAAC;;gBAClC,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;oBACrD,cAAc,EAAE,IAAI;oBACpB,WAAW,EAAE,qCAAqC;oBAClD,aAAa,EAAE,IAAI,CAAC,EAAE;wBACrB,IAAI,IAAI,GAAG,qH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EAAE;YAC5E,MAAM,UAAU,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC,CAAA,CAAC,CAAC;QAEH,IAAI,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,eAAe,EAAE,GAAQ,EAAE;YACtE,MAAM,SAAS,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC,CAAA,CAAC,CAAC;QAEH,IAAI,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,qBAAqB,EAAE,GAAQ,EAAE;YAClF,MAAM,SAAS,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC,CAAA,CAAC,CAAC;QAEH,IAAI,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,oBAAoB,EAAE,GAAQ,EAAE;YAChF,MAAM,SAAS,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC,CAAA,CAAC,CAAC;QAEH,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACxC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;CAAA;AAxMD,4BAwMC;AAED,SAAgB,UAAU,KAAI,CAAC;AAA/B,gCAA+B"} -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import * as eol from 'eol'; 3 | import { Webhook, MessageBuilder } from 'discord-webhook-node'; 4 | const hastebin = require('hastebin-save'); 5 | 6 | export async function activate(context: vscode.ExtensionContext) { 7 | console.log('The "Discode" extension has been loaded successfully.'); 8 | 9 | async function setWebhook(count = 1) { 10 | const webhookInput = await vscode.window.showInputBox({ 11 | ignoreFocusOut: true, 12 | placeHolder: 'Input a valid Discord webhook link.', 13 | validateInput: text => { 14 | var expr = /(https?):\/\/((?:ptb\.|canary\.)?discord(?:app)?\.com)\/api(?:\/)?(v\d{1,2})?\/webhooks\/(\d{17,19})\/([\w\-]{68})/i; 15 | return expr.test(text) ? null : 'That is not a valid Discord webhook link.'; 16 | } 17 | }); 18 | 19 | if (count === 1) { 20 | const nameInput = await vscode.window.showInputBox({ 21 | ignoreFocusOut: true, 22 | placeHolder: 'Input a name to show in the embed. Make sure it\'s less than 32 characters.', 23 | validateInput: text => { 24 | return text.length <= 32 ? null : 'That name is too long.'; 25 | } 26 | }); 27 | 28 | const avatarInput = await vscode.window.showInputBox({ 29 | ignoreFocusOut: true, 30 | placeHolder: 'Input an image link to show in the embed as the avatar. Supported formats: png, jpg, gif.', 31 | validateInput: text => { 32 | return text.endsWith('png') || text.endsWith('jpeg') || text.endsWith('jpg') || text.endsWith('gif') ? null : 'That format is not supported.'; 33 | } 34 | }); 35 | 36 | if (webhookInput) { 37 | await vscode.workspace.getConfiguration('discode').update('webhook', webhookInput, vscode.ConfigurationTarget.Global); 38 | 39 | if (nameInput) { 40 | await vscode.workspace.getConfiguration('discode').update('name', nameInput, vscode.ConfigurationTarget.Global); 41 | } 42 | 43 | if (avatarInput) { 44 | await vscode.workspace.getConfiguration('discode').update('avatar', avatarInput, vscode.ConfigurationTarget.Global); 45 | } 46 | } 47 | } else { 48 | if (webhookInput) { 49 | switch (count) { 50 | case 2: 51 | await vscode.workspace.getConfiguration('discode').update('webhookSecond', webhookInput, vscode.ConfigurationTarget.Global); 52 | break; 53 | case 3: 54 | await vscode.workspace.getConfiguration('discode').update('webhookThird', webhookInput, vscode.ConfigurationTarget.Global); 55 | break; 56 | } 57 | } 58 | } 59 | 60 | await vscode.window.showInformationMessage('Successfully set a webhook!'); 61 | } 62 | 63 | async function shareCode(count = 1) { 64 | const errorMessage = 'Discode has not been set up! You may be missing a name or avatar. Please use the "Set a Webhook" command through the Command Palette or configure it manually in the settings.'; 65 | 66 | switch (count) { 67 | case 1: 68 | if (!vscode.workspace.getConfiguration('discode').get('webhook') || !vscode.workspace.getConfiguration('discode').get('name')) { 69 | return vscode.window.showErrorMessage(errorMessage); 70 | } 71 | break; 72 | case 2: 73 | if (!vscode.workspace.getConfiguration('discode').get('webhookSecond') || !vscode.workspace.getConfiguration('discode').get('name')) { 74 | return vscode.window.showErrorMessage(errorMessage); 75 | } 76 | break; 77 | 78 | case 3: 79 | if (!vscode.workspace.getConfiguration('discode').get('webhookThird') || !vscode.workspace.getConfiguration('discode').get('name')) { 80 | return vscode.window.showErrorMessage(errorMessage); 81 | } 82 | break; 83 | } 84 | 85 | const editor = vscode.window.activeTextEditor; 86 | 87 | if (editor) { 88 | const document = editor.document; 89 | const selection = editor.selection; 90 | const text = document.getText(selection); 91 | 92 | let currentHook: string; 93 | 94 | switch (count) { 95 | case 1: 96 | currentHook = `${vscode.workspace.getConfiguration('discode').get('webhook')}`; 97 | break; 98 | case 2: 99 | currentHook = `${vscode.workspace.getConfiguration('discode').get('webhookSecond')}`; 100 | break; 101 | case 3: 102 | currentHook = `${vscode.workspace.getConfiguration('discode').get('webhookThird')}`; 103 | break; 104 | } 105 | 106 | const hook = new Webhook({ 107 | url: currentHook!, 108 | retryOnLimit: false 109 | }); 110 | 111 | const whitespaceAmount = text.length - text.trimLeft().length; 112 | const codeLines = eol.split(text); 113 | 114 | let code: string[] = []; 115 | 116 | codeLines.forEach(function(line: string) { 117 | code.push(line.substring(whitespaceAmount)); 118 | }); 119 | 120 | if (`${code}`.length > 2048) { 121 | try { 122 | let hastebinLink : string; 123 | 124 | // @ts-ignore 125 | await hastebin.upload(`${code.join('\n')}`, link => { 126 | hastebinLink = `https://hastebin.com/${link}`; 127 | }); 128 | 129 | vscode.window.showInformationMessage('Please wait...'); 130 | 131 | setTimeout(async function() { 132 | let embed = new MessageBuilder() 133 | .setColor(0x27b5f4) 134 | .setDescription(`**${document.fileName.substring(document.fileName.lastIndexOf('\\') + 1)}**\n${hastebinLink}`) 135 | .setFooter('Sent with Discode from Visual Studio Code', 'https://cdn.discordapp.com/attachments/798580610686779392/798580822641868870/embedIcon.png') 136 | .setTimestamp(); 137 | 138 | if (!vscode.workspace.getConfiguration('discode').get('avatar')) { 139 | embed.setAuthor(`${vscode.workspace.getConfiguration('discode').get('name')}`); 140 | } else { 141 | embed.setAuthor(`${vscode.workspace.getConfiguration('discode').get('name')}`, `${vscode.workspace.getConfiguration('discode').get('avatar')}`); 142 | } 143 | 144 | await hook.send(embed); 145 | 146 | await vscode.window.showInformationMessage('Successfully shared code to Discord!'); 147 | }, 3000); 148 | } catch (error) { 149 | console.log(error); 150 | await vscode.window.showErrorMessage('The webhook configuration is invalid! Please check if everything is correct in the settings or use the "Set a Webhook" command through the Command Palette.'); 151 | } 152 | } else { 153 | try { 154 | let embed = new MessageBuilder() 155 | .setColor(0x27b5f4) 156 | .setDescription(`**${document.fileName.substring(document.fileName.lastIndexOf('\\') + 1)}**\`\`\`${document.languageId}\n${code.join('\n')}\`\`\``) 157 | .setFooter('Sent with Discode from Visual Studio Code', 'https://cdn.discordapp.com/attachments/798580610686779392/798580822641868870/embedIcon.png') 158 | .setTimestamp(); 159 | 160 | if (!vscode.workspace.getConfiguration('discode').get('avatar')) { 161 | embed.setAuthor(`${vscode.workspace.getConfiguration('discode').get('name')}`); 162 | } else { 163 | embed.setAuthor(`${vscode.workspace.getConfiguration('discode').get('name')}`, `${vscode.workspace.getConfiguration('discode').get('avatar')}`); 164 | } 165 | 166 | await hook.send(embed); 167 | 168 | await vscode.window.showInformationMessage('Successfully shared code to Discord!'); 169 | } catch (error) { 170 | console.log(error); 171 | await vscode.window.showErrorMessage('The webhook configuration is invalid! Please check if everything is correct in the settings or use the "Set a Webhook" command through the Command Palette.'); 172 | } 173 | } 174 | } 175 | } 176 | 177 | let set = vscode.commands.registerCommand('discode.set', async() => { 178 | await setWebhook(1); 179 | }); 180 | 181 | let setSecond = vscode.commands.registerCommand('discode.setSecond', async() => { 182 | await setWebhook(2); 183 | }); 184 | let setThird = vscode.commands.registerCommand('discode.setThird', async() => { 185 | await setWebhook(3); 186 | }); 187 | 188 | let share = vscode.commands.registerCommand('discode.share', async() => { 189 | await shareCode(1); 190 | }); 191 | 192 | let shareSecond = vscode.commands.registerCommand('discode.shareSecond', async() => { 193 | await shareCode(2); 194 | }); 195 | 196 | let shareThird = vscode.commands.registerCommand('discode.shareThird', async() => { 197 | await shareCode(3); 198 | }); 199 | 200 | context.subscriptions.push(set); 201 | context.subscriptions.push(setSecond); 202 | context.subscriptions.push(setThird); 203 | context.subscriptions.push(share); 204 | context.subscriptions.push(shareSecond); 205 | context.subscriptions.push(shareThird); 206 | } 207 | 208 | export function deactivate() {} 209 | -------------------------------------------------------------------------------- /out/extension.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | exports.deactivate = exports.activate = void 0; 13 | const vscode = require("vscode"); 14 | const eol = require("eol"); 15 | const discord_webhook_node_1 = require("discord-webhook-node"); 16 | const hastebin = require('hastebin-save'); 17 | function activate(context) { 18 | return __awaiter(this, void 0, void 0, function* () { 19 | console.log('The "Discode" extension has been loaded successfully.'); 20 | function setWebhook(count = 1) { 21 | return __awaiter(this, void 0, void 0, function* () { 22 | const webhookInput = yield vscode.window.showInputBox({ 23 | ignoreFocusOut: true, 24 | placeHolder: 'Input a valid Discord webhook link.', 25 | validateInput: text => { 26 | var expr = /(https?):\/\/((?:ptb\.|canary\.)?discord(?:app)?\.com)\/api(?:\/)?(v\d{1,2})?\/webhooks\/(\d{17,19})\/([\w\-]{68})/i; 27 | return expr.test(text) ? null : 'That is not a valid Discord webhook link.'; 28 | } 29 | }); 30 | if (count === 1) { 31 | const nameInput = yield vscode.window.showInputBox({ 32 | ignoreFocusOut: true, 33 | placeHolder: 'Input a name to show in the embed. Make sure it\'s less than 32 characters.', 34 | validateInput: text => { 35 | return text.length <= 32 ? null : 'That name is too long.'; 36 | } 37 | }); 38 | const avatarInput = yield vscode.window.showInputBox({ 39 | ignoreFocusOut: true, 40 | placeHolder: 'Input an image link to show in the embed as the avatar. Supported formats: png, jpg, gif.', 41 | validateInput: text => { 42 | return text.endsWith('png') || text.endsWith('jpeg') || text.endsWith('jpg') || text.endsWith('gif') ? null : 'That format is not supported.'; 43 | } 44 | }); 45 | if (webhookInput) { 46 | yield vscode.workspace.getConfiguration('discode').update('webhook', webhookInput, vscode.ConfigurationTarget.Global); 47 | if (nameInput) { 48 | yield vscode.workspace.getConfiguration('discode').update('name', nameInput, vscode.ConfigurationTarget.Global); 49 | } 50 | if (avatarInput) { 51 | yield vscode.workspace.getConfiguration('discode').update('avatar', avatarInput, vscode.ConfigurationTarget.Global); 52 | } 53 | } 54 | } 55 | else { 56 | if (webhookInput) { 57 | switch (count) { 58 | case 2: 59 | yield vscode.workspace.getConfiguration('discode').update('webhookSecond', webhookInput, vscode.ConfigurationTarget.Global); 60 | break; 61 | case 3: 62 | yield vscode.workspace.getConfiguration('discode').update('webhookThird', webhookInput, vscode.ConfigurationTarget.Global); 63 | break; 64 | } 65 | } 66 | } 67 | yield vscode.window.showInformationMessage('Successfully set a webhook!'); 68 | }); 69 | } 70 | function shareCode(count = 1) { 71 | return __awaiter(this, void 0, void 0, function* () { 72 | const errorMessage = 'Discode has not been set up! You may be missing a name or avatar. Please use the "Set a Webhook" command through the Command Palette or configure it manually in the settings.'; 73 | switch (count) { 74 | case 1: 75 | if (!vscode.workspace.getConfiguration('discode').get('webhook') || !vscode.workspace.getConfiguration('discode').get('name')) { 76 | return vscode.window.showErrorMessage(errorMessage); 77 | } 78 | break; 79 | case 2: 80 | if (!vscode.workspace.getConfiguration('discode').get('webhookSecond') || !vscode.workspace.getConfiguration('discode').get('name')) { 81 | return vscode.window.showErrorMessage(errorMessage); 82 | } 83 | break; 84 | case 3: 85 | if (!vscode.workspace.getConfiguration('discode').get('webhookThird') || !vscode.workspace.getConfiguration('discode').get('name')) { 86 | return vscode.window.showErrorMessage(errorMessage); 87 | } 88 | break; 89 | } 90 | const editor = vscode.window.activeTextEditor; 91 | if (editor) { 92 | const document = editor.document; 93 | const selection = editor.selection; 94 | const text = document.getText(selection); 95 | let currentHook; 96 | switch (count) { 97 | case 1: 98 | currentHook = `${vscode.workspace.getConfiguration('discode').get('webhook')}`; 99 | break; 100 | case 2: 101 | currentHook = `${vscode.workspace.getConfiguration('discode').get('webhookSecond')}`; 102 | break; 103 | case 3: 104 | currentHook = `${vscode.workspace.getConfiguration('discode').get('webhookThird')}`; 105 | break; 106 | } 107 | const hook = new discord_webhook_node_1.Webhook({ 108 | url: currentHook, 109 | retryOnLimit: false 110 | }); 111 | const whitespaceAmount = text.length - text.trimLeft().length; 112 | const codeLines = eol.split(text); 113 | let code = []; 114 | codeLines.forEach(function (line) { 115 | code.push(line.substring(whitespaceAmount)); 116 | }); 117 | if (`${code}`.length > 2048) { 118 | try { 119 | let hastebinLink; 120 | // @ts-ignore 121 | yield hastebin.upload(`${code.join('\n')}`, link => { 122 | hastebinLink = `https://hastebin.com/${link}`; 123 | }); 124 | vscode.window.showInformationMessage('Please wait...'); 125 | setTimeout(function () { 126 | return __awaiter(this, void 0, void 0, function* () { 127 | let embed = new discord_webhook_node_1.MessageBuilder() 128 | .setColor(0x27b5f4) 129 | .setDescription(`**${document.fileName.substring(document.fileName.lastIndexOf('\\') + 1)}**\n${hastebinLink}`) 130 | .setFooter('Sent with Discode from Visual Studio Code', 'https://cdn.discordapp.com/attachments/798580610686779392/798580822641868870/embedIcon.png') 131 | .setTimestamp(); 132 | if (!vscode.workspace.getConfiguration('discode').get('avatar')) { 133 | embed.setAuthor(`${vscode.workspace.getConfiguration('discode').get('name')}`); 134 | } 135 | else { 136 | embed.setAuthor(`${vscode.workspace.getConfiguration('discode').get('name')}`, `${vscode.workspace.getConfiguration('discode').get('avatar')}`); 137 | } 138 | yield hook.send(embed); 139 | yield vscode.window.showInformationMessage('Successfully shared code to Discord!'); 140 | }); 141 | }, 3000); 142 | } 143 | catch (error) { 144 | console.log(error); 145 | yield vscode.window.showErrorMessage('The webhook configuration is invalid! Please check if everything is correct in the settings or use the "Set a Webhook" command through the Command Palette.'); 146 | } 147 | } 148 | else { 149 | try { 150 | let embed = new discord_webhook_node_1.MessageBuilder() 151 | .setColor(0x27b5f4) 152 | .setDescription(`**${document.fileName.substring(document.fileName.lastIndexOf('\\') + 1)}**\`\`\`${document.languageId}\n${code.join('\n')}\`\`\``) 153 | .setFooter('Sent with Discode from Visual Studio Code', 'https://cdn.discordapp.com/attachments/798580610686779392/798580822641868870/embedIcon.png') 154 | .setTimestamp(); 155 | if (!vscode.workspace.getConfiguration('discode').get('avatar')) { 156 | embed.setAuthor(`${vscode.workspace.getConfiguration('discode').get('name')}`); 157 | } 158 | else { 159 | embed.setAuthor(`${vscode.workspace.getConfiguration('discode').get('name')}`, `${vscode.workspace.getConfiguration('discode').get('avatar')}`); 160 | } 161 | yield hook.send(embed); 162 | yield vscode.window.showInformationMessage('Successfully shared code to Discord!'); 163 | } 164 | catch (error) { 165 | console.log(error); 166 | yield vscode.window.showErrorMessage('The webhook configuration is invalid! Please check if everything is correct in the settings or use the "Set a Webhook" command through the Command Palette.'); 167 | } 168 | } 169 | } 170 | }); 171 | } 172 | let set = vscode.commands.registerCommand('discode.set', () => __awaiter(this, void 0, void 0, function* () { 173 | yield setWebhook(1); 174 | })); 175 | let setSecond = vscode.commands.registerCommand('discode.setSecond', () => __awaiter(this, void 0, void 0, function* () { 176 | yield setWebhook(2); 177 | })); 178 | let setThird = vscode.commands.registerCommand('discode.setThird', () => __awaiter(this, void 0, void 0, function* () { 179 | yield setWebhook(3); 180 | })); 181 | let share = vscode.commands.registerCommand('discode.share', () => __awaiter(this, void 0, void 0, function* () { 182 | yield shareCode(1); 183 | })); 184 | let shareSecond = vscode.commands.registerCommand('discode.shareSecond', () => __awaiter(this, void 0, void 0, function* () { 185 | yield shareCode(2); 186 | })); 187 | let shareThird = vscode.commands.registerCommand('discode.shareThird', () => __awaiter(this, void 0, void 0, function* () { 188 | yield shareCode(3); 189 | })); 190 | context.subscriptions.push(set); 191 | context.subscriptions.push(setSecond); 192 | context.subscriptions.push(setThird); 193 | context.subscriptions.push(share); 194 | context.subscriptions.push(shareSecond); 195 | context.subscriptions.push(shareThird); 196 | }); 197 | } 198 | exports.activate = activate; 199 | function deactivate() { } 200 | exports.deactivate = deactivate; 201 | //# sourceMappingURL=extension.js.map --------------------------------------------------------------------------------