-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
76 lines (67 loc) · 4.17 KB
/
bot.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
from time import sleep
import telebot
import logging
import config
import utils
from SQLighter import SQLighter
logging.basicConfig(format = u'%(levelname)-8s [%(asctime)s] %(message)s',
level = logging.DEBUG, filename = config.botlog_name)
logging.info(u'PomniBot started')
bot = telebot.TeleBot(config.token)
# Обработка команды старт
@bot.message_handler(commands=['start'])
def start(message):
try:
db_worker = SQLighter(config.database_name)
if db_worker.select_single(message.chat.id):
markup = utils.generate_markup(['Забудь про меня'])
bot.send_message(message.chat.id, 'Не волнуйся, я тебя не забыл. Ты у меня уже на заметке, '
'напоминаю каждый день про отчет:)', reply_markup=markup)
else:
markup = utils.generate_markup(['Да. То, что нужно!'])
bot.send_message(message.chat.id, 'Привет! Я бот, который поможет тебе не забыть писать ежедневный отчет! '
'Напоминать тебе об этом?', reply_markup=markup)
except Exception as e:
logging.error(e)
@bot.message_handler(func=lambda message: True, content_types=['text'])
def message_handle(message):
try:
db_worker = SQLighter(config.database_name)
#убрать после того, как имена всех существующих обновятся
x = db_worker.select_single(message.chat.id)
if x:
username = '"' + message.chat.username.encode('utf-8') + '"' if message.chat.username else 'null'
if username:
db_worker.upd_col('chat_username', username, message.chat.id)
first_name = '"' + message.chat.first_name.encode('utf-8') + '"' if message.chat.first_name else 'null'
if first_name:
db_worker.upd_col('chat_first_name', first_name, message.chat.id)
#---------------------------------------------------------
if message.text == u'Да. То, что нужно!':
username = '"' + message.chat.username.encode('utf-8') + '"' if message.chat.username else 'null'
first_name = '"' + message.chat.first_name.encode('utf-8') + '"' if message.chat.first_name else 'null'
db_worker.add_row(message.chat.id, username, first_name)
bot.send_message(message.chat.id, 'Больше тебе приседать не придется:) Я буду ежедневно напоминать тебе '
'об отчете каждый час, начиная с 20:00. '
'До связи!', reply_markup=utils.hide_markup())
elif message.text == u'+':
db_worker.upd_col('done', 1, message.chat.id)
bot.send_message(message.chat.id, 'Отлично! встретимся завтра:)')
elif message.text == u'Спроси в другой раз':
bot.send_message(message.chat.id, 'Окей, напомню через час.')
elif message.text == u'Забудь про меня':
db_worker.delete_row(message.chat.id)
bot.send_message(message.chat.id, 'Хорошо, больше не буду тебе надоедать. '
'Если передумаешь подай команду /start')
elif message.text == u'Беру на себя всю ответственность':
bot.send_message(message.chat.id, 'Смотри, так до приседаний недалеко))')
else:
bot.send_message(message.chat.id, 'Извини, такой команды я не знаю. '
'Я пока примитивный глуповатый бот:( Но я учусь')
except Exception as e:
logging.error(e)
if __name__ == '__main__':
bot.polling(none_stop=True)