README.md 4.59 KB
Newer Older
Melroy van den Berg's avatar
Melroy van den Berg committed
1
2
# LBRY Bot

Melroy van den Berg's avatar
Melroy van den Berg committed
3
4
5
6
7
8
Botfather for [LBRY](https://lbry.com/) - Which knows everything you want to know

## What?

A Botfather chat bot for LBRY. The one that rule them all!

Melroy van den Berg's avatar
Melroy van den Berg committed
9
10
Open [@LBRY_telegram_bot](https://telegram.me/LBRY_telegram_bot) in Telegram.

Melroy van den Berg's avatar
Melroy van den Berg committed
11
12
## Why?

Melroy van den Berg's avatar
Melroy van den Berg committed
13
LBRY Bot can be used in chat applications like IRC, [Telegram](https://telegram.org/apps) or Discord to parse requests from clients and return useful information about LBRY.
Melroy van den Berg's avatar
Melroy van den Berg committed
14
15
16
17
18
19
20

This information could be anything like content, meta-data, network stats, address info, and much more!

And thus eventually to serve the LBRY user (yes, you)!

## How?

21
LBRY Bot is written in javascript using [Node.js](https://nodejs.org/en/download/).
Melroy van den Berg's avatar
Melroy van den Berg committed
22

Melroy van den Berg's avatar
Melroy van den Berg committed
23
LBRY Bot initually will use the [lbry-sdk](https://github.com/lbryio/lbry-sdk) (also known as `lbrynet`) in order to retrieve information from the LBRY (eg.  meta-data, resolve URLs and more).
Melroy van den Berg's avatar
Melroy van den Berg committed
24

Melroy van den Berg's avatar
Melroy van den Berg committed
25
The Bot also uses the [lbrycrd](https://github.com/lbryio/lbrycrd) API (for eg. blockchaininfo, network info, mining info). Last but not least, a more efficient [Chainquery](https://github.com/lbryio/chainquery) will be used to retrieve even more data like address, transactions, blocks, claims, channel info and more.
Melroy van den Berg's avatar
Melroy van den Berg committed
26
27
28
29
30
31
32

## Who?

Hi, it's me: Melroy van den Berg.

## When?

Melroy van den Berg's avatar
Melroy van den Berg committed
33
Bot is live and available in Telegram: [@LBRY_telegram_bot](https://telegram.me/LBRY_telegram_bot).
Melroy van den Berg's avatar
Melroy van den Berg committed
34

Melroy van den Berg's avatar
Melroy van den Berg committed
35
## Develop
Melroy van den Berg's avatar
Melroy van den Berg committed
36
37

Requirements:
Melroy van den Berg's avatar
Melroy van den Berg committed
38

Melroy van den Berg's avatar
Melroy van den Berg committed
39
40
* [Node.js v10](https://nodejs.org/en/download/)
* npm (package manager)
41
* [Lbrynet deamon](https://github.com/lbryio/lbry-sdk/releases)
42
* [Lbrycrd deamon](https://github.com/lbryio/lbrycrd) with txindex turned on
Melroy van den Berg's avatar
Melroy van den Berg committed
43

Melroy van den Berg's avatar
Melroy van den Berg committed
44
```sh
Melroy van den Berg's avatar
Melroy van den Berg committed
45
46
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs npm
Melroy van den Berg's avatar
Melroy van den Berg committed
47
48
```

Melroy van den Berg's avatar
Melroy van den Berg committed
49
### Running
Melroy van den Berg's avatar
Melroy van den Berg committed
50

Melroy van den Berg's avatar
Melroy van den Berg committed
51
52
53
54
55
56
57
| Chat Service  | Token env. name    | Obtain by                                    |
| ------------- |:------------------:| --------------------------------------------:|
| Telegram      | TELEGRAM_TOKEN     | [@bothfather](https://telegram.me/BotFather) |
| Discord       | TODO               | -                                            |
| IRC           | TODO               | -                                            |

Create & Fill-in the applicable tokens in `tokens.env` file, by using the template (see [tokens.env.example](tokens.env.example)):
Melroy van den Berg's avatar
Melroy van den Berg committed
58
59

```sh
Melroy van den Berg's avatar
Melroy van den Berg committed
60
TELEGRAM_TOKEN=xyz
Melroy van den Berg's avatar
Melroy van den Berg committed
61
DISCORD_TOKEN=xyz
Melroy van den Berg's avatar
Melroy van den Berg committed
62
COINMARKETCAP_API_TOKEN=xyz
63
RPC_PASSWORD=xyz
Melroy van den Berg's avatar
Melroy van den Berg committed
64
65
```

Melroy van den Berg's avatar
Melroy van den Berg committed
66
Finally, starting the bot server: `npm start` (or `node src/index.js`)
Melroy van den Berg's avatar
Melroy van den Berg committed
67

68
**Note 1:** Reverse proxy (eg. Nginx) is required to put between the bot and the world-wide-web. Expose the webserver on port 443 (with SSL). See [nginx_example.conf](nginx_example.conf).
69

70
**Note 2:** Assuming you are running the lbrynet deamon (see requirements).
Melroy van den Berg's avatar
Melroy van den Berg committed
71

72
73
74
75
76
77
78
79
**Note 3:** Assuming you are running the lbrycrd deamon (see requirements), with JSON RPC enabled and txindex enabled. Example of `~/.lbrycrd/lbrycrd.conf`:

```sh
rpcuser=lbry
rpcpassword=xyz
daemon=1
server=1
txindex=1
Melroy van den Berg's avatar
Melroy van den Berg committed
80
81
82
83
84

# The following options are optional (to reduce memory load)
#blocksonly=1 
#dbcache=20
#maxmempool=200
85
86
```

Melroy van den Berg's avatar
Melroy van den Berg committed
87
88
89
90
91
### Linting

Run lint: `npm run lint`

Fix lint issues: `npm run fix`
92

Melroy van den Berg's avatar
Melroy van den Berg committed
93
94
95
96
### Unit Testing

Run test: `npm test`

97
98
## Production

Melroy van den Berg's avatar
Melroy van den Berg committed
99
Starting the bot, can be done via:
100

Melroy van den Berg's avatar
Melroy van den Berg committed
101
102
103
* `./start_bot_prod.sh`

The bot can be started via crontab for example:
104

Melroy van den Berg's avatar
Melroy van den Berg committed
105
```sh
Melroy van den Berg's avatar
Melroy van den Berg committed
106
@reboot sh /path/to/start_bot_prod.sh
Melroy van den Berg's avatar
Melroy van den Berg committed
107
```
Melroy van den Berg's avatar
Melroy van den Berg committed
108

Melroy van den Berg's avatar
Melroy van den Berg committed
109
110
111
112
113
114
115
**General setup:**

* Be-sure both `lbrycrdd` and `lbrynet` binaries are installed into `/usr/bin` directory!
* Create an user lbry the unix machine (`adduser -M lbry`)

### LBRYcrd setup

116
* Create the LBRYcrd file (`lbryd.conf`) in `/etc/lbry` (so: `/etc/lbry/lbryd.conf`) for the LBRY Core Daemon service, example of this file:
Melroy van den Berg's avatar
Melroy van den Berg committed
117
118
119
120
121
122
123

```sh
rpcuser=lbry
rpcpassword=my_secure_password
daemon=1
server=1
txindex=1
124
125
126
127
128

# The following options are optional (to reduce memory load)
blocksonly=1
dbcache=20
maxmempool=200
Melroy van den Berg's avatar
Melroy van den Berg committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
```

* See [lbrycrd.service systemd file](lbrycrd.service) for Debian based distributions. Place this file into `/etc/systemd/system` folder.
* Core data will be stored into `/var/lib/lbrycrd`

### LBRYnet setup

* Place the LBRYNet file (`lbrynet.yml`) in `/etc/lbry`, example of this file:

```yml
api: 127.0.0.1:5279
streaming_server: 127.0.0.1:5280
allowed_origin: localhost
data_dir: /var/lib/lbrynet
download_dir: /var/lib/lbrynet
wallet_dir: /var/lib/lbryum
save_files: false
save_blobs: false
max_key_fee:
    currency: LBC
    amount: 0
use_keyring: false
```

* See [lbrynet.service systemd file](lbrynet.service). Place also inside `/etc/systemd/system`.
* LBRYNet (SDK) data will be stored into `/var/lib/lbrynet`

156
## Handy links 
Melroy van den Berg's avatar
Melroy van den Berg committed
157

Melroy van den Berg's avatar
Melroy van den Berg committed
158
159
160
* [LBRYnomics](https://lbrynomics.com)
* [LBRY Trending algos](https://github.com/eggplantbren/lbry-trending-algos)