async def cmd_give(msg: Message, *args): if len(args) != 2: raise InvalidArgumentsException() if args[0] not in msg.channel.chatters: await msg.reply(msg=f'no viewer found by the name "{args[0]}"') return caller = get_balance_from_msg(msg) target = get_balance(msg.channel_name, args[0]) try: give = int(args[1]) except ValueError: await msg.reply('invalid give amount') return cur_name = get_currency_name(msg.channel_name).name if caller.balance < give: await msg.reply(f"@{msg.author} you don't have enough {cur_name}") return caller.balance -= give target.balance += give session.commit() await msg.reply( f"@{msg.author} you gave @{args[0]} {give} {cur_name}, @{args[0]}'s balance is now {target.balance}" )
async def cmd_give(msg: Message, *args): if len(args) != 2: raise InvalidArgumentsError(reason='missing required arguments', cmd=cmd_give) if not msg.mentions or msg.mentions[0] not in msg.channel.chatters: raise InvalidArgumentsError(reason=f'no viewer found by the name "{(msg.mentions or args)[0]}"') caller = get_balance_from_msg(msg) target = get_balance(msg.channel_name, msg.mentions[0]) try: give = int(args[1]) except ValueError: raise InvalidArgumentsError(reason='give amount must be a integer, example: 100', cmd=cmd_give) if give <= 0: raise InvalidArgumentsError(reason='give amount must be 1 or higher', cmd=cmd_give) cur_name = get_currency_name(msg.channel_name).name if caller.balance < give: raise InvalidArgumentsError(reason=f"{msg.mention} you don't have enough {cur_name}", cmd=cmd_give) caller.balance -= give target.balance += give session.commit() await msg.reply( f"@{msg.author} you gave @{args[0]} {give} {cur_name}, @{args[0]}'s balance is now {target.balance}")
async def cmd_get_bal(msg: Message, *args): if args: target = args[0].lstrip('@') else: target = msg.author currency_name = get_currency_name(msg.channel_name).name balance = get_balance(msg.channel_name, target).balance await msg.reply(whisper=True, msg=f'@{target} has {balance} {currency_name}')
async def cmd_get_bal(msg: Message, *args): if args: target = args[0].lstrip('@') if target not in msg.channel.chatters: raise InvalidArgumentsError(reason=f'no viewer found by the name of "{target}"', cmd=cmd_get_bal) else: target = msg.author currency_name = get_currency_name(msg.channel_name).name balance = get_balance(msg.channel_name, target).balance await msg.reply(whisper=True, msg=f'@{target} has {balance} {currency_name}')
def _can_pay_entry_fee(fee): return get_balance(msg.channel_name, msg.author).balance >= fee