Passed
Push — main ( 6693a8...9599de )
by Yohann
01:21
created

info.InfoCog.__init__()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
import re
2
3
from pincer import __version__
4
from pincer.commands import ChatCommandHandler
5
from pincer.objects import Embed, Message, InteractionFlags
6
from pincer.utils import TaskScheduler
7
8
from pincer_bot.core.command import guild_command
9
from pincer_bot.tasks.get_pypi_downloads import get_pypi_stats
10
11
DL_PATTERN = re.compile(r'downloads: \d*')
12
13
14
class InfoCog:
15
16
    def __init__(self, client):
17
        self.client = client
18
19
        task = TaskScheduler(self.client)
20
        self.get_pypi_downloads = task.loop(minutes=10)(get_pypi_stats)
21
        self.get_pypi_downloads.start()
22
23
    @guild_command(name='about')
24
    async def about_command(self) -> Embed:
25
        return Embed(
26
            title=f"Pincer - {__version__}",
27
            description=(
28
                "🚀 An asynchronous python API wrapper meant to replace "
29
                "discord.py\n> Snappy discord api wrapper written "
30
                "with aiohttp & websockets"
31
            )
32
        ).add_field(
33
            name="**Github Repository**",
34
            value="> https://github.com/Pincer-org/Pincer"
35
        ).add_field(
36
            name="Website",
37
            value="> https://pincer.dev"
38
        ).add_field(
39
            name="PyPI package",
40
            value="> https://pypi.org/project/Pincer"
41
        ).add_field(
42
            name="ReadTheDocs",
43
            value="> https://pincer.readthedocs.io"
44
        ).set_footer(
45
            text="The package is currently within the planning phase",
46
            icon_url="https://pincer.dev/img/icon.png"
47
        ).set_author(
48
            name="Pincer",
49
            url='https://pincer.dev',
50
            icon_url="https://pincer.dev/img/icon.png"
51
        ).set_thumbnail(
52
            url="https://pincer.dev/img/icon.png"
53
        ).set_image(
54
            url=(
55
                "https://repository-images.githubusercontent.com"
56
                "/400871418/045ebf39-7c6e-4c3a-b744-0c3122374203"
57
            )
58
        )
59
60
    @guild_command(name="help")
61
    async def help_command(self):
62
        return Message(
63
            content='>>> ' + '\n'.join(
64
                f"`{cmd_name.capitalize()}` - {cmd_obj.app.description}"
65
                for cmd_name, cmd_obj in ChatCommandHandler.register.items()
66
            ),
67
            flags=InteractionFlags.EPHEMERAL
68
        )
69
70
    @guild_command(name="pypi_dl")
71
    async def pypi_dl_command(self):
72
        height = 15
73
        pypi = self.client.pypi
74
75
        lines = [
76
            (round((n / pypi.daily_max) * height) * '█').rjust(height, '░')
77
            for n in self.client.pypi.downloads.values()
78
        ]
79
80
        rotated = '\n'.join(
81
            ''.join(line) for line in zip(*lines)
82
        )
83
84
        return Embed(
85
            title="PyPI stats",
86
            description=(
87
                f"Totals downloads: `{self.client.pypi.total_downloads:,}`\n"
88
                f"Daily average: `{self.client.pypi.daily_average:,.0f}`"
89
            )
90
        ).add_field(
91
            name="graph",
92
            value=f'```py\n{rotated}\n```'
93
        )
94
95
96
setup = InfoCog
97