Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: lnp2pBot/bot
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.9.3
Choose a base ref
...
head repository: lnp2pBot/bot
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
Showing with 11,142 additions and 10,945 deletions.
  1. +11 −2 .env-sample
  2. +2 −1 .eslintrc.json
  3. +3 −3 .github/workflows/code-linter.yaml
  4. +21 −15 .github/workflows/integrate.yaml
  5. +3 −1 .gitignore
  6. +4 −6 CONTRIBUTING.md
  7. +6 −3 README.md
  8. +9 −8 app.js → app.ts
  9. +143 −93 bot/{commands.js → commands.ts}
  10. +0 −2 bot/{index.js → index.ts}
  11. +98 −72 bot/messages.ts
  12. +5 −3 bot/middleware/{commands.js → commands.ts}
  13. +0 −15 bot/middleware/index.js
  14. +11 −0 bot/middleware/index.ts
  15. +7 −6 bot/middleware/{stage.js → stage.ts}
  16. +6 −8 bot/middleware/{user.js → user.ts}
  17. +41 −15 bot/modules/community/{actions.js → actions.ts}
  18. +33 −30 bot/modules/community/{commands.js → commands.ts}
  19. +50 −0 bot/modules/community/communityContext.ts
  20. +9 −9 bot/modules/community/{index.js → index.ts}
  21. +27 −19 bot/modules/community/{messages.js → messages.ts}
  22. +13 −10 bot/modules/community/{scenes.communityAdmin.js → scenes.communityAdmin.ts}
  23. +133 −127 bot/modules/community/{scenes.js → scenes.ts}
  24. +17 −6 bot/modules/dispute/{actions.js → actions.ts}
  25. +40 −24 bot/modules/dispute/{commands.js → commands.ts}
  26. +5 −3 bot/modules/dispute/{index.js → index.ts}
  27. +0 −120 bot/modules/dispute/messages.js
  28. +170 −0 bot/modules/dispute/messages.ts
  29. +0 −14 bot/modules/events/community.js
  30. +16 −0 bot/modules/events/community.ts
  31. +0 −16 bot/modules/events/index.js
  32. +26 −0 bot/modules/events/index.ts
  33. +0 −23 bot/modules/events/orders.js
  34. +24 −0 bot/modules/events/orders.ts
  35. +0 −13 bot/modules/language/actions.js
  36. +16 −0 bot/modules/language/actions.ts
  37. +0 −18 bot/modules/language/commands.js
  38. +23 −0 bot/modules/language/commands.ts
  39. +0 −8 bot/modules/language/index.js
  40. +10 −0 bot/modules/language/index.ts
  41. +4 −2 bot/modules/language/{messages.js → messages.ts}
  42. +6 −5 bot/modules/nostr/{commands.js → commands.ts}
  43. +0 −19 bot/modules/nostr/config.js
  44. +21 −0 bot/modules/nostr/config.ts
  45. +0 −58 bot/modules/nostr/events.js
  46. +83 −0 bot/modules/nostr/events.ts
  47. +0 −44 bot/modules/nostr/index.js
  48. +38 −0 bot/modules/nostr/index.ts
  49. +0 −11 bot/modules/nostr/lib.js
  50. +11 −0 bot/modules/nostr/lib.ts
  51. +55 −36 bot/modules/orders/{commands.js → commands.ts}
  52. +21 −21 bot/modules/orders/{index.js → index.ts}
  53. +18 −14 bot/modules/orders/{messages.js → messages.ts}
  54. +47 −34 bot/modules/orders/{scenes.js → scenes.ts}
  55. +20 −20 bot/modules/orders/{takeOrder.js → takeOrder.ts}
  56. +9 −3 bot/modules/user/{index.js → index.ts}
  57. +0 −1 bot/modules/user/scenes/index.js
  58. +3 −0 bot/modules/user/scenes/index.ts
  59. +46 −32 bot/modules/user/scenes/{settings.js → settings.ts}
  60. +76 −39 bot/{ordersActions.js → ordersActions.ts}
  61. +69 −31 bot/{scenes.js → scenes.ts}
  62. +168 −120 bot/start.ts
  63. +140 −71 bot/{validations.js → validations.ts}
  64. +7 −5 db_connect.js → db_connect.ts
  65. +79 −110 docs/INSTALL.es.md
  66. +86 −118 docs/INSTALL.md
  67. BIN images/Ant.png
  68. BIN images/Aquarium.png
  69. BIN images/Badger.png
  70. BIN images/Bat Face.png
  71. BIN images/Bear.png
  72. BIN images/Beaver.png
  73. BIN images/Bee.png
  74. BIN images/Bird.png
  75. BIN images/Bug.png
  76. BIN images/Bull.png
  77. BIN images/Bumblebee.png
  78. BIN images/Butterfly.png
  79. BIN images/Cat Footprint.png
  80. BIN images/Cat.png
  81. BIN images/Caterpillar.png
  82. BIN images/Chicken.png
  83. BIN images/Clown Fish.png
  84. BIN images/Corgi.png
  85. BIN images/Cow.png
  86. BIN images/Crab.png
  87. BIN images/Deer.png
  88. BIN images/Dinosaur.png
  89. BIN images/Dog Park.png
  90. BIN images/Dog.png
  91. BIN images/Dolphin.png
  92. BIN images/Dragonfly.png
  93. BIN images/Duck.png
  94. BIN images/Elephant.png
  95. BIN images/Falcon.png
  96. BIN images/Fish Food.png
  97. BIN images/Fish.png
  98. BIN images/Fly.png
  99. BIN images/Frog.png
  100. BIN images/Giraffe.png
  101. BIN images/Gorilla.png
  102. BIN images/Grasshopper.png
  103. BIN images/Hornet Hive.png
  104. BIN images/Hornet.png
  105. BIN images/Horse.png
  106. BIN images/Hummingbird.png
  107. BIN images/Insect.png
  108. BIN images/Kangaroo.png
  109. BIN images/Kiwi Bird.png
  110. BIN images/Ladybird.png
  111. BIN images/Leopard.png
  112. BIN images/Lion.png
  113. BIN images/Llama.png
  114. BIN images/Mite.png
  115. BIN images/Mosquito.png
  116. BIN images/Octopus.png
  117. BIN images/Panda.png
  118. BIN images/Pig With Lipstick.png
  119. BIN images/Pig.png
  120. BIN images/Prawn.png
  121. BIN images/Puffin Bird.png
  122. BIN images/Rabbit.png
  123. BIN images/Rhinoceros.png
  124. BIN images/Seahorse.png
  125. BIN images/Shark.png
  126. BIN images/Sheep.png
  127. BIN images/Snail.png
  128. BIN images/Spider.png
  129. BIN images/Starfish.png
  130. BIN images/Stork.png
  131. BIN images/Tentacles.png
  132. BIN images/Turtle.png
  133. BIN images/Unicorn.png
  134. BIN images/Wasp.png
  135. BIN images/Whale.png
  136. BIN images/Wolf.png
  137. +7 −6 jobs/{calculate_community_earnings.js → calculate_community_earnings.ts}
  138. +22 −9 jobs/{cancel_orders.js → cancel_orders.ts}
  139. +9 −6 jobs/{communities.js → communities.ts}
  140. +9 −6 jobs/{delete_published_orders.js → delete_published_orders.ts}
  141. +0 −19 jobs/index.js
  142. +19 −0 jobs/index.ts
  143. +0 −20 jobs/node_info.js
  144. +26 −0 jobs/node_info.ts
  145. +19 −10 jobs/pending_payments.ts
  146. +1 −1 ln/connect.js
  147. +1 −1 ln/hold_invoice.js
  148. +2 −1 ln/index.js
  149. +1 −1 ln/info.js
  150. +3 −1 ln/pay_request.js
  151. +3 −3 ln/resubscribe_invoices.js
  152. +71 −57 ln/subscribe_invoice.js
  153. +1 −1 ln/subscribe_probe.js
  154. +8 −12 lnurl/{lnurl-pay.js → lnurl-pay.ts}
  155. +89 −27 locales/de.yaml
  156. +91 −27 locales/en.yaml
  157. +87 −27 locales/es.yaml
  158. +644 −0 locales/fa.yaml
  159. +85 −24 locales/fr.yaml
  160. +642 −580 locales/it.yaml
  161. +640 −0 locales/ko.yaml
  162. +132 −70 locales/pt.yaml
  163. +84 −21 locales/ru.yaml
  164. +86 −24 locales/uk.yaml
  165. +5 −5 logger.js → logger.ts
  166. +4 −2 models/community.ts
  167. +1 −2 models/config.ts
  168. +3 −3 models/dispute.ts
  169. +0 −15 models/index.js
  170. +15 −0 models/index.ts
  171. +26 −7 models/order.ts
  172. +1 −1 models/pending_payment.ts
  173. +1 −1 models/user.ts
  174. +4,017 −8,164 package-lock.json
  175. +22 −16 package.json
  176. +593 −0 tests/bot/bot.spec.ts
  177. +117 −0 tests/bot/mocks/currenciesResponse.ts
  178. +33 −0 tests/bot/mocks/languagesResponse.ts
  179. +137 −0 tests/bot/modules/dispute/messages.ts
  180. +1,104 −0 tests/bot/validation.spec.ts
  181. +0 −145 tests/bot_test.js
  182. +0 −23 tests/lightning_test.js
  183. +25 −0 tests/ln/lightning.spec.ts
  184. +3 −3 tests/{lightningResponse.js → ln/mocks/lightningResponse.ts}
  185. +0 −28 tests/order.js
  186. +0 −16 tests/user.js
  187. +21 −2 tsconfig.json
  188. +9 −0 tsconfig.test.json
  189. +31 −8 util/fiat.json
  190. +4 −0 util/fiatModel.ts
  191. +180 −63 util/{index.js → index.ts}
  192. +10 −0 util/languages.json
  193. +9 −0 util/languagesModel.ts
13 changes: 11 additions & 2 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ MONGO_URI='mongodb://username:password@localhost'

# lightning invoice expiration time in milliseconds
INVOICE_EXPIRATION_WINDOW=3600000
# lightning hold invoice expiration time in seconds
# This is the time that a taker has to pay the invoice (seller) or add a new invoice (buyer), in seconds
HOLD_INVOICE_EXPIRATION_WINDOW=600

CHANNEL='@p2plnbotchannel'
@@ -71,4 +71,13 @@ DISPUTE_CHANNEL='@p2plnbotDispute'
COMMUNITY_TTL=31

# nostr bot private key
NOSTR_SK=''
NOSTR_SK=''

# Number of currencies allowed in a community
COMMUNITY_CURRENCIES=20

# List of relays to connect to
RELAYS='ws://localhost:7000,ws://localhost:8000,ws://localhost:9000'

# Seconds to wait to allow disputes to be started
DISPUTE_START_WINDOW=600
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
"rules": {
"no-underscore-dangle": "off",
"camelcase": "off",
"eqeqeq": "off"
"eqeqeq": "off",
"no-void": "off"
}
}
6 changes: 3 additions & 3 deletions .github/workflows/code-linter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Auto Check Lint
on:
pull_request:
branches: ['main']
- pull_request
- push

jobs:
Lint:
@@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 18.x
- run: |
npm ci
npm run lint
36 changes: 21 additions & 15 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
name: integracion continua con node.js
name: NodeJS Continuous Integration

on: [push, pull_request]
on:
push:
pull_request:
workflow_dispatch:

# see https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
schedule:
- cron: "0 0 * * *"

jobs:
ci_to_main:
runs-on: ubuntu-latest
container:
image: 'ubuntu:24.04'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14.x

- name: Update apt and install required packages
run: |
sudo apt update
sudo apt install --yes --no-install-recommends curl
sudo apt-get install --yes gnupg
apt update --yes
apt install --yes sudo
sudo apt install --yes --no-install-recommends npm
- name: Import the public key used by the package management system
- name: Import MongoDB's public key for the package management system
run: |
sudo apt install --yes --no-install-recommends curl gnupg
sudo rm -f /etc/ssl/certs/ca-bundle.crt
sudo apt reinstall --yes ca-certificates
sudo update-ca-certificates
@@ -33,9 +41,7 @@ jobs:
- name: Check Mongo version
run: mongod --version
- name: Start MongoDB
run: sudo service mongod start
- name: Verify that MongoDB has started successfully
run: sudo service mongod status
run: sudo nohup mongod --quiet --config /etc/mongod.conf &

- name: Create database
run: |
@@ -50,14 +56,14 @@ jobs:
mongosh --eval 'db.getSiblingDB("lnp2pbot").createCollection("mycollection")'
- run: npm install @types/node @types/i18n
- run: tsc
- run: npm install @types/node @types/i18n @types/mocha
- run: npx tsc
- run: npm ci
- name: Run tests
env:
DB_USER: ''
DB_PASS: ''
DB_HOST: 'localhost'
DB_HOST: '127.0.0.1'
DB_PORT: '27017'
DB_NAME: 'lnp2pbot'
run: npm test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules
.env
admin.macaroon
tls.cert
tls.cert
dist/
.history/
10 changes: 4 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ Most communication about @lnp2pbot happens on the main [Telegram group](https://
All @lnp2pbot contributors submit changes via pull requests. The workflow is as follows:

- Fork the repository
- Create a topic branch from the `master` branch
- Create a topic branch from the `main` branch
- Commit patches
- Squash redundant or unnecessary commits
- Submit a pull request from your topic branch back to the `main` branch of the main repository
@@ -41,6 +41,8 @@ Please note that Pull Requests marked `NACK` and/or GitHub's `Change requested`

We ~~try to~~ use [Airbnb javascript style guide](https://github.com/airbnb/javascript) in order to have a cleaner code.

All new code should be TypeScript. The use of `any` type is discouraged, except in the tests.

### Configure Git user name and email metadata

See https://help.github.com/articles/setting-your-username-in-git/ for instructions.
@@ -63,10 +65,6 @@ From https://chris.beams.io/posts/git-commit/#seven-rules:
See https://github.com/blog/2144-gpg-signature-verification for background and
https://help.github.com/articles/signing-commits-with-gpg/ for instructions.

### Use an editor that supports Editorconfig

The [.editorconfig](.editorconfig) settings in this repository ensure consistent management of whitespace. Most modern editors support it natively or with plugin. See http://editorconfig.org for details.

### Keep the git history clean

It's very important to keep the git history clear, light and easily browsable. This means contributors must make sure their pull requests include only meaningful commits (if they are redundant or were added after a review, they should be removed) and _no merge commits_.
It's very important to keep the git history clear, light and easily browsable. This means contributors must make sure their pull requests include only meaningful commits (if they are redundant or were added after a review, they should be removed) and _no merge commits_.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -43,13 +43,16 @@ Only if both parties cancel cooperatively the order is canceled and seller's fun
If users have a disagreement on canceling or don't want to go forward they can start a dispute.

## Disputes
Both parties can start a dispute at any moment, after a dispute is started a human will be notified with all the information, this human will contact both parties to evaluate the situation and take a decision.
Both parties can start a dispute at any moment, after a dispute is started a human (aka "solver") will be notified with all the information, this solver will contact both parties to evaluate the situation and take a decision.

After a user starts a dispute, both parties will have increased by **1** their own `dispute` field in database and after **2** disputes users will be banned from using the bot.
After a user starts a dispute, both parties will have increased by **1** their own `dispute` field in database. If during a dispute it is proven that there is a malicious user, the solver can ban that user, and they will no longer be able to use the bot anymore.

## Incentive to release funds
A seller that didn't release funds to the buyer can't open or take another order from the bot and probably will be involved in a dispute from the buyer damaging his/her reputation

## Communities
Anyone who already has or creates a Telegram group can include the [bot](https://t.me/lnp2pbot) inside to facilitate buying and selling bitcoin among its members. The group administrator will earn a commission for transactions conducted within their community, and they can also offer discounts on the fees that the bot charges within their community.

# Financial Support
**LNp2pBot** is an open source project. We are not a company, we don't do ICOs or dark business, we are just people that wants bring solutions to the people using the best open source money in the world. Our work depends on the financial collaboration of the users.

@@ -111,7 +114,7 @@ $ npm start
$ npm test
```
# Documentation
You can find documentation in [english](https://lnp2pbot.com/learn) and [spanish](https://lnp2pbot.com/aprende).
You can find documentation in [English](https://lnp2pbot.com/learn), [Spanish](https://lnp2pbot.com/aprende), [Portuguese](https://lnp2pbot.com/aprenda), [French](https://lnp2pbot.com/apprendre) and [Persian](https://lnp2pbot.com/farsi-doc)

# Contribute

17 changes: 9 additions & 8 deletions app.js → app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require('dotenv').config();
const { SocksProxyAgent } = require('socks-proxy-agent');
const { start } = require('./bot');
const mongoConnect = require('./db_connect');
import "dotenv/config";
import { SocksProxyAgent } from "socks-proxy-agent";
import { MainContext, start } from "./bot/start";
import { connect as mongoConnect } from './db_connect'
const { resubscribeInvoices } = require('./ln');
const logger = require('./logger');
import { logger } from "./logger";
import { Telegraf } from "telegraf";
const { delay } = require('./util');

(async () => {
@@ -23,7 +24,7 @@ const { delay } = require('./util');
mongoose.connection
.once('open', async () => {
logger.info('Connected to Mongo instance.');
let options = { handlerTimeout: 60000 };
let options: Partial<Telegraf.Options<MainContext>> = { handlerTimeout: 60000 };
if (process.env.SOCKS_PROXY_HOST) {
const agent = new SocksProxyAgent(process.env.SOCKS_PROXY_HOST);
options = {
@@ -32,10 +33,10 @@ const { delay } = require('./util');
},
};
}
const bot = start(process.env.BOT_TOKEN, options);
const bot = start(String(process.env.BOT_TOKEN), options);
// Wait 1 seconds before try to resubscribe hold invoices
await delay(1000);
await resubscribeInvoices(bot);
})
.on('error', error => logger.error(`Error connecting to Mongo: ${error}`));
.on('error', (error: Error) => logger.error(`Error connecting to Mongo: ${error}`));
})();
Loading