async def on_message(message): msg = message.content.strip() if not message.author.bot: if database.get_user(message.author.id) is not None: if message.author.id in user_time_dict.keys(): if datetime.datetime.utcnow() - user_time_dict[ message.author.id] > datetime.timedelta(minutes=1): database.add_balance(message.author, int(random.uniform(9, 15))) user_time_dict[ message.author.id] = datetime.datetime.utcnow() else: user_time_dict[message.author.id] = datetime.datetime.utcnow() else: database.init_user(message.author) database.add_balance(message.author, 50) server_id = int(message.server.id) if message.server.id == 542778736857317386 and message.id not in [ 542783664023535616 ]: pass if msg.startswith(database.get_prefix(server_id)): _command = msg.split(" ")[0].lower() args = re.sub(" +", " ", msg).split(" ")[1:] # clean_command = re.sub(get_prefix(hash(message.server)), "", _command) prefix = database.get_prefix(server_id) clean_command = _command[(len(prefix)):] for k in database.command_alias: if clean_command in k[0]: clean_command = k[1] break try: print( f"{message.author.name} runs {clean_command.capitalize()}Command with {args}" ) mod = __import__("commands", fromlist=[f"{clean_command.capitalize()}Command"]) comm = getattr(mod, f"{clean_command.capitalize()}Command") b = comm(client, message.server, message, message.author, args) a = b.do() if isinstance(a, tuple): text, embed = a else: text = a embed = None #if text is None: # text = "" a = await client.send_message(destination=message.channel, content=text, embed=embed) except Exception: print(f"Exception!") logging.exception(Exception) """
def sell(self, name, count): print(name) card_id = database.get_card(name) card = database.get_card_by_id(card_id) count = database.sell_card(self.sender, card_id, count) if card[3].lower() not in database.money.keys(): balance = int(random.random() * 500 + 500) else: balance = database.money[card[3].lower()] balance *= count if count and database.add_balance(self.sender, balance): return f"You removed {count} {card[2]} for {balance} money"
def do(self): super().do() if len(self.args) == 2: user = self.message.mentions[0] if database.get_user(user.id) is None: return "That user did not type !start, leave him alone" if user is self.sender: return "sad lawl trying to pay yourself (didn't work)" pay_amount = int(self.args[1]) if pay_amount < 0: return ":thinking:" if database.get_balance(self.sender) - pay_amount < 0: return "not allowed to give yourself debt" if database.add_balance(self.sender, -pay_amount) and database.add_balance( user, pay_amount): return f"Transaction completed: you paid {pay_amount} from you to {user.mention}" else: return "forgot to do !start" else: return f"command {self.name} has too many or too little arguments ( {self.args})"
def log_in_operation(self, card_no1): print("1. Balance\n2. Add income\n3. Do transfer\n4. Close account\n5. Log out\n0. Exit\n") login_option = int(input(">")) connection = database.connect() balance = database.show_balance(connection, card_no1) if login_option == 1: balance = database.show_balance(connection, card_no1) print(f"Balance: {balance[0]}" ) self.log_in_operation(card_no1) if login_option == 2: add_amount = int(input("Enter income:")) database.add_balance(connection, balance[0] + add_amount, card_no1) print("Income was added!") connection.commit() self.log_in_operation(card_no1) if login_option == 3: transfer_ac = input("Transfer\nEnter card number:\n>") transfer_ac_balance = database.show_balance(connection, transfer_ac) if transfer_ac == card_no1: print("You can't transfer money to the same account!") self.log_in_operation(card_no1) elif self.luhn(transfer_ac) != True: print("Probably you made a mistake in the card number. Please try again!") self.log_in_operation(card_no1) elif database.find_card(connection, transfer_ac) == None: print("Such a card does not exist.") self.log_in_operation(card_no1) else: transfer_amount = int(input("Enter how much you want to transfer:")) if balance[0] == 0 or (balance[0] - transfer_amount < 0): print("Not enough money!") self.log_in_operation(card_no1) database.add_balance(connection, transfer_ac_balance[0] + transfer_amount, transfer_ac) # add balance in transfer account database.add_balance(connection, (balance[0] - transfer_amount), card_no1) # decrease balance in main account connection.commit() print("Success!") self.log_in_operation(card_no1) connection.commit() elif login_option == 4: database.delete_card(connection, card_no1) print("The account has been closed!") self.log_in_status = False self.operation() elif login_option == 5: print("You have successfully logged out!") self.log_in_status = False self.operation() else: exit()
def do(self): super().do() _isList = False count = 1 if len(self.args) > 2: _isList = True elif len(self.args) == 2: try: count = int(self.args[1]) except ValueError: _isList = True elif len(self.args) == 1: count = 1 else: return f"requires 1 or 2 arguments" name = self.args[0] if len(self.args) > 1 and _isList: name = self.args[0:] if name == "ALL": cards = database.get_cards(self.sender) cards_ = database.get_card_by_ids(cards) b = 0 for card in cards_: count = database.sell_card(self.sender, card[1]) if count != 0: if card[3].lower() not in database.money.keys(): balance = int(random.random() * 500 + 500) else: balance = database.money[card[3].lower()] b += balance if database.add_balance(self.sender, b): return f"You sold everything for {b} money" else: a = "" if isinstance(name, str): a = self.sell(name, count) elif isinstance(name, list): b = [self.sell(n, 1) for n in name] a = "\n".join(b) return a
def do(self): super().do() embed = discord.Embed(descrption="Auctions", color=discord.Color.red()) embed.set_author(name=self.sender.name, icon_url=self.client.user.avatar_url) page = 0 if len(self.args) == 1: try: page = int(self.args[0]) except ValueError: return f"{self.args[0]} is not a valid number" if len(self.args) == 0: # change the values so they work in discord.py auctions = database.all_auctions(page) print(auctions) if len(auctions) == 0: return "No auctions" cleaned_results = [f"{r[0]} :: {util.escape_underscore(r[1])} :: " f"{r[2]} :: {database.get_card_by_id(r[3])[2]}" for r in auctions] embed.add_field(name="Auctions(id::owner::money::card)", value="\n".join(cleaned_results), inline=False) embed.set_footer( text=f"Showing page {page + 1} of {int(database.count_all_auctions() / 10) + 1}") return None, embed if self.args[0] == "accept" and self.args[1]: try: auction_id = int(self.args[1]) if not database.check_auction(auction_id): return f"{self.args[1]} is not a valid auction id!" except ValueError: return f"{self.args[1]} is not a valid auction id!" # here: auction = database.get_auction(auction_id)[0] print(auction) if database.get_balance(self.sender) >= auction[2]: database.remove_auction(auction[0]) database.add_card(self.sender, auction[3]) database.add_balance(self.sender, -auction[2]) database.add_balance_id(auction[4], auction[2]) return f"You earned {database.get_card_by_id(auction[3])[2]} " \ f"from an auction with a bid of {auction[2]}" else: return "You do not have enough money to accept that auction!" elif self.args[0] == "revoke" and self.args[1]: try: auction_id = int(self.args[1]) if not database.check_auction(auction_id): return f"{self.args[1]} is not a valid auction id!" except ValueError: return f"{self.args[1]} is not a valid auction id!" auction = database.get_auction(auction_id)[0] database.remove_auction(auction[0]) database.add_card(self.sender, auction[3]) return f"You revoked auction {auction_id}" elif len(self.args) == 2: try: bid_balance = int(self.args[1]) card_id = database.get_card(self.args[0]) except ValueError: return f"{self.args[1]} is not a valid number" if card_id is not None: if card_id in database.get_cards(self.sender): full_card = database.get_card_by_id(card_id) database.add_auction(self.sender, card_id, bid_balance) c = database.remove_card(self.sender, card_id) print(c) if c: return f"You put {full_card[2]} up for auction for {bid_balance} money" else: print("Error in auctioning card") else: return f"You do not have that card!" else: return f"Invalid card"