-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
102 lines (87 loc) · 2.93 KB
/
utils.py
File metadata and controls
102 lines (87 loc) · 2.93 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
#! /usr/bin/env python
# -*- coding:utf-8 -*-
# Standard lib Imports
import time
import sys
from datetime import datetime
import random
import re
# Third-Party Imports
import telebot
from sqlalchemy.engine import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from logger import logger
try:
TOKEN = str(sys.argv[1])
bot = telebot.TeleBot(TOKEN)
except:
print('Debe ingresar el token.')
DB_STRING = 'postgresql://bitsonbot:bitson@localhost:5432/bitsonbot'
# DB CONFIGURATION
logger.debug("Starting DB Connection")
engine = create_engine(DB_STRING)
Base = declarative_base(bind=engine)
Session = sessionmaker(bind=engine)
session = Session()
def get_content(text):
command = re.findall(r'/{1}\w+[@bitsonBot]*\s+(.*)', text.text,
re.DOTALL)
if command:
whole = ""
for line in command:
if line == "":
whole += "\n"
else:
whole += line
return whole
else:
pass
def in_time(message):
""" this function check if the message it's too old... """
time_range = time.mktime(datetime.now().timetuple())
if int(time_range - message.date) < 10:
if not message.forward_from:
return True
else:
return False
def verify_alarms():
from models.alarms import Alarm
while True:
now = datetime.now().strftime('%H:%M')
alarms = session.query(Alarm).filter(Alarm.enable==True,
Alarm.hour==now).all()
try:
for alarm in alarms:
bot.send_message(chat_id=alarm.chat_id,
text=alarm.message)
if not alarm.repeat:
alarm.enable = False
except Exception as ex:
logger.error(ex)
finally:
session.commit()
while now == datetime.now().strftime('%H:%M'):
pass
text_messages = {
'help': 'Estas son todas las cosas que puedo hacer...\n'
'> /help\n'
'> /flip <cara/seca>\n'
'> /set_alarm HH:MM, message, <repeat/norepeat>\n'
'> /rem_alarm HH:MM\n'
'> /show_alarms \n'
'Un monton, no?\n'
'Ingresá /<comando> "-?" para mas información',
'help_group':
u"`Mejor no spammear en {title}... Te envío un MP con la ayuda`",
'help_group_first':
u"Primero enviame /start por privado a @bitsonbot asi puedo "
u"empezar a hablarte",
'first_welcome': "Bienvenido al bot de Bitson.\n"
"Puede solicitar ayuda ingresando /help... o llamando al 911 "
"(dependiendo de que tipo de ayuda necesite)",
'welcome_again': "Bueno... con un /start estamos bien.\n"
"Puede solicitar ayuda ingresando /help... ",
'set_alarm': "Alarma configurada.",
'rem_alarm': "Alarma desactivada.",
}