Started work on the next version of tipbot.
This commit is contained in:
parent
559478cc40
commit
2f348e2051
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -74,3 +74,5 @@ typings/
|
||||||
|
|
||||||
# Configurations
|
# Configurations
|
||||||
default.json
|
default.json
|
||||||
|
|
||||||
|
.idea/*
|
|
@ -23,7 +23,11 @@ yarn install
|
||||||
```
|
```
|
||||||
node index.js
|
node index.js
|
||||||
```
|
```
|
||||||
|
>If you want to move over accounts from the old tipbot format which used usernames as identifier, run move_helper.js:
|
||||||
|
```
|
||||||
|
node move_helper.js
|
||||||
|
```
|
||||||
|
>It will automatically move over the old accounts to the new id based system.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
15
index.js
15
index.js
|
@ -67,6 +67,10 @@ function checkTweet(tweet, msg) {
|
||||||
case "terms":
|
case "terms":
|
||||||
doTerms(tweet, msg);
|
doTerms(tweet, msg);
|
||||||
break;
|
break;
|
||||||
|
case "lbryian":
|
||||||
|
logger.info("Got a command with the old format, handling it...");
|
||||||
|
checkTweet(tweet, msg.splice(1));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +79,7 @@ async function doHelp(tweet, msg) {
|
||||||
let post = await T.post("statuses/update", {
|
let post = await T.post("statuses/update", {
|
||||||
status:
|
status:
|
||||||
`@${tweet.user.screen_name} `+
|
`@${tweet.user.screen_name} `+
|
||||||
"All commands should be called with @ + subcommand \n" +
|
`All commands should be called with ${config.get("bot.handle")} + subcommand \n` +
|
||||||
"help - Shows this command. \n" +
|
"help - Shows this command. \n" +
|
||||||
"balance - Get your balance. \n" +
|
"balance - Get your balance. \n" +
|
||||||
"deposit - Get address for your deposits. \n" +
|
"deposit - Get address for your deposits. \n" +
|
||||||
|
@ -92,6 +96,13 @@ async function doHelp(tweet, msg) {
|
||||||
}
|
}
|
||||||
async function doTerms(tweet, msg){
|
async function doTerms(tweet, msg){
|
||||||
// ADD terms
|
// ADD terms
|
||||||
|
await T.post("statuses/update", {
|
||||||
|
status:
|
||||||
|
`@${tweet.user.screen_name} `+
|
||||||
|
"There are no fees to use this bot except the automatic daemon fee. \n"+
|
||||||
|
"In no event shall LBRY Inc be responsible in the event of lost, stolen or misdirected funds.",
|
||||||
|
in_reply_to_status_id: tweet.id_str
|
||||||
|
});
|
||||||
}
|
}
|
||||||
async function doBalance(tweet, msg) {
|
async function doBalance(tweet, msg) {
|
||||||
try {
|
try {
|
||||||
|
@ -162,6 +173,7 @@ async function doTip(tweet, msg) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const userToTip = tweet.entities.user_mentions.find(u => `@${u.screen_name}` === msg[2]).id_str;
|
const userToTip = tweet.entities.user_mentions.find(u => `@${u.screen_name}` === msg[2]).id_str;
|
||||||
|
await getAddress(id(userToTip)) // Call this to ensure user has an account.
|
||||||
if (userToTip === null) {
|
if (userToTip === null) {
|
||||||
return await T.post("statuses/update", {
|
return await T.post("statuses/update", {
|
||||||
status: `@${tweet.user.screen_name} I could not find that user...`,
|
status: `@${tweet.user.screen_name} I could not find that user...`,
|
||||||
|
@ -206,6 +218,7 @@ async function getAddress(userId) {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getValidatedAmount(amount) {
|
function getValidatedAmount(amount) {
|
||||||
amount = amount.trim();
|
amount = amount.trim();
|
||||||
if (amount.toLowerCase().endsWith("lbc")) {
|
if (amount.toLowerCase().endsWith("lbc")) {
|
||||||
|
|
97
move_helper.js
Normal file
97
move_helper.js
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
// This file helps with moving over accounts from the old username system to the id system.
|
||||||
|
// It uses the same configuration files as index.js
|
||||||
|
// Checks for the old format, gets their id from twitter, creates new acc, moves balance.
|
||||||
|
const Twit = require("twit");
|
||||||
|
const config = require("config");
|
||||||
|
const winston = require("winston");
|
||||||
|
require("winston-daily-rotate-file");
|
||||||
|
const Client = require("bitcoin-core");
|
||||||
|
const lbry = new Client({
|
||||||
|
version: "0.12.0",
|
||||||
|
username: config.get("lbrycrd.username"),
|
||||||
|
password: config.get("lbrycrd.password"),
|
||||||
|
port: config.get("lbrycrd.port")
|
||||||
|
});
|
||||||
|
const logger = winston.createLogger({
|
||||||
|
level: "info",
|
||||||
|
format: winston.format.json(),
|
||||||
|
transports: [
|
||||||
|
new winston.transports.DailyRotateFile({
|
||||||
|
filename: "move-helper-%DATE%.log",
|
||||||
|
dirname: "./logs",
|
||||||
|
datePattern: "YYYY-MM-DD-HH",
|
||||||
|
zippedArchive: true,
|
||||||
|
maxSize: "20m",
|
||||||
|
maxFiles: "14d"
|
||||||
|
}),
|
||||||
|
new winston.transports.Console({
|
||||||
|
format: winston.format.simple(),
|
||||||
|
level: "debug"
|
||||||
|
})
|
||||||
|
]
|
||||||
|
});
|
||||||
|
let notSynced = [];
|
||||||
|
|
||||||
|
const T = new Twit({
|
||||||
|
consumer_key: config.get("twitter.consumer_key"),
|
||||||
|
consumer_secret: config.get("twitter.consumer_secret"),
|
||||||
|
access_token: config.get("twitter.access_token"),
|
||||||
|
access_token_secret: config.get("twitter.access_token_secret"),
|
||||||
|
timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests.
|
||||||
|
strictSSL: true // optional - requires SSL certificates to be valid.
|
||||||
|
});
|
||||||
|
|
||||||
|
async function main(){
|
||||||
|
let accs = await getAccounts();
|
||||||
|
logger.info(`Trying to move ${accs.length} accounts...`)
|
||||||
|
for (let i in accs){
|
||||||
|
try {
|
||||||
|
//Get user details from twitter.
|
||||||
|
let data = await T.get('users/show', { screen_name: accs[i] });
|
||||||
|
//Create a account for the user by id.
|
||||||
|
let usr = data.data.id_str;
|
||||||
|
await getAddress(id(usr));
|
||||||
|
//Move over from old account to the new account
|
||||||
|
const balanceFromOld = await lbry.getBalance(`twttr-${accs[i]}`);
|
||||||
|
if (balanceFromOld !== 0) {
|
||||||
|
let res = await lbry.move(
|
||||||
|
`twttr-${accs[i]}`,
|
||||||
|
id(usr),
|
||||||
|
Number(balanceFromOld)
|
||||||
|
);
|
||||||
|
// If move is successful, log it!
|
||||||
|
if (res) logger.info(`Transferred ${balanceFromOld} LBC from twttr-${accs[i]} to ${id(usr)}!`);
|
||||||
|
}
|
||||||
|
}catch(e){
|
||||||
|
logger.info(`Could not sync ${accs[i]}, error occured:`, e.allErrors);
|
||||||
|
notSynced.push({ user: accs[i], error: e.allErrors});
|
||||||
|
logger.info("Could not sync these:"+JSON.stringify(notSynced));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Get a list of all twitter accounts on lbrycrd.
|
||||||
|
async function getAccounts(){
|
||||||
|
let accs = await lbry.listAccounts();
|
||||||
|
accs = Object.entries(accs);
|
||||||
|
let accsArr = [];
|
||||||
|
for (let i in accs){
|
||||||
|
if(accs[i][0].startsWith('twttr-')) accsArr.push(accs[i][0].substring(6));
|
||||||
|
}
|
||||||
|
return accsArr;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getAddress(userId) {
|
||||||
|
try {
|
||||||
|
let uAddresses = await lbry.getAddressesByAccount(userId);
|
||||||
|
if (uAddresses.length > 0) return;
|
||||||
|
await lbry.getNewAddress(userId);
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function id(usrId){
|
||||||
|
return `t-${usrId}`;
|
||||||
|
}
|
||||||
|
main();
|
Loading…
Reference in a new issue