-
Notifications
You must be signed in to change notification settings - Fork 0
keybase-bot monkeypatch #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ index.js | |
| scratchpad.js | ||
| deploy/docker-compose.yaml | ||
| node_modules/ | ||
| .env | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,28 +2,43 @@ | |
|
|
||
| ## Getting started | ||
|
|
||
| 1. `npm install` | ||
| 2. `npm install -g ts-node --save` | ||
| 3. Create two paperkeys within Keybase for your bot (click the Devices tab within the Keybase GUI). | ||
| 1. Create two bot accounts (one to use `/flip` and the other to read the result) | ||
| - Note: the bot with `DEV_CROUPIER_USERNAME1` is the Main bot | ||
| 2. Create two paperkeys within Keybase for your bots (click the Devices tab within the Keybase GUI). | ||
| 3. `npm install` | ||
| 4. Set these envvars: | ||
|
|
||
| * `CROUPIER_PAPERKEY_1` | ||
| * `CROUPIER_PAPERKEY_2` | ||
| * `MONGODB_USERNAME` | ||
| * `MONGODB_PASSWORD` | ||
| * `MONGODB_HOST` | ||
| - `DEV_CROUPIER_USERNAME1` | ||
| - `DEV_CROUPIER_USERNAME2` | ||
| - `DEV_CROUPIER_PAPERKEY1` | ||
| - `DEV_CROUPIER_PAPERKEY2` | ||
| - `MONGODB_USERNAME` | ||
| - `MONGODB_PASSWORD` | ||
| - `MONGODB_HOST` | ||
| - `IS_CLUSTER` (true or false) | ||
|
|
||
| 5. Run the bot with `ts-node index.ts` | ||
| 5. Verify you have an instance of Mongo running somewhere | ||
| 6. `npm run start` | ||
|
|
||
| ### Requirements | ||
|
|
||
| - MongoDB (if you're running the bot locally) | ||
| - Unix/Linux Server - Croupier relies on non-Windows commands (namely `which`) | ||
| - `expect` command (`apt-get install expect`) | ||
| - Some Lumens to fund the bot accounts (Main bot needs at least 1XLM to function) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Main bot needs at least 2.01XLM |
||
|
|
||
| ## Contributing | ||
|
|
||
| Contributions are welcome. Any new features should be accompanied by a test. To run the test suite, `yarn test --detectOpenHandles --verbose --forceExit` | ||
| Contributions are welcome. Any new features should be accompanied by a test. To run the test suite, `yarn test --detectOpenHandles --verbose --forceExit` | ||
|
|
||
| Note: run `killall keybase` and `keybase ctl stop` before running test suite | ||
|
|
||
| ## Releases | ||
| ### All releases should more or less be stable. | ||
|
|
||
| * [Release v1](https://blog.codefor.cash/2019/07/01/finding-alice-and-bob-in-wonderland-a-writeup-of-croupier-the-keybase-bot/) | ||
| All releases should more or less be stable. | ||
|
|
||
| - [Release v1](https://blog.codefor.cash/2019/07/01/finding-alice-and-bob-in-wonderland-a-writeup-of-croupier-the-keybase-bot/) | ||
|
|
||
| The next release is a work in progress and is expected some time in July. | ||
|
|
||
| The next release is a work in progress and is expected some time in July. Join [@codeforcash](https://keybase.io/team/codeforcash) or [@mkbot#test3](https://keybase.io/team/mkbot#test3) on Keybase if you'd like to follow along. | ||
| Join [@codeforcash](https://keybase.io/team/codeforcash) or [@mkbot#test3](https://keybase.io/team/mkbot#test3) on Keybase if you'd like to follow along. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,25 +4,29 @@ import * as moment from "moment"; | |
| import * as mongodb from "mongodb"; | ||
| import * as os from "os"; | ||
| import * as throttledQueue from "throttled-queue"; | ||
| import * as Bot from "./keybase-bot"; | ||
| // @ts-ignore | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a lot of these @ts-ignore comments. They seem to be cluttering the code now – is there a deeper fix? |
||
| import * as Bot from "keybase-bot"; | ||
| import Snipe from "./snipe"; | ||
|
|
||
| import { ChatChannel, MessageSummary, Transaction } from "./keybase-bot"; | ||
| // @ts-ignore | ||
| import { ChatChannel, MessageSummary, Transaction } from "keybase-bot"; | ||
| import { IBetData, IBetList, IParticipant, IPopularityContest, IPositionSize, IPowerup, IPowerupAward, IReactionContent } from "./types"; | ||
|
|
||
| class Croupier { | ||
| public activeSnipes: object; | ||
| public bot1: Bot; | ||
| public bot2: Bot; | ||
| public botUsername: string; | ||
| public botUsername1: string; | ||
| public botUsername2: string; | ||
| public paperKey1: string; | ||
| public paperKey2: string; | ||
|
|
||
| private mongoDbUri: string; | ||
| private mongoDbClient: mongodb.MongoClient; | ||
|
|
||
| public constructor( | ||
| botUsername: string, | ||
| botUsername1: string, | ||
| botUsername2: string, | ||
| paperKey1: string, | ||
| paperKey2: string, | ||
| mongoDbUsername: string, | ||
|
|
@@ -46,28 +50,35 @@ class Croupier { | |
| } else { | ||
| uri = "mongodb://"; | ||
| } | ||
| uri += `${mongoDbUsername}:${mongoDbPassword}@${mongoDbHost}`; | ||
| if (mongoDbUsername === "" && mongoDbPassword === "") { | ||
| uri += `${mongoDbHost}`; | ||
| } else { | ||
| uri += `${mongoDbUsername}:${mongoDbPassword}@${mongoDbHost}` | ||
| } | ||
| uri += `/${mongoDbDatabase}?retryWrites=true&w=majority`; | ||
|
|
||
| this.mongoDbUri = uri; | ||
|
|
||
| console.log(uri); | ||
| this.botUsername = botUsername; | ||
| this.botUsername1 = botUsername1; | ||
| this.botUsername2 = botUsername2; | ||
|
|
||
| // @ts-ignore | ||
| this.bot1 = new Bot(os.homedir()); | ||
| // @ts-ignore | ||
| this.bot2 = new Bot(os.homedir()); | ||
| this.paperKey1 = paperKey1; | ||
| this.paperKey2 = paperKey2; | ||
| } | ||
|
|
||
| public async init(): Promise<any> { | ||
| this.activeSnipes = {}; | ||
| await this.bot1.init(this.botUsername, this.paperKey1, null); | ||
| await this.bot2.init(this.botUsername, this.paperKey2, null); | ||
| await this.bot1.init(this.botUsername1, this.paperKey1, null); | ||
| await this.bot2.init(this.botUsername2, this.paperKey2, null); | ||
| console.log("both paper keys initialized"); | ||
| } | ||
|
|
||
| public async run(loadActiveSnipes: boolean): Promise<any> { | ||
| if (!this.bot1._service.initialized) { | ||
| if (!this.bot1.myInfo()) { | ||
| await this.init(); | ||
| } | ||
|
|
||
|
|
@@ -389,7 +400,7 @@ class Croupier { | |
| const snipe: Snipe = this.activeSnipes[JSON.stringify(channel)]; | ||
|
|
||
| // If the transaction was not sent to us, then ignore | ||
| if (txn.toUsername !== this.botUsername) { | ||
| if (txn.toUsername !== this.botUsername1) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -485,7 +496,7 @@ class Croupier { | |
|
|
||
| this.bot1.chat.send(channel, { | ||
| body: helpMsg, | ||
| }); | ||
| }, {}); | ||
| } | ||
|
|
||
| private routeIncomingMessage(msg: MessageSummary): void { | ||
|
|
@@ -508,7 +519,7 @@ class Croupier { | |
| if (typeof snipe === "undefined") { | ||
| return; | ||
| } | ||
| if (msg.content.type === "flip" && msg.sender.username === this.botUsername) { | ||
| if (msg.content.type === "flip" && msg.sender.username === this.botUsername1) { | ||
| snipe.monitorFlipResults(msg); | ||
| return; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import * as dotenv from "dotenv"; | ||
| dotenv.config(); | ||
|
|
||
| import Croupier from "./croupier"; | ||
| import * as Bot from "./keybase-bot"; | ||
|
|
||
| let croupier: Croupier; | ||
|
|
||
|
|
@@ -8,13 +10,14 @@ async function main(): Promise<any> { | |
| process.env.DEVELOPMENT = "true"; | ||
|
|
||
| croupier = new Croupier( | ||
| "devcroupier", | ||
| process.env.DEV_CROUPIER_USERNAME1, | ||
| process.env.DEV_CROUPIER_USERNAME2, | ||
| process.env.DEV_CROUPIER_PAPERKEY1, | ||
| process.env.DEV_CROUPIER_PAPERKEY2, | ||
| process.env.MONGODB_USERNAME, | ||
| process.env.MONGODB_PASSWORD, | ||
| process.env.MONGODB_HOST, | ||
| true, | ||
| JSON.parse(process.env.IS_CLUSTER), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're now coding this as an envvar, we should remove the isCluster param from the |
||
| ); | ||
| await croupier.run(true); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macOS, Linux, or Windows Subsystem for Linux – Croupier relies on non-Windows commands such as
which