Skip to content

Commit 0cebb35

Browse files
committed
feat: add small widgets
1 parent 563e48a commit 0cebb35

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

topgg/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .errors import Error, RequestError, Ratelimited
2727
from .models import Bot, SortBy, Voter
2828
from .webhooks import Vote, Webhooks
29+
from .widget import WidgetType
2930
from .version import VERSION
3031
from .client import Client
3132
from . import widget
@@ -51,4 +52,5 @@
5152
'Voter',
5253
'Webhooks',
5354
'widget',
55+
'WidgetType',
5456
)

topgg/widget.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,76 @@
11
from .client import BASE_URL
22

3-
def large(id: int) -> str:
3+
import enum
4+
5+
6+
class WidgetType(enum.Enum):
7+
"""
8+
Widget type.
9+
"""
10+
11+
DISCORD_BOT = 'discord/bot'
12+
DISCORD_SERVER = 'discord/server'
13+
14+
15+
def large(type: WidgetType, id: int) -> str:
416
"""
517
Generates a large widget URL.
618
19+
:param type: The widget type.
20+
:type type: :class:`.WidgetType`
21+
:param id: The requested ID.
22+
:type id: :py:class:`int`
23+
24+
:returns: The widget URL.
25+
:rtype: :py:class:`str`
26+
"""
27+
28+
return f'{BASE_URL}/widgets/large/{type.value}/{id}'
29+
30+
31+
def votes(type: WidgetType, id: int) -> str:
32+
"""
33+
Generates a small widget URL for displaying votes.
34+
35+
:param type: The widget type.
36+
:type type: :class:`.WidgetType`
37+
:param id: The requested ID.
38+
:type id: :py:class:`int`
39+
40+
:returns: The widget URL.
41+
:rtype: :py:class:`str`
42+
"""
43+
44+
return f'{BASE_URL}/widgets/small/votes/{type.value}/{id}'
45+
46+
47+
def owner(type: WidgetType, id: int) -> str:
48+
"""
49+
Generates a small widget URL for displaying an entity's owner.
50+
51+
:param type: The widget type.
52+
:type type: :class:`.WidgetType`
53+
:param id: The requested ID.
54+
:type id: :py:class:`int`
55+
56+
:returns: The widget URL.
57+
:rtype: :py:class:`str`
58+
"""
59+
60+
return f'{BASE_URL}/widgets/small/owner/{type.value}/{id}'
61+
62+
63+
def social(type: WidgetType, id: int) -> str:
64+
"""
65+
Generates a small widget URL for displaying social stats.
66+
67+
:param type: The widget type.
68+
:type type: :class:`.WidgetType`
769
:param id: The requested ID.
870
:type id: :py:class:`int`
971
1072
:returns: The widget URL.
1173
:rtype: :py:class:`str`
1274
"""
1375

14-
return f'{BASE_URL}/widgets/large/{id}'
76+
return f'{BASE_URL}/widgets/small/social/{type.value}/{id}'

0 commit comments

Comments
 (0)