-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremind.py
More file actions
207 lines (159 loc) · 5.23 KB
/
remind.py
File metadata and controls
207 lines (159 loc) · 5.23 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
icon = 'https://img.icons8.com/emoji/96/000000/penguin--v2.png'
import db
import datetime
conn = db.db()
import blocks
remindersblock = blocks.reminder
reminders = {}
def sendreminder(slack_client):
"""
Comparing the remainders with current time and sending remainders to the \
users
"""
x = datetime.datetime.now()
currenttime = x.strftime("%H") +":"+x.strftime("%M")
for time in reminders:
if currenttime == time[1]:
remindersblock(slack_client, time[0])
def setreminder(user, timetoset):
"""
Inserting remainders to the remainders table
"""
global reminders
try:
cursor = conn.cursor()
query = """select * from reminders where slack_id = %s"""
cursor.execute(query,(user, ))
count = cursor.rowcount
#print(record)
if count >=2:
return "You can set a maximum of 2 reminders per day. Contact us \
if you need any help"
#return record
query = """ INSERT INTO reminders ( slack_id ,
timetoset,
ts) VALUES (%s, %s, %s)"""
insert = (user, timetoset, datetime.datetime.now())
cursor.execute(query, insert)
conn.commit()
getreminders()
return "Success"
except:
return "an error occured"
def getreminders():
"""
Getting the remainders list and storing them in the global variable\
'remainders'
"""
global reminders
cursor = conn.cursor()
try:
query = """select slack_id, timetoset from reminders"""
cursor.execute(query)
record = cursor.fetchall()
conn.commit()
reminders = record
return record
except:
return ""
reminders = getreminders()
def deletereminder(_id):
"""
deleting the remainders set by the user with block actions
"""
cursor = conn.cursor()
_id = int(_id)
query = """select * from reminders where id = %s"""
cursor.execute(query,(_id, ))
count = cursor.rowcount
if count<1:
return "Refresh the command"
try:
query = """DELETE FROM reminders WHERE id = %s"""
cursor.execute(query,(_id,))
count = cursor.rowcount
conn.commit()
except:
return "Failed to insert"
getreminders()
return "Successfully deleted"
def unset(user):
"""
getting the remainders from the the remainders table, when a user \
invokes `unset` command
"""
cursor = conn.cursor()
try:
query = """select timetoset,id from reminders where slack_id = %s"""
cursor.execute(query, (user,))
record = cursor.fetchall()
count = cursor.rowcount
conn.commit()
except:
return ""
if count <1:
return ""
return record
def reminder(n,client):
"""
Sending remainders to the users at the default time given in custom.py \
everyday by retreiving the users list after calling users.test api call
"""
userslist = client.api_call("users.list")
for s in userslist['members']:
if s['is_bot']!= True:
user = s['id']
remindersblock(client, user)
client.api_call(
"chat.postMessage",
as_user=True,
channel=s['id'],
icon_url=icon,
text=f"Hey <@{user}>!, :wave: Fill in what you've done today",
attachments=[{
"text": "",
"callback_id": "workform",
"color": "#3AA3E3",
"attachment_type": "default",
"actions": [{
"name": "workform",
"text": "Submit Today\'s work",
"type": "button",
"value": "Work_data"
}]
}]
)
client.api_call(
"chat.postMessage",
as_user=True,
channel=s['id'],
icon_url=icon,
text="Glad, I\'m here to help in submitting your work data",
blocks= [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Other quick actions"
},
"accessory": {
"type": "static_select",
"placeholder": {
"type": "plain_text",
"emoji": True,
"text": "Manage"
},
"options": [
{
"text": {
"type": "plain_text",
"emoji": True,
"text": "Request for a day-off"
},
"value": "dayoff"
}
]
}
}
]
)