Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ index.js
scratchpad.js
deploy/docker-compose.yaml
node_modules/
.env
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Copy link
Collaborator

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

- `expect` command (`apt-get install expect`)
- Some Lumens to fund the bot accounts (Main bot needs at least 1XLM to function)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
4 changes: 2 additions & 2 deletions __tests__/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as os from "os";
import Croupier from "../croupier";
import * as Bot from "../keybase-bot";
import { ChatChannel, MessageSummary, Transaction } from "../keybase-bot";
import * as Bot from "keybase-bot";
import { ChatChannel, MessageSummary, Transaction } from "keybase-bot";

import {
IBetData,
Expand Down
37 changes: 24 additions & 13 deletions croupier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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,
Expand All @@ -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();
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -485,7 +496,7 @@ class Croupier {

this.bot1.chat.send(channel, {
body: helpMsg,
});
}, {});
}

private routeIncomingMessage(msg: MessageSummary): void {
Expand All @@ -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;
}
Expand Down
9 changes: 6 additions & 3 deletions index.ts
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;

Expand All @@ -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),
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 class Croupier constructor(), and just have the constructor method check JSON.parse(process.env.IS_CLUSTER).

);
await croupier.run(true);
}
Expand Down
Loading