2020-05-12 23:55:08 +00:00
|
|
|
|
# © 2018–2020 io mintz <io@mintz.cc>
|
|
|
|
|
#
|
|
|
|
|
# Emote Manager is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# Emote Manager is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
# along with Emote Manager. If not, see <https://www.gnu.org/licenses/>.
|
2018-07-30 04:34:27 +00:00
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
various utilities related to custom emotes
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
"""Matches :foo: and ;foo; but not :foo;. Used for emotes in text."""
|
|
|
|
|
RE_EMOTE = re.compile(r'(:|;)(?P<name>\w{2,32})\1|(?P<newline>\n)', re.ASCII)
|
|
|
|
|
|
|
|
|
|
"""Matches only custom server emotes."""
|
|
|
|
|
RE_CUSTOM_EMOTE = re.compile(r'<(?P<animated>a?):(?P<name>\w{2,32}):(?P<id>\d{17,})>', re.ASCII)
|
|
|
|
|
|
|
|
|
|
def url(id, *, animated: bool = False):
|
|
|
|
|
"""Convert an emote ID to the image URL for that emote."""
|
|
|
|
|
extension = 'gif' if animated else 'png'
|
|
|
|
|
return f'https://cdn.discordapp.com/emojis/{id}.{extension}?v=1'
|