Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
43ebaa7
Add initial design in comments
benefacto Mar 23, 2020
6844ab7
Fix typos
benefacto Mar 23, 2020
b1f4db3
Fix formatting of comment
benefacto Mar 23, 2020
ee0c06e
Move to Typescript
benefacto Mar 28, 2020
becdc60
Fix readme typos
benefacto Mar 28, 2020
137dea8
Fix additional readme typo
benefacto Mar 28, 2020
57d990a
Add example usage to readme
benefacto Mar 28, 2020
568e448
Fix formatting of examples in readme
benefacto Mar 28, 2020
cca4f75
Move examples to top of readme
benefacto Mar 28, 2020
48cae76
Slight refactor, added additional examples to readme
benefacto Mar 28, 2020
7d95f68
Added scaffolding for functionality
benefacto Mar 28, 2020
55b56ee
Added additional scaffolding for functionality
benefacto Mar 28, 2020
e64926e
Implement scaffolding for validation
benefacto Mar 28, 2020
ac1e1f3
Added initial percentage validation logic
benefacto Mar 28, 2020
41d0d8e
Added initial CRUD operations for Keybase keyvalue store
benefacto Apr 4, 2020
5990e53
Add support for CRUD operations on multiple availabilities
benefacto Apr 4, 2020
9b930d1
Improve output formatting
benefacto Apr 4, 2020
8c1f63e
Add date validation
benefacto Apr 11, 2020
a1ed738
Add work level validation regex
benefacto Apr 11, 2020
d75d42a
Added time zone validation
benefacto Apr 11, 2020
8b5d037
Add initial timezone conversion
benefacto Apr 11, 2020
913feb9
Fix bug where dates' timezones are adjusted improperly
benefacto Apr 18, 2020
910f066
Added validation of moment dates
benefacto Apr 18, 2020
ee02255
Initial work-in-progress refactor
benefacto Apr 18, 2020
5724ae0
Got refactor into class working
benefacto May 9, 2020
c046559
Add additional tasks to do and reprioritize a little bit
benefacto May 10, 2020
3c3a706
Work on fixing super class method calls
benefacto May 10, 2020
d3fb082
Fix issues referencing parent class and 'this'
benefacto May 16, 2020
43f3e39
Ensure bot shuts down gracefully
benefacto May 16, 2020
a2da0a0
Move configuration to additional environment variables, reorganize files
benefacto May 16, 2020
2c1e63f
Minor tweaks
benefacto May 16, 2020
946cd20
changes based on feedback
dOrgJelli May 23, 2020
5cc7fc3
changes based on feedback
dOrgJelli May 23, 2020
7559f6b
changes based on feedback
dOrgJelli May 23, 2020
1cc1b85
Merge pull request #3 from dOrgTech/refactor
dOrgJelli May 23, 2020
a627c7e
init
dOrgJelli Apr 20, 2020
b7cd6c6
Resolve conflicts with dev
benefacto May 30, 2020
ee7c906
Add validation of correct Node version
benefacto Jun 6, 2020
57d5720
Load environment variables from .env file using dotenv
benefacto Jun 6, 2020
59d04ac
Add Docker support
benefacto Jul 25, 2020
eb93f3f
Merge pull request #2 from dOrgTech/jelli-edits
benefacto Jul 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
KEYBASE_AGENTAVAILABILITYBOT_USERNAME=keybase_username,
KEYBASE_AGENTAVAILABILITYBOT_PAPERKEY=keybase_paperkey,
KEYBASE_AGENTAVAILABILITYBOT_TEAMNAME=keybase_teamname,
KEYBASE_AGENTAVAILABILITYBOT_COMMANDPREFIX=/avail ,
KEYBASE_AGENTAVAILABILITYBOT_ASSUMEDTIME=12:00,
KEYBASE_AGENTAVAILABILITYBOT_COMMANDVERB_ADD=add,
KEYBASE_AGENTAVAILABILITYBOT_COMMANDVERB_GET=get,
KEYBASE_AGENTAVAILABILITYBOT_COMMANDVERB_SET=set,
KEYBASE_AGENTAVAILABILITYBOT_COMMANDVERB_RM=rm,
KEYBASE_AGENTAVAILABILITYBOT_CONFIGKEY_DEFAULT=default,
KEYBASE_AGENTAVAILABILITYBOT_CONFIGKEY_TIMEZONE=timezone,
KEYBASE_AGENTAVAILABILITYBOT_DATEFORMAT=M/D/YYYY,
KEYBASE_AGENTAVAILABILITYBOT_INPUTDATEFORMAT=M/D/YYYY HH:mm,
KEYBASE_AGENTAVAILABILITYBOT_NAMESPACE_AVAILABILITIES=AgentAvailability.Availabilities,
KEYBASE_AGENTAVAILABILITYBOT_NAMESPACE_DEFAULT=AgentAvailability.DefaultWorkLevels,
KEYBASE_AGENTAVAILABILITYBOT_NAMESPACE_TIMEZONES=AgentAvailability.TimeZones,
15 changes: 14 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
_temp/
.DS_Store
gulp-tsc-tmp-*
.gulp-tsc-tmp-*
output/
*.js
*.js.map
*.d.ts
config.json
!gulpfile.js

# Logs
logs
*.log
Expand Down Expand Up @@ -108,8 +119,10 @@ dist
.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*

# VSCode configuration files
.vscode/*
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v10.16.3
33 changes: 30 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
FROM keybaseio/client:nightly-node

## Install NVM
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN apt-get update && apt-get install -y -q --no-install-recommends \
apt-transport-https \
build-essential \
ca-certificates \
curl \
git \
libssl-dev \
wget \
&& rm -rf /var/lib/apt/lists/*
ENV NVM_DIR /root/.nvm
ENV NODE_VERSION 10.16.3
RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh| bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/v$NODE_VERSION/bin:$PATH

## Setup Keybase bot
RUN mkdir /app && chown keybase:keybase /app
WORKDIR /app
COPY . /app
RUN yarn install
CMD node /app/index.js
COPY . .
COPY src/.env src/.env
RUN yarn install --production=false
RUN npx tsc --project tsconfig.json
CMD node src/output/src/index.js
170 changes: 170 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,171 @@
# AgentAvailability

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
- [3/25/2020 - 3/27/2020] 0%
- [3/28/2020 - 4/28/2020] 50%
- [4/29/2020 - 5/01/2020] 25%
- [5/02/2020 - 5/10/2020] 75%
```

```
User: /avail get usera
Bot: usera has not set their availability
```

```
User: /avail get userb
Bot: Availability for user userb:
Default: 50%
Time Zone: America/New_York
- [3/25/2020 - 3/27/2020] 0%
- [3/28/2020 - 4/28/2020] 50%
- [4/29/2020 - 5/01/2020] 25%
- [5/02/2020 - 5/10/2020] 75%
```

```
User: /avail set default 80%
Bot: Your default availability has been set to 80%
```

```
User: /avail add 0% 7/10/2020 7/30/2020
Bot: Please set your time zone first
```

```
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
```

```
User: /avail rm
Bot: Which availability would you like to remove?
Default: 50%
Time Zone: America/New_York
1. [3/25/2020 - 3/27/2020] 0%
2. [3/28/2020 - 4/28/2020] 50%
3. [4/29/2020 - 5/01/2020] 25%
4. [5/02/2020 - 5/10/2020] 75%
Respond with /avail rm #
User: /avail rm 1
Bot: Removed availability of 0% for 3/25/2020 3/27/2020 America/New_York
```

## Running Locally

1. Create a .env file in the root of the src/ folder, using .env.example as a base and replacing the values of
KEYBASE_AGENTAVAILABILITYBOT_USERNAME, KEYBASE_AGENTAVAILABILITYBOT_PAPERKEY, KEYBASE_AGENTAVAILABILITYBOT_TEAMNAME as appropriate.
2. Use the proper version of Node & NPM
```bash
nvm use
```
3. Install dependencies
```bash
yarn install
```
4. Compile TypeScript into JavaScript
```bash
cd src
npx tsc --project ../tsconfig.json
```
5. Run compiled JavaScript on Node
```bash
node output/src/index.js
```

## Running Locally via Docker

1. Create a .env file in the root of the src/ folder, using .env.example as a base and replacing the values of
KEYBASE_AGENTAVAILABILITYBOT_USERNAME, KEYBASE_AGENTAVAILABILITYBOT_PAPERKEY, KEYBASE_AGENTAVAILABILITYBOT_TEAMNAME as appropriate.
2. Run the following commands in the root of the repository:
```bash
docker build -t "keybase-docker-local" .
sudo docker run --env-file src/.env --rm keybase-docker-local
```

## 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/src/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).

## Tasks to do
* Add build process
* Add debugging
* Add testing
* Add better examples
* Change /avail get to get all users' availability
* Add /avail me for getting your own user's availability
* Add permissions to limit it to to dOrg team
* Setup test users to test multiple users functionality
* Add conversion to a specified time zone, example:
```
User: /avail get userb America/Los_Angeles
Bot: Availability for user userb:
Default: 50%
Time Zone: America/Los_Angeles
- [3/25/2020 - 3/27/2020] 0%
- [3/28/2020 - 4/28/2020] 50%
- [4/29/2020 - 5/01/2020] 25%
- [5/02/2020 - 5/10/2020] 75%
```
Uses specified time zone "America/Los_Angeles" instead of userb's time zone of "America/New_York"
* Add a help verb to display docs for different commands, example:
```
User: /avail help
Bot: Usage: /avail [verb] [parameter1] [parameter2] [parameter3]
Verbs:
get
set
rm
add
```
```
User: /avail help add
Bot: Usage: /avail add [workLevel%] [MM/DD/YYYY] [MM/DD/YYYY]
Examples: /avail add 0% 7/10/2020 7/30/2020
/avail add 50% 7/10/2020
```
* Deploy
* Make proposal to dOrg DAO for bounty completion
* (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)
65 changes: 0 additions & 65 deletions index.js

This file was deleted.

40 changes: 31 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
{
"name": "AgentAvailability",
"version": "1.0.0",
"main": "index.js",
"author": "",
"license": "MIT",
"private": true,
"name": "agent-availability",
"version": "0.0.1",
"main": "/src/output/src/index.js",
"description": "A Keybase bot used to signal dOrg Agent availability.",
"author": {
"email": "[email protected]",
"name": "Ben Walker",
"url": "https://dorg.tech"
},
"scripts": {
"build": "tsc",
"requirements-check": "tsc src/scripts/check_node_version.ts"
},
"dependencies": {
"@types/moment-timezone": "^0.5.13",
"@types/node": "^13.11.1",
"@types/semver": "^7.2.0",
"add": "^2.0.6",
"dotenv": "^8.2.0",
"keybase-bot": "^3.6.1",
"mathjs": "^6.6.1"
}
}
"moment": "^2.26.0",
"moment-timezone": "^0.5.28",
"semver": "^7.3.2"
},
"devDependencies": {
"typescript": "^3.9.2"
},
"engineStrict": true,
"engines": {
"node": "10.16.3"
},
"license": "MIT"
}
Loading