Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
dOrgJelli committed Apr 20, 2020
1 parent 910f066 commit b4de093
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 145 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
KB_USERNAME=
KB_PAPERKEY=
KB_TEAMNAME=
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ dist
.yarn/unplugged
.yarn/build-state.yml
.pnp.*

launch.json
tasks.json
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v10.15.3
124 changes: 49 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`.
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)
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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}$/

Expand Down
10 changes: 0 additions & 10 deletions src/package.json

This file was deleted.

59 changes: 0 additions & 59 deletions src/tsconfig.json

This file was deleted.

14 changes: 14 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}
5 changes: 5 additions & 0 deletions src/yarn.lock → yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==

[email protected]:
version "1.3.1"
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
Expand Down

0 comments on commit b4de093

Please sign in to comment.