Move emojisize pull parsing into the model
This commit is contained in:
@@ -3096,7 +3096,7 @@ class Client(object):
|
||||
)
|
||||
|
||||
if metadata and metadata.get("tags"):
|
||||
emoji_size = get_emojisize_from_tags(metadata.get("tags"))
|
||||
emoji_size = EmojiSize._from_tags(metadata.get("tags"))
|
||||
|
||||
message = Message(
|
||||
text=delta.get("body"),
|
||||
|
@@ -13,6 +13,22 @@ class EmojiSize(Enum):
|
||||
MEDIUM = "369239343222814"
|
||||
SMALL = "369239263222822"
|
||||
|
||||
@classmethod
|
||||
def _from_tags(cls, tags):
|
||||
string_to_emojisize = {
|
||||
"large": cls.LARGE,
|
||||
"medium": cls.MEDIUM,
|
||||
"small": cls.SMALL,
|
||||
"l": cls.LARGE,
|
||||
"m": cls.MEDIUM,
|
||||
"s": cls.SMALL,
|
||||
}
|
||||
for tag in tags or ():
|
||||
data = tag.split(":", maxsplit=1)
|
||||
if len(data) > 1 and data[0] == "hot_emoji_size":
|
||||
return string_to_emojisize.get(data[1])
|
||||
return None
|
||||
|
||||
|
||||
class MessageReaction(Enum):
|
||||
"""Used to specify a message reaction"""
|
||||
|
@@ -12,7 +12,6 @@ import warnings
|
||||
import logging
|
||||
import requests
|
||||
import aenum
|
||||
from .models import *
|
||||
|
||||
try:
|
||||
from urllib.parse import urlencode, parse_qs, urlparse
|
||||
@@ -47,15 +46,6 @@ USER_AGENTS = [
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6",
|
||||
]
|
||||
|
||||
LIKES = {
|
||||
"large": EmojiSize.LARGE,
|
||||
"medium": EmojiSize.MEDIUM,
|
||||
"small": EmojiSize.SMALL,
|
||||
"l": EmojiSize.LARGE,
|
||||
"m": EmojiSize.MEDIUM,
|
||||
"s": EmojiSize.SMALL,
|
||||
}
|
||||
|
||||
|
||||
GENDERS = {
|
||||
# For standard requests
|
||||
@@ -295,20 +285,6 @@ def get_jsmods_require(j, index):
|
||||
return None
|
||||
|
||||
|
||||
def get_emojisize_from_tags(tags):
|
||||
if tags is None:
|
||||
return None
|
||||
tmp = [tag for tag in tags if tag.startswith("hot_emoji_size:")]
|
||||
if len(tmp) > 0:
|
||||
try:
|
||||
return LIKES[tmp[0].split(":")[1]]
|
||||
except (KeyError, IndexError):
|
||||
log.exception(
|
||||
"Could not determine emoji size from {} - {}".format(tags, tmp)
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
def require_list(list_):
|
||||
if isinstance(list_, list):
|
||||
return set(list_)
|
||||
|
@@ -7,7 +7,6 @@ from ._util import (
|
||||
log,
|
||||
handler,
|
||||
USER_AGENTS,
|
||||
LIKES,
|
||||
GENDERS,
|
||||
ReqUrl,
|
||||
facebookEncoding,
|
||||
@@ -25,7 +24,6 @@ from ._util import (
|
||||
check_json,
|
||||
check_request,
|
||||
get_jsmods_require,
|
||||
get_emojisize_from_tags,
|
||||
require_list,
|
||||
mimetype_to_key,
|
||||
get_files_from_urls,
|
||||
|
Reference in New Issue
Block a user