1
|
|
|
from typing import NoReturn, Optional |
2
|
|
|
|
3
|
|
|
from discord import TextChannel |
4
|
|
|
from discord.ext import commands |
5
|
|
|
from discord.ext.commands import Context |
6
|
|
|
|
7
|
|
|
from app.bot import Bot |
8
|
|
|
from app.classes.pot import Pot |
9
|
|
|
from app.utils import SALARIED_ROLE_ID, PDG_ROLE_ID |
10
|
|
|
|
11
|
|
|
CHANNEL_ID: int = 889523568298307594 |
12
|
|
|
MESSAGE_ID: int = 890313495030157313 |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class TicketCog(commands.Cog): |
16
|
|
|
"""A simple commands cog template.""" |
17
|
|
|
|
18
|
|
|
def __init__(self, client: Bot): |
19
|
|
|
"""Link to bot instance.""" |
20
|
|
|
self.name = 'Cagnotte' |
21
|
|
|
self.client: Bot = client |
22
|
|
|
self.channel: Optional[TextChannel] = None |
23
|
|
|
self.pot: Optional[Pot] = None |
24
|
|
|
|
25
|
|
|
@commands.Cog.listener() |
26
|
|
|
async def on_ready(self): |
27
|
|
|
self.channel = self.client.guild.get_channel(CHANNEL_ID) |
28
|
|
|
|
29
|
|
|
self.pot = Pot( |
30
|
|
|
await self.channel.fetch_message(MESSAGE_ID), |
31
|
|
|
) |
32
|
|
|
|
33
|
|
|
await self.pot.update() |
34
|
|
|
|
35
|
|
|
@commands.command( |
36
|
|
|
name="vente", |
37
|
|
|
description="Ajoute le montant rapporté par la cagnotte" |
38
|
|
|
) |
39
|
|
|
@commands.has_any_role(SALARIED_ROLE_ID, PDG_ROLE_ID) |
40
|
|
|
async def sell_command(self, ctx: Context, amount: int): |
41
|
|
|
await ctx.message.delete() |
42
|
|
|
await self.pot.add(amount) |
43
|
|
|
await ctx.send("> Ajouté!", delete_after=3) |
44
|
|
|
|
45
|
|
|
@commands.command( |
46
|
|
|
name="erreur", |
47
|
|
|
description="Corrige une erreur sur la cagnotte" |
48
|
|
|
) |
49
|
|
|
@commands.has_any_role(SALARIED_ROLE_ID, PDG_ROLE_ID) |
50
|
|
|
async def error_remove_command(self, ctx: Context, amount: int): |
51
|
|
|
await ctx.message.delete() |
52
|
|
|
await self.pot.correct(amount) |
53
|
|
|
await ctx.send("> Corrigé", delete_after=3) |
54
|
|
|
|
55
|
|
|
@commands.command( |
56
|
|
|
name="achat", |
57
|
|
|
description="Retire le montant utilisé depuis la cagnotte" |
58
|
|
|
) |
59
|
|
|
@commands.has_any_role(SALARIED_ROLE_ID, PDG_ROLE_ID) |
60
|
|
|
async def buy_remove_command(self, ctx: Context, amount: int): |
61
|
|
|
await ctx.message.delete() |
62
|
|
|
await self.pot.remove(amount) |
63
|
|
|
await ctx.send("> Retiré", delete_after=3) |
64
|
|
|
|
65
|
|
View Code Duplication |
@commands.command( |
|
|
|
|
66
|
|
|
name="desc-4", |
67
|
|
|
description="Met à jour la description de la cagnotte." |
68
|
|
|
) |
69
|
|
|
@commands.has_any_role(SALARIED_ROLE_ID, PDG_ROLE_ID) |
70
|
|
|
async def set_drink_list_description(self, ctx: Context, *, message: str): |
71
|
|
|
await ctx.message.delete() |
72
|
|
|
|
73
|
|
|
with open( |
74
|
|
|
"assets/pot_description.txt", |
75
|
|
|
'w', encoding='utf-8' |
76
|
|
|
) as f: |
77
|
|
|
f.write(message) |
78
|
|
|
|
79
|
|
|
await ctx.send( |
80
|
|
|
f"Description mise à jour\n>>> {message}", delete_after=5 |
81
|
|
|
) |
82
|
|
|
|
83
|
|
|
await self.pot.update() |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
def setup(client) -> NoReturn: |
87
|
|
|
client.add_cog(TicketCog(client)) |
88
|
|
|
|