1
|
|
|
from typing import NoReturn, Optional |
2
|
|
|
|
3
|
|
|
from discord import TextChannel, User |
4
|
|
|
from discord.ext import commands |
5
|
|
|
from discord.ext.commands import Context, CommandError |
6
|
|
|
|
7
|
|
|
from app.bot import Bot |
8
|
|
|
from app.classes.work_list import WorkList |
9
|
|
|
from app.exceptions import EmployeeFound, EmployeeNotFound |
10
|
|
|
from app.tasks.update_salaries import UpdateSalariesTask |
11
|
|
|
|
12
|
|
|
CHANNEL_ID: int = 888821011989012551 |
13
|
|
|
MESSAGE_ID: int = 890274291969572874 |
14
|
|
|
SALARIED_ROLE_ID: int = 888527962935296091 |
15
|
|
|
PDG_ROLE_ID: int = 888527789794422784 |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
class WorkerCog(commands.Cog): |
19
|
|
|
"""A simple commands cog template.""" |
20
|
|
|
|
21
|
|
|
def __init__(self, client: Bot): |
22
|
|
|
"""Link to bot instance.""" |
23
|
|
|
self.name = 'Travail' |
24
|
|
|
self.client: Bot = client |
25
|
|
|
self.channel: Optional[TextChannel] = None |
26
|
|
|
self.manager: Optional[WorkList] = None |
27
|
|
|
|
28
|
|
|
@commands.Cog.listener() |
29
|
|
|
async def on_ready(self): |
30
|
|
|
self.channel = self.client.guild.get_channel(CHANNEL_ID) |
31
|
|
|
|
32
|
|
|
self.manager = WorkList( |
33
|
|
|
await self.channel.fetch_message(MESSAGE_ID), |
34
|
|
|
) |
35
|
|
|
|
36
|
|
|
await UpdateSalariesTask(self.manager).setup() |
37
|
|
|
await self.manager.update() |
38
|
|
|
|
39
|
|
|
@commands.command( |
40
|
|
|
name='co', |
41
|
|
|
description=( |
42
|
|
|
"Démarre le mode et travail pour garder le temps " |
43
|
|
|
"et calculer le salaire" |
44
|
|
|
) |
45
|
|
|
) |
46
|
|
|
@commands.has_any_role(SALARIED_ROLE_ID, PDG_ROLE_ID) |
47
|
|
|
async def connect_command(self, ctx: Context): |
48
|
|
|
await ctx.message.delete() |
49
|
|
|
await self.manager.add(ctx.author.id) |
50
|
|
|
await ctx.send("> Mise au travail...", delete_after=3) |
51
|
|
|
|
52
|
|
View Code Duplication |
@commands.command( |
|
|
|
|
53
|
|
|
name='add15m', |
54
|
|
|
description="Ajoute 15m de salaire à la personne mentionnée" |
55
|
|
|
) |
56
|
|
|
@commands.has_any_role(SALARIED_ROLE_ID, PDG_ROLE_ID) |
57
|
|
|
async def add_15m_command(self, ctx: Context, user: User = None, amount=1): |
58
|
|
|
await ctx.message.delete() |
59
|
|
|
|
60
|
|
|
if user is None: |
61
|
|
|
user = ctx.author |
62
|
|
|
|
63
|
|
|
if user.id not in self.manager.payees: |
64
|
|
|
self.manager.payees[user.id] = 0 |
65
|
|
|
|
66
|
|
|
self.manager.payees[user.id] += (self.manager.paye_amount * amount) |
67
|
|
|
|
68
|
|
|
if self.manager.payees[user.id] == 0: |
69
|
|
|
self.manager.payees.pop(user.id) |
70
|
|
|
|
71
|
|
|
await self.manager.update() |
72
|
|
|
await ctx.send("> Ajouté", delete_after=3) |
73
|
|
|
|
74
|
|
View Code Duplication |
@commands.command( |
|
|
|
|
75
|
|
|
name='remove15m', |
76
|
|
|
description="Retire 15m de salaire à la personne mentionnée" |
77
|
|
|
) |
78
|
|
|
@commands.has_any_role(SALARIED_ROLE_ID, PDG_ROLE_ID) |
79
|
|
|
async def remove_15m_command( |
80
|
|
|
self, ctx: Context, user: User = None, amount=1 |
81
|
|
|
): |
82
|
|
|
await ctx.message.delete() |
83
|
|
|
|
84
|
|
|
if user is None: |
85
|
|
|
user = ctx.author |
86
|
|
|
|
87
|
|
|
if user.id not in self.manager.payees: |
88
|
|
|
self.manager.payees[user.id] = 0 |
89
|
|
|
|
90
|
|
|
self.manager.payees[user.id] -= (self.manager.paye_amount * amount) |
91
|
|
|
|
92
|
|
|
if self.manager.payees[user.id] == 0: |
93
|
|
|
self.manager.payees.pop(user.id) |
94
|
|
|
|
95
|
|
|
await self.manager.update() |
96
|
|
|
await ctx.send("> Retiré", delete_after=3) |
97
|
|
|
|
98
|
|
|
@commands.command( |
99
|
|
|
name='deco', |
100
|
|
|
description="Arrête le mode travail." |
101
|
|
|
) |
102
|
|
|
@commands.has_any_role(SALARIED_ROLE_ID, PDG_ROLE_ID) |
103
|
|
|
async def disconnect(self, ctx: Context): |
104
|
|
|
await ctx.message.delete() |
105
|
|
|
await self.manager.remove(ctx.author.id) |
106
|
|
|
await ctx.send('> Arrêt', delete_after=3) |
107
|
|
|
|
108
|
|
|
@commands.command( |
109
|
|
|
name='wipe', |
110
|
|
|
description="Supprime la liste des salaries à payer." |
111
|
|
|
) |
112
|
|
|
async def wipe(self, ctx: Context): |
113
|
|
|
await self.manager.wipe() |
114
|
|
|
await ctx.send("> Wiped!") |
115
|
|
|
|
116
|
|
View Code Duplication |
@commands.command( |
|
|
|
|
117
|
|
|
name="desc-3", |
118
|
|
|
description="Met à jour la description de la liste de travail." |
119
|
|
|
) |
120
|
|
|
@commands.has_any_role(SALARIED_ROLE_ID, PDG_ROLE_ID) |
121
|
|
|
async def set_drink_list_description(self, ctx, *, message): |
122
|
|
|
await ctx.message.delete() |
123
|
|
|
|
124
|
|
|
with open( |
125
|
|
|
"assets/worklist_description.txt", |
126
|
|
|
'w', encoding='utf-8' |
127
|
|
|
) as f: |
128
|
|
|
f.write(message) |
129
|
|
|
|
130
|
|
|
await ctx.send( |
131
|
|
|
f"Description mise à jour\n>>> {message}", delete_after=5 |
132
|
|
|
) |
133
|
|
|
|
134
|
|
|
await self.manager.update() |
135
|
|
|
|
136
|
|
|
@commands.command(name="pay") |
137
|
|
|
@commands.has_any_role(SALARIED_ROLE_ID, PDG_ROLE_ID) |
138
|
|
|
async def set_pay_command(self, ctx: Context, amount: int): |
139
|
|
|
await ctx.message.delete() |
140
|
|
|
|
141
|
|
|
self.manager.paye_amount = amount |
142
|
|
|
await self.manager.update() |
143
|
|
|
await ctx.send( |
144
|
|
|
f"La paye est maintenant de `${amount:,}`", delete_after=5 |
145
|
|
|
) |
146
|
|
|
|
147
|
|
|
@commands.Cog.listener() |
148
|
|
|
async def on_command_error(self, ctx: Context, exc: CommandError): |
149
|
|
|
if not isinstance(exc, commands.errors.CommandInvokeError): |
150
|
|
|
return |
151
|
|
|
|
152
|
|
|
if isinstance(exc.original, EmployeeNotFound): |
153
|
|
|
await ctx.send( |
154
|
|
|
"Vous n' êtes pas en train de travailler" |
155
|
|
|
) |
156
|
|
|
|
157
|
|
|
if isinstance(exc.original, EmployeeFound): |
158
|
|
|
await ctx.send("Vous êtes déjà dans la liste des employées actifs.") |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
def setup(client) -> NoReturn: |
162
|
|
|
client.add_cog(WorkerCog(client)) |
163
|
|
|
|