1
|
|
|
import discord |
2
|
|
|
|
3
|
|
|
from app.classes.abc.message_manager import MessageManager |
4
|
|
|
from app.exceptions import EmployeeFound, EmployeeNotFound |
5
|
|
|
from app.utils import get_int, get_last_half_hour |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class WorkList(MessageManager): |
9
|
|
|
|
10
|
|
|
def __init__(self, message): |
11
|
|
|
self.work_list_message = message |
12
|
|
|
|
13
|
|
|
fields = message.embeds[0].fields |
14
|
|
|
|
15
|
|
|
self.paye_amount = 1200 |
16
|
|
|
|
17
|
|
|
self.work_list = parse_from_message( |
18
|
|
|
fields[0].value, 'Aucun employés actifs', ' || ' |
19
|
|
|
) |
20
|
|
|
|
21
|
|
|
self.payees = parse_from_message( |
22
|
|
|
fields[1].value, 'Pas de salaires enregistré', '$' |
23
|
|
|
) |
24
|
|
|
|
25
|
|
|
async def update(self): |
26
|
|
|
drink_list_embed = discord.Embed( |
27
|
|
|
title="Travail", |
28
|
|
|
description=get_embed_description() |
29
|
|
|
).add_field( |
30
|
|
|
name="Actifs", |
31
|
|
|
value='\n'.join( |
32
|
|
|
f'- <@{employee_name}> || {start_time} ||' |
33
|
|
|
for employee_name, start_time in self.work_list.items() |
34
|
|
|
) or 'Aucun employés actifs' |
35
|
|
|
).add_field( |
36
|
|
|
name="Payes", |
37
|
|
|
value='\n'.join( |
38
|
|
|
f'- <@{employee_name}> `${payee:,}`' |
39
|
|
|
for employee_name, payee in self.payees.items() |
40
|
|
|
) or 'Pas de salaires enregistré', |
41
|
|
|
inline=False |
42
|
|
|
).add_field( |
43
|
|
|
name='Tarif (30min)', |
44
|
|
|
value=f'> `${self.paye_amount:,}`' |
45
|
|
|
) |
46
|
|
|
|
47
|
|
|
await self.work_list_message.edit( |
48
|
|
|
content='', |
49
|
|
|
embed=drink_list_embed |
50
|
|
|
) |
51
|
|
|
|
52
|
|
|
async def update_salaries(self): |
53
|
|
|
for employee_name in list(self.work_list.keys()): |
54
|
|
|
if self.payees.get(employee_name) is None: |
55
|
|
|
self.payees[employee_name] = 0 |
56
|
|
|
|
57
|
|
|
self.payees[employee_name] += self.paye_amount |
58
|
|
|
|
59
|
|
|
await self.update() |
60
|
|
|
|
61
|
|
|
async def add(self, worker, t=0): |
62
|
|
|
if worker in self.work_list: |
63
|
|
|
raise EmployeeFound(worker) |
64
|
|
|
|
65
|
|
|
self.work_list[worker] = t or get_last_half_hour() |
66
|
|
|
await self.update() |
67
|
|
|
|
68
|
|
|
async def remove(self, worker): |
69
|
|
|
if worker not in self.work_list: |
70
|
|
|
raise EmployeeNotFound(worker) |
71
|
|
|
|
72
|
|
|
self.work_list.pop(worker) |
73
|
|
|
await self.update() |
74
|
|
|
|
75
|
|
|
async def wipe(self): |
76
|
|
|
self.payees = {} |
77
|
|
|
await self.update() |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
def get_embed_description() -> str: |
81
|
|
|
with open('assets/worklist_description.txt', encoding='utf-8') as f: |
82
|
|
|
return f.read() |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
def parse_from_message(content, empty, delim): |
86
|
|
|
if content == empty: |
87
|
|
|
return {} |
88
|
|
|
|
89
|
|
|
parsed = {} |
90
|
|
|
for line in content.splitlines(): |
91
|
|
|
left, right = line.split(delim) |
92
|
|
|
parsed[get_int(left)] = get_int(right) |
|
|
|
|
93
|
|
|
|
94
|
|
|
return parsed |
95
|
|
|
|