def unban(not_so_bad_user): if str(not_so_bad_user.id) not in BLACKLIST: debug_group.send_message(text=getDisplayUser(not_so_bad_user) + ' not banned', parse_mode='Markdown') return BLACKLIST.remove(str(not_so_bad_user.id)) saveBlacklist() debug_group.send_message(text=getDisplayUser(not_so_bad_user) + ' unbanned', parse_mode='Markdown')
def ban(bad_user): if bad_user.id == this_bot: return # don't ban the bot itself :p if str(bad_user.id) in BLACKLIST: debug_group.send_message(text=getDisplayUser(bad_user) + ' already banned', parse_mode='Markdown') return BLACKLIST.add(str(bad_user.id)) saveBlacklist() debug_group.send_message(text=getDisplayUser(bad_user) + ' banned', parse_mode='Markdown')
def add(msg, content): if not msg.from_user: return if msg.from_user.id not in CREDENTIALS.get('admins', []): tele.bot.send_message(chat_id=debug_group, text='suggestion: ' + content) msg.reply_text('Only admin can add, your suggestion is recorded.', quote=False) tele.bot.send_message(chat_id=debug_group, text='suggestion from ' + getDisplayUser(msg.from_user), parse_mode='Markdown', disable_web_page_preview=True) return pieces = [x.strip() for x in content.split('/') if x.strip()] if len(pieces) == 0: return msg.reply_text('FAIL. can not find channel: ' + content, quote=False) name = pieces[-1] if name.startswith('@'): name = name[1:] if not name: return msg.reply_text('FAIL. can not find channel: ' + content, quote=False) if name in DB['pool']: return msg.reply_text('channel already in pool: ' + content, quote=False) DB['pool'].append(name) if msg.chat_id < 0: addKey(msg.chat_id, name) msg.reply_text('success', quote=False)
def shouldKick(self, user): if (self.kick_if_name_longer_than and len(user.first_name or '') + len(user.last_name or '') > self.kick_if_name_longer_than): return True if matchKey(getDisplayUser(user), self.kick_if_name_contains): return True return False
def suspiciousUser(user): display = getDisplayUser(user) if isCN(display): return False if len(''.join(display.split())) <= 2: return True if display.lower() == 'deleted account': return True return False
def handleJoin(update, context): msg = update.message for member in msg.new_chat_members: if needKick(member): context.bot.kick_chat_member(msg.chat.id, member.id) ban(member) debug_group.send_message(getDisplayUser(member) + ' kicked from ' + getGroupName(msg), parse_mode='Markdown', disable_web_page_preview=True) continue if member.id != this_bot and member.id not in JOIN_TIME: JOIN_TIME[msg.chat.id] = JOIN_TIME.get(msg.chat.id, {}) JOIN_TIME[msg.chat.id][member.id] = time.time()
def handlePrivate(update, context): global ban usr = update.effective_user msg = update.effective_message if not usr or not msg: return if usr.username == test_usr and msg.text == 'ban': to_ban = msg.reply_to_message.forward_from ban.add(to_ban.username) with open('ban', 'w') as f: f.write( yaml.dump(ban, sort_keys=True, indent=2, allow_unicode=True)) msg.reply_text(getDisplayUser(to_ban) + ' banned', parse_mode='Markdown') return usr = usr.username if not usr: return msg.reply_text(strings['e0']) os.system('mkdir photo > /dev/null 2>&1') photo = None profile = update.effective_user.get_profile_photos() if profile.total_count > 0 and not path.exists('photo/' + usr): photo = profile.photos[0] if msg.photo: photo = msg.photo if photo: photo[0].get_file().download('photo/' + usr) if msg.photo: msg.reply_text(strings['p']) text = (msg.text or '').strip() if not text: return askNext(usr, msg) if msg.reply_to_message: question = msg.reply_to_message.text for index in db.questions: if question == strings['q' + index]: db.save(usr, index, text) msg.reply_text(strings['r']) return askNext(usr, msg) idx = db.getQuestionIndex(usr) if idx == -1: msg.reply_text(strings['h1']) return askNext(usr, msg) if idx == float('Inf'): return msg.reply_text(strings['h2']) db.save(usr, idx, text) msg.reply_text(strings['r']) return askNext(usr, msg)
def deleteMsg(msg): text = msg.text if text: text = ': ' + text else: text = '' action_users = getActionUsers(msg) names = ', '.join([getDisplayUser(x) for x in action_users]) debug_group.send_message(text=names + ' ' + getMsgType(msg) + ' ' + getGroupName(msg) + text, parse_mode='Markdown', disable_web_page_preview=True) if msg.photo: filename = getTmpFile(msg) debug_group.send_photo(photo=open(filename, 'rb')) os.system('rm ' + filename) if msg.video: filename = getTmpFile(msg) debug_group.send_document(document=open(filename, 'rb')) os.system('rm ' + filename) msg.delete()
def needKick(user): name = getDisplayUser(user) return matchKey(name, KICK_KEYS)
def shouldKick(user): if len(user.first_name) + len(user.last_name or '') > 40: return True return badText(getDisplayUser(user))