mirror of
https://gitea.phreedom.club/localhost_frssoft/FMN_bot.git
synced 2024-11-23 13:43:01 +00:00
Some fixes and features
* Fix database select * Added detect already suggested movies
This commit is contained in:
parent
cc4f78d08f
commit
b23114d1be
@ -28,32 +28,45 @@ def mark_as_watched_movie(original_name=None, ru_name=None, year=None):
|
||||
|
||||
|
||||
def get_already_watched(original_name=None, ru_name=None, year=None):
|
||||
already_watched = c.execute(f"SELECT * FROM watched_movies WHERE original_name == (?) AND ru_name == (?) AND year == (?) COLLATE NOCASE",
|
||||
already_watched = c.execute('''
|
||||
SELECT * FROM watched_movies
|
||||
WHERE (original_name = (?) OR ru_name = (?)) COLLATE NOCASE
|
||||
AND year = (?)''',
|
||||
(original_name,ru_name,year)).fetchone()
|
||||
if already_watched:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def get_already_suggested(acct, original_name, ru_name, year):
|
||||
already_suggested = c.execute('''SELECT * FROM poll
|
||||
WHERE (original_name = (?) OR ru_name = (?)) COLLATE NOCASE
|
||||
AND year == (?)''', (original_name, ru_name, year)).fetchone()
|
||||
return already_suggested
|
||||
|
||||
|
||||
def get_suggested_movies_count():
|
||||
poll_count = c.execute(f"SELECT * FROM poll").fetchall()
|
||||
poll_count = c.execute("SELECT * FROM poll").fetchall()
|
||||
return len(poll_count)
|
||||
|
||||
|
||||
def per_user_accepted_movie_count(acct=str):
|
||||
user_suggested_count = c.execute(f"SELECT user_suggested FROM poll WHERE user_suggested == (?)", (acct,)).fetchall()
|
||||
user_suggested_count = c.execute("SELECT user_suggested FROM poll WHERE user_suggested == (?)", (acct,)).fetchall()
|
||||
return len(user_suggested_count)
|
||||
|
||||
|
||||
def add_movie_to_poll(acct=str, original_name=None, ru_name=None, year=None):
|
||||
if per_user_accepted_movie_count(acct) >= limit_movies_per_user:
|
||||
return False
|
||||
else:
|
||||
check_user_limit = per_user_accepted_movie_count(acct)
|
||||
already_fmn = get_already_suggested(acct, original_name, ru_name, year)
|
||||
if already_fmn:
|
||||
return 1
|
||||
elif check_user_limit >= limit_movies_per_user:
|
||||
return 2
|
||||
if check_user_limit < limit_movies_per_user and already_fmn is None:
|
||||
c.execute("INSERT OR IGNORE INTO poll(user_suggested, original_name, ru_name, year, votes) VALUES (?, ?, ?, ?, ?)", (acct, original_name, ru_name, year, 0))
|
||||
conn.commit()
|
||||
logger.info('Add option to poll: ' + str((acct, original_name, ru_name, year)))
|
||||
return True
|
||||
return 0
|
||||
|
||||
|
||||
def get_movies_for_poll():
|
||||
|
@ -130,7 +130,10 @@ def scan_context_thread():
|
||||
movie_string = f"{name_ru}, {year}"
|
||||
if name_ru is None:
|
||||
movie_string = f"{name}, {year}"
|
||||
|
||||
if year is None:
|
||||
post_status('🎬 Мы временно не можем обработать ваше предложение: Обработка фильма без наличия года невозможна.', id_st)
|
||||
fail_limit[acct] += 1
|
||||
break
|
||||
if get_suggested_movies_count() >= limit_all_movies_poll:
|
||||
post_status('🎬 Мы не можем обработать ваше предложение: количество уже предложенных не помещается в лимит голосовалки.', id_st)
|
||||
logger.warning(f'Предложение {acct} было отклонено: количество уже предложенных фильмов превышает\равно {limit_all_movies_poll}')
|
||||
@ -140,11 +143,18 @@ def scan_context_thread():
|
||||
if get_already_watched(name, name_ru, year) == True:
|
||||
message_writer.append(f"ℹ️Этот фильм уже был на FMN: {movie_string}")
|
||||
logger.info(f'Попытка предложить уже просмотренный фильм: {acct} {name} {name_ru} {year}')
|
||||
fail_limit[acct] += 1
|
||||
continue
|
||||
|
||||
if add_movie_to_poll(acct, name, name_ru, year) == True:
|
||||
add_result = add_movie_to_poll(acct, name, name_ru, year)
|
||||
|
||||
if add_result == 0:
|
||||
message_writer.append(f"✅ Принято: {movie_string}")
|
||||
logger.info(f'Предложение от {acct} принято: {name} {name_ru} {year}')
|
||||
elif add_result == 1:
|
||||
post_status("❌ Этот фильм уже был предложен", id_st)
|
||||
logger.info(f'Предложение от {acct} было отлонено - фильм в опросе существует')
|
||||
fail_limit[acct] += 1
|
||||
else:
|
||||
post_status("❌ Вы не можете добавить больше 2х фильмов", id_st)
|
||||
logger.info(f'Предложение от {acct} было отлонено - лимит на пользователя')
|
||||
@ -154,3 +164,4 @@ def scan_context_thread():
|
||||
|
||||
time.sleep(30)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user