Skip to content

Commit

Permalink
add number of receivers and more data for tipall, tips
Browse files Browse the repository at this point in the history
  • Loading branch information
wrkzdev committed Jun 30, 2019
1 parent c7eb72c commit 3bf4c74
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
12 changes: 9 additions & 3 deletions wrkzcoin_tipbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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 = []
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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 = []
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 18 additions & 4 deletions wrkzcoin_tipbot/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit 3bf4c74

Please sign in to comment.