Fix various errors
Found using mypy!
This commit is contained in:
@@ -2,7 +2,6 @@ import datetime
|
|||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
from ._core import log
|
from ._core import log
|
||||||
from . import _util, _graphql, _session
|
from . import _util, _graphql, _session
|
||||||
@@ -25,14 +24,7 @@ from ._quick_reply import (
|
|||||||
QuickReplyEmail,
|
QuickReplyEmail,
|
||||||
)
|
)
|
||||||
from ._poll import Poll, PollOption
|
from ._poll import Poll, PollOption
|
||||||
from ._plan import Plan
|
from ._plan import ACONTEXT, Plan
|
||||||
|
|
||||||
|
|
||||||
ACONTEXT = {
|
|
||||||
"action_history": [
|
|
||||||
{"surface": "messenger_chat_tab", "mechanism": "messenger_composer"}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import attr
|
import attr
|
||||||
from ._core import attrs_default, Image
|
from ._core import attrs_default, Image
|
||||||
from . import _util, _session, _plan, _thread, _user
|
from . import _util, _session, _graphql, _plan, _thread, _user
|
||||||
from typing import Sequence, Iterable
|
from typing import Sequence, Iterable
|
||||||
|
|
||||||
|
|
||||||
@@ -69,10 +69,10 @@ class Group(_thread.ThreadABC):
|
|||||||
user_id: User ID to remove
|
user_id: User ID to remove
|
||||||
"""
|
"""
|
||||||
data = {"uid": user_id, "tid": self.id}
|
data = {"uid": user_id, "tid": self.id}
|
||||||
j = self._payload_post("/chat/remove_participants/", data)
|
j = self.session._payload_post("/chat/remove_participants/", data)
|
||||||
|
|
||||||
def _admin_status(self, user_ids: Iterable[str], status: bool):
|
def _admin_status(self, user_ids: Iterable[str], status: bool):
|
||||||
data = {"add": admin, "thread_fbid": self.id}
|
data = {"add": status, "thread_fbid": self.id}
|
||||||
|
|
||||||
for i, user_id in enumerate(user_ids):
|
for i, user_id in enumerate(user_ids):
|
||||||
data["admin_ids[{}]".format(i)] = str(user_id)
|
data["admin_ids[{}]".format(i)] = str(user_id)
|
||||||
@@ -119,7 +119,7 @@ class Group(_thread.ThreadABC):
|
|||||||
Args:
|
Args:
|
||||||
require_admin_approval: True or False
|
require_admin_approval: True or False
|
||||||
"""
|
"""
|
||||||
data = {"set_mode": int(require_admin_approval), "thread_fbid": thread_id}
|
data = {"set_mode": int(require_admin_approval), "thread_fbid": self.id}
|
||||||
j = self.session._payload_post("/messaging/set_approval_mode/?dpr=1", data)
|
j = self.session._payload_post("/messaging/set_approval_mode/?dpr=1", data)
|
||||||
|
|
||||||
def _users_approval(self, user_ids: Iterable[str], approve: bool):
|
def _users_approval(self, user_ids: Iterable[str], approve: bool):
|
||||||
|
@@ -10,6 +10,13 @@ class GuestStatus(Enum):
|
|||||||
DECLINED = 3
|
DECLINED = 3
|
||||||
|
|
||||||
|
|
||||||
|
ACONTEXT = {
|
||||||
|
"action_history": [
|
||||||
|
{"surface": "messenger_chat_tab", "mechanism": "messenger_composer"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@attrs_default
|
@attrs_default
|
||||||
class Plan:
|
class Plan:
|
||||||
"""Represents a plan."""
|
"""Represents a plan."""
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
import abc
|
import abc
|
||||||
import attr
|
import attr
|
||||||
|
import collections
|
||||||
import datetime
|
import datetime
|
||||||
from ._core import attrs_default, Enum, Image
|
from ._core import attrs_default, Enum, Image
|
||||||
from . import _util, _exception, _session
|
from . import _util, _exception, _session, _graphql, _attachment, _file, _plan
|
||||||
from typing import MutableMapping, Any, Iterable, Tuple
|
from typing import MutableMapping, Any, Iterable, Tuple
|
||||||
|
|
||||||
|
|
||||||
@@ -231,6 +232,8 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
Returns:
|
Returns:
|
||||||
list: `Message` objects
|
list: `Message` objects
|
||||||
"""
|
"""
|
||||||
|
from . import _message
|
||||||
|
|
||||||
# TODO: Return proper searchable iterator
|
# TODO: Return proper searchable iterator
|
||||||
params = {
|
params = {
|
||||||
"id": self.id,
|
"id": self.id,
|
||||||
@@ -244,12 +247,14 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if j.get("message_thread") is None:
|
if j.get("message_thread") is None:
|
||||||
raise FBchatException("Could not fetch thread {}: {}".format(self.id, j))
|
raise _exception.FBchatException(
|
||||||
|
"Could not fetch thread {}: {}".format(self.id, j)
|
||||||
|
)
|
||||||
|
|
||||||
read_receipts = j["message_thread"]["read_receipts"]["nodes"]
|
read_receipts = j["message_thread"]["read_receipts"]["nodes"]
|
||||||
|
|
||||||
messages = [
|
messages = [
|
||||||
Message._from_graphql(self.session, message, read_receipts)
|
_message.Message._from_graphql(self.session, message, read_receipts)
|
||||||
for message in j["message_thread"]["messages"]["nodes"]
|
for message in j["message_thread"]["messages"]["nodes"]
|
||||||
]
|
]
|
||||||
messages.reverse()
|
messages.reverse()
|
||||||
@@ -279,11 +284,11 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if i["node"].get("__typename") == "MessageImage":
|
if i["node"].get("__typename") == "MessageImage":
|
||||||
yield ImageAttachment._from_list(i)
|
yield _file.ImageAttachment._from_list(i)
|
||||||
elif i["node"].get("__typename") == "MessageVideo":
|
elif i["node"].get("__typename") == "MessageVideo":
|
||||||
yield VideoAttachment._from_list(i)
|
yield _file.VideoAttachment._from_list(i)
|
||||||
else:
|
else:
|
||||||
yield Attachment(id=i["node"].get("legacy_attachment_id"))
|
yield _attachment.Attachment(id=i["node"].get("legacy_attachment_id"))
|
||||||
del j[self.id]["message_shared_media"]["edges"][0]
|
del j[self.id]["message_shared_media"]["edges"][0]
|
||||||
|
|
||||||
def set_nickname(self, user_id: str, nickname: str):
|
def set_nickname(self, user_id: str, nickname: str):
|
||||||
@@ -385,8 +390,8 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
"title": name,
|
"title": name,
|
||||||
"thread_id": self.id,
|
"thread_id": self.id,
|
||||||
"location_id": location_id or "",
|
"location_id": location_id or "",
|
||||||
"location_name": location or "",
|
"location_name": location_name or "",
|
||||||
"acontext": ACONTEXT,
|
"acontext": _plan.ACONTEXT,
|
||||||
}
|
}
|
||||||
j = self.session._payload_post("/ajax/eventreminder/create", data)
|
j = self.session._payload_post("/ajax/eventreminder/create", data)
|
||||||
if "error" in j:
|
if "error" in j:
|
||||||
@@ -404,7 +409,9 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
# the POST parameters is badly implemented, and deals with ordering the options
|
# the POST parameters is badly implemented, and deals with ordering the options
|
||||||
# wrongly. If you can find a way to fix this for the endpoint, or if you find
|
# wrongly. If you can find a way to fix this for the endpoint, or if you find
|
||||||
# another endpoint, please do suggest it ;)
|
# another endpoint, please do suggest it ;)
|
||||||
data = OrderedDict([("question_text", question), ("target_id", self.id)])
|
data = collections.OrderedDict(
|
||||||
|
[("question_text", question), ("target_id", self.id)]
|
||||||
|
)
|
||||||
|
|
||||||
for i, (text, vote) in enumerate(options):
|
for i, (text, vote) in enumerate(options):
|
||||||
data["option_text_array[{}]".format(i)] = text
|
data["option_text_array[{}]".format(i)] = text
|
||||||
|
Reference in New Issue
Block a user