8
8
9
9
10
10
class Version :
11
+ """
12
+ This class represents a single version of Modmail.
13
+
14
+ Parameters
15
+ ----------
16
+ bot : Bot
17
+ The Modmail bot.
18
+ version : str
19
+ The version string (ie. "v2.12.0").
20
+ lines : str
21
+ The lines of changelog messages for this version.
22
+
23
+ Attributes
24
+ ----------
25
+ bot : Bot
26
+ The Modmail bot.
27
+ version : str
28
+ The version string (ie. "v2.12.0").
29
+ lines : List[str]
30
+ A list of lines of changelog messages for this version.
31
+ fields : defaultdict[str, str]
32
+ A dict of fields separated by "Fixed", "Changed", etc sections.
33
+ description : str
34
+ General description of the version.
35
+ """
36
+
11
37
def __init__ (self , bot : Bot , version : str , lines : str ):
12
38
self .bot = bot
13
39
self .version = version
@@ -20,6 +46,13 @@ def __repr__(self) -> str:
20
46
return f'Version({ self .version } , description="{ self .description } ")'
21
47
22
48
def parse (self ) -> None :
49
+ """
50
+ Parse the lines and split them into `description` and `fields`.
51
+ .
52
+ Returns
53
+ -------
54
+ None
55
+ """
23
56
curr_action = None
24
57
25
58
for line in self .lines :
@@ -32,6 +65,9 @@ def parse(self) -> None:
32
65
33
66
@property
34
67
def embed (self ) -> Embed :
68
+ """
69
+ Embed: the formatted `Embed` of this `Version`.
70
+ """
35
71
embed = Embed (color = Color .green (), description = self .description )
36
72
embed .set_author (
37
73
name = f'{ self .version } - Changelog' ,
@@ -46,31 +82,81 @@ def embed(self) -> Embed:
46
82
return embed
47
83
48
84
49
- class ChangeLog :
50
- changelog_url = ('https://raw.githubusercontent.com/'
85
+ class Changelog :
86
+ """
87
+ This class represents the complete changelog of Modmail.
88
+
89
+ Parameters
90
+ ----------
91
+ bot : Bot
92
+ The Modmail bot.
93
+ text : str
94
+ The complete changelog text.
95
+
96
+ Attributes
97
+ ----------
98
+ bot : Bot
99
+ The Modmail bot.
100
+ text : str
101
+ The complete changelog text.
102
+ versions : List[Version]
103
+ A list of `Version`'s within the changelog.
104
+
105
+ Class Attributes
106
+ ----------------
107
+ CHANGELOG_URL : str
108
+ The URL to Modmail changelog.
109
+ VERSION_REGEX : re.Pattern
110
+ The regex used to parse the versions.
111
+ """
112
+
113
+ CHANGELOG_URL = ('https://raw.githubusercontent.com/'
51
114
'kyb3r/modmail/master/CHANGELOG.md' )
52
- regex = re .compile (r'# (v\d+\.\d+\.\d+)([\S\s]*?(?=# v|$))' )
115
+ VERSION_REGEX = re .compile (r'# (v\d+\.\d+\.\d+)([\S\s]*?(?=# v|$))' )
53
116
54
117
def __init__ (self , bot : Bot , text : str ):
55
118
self .bot = bot
56
119
self .text = text
57
- self .versions = [Version (bot , * m ) for m in self .regex .findall (text )]
120
+ self .versions = [Version (bot , * m )
121
+ for m in self .VERSION_REGEX .findall (text )]
58
122
59
123
@property
60
124
def latest_version (self ) -> Version :
125
+ """
126
+ Version: The latest `Version` of the `Changelog`.
127
+ """
61
128
return self .versions [0 ]
62
129
63
130
@property
64
131
def embeds (self ) -> List [Embed ]:
132
+ """
133
+ List[Embed]: A list of `Embed`'s for each of the `Version`.
134
+ """
65
135
return [v .embed for v in self .versions ]
66
136
67
137
@classmethod
68
- async def from_repo (cls , bot , url : str = '' ) -> 'ChangeLog' :
69
- url = url or cls .changelog_url
138
+ async def from_url (cls , bot : Bot , url : str = '' ) -> 'Changelog' :
139
+ """
140
+ Create a `Changelog` from a URL.
141
+
142
+ Parameters
143
+ ----------
144
+ bot : Bot
145
+ The Modmail bot.
146
+ url : str, optional
147
+ Defaults to `CHANGELOG_URL`.
148
+ The URL to the changelog.
149
+
150
+ Returns
151
+ -------
152
+ Changelog
153
+ The newly created `Changelog` parsed from the `url`.
154
+ """
155
+ url = url or cls .CHANGELOG_URL
70
156
resp = await bot .session .get (url )
71
157
return cls (bot , await resp .text ())
72
158
73
159
74
160
if __name__ == '__main__' :
75
161
with open ('../CHANGELOG.md' ) as f :
76
- print (ChangeLog (..., f .read ()).latest_version )
162
+ print (Changelog (..., f .read ()).latest_version )
0 commit comments