def kick(update, context): chat = update.effective_chat bot = context.bot user_to_kick = update.effective_message.reply_to_message.from_user reason = ' '.join(context.args) if is_banned(user_to_kick.id, chat.id, bot): return update.effective_message.reply_text( strings.get(strings.user_is_not_member, chat, user_to_kick.first_name)) bot.kick_chat_member(chat.id, user_to_kick.id) bot.unban_chat_member(chat.id, user_to_kick.id) update.effective_message.reply_text(strings.get( strings.user_has_been_kicked, chat, escape_markdown(user_to_kick.first_name, version=2) + ('\n' + strings.get(strings.reason, chat, reason) if reason else '')), parse_mode=ParseMode.MARKDOWN_V2)
def kick(update, context): chat = update.effective_chat bot = context.bot user_to_kick = update.effective_message.reply_to_message.from_user reason = ' '.join(context.args) if is_banned(user_to_kick.id, chat.id, bot): return update.effective_message.reply_text(strings.get( strings.user_is_not_member, chat, user_to_kick.mention_html()), parse_mode=ParseMode.HTML) bot.kick_chat_member(chat.id, user_to_kick.id) bot.unban_chat_member(chat.id, user_to_kick.id) update.effective_message.reply_text( strings.get(strings.user_has_been_kicked, chat, user_to_kick.mention_html()) + '\n' + (strings.get(strings.reason, chat, escape(reason, True)) if reason else ''), parse_mode=ParseMode.HTML)
def before_request(): # Check if remote address is banned if utils.is_banned(request.remote_addr): if request.endpoint != "static": return abort(403) # Make sure cookies are still valid if session.get("current_user"): crab_id = session.get("current_user") crab = models.Crab.get_security_overview(crab_id) current_user_ts = session.get("current_user_ts") # Account deleted or banned if crab is None or crab.banned or crab.deleted: # Force logout session["current_user"] = None if crab and crab.banned: return utils.show_error( "The account you were logged into has been banned.", "/login") return utils.show_error( "The account you were logged into no longer exists.", "/login") # Potential database rollback or exploit elif int(crab.register_time.timestamp()) != current_user_ts: if current_user_ts: # Force logout session["current_user"] = None return utils.show_error( "Your cookies are invalidated or corrupted. Please attempt" " to log in again.", "/login", ) else: session["current_user_ts"] = crab.register_timestamp # Persist session after browser is closed session.permanent = True
def unban(update, context): chat = update.effective_chat bot = context.bot user_to_unban = update.effective_message.reply_to_message.from_user if is_banned(user_to_unban.id, chat.id, bot): bot.unban_chat_member(chat.id, user_to_unban.id) try: bot.send_message( user_to_unban.id, strings.get( strings.you_can_join, user_to_unban.language_code, f'<a href="https://t.me/{update.effective_chat.username}">{chat.title}</a>' ), parse_mode=ParseMode.HTML) except: pass update.effective_message.reply_text( strings.get(strings.user_has_been_unbanned, chat, user_to_unban.first_name)) else: update.effective_message.reply_text( strings.get(strings.user_is_not_banned, chat, user_to_unban.first_name))
def level(path): ''' Display, the question, validate answers, hints and increment user level. ''' if is_banned(get_db().cursor(), current_user.id): print 'here' return redirect('/logout') if not event_start(EVENT_DATA): if ENV_DEV: pass else: return redirect('/') level_index = routing(EVENT_DATA, path, 'index') user_index = get_user_level(get_db().cursor(), current_user.id) if level_index > user_index: return redirect(routing(EVENT_DATA, user_index, 'path')) data = get_level_data(EVENT_DATA, path) if data is None: return redirect('/') if request.method == 'POST': answer = request.form.get('answer') correct, hint, text = validate_answer(data, answer) if correct: if user_index == level_index: increment(get_db(), current_user.id, (level_index + 1)) if (level_index + 1) > len(EVENT_DATA['levels']): return redirect('/congratulations') return redirect(routing(EVENT_DATA, (level_index + 1), 'path')) elif hint: return render_template('level.html', year=YEAR, event=EVENT_DATA['name'], host=EVENT_DATA['host'], faq=EVENT_DATA['faq'], social=EVENT_DATA['social'], discuss=EVENT_DATA['discuss'], user=current_user.id, media=data['media'], hint=hint, hint_text=text, text=data['text'], level=level_index, title=data['title'], source=data['source']) return render_template('level.html', year=YEAR, event=EVENT_DATA['name'], host=EVENT_DATA['host'], faq=EVENT_DATA['faq'], social=EVENT_DATA['social'], discuss=EVENT_DATA['discuss'], user=current_user.id, media=data['media'], hint=False, hint_text='', text=data['text'], level=level_index, title=data['title'], source=data['source']) else: return render_template('level.html', year=YEAR, event=EVENT_DATA['name'], host=EVENT_DATA['host'], faq=EVENT_DATA['faq'], social=EVENT_DATA['social'], discuss=EVENT_DATA['discuss'], user=current_user.id, media=data['media'], hint=False, hint_text='', text=data['text'], level=level_index, title=data['title'], source=data['source'])