Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fb8fc88101 | |||
| 6ca1254c9a | |||
| 38483cbbeb | |||
| 0203cb1a62 | |||
| 797fddfafb | |||
| 82fe54b90a | |||
| 4a8ea160a8 | |||
| 17543cb67b | |||
| 9bd875acba | |||
| cae2bd84b2 |
52
index.js
52
index.js
@@ -47,23 +47,35 @@ const Web3 = require('web3');
|
|||||||
|
|
||||||
robot.logger.info('[hubot-kredits] Wallet address: ' + hubotWalletAddress);
|
robot.logger.info('[hubot-kredits] Wallet address: ' + hubotWalletAddress);
|
||||||
|
|
||||||
web3.eth.getBalance(hubotWalletAddress, function (err, balance) {
|
getBalance().then(balance => {
|
||||||
if (err) { robot.logger.error('[hubot-kredits] Error checking balance'); return; }
|
|
||||||
if (balance <= 0) {
|
if (balance <= 0) {
|
||||||
robot.logger.info('[hubot-kredits] Hubot is broke. Please send some ETH to ' + hubotWalletAddress);
|
messageRoom(`Yo gang, I\'m broke! Please drop me some ETH to ${hubotWalletAddress}. kthxbai.`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let getValueFromContract = function(contractMethod, ...args) {
|
function getBalance() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
web3.eth.getBalance(hubotWalletAddress, function (err, balance) {
|
||||||
|
if (err) {
|
||||||
|
robot.logger.error('[hubot-kredits] Error checking balance');
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(balance);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getValueFromContract(contractMethod, ...args) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
kredits[contractMethod](...args, (err, data) => {
|
kredits[contractMethod](...args, (err, data) => {
|
||||||
if (err) { reject(err); }
|
if (err) { reject(err); }
|
||||||
resolve(data);
|
resolve(data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
let getContributorData = function(i) {
|
function getContributorData(i) {
|
||||||
let promise = new Promise((resolve, reject) => {
|
let promise = new Promise((resolve, reject) => {
|
||||||
getValueFromContract('contributorAddresses', i).then(address => {
|
getValueFromContract('contributorAddresses', i).then(address => {
|
||||||
robot.logger.debug('address', address);
|
robot.logger.debug('address', address);
|
||||||
@@ -81,9 +93,9 @@ const Web3 = require('web3');
|
|||||||
}).catch(err => reject(err));
|
}).catch(err => reject(err));
|
||||||
});
|
});
|
||||||
return promise;
|
return promise;
|
||||||
};
|
}
|
||||||
|
|
||||||
let getContributors = function() {
|
function getContributors() {
|
||||||
return getValueFromContract('contributorsCount').then(contributorsCount => {
|
return getValueFromContract('contributorsCount').then(contributorsCount => {
|
||||||
let contributors = [];
|
let contributors = [];
|
||||||
|
|
||||||
@@ -93,9 +105,9 @@ const Web3 = require('web3');
|
|||||||
|
|
||||||
return Promise.all(contributors);
|
return Promise.all(contributors);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
let getContributorByGithubUser = function(username) {
|
function getContributorByGithubUser(username) {
|
||||||
let promise = new Promise((resolve, reject) => {
|
let promise = new Promise((resolve, reject) => {
|
||||||
getContributors().then(contributors => {
|
getContributors().then(contributors => {
|
||||||
let contrib = contributors.find(c => {
|
let contrib = contributors.find(c => {
|
||||||
@@ -109,7 +121,7 @@ const Web3 = require('web3');
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
return promise;
|
return promise;
|
||||||
};
|
}
|
||||||
|
|
||||||
function messageRoom(message) {
|
function messageRoom(message) {
|
||||||
robot.messageRoom(process.env.KREDITS_ROOM, message);
|
robot.messageRoom(process.env.KREDITS_ROOM, message);
|
||||||
@@ -217,16 +229,32 @@ const Web3 = require('web3');
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
robot.respond(/(got ETH)|(got gas)\?/i, res => {
|
||||||
|
getBalance().then(balance => {
|
||||||
|
if (balance <= 0) {
|
||||||
|
res.send(`HALP, I\'m totally broke! Not a single wei in my pocket.`);
|
||||||
|
}
|
||||||
|
else if (balance >= 1e+17) {
|
||||||
|
res.send(`my wallet contains ${web3.fromWei(balance, 'ether')} ETH`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.send(`I\'m almost broke! Only have ${web3.fromWei(balance, 'ether')} ETH left in my pocket. :(`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
robot.router.post('/incoming/kredits/github/'+process.env.KREDITS_WEBHOOK_TOKEN, (req, res) => {
|
robot.router.post('/incoming/kredits/github/'+process.env.KREDITS_WEBHOOK_TOKEN, (req, res) => {
|
||||||
let evt = req.header('X-GitHub-Event');
|
let evt = req.header('X-GitHub-Event');
|
||||||
let data = req.body;
|
let data = req.body;
|
||||||
robot.logger.debug(`Received GitHub hook. Event: ${evt}, action: ${data.action}`);
|
robot.logger.info(`Received GitHub hook. Event: ${evt}, action: ${data.action}`);
|
||||||
|
|
||||||
if (evt === 'pull_request' && data.action === 'closed') {
|
if (evt === 'pull_request' && data.action === 'closed') {
|
||||||
handleGitHubPullRequestClosed(data).then(() => res.send(200));
|
handleGitHubPullRequestClosed(data).then(() => res.send(200));
|
||||||
}
|
}
|
||||||
else if (evt === 'issues' && data.action === 'closed') {
|
else if (evt === 'issues' && data.action === 'closed') {
|
||||||
handleGitHubIssueClosed(data).then(() => res.send(200));
|
handleGitHubIssueClosed(data).then(() => res.send(200));
|
||||||
|
} else {
|
||||||
|
res.send(200);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hubot-kredits",
|
"name": "hubot-kredits",
|
||||||
"version": "1.3.0",
|
"version": "1.4.4",
|
||||||
"description": "Kosmos Kredits functionality for chat bots",
|
"description": "Kosmos Kredits functionality for chat bots",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user