-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegramAPI_handler.py
More file actions
70 lines (42 loc) · 1.77 KB
/
telegramAPI_handler.py
File metadata and controls
70 lines (42 loc) · 1.77 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
#Aca van las funciones que se ejecutan cuando llega un comando del chat. La idea es que en telegramBot solo esten las funciones de la API y que llame a las funciones de aca. Esto deberia modulizar todo.
#imports
import memeHandler as juan
import utils as u
# Class that keeps track of the last image sent
class LastSent:
def __init__(self,fileId: str):
lastSent = fileId
ultima_foto = LastSent('')
def send_meme(texto_crudo): #manda el meme que pidio el usuario
parametro=' '.join(texto_crudo)
if parametro.isdigit():
photoToSend,tags = juan.sendMemeIndex(int(parametro))
else:
parametro = parametro.split()
photoToSend, tags = juan.sendRandomMeme(parametro)
ultima_foto.lastSent = photoToSend
return photoToSend, u.pasarACaption(tags)
def photo_sent_in_chat(photoid):
#actualizo ultima foto
ultima_foto.lastSent = photoid
#esto lo podria cambiar cuando quiero que guarde todas las fotos que envie, para armar la datbase por ejemplo
if False:
addMeme(u.ultima_foto.lastSent, tags = [])
print('foto guaradada, file id' + str(photoid[-10:-1]))
def save_image(texto_crudo):
if ultima_foto.lastSent == '':
mensaje = "no hay foto que guardar"
else:
hashtags=' '.join(texto_crudo) #el texto en crudo
hashtags = hashtags.split()
juan.addMeme(ultima_foto.lastSent, tags = hashtags)
mensaje = "Guardada con tags " + str(hashtags)
return mensaje
def add_hashtag(texto_crudo):
hashtags = ' '.join(texto_crudo) #el texto en crudo
hashtags = hashtags.split()
print(hashtags)
#foto a agregarle los tags:
foto = ultima_foto.lastSent
juan.agregarTags(foto,hashtags)
return 'Tags agregadas'