Add unfinished NewGroup helper class
This commit is contained in:
@@ -1158,34 +1158,6 @@ class Client:
|
|||||||
fb_error_message=j["error"],
|
fb_error_message=j["error"],
|
||||||
)
|
)
|
||||||
|
|
||||||
def create_group(self, message, user_ids):
|
|
||||||
"""Create a group with the given user ids.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
message: The initial message
|
|
||||||
user_ids: A list of users to create the group with.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
ID of the new group
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
FBchatException: If request failed
|
|
||||||
"""
|
|
||||||
data = self._old_message(message)._to_send_data()
|
|
||||||
|
|
||||||
if len(user_ids) < 2:
|
|
||||||
raise ValueError("Error when creating group: Not enough participants")
|
|
||||||
|
|
||||||
for i, user_id in enumerate(user_ids + [self._session.user_id]):
|
|
||||||
data["specific_to_list[{}]".format(i)] = "fbid:{}".format(user_id)
|
|
||||||
|
|
||||||
message_id, thread_id = self._do_send_request(data, get_thread_id=True)
|
|
||||||
if not thread_id:
|
|
||||||
raise FBchatException(
|
|
||||||
"Error when creating group: No thread_id could be found"
|
|
||||||
)
|
|
||||||
return thread_id
|
|
||||||
|
|
||||||
def change_thread_title(self, title, thread_id=None, thread_type=ThreadType.USER):
|
def change_thread_title(self, title, thread_id=None, thread_type=ThreadType.USER):
|
||||||
"""Change title of a thread.
|
"""Change title of a thread.
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import attr
|
import attr
|
||||||
from ._core import attrs_default, Image
|
from ._core import attrs_default, Image
|
||||||
from . import _util, _session, _plan, _thread
|
from . import _util, _session, _plan, _thread, _user
|
||||||
from typing import Iterable
|
from typing import Sequence, Iterable
|
||||||
|
|
||||||
|
|
||||||
@attrs_default
|
@attrs_default
|
||||||
@@ -197,3 +197,32 @@ class Group(_thread.ThreadABC):
|
|||||||
|
|
||||||
def _to_send_data(self):
|
def _to_send_data(self):
|
||||||
return {"thread_fbid": self.id}
|
return {"thread_fbid": self.id}
|
||||||
|
|
||||||
|
|
||||||
|
@attrs_default
|
||||||
|
class NewGroup(_thread.ThreadABC):
|
||||||
|
"""Helper class to create new groups.
|
||||||
|
|
||||||
|
TODO: Complete this!
|
||||||
|
|
||||||
|
Construct this class with the desired users, and call a method like `wave`, to...
|
||||||
|
"""
|
||||||
|
|
||||||
|
#: The session to use when making requests.
|
||||||
|
session = attr.ib(type=_session.Session)
|
||||||
|
#: The users that should be added to the group.
|
||||||
|
_users = attr.ib(type=Sequence[_user.User])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def id(self):
|
||||||
|
raise NotImplementedError(
|
||||||
|
"The method you called is not supported on NewGroup objects."
|
||||||
|
" Please use the supported methods to create the group, before attempting"
|
||||||
|
" to call the method."
|
||||||
|
)
|
||||||
|
|
||||||
|
def _to_send_data(self) -> dict:
|
||||||
|
return {
|
||||||
|
"specific_to_list[{}]".format(i): "fbid:{}".format(user.id)
|
||||||
|
for i, user in enumerate(self._users)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user