Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telebot
- import requests
- import json
- import re
- from googletrans import Translator
- bot = telebot.TeleBot('') # bot id
- arr = []
- trs = []
- x1 = ''
- x2 = ''
- x3 = ''
- x4 = ''
- data = ''
- out = ''
- final = ''
- final2 = ''
- final3 = ''
- final4 = ''
- msg_id = ''
- msg_id2 = ''
- msg_id3 = ''
- msg_id4 = ''
- headers = {
- 'authority': 'beta.character.ai',
- 'accept': '*/*',
- 'accept-language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,ja;q=0.6',
- 'authorization': '', # token
- 'content-type': 'application/json',
- 'dnt': '1',
- 'origin': 'https://beta.character.ai',
- 'referer': 'https://beta.character.ai/chat?char=',
- 'sec-ch-ua': '"Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"',
- 'sec-ch-ua-mobile': '?0',
- 'sec-ch-ua-platform': '"Windows"',
- 'sec-fetch-dest': 'empty',
- 'sec-fetch-mode': 'cors',
- 'sec-fetch-site': 'same-origin',
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
- }
- json_data = {
- 'history_external_id': '', # history id
- 'character_external_id': '', # character id
- 'text': '',
- 'tgt': '', #internal id
- 'ranking_method': 'random',
- 'staging': False,
- 'model_server_address': None,
- 'override_prefix': None,
- 'override_rank': None,
- 'rank_candidates': None,
- 'filter_candidates': None,
- 'prefix_limit': None,
- 'prefix_token_limit': None,
- 'livetune_coeff': None,
- 'stream_params': None,
- 'enable_tti': True,
- 'initial_timeout': None,
- 'insert_beginning': None,
- 'translate_candidates': None,
- 'stream_every_n_steps': 100,
- 'chunks_to_pad': 100,
- 'is_proactive': False,
- 'image_rel_path': '',
- 'image_description': '',
- 'image_description_type': '',
- 'image_origin_type': '',
- 'voice_enabled': False,
- }
- update_headers = {
- 'authority': 'beta.character.ai',
- 'accept': '*/*',
- 'accept-language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,ja;q=0.6',
- 'authorization': '', # token
- 'content-type': 'application/json',
- 'sec-ch-ua': '"Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"',
- 'sec-ch-ua-mobile': '?0',
- 'sec-ch-ua-platform': '"Windows"',
- 'sec-fetch-dest': 'empty',
- 'sec-fetch-mode': 'cors',
- 'sec-fetch-site': 'same-origin',
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
- }
- update_json_data = {
- 'message_id': '',
- 'reason': 'SWIPE',
- }
- def send_msg():
- global arr
- global trs
- global x1,x2,x3,x4
- global final,final2,final3,final4
- global msg_id
- translator = Translator()
- response = requests.post('https://beta.character.ai/chat/streaming/', headers=headers, json=json_data)
- print('Response:', response.status_code)
- f = response.text
- log = open('response.txt', 'w')
- log.write(f)
- log.close()
- for matched in re.findall(r'{\"text\": \"(.*?)}', f):
- arr.append(matched)
- str = '{"text": "' + arr[-1] + '}'
- str2 = '{"text": "' + arr[-2] + '}'
- str3 = '{"text": "' + arr[-3] + '}'
- str4 = '{"text": "' + arr[-4] + '}'
- try:
- data = json.loads(str)
- except Exception as e:
- print("Some error occured while loading json")
- try:
- data2 = json.loads(str2)
- except Exception as e:
- print("Some error occured while loading json")
- try:
- data3 = json.loads(str3)
- except Exception as e:
- print("Some error occured while loading json")
- try:
- data4 = json.loads(str4)
- except Exception as e:
- print("Some error occured while loading json")
- try:
- final = data['text']
- msg_id = data['id']
- except Exception as e:
- print("Some error occured while parsing json")
- try:
- final2 = data2['text']
- except Exception as e:
- print("Some error occured while parsing json")
- try:
- final3 = data3['text']
- except Exception as e:
- print("Some error occured while parsing json")
- try:
- final4 = data4['text']
- except Exception as e:
- print("Some error occured while parsing json")
- if (msg_id!=''):
- update_json_data["message_id"] = msg_id
- response_update = requests.post('https://beta.character.ai/chat/msg/update/primary/', headers=update_headers, json=update_json_data)
- print('Response:', response_update.text)
- print(msg_id)
- @bot.message_handler(content_types=["text"])
- def handle_text(message):
- global json_data
- global x1,x2,x3,x4
- global out
- json_data["text"] = message.text
- print('Message: ', message.text)
- send_msg()
- try:
- bot.send_message(message.chat.id,final)
- except Exception as e:
- print("Some error occured while sending message")
- bot.polling(none_stop=True, interval=0, timeout=600)
Advertisement
Add Comment
Please, Sign In to add comment