Skip to content

Commit 979789d

Browse files
committed
wip
1 parent c9d2888 commit 979789d

3 files changed

Lines changed: 133 additions & 0 deletions

File tree

bot_logic.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,124 @@ def sugerireci(update, context):
149149
def sugerirotro(update, context):
150150
suggest_listable(update, context, Otro)
151151

152+
def campusvivo(update, context):
153+
msg = update.message.reply_text("Bancá que me fijo...", quote=False)
154+
155+
campus_response_text = is_campus_up()
156+
157+
context.bot.editMessageText(chat_id=msg.chat_id,
158+
message_id=msg.message_id,
159+
text=msg.text + "\n" + campus_response_text)
160+
161+
context.sent_messages.append(msg)
162+
163+
def flan(update, context):
164+
responder_imagen(update, context, 'files/Plandeestudios.png')
165+
166+
def flanviejo(update, context):
167+
responder_imagen(update, context, 'files/Plandeestudios-93.png')
168+
169+
def aulas(update, context):
170+
responder_documento(update, context, 'files/0I-aulas.pdf')
171+
172+
def checodepers(update, context):
173+
if not context.args:
174+
ejemplo = """ Ejemplo de uso:
175+
/checodepers Hola, tengo un mensaje mucho muy importante que me gustaria que respondan
176+
"""
177+
msg = update.message.reply_text(ejemplo, quote=False)
178+
context.sent_messages.append(msg)
179+
return
180+
user = update.message.from_user
181+
try:
182+
if not user.username:
183+
raise Exception("not userneim")
184+
message = " ".join(context.args)
185+
context.bot.sendMessage(
186+
chat_id=CODEPERS_CHATID, text=f"{user.first_name}(@{user.username}) : {message}")
187+
except Exception:
188+
try:
189+
context.bot.forward_message(
190+
CODEPERS_CHATID, update.message.chat_id, update.message.message_id)
191+
logger.info(f"Malio sal {str(user)}")
192+
except Exception as e:
193+
update.message.reply_text(
194+
"La verdad me re rompí, avisale a roz asi ve que onda", quote=False)
195+
logger.error(e)
196+
return
197+
msg = update.message.reply_text(
198+
"OK, se lo mando a les codepers.", quote=False)
199+
context.sent_messages.append(msg)
200+
201+
202+
def checodeppers(update, context):
203+
checodepers(update, context)
204+
205+
def cuandovence(update, context):
206+
ejemplo = "\nCuatris: 1c, 2c, i, inv, invierno, v, ver, verano.\nEjemplo: /cuandovence verano2010"
207+
if not context.args:
208+
ayuda = "Pasame cuatri y año en que aprobaste los TPs." + ejemplo
209+
msg = update.message.reply_text(ayuda, quote=False)
210+
context.sent_messages.append(msg)
211+
return
212+
try:
213+
linea_entrada = "".join(context.args).lower()
214+
cuatri, anio = parse_cuatri_y_anio(linea_entrada)
215+
except Exception:
216+
msg = update.message.reply_text(
217+
"¿Me pasás las cosas bien? Es cuatri+año." + ejemplo, quote=False)
218+
context.sent_messages.append(msg)
219+
return
220+
221+
vencimiento = calcular_vencimiento(cuatri, anio)
222+
msg = update.message.reply_text(
223+
vencimiento, quote=False, parse_mode=ParseMode.MARKDOWN,disable_web_page_preview=True)
224+
context.sent_messages.append(msg)
225+
226+
227+
def colaborar(update, context):
228+
msg = update.message.reply_text(
229+
"Se puede colaborar con el DCUBA bot en https://github.com/comcomUBA/dcubabot", quote=False)
230+
context.sent_messages.append(msg)
231+
232+
# Manda una imagen a partir de su path al chat del update dado
233+
def mandar_imagen(chat_id, context, file_path):
234+
context.bot.sendChatAction(chat_id=chat_id, action=ChatAction.UPLOAD_PHOTO)
235+
with db_session:
236+
file = File.get(path=file_path)
237+
if file:
238+
msg = context.bot.send_photo(
239+
chat_id=chat_id, photo=file.file_id, allow_sending_without_reply=True)
240+
else:
241+
msg = context.bot.send_photo(
242+
chat_id=chat_id, photo=open(file_path, 'rb'), allow_sending_without_reply=True)
243+
with db_session:
244+
File(path=file_path, file_id=msg.photo[0].file_id)
245+
246+
# Manda un documento a partir de su path al chat del update dado
247+
def mandar_pdf(chat_id, context, file_path):
248+
context.bot.sendChatAction(
249+
chat_id=chat_id, action=ChatAction.UPLOAD_DOCUMENT)
250+
with db_session:
251+
file = File.get(path=file_path)
252+
if file:
253+
msg = context.bot.send_document(
254+
chat_id=chat_id, document=file.file_id, allow_sending_without_reply=True)
255+
else:
256+
msg = context.bot.send_document(
257+
chat_id=chat_id, document=open(file_path, 'rb'), allow_sending_without_reply=True)
258+
with db_session:
259+
File(path=file_path, file_id=msg.document[0].file_id)
260+
261+
262+
# Responde una imagen a partir de su path al chat del update dado
263+
def responder_imagen(update, context, file_path):
264+
mandar_imagen(update.message.chat_id, context, file_path)
265+
266+
# Responde un documento a partir de su path al chat del update dado
267+
def responder_documento(update, context, file_path):
268+
mandar_pdf(update.message.chat_id, context, file_path)
269+
152270

153271
COMMANDS = {
154272
'start': start,
@@ -163,6 +281,16 @@ def sugerirotro(update, context):
163281
'sugeriroptativa': sugeriroptativa,
164282
'sugerireci': sugerireci,
165283
'sugerirotro': sugerirotro,
284+
'campusvivo': campusvivo,
285+
'noitip': noitip,
286+
'asm': asm,
287+
'flan': flan,
288+
'flanviejo': flanviejo,
289+
'aulas': aulas,
290+
'checodepers': checodepers,
291+
'checodeppers': checodeppers,
292+
'cuandovence': cuandovence,
293+
'colaborar': colaborar,
166294
}
167295

168296
def handle_command(update, bot):

dcubabot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# Local imports
1818
# from tokenz import *
1919
from handlers.update_groups import update_groups, actualizar_grupos
20+
from handlers.new_commands import ping
2021
from models import *
2122
from deletablecommandhandler import DeletableCommandHandler
2223
import labos
@@ -410,6 +411,7 @@ def add_all_handlers(dispatcher):
410411
if command.description:
411412
descriptions.append((command.name, command.description))
412413
dispatcher.add_handler(CallbackQueryHandler(button))
414+
dispatcher.add_handler(CommandHandler("ping", ping))
413415
print(descriptions)
414416
dispatcher.bot.set_my_commands(descriptions)
415417

handlers/new_commands.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
def ping(update, context):
3+
update.message.reply_text("pong")

0 commit comments

Comments
 (0)