|
28 | 28 | from typing import Any, Optional, Union |
29 | 29 | from json import JSONDecodeError |
30 | 30 | from inspect import isawaitable |
31 | | -from urllib import parse |
32 | 31 |
|
33 | | - |
34 | | -RawCallback = Callable[[web.Request], Awaitable[web.StreamResponse]] |
35 | | - |
36 | | - |
37 | | -class Vote: |
38 | | - """A dispatched Top.gg vote event.""" |
39 | | - |
40 | | - __slots__ = ('receiver_id', 'voter_id', 'is_test', 'is_weekend', 'query') |
41 | | - |
42 | | - receiver_id: int |
43 | | - """The ID of the Discord bot/server that received a vote.""" |
44 | | - |
45 | | - voter_id: int |
46 | | - """The ID of the Top.gg user who voted.""" |
47 | | - |
48 | | - is_test: bool |
49 | | - """Whether this vote is just a test done from the page settings.""" |
50 | | - |
51 | | - is_weekend: bool |
52 | | - """Whether the weekend multiplier is active, where a single vote counts as two.""" |
53 | | - |
54 | | - query: dict[str, str] |
55 | | - """Query strings found on the vote page.""" |
56 | | - |
57 | | - def __init__(self, json: dict): |
58 | | - guild = json.get('guild') |
59 | | - |
60 | | - self.receiver_id = int(json.get('bot', guild)) |
61 | | - self.voter_id = int(json['user']) |
62 | | - self.is_test = json['type'] == 'test' |
63 | | - self.is_weekend = bool(json.get('isWeekend')) |
64 | | - |
65 | | - if query := json.get('query'): |
66 | | - self.query = { |
67 | | - k: v[0] for k, v in parse.parse_qs(parse.urlsplit(query).query).items() |
68 | | - } |
69 | | - else: |
70 | | - self.query = {} |
71 | | - |
72 | | - def __repr__(self) -> str: |
73 | | - return ( |
74 | | - f'<{__class__.__name__} receiver_id={self.receiver_id} voter_id={self.voter_id}>' |
75 | | - ) |
| 32 | +from .models import Vote |
76 | 33 |
|
77 | 34 |
|
| 35 | +RawCallback = Callable[[web.Request], Awaitable[web.StreamResponse]] |
78 | 36 | OnVoteCallback = Callable[[Vote], Any] |
79 | 37 | OnVoteDecorator = Callable[[OnVoteCallback], RawCallback] |
80 | 38 |
|
|
0 commit comments