diff --git a/config.json b/config.json index b3340da..6356d1b 100644 --- a/config.json +++ b/config.json @@ -17,7 +17,8 @@ "queue": "data/queue", "sent": "data/sent", "index": "data/index.json", - "submit": "data/submit.json" + "submit": "data/submit.json", + "blocked": "data/blocked.json" }, "posting": { "channel": 0, @@ -54,6 +55,6 @@ "link": null }, "submission": { - "limit": 30 + "timeout": 30 } } \ No newline at end of file diff --git a/data/blocked.json b/data/blocked.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/data/blocked.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/main.py b/main.py index 1a46db8..0607730 100644 --- a/main.py +++ b/main.py @@ -168,35 +168,52 @@ def subLimited(user): else: submit = jsonLoad(configGet("submit", "locations")) 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 else: return False else: 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) def get_submission(_, msg): - if not subLimited(msg.from_user): - msg.copy(configGet("admin", "reports"), reply_markup=InlineKeyboardMarkup( - [ - 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="☠️ Block sender", callback_data=f"sub_block_{msg.from_user.id}") - ] - )) - msg.reply_text(f"Media has been submitten.\nWe'll notify you whether it will be accepted or not soon.") - subLimit(msg.from_user) - else: - msg.reply_text(f'You can only submit 1 media per {configGet("limit", "submission")} seconds') + if msg.from_user.id not in jsonLoad(configGet("blocked", "locations")): + if not subLimited(msg.from_user): + msg.copy(configGet("admin", "reports"), reply_markup=InlineKeyboardMarkup([ + [ + 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="☠️ 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 submitted.\nWe'll notify you whether it will be accepted or not soon.", quote=True) + subLimit(msg.from_user) + else: + 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 def callback_query_yes(app, clb): # type: ignore fullclb = clb.data.split("_") try: - submission = app.get_messages(fullclb[2], fullclb[3]) + submission = app.get_messages(int(fullclb[2]), int(fullclb[3])) except: clb.answer(text=f"Submission message no longer exist", show_alert=True) return @@ -205,29 +222,33 @@ def callback_query_yes(app, clb): # type: ignore except: clb.answer(text=f"Could not download submission", show_alert=True) 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) @app.on_callback_query(filters.regex("sub_no_[\s\S]*_[\s\S]*")) # type: ignore def callback_query_no(app, clb): # type: ignore fullclb = clb.data.split("_") try: - submission = app.get_messages(fullclb[2], fullclb[3]) + submission = app.get_messages(int(fullclb[2]), int(fullclb[3])) except: clb.answer(text=f"Submission message no longer exist", show_alert=True) 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) @app.on_callback_query(filters.regex("sub_block_[\s\S]*")) # type: ignore def callback_query_block(app, clb): # type: ignore fullclb = clb.data.split("_") - app.send_message(fullclb[2], "You were blocked and you can't submit media anymore.") - blocked = app.block_user(fullclb[2]) - if blocked: - 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.send_message(int(fullclb[2]), "You were blocked and you can't submit media anymore.") + subBlock(int(fullclb[2])) + clb.answer(text=f"User {fullclb[2]} has been blocked", 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) #===========================================================================================================================================