예제 #1
0
def begin_test(m):
    text = m.text
    uid = m.from_user.id
    if text.startswith('/'):
        if text == '/cancel':
            bot.send_message(uid, get_string('test_cancelled'))
        else:
            bot.send_chat_action(uid, 'typing')
    else:
        qtns = tools.questions
        data = tools.check_name(text)
        if data.valid:
            info = {"name": data.name, "surname": data.surname}
            status = {"score": 0, "limit": 0, "date": None}
            f.open('./user/{}/info.json'.format(uid),
                   'w').write(json.dumps(info))
            f.open('./user/{}/status.json'.format(uid),
                   'w').write(json.dumps(status))
            k = tools.btn_maker(1)
            bot.send_message(uid,
                             text="<b>{}-savol</b>\n{}".format(
                                 1, qtns['1']['question']),
                             reply_markup=k,
                             parse_mode='html')
        else:
            if text == '/cancel':
                bot.send_message(uid, get_string('test_cancelled'))
            else:
                a = bot.send_message(uid,
                                     get_string('test_invalid_credentials'))
                bot.register_next_step_handler(a, begin_test)
 def main(self, argv):
     f = File()
     f2 = File()
     f2.open()
     f.open()
     f.write()
     f2.close()
예제 #3
0
def get_comment(m):
    text = m.text
    uid = m.from_user.id
    cid = m.chat.id
    if text == '/cancel':
        bot.send_message(cid, get_string('book_comment_cancelled'))
        return
    else:
        name = m.from_user.first_name
        if m.from_user.last_name:
            name += " " + m.from_user.last_name
        name = resize(name)
        book_steps = json.loads(f.open('./books/steps.json', 'r').read())
        book_id = book_steps['{}'.format(uid)]
        try:
            books = json.loads(f.open('./books/all.json', 'r').read())
            try:
                books[int(book_id)]
            except Exception as e:
                bot.send_message(uid, get_string('error_in_comment'))
                log('XATOLIK: comment => {}'.format(e))
        except:
            book.start()
        book.add_comment(book_id=book_id, uid=uid, text=text, name=name)
        bot.send_message(cid, get_string('book_comment_saved'))
예제 #4
0
파일: book.py 프로젝트: SamixGroup/hops
def del_comment(data):
    data = data.split('\n')
    book_id = int(data[1])
    starting_text = data[2]
    date = data[3]

    try:
        comments = json.loads(
            f.open('./books/comments/book_{}.db'.format(book_id), 'r').read())
    except:
        f.open('./books/comments/book_{}.db'.format(book_id),
               'w').write(json.dumps({'all': 0}))
        comments = {'all': 0}
    for user in list(comments.keys()):
        if user == 'all':
            continue
        for post in comments[user]['posts']:
            if post['text'].lower().startswith(
                    starting_text.lower()) and post['date'] == date:
                if len(comments[user]['posts']) > 1:
                    comments[user]['posts'].remove(post)
                else:
                    comments.pop(user)
                    comments['all'] -= 1

    result = maker(ind=book_id, comments=comments)
    all_books = start()
    client.edit_page(path=all_books[book_id]['url'][18:],
                     title=all_books[book_id]['title'],
                     content=result,
                     author_name='Hops',
                     author_url='https://t.me/Hopsrobot')
    f.open('./books/comments/book_{}.db'.format(book_id),
           'w').write(json.dumps(comments))
예제 #5
0
파일: book.py 프로젝트: SamixGroup/hops
def add_book(data):
    data = data.split('\n')
    title = data[1]
    author = data[2]
    lang = data[3]
    tip = data[4]
    size = data[5]
    download = data[6]
    book_id = len(books)
    new_book = {
        'title': title,
        'author': author,
        'lang': lang,
        'type': tip,
        'size': size,
        'download': download
    }
    result = maker(book=new_book, ind=book_id)
    page = client.create_page(title=title,
                              content=result,
                              author_name='Hops',
                              author_url='https://t.me/Hopsrobot')
    new_book['url'] = page.url
    books.append(new_book)
    f.open('./books/all.db', 'w').write(json.dumps(books))
예제 #6
0
def editor(m):
    try:
        langs = {'24': '#py', '5': '#py2', '8': '#php'}

        uid = m.from_user.id
        cid = m.chat.id
        request_id = m.message_id
        data = json.loads(
            f.open('./codes/{}/{}/{}_code.json'.format(cid, uid, request_id),
                   'r').read())
        lang = data['lang']
        response_id = data['response_id']
        code = m.text.replace('{}\n'.format(langs[str(lang)]), '', 1)
        modified = modify_the_code(code)
        code = modified[0]
        k = types.InlineKeyboardMarkup()
        b = types.InlineKeyboardButton(text="Info",
                                       callback_data="info_{}/{}/{}".format(
                                           cid, uid, request_id))
        k.add(b)
        try:
            bot.send_chat_action(cid, 'typing')
            compiled = run(lang, code)
            if len(str(compiled.result)) <= 3000:
                if compiled.success:
                    bot.edit_message_text(chat_id=cid,
                                          message_id=response_id,
                                          text=get_string('output').format(
                                              html_converter(compiled.result)),
                                          parse_mode='html',
                                          reply_markup=k)
                else:
                    bot.edit_message_text(
                        chat_id=cid,
                        message_id=response_id,
                        text=get_string('output_error').format(
                            html_converter(compiled.errors)),
                        parse_mode='html',
                        reply_markup=k)
            else:
                bot.edit_message_text(chat_id=cid,
                                      message_id=response_id,
                                      text=get_string('output_too_large'),
                                      parse_mode='html',
                                      reply_markup=k)
            data = {
                "response_id": response_id,
                "stats": compiled.stats,
                "lang": lang
            }
            f.open('./codes/{}/{}/{}_code.json'.format(cid, uid, request_id),
                   'w').write(json.dumps(data))
        except Exception as e:
            log(e)
    except Exception as e:
        log(e)
예제 #7
0
def msg_id(mid=False):
    try:
        data = f.open('./mid.txt', 'r').read()
    except:
        data = '0'
        f.open('./mid.txt', 'w').write(data)

    if mid:
        f.open('./mid.txt', 'w').write(str(mid))
    else:
        return int(data)
예제 #8
0
 def reduce_limit(self):
     atm = (datetime.now() + timedelta(hours=3)).strftime('%Y-%m-%d')
     if self.date != atm:
         self.limit = self.score - 3 if self.score else None
         self.date = atm
     self.limit -= 1
     f.open('./user/{}/status.db'.format(uid), 'w').write(json.dumps(
         {
             "score": self.score,
             "limit": self.limit,
             "date": self.date
         })
     )
예제 #9
0
파일: book.py 프로젝트: SamixGroup/hops
def start():
    global books
    try:
        books = json.loads(f.open('./books/all.db', 'r').read())
    except:
        bot.send_message(dev, str(books))
        result = maker(book=books[0], ind=0)
        page = client.create_page(title=books[0]['title'],
                                  content=result,
                                  author_name='Hops',
                                  author_url='https://t.me/Hopsrobot')
        books[0]['url'] = page.url
        f.open('./books/all.db', 'w').write(json.dumps(books))
    return books
예제 #10
0
def all_pages(uid):
    try:
        data = eval(f.open('./comments/{}/all.db'.format(uid), 'r').read())
        log(1, data)
    except:
        data = False

    if data:
        pages = data['all']
        log(3, pages)
        url = data['url']
        result = []
        stat = {
            'tag': 'b',
            'children': ['{} ta kod uchun izohlar'.format(len(pages))]
        }
        result.append(stat)
        result.append({'tag': 'br'})
        if len(pages) > 0:
            for page in pages:
                result.append({
                    'tag': 'a',
                    'attrs': {
                        'href': page
                    },
                    'children': ['• {}\n'.format(page[18:])]
                })
        else:
            return False
        log(4, result)
        if url:
            log(5, url)
            try:
                page = client.edit_page(path=data['url'][18:],
                                        title='Barcha kod va izohlar',
                                        content=result[:-1],
                                        author_name='Hops',
                                        author_url='https://t.me/Hopsrobot')
            except Exception as e:
                log(7, e)
        else:
            log(6, 'started to create')
            page = client.create_page(title='Barcha kod va izohlar',
                                      content=result,
                                      author_name='Hops',
                                      author_url='https://t.me/Hopsrobot')
            data['url'] = page.url
            log(2, data)
            f.open('./comments/{}/all.db'.format(uid), 'w').write(str(data))
        return page.url
예제 #11
0
def get_user_data(forwarded_message):
    user = forwarded_message.forward_from.id
    a = bot.get_chat_member(python_uz, user)
    if a.status == 'left':
        return False
    data = tools.get_info(user)
    try:
        ban_info = json.loads(
            f.open('./restricted/user_{}.json'.format(user),
                   'r').read())['times']
    except:
        ban_info = 0
    result = get_string('user_info')
    rest = is_restricted(python_uz, user)
    rest_date = get_string('user_info_date').format(
        get_restrict_time(python_uz, user)) if rest else ''
    rest = '{} {}'.format(get_string('yes'),
                          rest_date) if rest else get_string('no')
    certified = get_string('yes') if data.cert else get_string('no')
    limit = data.limit if data.limit else '0'
    score = data.score if data.score else '0'
    result = result.format(
        rest, ban_info, certified,
        get_string('user_info_scores').format(score, limit)
        if data.cert else '')
    return result
예제 #12
0
        def __init__(self, uid):
            self.expired = False
            try:
                data = json.loads(f.open('./user/{}/status.db'.format(uid), 'r').read())
                if data['score'] > 5:
                    self.cert = True
                else:
                    self.cert = False
            except:
                self.cert = False
            if self.cert:
                self.score = data['score']
                self.date = data['date']
                self.limit = data['limit']
            else:
                self.score = None
                self.date = None
                self.limit = None

            if self.limit <= 0:
                if self.date == datetime.now().strftime('%Y-%m-%d'):
                    self.expired = True
                else:
                    self.limit = self.score - 3 if self.score else None
                    self.date = datetime.now().strftime('%Y-%m-%d')
                    self.expired = False
예제 #13
0
파일: book.py 프로젝트: SamixGroup/hops
def add_comment(book_id, uid, text, name):
    all_books = json.loads(f.open('./books/all.db', 'r').read())
    atm = str(time.time()).split('.')[0]
    date = (datetime.now() + timedelta(hours=5)).strftime('%Y.%m.%d')
    user = '******'.format(atm, uid)
    try:
        comments = json.loads(
            f.open('./books/comments/book_{}.db'.format(book_id), 'r').read())
    except:
        f.open('./books/comments/book_{}.db'.format(book_id),
               'w').write(json.dumps({'all': 0}))
        comments = {'all': 0}
    if comments['all'] > 0:
        recorded = False
        for key in list(comments.keys()):
            if str(uid) in key:
                comments[key]['posts'].append({'text': text, 'date': date})
                recorded = True
        if not recorded:
            comments[user] = {
                'name': name,
                'posts': [{
                    'text': text,
                    'date': date
                }]
            }
    else:
        comments[user] = {
            'name': name,
            'posts': [{
                'text': text,
                'date': date
            }]
        }
    comments['all'] += 1
    f.open('./books/comments/book_{}.db'.format(book_id),
           'w').write(json.dumps(comments))
    result = maker(all_books[book_id], ind=book_id, comments=comments)
    if all_books[book_id]['url']:
        client.edit_page(path=all_books[book_id]['url'][18:],
                         title=all_books[book_id]['title'],
                         content=result,
                         author_name='Hops',
                         author_url='https://t.me/Hopsrobot')
    else:
        page = client.create_page(title=all_books[book_id]['title'],
                                  content=result,
                                  author_name='Hops',
                                  author_url='https://t.me/Hopsrobot')
        all_books[book_id]['url'] = page.url
        f.open('./books/all.db', 'w').write(json.dumps(all_books))
예제 #14
0
def notify(message, mark=False):
    user = message.reply_to_message.from_user.id
    code_id = message.reply_to_message.message_id
    code = message.reply_to_message.text
    try:
        info = json.loads(
            f.open(
                './comments/{}/codes/{}/info_{}.db'.format(
                    user, code_id, code_id), 'r').read())
    except:
        info = {
            'likes': {
                'all': 0,
                'clicked': []
            },
            'people': 0,
            'comments': 0,
            'code': code,
            'url': None,
            'notified': False
        }
        f.open(
            './comments/{}/codes/{}/info_{}.db'.format(user, code_id, code_id),
            'w').write(json.dumps(info))
        info = json.loads(
            f.open(
                './comments/{}/codes/{}/info_{}.db'.format(
                    user, code_id, code_id), 'r').read())
    if mark:
        info['notified'] = True
        f.open(
            './comments/{}/codes/{}/info_{}.db'.format(user, code_id, code_id),
            'w').write(json.dumps(info))
    return info['notified']
예제 #15
0
def update(message, is_code=False):
    if is_code:
        user = message.from_user.id
        code_id = message.message_id
        code = message.text
        try:
            info = json.loads(
                f.open(
                    './comments/{}/codes/{}/info_{}.db'.format(
                        user, code_id, code_id), 'r').read())
        except:
            info = {
                'likes': {
                    'all': 0,
                    'clicked': []
                },
                'people': 0,
                'comments': 0,
                'code': code,
                'url': None,
                'notified': False
            }
            f.open(
                './comments/{}/codes/{}/info_{}.db'.format(
                    user, code_id, code_id), 'w').write(json.dumps(info))
            info = json.loads(
                f.open(
                    './comments/{}/codes/{}/info_{}.db'.format(
                        user, code_id, code_id), 'r').read())
        info['code'] = code
        f.open(
            './comments/{}/codes/{}/info_{}.db'.format(user, code_id, code_id),
            'w').write(json.dumps(info))
        return False, False

    user = message.reply_to_message.from_user.id
    code_id = message.reply_to_message.message_id
    commenter = message.from_user.id
    comment = message.text
    code = message.reply_to_message.text

    if not code.startswith('#p'):
        return False, False

    likes = ['👍', '❤️']
    icons = ['❤️', '👤', '✏️']

    try:
        info = json.loads(
            f.open(
                './comments/{}/codes/{}/info_{}.db'.format(
                    user, code_id, code_id), 'r').read())
    except:
        info = {
            'likes': {
                'all': 0,
                'clicked': []
            },
            'people': 0,
            'comments': 0,
            'code': code,
            'url': None,
            'notified': False
        }
        f.open(
            './comments/{}/codes/{}/info_{}.db'.format(user, code_id, code_id),
            'w').write(json.dumps(info))
        info = json.loads(
            f.open(
                './comments/{}/codes/{}/info_{}.db'.format(
                    user, code_id, code_id), 'r').read())

    for i in likes:
        if comment.startswith(i):
            if not commenter in info['likes']['clicked']:
                info['likes']['clicked'].append(commenter)
                info['likes']['all'] += 1

    try:
        data = json.loads(
            f.open(
                './comments/{}/codes/{}/{}.db'.format(user, code_id, code_id),
                'r').read())
    except:
        data = {'users': {}}
        f.open('./comments/{}/codes/{}/{}.db'.format(user, code_id, code_id),
               'w').write(json.dumps(data))
        data = json.loads(
            f.open(
                './comments/{}/codes/{}/{}.db'.format(user, code_id, code_id),
                'r').read())

    if str(commenter) in data['users'].keys():
        if str(message.message_id) in data['users'][str(commenter)].keys():
            data['users'][str(commenter)][str(
                message.message_id)][0] = node(message)[str(
                    message.message_id)][0]
        else:
            data['users'][str(commenter)][str(
                message.message_id)] = node(message)[str(message.message_id)]
    else:
        data['users'][str(commenter)] = node(message)

    result = list()
    result.append({'tag': 'pre', 'children': [code]})
    result.append({
        'tag': 'aside',
        'children': ['❤️ {}'.format(info['likes']['all'])]
    })
    all_people = 0
    all_comments = 0
    if len(data['users'].keys()) > 0:
        for _user in data['users'].keys():
            all_people += 1
            result.append({'tag': 'pre', 'children': [name(int(_user))]})
            for comment in data['users'][_user].keys():
                all_comments += 1
                result.append(data['users'][_user][comment][0])
                result.append(data['users'][_user][comment][1])
                br = {'tag': 'br'}
                result.append(br)

    info['people'] = all_people
    info['comments'] = all_comments

    result[1]['children'] = [
        '{likes}  {like} {space} {peoples}  {people} {space} {comments}  {comment}'
        .format(like=icons[0],
                likes=info['likes']['all'],
                people=icons[1],
                peoples=info['people'],
                comment=icons[2],
                comments=info['comments'],
                space=" " * 10)
    ]
    if info['url']:
        page = client.edit_page(path=info['url'][18:],
                                title='Kod uchun izohlar',
                                content=result,
                                author_name='Hops',
                                author_url='https://t.me/Hopsrobot',
                                return_content=True)
    else:
        page = client.create_page(title='Kod uchun izohlar',
                                  content=result,
                                  author_name='Hops',
                                  author_url='https://t.me/Hopsrobot')

    try:
        all_pages = json.loads(
            f.open('./comments/{}/all.db'.format(user), 'r').read())
    except:
        f.open('./comments/{}/all.db'.format(user),
               'w').write(json.dumps({
                   "all": [],
                   "url": None
               }))
        all_pages = json.loads(
            f.open('./comments/{}/all.db'.format(user), 'r').read())

    if not page.url in all_pages['all']:
        all_pages['all'].append(page.url)
        f.open('./comments/{}/all.db'.format(user),
               'w').write(json.dumps(all_pages))

    info['url'] = page.url

    f.open('./comments/{}/codes/{}/info_{}.db'.format(user, code_id, code_id),
           'w').write(json.dumps(info))
    f.open('./comments/{}/codes/{}/{}.db'.format(user, code_id, code_id),
           'w').write(json.dumps(data))
    if user == commenter:
        return False, False
    return page.url, True
예제 #16
0
	def main(self, argv):
		f = File()
		f.open()
		f.write()
		f.close()
		print "Done."
예제 #17
0
def test_callback(call):
    user = call.from_user.id
    cid = call.message.chat.id
    if call.data.startswith('done_'):
        dat = call.data.replace('done_', '', 1).split('|')
        uid = int(dat[0])
        http = dat[1]
        if user == uid:
            bot.answer_callback_query(
                call.id,
                text=get_string('new_member_rules_prepare'),
                url="https://t.me/{}?start=rules_{}".format(botlink, http),
                show_alert=True)
            bot.delete_message(call.message.chat.id, call.message.message_id)
        else:
            bot.answer_callback_query(
                call.id,
                text=get_string('new_member_rules_taken_by_wrong_user'),
                show_alert=True)
    if call.data.startswith('info_'):
        path = call.data.replace('info_', '', 1)
        data = json.loads(
            f.open('./codes/{}_code.json'.format(path), 'r').read())
        info = splitter(data['stats'])
        bot.answer_callback_query(callback_query_id=call.id,
                                  text=info,
                                  show_alert=True)
    if call.data.startswith('test_'):
        data = call.data.replace('test_', '', 1).split('_')
        ind = int(data[0]) + 1
        answer = data[1]
        score = int(data[2])
        scores = {
            '6': [3, 'E'],
            '7': [4, 'D'],
            '8': [5, 'C'],
            '9': [6, 'B'],
            '10': [7, 'A']
        }
        if answer == 'True':
            score += 1
        if ind == 11:
            if score >= 6:
                user_data = tools.get_info(user)
                data = json.loads(
                    f.open('./user/{}/status.json'.format(user), 'r').read())
                data['score'] = score
                if user_data.cert:
                    data['limit'] = user_data.limit
                else:
                    data['limit'] = scores[str(score)][0]
                data['date'] = datetime.now().strftime('%Y-%m-%d')
                number = "#{}{}".format(scores[str(score)][1], str(user)[-5:])
                data['cert'] = number
                f.open('./user/{}/status.json'.format(user),
                       'w').write(json.dumps(data))
                bot.edit_message_text(
                    chat_id=cid,
                    message_id=call.message.message_id,
                    text=get_string('get_cert_completed_success').format(
                        scores[str(score)][1], scores[str(score)][0]))
                try:
                    data = json.loads(
                        f.open('./certificates/users.json', 'r').read())
                except:
                    f.open('./certificates/users.json',
                           'w').write('{"all": []}')
                    data = json.loads(
                        f.open('./certificates/users.json', 'r').read())
                data['all'].append(user)
                f.open('./certificates/users.json',
                       'w').write(json.dumps(data))
            else:
                bot.edit_message_text(
                    chat_id=cid,
                    message_id=call.message.message_id,
                    text=get_string('get_cert_completed_fail').format(score))
        else:
            k = tools.btn_maker(ind, score)
            bot.edit_message_text(chat_id=cid,
                                  message_id=call.message.message_id,
                                  text="<b>{}-savol</b>\n{}".format(
                                      ind,
                                      tools.questions[str(ind)]['question']),
                                  parse_mode='html',
                                  reply_markup=k)

    if call.data.startswith('cert_'):
        uid = int(call.data.replace('cert_', '', 1))
        if user == uid:
            bot.delete_message(cid, call.message.message_id)
            bot.answer_callback_query(
                call.id,
                url='https://t.me/{}?start=start_test'.format(botlink))
        else:
            bot.answer_callback_query(
                call.id,
                text=get_string("get_cert_button_taken_by_wrong_user"),
                show_alert=True)
    if call.data.startswith('booknextpage_'):
        page_number = int(call.data.split('_')[1])
        books = book.start()
        mark = book.books_in_keyboards(all_books=books,
                                       go=True,
                                       page_number=page_number)
        bot.edit_message_text(chat_id=cid,
                              message_id=call.message.message_id,
                              text=get_string('book_choose'),
                              reply_markup=mark)

    if call.data.startswith('bookbackpage_'):
        page_number = int(call.data.split('_')[1])
        books = book.start()
        mark = book.books_in_keyboards(all_books=books,
                                       back=True,
                                       page_number=page_number)
        bot.edit_message_text(chat_id=cid,
                              message_id=call.message.message_id,
                              text=get_string('book_choose'),
                              reply_markup=mark)
예제 #18
0
def new_chat_member(message):
    chat_id = message.chat.id
    key = random.choice(get_string('keys'))
    key_in = get_string('keys').index(key)
    try:
        data = json.loads(f.open('./agreed/users.json', 'r').read())
    except Exception as e:
        log("agreed/users -> {}".format(e))
        f.open('./agreed/users.json', 'w').write('{"all": []}')
        data = json.loads(f.open('./agreed/users.json', 'r').read())
    users = data['all']

    for i in message.new_chat_members:
        if i.id == bot_id:
            if stranger(chat_id) and message.chat.type != 'private':
                bot.leave_chat(chat_id)
        else:
            if not i.is_bot:
                name = i.first_name
                if i.last_name:
                    name += " " + i.last_name
                name = resize(name)
                name = html_converter(name)
                try:
                    data = json.loads(
                        f.open('./restricted/user_{}.json'.format(i.id),
                               'r').read())
                except Exception as e:
                    log("Yangi fayl ochildi: {}".format(e))
                    f.open('./restricted/user_{}.json'.format(i.id),
                           'w').write('{"times": 0}')
                    data = json.loads(
                        f.open('./restricted/user_{}.json'.format(i.id),
                               'r').read())
                times = data['times']
                if is_restricted(chat_id, i.id):
                    until_date = get_restrict_time(chat_id, i.id)
                    if times >= 720:
                        bot.kick_chat_member(chat_id, i.id)
                        bot.send_message(
                            chat_id,
                            get_string('banned_in_entrance').format(uid=i.id,
                                                                    name=name),
                            parse_mode='html')
                    else:
                        try:
                            if until_date == 'forever':
                                k = types.InlineKeyboardMarkup()
                                b = types.InlineKeyboardButton(
                                    text=get_string('click_the_button'),
                                    callback_data="done_{}|{}_{}_{}".format(
                                        i.id, encryptor(i.id),
                                        encryptor(chat_id), encryptor(key_in)))
                                k.row(b)
                                bot.send_message(
                                    chat_id,
                                    get_string('restricted_user_rules').format(
                                        i.id, name),
                                    parse_mode='HTML',
                                    reply_markup=k)
                            else:
                                bot.send_message(
                                    chat_id,
                                    get_string('restricted_user').format(
                                        i.id, name, until_date),
                                    parse_mode='HTML')
                        except Exception as e:
                            log("Trying again: {}".format(e))
                elif i.id in users and not is_restricted(chat_id, i.id):
                    if times >= 720:
                        bot.kick_chat_member(chat_id, i.id)
                        bot.send_message(
                            chat_id,
                            get_string('banned_in_entrance').format(uid=i.id,
                                                                    name=name),
                            parse_mode='html')
                    else:
                        bot.send_message(chat_id,
                                         get_string('old_member').format(
                                             i.id, name),
                                         parse_mode='HTML')
                else:
                    user = "******".format(encryptor(i.id),
                                             encryptor(chat_id),
                                             encryptor(key_in))
                    try:
                        bot.restrict_chat_member(chat_id,
                                                 i.id,
                                                 can_send_messages=False)
                        msg = bot.send_message(chat_id,
                                               get_string('new_member').format(
                                                   name=resize(name),
                                                   user=user),
                                               parse_mode='HTML')
                        f.open('./msg_ids/{}.txt'.format(i.id),
                               'w').write(str(msg.message_id))
                        msg_id(msg.message_id)
                    except Exception as e:
                        log("Restrictda xato: " + str(e))
예제 #19
0
def hops(m, words):
    if len(words) > 1:
        words = ", ".join(words)
    else:
        words = words[0]
    words = html_converter(words)
    uid = m.from_user.id
    cid = m.chat.id
    name = m.from_user.first_name
    if m.from_user.last_name:
        name += " " + m.from_user.last_name
    name = resize(name)
    name = html_converter(name)
    stat = bot.get_chat_member(cid, uid).status
    if stat != 'creator' and stat != 'administrator':
        if uid not in verified:
            try:
                import time
                try:
                    data = json.loads(
                        f.open('./restricted/user_{}.json'.format(uid),
                               'r').read())
                except Exception as e:
                    log("Yangi fayl ochildi: {}".format(e))
                    f.open('./restricted/user_{}.json'.format(uid),
                           'w').write('{"times": 0}')
                    data = json.loads(
                        f.open('./restricted/user_{}.json'.format(uid),
                               'r').read())
                times = data['times']
                if is_restricted(cid, uid):
                    times += (times + 1)
                else:
                    times += 1
                data = {"times": times}
                f.open('./restricted/user_{}.json'.format(uid),
                       'w').write(json.dumps(data))
                atm = datetime.now()
                result = atm + timedelta(hours=times)
                overall = time.mktime(result.timetuple())
                if times >= 720:
                    bot.restrict_chat_member(cid,
                                             uid,
                                             can_send_messages=False,
                                             can_send_media_messages=False,
                                             can_send_other_messages=False,
                                             can_add_web_page_previews=False,
                                             until_date=overall)
                    bot.kick_chat_member(cid, uid)
                else:
                    bot.restrict_chat_member(cid,
                                             uid,
                                             can_send_messages=False,
                                             until_date=overall)

            except Exception as e:
                log("Error while restricting: {}".format(e))
            msg = bot.send_message(cid,
                                   get_string('warn') + steper(0, 7),
                                   parse_mode='HTML',
                                   reply_to_message_id=m.message_id)
            for i in range(1, 8):
                sleep(3)
                try:
                    bot.edit_message_text(chat_id=cid,
                                          message_id=msg.message_id,
                                          text=get_string('warn') +
                                          steper(i, 7),
                                          parse_mode='HTML')
                except:
                    break
            sleep(1)
            try:
                bot.delete_message(cid, m.message_id)
            except:
                bot.send_chat_action(cid, 'typing')
            bot.delete_message(cid, msg.message_id)
            until_date = get_restrict_time(cid, uid)
            if until_date == 'forever':
                bot.send_message(cid,
                                 get_string('banned').format(name,
                                                             times,
                                                             uid=uid,
                                                             words=words),
                                 parse_mode='HTML')
            else:
                bot.send_message(cid,
                                 get_string('restricted').format(name,
                                                                 times,
                                                                 until_date,
                                                                 uid=uid,
                                                                 words=words),
                                 parse_mode='HTML')
예제 #20
0
def main(m):
    text = m.text
    uid = m.from_user.id
    cid = m.chat.id
    lowmsg = text.lower()
    name = m.from_user.first_name
    stat = bot.get_chat_member(python_uz, uid).status
    allowed = ['administrator', 'creator']
    if m.reply_to_message:
        if m.reply_to_message:
            if m.reply_to_message.text:
                if m.reply_to_message.text.startswith('#py\n') \
                        or m.reply_to_message.text.startswith('#py2\n') \
                        or m.reply_to_message.text.startswith('#php\n'):
                    coder = m.reply_to_message.from_user.id
                    page = telegraph.update(m)
                    if page[0]:
                        notify = telegraph.notify(m)
                        if page[1]:
                            if not notify:
                                bot.send_message(
                                    coder,
                                    get_string('you_have_new_comment').format(
                                        page[0]),
                                    parse_mode='html')
                                telegraph.notify(m, True)
                        else:
                            if not notify:
                                bot.send_message(
                                    coder,
                                    get_string(
                                        'somebody_liked_your_code').format(
                                            page[0]),
                                    parse_mode='html')
                                telegraph.notify(m, True)

    if m.from_user.last_name:
        name += " " + m.from_user.last_name
    name = resize(name)
    if lowmsg == 'order_101':
        bot.send_message(
            cid,
            'Privacy and policy requirements [ordered by 101]\n\n{}'.format(
                get_string('new_member_rules')))

    if lowmsg == 'order_102':
        bot.send_message(cid,
                         'Manual for beginners [ordered by 102]\n\n{}'.format(
                             get_string('manual')),
                         parse_mode='html')
    if lowmsg == 'yordam' and m.chat.type == 'private':
        bot.send_message(cid, get_string('manual'), parse_mode='html')
    if cid in allowed_groups:
        police = scaner(lowmsg)
        is_bad = police['is_bad']
        if is_bad:
            hops(m, police['words'])
        if m.photo or m.video or m.audio or m.voice or m.document:
            police = scaner(lowmsg)
            is_bad = police['is_bad']
            if is_bad:
                hops(m, police['words'])
            else:
                if anti_spam(text):
                    bot.delete_message(cid, m.message_id)
    elif stranger(cid) and m.chat.type != 'private':
        log(cid)
        bot.leave_chat(cid)

    elif m.chat.type == 'private':
        if text.startswith('/start'):
            if text == '/start start_test':
                a = bot.send_message(cid, get_string('start_test'))
                bot.register_next_step_handler(a, begin_test)

            elif text.startswith('/start bookcomment_'):
                a = bot.send_message(cid, get_string('book_send_comment'))
                book_id = int(text.split('_')[1])
                try:
                    book_steps = json.loads(
                        f.open('./books/steps.json', 'r').read())
                    book_steps['{}'.format(uid)] = book_id
                    f.open('./books/steps.json',
                           'w').write(json.dumps(book_steps))
                except:
                    f.open('./books/steps.json', 'w').write(
                        json.dumps({
                            'ok': True,
                            '{}'.format(uid): book_id
                        }))
                bot.register_next_step_handler(a, get_comment)

            else:
                try:
                    try:
                        data = json.loads(f.open('./members.json', 'r').read())
                    except:
                        f.open('./members.json', 'w').write('{"all":[]}')
                        data = json.loads(f.open('./members.json', 'r').read())
                    if uid in data['all']:
                        pass
                    else:
                        data['all'].append(uid)
                    text = text.replace('/start ', '', 1)
                    if text.startswith('rules_'):
                        try:
                            data = json.loads(
                                f.open('./agreed/users.json', 'r').read())
                        except Exception as e:
                            log("agreed/users -> {}".format(e))
                            f.open('./agreed/users.json',
                                   'w').write('{"all": []}')
                            data = json.loads(
                                f.open('./agreed/users.json', 'r').read())
                        users = data['all']
                        if uid in users:
                            bot.send_message(cid, get_string('agreed_already'))
                        else:
                            datas = text.replace('rules_', '', 1).split('_')
                            user = int(decryptor(datas[0]))
                            chat_id = decryptor(datas[1])
                            key_in = int(decryptor(datas[2]))
                            if uid == user:
                                msg = bot.send_message(
                                    uid,
                                    get_string('new_member_rules').format(
                                        key=get_string('keys')[key_in]),
                                    parse_mode='HTML')
                                info = {"cid": chat_id, "key_in": key_in}
                                f.open('./users/{}_rules.json'.format(uid),
                                       'w').write(json.dumps(info))
                                bot.register_next_step_handler(msg, sign)
                            else:
                                bot.send_message(
                                    cid,
                                    get_string('rules_taken_by_wrong_user'))
                    f.open('./members.json', 'w').write(json.dumps(data))
                except Exception as e:
                    log(
                        """Common Rule: {}\n\n{}\n<a href="tg://user?id={}">{}</a>"""
                        .format(html_converter(str(e)), html_converter(str(m)),
                                uid, html_converter(name)), )
    else:
        pass
    if lowmsg == '#stat':
        if m.chat.type == 'private':
            try:
                data = json.loads(
                    f.open('./restricted/user_{}.json'.format(uid),
                           'r').read())
            except:
                data = {"times": 0}
            times = int(data['times'])
            if times > 0:
                bot.send_message(cid,
                                 get_string('stat_restricted').format(times),
                                 reply_to_message_id=m.message_id)
            else:
                bot.send_message(cid,
                                 get_string('stat_good'),
                                 reply_to_message_id=m.message_id)
        else:
            bot.send_chat_action(cid, "typing")
    if lowmsg == '#comments':
        if m.chat.type == 'private':
            data = telegraph.all_pages(uid)
            if data:
                msg = get_string('comments_all').format(data)
            else:
                msg = get_string('comments_not_found')
            bot.send_message(uid, msg, parse_mode='html')
    if text.startswith('#py\n'):
        telegraph.update(m, True)
        runner(m, '#py')
    if text.startswith('#py2\n'):
        telegraph.update(m, True)
        runner(m, '#py2')
    if text.startswith('#php\n'):
        telegraph.update(m, True)
        runner(m, '#php')
    if text == '/test':
        if m.chat.type == 'private':
            try:
                qtns = questions
                json.loads(
                    f.open('./user/{}/info.json'.format(uid), 'r').read())
                k = btn_maker(1)
                bot.send_message(uid,
                                 text=get_string('test_question').format(
                                     1, qtns['1']['question']),
                                 reply_markup=k,
                                 parse_mode='html')
            except:
                a = bot.send_message(cid, get_string('start_test'))
                bot.register_next_step_handler(a, begin_test)

    if text == '#books':
        if m.chat.type == 'private':
            books = book.start()
            mark = book.books_in_keyboards(all_books=books, first=True)
            bot.send_message(cid, get_string('book_choose'), reply_markup=mark)

    if uid == dev or stat in allowed:
        if text.startswith("#reo "):
            data = text.replace("#reo ", "", 1).split()
            user = int(data[0])
            amount = int(data[1])
            try:
                data = json.loads(
                    f.open('./restricted/user_{}.json'.format(user),
                           'r').read())
            except:
                data = {"times": 0}
            times = int(data['times'])
            data = {"times": amount}
            f.open('./restricted/user_{}.json'.format(user),
                   'w').write(json.dumps(data))
            bot.send_message(cid,
                             get_string('reo').format(user, get_string('user'),
                                                      times, amount),
                             reply_to_message_id=m.message_id,
                             parse_mode='HTML')

        elif text.startswith('#add_book\n'):
            book.add_book(text)
            bot.send_message(cid, "Kitob qo'shildi")

        elif text.startswith('#del_book '):
            book_id = int(text.split()[1])
            book.del_book(book_id)
            log("O'chirildi")

        elif text.startswith('#del_comment\n'):
            book.del_comment(text)
            bot.send_message(cid, "O'chirildi")

        elif text.startswith('#send '):
            text = text.replace('#send ', '', 1)
            try:
                cid = int(text.split()[0])
            except:
                if text.split()[0] == 'py':
                    text = text.replace('py', '', 1)
                    cid = python_uz
                else:
                    log("Xatolik kelib chiqdi")
            text = text.replace(str(cid), '', 1)
            try:
                bot.send_message(cid,
                                 text,
                                 parse_mode='markdown',
                                 disable_web_page_preview=True)
                log("Jo'natildi")
            except:
                log("Markdownda xato")

        elif text.startswith("#check "):
            data = text.replace("#check ", "", 1).split()
            user = int(data[0])
            try:
                data = json.loads(
                    f.open('./restricted/user_{}.json'.format(user),
                           'r').read())
            except Exception as e:
                data = {"times": 0}
            times = int(data['times'])
            bot.send_message(cid,
                             "<a href=\"tg://user?id={}\">Vaqt</a>: {}".format(
                                 user, times),
                             reply_to_message_id=m.message_id,
                             parse_mode='html')

        elif m.forward_from:
            if stat == 'administrator' or stat == 'creator':
                if m.chat.type == 'private':
                    data = get_user_data(m)
                    if data:
                        bot.send_message(uid, data, parse_mode='html')
                    else:
                        bot.send_message(uid,
                                         get_string('user_info_not_a_member'))
    if cid == python_uz:
        msg_id(m.message_id)
예제 #21
0
파일: book.py 프로젝트: SamixGroup/hops
def del_book(book_id):
    all_books = start()
    books.pop(book_id)
    f.open('./books/all.db', 'w').write(json.dumps(all_books))
예제 #22
0
파일: book.py 프로젝트: SamixGroup/hops
def maker(book=None, ind=0, comments=False):

    if not comments:
        try:
            comments = json.loads(
                f.open('./books/comments/book_{}.db'.format(ind), 'r').read())
        except:
            f.open('./books/comments/book_{}.db'.format(ind),
                   'w').write(json.dumps({'all': 0}))
            comments = {'all': 0}
    if not book:
        all_books = start()
        book = all_books[ind]

    result = []
    br = {'tag': 'br'}
    result.append(br)
    result.append({
        'tag': 'b',
        'children': ['Muallif: {}'.format(book['author'])]
    })
    result.append(br)
    result.append({
        'tag': 'b',
        'children': ['Til: {}'.format(langs[book['lang']])]
    })
    result.append(br)
    result.append({
        'tag': 'b',
        'children': ['Turi: {}'.format(book['type'].upper())]
    })
    result.append(br)
    result.append({
        'tag': 'b',
        'children': ['Hajmi: {} MB'.format(book['size'])]
    })
    result.append(br)
    result.append({
        'tag': 'a',
        'attrs': {
            'href': book['download']
        },
        'children': ['⬇️YUKLAB OLISH']
    })

    result.append({'tag': 'br'})
    result.append({'tag': 'aside', 'children': ['Kitob haqida fikrlar']})
    if comments['all'] > 0:
        for person in sorted(list(comments.keys())):
            if person == 'all':
                continue
            log(0, person, comments)
            log(list(comments.keys()))
            log(comments[person])
            try:
                result.append({
                    'tag': 'pre',
                    'children': [comments[person]['name']]
                })
            except Exception as e:
                return '1. ' + str(e)
            for post in comments[person]['posts']:
                try:
                    result.append({'tag': 'code', 'children': [post['date']]})
                    result.append({
                        'tag': 'blockquote',
                        'children': [post['text']]
                    })
                except Exception as e:
                    return '2. ' + str(e)
    else:
        result.append({
            'tag': 'i',
            'children': ['Hozircha izohlar mavjud emas']
        })
    return result
예제 #23
0
	def main(self, argv):
		f = File()
		f.open()
		f.write()
예제 #24
0
def runner(m, lang):
    uid = m.from_user.id
    cid = m.chat.id
    langs = {'#py': 24, '#py2': 5, '#php': 8}
    available = True

    if m.chat.type != 'private':
        status = bot.get_chat_member(cid, uid).status
        if status != 'administrator' and status != 'creator':
            user = get_info(uid)
            if user.cert:
                if user.expired:
                    available = False
                else:
                    user.reduce_limit()
            else:
                available = False
                k = types.InlineKeyboardMarkup()
                b = types.InlineKeyboardButton(
                    text=get_string('get_cert_button'),
                    callback_data='cert_{}'.format(uid))
                k.row(b)
                bot.send_message(cid,
                                 get_string('get_cert'),
                                 reply_markup=k,
                                 reply_to_message_id=m.message_id)

    if available:
        try:
            bot.send_chat_action(cid, 'typing')
            code = m.text.replace('{}\n'.format(lang), '', 1)
            modified = modify_the_code(code)
            code = modified[0]
            changed = modified[1]
            request_id = m.message_id
            compiled = run(langs[lang], code)
            k = types.InlineKeyboardMarkup()
            b = types.InlineKeyboardButton(
                text="Info",
                callback_data="info_{}/{}/{}".format(cid, uid, request_id))
            k.add(b)
            if len(str(compiled.result)) <= 3000:
                if compiled.success:
                    check = scaner(
                        compiled.result) if m.chat.type != 'private' else {
                            'is_bad': False
                        }
                    if check['is_bad'] and (not changed):
                        bot.send_message(cid,
                                         get_string('bad_word_in_output'),
                                         parse_mode='html',
                                         reply_to_message_id=m.message_id)
                        hops(m, check['words'])
                        return
                    response = bot.send_message(
                        cid,
                        get_string('output').format(
                            html_converter(compiled.result)),
                        reply_to_message_id=m.message_id,
                        parse_mode='html',
                        reply_markup=k)
                else:
                    response = bot.send_message(
                        cid,
                        get_string('output_error').format(
                            html_converter(compiled.errors)),
                        reply_to_message_id=m.message_id,
                        parse_mode='html',
                        reply_markup=k)
            else:
                response = bot.send_message(cid,
                                            get_string('output_too_large'),
                                            reply_to_message_id=m.message_id,
                                            parse_mode='html')
            response_id = response.message_id
            data = {
                "response_id": response_id,
                "stats": compiled.stats,
                "lang": langs[lang]
            }
            f.open('./codes/{}/{}/{}_code.json'.format(cid, uid, request_id),
                   'w').write(json.dumps(data))

        except Exception as e:
            log(e)
            bot.send_message(cid,
                             get_string('fatal_error'),
                             reply_to_message_id=m.message_id)
예제 #25
0
def sign(m):
    text = m.text
    uid = m.from_user.id
    cid = m.chat.id
    lowmsg = str(text).lower()
    try:
        data = json.loads(f.open('./agreed/users.json', 'r').read())
    except Exception as e:
        log("agreed/users -> {}".format(e))
        f.open('./agreed/users.json', 'w').write('{"all": []}')
        data = json.loads(f.open('./agreed/users.json', 'r').read())
    users = data['all']
    try:
        info = json.loads(
            f.open('./users/{}_rules.json'.format(uid), 'r').read())
    except Exception as e:
        log("Error in f.opening users/rules -> {}".format(e))
        bot.send_message(cid, get_string('fatal_error'))
        info = {}
    chat_id = int(info['cid'])
    key_in = int(info['key_in'])
    if lowmsg == get_string('keys')[key_in]:
        try:
            try:
                bot.restrict_chat_member(chat_id=chat_id,
                                         user_id=uid,
                                         can_send_messages=True,
                                         can_send_media_messages=True,
                                         can_send_other_messages=True,
                                         can_add_web_page_previews=True)
            except Exception as e:
                log("Rest: " + str(e))
            name = m.from_user.first_name
            if m.from_user.last_name:
                name += " " + m.from_user.last_name
            name = resize(name)
            name = html_converter(name)

            try:
                msg_id_of_sent_rules_in_group = int(
                    f.open('./msg_ids/{}.txt'.format(uid), 'r').read())
            except:
                msg_id_of_sent_rules_in_group = 0

            last_message_in_group = msg_id()
            if int(last_message_in_group) == int(
                    msg_id_of_sent_rules_in_group):
                bot.edit_message_text(
                    chat_id=chat_id,
                    message_id=last_message_in_group,
                    text=get_string('new_agreement_in_group').format(
                        uid, resize(name)),
                    parse_mode='HTML')
            else:
                bot.send_message(chat_id,
                                 get_string('new_agreement_in_group').format(
                                     uid, resize(name)),
                                 parse_mode='HTML')

            bot.send_message(uid, get_string('congrats'), parse_mode='HTML')
            bot.send_message(uid, get_string('manual'), parse_mode='html')

            users.append(uid)
            data = {"all": users}
            f.open('./agreed/users.json', 'w').write(json.dumps(data))
        except Exception as e:
            log("RestOver: " + str(e))
    else:
        if text.startswith('/'):
            bot.send_chat_action(cid, 'typing')
        else:
            bot.send_message(uid, get_string('no_agreement'))