|
|
@@ -9,77 +9,88 @@ import os
|
|
|
|
|
|
|
|
|
def accept_donation(donation_info, donation_points):
|
|
|
- db = get_db()
|
|
|
- is_public = donation_info[0]
|
|
|
- email = donation_info[2]
|
|
|
- amount = donation_info[3]
|
|
|
- amount = int(float(amount)) # Convert from str to int
|
|
|
- message = donation_info[4]
|
|
|
- points = amount * donation_points # Multiply by streamers donation points award
|
|
|
- ids = get_id_by_email(db, email)
|
|
|
- if not ids: # If no id found with that email address
|
|
|
- if add_email_to_points(db, email, points): # Create empty account with email and points
|
|
|
- name = 'Someone'
|
|
|
- current_app.logger.info(f'No user with email \"{email}\" found in database, created empty account.')
|
|
|
- else: # Grant points to the corresponding id
|
|
|
- for id in ids:
|
|
|
- if award_chat_points(db, id[0], points): # Grant points
|
|
|
- for user in get_all_users_with_user_id(db, id[0]):
|
|
|
- name = user[1]
|
|
|
- current_app.logger.info(f'Granted user id {id[0]} {porps(points)} for their ${amount} donation.')
|
|
|
- if is_public:
|
|
|
- message = f'{name} got {porps(points)} for donating ${amount} on Kofi!'
|
|
|
- current_app.logger.info(f'Public donation of ${amount} received from {name}')
|
|
|
- else:
|
|
|
- message = None
|
|
|
- current_app.logger.info(f'Private donation of ${amount} received from {name}')
|
|
|
- if message is not None: # Only send chat message if it's a public donation
|
|
|
- send_chat(message)
|
|
|
+ try:
|
|
|
+ db = get_db()
|
|
|
+ is_public = donation_info[0]
|
|
|
+ email = donation_info[2]
|
|
|
+ amount = donation_info[3]
|
|
|
+ amount = int(float(amount)) # Convert from str to int
|
|
|
+ message = donation_info[4]
|
|
|
+ points = amount * donation_points # Multiply by streamers donation points award
|
|
|
+ ids = get_id_by_email(db, email)
|
|
|
+ if not ids: # If no id found with that email address
|
|
|
+ if add_email_to_points(db, email, points): # Create empty account with email and points
|
|
|
+ name = 'Someone'
|
|
|
+ current_app.logger.info(f'No user with email \"{email}\" found in database, created empty account.')
|
|
|
+ else: # Grant points to the corresponding id
|
|
|
+ for id in ids:
|
|
|
+ if award_chat_points(db, id[0], points): # Grant points
|
|
|
+ for user in get_all_users_with_user_id(db, id[0]):
|
|
|
+ name = user[1]
|
|
|
+ current_app.logger.info(f'Granted user id {id[0]} {porps(points)} for their ${amount} donation.')
|
|
|
+ if is_public:
|
|
|
+ message = f'{name} got {porps(points)} for donating ${amount} on Kofi!'
|
|
|
+ current_app.logger.info(f'Public donation of ${amount} received from {name}')
|
|
|
+ else:
|
|
|
+ message = None
|
|
|
+ current_app.logger.info(f'Private donation of ${amount} received from {name}')
|
|
|
+ if message is not None: # Only send chat message if it's a public donation
|
|
|
+ send_chat(message)
|
|
|
+ return True
|
|
|
+ except Exception as aderror:
|
|
|
+ current_app.logger.error(f'General Exception: {aderror}')
|
|
|
|
|
|
|
|
|
def accept_sub(sub_info, sub_points):
|
|
|
- db = get_db()
|
|
|
- is_public = sub_info[0]
|
|
|
- name = sub_info[1]
|
|
|
- email = sub_info[2]
|
|
|
- amount = sub_info[3]
|
|
|
- amount = int(float(amount)) # Convert from str to int
|
|
|
- message = sub_info[4]
|
|
|
- first_sub = sub_info[5]
|
|
|
- tier_name = sub_info[6]
|
|
|
- points = sub_points
|
|
|
- ids = get_id_by_email(db, email)
|
|
|
- if not ids: # If no id found with that email address
|
|
|
- if add_email_to_points(db, email, points): # Create empty account with email and points
|
|
|
- name = 'Someone'
|
|
|
- current_app.logger.info(f'No user with email \"{email}\" found in database, created empty account.')
|
|
|
- else: # Grant points to the corresponding id
|
|
|
- for id in ids:
|
|
|
- if award_chat_points(db, id[0], points): # Grant points
|
|
|
- for user in get_all_users_with_user_id(db, id[0]):
|
|
|
- name = user[1] # Assign name from points table
|
|
|
- current_app.logger.info(f'Awarded user id {id[0]} {porps(points)} for their subscription.')
|
|
|
- if is_public:
|
|
|
- if not name: # If no name in points table
|
|
|
- name = 'Someone'
|
|
|
- if first_sub:
|
|
|
- message = f'{name} got {porps(points)} for their one month membership on Kofi!'
|
|
|
- current_app.logger.info(f'Public subscription received from {name}')
|
|
|
- else:
|
|
|
- message = f'{name} got {porps(points)} for renewing their membership on Kofi!'
|
|
|
- current_app.logger.info(f'Public subscription renewal received from {name}')
|
|
|
- send_chat(message) # Send message publicly if a public membership
|
|
|
- else:
|
|
|
- if not name: # If no name in points table
|
|
|
- name = sub_info[1] # Assign name from Kofi response
|
|
|
- if first_sub:
|
|
|
- message = f'Thanks so much for your subscribing to my Kofi! You\'ve been awarded {porps(points)}!'
|
|
|
- current_app.logger.info(f'Private subscription received from {name}')
|
|
|
+ try:
|
|
|
+ db = get_db()
|
|
|
+ is_public = sub_info[0]
|
|
|
+ name = sub_info[1]
|
|
|
+ email = sub_info[2]
|
|
|
+ amount = sub_info[3]
|
|
|
+ amount = int(float(amount)) # Convert from str to int
|
|
|
+ message = sub_info[4]
|
|
|
+ first_sub = sub_info[5]
|
|
|
+ tier_name = sub_info[6]
|
|
|
+ points = sub_points
|
|
|
+ ids = get_id_by_email(db, email)
|
|
|
+ if not ids: # If no id found with that email address
|
|
|
+ if add_email_to_points(db, email, points): # Create empty account with email and points
|
|
|
+ name = 'Someone'
|
|
|
+ current_app.logger.info(f'No user with email \"{email}\" found in database, created empty account.')
|
|
|
+ else: # Grant points to the corresponding id
|
|
|
+ for id in ids:
|
|
|
+ if award_chat_points(db, id[0], points): # Grant points
|
|
|
+ for user in get_all_users_with_user_id(db, id[0]):
|
|
|
+ name = user[1] # Assign name from points table
|
|
|
+ current_app.logger.info(f'Awarded user id {id[0]} {porps(points)} for their subscription.')
|
|
|
+ if is_public:
|
|
|
+ if not name: # If no name in points table
|
|
|
+ name = 'Someone'
|
|
|
+ if first_sub:
|
|
|
+ message = f'{name} got {porps(points)} for their one month membership on Kofi!'
|
|
|
+ current_app.logger.info(f'Public subscription received from {name}')
|
|
|
+ else:
|
|
|
+ message = f'{name} got {porps(points)} for renewing their membership on Kofi!'
|
|
|
+ current_app.logger.info(f'Public subscription renewal received from {name}')
|
|
|
+ send_chat(message) # Send message publicly if a public membership
|
|
|
else:
|
|
|
- message = f'Thanks so much for renewing your membership to my Kofi! You\'ve been awarded {porps(points)}!'
|
|
|
- current_app.logger.info(f'Private subscription renewal received from {name}')
|
|
|
- send_private_chat(id[0], message)
|
|
|
-
|
|
|
+ if not ids:
|
|
|
+ current_app.logger.info(f'No account to associate with.')
|
|
|
+ # return True
|
|
|
+ if not name: # If no name in points table
|
|
|
+ name = sub_info[1] # Assign name from Kofi response
|
|
|
+ if first_sub:
|
|
|
+ message = f'Thanks so much for your subscribing to my Kofi! You\'ve been awarded {porps(points)}!'
|
|
|
+ current_app.logger.info(f'Private subscription received from {name}')
|
|
|
+ else:
|
|
|
+ message = f'Thanks so much for renewing your membership to my Kofi! You\'ve been awarded {porps(points)}!'
|
|
|
+ current_app.logger.info(f'Private subscription renewal received from {name}')
|
|
|
+ send_private_chat(id[0], message)
|
|
|
+ return True
|
|
|
+ except Exception as aderror:
|
|
|
+ current_app.logger.error(f'General Exception: {aderror}')
|
|
|
+
|
|
|
|
|
|
def save_kofi_settings(ksettings_info): # Write rewards to kofi.py
|
|
|
settings_file = os.path.join(current_app.instance_path, 'kofi.py')
|