def echo_all(message): while True: mysql.start_bot(message.chat.id) user_id = message.chat.id message = message banned = mysql.user_tables(user_id)['banned'] ticket_status = mysql.user_tables(user_id)['open_ticket'] ticket_spam = mysql.user_tables(user_id)['open_ticket_spam'] if banned == 1: return elif msg.spam_handler_warning(bot, user_id, message): # First spam warning return elif msg.bad_words_handler(bot, message): return elif msg.spam_handler_blocked( bot, user_id, message ): # Final spam warning // user cant send messages anymore return elif ticket_status == 0: mysql.open_ticket(user_id) continue else: msg.fwd_handler(user_id, bot, message) return
def ot_handler(message): if message.chat.id == config.support_chat: if not mysql.open_tickets: bot.reply_to(message, "ℹ️ Great job, you answered all your tickets!") return ot_msg = '📨 *Open tickets:*\n\n' for user in mysql.open_tickets: bot.send_chat_action(message.chat.id, 'typing') ot_link = mysql.user_tables(int(user))['open_ticket_link'] now = arrow.now() diff = datetime.now() - mysql.user_tables( int(user))['open_ticket_time'] diff.total_seconds() / 3600 # seconds to hour time_since_secs = float(diff.seconds) time_since = now.shift(seconds=-time_since_secs).humanize() # Bring attention to 1 day old tickets if time_since_secs > config.open_ticket_emoji * 3600: alert = ' ↳ ⚠️ ' else: alert = ' ↳ ' ot_msg += "• [{0}{1}](tg://user?id={2}) (`{2}`)\n{5}_{3}_ [➜ Go to msg]({4})\n".format( bot.get_chat(int(user)).first_name, ' {0}'.format(bot.get_chat(int(user)).last_name) if bot.get_chat(int(user)).last_name else '', int(user), time_since, ot_link, alert) bot.send_message(message.chat.id, ot_msg, parse_mode='Markdown') else: pass
def ot_handler(message): try: if message.chat.id == config.support_chat: if message.reply_to_message and '(#id' in msg.msgCheck(message): user_id = msg.getUserID(message) banned_status = mysql.user_tables(user_id)['banned'] if banned_status == 0: bot.reply_to(message, '❌ That user is already un-banned...') else: mysql.unban_user(user_id) bot.reply_to(message, '✅ Ok, un-banned that user!') elif msg.getReferrer(message.text): user_id = int(msg.getReferrer(message.text)) banned_status = mysql.user_tables(user_id)['banned'] if banned_status == 0: bot.reply_to(message, '❌ That user is already un-banned...') else: mysql.unban_user(user_id) bot.reply_to(message, '✅ Ok, un-banned that user!') else: bot.reply_to( message, 'ℹ️ You\'d have to either reply to a message or mention an `Users ID`.', parse_mode='Markdown') except TypeError: bot.reply_to(message, '❌ Are you sure I interacted with that user before...?')
def spam_handler_warning(bot, user_id, message): if config.spam_toggle: ticket_spam = mysql.user_tables(user_id)['open_ticket_spam'] if ticket_spam > config.spam_protection: bot.reply_to(message, '{}, your messages are not being forwarded anymore. Please wait until the team responded. Thank you.\n\n' \ f'_The support\'s local time is_ `{current_time}`.'.format(message.from_user.first_name), parse_mode='Markdown') return spam_handler_warning
def spam_handler_blocked(bot, user_id, message): if config.spam_toggle: ticket_spam = mysql.user_tables(user_id)['open_ticket_spam'] if ticket_spam == config.spam_protection - 1: fwd_handler(user_id, bot, message) bot.reply_to(message, 'We will be with you shortly.\n\n{}, to prevent spam you can only send us *1* more message.\n\n' \ f'_The support\'s local time is_ `{current_time}`.'.format(message.from_user.first_name), parse_mode='Markdown') return spam_handler_blocked
def ot_handler(message): try: if message.chat.id == config.support_chat: if message.reply_to_message and '(#id' in msg.msgCheck(message): user_id = msg.getUserID(message) banned_status = mysql.user_tables(user_id)['banned'] if banned_status == 1: bot.reply_to(message, '❌ That user is already banned...') else: mysql.ban_user(user_id) try: # Reset Open Tickets as well as the Spamfilter mysql.reset_open_ticket(user_id) except Exception as e: pass bot.reply_to(message, '✅ Ok, banned that user!') elif msg.getReferrer(message.text): user_id = int(msg.getReferrer(message.text)) banned_status = mysql.user_tables(user_id)['banned'] if banned_status == 1: bot.reply_to(message, '❌ That user is already banned...') else: mysql.ban_user(user_id) try: # Reset Open Tickets as well as the Spamfilter mysql.reset_open_ticket(user_id) except Exception as e: pass bot.reply_to(message, '✅ Ok, banned that user!') else: bot.reply_to( message, 'ℹ️ You\'d have to either reply to a message or mention an `Users ID`.', parse_mode='Markdown') except TypeError: bot.reply_to(message, '❌ Are you sure I interacted with that user before...?')
def echo_all(message): while True: try: try: user_id = msg.getUserID(message) message = message text = message.text msg_check = msg.msgCheck(message) ticket_status = mysql.user_tables(user_id)['open_ticket'] banned_status = mysql.user_tables(user_id)['banned'] if banned_status == 1: # If User is banned - un-ban user and sent message mysql.unban_user(user_id) bot.reply_to( message, 'ℹ️ *FYI: That user was banned.*\n_Un-banned and sent message!_', parse_mode='Markdown') elif ticket_status == 1: # Reset Open Tickets as well as the Spamfilter mysql.reset_open_ticket(user_id) continue else: if message.reply_to_message and '(#id' in msg_check: msg.snd_handler(user_id, bot, message, text) return except telebot.apihelper.ApiException: bot.reply_to( message, '❌ I was unable to send that message...\nThe user might\'ve blocked me.' ) return except Exception as e: bot.reply_to(message, '❌ Invalid command!') return
def ot_handler(message): if message.chat.id == config.support_chat: if message.reply_to_message and '(#id' in message.reply_to_message.text: bot.send_chat_action(message.chat.id, 'typing') user_id = int( message.reply_to_message.text.split('(#id')[1].split(')')[0]) ticket_status = mysql.user_tables(user_id)['open_ticket'] if ticket_status == 0: bot.reply_to(message, '❌ That user has no open ticket...') else: # Reset Open Tickets as well as the Spamfilter mysql.reset_open_ticket(user_id) bot.reply_to(message, '✅ Ok, closed that users ticket!') else: bot.reply_to(message, 'ℹ️ You\'d have to reply to a message') else: pass
def ot_handler(message): if message.chat.id == config.support_chat: if not mysql.banned: bot.reply_to(message, "ℹ️ Great news, nobody got banned... Yet.") return ot_msg = '⛔️ *Banned users:*\n\n' for user in mysql.banned: bot.send_chat_action(message.chat.id, 'typing') ot_link = mysql.user_tables(int(user))['open_ticket_link'] ot_msg += "• [{0}{1}](tg://user?id={2}) (`{2}`)\n[➜ Go to last msg]({3})\n".format( bot.get_chat(int(user)).first_name, ' {0}'.format(bot.get_chat(int(user)).last_name) if bot.get_chat(int(user)).last_name else '', int(user), ot_link) bot.send_message(message.chat.id, ot_msg, parse_mode='Markdown') else: pass