Passed
Push — master ( a8a0e7...5f5103 )
by Yohann
01:28
created

pot.Pot.update()   A

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nop 1
dl 0
loc 12
rs 9.95
c 0
b 0
f 0
1
import discord
2
3
from app.classes.abc.message_manager import MessageManager
4
from app.utils import get_int
5
6
7
class Pot(MessageManager):
8
9
    def __init__(self, message):
10
        self.pot_message = message
11
        self.pot = parse_from_message(message.embeds[0].description)
12
13
    async def update(self):
14
        drink_list_embed = discord.Embed(
15
            title="Cagnotte",
16
            description=(
17
                    get_embed_description()
18
                    + f'\n\n**Total:** `${self.pot:,}`'
19
            )
20
        )
21
22
        await self.pot_message.edit(
23
            content='',
24
            embed=drink_list_embed
25
        )
26
27
    async def add(self, amount):
28
        self.pot += amount
29
        await self.update()
30
31
    async def correct(self, amount):
32
        self.pot -= amount
33
        await self.update()
34
35
    async def remove(self, amount):
36
        self.pot -= amount
37
        await self.update()
38
39
40
def get_embed_description() -> str:
41
    with open('assets/pot_description.txt', encoding='utf-8') as f:
42
        return f.read()
43
44
45
def parse_from_message(content):
46
    return get_int(content.splitlines()[-1].split('$')[1])
47