Exemple #1
0
def do_command(context, from_, target, command, args):
	nick = from_[0]
	nick = nick.lower()
	bot = context['bot']
	bitcoin = context['bitcoin']
	config = context['config']['roulette']
	wager = config['wager']
	winnings = config['winnings']
	try:
		if command == 'roulette':
			if not is_int(args[0]):
				bot.notice(nick, 'Please enter a valid chamber number')
				return
			chamber = int(args[0])
			if chamber < 1 or chamber > 6:
				bot.notice(nick, 'Please enter a valid chamber number 1-6')
				return
			balance = btc.getbalance(bitcoin, nick)
			if wager > balance:
				bot.notice(nick, 'Sorry, you don\'t have ' + str(wager) + ' BTC in your balance')
				return
			bitcoin.move(nick, 'roulette', wager)
			if roulette(chamber):
				roulette_bal = btc.getbalance(bitcoin, 'roulette')
				roulette_bal = roulette_bal * winnings
				bitcoin.move('roulette', nick, btc.to_float(roulette_bal))
				bot.notice(nick, 'The gun went *CLICK* and you won ' + btc.to_string(roulette_bal) + ' BTC.')
				bot.privmsg('##btcbot', from_[0] + '\'s gun went *CLICK*, winning them ' + btc.to_string(roulette_bal) + ' BTC.')
			else:
				bot.notice(nick, 'The gun went *BANG* and you lost ' + str(wager) + ' BTC.')

	except JSONRPCException:
		bot.notice(nick, 'An error has occured communicating with bitcoind, please report this to bool_')
Exemple #2
0
def do_command(context, from_, target, command, args):
	nick = from_[0]
	nick = nick.lower()
	bot = context['bot']
	bitcoin = context['bitcoin']
	try:
		if command == 'deposit':
			address = bitcoin.getaccountaddress(nick)
			bot.notice(nick, 'Your deposit address is: ' + address)
		if command == 'balance':
			balance = btc.getbalance(bitcoin, nick)
			bot.notice(nick, 'Your current balance is: ' + btc.to_string(balance))
		if command == 'withdraw':
			address = args[0]
			if len(address) < 31:
				new_address = resolve_firstbits(address)
				if new_address == None:
					bot.notify(nick, 'Sorry, that firstbits address could not be resolved, please use a bitcoin address')
					return
				address = new_address
			else:
				valid = bitcoin.validateaddress(address)['isvalid']
				if not valid:
					bot.notice(nick, 'Please enter a valid bitcoin address')
					return
			balance = btc.getbalance(bitcoin, nick)
			amount = balance
			if len(args) == 2:
				if not is_float(args[1]):
					bot.notice(nick, 'Please enter a valid amount')
					return
				amount = btc.to_btc(float(args[1]))
				if balance == 0:
					bot.notice(nick, 'You don\'t have any BTC to withdraw')
					return
				if amount > balance:
					bot.notice(nick, 'You can\'t withdraw more than ' + btc.to_string(balance) + ' BTC')
					return

			tx_id = bitcoin.sendfrom(nick, address, btc.to_float(amount))
			bot.notice(nick, 'Sent ' + btc.to_string(amount) + ' BTC to ' + address + ', transaction: ' + tx_id)
			balance = btc.getbalance(bitcoin, nick)
			if balance < 0: # take care of any tax that was applied
				bitcoin.move('buffer', nick, btc.to_float(abs(balance)))
	except JSONRPCException as ex:
		if ex.error['code'] == -4:
			bot.notice(nick, 'This transaction requires a fee of 0.0005, please subtract this from your withdrawl amount')
		bot.notice(nick, 'An error has occured communicating with bitcoind, please report this to bool_')
Exemple #3
0
def do_command(context, from_, target, command, args):
	nick = from_[0].lower()
	bot = context['bot']
	bitcoin = context['bitcoin']
	config = context['config']['raffle']
	ticket_price = config['ticket_price']
	tipping_point = config['tipping_point']
	try:
		if command == 'raffle':
			ticket_count = 1
			if len(args) > 0:
				if not is_int(args[0]):
					bot.notice(nick, 'Please enter a valid ticket count')
					return
				ticket_count = int(args[0])
			balance = btc.getbalance(bitcoin, nick)
			price = ticket_count * ticket_price
			price = btc.to_btc(price)
			if price > balance:
				bot.notice(nick, 'Sorry, you don\'t have ' + btc.to_string(price) + ' BTC in your balance')
				return
			bitcoin.move(nick, 'raffle', btc.to_float(price))
			for x in range(0, ticket_count):
				tickets.append(nick)
				random.shuffle(tickets)
			bot.notice(nick, 'You have purchased ' + str(ticket_count) + ' tickets for ' + btc.to_string(price) + ' BTC')
			if len(tickets) >= tipping_point:
				select_winner(context, bitcoin, from_[0])
	except JSONRPCException:
		bot.notice(nick, 'An error has occured communicating with bitcoind, please report this to bool_')
Exemple #4
0
def do_command(context, from_, target, command, args):
    nick = from_[0]
    nick = nick.lower()
    bot = context['bot']
    bitcoin = context['bitcoin']
    config = context['config']['roulette']
    wager = config['wager']
    winnings = config['winnings']
    try:
        if command == 'roulette':
            if not is_int(args[0]):
                bot.notice(nick, 'Please enter a valid chamber number')
                return
            chamber = int(args[0])
            if chamber < 1 or chamber > 6:
                bot.notice(nick, 'Please enter a valid chamber number 1-6')
                return
            balance = btc.getbalance(bitcoin, nick)
            if wager > balance:
                bot.notice(
                    nick, 'Sorry, you don\'t have ' + str(wager) +
                    ' BTC in your balance')
                return
            bitcoin.move(nick, 'roulette', wager)
            if roulette(chamber):
                roulette_bal = btc.getbalance(bitcoin, 'roulette')
                roulette_bal = roulette_bal * winnings
                bitcoin.move('roulette', nick, btc.to_float(roulette_bal))
                bot.notice(
                    nick, 'The gun went *CLICK* and you won ' +
                    btc.to_string(roulette_bal) + ' BTC.')
                bot.privmsg(
                    '##btcbot',
                    from_[0] + '\'s gun went *CLICK*, winning them ' +
                    btc.to_string(roulette_bal) + ' BTC.')
            else:
                bot.notice(
                    nick,
                    'The gun went *BANG* and you lost ' + str(wager) + ' BTC.')

    except JSONRPCException:
        bot.notice(
            nick,
            'An error has occured communicating with bitcoind, please report this to bool_'
        )
Exemple #5
0
def do_command(context, from_, target, command, args):
	nick = from_[0].lower()
	bot = context['bot']
	bitcoin = context['bitcoin']
	try:
		if command == 'ubalance':
			balance = btc.getbalance(bitcoin, args[0])
			bot.notice(nick, args[0] +'\'s current balance is: ' + btc.to_string(balance))
	except JSONRPCException:
		bot.notice(nick, 'An error has occured commincating with bitcoind, please report this to bool_')
Exemple #6
0
def do_command(context, from_, target, command, args):
    nick = from_[0].lower()
    bot = context['bot']
    bitcoin = context['bitcoin']
    try:
        if command == 'ubalance':
            balance = btc.getbalance(bitcoin, args[0])
            bot.notice(
                nick,
                args[0] + '\'s current balance is: ' + btc.to_string(balance))
    except JSONRPCException:
        bot.notice(
            nick,
            'An error has occured commincating with bitcoind, please report this to bool_'
        )
Exemple #7
0
def select_winner(context, bitcoin, nick):
	global tickets
	bot = context['bot']
	commission_mul = context['config']['raffle']['commission']
	winnings_mul = context['config']['raffle']['winnings']
	beneficiaries = context['config']['beneficiaries']
	winner = random.choice(tickets)
	balance = btc.getbalance(bitcoin, 'raffle')
	winnings = balance * winnings_mul
	commission = balance * commission_mul
	bitcoin.move('raffle', winner, btc.to_float(winnings))
	for name, mul in beneficiaries.items():
		bitcoin.move('raffle', name, btc.to_float(commission * mul))
	bot.notice(winner, 'Congratulations, you have won ' + btc.to_string(winnings) + ' BTC in the raffle!')
	bot.privmsg('##btcbot', 'Congratualtions to ' + winner + ' who has won ' + btc.to_string(winnings) + ' BTC in the raffle!')
	tickets = []
Exemple #8
0
def select_winner(context, bitcoin, nick):
    global tickets
    bot = context['bot']
    commission_mul = context['config']['raffle']['commission']
    winnings_mul = context['config']['raffle']['winnings']
    beneficiaries = context['config']['beneficiaries']
    winner = random.choice(tickets)
    balance = btc.getbalance(bitcoin, 'raffle')
    winnings = balance * winnings_mul
    commission = balance * commission_mul
    bitcoin.move('raffle', winner, btc.to_float(winnings))
    for name, mul in beneficiaries.items():
        bitcoin.move('raffle', name, btc.to_float(commission * mul))
    bot.notice(
        winner, 'Congratulations, you have won ' + btc.to_string(winnings) +
        ' BTC in the raffle!')
    bot.privmsg(
        '##btcbot', 'Congratualtions to ' + winner + ' who has won ' +
        btc.to_string(winnings) + ' BTC in the raffle!')
    tickets = []
Exemple #9
0
def do_command(context, from_, target, command, args):
    nick = from_[0].lower()
    bot = context['bot']
    bitcoin = context['bitcoin']
    config = context['config']['raffle']
    ticket_price = config['ticket_price']
    tipping_point = config['tipping_point']
    try:
        if command == 'raffle':
            ticket_count = 1
            if len(args) > 0:
                if not is_int(args[0]):
                    bot.notice(nick, 'Please enter a valid ticket count')
                    return
                ticket_count = int(args[0])
            balance = btc.getbalance(bitcoin, nick)
            price = ticket_count * ticket_price
            price = btc.to_btc(price)
            if price > balance:
                bot.notice(
                    nick, 'Sorry, you don\'t have ' + btc.to_string(price) +
                    ' BTC in your balance')
                return
            bitcoin.move(nick, 'raffle', btc.to_float(price))
            for x in range(0, ticket_count):
                tickets.append(nick)
                random.shuffle(tickets)
            bot.notice(
                nick, 'You have purchased ' + str(ticket_count) +
                ' tickets for ' + btc.to_string(price) + ' BTC')
            if len(tickets) >= tipping_point:
                select_winner(context, bitcoin, from_[0])
    except JSONRPCException:
        bot.notice(
            nick,
            'An error has occured communicating with bitcoind, please report this to bool_'
        )
Exemple #10
0
def do_command(context, from_, target, command, args):
    nick = from_[0]
    nick = nick.lower()
    bot = context['bot']
    bitcoin = context['bitcoin']
    try:
        if command == 'deposit':
            address = bitcoin.getaccountaddress(nick)
            bot.notice(nick, 'Your deposit address is: ' + address)
        if command == 'balance':
            balance = btc.getbalance(bitcoin, nick)
            bot.notice(nick,
                       'Your current balance is: ' + btc.to_string(balance))
        if command == 'withdraw':
            address = args[0]
            if len(address) < 31:
                new_address = resolve_firstbits(address)
                if new_address == None:
                    bot.notify(
                        nick,
                        'Sorry, that firstbits address could not be resolved, please use a bitcoin address'
                    )
                    return
                address = new_address
            else:
                valid = bitcoin.validateaddress(address)['isvalid']
                if not valid:
                    bot.notice(nick, 'Please enter a valid bitcoin address')
                    return
            balance = btc.getbalance(bitcoin, nick)
            amount = balance
            if len(args) == 2:
                if not is_float(args[1]):
                    bot.notice(nick, 'Please enter a valid amount')
                    return
                amount = btc.to_btc(float(args[1]))
                if balance == 0:
                    bot.notice(nick, 'You don\'t have any BTC to withdraw')
                    return
                if amount > balance:
                    bot.notice(
                        nick, 'You can\'t withdraw more than ' +
                        btc.to_string(balance) + ' BTC')
                    return

            tx_id = bitcoin.sendfrom(nick, address, btc.to_float(amount))
            bot.notice(
                nick, 'Sent ' + btc.to_string(amount) + ' BTC to ' + address +
                ', transaction: ' + tx_id)
            balance = btc.getbalance(bitcoin, nick)
            if balance < 0:  # take care of any tax that was applied
                bitcoin.move('buffer', nick, btc.to_float(abs(balance)))
    except JSONRPCException as ex:
        if ex.error['code'] == -4:
            bot.notice(
                nick,
                'This transaction requires a fee of 0.0005, please subtract this from your withdrawl amount'
            )
        bot.notice(
            nick,
            'An error has occured communicating with bitcoind, please report this to bool_'
        )