add thread color change
This commit is contained in:
@@ -52,6 +52,7 @@ LogoutURL ="https://www.facebook.com/logout.php"
|
||||
AllUsersURL ="https://www.facebook.com/chat/user_info_all"
|
||||
SaveDeviceURL="https://m.facebook.com/login/save-device/cancel/"
|
||||
CheckpointURL="https://m.facebook.com/login/checkpoint/"
|
||||
ChatColorURL="https://www.facebook.com/messaging/save_thread_color/?source=thread_settings&dpr=1"
|
||||
facebookEncoding = 'UTF-8'
|
||||
|
||||
# Log settings
|
||||
@@ -505,6 +506,7 @@ class Client(object):
|
||||
users.append(User(entry))
|
||||
return users # have bug TypeError: __repr__ returned non-string (type bytes)
|
||||
|
||||
|
||||
"""
|
||||
SEND METHODS
|
||||
"""
|
||||
@@ -612,7 +614,7 @@ class Client(object):
|
||||
:param thread_type: specify whether thread_id is user or group chat
|
||||
:return: a list of message ids of the sent message(s)
|
||||
"""
|
||||
data = self._getSendData(thread_id=thread_id, thread_type=ThreadType.GROUP)
|
||||
data = self._getSendData(thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
data['action_type'] = 'ma-type:user-generated-message'
|
||||
data['body'] = message or ''
|
||||
@@ -785,6 +787,22 @@ class Client(object):
|
||||
|
||||
return self._doSendRequest(data)
|
||||
|
||||
def changeThreadColor(self, new_color, thread_id=None, thread_type=None):
|
||||
# type: (ChatColor, str, ThreadType) -> bool
|
||||
if thread_id is None and self.def_thread_type == ThreadType.GROUP:
|
||||
thread_id = self.def_thread_id
|
||||
elif thread_id is None:
|
||||
raise ValueError('Default Thread ID is not set.')
|
||||
|
||||
data = {
|
||||
"color_choice": new_color.value,
|
||||
"thread_or_other_fbid": thread_id
|
||||
}
|
||||
|
||||
r = self._post(ChatColorURL, data)
|
||||
|
||||
return r.ok
|
||||
|
||||
"""
|
||||
END SEND METHODS
|
||||
"""
|
||||
@@ -1129,7 +1147,7 @@ class Client(object):
|
||||
self.onUnknownMesssageType(msg=m)
|
||||
|
||||
except Exception as e:
|
||||
self.onMessageError(exception=e, msg=msg)
|
||||
self.onMessageError(exception=e, msg=m)
|
||||
|
||||
|
||||
@deprecated(deprecated_in='0.10.2', details='Use startListening() instead')
|
||||
|
@@ -73,18 +73,9 @@ class TypingStatus(Enum):
|
||||
TYPING = 1
|
||||
|
||||
class EmojiSize(Enum):
|
||||
LARGE = {
|
||||
'value': '369239383222810',
|
||||
'name': 'large'
|
||||
}
|
||||
MEDIUM = {
|
||||
'value': '369239343222814',
|
||||
'name': 'medium'
|
||||
}
|
||||
SMALL = {
|
||||
'value': '369239263222822',
|
||||
'name': 'small'
|
||||
}
|
||||
LARGE = '369239383222810'
|
||||
MEDIUM = '369239343222814'
|
||||
SMALL = '369239263222822'
|
||||
|
||||
LIKES = {
|
||||
'l': EmojiSize.LARGE,
|
||||
@@ -94,3 +85,20 @@ LIKES = {
|
||||
LIKES['large'] = LIKES['l']
|
||||
LIKES['medium'] =LIKES['m']
|
||||
LIKES['small'] = LIKES['s']
|
||||
|
||||
class ChatColor(Enum):
|
||||
MESSENGER_BLUE = ''
|
||||
VIKING = '#44bec7'
|
||||
GOLDEN_POPPY = '#ffc300'
|
||||
RADICAL_RED = '#fa3c4c'
|
||||
SHOCKING = '#d696bb'
|
||||
PICTON_BLUE = '#6699cc'
|
||||
FREE_SPEECH_GREEN = '#13cf13'
|
||||
PUMPKIN = '#ff7e29'
|
||||
LIGHT_CORAL = '#e68585'
|
||||
MEDIUM_SLATE_BLUE = '#7646ff'
|
||||
DEEP_SKY_BLUE = '#20cef5'
|
||||
FERN = '#67b868'
|
||||
CAMEO = '#d4a88c'
|
||||
BRILLIANT_ROSE = '#ff5ca1'
|
||||
BILOBA_FLOWER = '#a695c7'
|
||||
|
42
tests.py
42
tests.py
@@ -18,14 +18,7 @@ logging.basicConfig(level=logging.INFO)
|
||||
Tests for fbchat
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
To use these tests, make a json file called test_data.json, put this example in it, and fill in the gaps:
|
||||
{
|
||||
"email": "example@email.com",
|
||||
"password": "example_password",
|
||||
"group_thread_id": 0,
|
||||
"user_thread_id": 0
|
||||
}
|
||||
or type this information manually in the terminal prompts.
|
||||
To use these tests fill in test_data.json or type this information manually in the terminal prompts.
|
||||
|
||||
- email: Your (or a test user's) email / phone number
|
||||
- password: Your (or a test user's) password
|
||||
@@ -83,10 +76,10 @@ class TestFbchat(unittest.TestCase):
|
||||
|
||||
# Test if values are set correctly
|
||||
self.assertIsInstance(u.uid, int)
|
||||
self.assertEquals(u.type, 'user')
|
||||
self.assertEquals(u.photo[:4], 'http')
|
||||
self.assertEquals(u.url[:4], 'http')
|
||||
self.assertEquals(u.name, 'Mark Zuckerberg')
|
||||
self.assertEqual(u.type, 'user')
|
||||
self.assertEqual(u.photo[:4], 'http')
|
||||
self.assertEqual(u.url[:4], 'http')
|
||||
self.assertEqual(u.name, 'Mark Zuckerberg')
|
||||
self.assertGreater(u.score, 0)
|
||||
|
||||
def test_sendEmoji(self):
|
||||
@@ -109,13 +102,13 @@ class TestFbchat(unittest.TestCase):
|
||||
# Idk why but doesnt work, payload is null
|
||||
self.assertTrue(client.sendLocalImage(image_local_url, 'test_send_group_images_local', user_uid, ThreadType.USER))
|
||||
self.assertTrue(client.sendLocalImage(image_local_url, 'test_send_group_images_local', group_uid, ThreadType.GROUP))
|
||||
|
||||
|
||||
def test_getThreadInfo(self):
|
||||
client.sendMessage('test_user_getThreadInfo', user_uid, ThreadType.USER)
|
||||
time.sleep(3)
|
||||
info = client.getThreadInfo(20, user_uid, ThreadType.USER)
|
||||
self.assertEquals(info[0].author, 'fbid:' + client.uid)
|
||||
self.assertEquals(info[0].body, 'test_user_getThreadInfo')
|
||||
self.assertEqual(info[0].author, 'fbid:' + client.uid)
|
||||
self.assertEqual(info[0].body, 'test_user_getThreadInfo')
|
||||
|
||||
client.sendMessage('test_group_getThreadInfo', group_uid, ThreadType.GROUP)
|
||||
time.sleep(3)
|
||||
@@ -141,6 +134,25 @@ class TestFbchat(unittest.TestCase):
|
||||
def test_changeThreadTitle(self):
|
||||
self.assertTrue(client.changeThreadTitle('test_changeThreadTitle', group_uid))
|
||||
|
||||
def test_changeThreadColor(self):
|
||||
self.assertTrue(client.changeThreadColor(ChatColor.BRILLIANT_ROSE, group_uid, ThreadType.GROUP))
|
||||
client.sendMessage(ChatColor.BRILLIANT_ROSE.name, group_uid, ThreadType.GROUP)
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
self.assertTrue(client.changeThreadColor(ChatColor.MESSENGER_BLUE, group_uid, ThreadType.GROUP))
|
||||
client.sendMessage(ChatColor.MESSENGER_BLUE.name, group_uid, ThreadType.GROUP)
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
self.assertTrue(client.changeThreadColor(ChatColor.BRILLIANT_ROSE, user_uid, ThreadType.USER))
|
||||
client.sendMessage(ChatColor.BRILLIANT_ROSE.name, user_uid, ThreadType.USER)
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
self.assertTrue(client.changeThreadColor(ChatColor.MESSENGER_BLUE, user_uid, ThreadType.USER))
|
||||
client.sendMessage(ChatColor.MESSENGER_BLUE.name, user_uid, ThreadType.USER)
|
||||
|
||||
|
||||
def start_test(param_client, param_group_uid, param_user_uid, tests=[]):
|
||||
global client
|
||||
|
Reference in New Issue
Block a user