diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..daec5f4 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +KB_USERNAME= +KB_PAPERKEY= +KB_TEAMNAME= diff --git a/.gitignore b/.gitignore index d1ffb78..741e95a 100644 --- a/.gitignore +++ b/.gitignore @@ -125,3 +125,6 @@ dist .yarn/unplugged .yarn/build-state.yml .pnp.* + +launch.json +tasks.json diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..cc5875f --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v10.15.3 diff --git a/README.md b/README.md index 80da332..cb4fd57 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,13 @@ # AgentAvailability -This Keybase bot is used to signal dOrg Agent availability. -Timezones must a valid Moment timezone name. -See examples in the zones properties [here](https://github.com/moment/moment-timezone/blob/develop/data/meta/latest.json). -Noon in the user's local is used as the assumed time of the provided availability date to make timezone conversions more consistent. - -## Example usage +A Keybase bot used to signal dOrg Agent availability. +## Usage +### Get Availability ``` User: /avail get +``` +``` Bot: Availability for user usera: Default: 50% Time Zone: America/New_York @@ -49,6 +48,10 @@ User: /avail set timezone America/New_York Bot: Your time zone has been updated to America/New_York ``` +**NOTE:** Timezones must a valid Moment timezone name. +See examples in the zones properties [here](https://github.com/moment/moment-timezone/blob/develop/data/meta/latest.json). +Noon in the user's local is used as the assumed time of the provided availability date to make timezone conversions more consistent. + ``` User: /avail add 0% 7/10/2020 7/30/2020 Bot: Added availability of 0% for 7/10/2020 7/30/2020 America/Los_Angeles @@ -68,6 +71,45 @@ User: /avail rm 1 Bot: Removed availability of 0% for 3/25/2020 3/27/2020 America/New_York ``` +## Running Locally + +1. Use the proper version of Node & NPM +```base +nvm use $(cat .nvmrc) +``` +2. Install dependencies +```bash +yarn +``` +3. + +## Debugging With VSCode + +Add this file to your `.vscode` folder at the root of the Git repository to debug within Visual Studio Code: + +`launch.json` ([documentation](https://go.microsoft.com/fwlink/?linkid=830387)) + +```json +{ + "configurations": [ + { + "name": "Launch Program", + "program": "${workspaceFolder}//src//output//index.js", + "request": "launch", + "smartStep": true, + "sourceMaps": true, + "type": "node" + } + ], + "version": "3.0.1" +} +``` + +More information on Node.js debugging within VSCode can be found [here](https://code.visualstudio.com/docs/nodejs/nodejs-debugging). + +TODO: building, env, debugging, testing, better examples +TODO review: break apart functionality into separate files, implement all functions + ## Development tasks to do * Add better validation fail messages * Add logging & better error handling @@ -103,72 +145,4 @@ Examples: /avail add 0% 7/10/2020 7/30/2020 ``` * (Optional) Add CI/CD * (Optional) Figure out a simple way to validate keybase usernames: -May need to add the [Go client](https://github.com/keybase/client) to project or implement own [user endpoint call.](https://keybase.io/docs/api/1.0/call/user/lookup) - -## Running locally - -You will need to run yarn install in the `src` folder to get started: - -```bash -yarn install -``` - -## Debugging locally - -Set up these two files in a `.vscode` folder at the root of the Git repository to debug within Visual Studio Code: - -`launch.json` - replace example values in env's nested properties as appropriate - -```json -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "configurations": [ - { - "env": { - "KB_USERNAME": "keybase_username", - "KB_PAPERKEY": "keybase_paperkey", - "KB_TEAMNAME": "keybase_teamname" - }, - "name": "Launch Program", - "outFiles": [ - "${workspaceFolder}/src/output/*.js" - ], - "outputCapture": "std", - "program": "${workspaceFolder}//src//output//index.js", - "request": "launch", - "smartStep": true, - "sourceMaps": true, - "type": "node" - } - ], - "version": "3.0.1" -} -``` - -`tasks.json` - -```json -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "3.0.1", - "tasks": [ - { - "type": "typescript", - "tsconfig": "src\\tsconfig.json", - "option": "watch", - "problemMatcher": [ - "$tsc-watch" - ], - "group": { - "kind": "build", - "isDefault": true - } - } - ] -} -``` - -Then run the build step by pressing `Ctrl+Shift+B`, and any updates will trigger a TypeScript build. Debug by pressing `F5`. \ No newline at end of file +May need to add the [Go client](https://github.com/keybase/client) to project or implement own [user endpoint call.](https://keybase.io/docs/api/1.0/call/user/lookup) \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..428188a --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "@dorgtech/agent-availability-bot", + "version": "1.0.0-alpha.01", + "main": "./dist/index.js", + "scripts": { + "build": "tsc --build ./tsconfig.json" + }, + "dependencies": { + "@types/moment-timezone": "^0.5.13", + "@types/node": "^13.11.1", + "add": "^2.0.6", + "keybase-bot": "^3.6.1", + "moment": "^2.24.0", + "moment-timezone": "^0.5.28" + }, + "devDependencies": { + "typescript": "^3.8.3" + } +} diff --git a/src/index.ts b/src/index.ts index 02a895d..bec367e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ -#!/usr/bin/env node import Bot from 'keybase-bot' import { MsgSummary } from 'keybase-bot/lib/types/chat1' import moment, { Moment } from 'moment' @@ -28,6 +27,7 @@ const nameSpaces = { const paperkey = process.env.KB_PAPERKEY; const teamName = process.env.KB_TEAMNAME; const username = process.env.KB_USERNAME; + // Regex for a valid integer 0-100 followed by a % const workLevelRegex = /^(?:100|[1-9]?[0-9])%{1}$/ diff --git a/src/package.json b/src/package.json deleted file mode 100644 index 5c93aa1..0000000 --- a/src/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "dependencies": { - "@types/moment-timezone": "^0.5.13", - "@types/node": "^13.11.1", - "add": "^2.0.6", - "keybase-bot": "^3.6.1", - "moment": "^2.24.0", - "moment-timezone": "^0.5.28" - } -} diff --git a/src/tsconfig.json b/src/tsconfig.json deleted file mode 100644 index 07d007e..0000000 --- a/src/tsconfig.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "compilerOptions": { - /* Basic Options */ - "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - // "lib": [ "es2015" ], /* Specify library files to be included in the compilation. */ - // "allowJs": true, /* Allow javascript files to be compiled. */ - // "checkJs": true, /* Report errors in .js files. */ - // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - "declaration": true, /* Generates corresponding '.d.ts' file. */ - // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ - "sourceMap": true, /* Generates corresponding '.map' file. */ - // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./output", /* Redirect output structure to the directory. */ - // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - // "composite": true, /* Enable project compilation */ - // "removeComments": true, /* Do not emit comments to output. */ - // "noEmit": true, /* Do not emit outputs. */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - - /* Strict Type-Checking Options */ - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - "strictNullChecks": true, /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ - - /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - - /* Module Resolution Options */ - // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ - // "types": [], /* Type declaration files to be included in compilation. */ - // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - - /* Source Map Options */ - // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - } -} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..180f5eb --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "declaration": true, + "sourceMap": true, + "outDir": "./dist", + "strict": true, + "strictNullChecks": true, + "strictPropertyInitialization": true, + "alwaysStrict": true, + "esModuleInterop": true + } +} diff --git a/src/yarn.lock b/yarn.lock similarity index 92% rename from src/yarn.lock rename to yarn.lock index d6e7837..5c2529e 100644 --- a/src/yarn.lock +++ b/yarn.lock @@ -75,6 +75,11 @@ moment-timezone@^0.5.28: resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b" integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg== +typescript@^3.8.3: + version "3.8.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061" + integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w== + which@1.3.1: version "1.3.1" resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"