def process_message(self, args, user): if len(args) == 0: return docs.rain_msg.format(round(self.RBOT.balance, 8), round(self.thresh, 8), self.RBOT.address) if 0 < len(args) < 2: return give(args[0], user, self.RBOT, add_success_msg='\n\nThank you for raining on the users!', donation=True) return '{}Too many arguments provided'.format(e.CANNOT)
async def do_rain(self, UDB, client): ulist = [uid for uid in UDB] online = set() bias = uniform(0.001, 0.01) rain_amt = round(self.RBOT.balance - bias, 8) for member in client.get_all_members(): if member.status == discord.Status.online and member.id in ulist: online.add(member.id) online = list(online) for i, val in enumerate(self.get_rain_vals(len(online), bias)): give(val, self.RBOT, UDB[online[i]]) big_string = '{}Rained `{} GRC`\n'.format(e.RAIN, rain_amt) for user in online: big_string += '<@{}>\n'.format(user) if len(big_string) >= 2000: big_string = '{}Rainbot has rained `{} GRC` on {} users. See if you are lucky!'.format(e.RAIN, rain_amt, len(online)) await client.send_message(client.get_channel(g.RAIN_CHAN), big_string) self.get_next_thresh()
async def on_message(msg): global UDB cmd = msg.content chan = msg.channel uname = msg.author.name user = msg.author.id INDB = user in UDB iscommand = cmd.startswith(g.pre) if iscommand and (len(cmd) > 1): cmd = cmd[1:] if chan.is_private: logging.info('COMMAND "%s" executed by %s (%s) in private channel', cmd.split()[0], user, uname) else: logging.info('COMMAND "%s" executed by %s (%s)', cmd.split()[0], user, uname) if cmd.startswith('status'): await client.send_message(chan, await bot.dump_cfg(price_fetcher)) elif cmd.startswith('new'): if not INDB: await client.send_message( chan, '{}Creating your account now...'.format(e.SETTING)) status, reply, userobj = await bot.new_user(user) if status == 0: UDB[user] = userobj await client.send_message(chan, reply) else: await client.send_message( chan, '{}Cannot create new account, you already have one.'. format(e.CANNOT)) elif cmd.startswith('help'): await client.send_message(chan, bot.help_interface(cmd.split().pop())) elif cmd.startswith('info'): await client.send_message(chan, docs.info) elif INDB: USROBJ = UDB[user] if cmd in ['bal', 'balance']: await client.send_message( chan, await bot.fetch_balance(USROBJ, price_fetcher)) elif cmd.startswith('addr'): await client.send_message(chan, USROBJ.address) elif cmd.split()[0] in ['wdr', 'withdraw', 'send']: args = cmd.split()[1:] if len(args) == 2: reply = await bot.withdraw(args[1], args[0], USROBJ) else: reply = '{}To withdraw from your account type: `%wdr [address to send to] [amount-GRC]`\nA service fee of {} GRC is subtracted from what you send. If you wish to send GRC to someone in the server, use `%give`'.format( e.INFO, str(g.tx_fee)) await client.send_message(chan, reply) elif cmd.startswith('donate'): args = cmd.split()[1:] if len(args) == 2: reply = await bot.donate(args[0], args[1], USROBJ) else: reply = bot.fetch_donation_addrs() await client.send_message(chan, reply) elif cmd.startswith('rdonate'): args = cmd.split()[1:] if len(args) == 1: reply = await bot.rdonate(args[0], USROBJ) else: reply = '{}To donate to a random contributor type: `%rdonate [amount-GRC]`'.format( e.GIVE) await client.send_message(chan, reply) elif cmd.startswith('give'): args = cmd.split()[1:] if chan.is_private: await client.send_message(chan, docs.PM_msg) elif (len(args) != 2) or (len(msg.mentions) != 1): await client.send_message( chan, '{}To give funds to a member in the server, type `%give [discord mention of user] [amount to give]`.\nThe person must also have an account with the bot.' .format(e.INFO)) elif not msg.mentions[0].id in UDB: await client.send_message( chan, '{}Invalid user specified.'.format(e.ERROR)) else: await client.send_message( chan, bot.give(args[1], USROBJ, UDB[msg.mentions[0].id])) elif cmd.startswith('fgive'): args = cmd.split()[1:] if len(args) < 1: await client.send_message( chan, '{}Please specify an amount to give.'.format(e.ERROR)) else: await client.send_message( chan, bot.give(args[0], USROBJ, UDB[FCT], add_success_msg= '\n\nThank you for donating to the faucet!', donation=True)) elif cmd in ['faucet', 'fct', 'get']: fctobj = UDB[FCT] await client.send_message( chan, docs.faucetmsg.format(round(fctobj.balance, 8), g.FCT_REQ_LIM, fctobj.address)) if chan.is_private: await client.send_message(chan, docs.PM_msg) else: await client.send_message(chan, bot.faucet(fctobj, USROBJ)) elif cmd.startswith('qr'): args = cmd.split()[1:] if chan.is_private: await client.send_message(chan, docs.PM_msg) elif len(args) == 1: await client.send_file( chan, bot.get_qr(args[0], filename=user + '.png')) elif len(args) > 1: await client.send_message( chan, '{}Too many arguments provided'.format(e.CANNOT)) else: await client.send_file(chan, bot.get_qr(USROBJ.address), filename=user + '.png') elif cmd.startswith('bin {}'.format(user)): args = cmd.split()[2:] if len(args) > 0 and chan.is_private: amt = 0 if (bot.amt_filter(args[0], USROBJ) == None) else bot.amt_filter(args[0], USROBJ) USROBJ.balance -= amt await client.send_message(chan, 'Burned `{} GRC`'.format(amt)) else: await client.send_message( chan, '{}Invalid command. Type `%help` for help.'.format(e.INFO)) else: await client.send_message( chan, '{}Either incorrect command or not in user database (try `%new` or type `%help` for help)' .format(e.ERROR))
run = True else: print('Incorrect argument supplied (try -y?)') run = False else: run = bf.ask_to_play() while run: command = input( 'What would you like to do? Type help for options. ').lower() if command == 'help': commands.help() elif command == 'give': hotbar = commands.give(hotbar) elif command == 'quit': run = commands.quit() elif command == 'remove': hotbar = commands.remove(hotbar) elif command == 'see': for s in hotbar: print(s) elif command == 'add': hotbar = commands.add(hotbar) elif command == 'creeper':
async def on_message(msg): global UDB cmd = msg.content chan = msg.channel a = msg.author uname = a.name user = a.id INDB = user in UDB iscommand = cmd.startswith(g.pre) if a.bot or checkspam(user) or blacklister.is_banned( user, chan.is_private): pass elif iscommand and user_is_new(a.created_at): await client.send_message(chan, docs.new_usr_msg) elif iscommand and (len(cmd) > 1): cmd = cmd[1:] if chan.is_private: logging.info('COMMAND "%s" executed by %s (%s) in private channel', cmd.split()[0], user, uname) else: logging.info('COMMAND "%s" executed by %s (%s)', cmd.split()[0], user, uname) if cmd.startswith('status'): await client.send_message(chan, await bot.dump_cfg(price_fetcher)) elif cmd.startswith('new'): if not INDB: await client.send_message(chan, docs.welcome) status, reply, userobj = await bot.new_user(user) if status == 0: UDB[user] = userobj await client.send_message(chan, reply) await client.send_message(await client.start_private_message(a), embed=docs.rules) await client.send_message(await client.start_private_message(a), embed=docs.terms) else: await client.send_message( chan, '{}Cannot create new account, you already have one.'. format(e.CANNOT)) elif cmd.startswith('help'): await client.send_message(chan, bot.help_interface(cmd.split().pop())) elif cmd.startswith('info'): await client.send_message(chan, embed=docs.info) elif cmd.startswith('faq'): reply = bot.faq(cmd.split()[1:]) if type(reply) is str: await client.send_message(chan, reply) else: await client.send_message(await client.start_private_message(a), embed=reply) await client.add_reaction(msg, '✅') elif cmd.startswith('rule'): await client.send_message(await client.start_private_message(a), embed=docs.rules) await client.add_reaction(msg, '✅') elif cmd.startswith('term'): await client.send_message(await client.start_private_message(a), embed=docs.terms) await client.add_reaction(msg, '✅') elif INDB: USROBJ = UDB[user] if cmd in ['bal', 'balance']: await client.send_message( chan, await bot.fetch_balance(USROBJ, price_fetcher)) elif cmd.startswith('addr'): await client.send_message(chan, USROBJ.address) elif cmd.split()[0] in ['wdr', 'withdraw', 'send']: args = cmd.split()[1:] if len(args) == 2: reply = await bot.withdraw(args[1], args[0], USROBJ) else: reply = '{}To withdraw from your account type: `%wdr [address to send to] [amount-GRC]`\nA service fee of {} GRC is subtracted from what you send. If you wish to send GRC to someone in the server, use `%give`'.format( e.INFO, str(g.tx_fee)) await client.send_message(chan, reply) elif cmd.startswith('donate'): args = cmd.split()[1:] if len(args) == 2: reply = await bot.donate(args[0], args[1], USROBJ) else: reply = bot.index_displayer( '{}Be generous! Below are possible donation options.\nTo donate, type `%donate [selection no.] [amount-GRC]`\n' .format(e.GIVE), g.donation_accts) await client.send_message(chan, reply) elif cmd.startswith('rdonate'): args = cmd.split()[1:] if len(args) == 1: reply = await bot.rdonate(args[0], USROBJ) else: reply = '{}To donate to a random contributor type: `%rdonate [amount-GRC]`'.format( e.GIVE) await client.send_message(chan, reply) elif cmd.split()[0] in ['give', 'tip']: args = cmd.split()[1:] if chan.is_private: await client.send_message(chan, docs.PM_msg) elif (len(args) != 2) or (len(msg.mentions) != 1): await client.send_message( chan, '{}To give funds to a member in the server, type `%give [discord mention of user] [amount to give]`.\nThe person must also have an account with the bot.' .format(e.INFO)) elif not msg.mentions[0].id in UDB: await client.send_message( chan, '{}Invalid user specified.'.format(e.ERROR)) else: await client.send_message( chan, bot.give(args[1], USROBJ, UDB[msg.mentions[0].id])) elif cmd.startswith('fgive'): args = cmd.split()[1:] if len(args) < 1: await client.send_message( chan, '{}Please specify an amount to give.'.format(e.ERROR)) else: await client.send_message( chan, bot.give(args[0], USROBJ, UDB[FCT], add_success_msg= '\n\nThank you for donating to the faucet!', donation=True)) elif cmd in ['faucet', 'fct', 'get']: fctobj = UDB[FCT] await client.send_message( chan, docs.faucetmsg.format(round(fctobj.balance, 8), g.FCT_REQ_LIM, fctobj.address)) if chan.is_private: await client.send_message(chan, docs.PM_msg) else: await client.send_message(chan, bot.faucet(fctobj, USROBJ)) elif cmd.startswith('rain'): await client.send_message( chan, rbot.process_message(cmd.split()[1:], USROBJ)) elif cmd.startswith('qr'): args = cmd.split()[1:] if chan.is_private: await client.send_message(chan, docs.PM_msg) elif len(args) == 1: await client.send_file(chan, bot.get_qr(args[0]), filename=user + '.png') elif len(args) > 1: await client.send_message( chan, '{}Too many arguments provided'.format(e.CANNOT)) else: await client.send_file(chan, bot.get_qr(USROBJ.address), filename=user + '.png') elif cmd.startswith('time'): await client.send_message(chan, bot.check_times(USROBJ)) # ADMINISTRATION COMMANDS elif cmd.startswith( 'blist') and user == g.owner_id and chan.is_private: args = cmd.split()[1:] if len(args) > 0: await client.send_message( chan, bot.blist_iface(args, blacklister)) else: await client.send_message(chan, blacklister.get_blisted()) elif cmd.startswith( 'bin {}'.format(user) ) and chan.is_private: # 'Burns' GRC from your account args = cmd.split()[2:] if len(args) > 0: amt = 0 if (bot.amt_filter(args[0], USROBJ) == None) else bot.amt_filter(args[0], USROBJ) USROBJ.balance -= amt await client.send_message(chan, 'Burned `{} GRC`'.format(amt)) else: await client.send_message( chan, '{}Invalid command. Type `%help` for help.'.format(e.INFO)) else: await client.send_message( chan, '{}Either incorrect command or not in user database (try `%new` or type `%help` for help)' .format(e.ERROR))