@@ -104,9 +104,9 @@ class DateTimeConverter(commands.Converter[datetime.datetime]):
104
104
105
105
Examples
106
106
--------
107
- - `<t:{6969...}[:t|T|d|D|f|F|R]> -> datetime(seconds=6969...)`
108
- - `YYYY-MM-DD[*HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]] -> datetime`
109
- - `November 18th, 2069 12:30:30.55 am; -3 -> datetime.datetime(2029, 11, 18, 0, 30, 30, 550000, tzinfo=tzoffset(None, 10800))
107
+ - `<t:{6969...}[:t|T|d|D|f|F|R]>` -> ` datetime(seconds=6969...)`
108
+ - `YYYY-MM-DD[*HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]]` -> ` datetime`
109
+ - `November 18th, 2069 12:30:30.55 am; -3` -> ` datetime.datetime(2029, 11, 18, 0, 30, 30, 550000, tzinfo=tzoffset(None, 10800))`
110
110
"""
111
111
112
112
async def convert (
@@ -142,9 +142,9 @@ class TimeConverter(commands.Converter[datetime.time]):
142
142
143
143
Examples
144
144
--------
145
- - `<t:{6969...}[:t|T|d|D|f|F|R]> -> time`
146
- - `HH[:MM[:SS]][+HH:MM[:SS]] -> time`
147
- - `12:30:30 am; -3 -> datetime.time(0, 30, 30, 550000, tzinfo=tzoffset(None, -10800))
145
+ - `<t:{6969...}[:t|T|d|D|f|F|R]>` -> ` time`
146
+ - `HH[:MM[:SS]][+HH:MM[:SS]]` -> ` time`
147
+ - `12:30:30 am; -3` -> ` datetime.time(0, 30, 30, 550000, tzinfo=tzoffset(None, -10800))`
148
148
"""
149
149
150
150
async def convert (
@@ -232,10 +232,10 @@ class TimeDeltaConverter(commands.Converter[datetime.timedelta]):
232
232
233
233
Examples
234
234
--------
235
- - `<t:{6969...}[:t|T|d|D|f|F|R]> -> datetime(second=6969...) - datetime.now(timezone.utc)`
236
- - `HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]] -> time`
237
- - `300d[ay[s]] 40m[in[ute[s]|s]] -> timedelta(days=30, minutes=40)``
238
- - `6:30:05 -> timedelta(hours=6, minutes=30, seconds=5)`
235
+ - `<t:{6969...}[:t|T|d|D|f|F|R]>` -> ` datetime(second=6969...) - datetime.now(timezone.utc)`
236
+ - `HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]` -> ` time`
237
+ - `300d[ay[s]] 40m[in[ute[s]|s]]` -> ` timedelta(days=30, minutes=40)``
238
+ - `6:30:05` -> ` timedelta(hours=6, minutes=30, seconds=5)`
239
239
"""
240
240
241
241
async def convert (
@@ -296,13 +296,13 @@ class ClosedRangeConverter(commands.Converter[range]):
296
296
297
297
Examples
298
298
--------
299
- - `start-stop -> range(start, stop+1)`
300
- - `start-stop|[+]step -> range(start, stop+1, +step)` *
301
- - `start-stop|-step -> range(start, stop+1, -step)` *
299
+ - `start-stop` -> ` range(start, stop+1)`
300
+ - `start-stop|[+]step` -> ` range(start, stop+1, +step)` *
301
+ - `start-stop|-step` -> ` range(start, stop+1, -step)` *
302
302
303
- - `start>|>=|≥x>|>=|≥stop -> range(start[+1], stop[+1])`
304
- - `start>|>=|≥x>|>=|≥stop|[+]step -> range(start[+1], stop[+1], +step)` *
305
- - `start>|>=|≥x>|>=|≥stop|-step -> range(start[+1], stop[+1], -step)` *
303
+ - `start>|>=|≥x>|>=|≥stop` -> ` range(start[+1], stop[+1])`
304
+ - `start>|>=|≥x>|>=|≥stop|[+]step` -> ` range(start[+1], stop[+1], +step)` *
305
+ - `start>|>=|≥x>|>=|≥stop|-step` -> ` range(start[+1], stop[+1], -step)` *
306
306
307
307
*The last '|' is considered as part of the syntax.
308
308
"""
@@ -621,8 +621,8 @@ class StringConverter(_StringConverter, Generic[_T]):
621
621
622
622
Examples
623
623
--------
624
- - `"'abc'" -> 'abc'`
625
- - `'"ab\\ "c"' -> 'ab"c'`
624
+ - `"'abc'"` -> ` 'abc'`
625
+ - `'"ab\\ "c"'` -> ` 'ab"c'`
626
626
"""
627
627
628
628
def __init__ (self , size : Any = None ) -> None :
@@ -847,8 +847,8 @@ class ParensConverter(commands.Converter[tuple]):
847
847
848
848
Examples
849
849
--------
850
- - `"( 1 2 4 5.5 )" -> (1, 2, 4, 5.5)`
851
- - `'( 1 ( 4 ) () ( ( 6 ( "a" ) ) ) 0 )' -> (1, (4,), (), ((6,("a",),),), 0)`
850
+ - `"( 1 2 4 5.5 )"` -> ` (1, 2, 4, 5.5)`
851
+ - `'( 1 ( 4 ) () ( ( 6 ( "a" ) ) ) 0 )'` -> ` (1, (4,), (), ((6,("a",),),), 0)`
852
852
"""
853
853
854
854
OPENING = "("
@@ -1168,13 +1168,113 @@ def _repr_converter(obj):
1168
1168
return repr (obj )
1169
1169
1170
1170
1171
+ class UnicodeEmojiConverter (commands .Converter [str ]):
1172
+ """A converter that converts emoji shortcodes or unicode
1173
+ character escapes into valid unicode emojis. Already valid
1174
+ inputs are ignored.
1175
+
1176
+ Syntax
1177
+ ------
1178
+ - `":eggplant:"` -> `"🍆"`
1179
+ - `"\\ u270c\\ u1f3fd"` -> `"✌🏽"`
1180
+ """
1181
+
1182
+ async def convert (self , ctx : commands .Context [BotT ], argument : str ) -> str :
1183
+ argument = StringConverter .escape (argument )
1184
+
1185
+ if snakecore .utils .is_emoji_shortcode (argument ):
1186
+ return snakecore .utils .shortcode_to_unicode_emoji (argument )
1187
+
1188
+ elif snakecore .utils .is_unicode_emoji (argument ):
1189
+ return argument
1190
+
1191
+ raise commands .BadArgument (
1192
+ "argument must be a valid unicode emoji or emoji shortcode"
1193
+ )
1194
+
1195
+
1196
+ UnicodeEmoji = Annotated [str , UnicodeEmojiConverter ]
1197
+ """A converter that converts emoji shortcodes or unicode
1198
+ character escapes into valid unicode emojis. Already valid
1199
+ inputs are ignored.
1200
+
1201
+ Syntax
1202
+ ------
1203
+ - `":eggplant:"` -> `"🍆"`
1204
+ - `"\\ u270c\\ u1f3fd"` -> `"✌🏽"`
1205
+ """
1171
1206
DateTime = Annotated [datetime .datetime , DateTimeConverter ]
1207
+ """A converter that parses timestamps to `datetime` objects.
1208
+
1209
+ Examples
1210
+ --------
1211
+ - `<t:{6969...}[:t|T|d|D|f|F|R]>` -> `datetime(seconds=6969...)`
1212
+ - `YYYY-MM-DD[*HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]]` -> `datetime`
1213
+ - `November 18th, 2069 12:30:30.55 am; -3` -> `datetime.datetime(2029, 11, 18, 0, 30, 30, 550000, tzinfo=tzoffset(None, 10800))`
1214
+ """
1172
1215
Time = Annotated [datetime .time , TimeConverter ]
1216
+ """A converter that parses time to `time` objects.
1217
+
1218
+ Examples
1219
+ --------
1220
+ - `<t:{6969...}[:t|T|d|D|f|F|R]>` -> `time`
1221
+ - `HH[:MM[:SS]][+HH:MM[:SS]]` -> `time`
1222
+ - `12:30:30 am; -3` -> `datetime.time(0, 30, 30, 550000, tzinfo=tzoffset(None, -10800))`
1223
+ """
1173
1224
TimeDelta = Annotated [datetime .timedelta , TimeDeltaConverter ]
1225
+ """A converter that parses time intervals to `timedelta` objects.
1226
+
1227
+ Examples
1228
+ --------
1229
+ - `<t:{6969...}[:t|T|d|D|f|F|R]>` -> `datetime(second=6969...) - datetime.now(timezone.utc)`
1230
+ - `HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]` -> `time`
1231
+ - `300d[ay[s]] 40m[in[ute[s]|s]]` -> `timedelta(days=30, minutes=40)``
1232
+ - `6:30:05` -> `timedelta(hours=6, minutes=30, seconds=5)`
1233
+ """
1174
1234
ClosedRange = Annotated [range , ClosedRangeConverter ]
1235
+ """A converter that parses closed integer ranges to Python `range` objects.
1236
+ Both a hyphen-based notation is supported (as used in English phrases) which always
1237
+ includes endpoints, as well as a mathematical notation using comparison operators.
1238
+
1239
+ Examples
1240
+ --------
1241
+ - `start-stop` -> `range(start, stop+1)`
1242
+ - `start-stop|[+]step` -> `range(start, stop+1, +step)` *
1243
+ - `start-stop|-step` -> `range(start, stop+1, -step)` *
1244
+
1245
+ - `start>|>=|≥x>|>=|≥stop` -> `range(start[+1], stop[+1])`
1246
+ - `start>|>=|≥x>|>=|≥stop|[+]step` -> `range(start[+1], stop[+1], +step)` *
1247
+ - `start>|>=|≥x>|>=|≥stop|-step` -> `range(start[+1], stop[+1], -step)` *
1248
+
1249
+ *The last '|' is considered as part of the syntax.
1250
+ """
1175
1251
1176
1252
if TYPE_CHECKING : # type checker deception
1177
1253
Parens = tuple
1254
+ """A special converter that establishes its own scope of arguments
1255
+ and parses argument tuples.
1256
+
1257
+ The recognized arguments are converted into their desired formats
1258
+ using the converters given to it as input, which are then converted
1259
+ into a tuple of arguments. This can be used to implement parsing
1260
+ of argument tuples. Nesting is also supported, as well as variadic
1261
+ parsing of argument tuples. The syntax is similar to type annotations
1262
+ using the `tuple` type (tuple[int, ...] = Parens[int, ...], etc.).
1263
+
1264
+ Arguments for this converter must be surrounded by whitespace, followed
1265
+ by round parentheses on both sides (`'( ... ... ... )'`).
1266
+
1267
+ This converter does not parse successfully if specified inside a tuple
1268
+ annotation of `discord.ext.commands.flags.Flag`, inside a subclass of
1269
+ `discord.ext.commands`'s default `FlagConverter`. To migitate this, it
1270
+ is recommended to subclass `snakecore.commands.converters.FlagConverter`
1271
+ instead.
1272
+
1273
+ Examples
1274
+ --------
1275
+ - `"( 1 2 4 5.5 )"` -> `(1, 2, 4, 5.5)`
1276
+ - `'( 1 ( 4 ) () ( ( 6 ( "a" ) ) ) 0 )'` -> `(1, (4,), (), ((6,("a",),),), 0)`
1277
+ """
1178
1278
1179
1279
class String (str ): # type: ignore
1180
1280
"""A converter that parses string literals to string objects,
@@ -1192,8 +1292,8 @@ class String(str): # type: ignore
1192
1292
1193
1293
Examples
1194
1294
--------
1195
- - `"'abc'" -> 'abc'`
1196
- - `'"ab\\ "c"' -> 'ab"c'`
1295
+ - `"'abc'"` -> ` 'abc'`
1296
+ - `'"ab\\ "c"'` -> ` 'ab"c'`
1197
1297
"""
1198
1298
1199
1299
def __class_getitem__ (cls , size : Union [StringParams , StringParamsTuple ]):
@@ -1208,8 +1308,8 @@ class StringExpr(str): # type: ignore
1208
1308
1209
1309
Examples
1210
1310
--------
1211
- - `"'abc'" -> 'abc'`
1212
- - `'"ab\\ "c"' -> 'ab"c'`
1311
+ - `"'abc'"` -> ` 'abc'`
1312
+ - `'"ab\\ "c"'` -> ` 'ab"c'`
1213
1313
"""
1214
1314
1215
1315
def __class_getitem__ (cls , regex_and_examples : Union [str , tuple [str , ...]]):
0 commit comments