diff --git a/fbchat/_client.py b/fbchat/_client.py index 47b23ed..a2841aa 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -956,7 +956,7 @@ class Client: Raises: FBchatException: If request failed """ - thread = thread_type._to_class()(thread_id) + thread = thread_type._to_class()(uid=thread_id) data = thread._to_send_data() data.update(message._to_send_data()) return self._do_send_request(data) @@ -975,7 +975,7 @@ class Client: Raises: FBchatException: If request failed """ - thread = thread_type._to_class()(thread_id) + thread = thread_type._to_class()(uid=thread_id) data = thread._to_send_data() data["action_type"] = "ma-type:user-generated-message" data["lightweight_action_attachment[lwa_state]"] = ( @@ -1050,7 +1050,7 @@ class Client: def _send_location( self, location, current=True, message=None, thread_id=None, thread_type=None ): - thread = thread_type._to_class()(thread_id) + thread = thread_type._to_class()(uid=thread_id) data = thread._to_send_data() if message is not None: data.update(message._to_send_data()) @@ -1118,7 +1118,7 @@ class Client: `files` should be a list of tuples, with a file's ID and mimetype. """ - thread = thread_type._to_class()(thread_id) + thread = thread_type._to_class()(uid=thread_id) data = thread._to_send_data() data.update(self._old_message(message)._to_send_data()) data["action_type"] = "ma-type:user-generated-message" @@ -1284,7 +1284,7 @@ class Client: Raises: FBchatException: If request failed """ - data = Group(thread_id)._to_send_data() + data = Group(uid=thread_id)._to_send_data() data["action_type"] = "ma-type:log-message" data["log_message_type"] = "log:subscribe" diff --git a/fbchat/_core.py b/fbchat/_core.py index ae7ecb1..1827198 100644 --- a/fbchat/_core.py +++ b/fbchat/_core.py @@ -1,11 +1,15 @@ +import sys import attr import logging import aenum log = logging.getLogger("fbchat") +# Enable kw_only if the python version supports it +kw_only = sys.version_info[:2] > (3, 5) + #: Default attrs settings for classes -attrs_default = attr.s(slots=True) # TODO: Add kw_only=True +attrs_default = attr.s(slots=True, kw_only=kw_only) class Enum(aenum.Enum): @@ -27,7 +31,7 @@ class Enum(aenum.Enum): return cls(value) -@attr.s(frozen=True, slots=True) # TODO: Add kw_only=True +@attr.s(frozen=True, slots=True, kw_only=kw_only) class Image: #: URL to the image url = attr.ib(type=str) diff --git a/fbchat/_group.py b/fbchat/_group.py index bb73b2c..eef0b0a 100644 --- a/fbchat/_group.py +++ b/fbchat/_group.py @@ -42,7 +42,7 @@ class Group(Thread): plan = _plan.Plan._from_graphql(data["event_reminders"]["nodes"][0]) return cls( - data["thread_key"]["thread_fbid"], + uid=data["thread_key"]["thread_fbid"], participants=set( [ node["messaging_actor"]["id"] diff --git a/fbchat/_message.py b/fbchat/_message.py index ef0c7c8..87c928d 100644 --- a/fbchat/_message.py +++ b/fbchat/_message.py @@ -236,7 +236,7 @@ class Message: text=data["message"].get("text"), mentions=[ Mention( - m.get("entity", {}).get("id"), + thread_id=m.get("entity", {}).get("id"), offset=m.get("offset"), length=m.get("length"), ) @@ -295,7 +295,7 @@ class Message: return cls( text=data.get("body"), mentions=[ - Mention(m.get("i"), offset=m.get("o"), length=m.get("l")) + Mention(thread_id=m.get("i"), offset=m.get("o"), length=m.get("l")) for m in json.loads(data.get("data", {}).get("prng", "[]")) ], emoji_size=EmojiSize._from_tags(tags), @@ -318,7 +318,7 @@ class Message: try: mentions = [ Mention( - str(mention.get("i")), + thread_id=str(mention.get("i")), offset=mention.get("o"), length=mention.get("l"), ) diff --git a/fbchat/_page.py b/fbchat/_page.py index aceb88b..e675df8 100644 --- a/fbchat/_page.py +++ b/fbchat/_page.py @@ -32,7 +32,7 @@ class Page(Thread): plan = _plan.Plan._from_graphql(data["event_reminders"]["nodes"][0]) return cls( - data["id"], + uid=data["id"], url=data.get("url"), city=data.get("city").get("name"), category=data.get("category_type"), diff --git a/fbchat/_state.py b/fbchat/_state.py index 78092fd..9f69a16 100644 --- a/fbchat/_state.py +++ b/fbchat/_state.py @@ -98,7 +98,7 @@ def _2fa_helper(session, code, r): return r -@attrs_default # TODO i Python 3: Add kw_only=True +@attrs_default class State: """Stores and manages state required for most Facebook requests.""" diff --git a/fbchat/_user.py b/fbchat/_user.py index 18dd773..5071c38 100644 --- a/fbchat/_user.py +++ b/fbchat/_user.py @@ -78,7 +78,7 @@ class User(Thread): plan = _plan.Plan._from_graphql(data["event_reminders"]["nodes"][0]) return cls( - data["id"], + uid=data["id"], url=data.get("url"), first_name=data.get("first_name"), last_name=data.get("last_name"), @@ -123,7 +123,7 @@ class User(Thread): plan = _plan.Plan._from_graphql(data["event_reminders"]["nodes"][0]) return cls( - user["id"], + uid=user["id"], url=user.get("url"), name=user.get("name"), first_name=first_name, @@ -144,7 +144,7 @@ class User(Thread): @classmethod def _from_all_fetch(cls, data): return cls( - data["id"], + uid=data["id"], first_name=data.get("firstName"), url=data.get("uri"), photo=Image(url=data.get("thumbSrc")), diff --git a/tests/test_plans.py b/tests/test_plans.py index 12807ee..411f576 100644 --- a/tests/test_plans.py +++ b/tests/test_plans.py @@ -10,12 +10,12 @@ pytestmark = pytest.mark.online @pytest.fixture( scope="module", params=[ - Plan(int(time()) + 100, random_hex()), + Plan(time=int(time()) + 100, title=random_hex()), pytest.param( - Plan(int(time()), random_hex()), + Plan(time=int(time()), title=random_hex()), marks=[pytest.mark.xfail(raises=FBchatFacebookError)], ), - pytest.param(Plan(0, None), marks=[pytest.mark.xfail()]), + pytest.param(Plan(time=0, title=None), marks=[pytest.mark.xfail()]), ], ) def plan_data(request, client, user, thread, catch_event, compare): diff --git a/tests/test_polls.py b/tests/test_polls.py index 94210b4..f45724e 100644 --- a/tests/test_polls.py +++ b/tests/test_polls.py @@ -13,26 +13,26 @@ pytestmark = pytest.mark.online Poll( title=random_hex(), options=[ - PollOption(random_hex(), vote=True), - PollOption(random_hex(), vote=True), + PollOption(text=random_hex(), vote=True), + PollOption(text=random_hex(), vote=True), ], ), Poll( title=random_hex(), options=[ - PollOption(random_hex(), vote=False), - PollOption(random_hex(), vote=False), + PollOption(text=random_hex(), vote=False), + PollOption(text=random_hex(), vote=False), ], ), Poll( title=random_hex(), options=[ - PollOption(random_hex(), vote=True), - PollOption(random_hex(), vote=True), - PollOption(random_hex(), vote=False), - PollOption(random_hex(), vote=False), - PollOption(random_hex()), - PollOption(random_hex()), + PollOption(text=random_hex(), vote=True), + PollOption(text=random_hex(), vote=True), + PollOption(text=random_hex(), vote=False), + PollOption(text=random_hex(), vote=False), + PollOption(text=random_hex()), + PollOption(text=random_hex()), ], ), pytest.param( diff --git a/tests/utils.py b/tests/utils.py index 93e762b..64ec01c 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -22,9 +22,13 @@ EMOJI_LIST = [ ] STICKER_LIST = [ - Sticker("767334476626295"), - pytest.param(Sticker("0"), marks=[pytest.mark.xfail(raises=FBchatFacebookError)]), - pytest.param(Sticker(None), marks=[pytest.mark.xfail(raises=FBchatFacebookError)]), + Sticker(uid="767334476626295"), + pytest.param( + Sticker(uid="0"), marks=[pytest.mark.xfail(raises=FBchatFacebookError)] + ), + pytest.param( + Sticker(uid=None), marks=[pytest.mark.xfail(raises=FBchatFacebookError)] + ), ] TEXT_LIST = [