<commit_before>// Description:
//   Allows hubot query ethereum blockchain and few ethereum api
//
// Dependencies:
//   hubot-brain-redis
//
// Configuration:
//   none
//
// Commands:
//   ethereum balance
//   ethereum check <address>
//
// Author:
//   <NAME> <<EMAIL>> (https://edouard.schweisguth.fr)
//

var https = require("https");

var DEFAULT_PRICE_CURRENCY = "eur";
var SECOND_PRICE_CURRENCY = "usd";

function main(robot){
	
	var UNIT = 1000000000000000000;

	var hu = require("./lib/hubot_utils.js");
	hu.setRobot(robot);
	var eu = require("./lib/ethereum_utils.js");
	eu.setRobot(robot);
	var nanopool = require("./lib/nanopool.js");
	
	robot.hear(/ethereum( .*)?/i, function(res){
		if(res.message.rawText.match(/^ethereum/i)){

			res.match[1] = res.match[1].trim();
			switch(true){
				case /check/.test(res.match[1]):
					if(/\$|\€/.test(res.match[1])){
						console.info("€ or $ found");
						_checkByCurrency(res);
					}else{
						console.info("€ or $ NOT found");
						_check(res);
					}
					break;
				case /add/.test(res.match[1]):
					_addAddr(res);
					break;
				case /(rm)|(delete)|(remove)/.test(res.match[1]):
					_deleteAddr(res);
					break;
				case res.match[1] == "list":
					_getList(res);
					break;
				case /transaction (.*)/.test(res.match[1]):
					_getTransactionByAddr(res);
					break;
				case res.match[1] == "transaction":
					_getTransaction(res);
					break;
				case /nanopool (.*)/.test(res.match[1]):
					_getNanopoolBalanceByCurrency(res);
					break;
				case res.match[1] == "nanopool":
				case res.match[1] == "nanopool balance":
					_getNanopoolBalance(res);
					break;

				case /balance (.*)/.test(res.match[1]) :
					_getBalanceByCurrency(res);
					break;

				case res.match[1] == "balance" :
					_getBalance(res);
					break;

				case res.match[1] == "price":
					_getPrice(res);
					break;
				case res.match[1] == "version":
						res.send(require("./package.json").version);
					break;

				case res.match[1] == "?":
				case res.match[1] == "help":
					res.send(getHelp());
					break;
				case /convert (.*)/.test(res.match[1]):
					_getConvertion(res);
					break;

				default:
					res.send(getHelp());
					break;
			}
		}
	});

	function getHelp(){
		return [
			"Ethereum commands",
				" - add <address> : Attach address to your user",
				" - delete <address> : Delete address from your user",
				" - remove <address> : Alias for delete",
				" - rm <address> : Alias for delete",
				" - list : list addresses from the current user",
				" - balance : Get the balance of the current user",
				" - balance <€ or $> : Get the balance of the current user in the provided currency",
				" - nanopool [balance] : Get nanopool balance of the current user (if the miner has mined something)",
				" - nanopool <€ or $> : Get nanopool balance of the current user in the provided currency",
				" - transaction : List latest transaction of the current user",
				" - check <address> : Get balance from the address provided",
				" - price : value of ethereum",
				" - convert <value> <from> <to> : convert value from currency to another (<to> default = eth)") ",<commit_msg>add 'eth' shortcut to command<commit_after>// Description:
//   Allows hubot query ethereum blockchain and few ethereum api
//
// Dependencies:
//   hubot-brain-redis
//
// Configuration:
//   none
//
// Commands:
//   ethereum balance
//   ethereum check <address>
//
// Author:
//   <NAME> <<EMAIL>> (https://edouard.schweisguth.fr)
//

var https = require("https");

var DEFAULT_PRICE_CURRENCY = "eur";
var SECOND_PRICE_CURRENCY = "usd";

function main(robot){
	
	var UNIT = 1000000000000000000;

	var hu = require("./lib/hubot_utils.js");
	hu.setRobot(robot);
	var eu = require("./lib/ethereum_utils.js");
	eu.setRobot(robot);
	var nanopool = require("./lib/nanopool.js");
	
	robot.hear(/(?:ethereum|eth)( .*)?/i, function(res){
		if(res.message.rawText.match(/^(?:ethereum|eth)/i)){

			res.match[1] = res.match[1].trim();
			switch(true){
				case /check/.test(res.match[1]):
					if(/\$|\€/.test(res.match[1])){
						console.info("€ or $ found");
						_checkByCurrency(res);
					}else{
						console.info("€ or $ NOT found");
						_check(res);
					}
					break;
				case /add/.test(res.match[1]):
					_addAddr(res);
					break;
				case /(rm)|(delete)|(remove)/.test(res.match[1]):
					_deleteAddr(res);
					break;
				case res.match[1] == "list":
					_getList(res);
					break;
				case /transaction (.*)/.test(res.match[1]):
					_getTransactionByAddr(res);
					break;
				case res.match[1] == "transaction":
					_getTransaction(res);
					break;
				case /nanopool (.*)/.test(res.match[1]):
					_getNanopoolBalanceByCurrency(res);
					break;
				case res.match[1] == "nanopool":
				case res.match[1] == "nanopool balance":
					_getNanopoolBalance(res);
					break;

				case /balance (.*)/.test(res.match[1]) :
					_getBalanceByCurrency(res);
					break;

				case res.match[1] == "balance" :
					_getBalance(res);
					break;

				case res.match[1] == "price":
					_getPrice(res);
					break;
				case res.match[1] == "version":
						res.send(require("./package.json").version);
					break;

				case res.match[1] == "?":
				case res.match[1] == "help":
					res.send(getHelp());
					break;
				case /convert (.*)/.test(res.match[1]):
					_getConvertion(res);
					break;

				default:
					res.send(getHelp());
					break;
			}
		}
	});

	function getHelp(){
		return [
			"Ethereum commands",
				" - add <address> : Attach address to your user",
				" - delete <address> : Delete address from your user",
				" - remove <address> : Alias for delete",
				" - rm <address> : Alias for delete",
				" - list : list addresses from the current user",
				" - balance : Get the balance of the current user",
				" - balance <€ or $> : Get the balance of the current user in the provided currency",
				" - nanopool [balance] : Get nanopool balance of the current user (if the miner has mined something)",
				" - nanopool <€ or $> : Get nanopool balance of the current user in the provided currency",
				" - transaction : List latest transaction of the current user",
				" - check <address> : Get balance from the address provided",
				" - price : value of ethereum",
				" - convert <value> <from> <to> : convert value from currency to another (<to> default = eth)",
{'fraction_non_alphanumeric': 0.17040640200847323, 'fraction_numerical': 0.011925309901145457, 'mean_word_length': 2.7895362663495837, 'pattern_counts': {'":': 16, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2424459', 'n_tokens_mistral': 2764, 'n_tokens_neox': 2183, 'n_words': 530}