forked from AmI-2018/python-lab4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathto_do_bot_sql.py
More file actions
84 lines (65 loc) · 2.43 KB
/
to_do_bot_sql.py
File metadata and controls
84 lines (65 loc) · 2.43 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
from telegram.ext import Updater, CommandHandler, \
MessageHandler, Filters
from telegram import ChatAction
import sql_db
def insert(st):
sql_db.insert(st)
def remove(task):
sql_db.remove(task)
def start(bot,update):
update.message.reply_text("Hello!")
print("Hello!")
def nomsg(bot, update):
bot.sendChatAction(update.message.chat_id, ChatAction.TYPING)
update.message.reply_text("I'm sorry, I can't do that.")
def show(bot, update):
result = sql_db.showAll()
if not result:
update.message.reply_text("Nothing to show.")
else:
for x in result:
update.message.reply_text(x)
def rmv(bot, update, args):
bot.sendChatAction(update.message.chat_id, ChatAction.TYPING)
string = " ".join(str(x) for x in args)
if not sql_db.check(string):
update.message.reply_text(string + "not found!")
else:
sql_db.remove(string)
update.message.reply_text(string + "removed successfully!")
def rmvall(bot, update, args):
name = str(args[0])
removed = []
if sql_db.match(name) == None :
update.message.reply_text("No matches.")
else:
string = "\" and \"".join(str(x[1]) for x in sql_db.match(name))
sql_db.removeAll(name)
update.message.reply_text("The elements \"" + string + "\" successfully removed!")
def new(bot, update, args):
bot.sendChatAction(update.message.chat_id, ChatAction.TYPING)
string = " ".join(str(x) for x in args)
insert(string)
update.message.reply_text("Successfully added!")
def help(bot,update):
update.message.reply_text("To-do Manager:\n1. Insert new task with /newTask"
"\n2. Remove task with /removeTask or /removeAllTasks (matching a string)"
"\n3. Show all tasks with /showTasks")
def main():
"""
My First Bot
"""
inpt=open("TOKEN.txt","r")
updater=Updater(inpt.readline())
dp = updater.dispatcher
dp.add_handler(CommandHandler("start",start))
dp.add_handler(MessageHandler(Filters.text,nomsg))
dp.add_handler(CommandHandler("help", help))
dp.add_handler(CommandHandler("showTasks",show))
dp.add_handler(CommandHandler("newTask",new, pass_args=True))
dp.add_handler(CommandHandler("removeTask",rmv,pass_args=True))
dp.add_handler(CommandHandler("removeAllTasks",rmvall, pass_args=True))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()