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"
|
AllUsersURL ="https://www.facebook.com/chat/user_info_all"
|
||||||
SaveDeviceURL="https://m.facebook.com/login/save-device/cancel/"
|
SaveDeviceURL="https://m.facebook.com/login/save-device/cancel/"
|
||||||
CheckpointURL="https://m.facebook.com/login/checkpoint/"
|
CheckpointURL="https://m.facebook.com/login/checkpoint/"
|
||||||
|
ChatColorURL="https://www.facebook.com/messaging/save_thread_color/?source=thread_settings&dpr=1"
|
||||||
facebookEncoding = 'UTF-8'
|
facebookEncoding = 'UTF-8'
|
||||||
|
|
||||||
# Log settings
|
# Log settings
|
||||||
@@ -505,6 +506,7 @@ class Client(object):
|
|||||||
users.append(User(entry))
|
users.append(User(entry))
|
||||||
return users # have bug TypeError: __repr__ returned non-string (type bytes)
|
return users # have bug TypeError: __repr__ returned non-string (type bytes)
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
SEND METHODS
|
SEND METHODS
|
||||||
"""
|
"""
|
||||||
@@ -612,7 +614,7 @@ class Client(object):
|
|||||||
:param thread_type: specify whether thread_id is user or group chat
|
:param thread_type: specify whether thread_id is user or group chat
|
||||||
:return: a list of message ids of the sent message(s)
|
: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['action_type'] = 'ma-type:user-generated-message'
|
||||||
data['body'] = message or ''
|
data['body'] = message or ''
|
||||||
@@ -785,6 +787,22 @@ class Client(object):
|
|||||||
|
|
||||||
return self._doSendRequest(data)
|
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
|
END SEND METHODS
|
||||||
"""
|
"""
|
||||||
@@ -1129,7 +1147,7 @@ class Client(object):
|
|||||||
self.onUnknownMesssageType(msg=m)
|
self.onUnknownMesssageType(msg=m)
|
||||||
|
|
||||||
except Exception as e:
|
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')
|
@deprecated(deprecated_in='0.10.2', details='Use startListening() instead')
|
||||||
|
@@ -73,18 +73,9 @@ class TypingStatus(Enum):
|
|||||||
TYPING = 1
|
TYPING = 1
|
||||||
|
|
||||||
class EmojiSize(Enum):
|
class EmojiSize(Enum):
|
||||||
LARGE = {
|
LARGE = '369239383222810'
|
||||||
'value': '369239383222810',
|
MEDIUM = '369239343222814'
|
||||||
'name': 'large'
|
SMALL = '369239263222822'
|
||||||
}
|
|
||||||
MEDIUM = {
|
|
||||||
'value': '369239343222814',
|
|
||||||
'name': 'medium'
|
|
||||||
}
|
|
||||||
SMALL = {
|
|
||||||
'value': '369239263222822',
|
|
||||||
'name': 'small'
|
|
||||||
}
|
|
||||||
|
|
||||||
LIKES = {
|
LIKES = {
|
||||||
'l': EmojiSize.LARGE,
|
'l': EmojiSize.LARGE,
|
||||||
@@ -94,3 +85,20 @@ LIKES = {
|
|||||||
LIKES['large'] = LIKES['l']
|
LIKES['large'] = LIKES['l']
|
||||||
LIKES['medium'] =LIKES['m']
|
LIKES['medium'] =LIKES['m']
|
||||||
LIKES['small'] = LIKES['s']
|
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'
|
||||||
|
40
tests.py
40
tests.py
@@ -18,14 +18,7 @@ logging.basicConfig(level=logging.INFO)
|
|||||||
Tests for fbchat
|
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:
|
To use these tests fill in test_data.json or type this information manually in the terminal prompts.
|
||||||
{
|
|
||||||
"email": "example@email.com",
|
|
||||||
"password": "example_password",
|
|
||||||
"group_thread_id": 0,
|
|
||||||
"user_thread_id": 0
|
|
||||||
}
|
|
||||||
or type this information manually in the terminal prompts.
|
|
||||||
|
|
||||||
- email: Your (or a test user's) email / phone number
|
- email: Your (or a test user's) email / phone number
|
||||||
- password: Your (or a test user's) password
|
- password: Your (or a test user's) password
|
||||||
@@ -83,10 +76,10 @@ class TestFbchat(unittest.TestCase):
|
|||||||
|
|
||||||
# Test if values are set correctly
|
# Test if values are set correctly
|
||||||
self.assertIsInstance(u.uid, int)
|
self.assertIsInstance(u.uid, int)
|
||||||
self.assertEquals(u.type, 'user')
|
self.assertEqual(u.type, 'user')
|
||||||
self.assertEquals(u.photo[:4], 'http')
|
self.assertEqual(u.photo[:4], 'http')
|
||||||
self.assertEquals(u.url[:4], 'http')
|
self.assertEqual(u.url[:4], 'http')
|
||||||
self.assertEquals(u.name, 'Mark Zuckerberg')
|
self.assertEqual(u.name, 'Mark Zuckerberg')
|
||||||
self.assertGreater(u.score, 0)
|
self.assertGreater(u.score, 0)
|
||||||
|
|
||||||
def test_sendEmoji(self):
|
def test_sendEmoji(self):
|
||||||
@@ -114,8 +107,8 @@ class TestFbchat(unittest.TestCase):
|
|||||||
client.sendMessage('test_user_getThreadInfo', user_uid, ThreadType.USER)
|
client.sendMessage('test_user_getThreadInfo', user_uid, ThreadType.USER)
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
info = client.getThreadInfo(20, user_uid, ThreadType.USER)
|
info = client.getThreadInfo(20, user_uid, ThreadType.USER)
|
||||||
self.assertEquals(info[0].author, 'fbid:' + client.uid)
|
self.assertEqual(info[0].author, 'fbid:' + client.uid)
|
||||||
self.assertEquals(info[0].body, 'test_user_getThreadInfo')
|
self.assertEqual(info[0].body, 'test_user_getThreadInfo')
|
||||||
|
|
||||||
client.sendMessage('test_group_getThreadInfo', group_uid, ThreadType.GROUP)
|
client.sendMessage('test_group_getThreadInfo', group_uid, ThreadType.GROUP)
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
@@ -141,6 +134,25 @@ class TestFbchat(unittest.TestCase):
|
|||||||
def test_changeThreadTitle(self):
|
def test_changeThreadTitle(self):
|
||||||
self.assertTrue(client.changeThreadTitle('test_changeThreadTitle', group_uid))
|
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=[]):
|
def start_test(param_client, param_group_uid, param_user_uid, tests=[]):
|
||||||
global client
|
global client
|
||||||
|
Reference in New Issue
Block a user