Mass update to deps and move to typescript
This commit is contained in:
parent
0395ef7026
commit
f5c899aeb4
11 changed files with 460 additions and 5607 deletions
31
.eslintrc.json
Normal file
31
.eslintrc.json
Normal 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
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"deepscan.enable": true
|
||||||
|
}
|
|
@ -2,12 +2,21 @@
|
||||||
"bot": {
|
"bot": {
|
||||||
"token": "discordbottoken",
|
"token": "discordbottoken",
|
||||||
"prefix": "!",
|
"prefix": "!",
|
||||||
"debug": false
|
"debug": true,
|
||||||
|
"intents": [
|
||||||
|
"guilds",
|
||||||
|
"guildEmojis",
|
||||||
|
"guildMembers",
|
||||||
|
"guildMessages",
|
||||||
|
"guildMessageReactions",
|
||||||
|
"directMessages",
|
||||||
|
"directMessageReactions"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"lbrycrd": {
|
"lbrycrd": {
|
||||||
"port": 9245,
|
"port": 9245,
|
||||||
"user": "lbry",
|
"username": "lbry",
|
||||||
"pass": "lbry"
|
"password": "lbry"
|
||||||
},
|
},
|
||||||
"sandboxchannel": "#369896313082478594"
|
"sandboxchannel": "#369896313082478594"
|
||||||
}
|
}
|
||||||
|
|
3524
package-lock.json
generated
3524
package-lock.json
generated
File diff suppressed because it is too large
Load diff
33
package.json
33
package.json
|
@ -1,33 +1,32 @@
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-cli": "^6.26.0",
|
"bitcoin-core": "^3.0.0",
|
||||||
"babel-preset-node8": "^1.2.0",
|
"chrono-node": "^2.1.9",
|
||||||
"bitcoin": "^3.0.1",
|
"config": "^3.3.2",
|
||||||
"chrono-node": "^1.3.11",
|
"discord.js": "^12.4.1",
|
||||||
"config": "^3.1.0",
|
"jsonpath": "^1.0.2",
|
||||||
"discord.js": "^11.4.2",
|
"moment": "^2.29.1",
|
||||||
"embed-creator": "^1.2.4",
|
"needle": "^2.5.2",
|
||||||
"jsonpath": "^1.0.1",
|
|
||||||
"moment": "^2.24.0",
|
|
||||||
"mongoose": "^5.7.5",
|
|
||||||
"node-config": "^0.0.2",
|
"node-config": "^0.0.2",
|
||||||
"numeral": "^2.0.6",
|
"numeral": "^2.0.6"
|
||||||
"request": "^2.88.0"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prettier": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240",
|
"prettier": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240",
|
||||||
"build": "babel bot -d dist",
|
"build": "tsc",
|
||||||
"prod": "babel bot -d dist & node dist/bot.js",
|
"start": "tsc && node dist/bot.js",
|
||||||
"lint": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240",
|
"lint": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240",
|
||||||
"precommit": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240"
|
"precommit": "prettier --write '{bot,.}/**/*.{js,json}' --single-quote --print-width 240"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prettier": "^1.16.4"
|
"@types/config": "^0.0.36",
|
||||||
|
"@types/node": "^14.14.7",
|
||||||
|
"prettier": "^2.1.2",
|
||||||
|
"typescript": "latest"
|
||||||
},
|
},
|
||||||
"name": "lbry-tipbot",
|
"name": "lbry-tipbot",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"description": "LBRYs tipbot for Discord",
|
"description": "LBRYs tipbot for Discord",
|
||||||
"main": "app.js",
|
"main": "dist/bot.js",
|
||||||
"repository": "https://github.com/lbryio/lbry-tipbot",
|
"repository": "https://github.com/lbryio/lbry-tipbot",
|
||||||
"author": "filipnyquist <filip@lbry.com>",
|
"author": "filipnyquist <filip@lbry.com>",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
'use strict';
|
import Discord from 'discord.js';
|
||||||
|
import config from 'config';
|
||||||
|
import { BotConfig } from './typings';
|
||||||
|
|
||||||
// Load up libraries
|
let botConfig: BotConfig = config.get('bot');
|
||||||
const Discord = require('discord.js');
|
|
||||||
// Load config!
|
|
||||||
let config = require('config');
|
|
||||||
let botConfig = config.get('bot');
|
|
||||||
let commands = {};
|
let commands = {};
|
||||||
|
|
||||||
const bot = new Discord.Client();
|
const bot = new Discord.Client();
|
||||||
|
|
||||||
bot.on('ready', function() {
|
bot.on('ready', () => {
|
||||||
console.log(`Logged in! Serving in ${bot.guilds.array().length} servers`);
|
console.log(`Logged in! Serving in ${bot.guilds.cache.size} servers`);
|
||||||
require('./plugins.js').init();
|
require('./plugins.js').init();
|
||||||
console.log(`type ${botConfig.prefix}help in Discord for a commands list.`);
|
console.log(`type ${botConfig.prefix}help in Discord for a commands list.`);
|
||||||
bot.user.setActivity(botConfig.prefix + 'tip');
|
bot.user.setActivity(botConfig.prefix + 'tip');
|
||||||
|
@ -21,16 +19,16 @@ bot.on('disconnected', function() {
|
||||||
process.exit(1); //exit node.js with an error
|
process.exit(1); //exit node.js with an error
|
||||||
});
|
});
|
||||||
|
|
||||||
function checkMessageForCommand(msg) {
|
bot.on('message', msg => {
|
||||||
//check if message is a command
|
//check if message is a command
|
||||||
if (msg.author.id !== bot.user.id && msg.content.startsWith(botConfig.prefix)) {
|
if (msg.author.id !== bot.user.id && msg.content.startsWith(botConfig.prefix)) {
|
||||||
console.log(`treating ${msg.content} from ${msg.author} as command`);
|
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
|
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 {
|
try {
|
||||||
cmdTxt = msg.content.split(' ')[1];
|
cmdTxt = msg.content.split(' ')[1];
|
||||||
suffix = msg.content.substring(bot.user.mention().length + cmdTxt.length + botConfig.prefix.length + 1);
|
suffix = msg.content.substring(bot.user.toString().length + cmdTxt.length + botConfig.prefix.length + 1);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//no command
|
//no command
|
||||||
return msg.channel.send('Yes?');
|
return msg.channel.send('Yes?');
|
||||||
|
@ -56,13 +54,11 @@ function checkMessageForCommand(msg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.author !== bot.user && msg.isMentioned(bot.user)) {
|
if (msg.author !== bot.user && msg.mentions.has(bot.user)) {
|
||||||
msg.channel.send('yes?'); //using a mention here can lead to looping
|
msg.channel.send('yes?'); //using a mention here can lead to looping
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
bot.on('message', msg => checkMessageForCommand(msg));
|
|
||||||
|
|
||||||
exports.addCommand = function(commandName, commandObject) {
|
exports.addCommand = function(commandName, commandObject) {
|
||||||
try {
|
try {
|
|
@ -1,10 +1,10 @@
|
||||||
'use strict';
|
import { LBRYCrdConfig } from '../typings';
|
||||||
|
import config from 'config';
|
||||||
|
import BitcoinClient = require('bitcoin-core');
|
||||||
|
|
||||||
const bitcoin = require('bitcoin');
|
let spamchannel: string = config.get('sandboxchannel');
|
||||||
let config = require('config');
|
let lbrycrdConfig: LBRYCrdConfig = config.get('lbrycrd');
|
||||||
let spamchannel = config.get('sandboxchannel');
|
const lbry = new BitcoinClient(lbrycrdConfig);
|
||||||
let lbrycrdConfig = config.get('lbrycrd');
|
|
||||||
const lbry = new bitcoin.Client(lbrycrdConfig);
|
|
||||||
const helpmsg = {
|
const helpmsg = {
|
||||||
embed: {
|
embed: {
|
||||||
description:
|
description:
|
||||||
|
@ -32,7 +32,7 @@ exports.tip = {
|
||||||
usage: '<subcommand>',
|
usage: '<subcommand>',
|
||||||
description: 'Tip a given user with an amount of LBC or perform wallet specific operations.',
|
description: 'Tip a given user with an amount of LBC or perform wallet specific operations.',
|
||||||
process: async function(bot, msg, suffix) {
|
process: async function(bot, msg, suffix) {
|
||||||
let tipper = msg.author.id.replace('!', ''),
|
let tipper = msg.author.id,
|
||||||
words = msg.content
|
words = msg.content
|
||||||
.trim()
|
.trim()
|
||||||
.split(' ')
|
.split(' ')
|
||||||
|
@ -131,22 +131,24 @@ function doHelp(message, helpmsg) {
|
||||||
message.author.send(helpmsg);
|
message.author.send(helpmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function doBalance(message, tipper) {
|
async function doBalance(message, tipper) {
|
||||||
lbry.getBalance(tipper, 1, function(err, balance) {
|
try {
|
||||||
if (err) {
|
const balance = await lbry.getBalance({
|
||||||
console.error(err);
|
account: tipper,
|
||||||
message.reply('Error getting balance.').then(message => message.delete(5000));
|
minconf: 1
|
||||||
} else {
|
|
||||||
message.reply(`You have *${balance}* LBC. This may not reflect recent balance changes. Please wait a couple minutes and try again.`);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
message.reply(`You have *${balance}* LBC. This may not reflect recent balance changes. Please wait a couple minutes and try again.`);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
message.reply('Error getting balance.').then(message => message.delete({timeout: 5000}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doDeposit(message, tipper) {
|
function doDeposit(message, tipper) {
|
||||||
getAddress(tipper, function(err, address) {
|
getAddress(tipper, function(err, address) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
message.reply('Error getting your deposit address.').then(message => message.delete(5000));
|
message.reply('Error getting your deposit address.').then(message => message.delete({timeout: 5000}));
|
||||||
} else {
|
} else {
|
||||||
message.reply(`Your address is ${address}`);
|
message.reply(`Your address is ${address}`);
|
||||||
}
|
}
|
||||||
|
@ -162,13 +164,13 @@ function doWithdraw(message, tipper, words, helpmsg) {
|
||||||
amount = getValidatedAmount(words[3]);
|
amount = getValidatedAmount(words[3]);
|
||||||
|
|
||||||
if (amount === null) {
|
if (amount === null) {
|
||||||
message.reply('Invalid amount of credits specified... Cannot withdraw credits.').then(message => message.delete(5000));
|
message.reply('Invalid amount of credits specified... Cannot withdraw credits.').then(message => message.delete({timeout: 5000}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lbry.sendFrom(tipper, address, amount, function(err, txId) {
|
lbry.sendFrom(tipper, address, amount, function(err, txId) {
|
||||||
if (err) {
|
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(`${amount} LBC has been withdrawn to ${address}.
|
message.reply(`${amount} LBC has been withdrawn to ${address}.
|
||||||
${txLink(txId)}`);
|
${txLink(txId)}`);
|
||||||
|
@ -190,7 +192,7 @@ function doTip(bot, message, tipper, words, helpmsg, MultiorRole) {
|
||||||
let amount = getValidatedAmount(words[amountOffset]);
|
let amount = getValidatedAmount(words[amountOffset]);
|
||||||
|
|
||||||
if (amount === null) {
|
if (amount === null) {
|
||||||
return message.reply('Invalid amount of credits specified...').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) {
|
if (message.mentions.users.first() && message.mentions.users.first().id) {
|
||||||
|
@ -214,11 +216,11 @@ function doMultiTip(bot, message, tipper, words, helpmsg, MultiorRole) {
|
||||||
}
|
}
|
||||||
let [userIDs, amount] = findUserIDsAndAmount(message, words, prv);
|
let [userIDs, amount] = findUserIDsAndAmount(message, words, prv);
|
||||||
if (amount == null) {
|
if (amount == null) {
|
||||||
message.reply('Invalid amount of credits specified...').then(message => message.delete(5000));
|
message.reply('Invalid amount of credits specified...').then(message => message.delete({timeout: 5000}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!userIDs) {
|
if (!userIDs.length) {
|
||||||
message.reply('Sorry, I could not find the user you are trying to tip...').then(message => message.delete(5000));
|
message.reply('Sorry, I could not find the user you are trying to tip...').then(message => message.delete({timeout: 5000}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (let i = 0; i < userIDs.length; i++) {
|
for (let i = 0; i < userIDs.length; i++) {
|
||||||
|
@ -236,7 +238,7 @@ function doRoleTip(bot, message, tipper, words, helpmsg, MultiorRole) {
|
||||||
|
|
||||||
let amount = getValidatedAmount(words[amountOffset]);
|
let amount = getValidatedAmount(words[amountOffset]);
|
||||||
if (amount === null) {
|
if (amount === null) {
|
||||||
message.reply("I don't know how to tip that amount of LBC...").then(message => message.delete(10000));
|
message.reply("I don't know how to tip that amount of LBC...").then(message => message.delete({timeout: 10000}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,10 +251,10 @@ function doRoleTip(bot, message, tipper, words, helpmsg, MultiorRole) {
|
||||||
sendLBC(bot, message, tipper, u, amount, isPrivateTip, MultiorRole);
|
sendLBC(bot, message, tipper, u, amount, isPrivateTip, MultiorRole);
|
||||||
});
|
});
|
||||||
} else {
|
} 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 {
|
} 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,11 +280,11 @@ function findUserIDsAndAmount(message, words, prv) {
|
||||||
function sendLBC(bot, message, tipper, recipient, amount, privacyFlag, MultiorRole) {
|
function sendLBC(bot, message, tipper, recipient, amount, privacyFlag, MultiorRole) {
|
||||||
getAddress(recipient.toString(), function(err, address) {
|
getAddress(recipient.toString(), function(err, address) {
|
||||||
if (err) {
|
if (err) {
|
||||||
message.reply(err.message).then(message => message.delete(5000));
|
message.reply(err.message).then(message => message.delete({timeout: 5000}));
|
||||||
} else {
|
} else {
|
||||||
lbry.sendFrom(tipper, address, Number(amount), 1, null, null, function(err, txId) {
|
lbry.sendFrom(tipper, address, Number(amount), 1, null, null, function(err, txId) {
|
||||||
if (err) {
|
if (err) {
|
||||||
message.reply(err.message).then(message => message.delete(5000));
|
message.reply(err.message).then(message => message.delete({timeout: 5000}));
|
||||||
} else {
|
} else {
|
||||||
let tx = txLink(txId);
|
let tx = txLink(txId);
|
||||||
let msgtail = `
|
let msgtail = `
|
|
@ -1,7 +1,5 @@
|
||||||
'use strict';
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
const fs = require('fs'),
|
|
||||||
path = require('path');
|
|
||||||
|
|
||||||
function getPlugins(srcpath) {
|
function getPlugins(srcpath) {
|
||||||
return fs.readdirSync(srcpath);
|
return fs.readdirSync(srcpath);
|
||||||
|
@ -9,7 +7,7 @@ function getPlugins(srcpath) {
|
||||||
let plugin_directory = path.join(__dirname, 'modules');
|
let plugin_directory = path.join(__dirname, 'modules');
|
||||||
let plugins = getPlugins(plugin_directory);
|
let plugins = getPlugins(plugin_directory);
|
||||||
|
|
||||||
exports.init = function init() {
|
export function init() {
|
||||||
load_plugins();
|
load_plugins();
|
||||||
};
|
};
|
||||||
|
|
18
src/typings.ts
Normal file
18
src/typings.ts
Normal 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;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
}
|
16
tsconfig.json
Normal file
16
tsconfig.json
Normal 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/**/*"]
|
||||||
|
}
|
Loading…
Reference in a new issue