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

pot   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A Pot.correct() 0 3 1
A Pot.add() 0 3 1
A Pot.update() 0 12 1
A Pot.__init__() 0 3 1
A Pot.remove() 0 3 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
A get_embed_description() 0 3 2
A parse_from_message() 0 2 1
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