Remove 24 hour accounts
Remove the additional will you be watching a show or movie question as well as 24 hour accounts. All accounts are now just available for 4 hours.
This commit is contained in:
parent
c370b32354
commit
517c0b328c
@ -8,32 +8,12 @@ import initialize_variables
|
|||||||
from create_message import create_message
|
from create_message import create_message
|
||||||
|
|
||||||
|
|
||||||
def movie_show_response_newaccount(from_number, message):
|
def create_jellyfin_account(from_number):
|
||||||
if from_number not in initialize_variables.temp_new_account_requests.keys():
|
|
||||||
create_message(from_number, "There is no current request that you can decide on. It might be that your /newaccount command timed out due since you took too long to response. Please try again. If this issue persists, please contact Parker.")
|
|
||||||
return
|
|
||||||
|
|
||||||
# If its been 5 minutes since prompt was sent, alert user of timed out request
|
|
||||||
if (datetime.datetime.now() - initialize_variables.temp_new_account_requests[from_number]).total_seconds() / 60 > 5:
|
|
||||||
del initialize_variables.temp_new_account_requests[from_number]
|
|
||||||
create_message(from_number, "You waited too long and therefore your request has timed out.\n\nPlease try again by re-running the /newaccount command. If this issue persists, please contact Parker.")
|
|
||||||
return
|
|
||||||
|
|
||||||
if message.strip().lower() == "show":
|
|
||||||
active_time = 24
|
|
||||||
|
|
||||||
elif message.strip().lower() == "movie":
|
|
||||||
active_time = 4
|
|
||||||
|
|
||||||
else:
|
|
||||||
create_message(from_number, "You did not enter a valid response. Please re-send the /newaccount command and try again. If you believe this is an error, please contact Parker.")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Otherwise, all checks have been completed
|
# Otherwise, all checks have been completed
|
||||||
username = ''.join(random.choices(string.ascii_lowercase + string.digits, k=5))
|
username = ''.join(random.choices(string.ascii_lowercase + string.digits, k=5))
|
||||||
password = ''.join(random.choices(string.ascii_lowercase + string.digits, k=15))
|
password = ''.join(random.choices(string.ascii_lowercase + string.digits, k=15))
|
||||||
|
|
||||||
deletion_time = datetime.datetime.now() + datetime.timedelta(hours=active_time)
|
deletion_time = datetime.datetime.now() + datetime.timedelta(hours=4)
|
||||||
# Create new Jellyfin account
|
# Create new Jellyfin account
|
||||||
request_1 = requests.post(f'{initialize_variables.jellyfin_url}/Users/New', headers=initialize_variables.jellyfin_headers, json={'Name': username, 'Password': password})
|
request_1 = requests.post(f'{initialize_variables.jellyfin_url}/Users/New', headers=initialize_variables.jellyfin_headers, json={'Name': username, 'Password': password})
|
||||||
if request_1.status_code != 200:
|
if request_1.status_code != 200:
|
||||||
@ -68,5 +48,5 @@ def movie_show_response_newaccount(from_number, message):
|
|||||||
db.commit()
|
db.commit()
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
create_message(from_number, f"Username: {username}\nPassword: {password}\n\nYour account will expire in {active_time} hours.")
|
create_message(from_number, f"Username: {username}\nPassword: {password}\n\nYour account will expire in 4 hours.")
|
||||||
return
|
return
|
@ -52,8 +52,8 @@ def init():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
global temp_new_account_requests
|
global jellyfin_active_accounts
|
||||||
temp_new_account_requests = {}
|
jellyfin_active_accounts = {}
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
'from_number': 'time'
|
'from_number': 'time'
|
||||||
|
@ -5,7 +5,7 @@ from create_message import create_message
|
|||||||
from commands.request import request
|
from commands.request import request
|
||||||
from commands.status import status
|
from commands.status import status
|
||||||
from commands.number_response_request import number_response_request
|
from commands.number_response_request import number_response_request
|
||||||
from commands.movie_show_response_newaccount import movie_show_response_newaccount
|
from commands.create_jellyfin_account import create_jellyfin_account
|
||||||
import initialize_variables
|
import initialize_variables
|
||||||
|
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
@ -58,34 +58,30 @@ def incoming():
|
|||||||
if from_number not in initialize_variables.valid_senders:
|
if from_number not in initialize_variables.valid_senders:
|
||||||
return 'OK'
|
return 'OK'
|
||||||
|
|
||||||
if message.startswith('/request'):
|
if message.strip().lower().startswith('/request'):
|
||||||
request(from_number, message)
|
request(from_number, message)
|
||||||
return 'OK'
|
return 'OK'
|
||||||
|
|
||||||
# If a user responded with a number, they are responding to
|
# If a user responded with a number, they are responding to
|
||||||
# the 'request' command prompt
|
# the 'request' command prompt
|
||||||
elif message.strip() in initialize_variables.numbers_responses.keys():
|
elif message.strip().lower() in initialize_variables.numbers_responses.keys():
|
||||||
number_response_request(from_number, message)
|
number_response_request(from_number, message)
|
||||||
return 'OK'
|
return 'OK'
|
||||||
|
|
||||||
elif message.startswith('/status'):
|
elif message.strip().lower().startswith('/status'):
|
||||||
status(from_number)
|
status(from_number)
|
||||||
return 'OK'
|
return 'OK'
|
||||||
|
|
||||||
elif message.startswith('/newaccount'):
|
elif message.strip().lower().startswith('/newaccount'):
|
||||||
if initialize_variables.enable_jellyfin_temp_accounts.lower() == 'true':
|
if initialize_variables.enable_jellyfin_temp_accounts.lower() == 'true':
|
||||||
# If number is already in the temp dict, delete it so that they can redo the request
|
# If number is already in the temp dict, delete it so that they can redo the request
|
||||||
if from_number in initialize_variables.temp_new_account_requests.keys():
|
if from_number in initialize_variables.jellyfin_active_accounts.keys():
|
||||||
del initialize_variables.temp_new_account_requests[from_number]
|
if datetime.datetime.now() - initialize_variables.jellyfin_active_accounts[from_number] < datetime.timedelta(hours=4):
|
||||||
|
create_message(from_number, "You already have an active account. Please wait until it expires to create a new one.")
|
||||||
|
return 'OK'
|
||||||
|
|
||||||
create_message(from_number, "Will you be watching a TV show or a movie?\n\nRespond with 'show' for TV show, 'movie' for movies")
|
create_jellyfin_account(from_number)
|
||||||
initialize_variables.temp_new_account_requests[from_number] = datetime.datetime.now()
|
initialize_variables.jellyfin_active_accounts[from_number] = datetime.datetime.now()
|
||||||
return 'OK'
|
|
||||||
|
|
||||||
# User must be responding to above prompt
|
|
||||||
elif message.strip().lower() in ['show', 'movie']:
|
|
||||||
if initialize_variables.enable_jellyfin_temp_accounts.lower() == 'true':
|
|
||||||
movie_show_response_newaccount(from_number, message)
|
|
||||||
return 'OK'
|
return 'OK'
|
||||||
|
|
||||||
# No valid commands were found, so just return
|
# No valid commands were found, so just return
|
||||||
|
Reference in New Issue
Block a user