diff --git a/wrkzcoin_tipbot/bot.py b/wrkzcoin_tipbot/bot.py index 6705b434..dca513e1 100644 --- a/wrkzcoin_tipbot/bot.py +++ b/wrkzcoin_tipbot/bot.py @@ -1818,6 +1818,7 @@ async def tipall(ctx, amount: str, *args): # End of checking receivers numbers. memids = [] # list of member ID has_forwardtip = None + list_receivers = [] for member in listMembers: # print(member.name) # you'll just print out Member objects your way. if ctx.message.author.id != member.id: @@ -1834,6 +1835,7 @@ async def tipall(ctx, amount: str, *args): else: address_to = user_to['balance_wallet_address'] if address_to: + list_receivers.append(str(member.id)) memids.append(address_to) user_from = store.sql_get_userwallet(ctx.message.author.id, COIN_NAME) @@ -1899,7 +1901,7 @@ async def tipall(ctx, amount: str, *args): # print(destinations) tip = None try: - tip = await store.sql_send_tipall(ctx.message.author.id, destinations, real_amount, COIN_NAME) + tip = await store.sql_send_tipall(str(ctx.message.author.id), destinations, real_amount, amountDiv, list_receivers, 'TIPALL', COIN_NAME) except Exception as e: print(e) if tip: @@ -3689,6 +3691,7 @@ async def _tip(ctx, amount, coin: str = None): memids = [] # list of member ID has_forwardtip = None + list_receivers = [] for member in listMembers: # print(member.name) # you'll just print out Member objects your way. if ctx.message.author.id != member.id: @@ -3703,6 +3706,7 @@ async def _tip(ctx, amount, coin: str = None): else: address_to = user_to['balance_wallet_address'] if address_to: + list_receivers.append(str(member.id)) memids.append(address_to) addresses = [] @@ -3759,7 +3763,7 @@ async def _tip(ctx, amount, coin: str = None): tip = None try: - tip = await store.sql_send_tipall(str(ctx.message.author.id), destinations, real_amount, COIN_NAME) + tip = await store.sql_send_tipall(str(ctx.message.author.id), destinations, real_amount, real_amount, list_receivers, 'TIPS', COIN_NAME) except Exception as e: print(e) if tip: @@ -3939,6 +3943,7 @@ async def _tip_talker(ctx, amount, list_talker, coin: str = None): destinations = [] memids = [] # list of member ID has_forwardtip = None + list_receivers = [] for member_id in list_talker: if member_id != ctx.message.author.id: user_to = store.sql_get_userwallet(str(member_id), COIN_NAME) @@ -3952,6 +3957,7 @@ async def _tip_talker(ctx, amount, list_talker, coin: str = None): else: address_to = user_to['balance_wallet_address'] if address_to: + list_receivers.append(str(member_id)) memids.append(address_to) addresses = [] @@ -4008,7 +4014,7 @@ async def _tip_talker(ctx, amount, list_talker, coin: str = None): tip = None try: - tip = await store.sql_send_tipall(ctx.message.author.id, destinations, real_amount, COIN_NAME) + tip = await store.sql_send_tipall(str(ctx.message.author.id), destinations, real_amount, real_amount, list_receivers, 'TIPS', COIN_NAME) except Exception as e: print(e) if tip: diff --git a/wrkzcoin_tipbot/store.py b/wrkzcoin_tipbot/store.py index 9476d284..645cf367 100644 --- a/wrkzcoin_tipbot/store.py +++ b/wrkzcoin_tipbot/store.py @@ -411,8 +411,10 @@ async def sql_send_tip(user_from: str, user_to: str, amount: int, coin: str = No return None -async def sql_send_tipall(user_from: str, user_tos, amount: int, coin: str = None): +async def sql_send_tipall(user_from: str, user_tos, amount: int, amount_div: int, user_ids, tiptype: str, coin: str = None): global conn + if tiptype.upper() not in ["TIPS", "TIPALL"]: + return None if coin is None: coin = "WRKZ" else: @@ -424,15 +426,27 @@ async def sql_send_tipall(user_from: str, user_tos, amount: int, coin: str = Non tx_hash = None if coin.upper() in ENABLE_COIN: tx_hash = await wallet.send_transactionall(user_from_wallet['balance_wallet_address'], user_tos, coin.upper()) + print('tx_hash: ') + print(tx_hash) if tx_hash: try: openConnection() with conn.cursor() as cur: timestamp = int(time.time()) if coin.upper() in ENABLE_COIN: - sql = """ INSERT INTO """+coin.lower()+"""_tipall (`from_user`, `amount_total`, `date`, `tx_hash`) - VALUES (%s, %s, %s, %s) """ - cur.execute(sql, (user_from, amount, timestamp, tx_hash,)) + sql = """ INSERT INTO """+coin.lower()+"""_tipall (`from_user`, `amount_total`, `date`, `tx_hash`, `numb_receivers`) + VALUES (%s, %s, %s, %s, %s) """ + cur.execute(sql, (user_from, amount, timestamp, tx_hash, len(user_tos),)) + conn.commit() + + values_str = [] + for item in user_ids: + values_str.append(f"('{user_from}', '{item}', {amount_div}, {timestamp}, '{tx_hash}', '{tiptype.upper()}')\n") + values_sql = "VALUES " + ",".join(values_str) + print(values_sql) + sql = """ INSERT INTO """+coin.lower()+"""_tip (`from_user`, `to_user`, `amount`, `date`, `tx_hash`, `tip_tips_tipall`) + """+values_sql+""" """ + cur.execute(sql,) conn.commit() except Exception as e: print(e)