Compare commits

...

68 commits

Author SHA1 Message Date
Jeremy Kauffman
eaa5f32c09
Merge pull request #62 from Eniamza/master
Fix : Use RegEx based splitting instead of space character
2021-04-20 16:17:47 -04:00
eniamza
a2596f0e93
Fix : RegEx based split in tipbot.ts 2021-03-20 18:02:36 +06:00
eniamza
28cb36b5d5
Fix : Use RegEx instead of space character in split 2021-03-20 17:59:43 +06:00
Ralph
eb7012c432
Remove auto-reply 'yes?' 2020-11-16 15:12:50 -05:00
Ralph
c2974d02ef
Update yarn.lock 2020-11-14 07:59:46 -05:00
Ralph
c80f9133c0
Update .gitignore 2020-11-14 07:59:32 -05:00
Ralph
34cd1211fb
Update .gitignore 2020-11-14 07:57:56 -05:00
Ralph
b3b12beb8f
Merge pull request #61 from lbryio/typescript-update
Dependency Update & Typescript Update
2020-11-14 07:53:45 -05:00
Ralph
5cc7996f9d
Update README.md 2020-11-14 07:35:08 -05:00
Ralph
4e7ecd78a6
Update README for Yarn & Typescript updates 2020-11-14 07:33:51 -05:00
Ralph
7ec1826454 rollback some bitcoin-core changes 2020-11-14 07:19:25 -05:00
Ralph
f5c899aeb4 Mass update to deps and move to typescript 2020-11-14 06:49:55 -05:00
Thomas Zarebczan
0395ef7026
Merge pull request #60 from VladHZC/patch-1
Update README.md
2020-10-16 16:54:10 -04:00
Vlad
4ee56aea5d
Update README.md 2020-10-16 17:44:28 -03:00
Niko Storni
c6c5e0bc69 print the error to console 2020-08-25 19:22:11 +02:00
Ralph
f41801c96e
Merge pull request #59 from lbryio/dependabot/npm_and_yarn/lodash-4.17.19
Bump lodash from 4.17.15 to 4.17.19
2020-08-14 23:40:42 -04:00
dependabot[bot]
a8bc6f4097
Bump lodash from 4.17.15 to 4.17.19
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-15 22:54:41 +00:00
Niko
571f3cb0aa
Merge pull request #58 from lbryio/dependabot/npm_and_yarn/mongoose-5.7.5
Bump mongoose from 5.5.0 to 5.7.5
2020-07-01 22:26:06 +02:00
dependabot[bot]
fc6178de6b
Bump mongoose from 5.5.0 to 5.7.5
Bumps [mongoose](https://github.com/Automattic/mongoose) from 5.5.0 to 5.7.5.
- [Release notes](https://github.com/Automattic/mongoose/releases)
- [Changelog](https://github.com/Automattic/mongoose/blob/master/History.md)
- [Commits](https://github.com/Automattic/mongoose/compare/5.5.0...5.7.5)

Signed-off-by: dependabot[bot] <support@github.com>
2020-06-30 19:35:17 +00:00
Thomas Zarebczan
38422d2543
Merge pull request #57 from eatdostacos/patch-1
Update balance command
2020-06-30 15:34:44 -04:00
eatdostacos
2334489da5
Update balance command 2020-05-22 22:00:39 -07:00
Thomas Zarebczan
485afee3fb
Merge pull request #55 from ykris45/patch-6
Update LICENSE
2020-02-03 17:06:28 -05:00
YULIUS KURNIAWAN KRISTIANTO
3c8a3c5b83
Update LICENSE 2020-02-03 05:56:08 +07:00
Thomas Zarebczan
cc5a979703
Merge pull request #52 from 0x15F9/importc
Remove redundant import
2019-10-28 10:59:02 -04:00
0x15F9
1e3a210e62 remove redundant import 2019-10-26 21:04:04 +04:00
Niko
b143a38bb7
Merge pull request #51 from kcseb/master
Fixed a minor typo and forced FAQ URL to NOT embed.
2019-10-15 15:49:26 -04:00
Kenneth C
904de88122
Fixed a minor typo and forced FAQ URL to NOT embed.
Fixed a minor typo and forced FAQ URL to NOT embed. 

When a user is tipped, the "read our Tipbot FAQ" URL will no longer embed.
Also fixed a minor typo "for a more details"
2019-10-15 20:45:43 +01:00
Niko
5f1abbdb7f
Merge pull request #50 from ceoger/patch-2
Update tipbot.js
2019-10-14 10:09:48 -04:00
Clement
950280b693
Update tipbot.js
prevent tipbot from embedding the faq image for tipbot on discord. This way it will only show the faq link without the example image
2019-10-11 20:22:40 +05:30
Thomas Zarebczan
9e5428eb04
Merge pull request #47 from Parikshit-Hooda/patch-1
update readme- typo fix and license mention
2019-10-10 14:21:49 -04:00
Thomas Zarebczan
5c17370fc4
Merge pull request #49 from StrikerRUS/patch-1
bump year in license
2019-10-10 14:20:49 -04:00
Nikita Titov
2d61e6fb82
bump year in license 2019-10-08 23:41:41 +03:00
Parikshit Hooda
9e68166321
update readme- typo fix and license mention
issue #46 
Fixed some punctuations for better comprehensibility.
Added MIT license in the readme itself as its a popular practice.
Opened as part of hacktoberfest.
2019-10-05 11:14:00 +05:30
Niko
765c50f248
Merge pull request #45 from lbryio/dependabot/npm_and_yarn/mixin-deep-1.3.2
Bump mixin-deep from 1.3.1 to 1.3.2
2019-09-04 14:37:19 +02:00
dependabot[bot]
5d4eb20c48
Bump mixin-deep from 1.3.1 to 1.3.2
Bumps [mixin-deep](https://github.com/jonschlinkert/mixin-deep) from 1.3.1 to 1.3.2.
- [Release notes](https://github.com/jonschlinkert/mixin-deep/releases)
- [Commits](https://github.com/jonschlinkert/mixin-deep/compare/1.3.1...1.3.2)

Signed-off-by: dependabot[bot] <support@github.com>
2019-08-28 14:09:14 +00:00
Niko
b45af0d976
Merge pull request #44 from lbryio/dependabot/npm_and_yarn/lodash-4.17.15
Bump lodash from 4.17.11 to 4.17.15
2019-08-05 11:47:51 -07:00
dependabot[bot]
0d32f2a8f5
Bump lodash from 4.17.11 to 4.17.15
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.11 to 4.17.15.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.11...4.17.15)

Signed-off-by: dependabot[bot] <support@github.com>
2019-08-05 18:45:54 +00:00
Thomas Zarebczan
3f1e18c862
Merge pull request #41 from DusanMarinkovic/patch-1
Fix for missing config file error
2019-05-02 15:41:49 -04:00
Thomas Zarebczan
eabee06bab
Merge pull request #42 from ceoger/patch-1
Update tipbot.js
2019-05-02 15:41:14 -04:00
Clement
24ffa74629
Update tipbot.js
updated instruction for private tip as the current instruction was wrong
2019-05-03 01:06:10 +05:30
DusanMarinkovic
ea109b01c5
Fix for missing config file error
Current code doesn't point to a proper location of config file also name of the config file should be "default.json" instead of "config.json"
2019-05-02 01:57:13 +02:00
Niko Storni
25d100ce83 upgrade dependencies 2019-04-10 10:04:39 -04:00
Niko
fbc8569bf9
Merge pull request #40 from ykris45/patch-5
change io to com
2019-03-27 23:48:47 +01:00
YULIUS KURNIAWAN KRISTIANTO
85accd4e35
Update LICENSE 2019-03-27 21:59:51 +07:00
YULIUS KURNIAWAN KRISTIANTO
e8507f0662
Update tipbot.js 2019-03-27 21:59:33 +07:00
YULIUS KURNIAWAN KRISTIANTO
56a310c4f8
Update package.json 2019-03-27 21:58:09 +07:00
YULIUS KURNIAWAN KRISTIANTO
f443ef2089
Update README.md 2019-03-27 21:57:38 +07:00
Niko
e582c638a7
Merge pull request #39 from kcseb/patch-1
update README
2019-02-27 14:24:42 +01:00
Kenneth C
0f4e15a712
Fixed line 53
Fixed line 53 to rename the default.json.example to config.json
2019-02-26 18:43:38 -05:00
Kenneth C
e3e999f313
Updated README.md with FULL install instructions
The documentation for this was severely lacking. I've taken the time to write up full install instructions for Ubuntu 18.04.
2019-02-26 18:41:37 -05:00
Niko Storni
44d94e7a25 fix private roletip 2018-12-04 20:38:48 -05:00
Niko Storni
a8578093bf fix of fix 2018-12-04 20:32:38 -05:00
Niko Storni
34151fc92b fix roletip 2018-12-04 20:26:51 -05:00
Niko
4dcaea3370
Merge pull request #33 from lbryio/fix-priv-roletip
Update tipbot.js
2018-12-04 18:26:53 -05:00
Niko Storni
d12471cc10
update packages 2018-11-15 12:01:07 -05:00
Niko Storni
ab45b1060a Merge branch 'ykris45-patch-3' 2018-11-15 11:58:06 -05:00
Niko Storni
54fe1351bb run linter 2018-11-15 11:57:40 -05:00
YULIUS KURNIAWAN KRISTIANTO
ed3050b1ac
Update tipbot.js
bring back comma
2018-11-06 03:09:47 +07:00
YULIUS KURNIAWAN KRISTIANTO
136f17c4ad
strict balance on general and remove comma 2018-11-04 21:23:12 +07:00
Niko Storni
54c7caaa63
upgrade packages 2018-10-11 14:45:53 -04:00
Niko Storni
b7f0e96bde
update dependencies 2018-10-11 14:40:16 -04:00
filipnyquist
637f49ea93
Merge pull request #36 from Invariant-Change/patch-5
Tipbot Repairs
2018-10-10 17:22:10 +02:00
Electron - Mark Firth
cdb0ba25e4
Tipbot Repairs
Formatting corrections: URL contained markdown which is only supported in `embed: {}`
Duplicate command removed: `!tip` and `!tips` now display the same message so only one required.
Duplicate tipper name removed: The bot mentioned the tippers name twice concurrently.
Removed unnecessary code: Unnecessary code removed `${message.content.split(' ', 1)[0]}\`
Removed author:  Author was set as `!tip` and not required.
2018-10-09 22:11:14 +10:00
filipnyquist
3c09e5fb77
Merge pull request #35 from kcseb/master
Updated tipbot.js (Fixed some messages)
2018-10-08 23:16:01 +02:00
filipnyquist
821f92e5b4
Merge pull request #34 from ykris45/patch-2
add read faq to send tippers
2018-10-08 23:08:37 +02:00
Kenneth C
128351e176
Updated tipbot.js (Fixed some messages)
Changed a few things with when a tip is sent or errors out. (Instead of just "I don't know how to tip that amount", it sounds a bit better and more accurate.)
Changed the "Wubba lubba dub dub" message to something a bit more... normal? 
Also changed some phrasing with messages in general. Nothing that will change the functionality, more just the general appearance of the messages.
2018-10-05 23:23:03 -04:00
YULIUS KURNIAWAN KRISTIANTO
d7312ed308
fix typo 2018-10-06 05:33:25 +07:00
YULIUS KURNIAWAN KRISTIANTO
cc836f5b53
add read faq to send tippers 2018-10-04 22:32:32 +07:00
13 changed files with 407 additions and 4265 deletions

31
.eslintrc.json Normal file
View file

@ -0,0 +1,31 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"globals": {},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"quotes": [
"warn",
"single"
],
"semi": [
"warn",
"always"
]
}
}

3
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,3 @@
{
"deepscan.enable": true
}

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2018 LBRY <filip@lbry.io>
Copyright (c) 2018-2020 LBRY <filip@lbry.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -1,4 +1,4 @@
# Bot for [LBRY's Discord](https://discord.gg/tgnNHf5)
# Bot for [LBRY's Discord](https://chat.lbry.com)
(This README will be updated along with bot updates)
Features:
@ -9,17 +9,63 @@ Features:
## Requirements
- node > 8.0.0
- npm > 0.12.x
- node > 12.0.x
- yarn
- node-typescript
- LBRYCrd 0.17.x (https://github.com/lbryio/lbrycrd/)
## Install the prerequisites
### NodeJS & Typescript
Install NodeJS v12 for the Operating system you are running.
[NodeJS Documentation link](https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions-enterprise-linux-fedora-and-snap-packages)
```
sudo apt install nodejs-typescript
```
### Install Yarn Globally
```
sudo npm install -g yarn
```
### Download LBRYCRD
Download the latest 0.17 release of LBRYcrd from the [Github](https://github.com/lbryio/lbrycrd/releases)
## Installation
Create a bot and get the bot's API Token: https://discordapp.com/developers/applications/me
Install LBRYCrd
```
$ unzip ~/lbrycrd-linux.zip
```
Follow the instructions on the LBRYCrds GitHub Repository to create a lbrycrd.conf and remember the username and password.
Edit and rename default.json.example in /config, then run:
Start LBRYCrd
```
./lbrycrdd -server -daemon
```
Create a bot and get the bot's API Token: https://discordapp.com/developers/applications/me - ![](https://i.imgur.com/gM8EpJe.png)
Make sure the bot has "bot" flags in OAuth2
```
npm install
node bot.js
$ cd lbry-tipbot/config
```
Then
```
$ vim default.json.example
```
Input your bot's token, the channel ID for your bot command channel, and the username & password for LBRYCrd
. Then, Rename the configuration file to "default.json" with
```
$ mv default.json.example default.json
```
Then run yarn install from within lbry-tipbot directory
```
yarn install
yarn start
```
## License
[MIT](https://github.com/lbryio/lbry-tipbot/blob/master/LICENSE)

View file

@ -2,7 +2,16 @@
"bot": {
"token": "discordbottoken",
"prefix": "!",
"debug": false
"debug": true,
"intents": [
"guilds",
"guildEmojis",
"guildMembers",
"guildMessages",
"guildMessageReactions",
"directMessages",
"directMessageReactions"
]
},
"lbrycrd": {
"port": 9245,

2451
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,35 +1,33 @@
{
"dependencies": {
"babel-cli": "^6.26.0",
"babel-preset-node8": "^1.2.0",
"bitcoin": "^3.0.1",
"chrono-node": "^1.3.5",
"config": "^1.30.0",
"discord.js": "^11.3.2",
"embed-creator": "^1.2.3",
"jsonpath": "^1.0.0",
"moment": "^2.22.1",
"mongoose": "^5.0.17",
"chrono-node": "^2.1.9",
"config": "^3.3.2",
"discord.js": "^12.4.1",
"jsonpath": "^1.0.2",
"moment": "^2.29.1",
"needle": "^2.5.2",
"node-config": "^0.0.2",
"numeral": "^2.0.6",
"regex": "^0.1.1",
"request": "^2.85.0"
"numeral": "^2.0.6"
},
"scripts": {
"prettier": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240",
"build": "babel bot -d dist",
"prod": "babel bot -d dist & node dist/bot.js",
"build": "tsc",
"start": "tsc && node dist/bot.js",
"lint": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240",
"precommit": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240"
},
"devDependencies": {
"prettier": "^1.12.1"
"@types/config": "^0.0.36",
"@types/node": "^14.14.7",
"prettier": "^2.1.2",
"typescript": "latest"
},
"name": "lbry-tipbot",
"version": "0.0.4",
"version": "0.0.5",
"description": "LBRYs tipbot for Discord",
"main": "app.js",
"main": "dist/bot.js",
"repository": "https://github.com/lbryio/lbry-tipbot",
"author": "filipnyquist <filip@lbry.io>",
"author": "filipnyquist <filip@lbry.com>",
"license": "MIT"
}

View file

@ -1,16 +1,14 @@
'use strict';
import Discord from 'discord.js';
import config from 'config';
import { BotConfig } from './typings';
// Load up libraries
const Discord = require('discord.js');
// Load config!
let config = require('config');
let botConfig = config.get('bot');
let botConfig: BotConfig = config.get('bot');
let commands = {};
const bot = new Discord.Client();
bot.on('ready', function() {
console.log(`Logged in! Serving in ${bot.guilds.array().length} servers`);
bot.on('ready', () => {
console.log(`Logged in! Serving in ${bot.guilds.cache.size} servers`);
require('./plugins.js').init();
console.log(`type ${botConfig.prefix}help in Discord for a commands list.`);
bot.user.setActivity(botConfig.prefix + 'tip');
@ -21,16 +19,16 @@ bot.on('disconnected', function() {
process.exit(1); //exit node.js with an error
});
function checkMessageForCommand(msg) {
bot.on('message', msg => {
//check if message is a command
if (msg.author.id !== bot.user.id && msg.content.startsWith(botConfig.prefix)) {
console.log(`treating ${msg.content} from ${msg.author} as command`);
let cmdTxt = msg.content.split(' ')[0].substring(botConfig.prefix.length);
let cmdTxt = msg.content.split(/ +/)[0].substring(botConfig.prefix.length);
let suffix = msg.content.substring(cmdTxt.length + botConfig.prefix.length + 1); //add one for the ! and one for the space
if (msg.isMentioned(bot.user)) {
if (msg.mentions.has(bot.user)) {
try {
cmdTxt = msg.content.split(' ')[1];
suffix = msg.content.substring(bot.user.mention().length + cmdTxt.length + botConfig.prefix.length + 1);
cmdTxt = msg.content.split(/ +/)[1];
suffix = msg.content.substring(bot.user.toString().length + cmdTxt.length + botConfig.prefix.length + 1);
} catch (e) {
//no command
return msg.channel.send('Yes?');
@ -55,14 +53,8 @@ function checkMessageForCommand(msg) {
if (msg.author === bot.user) {
return;
}
if (msg.author !== bot.user && msg.isMentioned(bot.user)) {
msg.channel.send('yes?'); //using a mention here can lead to looping
}
}
}
bot.on('message', msg => checkMessageForCommand(msg));
});
exports.addCommand = function(commandName, commandObject) {
try {

View file

@ -1,11 +1,10 @@
'use strict';
import { LBRYCrdConfig } from '../typings';
import config from 'config';
const Bitcoin = require('bitcoin');
const bitcoin = require('bitcoin');
let config = require('config');
let spamchannel = config.get('sandboxchannel');
let regex = require('regex');
let lbrycrdConfig = config.get('lbrycrd');
const lbry = new bitcoin.Client(lbrycrdConfig);
let spamchannel: string = config.get('sandboxchannel');
let lbrycrdConfig: LBRYCrdConfig = config.get('lbrycrd');
const lbry = new Bitcoin.Client(lbrycrdConfig);
const helpmsg = {
embed: {
description:
@ -13,19 +12,18 @@ const helpmsg = {
'**Balance**: `!tip balance`\n' +
'**Deposit Address**: `!tip deposit`\n' +
'**Withdraw**: `!tip withdraw <address> <amount>`\n' +
'**Private Tip**: `!privatetip <user> <amount>`\n\n' +
'**Private Tip**: `!tip private <user> <amount>`\n\n' +
'__**ROLE TIPS**__ Use this to tip everyone in a role.\n\n' +
'**Role Tip**: `!roletip <role> <amount>`\n' +
'**Private Role Tip**: `!privatetip <role> <amount>`\n\n' +
'__**MULTI TIPS**__ Use this to tip multiple people at once\n\n' +
'__**MULTI TIPS**__ Use this to tip multiple people at once.\n\n' +
'**Multi Tip**: `!multitip <user> <user> <amount>`\n' +
'**Private Multi Tip** `!multitip private <user> <user> <amount>`\n' +
'**Note**: Multi tips can contain any amount of users to tip.\n\n' +
'__**FURTHER INFORMATION**__\n\n' +
'**Help**: `!tip help` *Get this message.\n' +
'Read our [Tipbot FAQ](https://lbry.io/faq/tipbot-discord) for a more details',
color: 1109218,
author: { name: '!tip' }
'Read our [Tipbot FAQ](<https://lbry.com/faq/tipbot-discord>) for more details',
color: 1109218
}
};
@ -34,10 +32,10 @@ exports.tip = {
usage: '<subcommand>',
description: 'Tip a given user with an amount of LBC or perform wallet specific operations.',
process: async function(bot, msg, suffix) {
let tipper = msg.author.id.replace('!', ''),
let tipper = msg.author.id,
words = msg.content
.trim()
.split(' ')
.split(/ +/)
.filter(function(n) {
return n !== '';
}),
@ -49,7 +47,7 @@ exports.tip = {
privateOrSandboxOnly(msg, channelwarning, doHelp, [helpmsg]);
break;
case 'balance':
doBalance(msg, tipper);
privateOrSandboxOnly(msg, channelwarning, doBalance, [tipper]);
break;
case 'deposit':
privateOrSandboxOnly(msg, channelwarning, doDeposit, [tipper]);
@ -70,7 +68,7 @@ exports.multitip = {
let tipper = msg.author.id.replace('!', ''),
words = msg.content
.trim()
.split(' ')
.split(/ +/)
.filter(function(n) {
return n !== '';
}),
@ -90,12 +88,12 @@ exports.multitip = {
exports.roletip = {
usage: '<subcommand>',
description: 'Tip every user in a given role the same amount of LBC.',
description: 'Tip all users in a specified role an amount of LBC.',
process: async function(bot, msg, suffix) {
let tipper = msg.author.id.replace('!', ''),
words = msg.content
.trim()
.split(' ')
.split(/ +/)
.filter(function(n) {
return n !== '';
}),
@ -115,7 +113,7 @@ exports.roletip = {
exports.tips = {
usage: '',
description: 'Lists all available tipbot commands with brief descriptions for each one.',
description: 'Lists all available tipbot commands with brief descriptions for each command.',
process: async function(bot, msg, suffix) {
msg.reply(helpmsg);
}
@ -133,12 +131,13 @@ function doHelp(message, helpmsg) {
message.author.send(helpmsg);
}
function doBalance(message, tipper) {
async function doBalance(message, tipper) {
lbry.getBalance(tipper, 1, function(err, balance) {
if (err) {
message.reply('Error getting balance.').then(message => message.delete(5000));
console.error(err);
message.reply('Error getting balance.').then(message => message.delete({timeout: 5000}));
} else {
message.reply(`You have *${balance}* LBC`);
message.reply(`You have *${balance}* LBC. This may not reflect recent balance changes. Please wait a couple minutes and try again.`);
}
});
}
@ -146,7 +145,8 @@ function doBalance(message, tipper) {
function doDeposit(message, tipper) {
getAddress(tipper, function(err, address) {
if (err) {
message.reply('Error getting your deposit address.').then(message => message.delete(5000));
console.error(err);
message.reply('Error getting your deposit address.').then(message => message.delete({timeout: 5000}));
} else {
message.reply(`Your address is ${address}`);
}
@ -162,15 +162,15 @@ function doWithdraw(message, tipper, words, helpmsg) {
amount = getValidatedAmount(words[3]);
if (amount === null) {
message.reply("I don't know how to withdraw that many credits...").then(message => message.delete(5000));
message.reply('Invalid amount of credits specified... Cannot withdraw credits.').then(message => message.delete({timeout: 5000}));
return;
}
lbry.sendFrom(tipper, address, amount, function(err, txId) {
if (err) {
return message.reply(err.message).then(message => message.delete(5000));
return message.reply(err.message).then(message => message.delete({timeout: 5000}));
}
message.reply(`You withdrew ${amount} LBC to ${address}.
message.reply(`${amount} LBC has been withdrawn to ${address}.
${txLink(txId)}`);
});
}
@ -190,13 +190,13 @@ function doTip(bot, message, tipper, words, helpmsg, MultiorRole) {
let amount = getValidatedAmount(words[amountOffset]);
if (amount === null) {
return message.reply("I don't know how to tip that many credits...").then(message => message.delete(5000));
return message.reply('Invalid amount of credits specified...').then(message => message.delete({timeout: 5000}));
}
if (message.mentions.users.first() && message.mentions.users.first().id) {
return sendLBC(bot, message, tipper, message.mentions.users.first().id.replace('!', ''), amount, prv, MultiorRole);
}
message.reply('Sorry, I could not find a user in your tip...');
message.reply('Sorry, I could not find the user you are trying to tip...');
}
function doMultiTip(bot, message, tipper, words, helpmsg, MultiorRole) {
@ -214,11 +214,11 @@ function doMultiTip(bot, message, tipper, words, helpmsg, MultiorRole) {
}
let [userIDs, amount] = findUserIDsAndAmount(message, words, prv);
if (amount == null) {
message.reply("I don't know how to tip that many credits...").then(message => message.delete(5000));
message.reply('Invalid amount of credits specified...').then(message => message.delete({timeout: 5000}));
return;
}
if (!userIDs) {
message.reply('Sorry, I could not find a user in your tip...').then(message => message.delete(5000));
if (!userIDs.length) {
message.reply('Sorry, I could not find the user you are trying to tip...').then(message => message.delete({timeout: 5000}));
return;
}
for (let i = 0; i < userIDs.length; i++) {
@ -231,28 +231,28 @@ function doRoleTip(bot, message, tipper, words, helpmsg, MultiorRole) {
doHelp(message, helpmsg);
return;
}
let prv = false;
let amountOffset = 2;
if (words.length >= 4 && words[1] === 'private') {
prv = true;
amountOffset = 3;
}
let isPrivateTip = words.length >= 4 && words[1] === 'private';
let amountOffset = isPrivateTip ? 3 : 2;
let amount = getValidatedAmount(words[amountOffset]);
if (amount == null) {
message.reply("I don't know how to tip that many LBC coins...").then(message => message.delete(10000));
if (amount === null) {
message.reply("I don't know how to tip that amount of LBC...").then(message => message.delete({timeout: 10000}));
return;
}
if (message.mentions.roles.first().id) {
if (message.mentions.roles.first().members.first().id) {
let userIDs = message.mentions.roles.first().members.map(member => member.user.id.replace('!', ''));
for (let i = 0; i < userIDs.length; i++) {
sendLBC(bot, message, tipper, userIDs[i].toString(), amount, prv, MultiorRole);
}
let roleToTip = message.mentions.roles.first();
if (roleToTip !== null) {
let membersOfRole = roleToTip.members.keyArray();
if (membersOfRole.length > 0) {
let userIDs = membersOfRole.map(member => member.replace('!', ''));
userIDs.forEach(u => {
sendLBC(bot, message, tipper, u, amount, isPrivateTip, MultiorRole);
});
} else {
return message.reply('Sorry, I could not find any users to tip in that role...').then(message => message.delete(10000));
return message.reply('Sorry, I could not find any users to tip in that role...').then(message => message.delete({timeout: 10000}));
}
} else {
return message.reply('Sorry, I could not find any roles in your tip...').then(message => message.delete(10000));
return message.reply('Sorry, I could not find any roles in your tip...').then(message => message.delete({timeout: 10000}));
}
}
@ -278,27 +278,27 @@ function findUserIDsAndAmount(message, words, prv) {
function sendLBC(bot, message, tipper, recipient, amount, privacyFlag, MultiorRole) {
getAddress(recipient.toString(), function(err, address) {
if (err) {
message.reply(err.message).then(message => message.delete(5000));
message.reply(err.message).then(message => message.delete({timeout: 5000}));
} else {
lbry.sendFrom(tipper, address, Number(amount), 1, null, null, function(err, txId) {
if (err) {
message.reply(err.message).then(message => message.delete(5000));
message.reply(err.message).then(message => message.delete({timeout: 5000}));
} else {
let tx = txLink(txId);
let msgtail = `
DM me with \`${message.content.split(' ', 1)[0]}\` for command specific instructions or with \`!tips\` for all available commands`;
DM me with \`!tips\` for all available commands or read our Tipbot FAQ <https://lbry.com/faq/tipbot-discord> for more details`;
if (privacyFlag) {
let usr = message.guild.members.find('id', recipient).user;
let authmsg = `You have just privately tipped @${usr.tag} ${amount} LBC.
let authmsg = `You have sent a private tip to @${usr.tag} with the amount of ${amount} LBC.
${tx}${msgtail}`;
message.author.send(authmsg);
if (message.author.id !== message.mentions.users.first().id) {
if (message.author.id !== usr.id) {
let recipientmsg = `You have just been privately tipped ${amount} LBC by @${message.author.tag}.
${tx}${msgtail}`;
usr.send(recipientmsg);
}
} else {
let generalmsg = `Wubba lubba dub dub! <@${tipper}> tipped <@${recipient}> ${amount} LBC.
let generalmsg = `just tipped <@${recipient}> ${amount} LBC.
${tx}${msgtail}`;
message.reply(generalmsg);
}
@ -307,7 +307,6 @@ ${tx}${msgtail}`;
}
});
}
function getAddress(userId, cb) {
lbry.getAddressesByAccount(userId, function(err, addresses) {
if (err) {
@ -331,13 +330,10 @@ function inPrivateOrBotSandbox(msg) {
}
function getValidatedAmount(amount) {
amount = amount.trim();
if (amount.toLowerCase().endsWith('lbc')) {
amount = amount.substring(0, amount.length - 3);
}
amount = amount.toLowerCase().replace('lbc', '');
return amount.match(/^[0-9]+(\.[0-9]+)?$/) ? amount : null;
}
function txLink(txId) {
return '<https://explorer.lbry.io/tx/' + txId + '>';
return '<https://explorer.lbry.com/tx/' + txId + '>';
}

View file

@ -1,7 +1,5 @@
'use strict';
const fs = require('fs'),
path = require('path');
import fs from 'fs';
import path from 'path';
function getPlugins(srcpath) {
return fs.readdirSync(srcpath);
@ -9,7 +7,7 @@ function getPlugins(srcpath) {
let plugin_directory = path.join(__dirname, 'modules');
let plugins = getPlugins(plugin_directory);
exports.init = function init() {
export function init() {
load_plugins();
};

18
src/typings.ts Normal file
View file

@ -0,0 +1,18 @@
export interface Config {
bot: BotConfig;
lbrycrd: LBRYCrdConfig;
sandboxchannel: string;
}
export interface BotConfig {
token: string;
prefix: string;
debug: boolean;
intents: string[];
}
export interface LBRYCrdConfig {
port: number;
user: string;
pass: string;
}

16
tsconfig.json Normal file
View file

@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"inlineSourceMap": true,
"baseUrl": ".",
"outDir": "dist",
"removeComments": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"paths": {
"*": ["node_modules/*"]
}
},
"include": ["src/**/*"]
}

1890
yarn.lock

File diff suppressed because it is too large Load diff