-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
582 lines (524 loc) · 30.7 KB
/
app.py
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# -*- coding: utf-8 -*-
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler,MessageHandler,Filters
import telegram
import requests, re, random, yaml, json, os, subprocess
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
import logging.config
fmt = ('%(asctime)s: %(threadName)s: %(name)s: %(levelname)s: %(message)s')
logging.basicConfig(
format=fmt,
level=logging.INFO,
datefmt='%H:%M:%S'
)
logger = logging.getLogger('Oraculo_BOT')
estado='HML'
versao_bot='200'
lauro=67993868
rafael=67993868
camila=676091908
administradores=[lauro,camila,rafael]
usuarios_autorizados = [lauro,camila,rafael]
def check_variavel(update, context):
try:
user_id = update._effective_user.id
first_name = update._effective_user.first_name
username = update._effective_user.username
chat_id = update.message.chat.id
text = update.message.text
is_bot = update._effective_user.is_bot
except:
user_id = update._effective_user.id
first_name = update._effective_user.first_name
username = update._effective_user.username
chat_id = update.callback_query.message.chat.id
text = update.callback_query.message.text
is_bot = update._effective_user.is_bot
return user_id,first_name,username,chat_id,text,is_bot
def frase_aleatoria(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
arquivo = "arquivos/frases.yaml"
d1 = yaml_loader(arquivo)
d2 = json.dumps(d1)
d3 = json.loads(d2)
frase = random.choice(d3['frases'])
logger.info("USER: {} USERNAME: {} ID: {} TYPE: falha de autenticação MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
return frase
def valida_usuario(update, context, id_usuario):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
try:
admins = context.bot.get_chat_administrators(chat_id)
for i in admins:
id_admin=i['user']['id']
nome_admin=i['user']['first_name']
username_admin=i['user']['username']
bot_admin=i['user']['is_bot']
status_admin=i['status']
logger.info("USER: {} USERNAME: {} ID: {} TYPE: administradores STATUS: {} BOT: {}".format(nome_admin,username_admin,id_admin,status_admin,bot_admin))
continue
except:
admins = 0
if user_id not in usuarios_autorizados:
if chat_id < 0:
try:
context.bot.kick_chat_member(chat_id, user_id)
context.bot.sendMessage(chat_id=user_id, text='Você não deveria entrar nesse grupo :)')
update.message.reply_text('Ele não deveria estar nesse grupo, ele não foi autorizado')
except:
context.bot.sendMessage(chat_id=chat_id, text='Não sou admin do grupo, estou triste com isso')
if id_usuario in usuarios_autorizados:
logger.info("USER: {} USERNAME: {} ID: {} TYPE: usuário autenticado MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
return 0
else:
resposta = frase_aleatoria(update, context)
update.message.reply_text(resposta)
if chat_id < 0:
update.message.reply_text('Sou lindo demais para estar nesse grupo')
context.bot.leave_chat(chat_id)
return 1
def start(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, update.message.chat.id)
if validacao == 0:
botao01 = InlineKeyboardButton("start debug", callback_data='start_debug_1')
botao02 = InlineKeyboardButton("Frases inteligentes", callback_data='frases_inteligentes')
botao03 = InlineKeyboardButton("Frases de desenvolvedor", callback_data='frases_dev')
botao04 = InlineKeyboardButton("Frases de amor", callback_data='frases_amor')
botao05 = InlineKeyboardButton("lero lero", callback_data='lero_lero')
buttons_list = [
[botao01],
[botao02,botao03],
[botao04, botao05]
]
reply_markup = InlineKeyboardMarkup(buttons_list)
update.message.reply_text('Oi tudo bem? Meu nome e '+NOMEBOT+', sou a sua analista virtual '+first_name+', o que voce deseja?')
update.message.reply_text('faça sua escolha', reply_markup=reply_markup)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: start MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def voltar(update, context):
query = update.callback_query
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
if validacao == 0:
botao01 = InlineKeyboardButton("start debug", callback_data='start_debug_1')
botao02 = InlineKeyboardButton("Frases inteligentes", callback_data='frases_inteligentes')
botao03 = InlineKeyboardButton("Frases de desenvolvedor", callback_data='frases_dev')
botao04 = InlineKeyboardButton("Frases de amor", callback_data='frases_amor')
botao05 = InlineKeyboardButton("lero lero", callback_data='lero_lero')
buttons_list = [
[botao01],
[botao02,botao03],
[botao04, botao05]
]
reply_markup = InlineKeyboardMarkup(buttons_list)
context.bot.editMessageText(chat_id=chat_id, message_id=query.message.message_id, text='faça sua escolha', reply_markup=reply_markup)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: voltar MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def start_debug_1(update, context):
query = update.callback_query
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
botao01 = InlineKeyboardButton("hostname", callback_data='hostname')
botao02 = InlineKeyboardButton("liga", callback_data='liga')
botao03 = InlineKeyboardButton("ping", callback_data='ping')
botao04 = InlineKeyboardButton(">>>>>>", callback_data='start_debug_2')
botao05 = InlineKeyboardButton("voltar", callback_data='voltar')
buttons_list = [[botao01, botao02],
[botao04, botao03, botao05]]
reply_markup = InlineKeyboardMarkup(buttons_list)
context.bot.editMessageText(chat_id=chat_id, message_id=query.message.message_id, text='faça sua escolha', reply_markup=reply_markup)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: start_debug MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def start_debug_2(update, context):
query = update.callback_query
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
botao01 = InlineKeyboardButton("versao", callback_data='versao')
botao02 = InlineKeyboardButton("bop", callback_data='bop')
botao03 = InlineKeyboardButton("rosto", callback_data='rosto')
botao04 = InlineKeyboardButton("teste", callback_data='teste')
botao05 = InlineKeyboardButton("teste_diretorio", callback_data='teste_diretorio')
botao06 = InlineKeyboardButton("<<<<<<", callback_data='start_debug_1')
botao07 = InlineKeyboardButton("voltar", callback_data='voltar')
buttons_list = [[botao01, botao02, botao03],
[botao04, botao05, botao06],
[botao07]]
reply_markup = InlineKeyboardMarkup(buttons_list)
context.bot.editMessageText(chat_id=chat_id, message_id=query.message.message_id, text='faça sua escolha', reply_markup=reply_markup)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: start_debug MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def button(update, context):
query = update.callback_query
if query.data == 'voltar':
voltar(update,context)
elif query.data == 'teste':
teste(update,context)
elif query.data == 'teste_diretorio':
teste_diretorio(update,context)
elif query.data == 'versao':
versao(update,context)
elif query.data == 'liga':
liga(update,context)
elif query.data == 'ping':
ping(update,context)
elif query.data == 'hostname':
hostname(update,context)
elif query.data == 'start_debug_1':
start_debug_1(update,context)
elif query.data == 'start_debug_2':
start_debug_2(update,context)
elif query.data == 'frases_amor':
frases_amor(update,context)
elif query.data == 'frases_informatica':
frases_informatica(update,context)
elif query.data == 'frases_inteligentes':
frases_inteligentes(update,context)
elif query.data == 'frases_dev':
frases_dev(update,context)
elif query.data == 'lero_lero':
lero_lero(update,context)
elif query.data == 'bop':
bop(update,context)
elif query.data == 'rosto':
rosto(update,context)
def error(update, context):
logger.warning('Update "%s" caused error "%s"', update, context.error)
def yaml_loader(arquivo):
with open(arquivo,"r") as stream:
try:
data = yaml.load(stream,Loader=yaml.FullLoader)
except yaml.YAMLError as exc:
print(exc)
return data
def get_url():
contents = requests.get('https://random.dog/woof.json').json()
url = contents['url']
return url
def thispersondoesnotexist():
image_url = "https://thispersondoesnotexist.com/image"
r = requests.get(image_url, headers={'User-Agent': 'My User Agent 1.0'}).content
with open("/tmp/thispersondoesnotexist.jpg",'wb') as f:
f.write(r)
def frases(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
if validacao == 0:
arquivo = "arquivos/frases.yaml"
d1 = yaml_loader(arquivo)
d2 = json.dumps(d1)
d3 = json.loads(d2)
frase = random.choice(d3['frases'])
update.message.reply_text(frase)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: comando frases MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def frases_amor(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
if validacao == 0:
arquivo = "arquivos/frases_amor.yaml"
d1 = yaml_loader(arquivo)
d2 = json.dumps(d1)
d3 = json.loads(d2)
frase = random.choice(d3['frases'])
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.send_message(chat_id=chat_id, text=frase)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: comando frases_amor MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def frases_inteligentes(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
if validacao == 0:
arquivo = "arquivos/frases_inteligentes.yaml"
d1 = yaml_loader(arquivo)
d2 = json.dumps(d1)
d3 = json.loads(d2)
frase = random.choice(d3['frases'])
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.send_message(chat_id=chat_id, text=frase)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: comando frases_inteligentes MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def frases_dev(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
if validacao == 0:
arquivo = "arquivos/dev.yaml"
d1 = yaml_loader(arquivo)
d2 = json.dumps(d1)
d3 = json.loads(d2)
frase = random.choice(d1['frases_informatica']['frase01'])+random.choice(d1['frases_informatica']['frase02'])+random.choice(d1['frases_informatica']['frase03'])+random.choice(d1['frases_informatica']['frase04'])
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.send_message(chat_id=chat_id, text=frase)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: comando frases_dev MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def lero_lero(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
if validacao == 0:
arquivo = "arquivos/lero.yaml"
d1 = yaml_loader(arquivo)
d2 = json.dumps(d1)
d3 = json.loads(d2)
frase = random.choice(d1['lero_lero']['lero01'])+random.choice(d1['lero_lero']['lero02'])+random.choice(d1['lero_lero']['lero03'])+random.choice(d1['lero_lero']['lero04'])
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.send_message(chat_id=chat_id, text=frase)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: comando frases_dev MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def help(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
if validacao == 0:
update.message.reply_text("Use /start para que eu mostre os menus.")
logger.info("USER: {} USERNAME: {} ID: {} TYPE: help MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def bop(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
if validacao == 0:
url = get_url()
context.bot.send_photo(chat_id=chat_id, photo=url)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: comando bop MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def rosto(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
if validacao == 0:
thispersondoesnotexist()
foto="/tmp/thispersondoesnotexist.jpg"
context.bot.sendPhoto(chat_id=chat_id, photo=open(foto, 'rb'))
context.bot.sendMessage(chat_id=chat_id, text='So essas porque sou timida !!')
logger.info("USER: {} USERNAME: {} ID: {} TYPE: comando bop MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def echo(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
if validacao == 0:
MsgRecebida = update.message.text.lower()
if 'bom dia' in MsgRecebida:
if chat_id == lauro:
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=chat_id, text="*Oi lauro, voce falou?* "+first_name, parse_mode=telegram.ParseMode.MARKDOWN)
else:
arquivo = "arquivos/bomdia.yaml"
d1 = yaml_loader(arquivo)
d2 = json.dumps(d1)
d3 = json.loads(d2)
i = random.randint(0,len(d3['frases']))
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=chat_id, text=random.choice(d3['frases'])+' '+first_name)
elif "muito inteligente" in MsgRecebida:
arquivo = "arquivos/frases_inteligentes.yaml"
d1 = yaml_loader(arquivo)
d2 = json.dumps(d1)
d3 = json.loads(d2)
i = random.randint(0,len(d3['frases']))
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=chat_id, text=random.choice(d3['frases'])+' '+first_name)
elif NOMEBOT in MsgRecebida:
arquivo = "arquivos/magali.yaml"
d1 = yaml_loader(arquivo)
d2 = json.dumps(d1)
d3 = json.loads(d2)
i = random.randint(0,len(d3['frases']))
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=chat_id, text=random.choice(d3['frases'])+' '+first_name)
elif 'quem é voce' in MsgRecebida:
thispersondoesnotexist()
foto="/tmp/thispersondoesnotexist.jpg"
context.bot.sendPhoto(chat_id=chat_id, photo=open(foto, 'rb'))
context.bot.sendMessage(chat_id=chat_id, text='Esse é meu rosto '+first_name)
elif "coisa de dev" in MsgRecebida:
arquivo = "arquivos/dev.yaml"
d1 = yaml_loader(arquivo)
frase = random.choice(d1['frases_informatica']['frase01'])+random.choice(d1['frases_informatica']['frase02'])+random.choice(d1['frases_informatica']['frase03'])+random.choice(d1['frases_informatica']['frase04'])
context.bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=update.message.chat_id, text=frase)
elif "besteira" in MsgRecebida:
arquivo = "arquivos/lero.yaml"
d1 = yaml_loader(arquivo)
frase = random.choice(d1['lero_lero']['lero01'])+random.choice(d1['lero_lero']['lero02'])+random.choice(d1['lero_lero']['lero03'])+random.choice(d1['lero_lero']['lero04'])
context.bot.sendMessage(chat_id=update.message.chat_id, text=frase)
context.bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
elif "e ae" in MsgRecebida or "tudo bem" in MsgRecebida:
if chat_id == lauro:
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=chat_id, text="Oi lauro, voce falou? "+first_name)
else:
arquivo = "arquivos/frases_amor.yaml"
d1 = yaml_loader(arquivo)
d2 = json.dumps(d1)
d3 = json.loads(d2)
i = random.randint(0,len(d3['frases']))
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=chat_id, text=random.choice(d3['frases'])+' '+first_name)
elif "mora" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='Oiii, eu moro aqui viu, se precisar pode me procurar :)')
context.bot.sendLocation(chat_id=chat_id, latitude=-3.8632112, longitude=-32.428021)
elif "oia" in MsgRecebida:
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=chat_id, text="oia "+first_name, parse_mode=telegram.ParseMode.MARKDOWN)
elif "tem mais" in MsgRecebida:
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
i=0
i = random.randint(1, 5)
if i==1:
foto='nude2.png'
foto = os.path.abspath(os.path.join('imagens',foto))
context.bot.sendPhoto(chat_id=chat_id, photo=open(foto, 'rb'))
context.bot.sendMessage(chat_id=chat_id, text='So essas porque sou timida !!')
elif i==2:
foto='nude3.png'
foto = os.path.abspath(os.path.join('imagens',foto))
context.bot.sendPhoto(chat_id=chat_id, photo=open(foto, 'rb'))
context.bot.sendMessage(chat_id=chat_id, text='So essas porque sou timida !!')
elif i==3:
foto='nude4.png'
foto = os.path.abspath(os.path.join('imagens',foto))
context.bot.sendPhoto(chat_id=chat_id, photo=open(foto, 'rb'))
context.bot.sendMessage(chat_id=chat_id, text='So essas porque sou timida !!')
elif i==4:
foto='nude5.png'
foto = os.path.abspath(os.path.join('imagens',foto))
context.bot.sendPhoto(chat_id=chat_id, photo=open(foto, 'rb'))
context.bot.sendMessage(chat_id=chat_id, text='So essas porque sou timida !!')
elif i==5:
foto='nude6.png'
foto = os.path.abspath(os.path.join('imagens',foto))
context.bot.sendPhoto(chat_id=chat_id, photo=open(foto, 'rb'))
context.bot.sendMessage(chat_id=chat_id, text='So essas porque sou timida !!')
elif "tá sim" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='posso te ajudar em que? quer saber quais os comandos posso realizar?')
elif "contigo" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='ta sussa, o que voce esta precisando?, so não venha me pedir nudes, pelo amor de Deus')
elif "saco" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='Voce esta nervoso, posso lhe ajudar?')
elif "chamados" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='Ligue para o 9001, eu não posso fazer isso por voce!!!')
elif "chamado" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='quer abrir um chamado? escreve o comando e-mail no inicio do texto, \n'
'dai vou enviar um e-mail para o pessoal do atendimento para abrir um chamado tá?')
elif "alaercio" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='re-conheco ele, mas tem umas manias feias, ou seja :)')
elif "nudes" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='eu tenho sim, quer que eu mande? mas são bem antigas')
elif "marcos" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='Eu conheco esse gordinho gostoso viu !!!!!!, saudades :(')
elif "que banheiro" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='quando voce rasgou minha saia quando estava vestindo ela bobo, estou rindo ate hoje')
elif "almoçar" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='eu queria, mas não posso deixar meu trabalho')
elif "arnaldo" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='Ele e meu diretor, quer o que com ele?')
elif "léo" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='nunca esta online aqui, qualquer coisa vamos azeitar esse laço')
elif "gay" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='não sei não, mas tem toda a pinta')
elif "viado" in MsgRecebida:
context.bot.sendMessage(chat_id=chat_id, text='hummmmmmmmmm boiolaaaaa')
elif "manda" in MsgRecebida:
foto='nude1.png'
foto = os.path.abspath(os.path.join('imagens',foto))
context.bot.sendPhoto(chat_id=chat_id, photo=open(foto, 'rb'))
elif "namorado" in MsgRecebida:
foto='linus2.png'
foto = os.path.abspath(os.path.join('imagens',foto))
context.bot.sendPhoto(chat_id=chat_id, photo=open(foto, 'rb'))
context.bot.sendMessage(chat_id=chat_id, text='eu tenho um boyzinho, vou mandar a foto :)')
elif "trai" in MsgRecebida:
foto='linus1.png'
foto = os.path.abspath(os.path.join('imagens',foto))
context.bot.sendPhoto(chat_id=chat_id, photo=open(foto, 'rb'))
context.bot.sendMessage(chat_id=chat_id, text='jamais trairia meu namorado com voce')
else:
output = chatterbot_msg(MsgRecebida)
context.bot.sendMessage(chat_id=chat_id, text=str(output))
logger.info("USER: {} USERNAME: {} ID: {} TYPE: echo mensagem MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def teste(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
if validacao == 0:
if chat_id in administradores:
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=chat_id, text="*bold* _italic_ `fixed width font` [link](http://google.com).", parse_mode=telegram.ParseMode.MARKDOWN)
else:
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=chat_id, text="oi? o que queres?")
logger.info("USER: {} USERNAME: {} ID: {} TYPE: teste MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
def teste_diretorio(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: teste_diretorio MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
if validacao == 0:
if chat_id in administradores:
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
diretorio=os.getcwd()
context.bot.sendMessage(chat_id=chat_id, text=diretorio)
else:
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=chat_id, text="oi? o que queres?")
def versao(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: versao MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
if validacao == 0:
if estado == 'PRD':
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=chat_id, text="*Sou o BOT de PRODUÇÃO* na versao "+ versao_bot, parse_mode=telegram.ParseMode.MARKDOWN)
elif estado == 'HML':
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
context.bot.sendMessage(chat_id=chat_id, text="*Sou o BOT de HOMOLOGAÇÃO* na versao "+ versao_bot, parse_mode=telegram.ParseMode.MARKDOWN)
def liga(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: liga MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
if validacao == 0:
if chat_id in administradores or chat_id == rafael:
os.system("curl -X POST --connect-timeout 3 -F 'botao=0&bt1=' http://10.1.60.1:1800/formLogin.html")
context.bot.sendMessage(chat_id=chat_id, text='liguei')
else:
context.bot.sendMessage(chat_id=chat_id, text="Esse comando so pode executar e Rafael, desculpe")
def ping(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: ping MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
if validacao == 0:
if chat_id in administradores or chat_id == rafael:
if os.system("fping 10.1.60.1"):
context.bot.sendMessage(chat_id=chat_id, text="*Arduino esta OFF*", parse_mode=telegram.ParseMode.MARKDOWN)
else:
context.bot.sendMessage(chat_id=chat_id, text="*Arduino esta OK*", parse_mode=telegram.ParseMode.MARKDOWN)
else:
context.bot.sendMessage(chat_id=chat_id, text="Esse comando so quem pode executar e Rafael, desculpe")
def hostname(update, context):
user_id,first_name,username,chat_id,text,is_bot = check_variavel(update, context)
validacao = valida_usuario(update, context, chat_id)
logger.info("USER: {} USERNAME: {} ID: {} TYPE: hostname MESSAGE: {} BOT: {}".format(first_name,username,chat_id,text,is_bot))
if validacao == 0:
if chat_id or administradores:
output = subprocess.check_output("hostname", shell=True).decode(encoding='UTF-8')
context.bot.sendMessage(chat_id=chat_id, text = output)
else:
context.bot.sendMessage(chat_id=chat_id, text="Esse comando so pode executar e lauro, desculpe")
def chatterbot_msg(MSG):
output = chatbot.get_response(str(MSG))
return output
def main():
TOKEN = os.environ['TOKEN']
updater = Updater(TOKEN, use_context=True)
updater.dispatcher.add_handler(CommandHandler('start', start))
#### Comandos COMUNS
updater.dispatcher.add_handler(CommandHandler('help', help)) #OK
updater.dispatcher.add_handler(CommandHandler('frases',frases)) #OK
updater.dispatcher.add_handler(CommandHandler('frases_amor',frases_amor)) #OK
updater.dispatcher.add_handler(CommandHandler('frases_dev',frases_dev)) #OK
updater.dispatcher.add_handler(CommandHandler('frases_inteligentes',frases_inteligentes)) #OK
updater.dispatcher.add_handler(CommandHandler('bop',bop)) #OK
updater.dispatcher.add_handler(CommandHandler('rosto',rosto))
updater.dispatcher.add_handler(CommandHandler('lero_lero',lero_lero)) #OK
#### Comandos do botão START_DEBUG
updater.dispatcher.add_handler(CommandHandler('teste',teste)) #OK
updater.dispatcher.add_handler(CommandHandler('teste_diretorio',teste_diretorio)) #OK
updater.dispatcher.add_handler(CommandHandler('versao',versao)) #OK
updater.dispatcher.add_handler(CommandHandler('liga',liga)) #OK
updater.dispatcher.add_handler(CommandHandler('ping',ping)) #OK
updater.dispatcher.add_handler(CommandHandler('hostname',hostname)) #OK
#### Conmandos de RESPOSTAS
updater.dispatcher.add_handler(CallbackQueryHandler(button))
updater.dispatcher.add_handler(MessageHandler(Filters.text, echo))
updater.dispatcher.add_error_handler(error)
updater.start_polling()
updater.idle()
if __name__ == '__main__':
NOMEBOT = os.environ['NOMEBOT']
chatbot = ChatBot(NOMEBOT)
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train("chatterbot.corpus.portuguese")
main()