-
Notifications
You must be signed in to change notification settings - Fork 2
/
tasks.py
55 lines (40 loc) · 2.33 KB
/
tasks.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
import discord
taskFooter = "Please keep in mind that tasks are assigned on a first come, first served basis."
async def sendTaskEmbed(message, client, taskDetails, server):
"""Uses the message object and task details to anounce a task"""
#Sends the task message and assigns its id to sentTaskMsg
taskDesc = f"Number of people required: **{taskDetails['taskUsers']}**\nNumber of hours: **{taskDetails['taskHours']}**"
taskEmbed = discord.Embed(title=f"New Task! {taskDetails['taskName']}",description= taskDesc, color=0x67d129)
taskEmbed.set_thumbnail(url=server.logo)
taskEmbed.set_footer(text=taskFooter)
sentTaskMsg = await client.get_channel(server.taskschannel).send(content=f'@{server.taskMention}', embed=taskEmbed)
await sentTaskMsg.add_reaction(server.reactEmoji)
return sentTaskMsg
async def collectResponses(TaskMsg, client, taskDetails, server):
#Adds userid of each reaction to userList until length of userList rea
def check(reaction, user):
"""Returns true if a user other than the bot reacts with the correct emoji to the task message"""
return user!=client.user and reaction.message==TaskMsg and str(reaction.emoji) == server.reactEmoji
userList = []
resUsers = taskDetails['taskUsers'] + server.bufferUsers
while len(userList)<resUsers:
reaction, user = await client.wait_for('reaction_add', check=check)
userId = user.id
userList.append(userId)
return userList
async def closeTask(TaskMsg, taskDetails, server):
await TaskMsg.clear_reactions()
closedTaskName = "Task Closed"
closedTaskDesc = taskDetails['taskName'] + f"\nNumber of people required: {taskDetails['taskUsers']}\nNumber of hours: {taskDetails['taskHours']}"
closedTaskEmbed = discord.Embed(title=closedTaskName,description=closedTaskDesc)
closedTaskEmbed.set_thumbnail(url=server.logo)
closedTaskEmbed.set_footer(text=taskFooter)
await TaskMsg.edit(embed=closedTaskEmbed)
async def sendReport(client, taskDetails, userList, server):
reportDesc = ""
reportFooter = "Responses are sorted according to time."
for i in range(len(userList)):
reportDesc+=(f'{str(i+1)}. <@{userList[i]}>\n')
report = discord.Embed(title=f"Report for \"{taskDetails['taskName']}\"", description=reportDesc)
report.set_footer(text=reportFooter, icon_url=server.logo)
await client.get_channel(server.reportschannel).send(embed=report)