-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
223 lines (176 loc) · 8.04 KB
/
Copy pathbot.py
File metadata and controls
223 lines (176 loc) · 8.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
from email.policy import default
from types import NoneType
from telegram.ext import ApplicationBuilder, MessageHandler, filters, CallbackQueryHandler, CommandHandler
from gpt import *
from util import *
async def start(update, context):
dialog.mode = 'main'
text = load_message('main')
await send_photo(update, context, 'main')
await send_text(update, context, text)
await show_main_menu(update, context, {
'start': 'главное меню бота',
'profile': 'генерация Tinder-профля 😎',
'opener': 'сообщение для знакомства 🥰',
'message': 'переписка от вашего имени 😈',
'date': 'переписка со звездами 🔥',
'gpt': 'задать вопрос чату GPT 🧠'
})
async def gpt(update, context):
dialog.mode = 'gpt'
text = load_message('gpt')
await send_photo(update, context, 'gpt')
await send_text(update, context, text)
async def date(update, context):
dialog.mode = 'date'
text = load_message('date')
await send_photo(update, context, 'date')
await send_text_buttons(update, context, text, {
'date_grande': 'Ариана Гранде',
'date_robbie': 'Марго Робби',
'date_zendaya': 'Зендея',
'date_gosling': 'Райан Гослинг',
'date_hardy': 'Том Харди'
})
async def date_dialog(update, context):
text = update.message.text
my_message = await send_text(update, context, "Девушка набирает текст...")
answer = await chatgpt.add_message(text)
await my_message.edit_text(answer)
async def date_button(update, context):
query = update.callback_query.data
await update.callback_query.answer()
await send_photo(update, context, query)
await send_text(update, context, 'Отличный выбор! Пригласите девушку (парня) на свидание за 5 сообщений')
prompt = load_prompt(query)
chatgpt.set_prompt(prompt)
async def message(update, context):
dialog.mode = 'message'
text = load_message('message')
await send_photo(update, context, 'message')
await send_text_buttons(update, context, text, {
'message_next': 'Следующее сообщение',
'message_date': 'Пригласить на свидание'
})
dialog.list.clear()
async def message_button(update, context):
query = update.callback_query.data
await update.callback_query.answer()
prompt = load_prompt(query)
user_chat_history = '\n\n'.join(dialog.list)
my_message = await send_text(update, context, 'ChatGPT 🧠 думает над вариантами ответа...')
answer = await chatgpt.send_question(prompt, user_chat_history)
await my_message.edit_text(answer)
async def message_dialog(update, context):
text = update.message.text
dialog.list.append(text)
async def gpt_dialog(update, context):
text = update.message.text
prompt = load_prompt('gpt')
answer = await chatgpt.send_question(prompt, text)
await send_text(update, context, answer)
async def profile(update, context):
dialog.mode = "profile"
text = load_message('profile')
await send_photo(update, context, 'profile')
await send_text(update, context, text)
dialog.user.clear()
dialog.count = 0
await send_text(update, context, 'Сколько вам лет?')
async def profile_dialog(update, context):
text = update.message.text
dialog.count += 1
if dialog.count == 1:
dialog.user['age'] = text
await send_text(update, context, 'Кем вы работаете?')
elif dialog.count == 2:
dialog.user['occupation'] = text
await send_text(update, context, 'У вас есть хобби?')
elif dialog.count == 3:
dialog.user['hobby'] = text
await send_text(update, context, 'Что вам НЕ нравится в людях?')
elif dialog.count == 4:
dialog.user['annoys'] = text
await send_text(update, context, 'Цель знакомства?')
elif dialog.count == 5:
dialog.user['goals'] = text
prompt = load_prompt('profile')
user_info = dialog_user_info_to_str(dialog.user)
my_message = await send_text(update, context,
'ChatGPT 🧠 занимается генерацией вашего профиля. Подождите пару секунд...')
answer = await chatgpt.send_question(prompt, user_info)
await my_message.edit_text(answer)
async def opener(update, context):
dialog.mode = 'opener'
text = load_message('opener')
await send_photo(update, context, 'opener')
await send_text(update, context, text)
dialog.user.clear()
dialog.count = 0
await send_text(update, context, 'Имя девушки?')
async def opener_dialog(update, context):
text = update.message.text
dialog.count += 1
if dialog.count == 1:
dialog.user['name'] = text
await send_text(update, context, 'Сколько ей лет?')
elif dialog.count == 2:
dialog.user['age'] = text
await send_text(update, context, 'Оцените ее внешность: 1-10 баллов?')
elif dialog.count == 3:
dialog.user['handsome'] = text
await send_text(update, context, 'Кем она работает?')
elif dialog.count == 4:
dialog.user['occupation'] = text
await send_text(update, context, 'Цель знакомства?')
elif dialog.count == 5:
dialog.user['goals'] = text
prompt = load_prompt('opener')
user_info = dialog_user_info_to_str(dialog.user)
answer = await chatgpt.send_question(prompt, user_info)
await send_text(update, context, answer)
# тут будем писать наш код :)
async def hello(update, context):
if dialog.mode == 'gpt':
await gpt_dialog(update, context)
elif dialog.mode == 'date':
await date_dialog(update, context)
elif dialog.mode == 'message':
await message_dialog(update, context)
elif dialog.mode == 'profile':
await profile_dialog(update, context)
elif dialog.mode == 'opener':
await opener_dialog(update, context)
else:
await send_text(update, context, '*Привет*')
await send_text(update, context, '_Как дела?_')
await send_text(update, context, 'Вы написали ' + update.message.text)
await send_photo(update, context, 'avatar_main')
await send_text_buttons(update, context, 'Запустить процесс?', {
'start': 'Запустить',
'stop': 'Остановить'
})
async def hello_button(update, context):
query = update.callback_query.data
if query == 'start':
await send_text(update, context, 'Процесс запущен')
else:
await send_text(update, context, 'Процесс остановлен')
dialog = Dialog()
dialog.mode = None
dialog.list = []
dialog.count = 0
dialog.user = {}
chatgpt = ChatGptService(token='gpt:6iWpGTIVtrvZB0KTFlGqJFkblB3Tjikl0aobFUM6zUmVCkXU')
app = ApplicationBuilder().token("7676179726:AAEzXm-UJFumBkOJT1HYLX5q9W2QOiLzYsc").build()
app.add_handler(CommandHandler('start', start))
app.add_handler(CommandHandler('gpt', gpt))
app.add_handler(CommandHandler('date', date))
app.add_handler(CommandHandler('message', message))
app.add_handler(CommandHandler('profile', profile))
app.add_handler(CommandHandler('opener', opener))
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, hello))
app.add_handler(CallbackQueryHandler(date_button, pattern='^date_.*'))
app.add_handler(CallbackQueryHandler(message_button, pattern='^message_.*'))
app.add_handler(CallbackQueryHandler(hello_button))
app.run_polling()