-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtaskbot.py
142 lines (102 loc) · 3.52 KB
/
taskbot.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
from handle_updates import *
from git import *
HELP = """
/help
/new name1,name2,name3...
/todo ID ID...
/doing ID ID...
/done ID ID...
/delete ID ID...
/list
/rename ID NOME
/dependson ID ID...
/duplicate ID ID...
/priority ID PRIORITY{low, medium, high}
/duedate ID DUEDATE{DD/MM/YYYY}
/setdescription ID DESCRIPTION
/taskdetail ID ID...
/authorizegit
/code XXXXXXXXXXX
/listrepositories
/createissue NAME_OF_REPOSITORIE ID
"""
def handle_updates(updates):
for update in updates["result"]:
if 'message' in update:
message = update['message']
elif 'edited_message' in update:
message = update['edited_message']
else:
print('Can\'t process! {}'.format(update))
return
msg = ''
if 'text' in message:
command = message["text"].split(" ", 1)[0]
if len(message["text"].split(" ", 1)) > 1:
msg = message["text"].split(" ", 1)[1].strip()
else:
command = '/start'
chat = message["chat"]["id"]
start_chat(chat)
print(command, msg, chat)
if command == '/new':
new_task(chat, msg)
elif command == '/rename':
rename_task(chat, msg)
elif command == '/duplicate':
duplicate_task(chat, msg)
elif command == '/delete':
delete_task(chat, msg)
elif command == '/todo':
to_do_task(chat, msg)
elif command == '/doing':
doing_task(chat, msg)
elif command == '/done':
done_task(chat, msg)
elif command == '/list':
list_tasks(chat, msg)
elif command == '/dependson':
task_dependencies(chat, msg)
elif command == '/priority':
task_priority(chat, msg)
elif command == '/duedate':
set_due_date(chat, msg)
elif command == '/setdescription':
set_description(chat, msg)
elif command == '/taskdetail':
task_detail(chat, msg)
elif command == '/start':
start_chat(chat)
send_message("Welcome! Here is a list of things you can do.", chat)
send_message(HELP, chat)
elif command == '/help':
send_message("Here is a list of things you can do.", chat)
send_message(HELP, chat)
elif command == '/createissue':
GitApiHandlher.create_issue(msg, chat)
elif command == '/authorizegit':
GitApiHandlher.authorize_git(chat)
elif command == '/code':
GitApiHandlher.get_token_accsses(msg, chat)
elif command == '/listrepositories':
query = db.session.query(User).filter_by(chat_id=chat)
user = query.one()
if user.github_access_token is None:
send_message("You have to auhtorize the application first, please use the command: '/authorize_git' and follow the instructions.", chat)
else:
GitApiHandlher.list_repositories(user.github_access_token, chat)
else:
send_message("I'm sorry dave. I'm afraid I can't do that.", chat)
def main():
last_update_id = None
# Search for update every half second.
while True:
print("Updates")
updates = get_updates(last_update_id)
if len(updates["result"]) > 0:
last_update_id = get_last_update_id(updates) + 1
handle_updates(updates)
time.sleep(0.5)
if __name__ == '__main__':
main()