User blocking improved

This commit is contained in:
Profitroll 2022-08-09 14:44:06 +02:00
parent e18af786cf
commit e38b67495b
3 changed files with 50 additions and 27 deletions

View File

@ -17,7 +17,8 @@
"queue": "data/queue", "queue": "data/queue",
"sent": "data/sent", "sent": "data/sent",
"index": "data/index.json", "index": "data/index.json",
"submit": "data/submit.json" "submit": "data/submit.json",
"blocked": "data/blocked.json"
}, },
"posting": { "posting": {
"channel": 0, "channel": 0,
@ -54,6 +55,6 @@
"link": null "link": null
}, },
"submission": { "submission": {
"limit": 30 "timeout": 30
} }
} }

1
data/blocked.json Normal file
View File

@ -0,0 +1 @@
[]

47
main.py
View File

@ -168,35 +168,52 @@ def subLimited(user):
else: else:
submit = jsonLoad(configGet("submit", "locations")) submit = jsonLoad(configGet("submit", "locations"))
if str(user.id) in submit: if str(user.id) in submit:
if (time.time - submit[str(user.id)]) > configGet("limit", "submission"): if (time.time() - submit[str(user.id)]) < configGet("timeout", "submission"):
return True return True
else: else:
return False return False
else: else:
return False return False
def subBlock(user):
blocked = jsonLoad(configGet("blocked", "locations"))
if user.id not in blocked:
blocked.append(user.id)
jsonSave(blocked, configGet("blocked", "locations"))
def subUnblock(user):
blocked = jsonLoad(configGet("blocked", "locations"))
if user.id in blocked:
blocked.remove(user.id)
jsonSave(blocked, configGet("blocked", "locations"))
@app.on_message(filters.photo | filters.video | filters.animation) @app.on_message(filters.photo | filters.video | filters.animation)
def get_submission(_, msg): def get_submission(_, msg):
if msg.from_user.id not in jsonLoad(configGet("blocked", "locations")):
if not subLimited(msg.from_user): if not subLimited(msg.from_user):
msg.copy(configGet("admin", "reports"), reply_markup=InlineKeyboardMarkup( msg.copy(configGet("admin", "reports"), reply_markup=InlineKeyboardMarkup([
[ [
InlineKeyboardButton(text="✅ Accept", callback_data=f"sub_yes_{msg.from_user.id}_{msg.id}"), InlineKeyboardButton(text="✅ Accept", callback_data=f"sub_yes_{msg.from_user.id}_{msg.id}"),
InlineKeyboardButton(text="❌ Deny", callback_data=f"sub_no_{msg.from_user.id}_{msg.id}") InlineKeyboardButton(text="❌ Deny", callback_data=f"sub_no_{msg.from_user.id}_{msg.id}")
], ],
[ [
InlineKeyboardButton(text="☠️ Block sender", callback_data=f"sub_block_{msg.from_user.id}") InlineKeyboardButton(text="☠️ Block sender", callback_data=f"sub_block_{msg.from_user.id}")
],
[
InlineKeyboardButton(text="🏳️ Unblock sender", callback_data=f"sub_unblock_{msg.from_user.id}")
]
] ]
)) ))
msg.reply_text(f"Media has been submitten.\nWe'll notify you whether it will be accepted or not soon.") msg.reply_text(f"Media has been submitted.\nWe'll notify you whether it will be accepted or not soon.", quote=True)
subLimit(msg.from_user) subLimit(msg.from_user)
else: else:
msg.reply_text(f'You can only submit 1 media per {configGet("limit", "submission")} seconds') msg.reply_text(f'You can only submit 1 media per {configGet("timeout", "submission")} seconds')
@app.on_callback_query(filters.regex("sub_yes_[\s\S]*_[\s\S]*")) # type: ignore @app.on_callback_query(filters.regex("sub_yes_[\s\S]*_[\s\S]*")) # type: ignore
def callback_query_yes(app, clb): # type: ignore def callback_query_yes(app, clb): # type: ignore
fullclb = clb.data.split("_") fullclb = clb.data.split("_")
try: try:
submission = app.get_messages(fullclb[2], fullclb[3]) submission = app.get_messages(int(fullclb[2]), int(fullclb[3]))
except: except:
clb.answer(text=f"Submission message no longer exist", show_alert=True) clb.answer(text=f"Submission message no longer exist", show_alert=True)
return return
@ -205,29 +222,33 @@ def callback_query_yes(app, clb): # type: ignore
except: except:
clb.answer(text=f"Could not download submission", show_alert=True) clb.answer(text=f"Could not download submission", show_alert=True)
return return
submission.reply_text(f"✅ Submission approved and accepted") submission.reply_text(f"✅ Submission approved and accepted", quote=True)
clb.answer(text=f"✅ Submission approved", show_alert=True) clb.answer(text=f"✅ Submission approved", show_alert=True)
@app.on_callback_query(filters.regex("sub_no_[\s\S]*_[\s\S]*")) # type: ignore @app.on_callback_query(filters.regex("sub_no_[\s\S]*_[\s\S]*")) # type: ignore
def callback_query_no(app, clb): # type: ignore def callback_query_no(app, clb): # type: ignore
fullclb = clb.data.split("_") fullclb = clb.data.split("_")
try: try:
submission = app.get_messages(fullclb[2], fullclb[3]) submission = app.get_messages(int(fullclb[2]), int(fullclb[3]))
except: except:
clb.answer(text=f"Submission message no longer exist", show_alert=True) clb.answer(text=f"Submission message no longer exist", show_alert=True)
return return
submission.reply_text(f"❌ Submission reviewed and declined") submission.reply_text(f"❌ Submission reviewed and declined", quote=True)
clb.answer(text=f"❌ Submission declined", show_alert=True) clb.answer(text=f"❌ Submission declined", show_alert=True)
@app.on_callback_query(filters.regex("sub_block_[\s\S]*")) # type: ignore @app.on_callback_query(filters.regex("sub_block_[\s\S]*")) # type: ignore
def callback_query_block(app, clb): # type: ignore def callback_query_block(app, clb): # type: ignore
fullclb = clb.data.split("_") fullclb = clb.data.split("_")
app.send_message(fullclb[2], "You were blocked and you can't submit media anymore.") app.send_message(int(fullclb[2]), "You were blocked and you can't submit media anymore.")
blocked = app.block_user(fullclb[2]) subBlock(int(fullclb[2]))
if blocked:
clb.answer(text=f"User {fullclb[2]} has been blocked", show_alert=True) clb.answer(text=f"User {fullclb[2]} has been blocked", show_alert=True)
else:
clb.answer(text=f"Could not block {fullclb[2]}", show_alert=True) @app.on_callback_query(filters.regex("sub_unblock_[\s\S]*")) # type: ignore
def callback_query_unblock(app, clb): # type: ignore
fullclb = clb.data.split("_")
app.send_message(int(fullclb[2]), "You were unblocked and you can now submit media.")
subUnblock(int(fullclb[2]))
clb.answer(text=f"User {fullclb[2]} has been unblocked", show_alert=True)
#=========================================================================================================================================== #===========================================================================================================================================