id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
234,100 | CodeReclaimers/neat-python | neat/genome.py | DefaultGenome.connect_full_direct | def connect_full_direct(self, config):
""" Create a fully-connected genome, including direct input-output connections. """
for input_id, output_id in self.compute_full_connections(config, True):
connection = self.create_connection(config, input_id, output_id)
self.connections[connection.key] = connection | python | def connect_full_direct(self, config):
for input_id, output_id in self.compute_full_connections(config, True):
connection = self.create_connection(config, input_id, output_id)
self.connections[connection.key] = connection | [
"def",
"connect_full_direct",
"(",
"self",
",",
"config",
")",
":",
"for",
"input_id",
",",
"output_id",
"in",
"self",
".",
"compute_full_connections",
"(",
"config",
",",
"True",
")",
":",
"connection",
"=",
"self",
".",
"create_connection",
"(",
"config",
... | Create a fully-connected genome, including direct input-output connections. | [
"Create",
"a",
"fully",
"-",
"connected",
"genome",
"including",
"direct",
"input",
"-",
"output",
"connections",
"."
] | e3dbe77c0d776eae41d598e6439e6ac02ab90b18 | https://github.com/CodeReclaimers/neat-python/blob/e3dbe77c0d776eae41d598e6439e6ac02ab90b18/neat/genome.py#L541-L545 |
234,101 | CodeReclaimers/neat-python | neat/config.py | ConfigParameter.interpret | def interpret(self, config_dict):
"""
Converts the config_parser output into the proper type,
supplies defaults if available and needed, and checks for some errors.
"""
value = config_dict.get(self.name)
if value is None:
if self.default is None:
raise RuntimeError('Missing configuration item: ' + self.name)
else:
warnings.warn("Using default {!r} for '{!s}'".format(self.default, self.name),
DeprecationWarning)
if (str != self.value_type) and isinstance(self.default, self.value_type):
return self.default
else:
value = self.default
try:
if str == self.value_type:
return str(value)
if int == self.value_type:
return int(value)
if bool == self.value_type:
if value.lower() == "true":
return True
elif value.lower() == "false":
return False
else:
raise RuntimeError(self.name + " must be True or False")
if float == self.value_type:
return float(value)
if list == self.value_type:
return value.split(" ")
except Exception:
raise RuntimeError("Error interpreting config item '{}' with value {!r} and type {}".format(
self.name, value, self.value_type))
raise RuntimeError("Unexpected configuration type: " + repr(self.value_type)) | python | def interpret(self, config_dict):
value = config_dict.get(self.name)
if value is None:
if self.default is None:
raise RuntimeError('Missing configuration item: ' + self.name)
else:
warnings.warn("Using default {!r} for '{!s}'".format(self.default, self.name),
DeprecationWarning)
if (str != self.value_type) and isinstance(self.default, self.value_type):
return self.default
else:
value = self.default
try:
if str == self.value_type:
return str(value)
if int == self.value_type:
return int(value)
if bool == self.value_type:
if value.lower() == "true":
return True
elif value.lower() == "false":
return False
else:
raise RuntimeError(self.name + " must be True or False")
if float == self.value_type:
return float(value)
if list == self.value_type:
return value.split(" ")
except Exception:
raise RuntimeError("Error interpreting config item '{}' with value {!r} and type {}".format(
self.name, value, self.value_type))
raise RuntimeError("Unexpected configuration type: " + repr(self.value_type)) | [
"def",
"interpret",
"(",
"self",
",",
"config_dict",
")",
":",
"value",
"=",
"config_dict",
".",
"get",
"(",
"self",
".",
"name",
")",
"if",
"value",
"is",
"None",
":",
"if",
"self",
".",
"default",
"is",
"None",
":",
"raise",
"RuntimeError",
"(",
"'... | Converts the config_parser output into the proper type,
supplies defaults if available and needed, and checks for some errors. | [
"Converts",
"the",
"config_parser",
"output",
"into",
"the",
"proper",
"type",
"supplies",
"defaults",
"if",
"available",
"and",
"needed",
"and",
"checks",
"for",
"some",
"errors",
"."
] | e3dbe77c0d776eae41d598e6439e6ac02ab90b18 | https://github.com/CodeReclaimers/neat-python/blob/e3dbe77c0d776eae41d598e6439e6ac02ab90b18/neat/config.py#L47-L84 |
234,102 | CodeReclaimers/neat-python | examples/xor/visualize.py | plot_spikes | def plot_spikes(spikes, view=False, filename=None, title=None):
""" Plots the trains for a single spiking neuron. """
t_values = [t for t, I, v, u, f in spikes]
v_values = [v for t, I, v, u, f in spikes]
u_values = [u for t, I, v, u, f in spikes]
I_values = [I for t, I, v, u, f in spikes]
f_values = [f for t, I, v, u, f in spikes]
fig = plt.figure()
plt.subplot(4, 1, 1)
plt.ylabel("Potential (mv)")
plt.xlabel("Time (in ms)")
plt.grid()
plt.plot(t_values, v_values, "g-")
if title is None:
plt.title("Izhikevich's spiking neuron model")
else:
plt.title("Izhikevich's spiking neuron model ({0!s})".format(title))
plt.subplot(4, 1, 2)
plt.ylabel("Fired")
plt.xlabel("Time (in ms)")
plt.grid()
plt.plot(t_values, f_values, "r-")
plt.subplot(4, 1, 3)
plt.ylabel("Recovery (u)")
plt.xlabel("Time (in ms)")
plt.grid()
plt.plot(t_values, u_values, "r-")
plt.subplot(4, 1, 4)
plt.ylabel("Current (I)")
plt.xlabel("Time (in ms)")
plt.grid()
plt.plot(t_values, I_values, "r-o")
if filename is not None:
plt.savefig(filename)
if view:
plt.show()
plt.close()
fig = None
return fig | python | def plot_spikes(spikes, view=False, filename=None, title=None):
t_values = [t for t, I, v, u, f in spikes]
v_values = [v for t, I, v, u, f in spikes]
u_values = [u for t, I, v, u, f in spikes]
I_values = [I for t, I, v, u, f in spikes]
f_values = [f for t, I, v, u, f in spikes]
fig = plt.figure()
plt.subplot(4, 1, 1)
plt.ylabel("Potential (mv)")
plt.xlabel("Time (in ms)")
plt.grid()
plt.plot(t_values, v_values, "g-")
if title is None:
plt.title("Izhikevich's spiking neuron model")
else:
plt.title("Izhikevich's spiking neuron model ({0!s})".format(title))
plt.subplot(4, 1, 2)
plt.ylabel("Fired")
plt.xlabel("Time (in ms)")
plt.grid()
plt.plot(t_values, f_values, "r-")
plt.subplot(4, 1, 3)
plt.ylabel("Recovery (u)")
plt.xlabel("Time (in ms)")
plt.grid()
plt.plot(t_values, u_values, "r-")
plt.subplot(4, 1, 4)
plt.ylabel("Current (I)")
plt.xlabel("Time (in ms)")
plt.grid()
plt.plot(t_values, I_values, "r-o")
if filename is not None:
plt.savefig(filename)
if view:
plt.show()
plt.close()
fig = None
return fig | [
"def",
"plot_spikes",
"(",
"spikes",
",",
"view",
"=",
"False",
",",
"filename",
"=",
"None",
",",
"title",
"=",
"None",
")",
":",
"t_values",
"=",
"[",
"t",
"for",
"t",
",",
"I",
",",
"v",
",",
"u",
",",
"f",
"in",
"spikes",
"]",
"v_values",
"... | Plots the trains for a single spiking neuron. | [
"Plots",
"the",
"trains",
"for",
"a",
"single",
"spiking",
"neuron",
"."
] | e3dbe77c0d776eae41d598e6439e6ac02ab90b18 | https://github.com/CodeReclaimers/neat-python/blob/e3dbe77c0d776eae41d598e6439e6ac02ab90b18/examples/xor/visualize.py#L42-L88 |
234,103 | carpedm20/fbchat | fbchat/_client.py | Client.isLoggedIn | def isLoggedIn(self):
"""
Sends a request to Facebook to check the login status
:return: True if the client is still logged in
:rtype: bool
"""
# Send a request to the login url, to see if we're directed to the home page
r = self._cleanGet(self.req_url.LOGIN, allow_redirects=False)
return "Location" in r.headers and "home" in r.headers["Location"] | python | def isLoggedIn(self):
# Send a request to the login url, to see if we're directed to the home page
r = self._cleanGet(self.req_url.LOGIN, allow_redirects=False)
return "Location" in r.headers and "home" in r.headers["Location"] | [
"def",
"isLoggedIn",
"(",
"self",
")",
":",
"# Send a request to the login url, to see if we're directed to the home page",
"r",
"=",
"self",
".",
"_cleanGet",
"(",
"self",
".",
"req_url",
".",
"LOGIN",
",",
"allow_redirects",
"=",
"False",
")",
"return",
"\"Location\... | Sends a request to Facebook to check the login status
:return: True if the client is still logged in
:rtype: bool | [
"Sends",
"a",
"request",
"to",
"Facebook",
"to",
"check",
"the",
"login",
"status"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L426-L435 |
234,104 | carpedm20/fbchat | fbchat/_client.py | Client.setSession | def setSession(self, session_cookies):
"""Loads session cookies
:param session_cookies: A dictionay containing session cookies
:type session_cookies: dict
:return: False if `session_cookies` does not contain proper cookies
:rtype: bool
"""
# Quick check to see if session_cookies is formatted properly
if not session_cookies or "c_user" not in session_cookies:
return False
try:
# Load cookies into current session
self._session.cookies = requests.cookies.merge_cookies(
self._session.cookies, session_cookies
)
self._postLogin()
except Exception as e:
log.exception("Failed loading session")
self._resetValues()
return False
return True | python | def setSession(self, session_cookies):
# Quick check to see if session_cookies is formatted properly
if not session_cookies or "c_user" not in session_cookies:
return False
try:
# Load cookies into current session
self._session.cookies = requests.cookies.merge_cookies(
self._session.cookies, session_cookies
)
self._postLogin()
except Exception as e:
log.exception("Failed loading session")
self._resetValues()
return False
return True | [
"def",
"setSession",
"(",
"self",
",",
"session_cookies",
")",
":",
"# Quick check to see if session_cookies is formatted properly",
"if",
"not",
"session_cookies",
"or",
"\"c_user\"",
"not",
"in",
"session_cookies",
":",
"return",
"False",
"try",
":",
"# Load cookies int... | Loads session cookies
:param session_cookies: A dictionay containing session cookies
:type session_cookies: dict
:return: False if `session_cookies` does not contain proper cookies
:rtype: bool | [
"Loads",
"session",
"cookies"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L445-L467 |
234,105 | carpedm20/fbchat | fbchat/_client.py | Client.logout | def logout(self):
"""
Safely logs out the client
:param timeout: See `requests timeout <http://docs.python-requests.org/en/master/user/advanced/#timeouts>`_
:return: True if the action was successful
:rtype: bool
"""
if not hasattr(self, "_fb_h"):
h_r = self._post(self.req_url.MODERN_SETTINGS_MENU, {"pmid": "4"})
self._fb_h = re.search(r'name=\\"h\\" value=\\"(.*?)\\"', h_r.text).group(1)
data = {"ref": "mb", "h": self._fb_h}
r = self._get(self.req_url.LOGOUT, data)
self._resetValues()
return r.ok | python | def logout(self):
if not hasattr(self, "_fb_h"):
h_r = self._post(self.req_url.MODERN_SETTINGS_MENU, {"pmid": "4"})
self._fb_h = re.search(r'name=\\"h\\" value=\\"(.*?)\\"', h_r.text).group(1)
data = {"ref": "mb", "h": self._fb_h}
r = self._get(self.req_url.LOGOUT, data)
self._resetValues()
return r.ok | [
"def",
"logout",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"_fb_h\"",
")",
":",
"h_r",
"=",
"self",
".",
"_post",
"(",
"self",
".",
"req_url",
".",
"MODERN_SETTINGS_MENU",
",",
"{",
"\"pmid\"",
":",
"\"4\"",
"}",
")",
"self",... | Safely logs out the client
:param timeout: See `requests timeout <http://docs.python-requests.org/en/master/user/advanced/#timeouts>`_
:return: True if the action was successful
:rtype: bool | [
"Safely",
"logs",
"out",
"the",
"client"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L506-L524 |
234,106 | carpedm20/fbchat | fbchat/_client.py | Client._getThread | def _getThread(self, given_thread_id=None, given_thread_type=None):
"""
Checks if thread ID is given, checks if default is set and returns correct values
:raises ValueError: If thread ID is not given and there is no default
:return: Thread ID and thread type
:rtype: tuple
"""
if given_thread_id is None:
if self._default_thread_id is not None:
return self._default_thread_id, self._default_thread_type
else:
raise ValueError("Thread ID is not set")
else:
return given_thread_id, given_thread_type | python | def _getThread(self, given_thread_id=None, given_thread_type=None):
if given_thread_id is None:
if self._default_thread_id is not None:
return self._default_thread_id, self._default_thread_type
else:
raise ValueError("Thread ID is not set")
else:
return given_thread_id, given_thread_type | [
"def",
"_getThread",
"(",
"self",
",",
"given_thread_id",
"=",
"None",
",",
"given_thread_type",
"=",
"None",
")",
":",
"if",
"given_thread_id",
"is",
"None",
":",
"if",
"self",
".",
"_default_thread_id",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_... | Checks if thread ID is given, checks if default is set and returns correct values
:raises ValueError: If thread ID is not given and there is no default
:return: Thread ID and thread type
:rtype: tuple | [
"Checks",
"if",
"thread",
"ID",
"is",
"given",
"checks",
"if",
"default",
"is",
"set",
"and",
"returns",
"correct",
"values"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L534-L548 |
234,107 | carpedm20/fbchat | fbchat/_client.py | Client.setDefaultThread | def setDefaultThread(self, thread_id, thread_type):
"""
Sets default thread to send messages to
:param thread_id: User/Group ID to default to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
"""
self._default_thread_id = thread_id
self._default_thread_type = thread_type | python | def setDefaultThread(self, thread_id, thread_type):
self._default_thread_id = thread_id
self._default_thread_type = thread_type | [
"def",
"setDefaultThread",
"(",
"self",
",",
"thread_id",
",",
"thread_type",
")",
":",
"self",
".",
"_default_thread_id",
"=",
"thread_id",
"self",
".",
"_default_thread_type",
"=",
"thread_type"
] | Sets default thread to send messages to
:param thread_id: User/Group ID to default to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType | [
"Sets",
"default",
"thread",
"to",
"send",
"messages",
"to"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L550-L559 |
234,108 | carpedm20/fbchat | fbchat/_client.py | Client.fetchThreads | def fetchThreads(self, thread_location, before=None, after=None, limit=None):
"""
Get all threads in thread_location.
Threads will be sorted from newest to oldest.
:param thread_location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER
:param before: Fetch only thread before this epoch (in ms) (default all threads)
:param after: Fetch only thread after this epoch (in ms) (default all threads)
:param limit: The max. amount of threads to fetch (default all threads)
:return: :class:`models.Thread` objects
:rtype: list
:raises: FBchatException if request failed
"""
threads = []
last_thread_timestamp = None
while True:
# break if limit is exceeded
if limit and len(threads) >= limit:
break
# fetchThreadList returns at max 20 threads before last_thread_timestamp (included)
candidates = self.fetchThreadList(
before=last_thread_timestamp, thread_location=thread_location
)
if len(candidates) > 1:
threads += candidates[1:]
else: # End of threads
break
last_thread_timestamp = threads[-1].last_message_timestamp
# FB returns a sorted list of threads
if (before is not None and int(last_thread_timestamp) > before) or (
after is not None and int(last_thread_timestamp) < after
):
break
# Return only threads between before and after (if set)
if before is not None or after is not None:
for t in threads:
last_message_timestamp = int(t.last_message_timestamp)
if (before is not None and last_message_timestamp > before) or (
after is not None and last_message_timestamp < after
):
threads.remove(t)
if limit and len(threads) > limit:
return threads[:limit]
return threads | python | def fetchThreads(self, thread_location, before=None, after=None, limit=None):
threads = []
last_thread_timestamp = None
while True:
# break if limit is exceeded
if limit and len(threads) >= limit:
break
# fetchThreadList returns at max 20 threads before last_thread_timestamp (included)
candidates = self.fetchThreadList(
before=last_thread_timestamp, thread_location=thread_location
)
if len(candidates) > 1:
threads += candidates[1:]
else: # End of threads
break
last_thread_timestamp = threads[-1].last_message_timestamp
# FB returns a sorted list of threads
if (before is not None and int(last_thread_timestamp) > before) or (
after is not None and int(last_thread_timestamp) < after
):
break
# Return only threads between before and after (if set)
if before is not None or after is not None:
for t in threads:
last_message_timestamp = int(t.last_message_timestamp)
if (before is not None and last_message_timestamp > before) or (
after is not None and last_message_timestamp < after
):
threads.remove(t)
if limit and len(threads) > limit:
return threads[:limit]
return threads | [
"def",
"fetchThreads",
"(",
"self",
",",
"thread_location",
",",
"before",
"=",
"None",
",",
"after",
"=",
"None",
",",
"limit",
"=",
"None",
")",
":",
"threads",
"=",
"[",
"]",
"last_thread_timestamp",
"=",
"None",
"while",
"True",
":",
"# break if limit ... | Get all threads in thread_location.
Threads will be sorted from newest to oldest.
:param thread_location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER
:param before: Fetch only thread before this epoch (in ms) (default all threads)
:param after: Fetch only thread after this epoch (in ms) (default all threads)
:param limit: The max. amount of threads to fetch (default all threads)
:return: :class:`models.Thread` objects
:rtype: list
:raises: FBchatException if request failed | [
"Get",
"all",
"threads",
"in",
"thread_location",
".",
"Threads",
"will",
"be",
"sorted",
"from",
"newest",
"to",
"oldest",
"."
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L577-L628 |
234,109 | carpedm20/fbchat | fbchat/_client.py | Client.fetchAllUsersFromThreads | def fetchAllUsersFromThreads(self, threads):
"""
Get all users involved in threads.
:param threads: models.Thread: List of threads to check for users
:return: :class:`models.User` objects
:rtype: list
:raises: FBchatException if request failed
"""
users = []
users_to_fetch = [] # It's more efficient to fetch all users in one request
for thread in threads:
if thread.type == ThreadType.USER:
if thread.uid not in [user.uid for user in users]:
users.append(thread)
elif thread.type == ThreadType.GROUP:
for user_id in thread.participants:
if (
user_id not in [user.uid for user in users]
and user_id not in users_to_fetch
):
users_to_fetch.append(user_id)
for user_id, user in self.fetchUserInfo(*users_to_fetch).items():
users.append(user)
return users | python | def fetchAllUsersFromThreads(self, threads):
users = []
users_to_fetch = [] # It's more efficient to fetch all users in one request
for thread in threads:
if thread.type == ThreadType.USER:
if thread.uid not in [user.uid for user in users]:
users.append(thread)
elif thread.type == ThreadType.GROUP:
for user_id in thread.participants:
if (
user_id not in [user.uid for user in users]
and user_id not in users_to_fetch
):
users_to_fetch.append(user_id)
for user_id, user in self.fetchUserInfo(*users_to_fetch).items():
users.append(user)
return users | [
"def",
"fetchAllUsersFromThreads",
"(",
"self",
",",
"threads",
")",
":",
"users",
"=",
"[",
"]",
"users_to_fetch",
"=",
"[",
"]",
"# It's more efficient to fetch all users in one request",
"for",
"thread",
"in",
"threads",
":",
"if",
"thread",
".",
"type",
"==",
... | Get all users involved in threads.
:param threads: models.Thread: List of threads to check for users
:return: :class:`models.User` objects
:rtype: list
:raises: FBchatException if request failed | [
"Get",
"all",
"users",
"involved",
"in",
"threads",
"."
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L630-L654 |
234,110 | carpedm20/fbchat | fbchat/_client.py | Client.fetchAllUsers | def fetchAllUsers(self):
"""
Gets all users the client is currently chatting with
:return: :class:`models.User` objects
:rtype: list
:raises: FBchatException if request failed
"""
data = {"viewer": self._uid}
j = self._post(
self.req_url.ALL_USERS, query=data, fix_request=True, as_json=True
)
if j.get("payload") is None:
raise FBchatException("Missing payload while fetching users: {}".format(j))
users = []
for data in j["payload"].values():
if data["type"] in ["user", "friend"]:
if data["id"] in ["0", 0]:
# Skip invalid users
continue
users.append(User._from_all_fetch(data))
return users | python | def fetchAllUsers(self):
data = {"viewer": self._uid}
j = self._post(
self.req_url.ALL_USERS, query=data, fix_request=True, as_json=True
)
if j.get("payload") is None:
raise FBchatException("Missing payload while fetching users: {}".format(j))
users = []
for data in j["payload"].values():
if data["type"] in ["user", "friend"]:
if data["id"] in ["0", 0]:
# Skip invalid users
continue
users.append(User._from_all_fetch(data))
return users | [
"def",
"fetchAllUsers",
"(",
"self",
")",
":",
"data",
"=",
"{",
"\"viewer\"",
":",
"self",
".",
"_uid",
"}",
"j",
"=",
"self",
".",
"_post",
"(",
"self",
".",
"req_url",
".",
"ALL_USERS",
",",
"query",
"=",
"data",
",",
"fix_request",
"=",
"True",
... | Gets all users the client is currently chatting with
:return: :class:`models.User` objects
:rtype: list
:raises: FBchatException if request failed | [
"Gets",
"all",
"users",
"the",
"client",
"is",
"currently",
"chatting",
"with"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L656-L678 |
234,111 | carpedm20/fbchat | fbchat/_client.py | Client.searchForPages | def searchForPages(self, name, limit=10):
"""
Find and get page by its name
:param name: Name of the page
:return: :class:`models.Page` objects, ordered by relevance
:rtype: list
:raises: FBchatException if request failed
"""
params = {"search": name, "limit": limit}
j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_PAGE, params=params))
return [Page._from_graphql(node) for node in j[name]["pages"]["nodes"]] | python | def searchForPages(self, name, limit=10):
params = {"search": name, "limit": limit}
j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_PAGE, params=params))
return [Page._from_graphql(node) for node in j[name]["pages"]["nodes"]] | [
"def",
"searchForPages",
"(",
"self",
",",
"name",
",",
"limit",
"=",
"10",
")",
":",
"params",
"=",
"{",
"\"search\"",
":",
"name",
",",
"\"limit\"",
":",
"limit",
"}",
"j",
"=",
"self",
".",
"graphql_request",
"(",
"GraphQL",
"(",
"query",
"=",
"Gr... | Find and get page by its name
:param name: Name of the page
:return: :class:`models.Page` objects, ordered by relevance
:rtype: list
:raises: FBchatException if request failed | [
"Find",
"and",
"get",
"page",
"by",
"its",
"name"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L695-L707 |
234,112 | carpedm20/fbchat | fbchat/_client.py | Client.searchForGroups | def searchForGroups(self, name, limit=10):
"""
Find and get group thread by its name
:param name: Name of the group thread
:param limit: The max. amount of groups to fetch
:return: :class:`models.Group` objects, ordered by relevance
:rtype: list
:raises: FBchatException if request failed
"""
params = {"search": name, "limit": limit}
j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_GROUP, params=params))
return [Group._from_graphql(node) for node in j["viewer"]["groups"]["nodes"]] | python | def searchForGroups(self, name, limit=10):
params = {"search": name, "limit": limit}
j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_GROUP, params=params))
return [Group._from_graphql(node) for node in j["viewer"]["groups"]["nodes"]] | [
"def",
"searchForGroups",
"(",
"self",
",",
"name",
",",
"limit",
"=",
"10",
")",
":",
"params",
"=",
"{",
"\"search\"",
":",
"name",
",",
"\"limit\"",
":",
"limit",
"}",
"j",
"=",
"self",
".",
"graphql_request",
"(",
"GraphQL",
"(",
"query",
"=",
"G... | Find and get group thread by its name
:param name: Name of the group thread
:param limit: The max. amount of groups to fetch
:return: :class:`models.Group` objects, ordered by relevance
:rtype: list
:raises: FBchatException if request failed | [
"Find",
"and",
"get",
"group",
"thread",
"by",
"its",
"name"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L709-L722 |
234,113 | carpedm20/fbchat | fbchat/_client.py | Client.searchForThreads | def searchForThreads(self, name, limit=10):
"""
Find and get a thread by its name
:param name: Name of the thread
:param limit: The max. amount of groups to fetch
:return: :class:`models.User`, :class:`models.Group` and :class:`models.Page` objects, ordered by relevance
:rtype: list
:raises: FBchatException if request failed
"""
params = {"search": name, "limit": limit}
j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_THREAD, params=params))
rtn = []
for node in j[name]["threads"]["nodes"]:
if node["__typename"] == "User":
rtn.append(User._from_graphql(node))
elif node["__typename"] == "MessageThread":
# MessageThread => Group thread
rtn.append(Group._from_graphql(node))
elif node["__typename"] == "Page":
rtn.append(Page._from_graphql(node))
elif node["__typename"] == "Group":
# We don't handle Facebook "Groups"
pass
else:
log.warning(
"Unknown type {} in {}".format(repr(node["__typename"]), node)
)
return rtn | python | def searchForThreads(self, name, limit=10):
params = {"search": name, "limit": limit}
j = self.graphql_request(GraphQL(query=GraphQL.SEARCH_THREAD, params=params))
rtn = []
for node in j[name]["threads"]["nodes"]:
if node["__typename"] == "User":
rtn.append(User._from_graphql(node))
elif node["__typename"] == "MessageThread":
# MessageThread => Group thread
rtn.append(Group._from_graphql(node))
elif node["__typename"] == "Page":
rtn.append(Page._from_graphql(node))
elif node["__typename"] == "Group":
# We don't handle Facebook "Groups"
pass
else:
log.warning(
"Unknown type {} in {}".format(repr(node["__typename"]), node)
)
return rtn | [
"def",
"searchForThreads",
"(",
"self",
",",
"name",
",",
"limit",
"=",
"10",
")",
":",
"params",
"=",
"{",
"\"search\"",
":",
"name",
",",
"\"limit\"",
":",
"limit",
"}",
"j",
"=",
"self",
".",
"graphql_request",
"(",
"GraphQL",
"(",
"query",
"=",
"... | Find and get a thread by its name
:param name: Name of the thread
:param limit: The max. amount of groups to fetch
:return: :class:`models.User`, :class:`models.Group` and :class:`models.Page` objects, ordered by relevance
:rtype: list
:raises: FBchatException if request failed | [
"Find",
"and",
"get",
"a",
"thread",
"by",
"its",
"name"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L724-L754 |
234,114 | carpedm20/fbchat | fbchat/_client.py | Client.searchForMessageIDs | def searchForMessageIDs(self, query, offset=0, limit=5, thread_id=None):
"""
Find and get message IDs by query
:param query: Text to search for
:param offset: Number of messages to skip
:param limit: Max. number of messages to retrieve
:param thread_id: User/Group ID to search in. See :ref:`intro_threads`
:type offset: int
:type limit: int
:return: Found Message IDs
:rtype: generator
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, None)
data = {
"query": query,
"snippetOffset": offset,
"snippetLimit": limit,
"identifier": "thread_fbid",
"thread_fbid": thread_id,
}
j = self._post(
self.req_url.SEARCH_MESSAGES, data, fix_request=True, as_json=True
)
result = j["payload"]["search_snippets"][query]
snippets = result[thread_id]["snippets"] if result.get(thread_id) else []
for snippet in snippets:
yield snippet["message_id"] | python | def searchForMessageIDs(self, query, offset=0, limit=5, thread_id=None):
thread_id, thread_type = self._getThread(thread_id, None)
data = {
"query": query,
"snippetOffset": offset,
"snippetLimit": limit,
"identifier": "thread_fbid",
"thread_fbid": thread_id,
}
j = self._post(
self.req_url.SEARCH_MESSAGES, data, fix_request=True, as_json=True
)
result = j["payload"]["search_snippets"][query]
snippets = result[thread_id]["snippets"] if result.get(thread_id) else []
for snippet in snippets:
yield snippet["message_id"] | [
"def",
"searchForMessageIDs",
"(",
"self",
",",
"query",
",",
"offset",
"=",
"0",
",",
"limit",
"=",
"5",
",",
"thread_id",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"None",
")",
"dat... | Find and get message IDs by query
:param query: Text to search for
:param offset: Number of messages to skip
:param limit: Max. number of messages to retrieve
:param thread_id: User/Group ID to search in. See :ref:`intro_threads`
:type offset: int
:type limit: int
:return: Found Message IDs
:rtype: generator
:raises: FBchatException if request failed | [
"Find",
"and",
"get",
"message",
"IDs",
"by",
"query"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L756-L786 |
234,115 | carpedm20/fbchat | fbchat/_client.py | Client.search | def search(self, query, fetch_messages=False, thread_limit=5, message_limit=5):
"""
Searches for messages in all threads
:param query: Text to search for
:param fetch_messages: Whether to fetch :class:`models.Message` objects or IDs only
:param thread_limit: Max. number of threads to retrieve
:param message_limit: Max. number of messages to retrieve
:type thread_limit: int
:type message_limit: int
:return: Dictionary with thread IDs as keys and generators to get messages as values
:rtype: generator
:raises: FBchatException if request failed
"""
data = {"query": query, "snippetLimit": thread_limit}
j = self._post(
self.req_url.SEARCH_MESSAGES, data, fix_request=True, as_json=True
)
result = j["payload"]["search_snippets"][query]
if fetch_messages:
search_method = self.searchForMessages
else:
search_method = self.searchForMessageIDs
return {
thread_id: search_method(query, limit=message_limit, thread_id=thread_id)
for thread_id in result
} | python | def search(self, query, fetch_messages=False, thread_limit=5, message_limit=5):
data = {"query": query, "snippetLimit": thread_limit}
j = self._post(
self.req_url.SEARCH_MESSAGES, data, fix_request=True, as_json=True
)
result = j["payload"]["search_snippets"][query]
if fetch_messages:
search_method = self.searchForMessages
else:
search_method = self.searchForMessageIDs
return {
thread_id: search_method(query, limit=message_limit, thread_id=thread_id)
for thread_id in result
} | [
"def",
"search",
"(",
"self",
",",
"query",
",",
"fetch_messages",
"=",
"False",
",",
"thread_limit",
"=",
"5",
",",
"message_limit",
"=",
"5",
")",
":",
"data",
"=",
"{",
"\"query\"",
":",
"query",
",",
"\"snippetLimit\"",
":",
"thread_limit",
"}",
"j",... | Searches for messages in all threads
:param query: Text to search for
:param fetch_messages: Whether to fetch :class:`models.Message` objects or IDs only
:param thread_limit: Max. number of threads to retrieve
:param message_limit: Max. number of messages to retrieve
:type thread_limit: int
:type message_limit: int
:return: Dictionary with thread IDs as keys and generators to get messages as values
:rtype: generator
:raises: FBchatException if request failed | [
"Searches",
"for",
"messages",
"in",
"all",
"threads"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L811-L839 |
234,116 | carpedm20/fbchat | fbchat/_client.py | Client.fetchUserInfo | def fetchUserInfo(self, *user_ids):
"""
Get users' info from IDs, unordered
.. warning::
Sends two requests, to fetch all available info!
:param user_ids: One or more user ID(s) to query
:return: :class:`models.User` objects, labeled by their ID
:rtype: dict
:raises: FBchatException if request failed
"""
threads = self.fetchThreadInfo(*user_ids)
users = {}
for id_, thread in threads.items():
if thread.type == ThreadType.USER:
users[id_] = thread
else:
raise FBchatUserError("Thread {} was not a user".format(thread))
return users | python | def fetchUserInfo(self, *user_ids):
threads = self.fetchThreadInfo(*user_ids)
users = {}
for id_, thread in threads.items():
if thread.type == ThreadType.USER:
users[id_] = thread
else:
raise FBchatUserError("Thread {} was not a user".format(thread))
return users | [
"def",
"fetchUserInfo",
"(",
"self",
",",
"*",
"user_ids",
")",
":",
"threads",
"=",
"self",
".",
"fetchThreadInfo",
"(",
"*",
"user_ids",
")",
"users",
"=",
"{",
"}",
"for",
"id_",
",",
"thread",
"in",
"threads",
".",
"items",
"(",
")",
":",
"if",
... | Get users' info from IDs, unordered
.. warning::
Sends two requests, to fetch all available info!
:param user_ids: One or more user ID(s) to query
:return: :class:`models.User` objects, labeled by their ID
:rtype: dict
:raises: FBchatException if request failed | [
"Get",
"users",
"info",
"from",
"IDs",
"unordered"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L878-L898 |
234,117 | carpedm20/fbchat | fbchat/_client.py | Client.fetchPageInfo | def fetchPageInfo(self, *page_ids):
"""
Get pages' info from IDs, unordered
.. warning::
Sends two requests, to fetch all available info!
:param page_ids: One or more page ID(s) to query
:return: :class:`models.Page` objects, labeled by their ID
:rtype: dict
:raises: FBchatException if request failed
"""
threads = self.fetchThreadInfo(*page_ids)
pages = {}
for id_, thread in threads.items():
if thread.type == ThreadType.PAGE:
pages[id_] = thread
else:
raise FBchatUserError("Thread {} was not a page".format(thread))
return pages | python | def fetchPageInfo(self, *page_ids):
threads = self.fetchThreadInfo(*page_ids)
pages = {}
for id_, thread in threads.items():
if thread.type == ThreadType.PAGE:
pages[id_] = thread
else:
raise FBchatUserError("Thread {} was not a page".format(thread))
return pages | [
"def",
"fetchPageInfo",
"(",
"self",
",",
"*",
"page_ids",
")",
":",
"threads",
"=",
"self",
".",
"fetchThreadInfo",
"(",
"*",
"page_ids",
")",
"pages",
"=",
"{",
"}",
"for",
"id_",
",",
"thread",
"in",
"threads",
".",
"items",
"(",
")",
":",
"if",
... | Get pages' info from IDs, unordered
.. warning::
Sends two requests, to fetch all available info!
:param page_ids: One or more page ID(s) to query
:return: :class:`models.Page` objects, labeled by their ID
:rtype: dict
:raises: FBchatException if request failed | [
"Get",
"pages",
"info",
"from",
"IDs",
"unordered"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L900-L920 |
234,118 | carpedm20/fbchat | fbchat/_client.py | Client.fetchGroupInfo | def fetchGroupInfo(self, *group_ids):
"""
Get groups' info from IDs, unordered
:param group_ids: One or more group ID(s) to query
:return: :class:`models.Group` objects, labeled by their ID
:rtype: dict
:raises: FBchatException if request failed
"""
threads = self.fetchThreadInfo(*group_ids)
groups = {}
for id_, thread in threads.items():
if thread.type == ThreadType.GROUP:
groups[id_] = thread
else:
raise FBchatUserError("Thread {} was not a group".format(thread))
return groups | python | def fetchGroupInfo(self, *group_ids):
threads = self.fetchThreadInfo(*group_ids)
groups = {}
for id_, thread in threads.items():
if thread.type == ThreadType.GROUP:
groups[id_] = thread
else:
raise FBchatUserError("Thread {} was not a group".format(thread))
return groups | [
"def",
"fetchGroupInfo",
"(",
"self",
",",
"*",
"group_ids",
")",
":",
"threads",
"=",
"self",
".",
"fetchThreadInfo",
"(",
"*",
"group_ids",
")",
"groups",
"=",
"{",
"}",
"for",
"id_",
",",
"thread",
"in",
"threads",
".",
"items",
"(",
")",
":",
"if... | Get groups' info from IDs, unordered
:param group_ids: One or more group ID(s) to query
:return: :class:`models.Group` objects, labeled by their ID
:rtype: dict
:raises: FBchatException if request failed | [
"Get",
"groups",
"info",
"from",
"IDs",
"unordered"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L922-L939 |
234,119 | carpedm20/fbchat | fbchat/_client.py | Client.fetchThreadInfo | def fetchThreadInfo(self, *thread_ids):
"""
Get threads' info from IDs, unordered
.. warning::
Sends two requests if users or pages are present, to fetch all available info!
:param thread_ids: One or more thread ID(s) to query
:return: :class:`models.Thread` objects, labeled by their ID
:rtype: dict
:raises: FBchatException if request failed
"""
queries = []
for thread_id in thread_ids:
params = {
"id": thread_id,
"message_limit": 0,
"load_messages": False,
"load_read_receipts": False,
"before": None,
}
queries.append(GraphQL(doc_id="2147762685294928", params=params))
j = self.graphql_requests(*queries)
for i, entry in enumerate(j):
if entry.get("message_thread") is None:
# If you don't have an existing thread with this person, attempt to retrieve user data anyways
j[i]["message_thread"] = {
"thread_key": {"other_user_id": thread_ids[i]},
"thread_type": "ONE_TO_ONE",
}
pages_and_user_ids = [
k["message_thread"]["thread_key"]["other_user_id"]
for k in j
if k["message_thread"].get("thread_type") == "ONE_TO_ONE"
]
pages_and_users = {}
if len(pages_and_user_ids) != 0:
pages_and_users = self._fetchInfo(*pages_and_user_ids)
rtn = {}
for i, entry in enumerate(j):
entry = entry["message_thread"]
if entry.get("thread_type") == "GROUP":
_id = entry["thread_key"]["thread_fbid"]
rtn[_id] = Group._from_graphql(entry)
elif entry.get("thread_type") == "ONE_TO_ONE":
_id = entry["thread_key"]["other_user_id"]
if pages_and_users.get(_id) is None:
raise FBchatException("Could not fetch thread {}".format(_id))
entry.update(pages_and_users[_id])
if entry["type"] == ThreadType.USER:
rtn[_id] = User._from_graphql(entry)
else:
rtn[_id] = Page._from_graphql(entry)
else:
raise FBchatException(
"{} had an unknown thread type: {}".format(thread_ids[i], entry)
)
return rtn | python | def fetchThreadInfo(self, *thread_ids):
queries = []
for thread_id in thread_ids:
params = {
"id": thread_id,
"message_limit": 0,
"load_messages": False,
"load_read_receipts": False,
"before": None,
}
queries.append(GraphQL(doc_id="2147762685294928", params=params))
j = self.graphql_requests(*queries)
for i, entry in enumerate(j):
if entry.get("message_thread") is None:
# If you don't have an existing thread with this person, attempt to retrieve user data anyways
j[i]["message_thread"] = {
"thread_key": {"other_user_id": thread_ids[i]},
"thread_type": "ONE_TO_ONE",
}
pages_and_user_ids = [
k["message_thread"]["thread_key"]["other_user_id"]
for k in j
if k["message_thread"].get("thread_type") == "ONE_TO_ONE"
]
pages_and_users = {}
if len(pages_and_user_ids) != 0:
pages_and_users = self._fetchInfo(*pages_and_user_ids)
rtn = {}
for i, entry in enumerate(j):
entry = entry["message_thread"]
if entry.get("thread_type") == "GROUP":
_id = entry["thread_key"]["thread_fbid"]
rtn[_id] = Group._from_graphql(entry)
elif entry.get("thread_type") == "ONE_TO_ONE":
_id = entry["thread_key"]["other_user_id"]
if pages_and_users.get(_id) is None:
raise FBchatException("Could not fetch thread {}".format(_id))
entry.update(pages_and_users[_id])
if entry["type"] == ThreadType.USER:
rtn[_id] = User._from_graphql(entry)
else:
rtn[_id] = Page._from_graphql(entry)
else:
raise FBchatException(
"{} had an unknown thread type: {}".format(thread_ids[i], entry)
)
return rtn | [
"def",
"fetchThreadInfo",
"(",
"self",
",",
"*",
"thread_ids",
")",
":",
"queries",
"=",
"[",
"]",
"for",
"thread_id",
"in",
"thread_ids",
":",
"params",
"=",
"{",
"\"id\"",
":",
"thread_id",
",",
"\"message_limit\"",
":",
"0",
",",
"\"load_messages\"",
":... | Get threads' info from IDs, unordered
.. warning::
Sends two requests if users or pages are present, to fetch all available info!
:param thread_ids: One or more thread ID(s) to query
:return: :class:`models.Thread` objects, labeled by their ID
:rtype: dict
:raises: FBchatException if request failed | [
"Get",
"threads",
"info",
"from",
"IDs",
"unordered"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L941-L1003 |
234,120 | carpedm20/fbchat | fbchat/_client.py | Client.fetchThreadMessages | def fetchThreadMessages(self, thread_id=None, limit=20, before=None):
"""
Get the last messages in a thread
:param thread_id: User/Group ID to get messages from. See :ref:`intro_threads`
:param limit: Max. number of messages to retrieve
:param before: A timestamp, indicating from which point to retrieve messages
:type limit: int
:type before: int
:return: :class:`models.Message` objects
:rtype: list
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, None)
params = {
"id": thread_id,
"message_limit": limit,
"load_messages": True,
"load_read_receipts": True,
"before": before,
}
j = self.graphql_request(GraphQL(doc_id="1860982147341344", params=params))
if j.get("message_thread") is None:
raise FBchatException("Could not fetch thread {}: {}".format(thread_id, j))
messages = [
Message._from_graphql(message)
for message in j["message_thread"]["messages"]["nodes"]
]
messages.reverse()
read_receipts = j["message_thread"]["read_receipts"]["nodes"]
for message in messages:
for receipt in read_receipts:
if int(receipt["watermark"]) >= int(message.timestamp):
message.read_by.append(receipt["actor"]["id"])
return messages | python | def fetchThreadMessages(self, thread_id=None, limit=20, before=None):
thread_id, thread_type = self._getThread(thread_id, None)
params = {
"id": thread_id,
"message_limit": limit,
"load_messages": True,
"load_read_receipts": True,
"before": before,
}
j = self.graphql_request(GraphQL(doc_id="1860982147341344", params=params))
if j.get("message_thread") is None:
raise FBchatException("Could not fetch thread {}: {}".format(thread_id, j))
messages = [
Message._from_graphql(message)
for message in j["message_thread"]["messages"]["nodes"]
]
messages.reverse()
read_receipts = j["message_thread"]["read_receipts"]["nodes"]
for message in messages:
for receipt in read_receipts:
if int(receipt["watermark"]) >= int(message.timestamp):
message.read_by.append(receipt["actor"]["id"])
return messages | [
"def",
"fetchThreadMessages",
"(",
"self",
",",
"thread_id",
"=",
"None",
",",
"limit",
"=",
"20",
",",
"before",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"None",
")",
"params",
"=",
... | Get the last messages in a thread
:param thread_id: User/Group ID to get messages from. See :ref:`intro_threads`
:param limit: Max. number of messages to retrieve
:param before: A timestamp, indicating from which point to retrieve messages
:type limit: int
:type before: int
:return: :class:`models.Message` objects
:rtype: list
:raises: FBchatException if request failed | [
"Get",
"the",
"last",
"messages",
"in",
"a",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1005-L1045 |
234,121 | carpedm20/fbchat | fbchat/_client.py | Client.fetchThreadList | def fetchThreadList(
self, offset=None, limit=20, thread_location=ThreadLocation.INBOX, before=None
):
"""Get thread list of your facebook account
:param offset: Deprecated. Do not use!
:param limit: Max. number of threads to retrieve. Capped at 20
:param thread_location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER
:param before: A timestamp (in milliseconds), indicating from which point to retrieve threads
:type limit: int
:type before: int
:return: :class:`models.Thread` objects
:rtype: list
:raises: FBchatException if request failed
"""
if offset is not None:
log.warning(
"Using `offset` in `fetchThreadList` is no longer supported, "
"since Facebook migrated to the use of GraphQL in this request. "
"Use `before` instead."
)
if limit > 20 or limit < 1:
raise FBchatUserError("`limit` should be between 1 and 20")
if thread_location in ThreadLocation:
loc_str = thread_location.value
else:
raise FBchatUserError('"thread_location" must be a value of ThreadLocation')
params = {
"limit": limit,
"tags": [loc_str],
"before": before,
"includeDeliveryReceipts": True,
"includeSeqID": False,
}
j = self.graphql_request(GraphQL(doc_id="1349387578499440", params=params))
rtn = []
for node in j["viewer"]["message_threads"]["nodes"]:
_type = node.get("thread_type")
if _type == "GROUP":
rtn.append(Group._from_graphql(node))
elif _type == "ONE_TO_ONE":
rtn.append(User._from_thread_fetch(node))
else:
raise FBchatException(
"Unknown thread type: {}, with data: {}".format(_type, node)
)
return rtn | python | def fetchThreadList(
self, offset=None, limit=20, thread_location=ThreadLocation.INBOX, before=None
):
if offset is not None:
log.warning(
"Using `offset` in `fetchThreadList` is no longer supported, "
"since Facebook migrated to the use of GraphQL in this request. "
"Use `before` instead."
)
if limit > 20 or limit < 1:
raise FBchatUserError("`limit` should be between 1 and 20")
if thread_location in ThreadLocation:
loc_str = thread_location.value
else:
raise FBchatUserError('"thread_location" must be a value of ThreadLocation')
params = {
"limit": limit,
"tags": [loc_str],
"before": before,
"includeDeliveryReceipts": True,
"includeSeqID": False,
}
j = self.graphql_request(GraphQL(doc_id="1349387578499440", params=params))
rtn = []
for node in j["viewer"]["message_threads"]["nodes"]:
_type = node.get("thread_type")
if _type == "GROUP":
rtn.append(Group._from_graphql(node))
elif _type == "ONE_TO_ONE":
rtn.append(User._from_thread_fetch(node))
else:
raise FBchatException(
"Unknown thread type: {}, with data: {}".format(_type, node)
)
return rtn | [
"def",
"fetchThreadList",
"(",
"self",
",",
"offset",
"=",
"None",
",",
"limit",
"=",
"20",
",",
"thread_location",
"=",
"ThreadLocation",
".",
"INBOX",
",",
"before",
"=",
"None",
")",
":",
"if",
"offset",
"is",
"not",
"None",
":",
"log",
".",
"warnin... | Get thread list of your facebook account
:param offset: Deprecated. Do not use!
:param limit: Max. number of threads to retrieve. Capped at 20
:param thread_location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER
:param before: A timestamp (in milliseconds), indicating from which point to retrieve threads
:type limit: int
:type before: int
:return: :class:`models.Thread` objects
:rtype: list
:raises: FBchatException if request failed | [
"Get",
"thread",
"list",
"of",
"your",
"facebook",
"account"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1047-L1097 |
234,122 | carpedm20/fbchat | fbchat/_client.py | Client.fetchUnread | def fetchUnread(self):
"""
Get the unread thread list
:return: List of unread thread ids
:rtype: list
:raises: FBchatException if request failed
"""
form = {
"folders[0]": "inbox",
"client": "mercury",
"last_action_timestamp": now() - 60 * 1000
# 'last_action_timestamp': 0
}
j = self._post(
self.req_url.UNREAD_THREADS, form, fix_request=True, as_json=True
)
payload = j["payload"]["unread_thread_fbids"][0]
return payload["thread_fbids"] + payload["other_user_fbids"] | python | def fetchUnread(self):
form = {
"folders[0]": "inbox",
"client": "mercury",
"last_action_timestamp": now() - 60 * 1000
# 'last_action_timestamp': 0
}
j = self._post(
self.req_url.UNREAD_THREADS, form, fix_request=True, as_json=True
)
payload = j["payload"]["unread_thread_fbids"][0]
return payload["thread_fbids"] + payload["other_user_fbids"] | [
"def",
"fetchUnread",
"(",
"self",
")",
":",
"form",
"=",
"{",
"\"folders[0]\"",
":",
"\"inbox\"",
",",
"\"client\"",
":",
"\"mercury\"",
",",
"\"last_action_timestamp\"",
":",
"now",
"(",
")",
"-",
"60",
"*",
"1000",
"# 'last_action_timestamp': 0",
"}",
"j",
... | Get the unread thread list
:return: List of unread thread ids
:rtype: list
:raises: FBchatException if request failed | [
"Get",
"the",
"unread",
"thread",
"list"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1099-L1118 |
234,123 | carpedm20/fbchat | fbchat/_client.py | Client.fetchImageUrl | def fetchImageUrl(self, image_id):
"""Fetches the url to the original image from an image attachment ID
:param image_id: The image you want to fethc
:type image_id: str
:return: An url where you can download the original image
:rtype: str
:raises: FBchatException if request failed
"""
image_id = str(image_id)
data = {"photo_id": str(image_id)}
j = self._get(
ReqUrl.ATTACHMENT_PHOTO, query=data, fix_request=True, as_json=True
)
url = get_jsmods_require(j, 3)
if url is None:
raise FBchatException("Could not fetch image url from: {}".format(j))
return url | python | def fetchImageUrl(self, image_id):
image_id = str(image_id)
data = {"photo_id": str(image_id)}
j = self._get(
ReqUrl.ATTACHMENT_PHOTO, query=data, fix_request=True, as_json=True
)
url = get_jsmods_require(j, 3)
if url is None:
raise FBchatException("Could not fetch image url from: {}".format(j))
return url | [
"def",
"fetchImageUrl",
"(",
"self",
",",
"image_id",
")",
":",
"image_id",
"=",
"str",
"(",
"image_id",
")",
"data",
"=",
"{",
"\"photo_id\"",
":",
"str",
"(",
"image_id",
")",
"}",
"j",
"=",
"self",
".",
"_get",
"(",
"ReqUrl",
".",
"ATTACHMENT_PHOTO"... | Fetches the url to the original image from an image attachment ID
:param image_id: The image you want to fethc
:type image_id: str
:return: An url where you can download the original image
:rtype: str
:raises: FBchatException if request failed | [
"Fetches",
"the",
"url",
"to",
"the",
"original",
"image",
"from",
"an",
"image",
"attachment",
"ID"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1135-L1153 |
234,124 | carpedm20/fbchat | fbchat/_client.py | Client._getSendData | def _getSendData(self, message=None, thread_id=None, thread_type=ThreadType.USER):
"""Returns the data needed to send a request to `SendURL`"""
messageAndOTID = generateOfflineThreadingID()
timestamp = now()
data = {
"client": "mercury",
"author": "fbid:{}".format(self._uid),
"timestamp": timestamp,
"source": "source:chat:web",
"offline_threading_id": messageAndOTID,
"message_id": messageAndOTID,
"threading_id": generateMessageID(self._client_id),
"ephemeral_ttl_mode:": "0",
}
# Set recipient
if thread_type in [ThreadType.USER, ThreadType.PAGE]:
data["other_user_fbid"] = thread_id
elif thread_type == ThreadType.GROUP:
data["thread_fbid"] = thread_id
if message is None:
message = Message()
if message.text or message.sticker or message.emoji_size:
data["action_type"] = "ma-type:user-generated-message"
if message.text:
data["body"] = message.text
for i, mention in enumerate(message.mentions):
data["profile_xmd[{}][id]".format(i)] = mention.thread_id
data["profile_xmd[{}][offset]".format(i)] = mention.offset
data["profile_xmd[{}][length]".format(i)] = mention.length
data["profile_xmd[{}][type]".format(i)] = "p"
if message.emoji_size:
if message.text:
data["tags[0]"] = "hot_emoji_size:" + message.emoji_size.name.lower()
else:
data["sticker_id"] = message.emoji_size.value
if message.sticker:
data["sticker_id"] = message.sticker.uid
if message.quick_replies:
xmd = {"quick_replies": []}
for quick_reply in message.quick_replies:
q = dict()
q["content_type"] = quick_reply._type
q["payload"] = quick_reply.payload
q["external_payload"] = quick_reply.external_payload
q["data"] = quick_reply.data
if quick_reply.is_response:
q["ignore_for_webhook"] = False
if isinstance(quick_reply, QuickReplyText):
q["title"] = quick_reply.title
if not isinstance(quick_reply, QuickReplyLocation):
q["image_url"] = quick_reply.image_url
xmd["quick_replies"].append(q)
if len(message.quick_replies) == 1 and message.quick_replies[0].is_response:
xmd["quick_replies"] = xmd["quick_replies"][0]
data["platform_xmd"] = json.dumps(xmd)
if message.reply_to_id:
data["replied_to_message_id"] = message.reply_to_id
return data | python | def _getSendData(self, message=None, thread_id=None, thread_type=ThreadType.USER):
messageAndOTID = generateOfflineThreadingID()
timestamp = now()
data = {
"client": "mercury",
"author": "fbid:{}".format(self._uid),
"timestamp": timestamp,
"source": "source:chat:web",
"offline_threading_id": messageAndOTID,
"message_id": messageAndOTID,
"threading_id": generateMessageID(self._client_id),
"ephemeral_ttl_mode:": "0",
}
# Set recipient
if thread_type in [ThreadType.USER, ThreadType.PAGE]:
data["other_user_fbid"] = thread_id
elif thread_type == ThreadType.GROUP:
data["thread_fbid"] = thread_id
if message is None:
message = Message()
if message.text or message.sticker or message.emoji_size:
data["action_type"] = "ma-type:user-generated-message"
if message.text:
data["body"] = message.text
for i, mention in enumerate(message.mentions):
data["profile_xmd[{}][id]".format(i)] = mention.thread_id
data["profile_xmd[{}][offset]".format(i)] = mention.offset
data["profile_xmd[{}][length]".format(i)] = mention.length
data["profile_xmd[{}][type]".format(i)] = "p"
if message.emoji_size:
if message.text:
data["tags[0]"] = "hot_emoji_size:" + message.emoji_size.name.lower()
else:
data["sticker_id"] = message.emoji_size.value
if message.sticker:
data["sticker_id"] = message.sticker.uid
if message.quick_replies:
xmd = {"quick_replies": []}
for quick_reply in message.quick_replies:
q = dict()
q["content_type"] = quick_reply._type
q["payload"] = quick_reply.payload
q["external_payload"] = quick_reply.external_payload
q["data"] = quick_reply.data
if quick_reply.is_response:
q["ignore_for_webhook"] = False
if isinstance(quick_reply, QuickReplyText):
q["title"] = quick_reply.title
if not isinstance(quick_reply, QuickReplyLocation):
q["image_url"] = quick_reply.image_url
xmd["quick_replies"].append(q)
if len(message.quick_replies) == 1 and message.quick_replies[0].is_response:
xmd["quick_replies"] = xmd["quick_replies"][0]
data["platform_xmd"] = json.dumps(xmd)
if message.reply_to_id:
data["replied_to_message_id"] = message.reply_to_id
return data | [
"def",
"_getSendData",
"(",
"self",
",",
"message",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
")",
":",
"messageAndOTID",
"=",
"generateOfflineThreadingID",
"(",
")",
"timestamp",
"=",
"now",
"(",
")",
... | Returns the data needed to send a request to `SendURL` | [
"Returns",
"the",
"data",
"needed",
"to",
"send",
"a",
"request",
"to",
"SendURL"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1247-L1314 |
234,125 | carpedm20/fbchat | fbchat/_client.py | Client._doSendRequest | def _doSendRequest(self, data, get_thread_id=False):
"""Sends the data to `SendURL`, and returns the message ID or None on failure"""
j = self._post(self.req_url.SEND, data, fix_request=True, as_json=True)
# update JS token if received in response
fb_dtsg = get_jsmods_require(j, 2)
if fb_dtsg is not None:
self._payload_default["fb_dtsg"] = fb_dtsg
try:
message_ids = [
(action["message_id"], action["thread_fbid"])
for action in j["payload"]["actions"]
if "message_id" in action
]
if len(message_ids) != 1:
log.warning("Got multiple message ids' back: {}".format(message_ids))
if get_thread_id:
return message_ids[0]
else:
return message_ids[0][0]
except (KeyError, IndexError, TypeError) as e:
raise FBchatException(
"Error when sending message: "
"No message IDs could be found: {}".format(j)
) | python | def _doSendRequest(self, data, get_thread_id=False):
j = self._post(self.req_url.SEND, data, fix_request=True, as_json=True)
# update JS token if received in response
fb_dtsg = get_jsmods_require(j, 2)
if fb_dtsg is not None:
self._payload_default["fb_dtsg"] = fb_dtsg
try:
message_ids = [
(action["message_id"], action["thread_fbid"])
for action in j["payload"]["actions"]
if "message_id" in action
]
if len(message_ids) != 1:
log.warning("Got multiple message ids' back: {}".format(message_ids))
if get_thread_id:
return message_ids[0]
else:
return message_ids[0][0]
except (KeyError, IndexError, TypeError) as e:
raise FBchatException(
"Error when sending message: "
"No message IDs could be found: {}".format(j)
) | [
"def",
"_doSendRequest",
"(",
"self",
",",
"data",
",",
"get_thread_id",
"=",
"False",
")",
":",
"j",
"=",
"self",
".",
"_post",
"(",
"self",
".",
"req_url",
".",
"SEND",
",",
"data",
",",
"fix_request",
"=",
"True",
",",
"as_json",
"=",
"True",
")",... | Sends the data to `SendURL`, and returns the message ID or None on failure | [
"Sends",
"the",
"data",
"to",
"SendURL",
"and",
"returns",
"the",
"message",
"ID",
"or",
"None",
"on",
"failure"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1316-L1341 |
234,126 | carpedm20/fbchat | fbchat/_client.py | Client.send | def send(self, message, thread_id=None, thread_type=ThreadType.USER):
"""
Sends a message to a thread
:param message: Message to send
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type message: models.Message
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, thread_type)
data = self._getSendData(
message=message, thread_id=thread_id, thread_type=thread_type
)
return self._doSendRequest(data) | python | def send(self, message, thread_id=None, thread_type=ThreadType.USER):
thread_id, thread_type = self._getThread(thread_id, thread_type)
data = self._getSendData(
message=message, thread_id=thread_id, thread_type=thread_type
)
return self._doSendRequest(data) | [
"def",
"send",
"(",
"self",
",",
"message",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"thread_type",
")",
"data",
"... | Sends a message to a thread
:param message: Message to send
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type message: models.Message
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed | [
"Sends",
"a",
"message",
"to",
"a",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1343-L1359 |
234,127 | carpedm20/fbchat | fbchat/_client.py | Client.wave | def wave(self, wave_first=True, thread_id=None, thread_type=None):
"""
Says hello with a wave to a thread!
:param wave_first: Whether to wave first or wave back
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, thread_type)
data = self._getSendData(thread_id=thread_id, thread_type=thread_type)
data["action_type"] = "ma-type:user-generated-message"
data["lightweight_action_attachment[lwa_state]"] = (
"INITIATED" if wave_first else "RECIPROCATED"
)
data["lightweight_action_attachment[lwa_type]"] = "WAVE"
if thread_type == ThreadType.USER:
data["specific_to_list[0]"] = "fbid:{}".format(thread_id)
return self._doSendRequest(data) | python | def wave(self, wave_first=True, thread_id=None, thread_type=None):
thread_id, thread_type = self._getThread(thread_id, thread_type)
data = self._getSendData(thread_id=thread_id, thread_type=thread_type)
data["action_type"] = "ma-type:user-generated-message"
data["lightweight_action_attachment[lwa_state]"] = (
"INITIATED" if wave_first else "RECIPROCATED"
)
data["lightweight_action_attachment[lwa_type]"] = "WAVE"
if thread_type == ThreadType.USER:
data["specific_to_list[0]"] = "fbid:{}".format(thread_id)
return self._doSendRequest(data) | [
"def",
"wave",
"(",
"self",
",",
"wave_first",
"=",
"True",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"thread_type",
")",
"data",
"=",... | Says hello with a wave to a thread!
:param wave_first: Whether to wave first or wave back
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed | [
"Says",
"hello",
"with",
"a",
"wave",
"to",
"a",
"thread!"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1385-L1405 |
234,128 | carpedm20/fbchat | fbchat/_client.py | Client.quickReply | def quickReply(self, quick_reply, payload=None, thread_id=None, thread_type=None):
"""
Replies to a chosen quick reply
:param quick_reply: Quick reply to reply to
:param payload: Optional answer to the quick reply
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type quick_reply: models.QuickReply
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed
"""
quick_reply.is_response = True
if isinstance(quick_reply, QuickReplyText):
return self.send(
Message(text=quick_reply.title, quick_replies=[quick_reply])
)
elif isinstance(quick_reply, QuickReplyLocation):
if not isinstance(payload, LocationAttachment):
raise ValueError(
"Payload must be an instance of `fbchat.models.LocationAttachment`"
)
return self.sendLocation(
payload, thread_id=thread_id, thread_type=thread_type
)
elif isinstance(quick_reply, QuickReplyEmail):
if not payload:
payload = self.getEmails()[0]
quick_reply.external_payload = quick_reply.payload
quick_reply.payload = payload
return self.send(Message(text=payload, quick_replies=[quick_reply]))
elif isinstance(quick_reply, QuickReplyPhoneNumber):
if not payload:
payload = self.getPhoneNumbers()[0]
quick_reply.external_payload = quick_reply.payload
quick_reply.payload = payload
return self.send(Message(text=payload, quick_replies=[quick_reply])) | python | def quickReply(self, quick_reply, payload=None, thread_id=None, thread_type=None):
quick_reply.is_response = True
if isinstance(quick_reply, QuickReplyText):
return self.send(
Message(text=quick_reply.title, quick_replies=[quick_reply])
)
elif isinstance(quick_reply, QuickReplyLocation):
if not isinstance(payload, LocationAttachment):
raise ValueError(
"Payload must be an instance of `fbchat.models.LocationAttachment`"
)
return self.sendLocation(
payload, thread_id=thread_id, thread_type=thread_type
)
elif isinstance(quick_reply, QuickReplyEmail):
if not payload:
payload = self.getEmails()[0]
quick_reply.external_payload = quick_reply.payload
quick_reply.payload = payload
return self.send(Message(text=payload, quick_replies=[quick_reply]))
elif isinstance(quick_reply, QuickReplyPhoneNumber):
if not payload:
payload = self.getPhoneNumbers()[0]
quick_reply.external_payload = quick_reply.payload
quick_reply.payload = payload
return self.send(Message(text=payload, quick_replies=[quick_reply])) | [
"def",
"quickReply",
"(",
"self",
",",
"quick_reply",
",",
"payload",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
")",
":",
"quick_reply",
".",
"is_response",
"=",
"True",
"if",
"isinstance",
"(",
"quick_reply",
",",
"Quick... | Replies to a chosen quick reply
:param quick_reply: Quick reply to reply to
:param payload: Optional answer to the quick reply
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type quick_reply: models.QuickReply
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed | [
"Replies",
"to",
"a",
"chosen",
"quick",
"reply"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1407-L1444 |
234,129 | carpedm20/fbchat | fbchat/_client.py | Client.sendLocation | def sendLocation(self, location, message=None, thread_id=None, thread_type=None):
"""
Sends a given location to a thread as the user's current location
:param location: Location to send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type location: models.LocationAttachment
:type message: models.Message
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed
"""
self._sendLocation(
location=location,
current=True,
message=message,
thread_id=thread_id,
thread_type=thread_type,
) | python | def sendLocation(self, location, message=None, thread_id=None, thread_type=None):
self._sendLocation(
location=location,
current=True,
message=message,
thread_id=thread_id,
thread_type=thread_type,
) | [
"def",
"sendLocation",
"(",
"self",
",",
"location",
",",
"message",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
")",
":",
"self",
".",
"_sendLocation",
"(",
"location",
"=",
"location",
",",
"current",
"=",
"True",
",",
... | Sends a given location to a thread as the user's current location
:param location: Location to send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type location: models.LocationAttachment
:type message: models.Message
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed | [
"Sends",
"a",
"given",
"location",
"to",
"a",
"thread",
"as",
"the",
"user",
"s",
"current",
"location"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1469-L1489 |
234,130 | carpedm20/fbchat | fbchat/_client.py | Client.sendPinnedLocation | def sendPinnedLocation(
self, location, message=None, thread_id=None, thread_type=None
):
"""
Sends a given location to a thread as a pinned location
:param location: Location to send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type location: models.LocationAttachment
:type message: models.Message
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed
"""
self._sendLocation(
location=location,
current=False,
message=message,
thread_id=thread_id,
thread_type=thread_type,
) | python | def sendPinnedLocation(
self, location, message=None, thread_id=None, thread_type=None
):
self._sendLocation(
location=location,
current=False,
message=message,
thread_id=thread_id,
thread_type=thread_type,
) | [
"def",
"sendPinnedLocation",
"(",
"self",
",",
"location",
",",
"message",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
")",
":",
"self",
".",
"_sendLocation",
"(",
"location",
"=",
"location",
",",
"current",
"=",
"False",
... | Sends a given location to a thread as a pinned location
:param location: Location to send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type location: models.LocationAttachment
:type message: models.Message
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent message
:raises: FBchatException if request failed | [
"Sends",
"a",
"given",
"location",
"to",
"a",
"thread",
"as",
"a",
"pinned",
"location"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1491-L1513 |
234,131 | carpedm20/fbchat | fbchat/_client.py | Client._upload | def _upload(self, files, voice_clip=False):
"""
Uploads files to Facebook
`files` should be a list of files that requests can upload, see:
http://docs.python-requests.org/en/master/api/#requests.request
Returns a list of tuples with a file's ID and mimetype
"""
file_dict = {"upload_{}".format(i): f for i, f in enumerate(files)}
data = {"voice_clip": voice_clip}
j = self._postFile(
self.req_url.UPLOAD,
files=file_dict,
query=data,
fix_request=True,
as_json=True,
)
if len(j["payload"]["metadata"]) != len(files):
raise FBchatException(
"Some files could not be uploaded: {}, {}".format(j, files)
)
return [
(data[mimetype_to_key(data["filetype"])], data["filetype"])
for data in j["payload"]["metadata"]
] | python | def _upload(self, files, voice_clip=False):
file_dict = {"upload_{}".format(i): f for i, f in enumerate(files)}
data = {"voice_clip": voice_clip}
j = self._postFile(
self.req_url.UPLOAD,
files=file_dict,
query=data,
fix_request=True,
as_json=True,
)
if len(j["payload"]["metadata"]) != len(files):
raise FBchatException(
"Some files could not be uploaded: {}, {}".format(j, files)
)
return [
(data[mimetype_to_key(data["filetype"])], data["filetype"])
for data in j["payload"]["metadata"]
] | [
"def",
"_upload",
"(",
"self",
",",
"files",
",",
"voice_clip",
"=",
"False",
")",
":",
"file_dict",
"=",
"{",
"\"upload_{}\"",
".",
"format",
"(",
"i",
")",
":",
"f",
"for",
"i",
",",
"f",
"in",
"enumerate",
"(",
"files",
")",
"}",
"data",
"=",
... | Uploads files to Facebook
`files` should be a list of files that requests can upload, see:
http://docs.python-requests.org/en/master/api/#requests.request
Returns a list of tuples with a file's ID and mimetype | [
"Uploads",
"files",
"to",
"Facebook"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1515-L1544 |
234,132 | carpedm20/fbchat | fbchat/_client.py | Client._sendFiles | def _sendFiles(
self, files, message=None, thread_id=None, thread_type=ThreadType.USER
):
"""
Sends files from file IDs to a thread
`files` should be a list of tuples, with a file's ID and mimetype
"""
thread_id, thread_type = self._getThread(thread_id, thread_type)
data = self._getSendData(
message=self._oldMessage(message),
thread_id=thread_id,
thread_type=thread_type,
)
data["action_type"] = "ma-type:user-generated-message"
data["has_attachment"] = True
for i, (file_id, mimetype) in enumerate(files):
data["{}s[{}]".format(mimetype_to_key(mimetype), i)] = file_id
return self._doSendRequest(data) | python | def _sendFiles(
self, files, message=None, thread_id=None, thread_type=ThreadType.USER
):
thread_id, thread_type = self._getThread(thread_id, thread_type)
data = self._getSendData(
message=self._oldMessage(message),
thread_id=thread_id,
thread_type=thread_type,
)
data["action_type"] = "ma-type:user-generated-message"
data["has_attachment"] = True
for i, (file_id, mimetype) in enumerate(files):
data["{}s[{}]".format(mimetype_to_key(mimetype), i)] = file_id
return self._doSendRequest(data) | [
"def",
"_sendFiles",
"(",
"self",
",",
"files",
",",
"message",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
"... | Sends files from file IDs to a thread
`files` should be a list of tuples, with a file's ID and mimetype | [
"Sends",
"files",
"from",
"file",
"IDs",
"to",
"a",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1546-L1567 |
234,133 | carpedm20/fbchat | fbchat/_client.py | Client.sendRemoteFiles | def sendRemoteFiles(
self, file_urls, message=None, thread_id=None, thread_type=ThreadType.USER
):
"""
Sends files from URLs to a thread
:param file_urls: URLs of files to upload and send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent files
:raises: FBchatException if request failed
"""
file_urls = require_list(file_urls)
files = self._upload(get_files_from_urls(file_urls))
return self._sendFiles(
files=files, message=message, thread_id=thread_id, thread_type=thread_type
) | python | def sendRemoteFiles(
self, file_urls, message=None, thread_id=None, thread_type=ThreadType.USER
):
file_urls = require_list(file_urls)
files = self._upload(get_files_from_urls(file_urls))
return self._sendFiles(
files=files, message=message, thread_id=thread_id, thread_type=thread_type
) | [
"def",
"sendRemoteFiles",
"(",
"self",
",",
"file_urls",
",",
"message",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
")",
":",
"file_urls",
"=",
"require_list",
"(",
"file_urls",
")",
"files",
"=",
"self"... | Sends files from URLs to a thread
:param file_urls: URLs of files to upload and send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent files
:raises: FBchatException if request failed | [
"Sends",
"files",
"from",
"URLs",
"to",
"a",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1569-L1587 |
234,134 | carpedm20/fbchat | fbchat/_client.py | Client.sendLocalFiles | def sendLocalFiles(
self, file_paths, message=None, thread_id=None, thread_type=ThreadType.USER
):
"""
Sends local files to a thread
:param file_paths: Paths of files to upload and send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent files
:raises: FBchatException if request failed
"""
file_paths = require_list(file_paths)
with get_files_from_paths(file_paths) as x:
files = self._upload(x)
return self._sendFiles(
files=files, message=message, thread_id=thread_id, thread_type=thread_type
) | python | def sendLocalFiles(
self, file_paths, message=None, thread_id=None, thread_type=ThreadType.USER
):
file_paths = require_list(file_paths)
with get_files_from_paths(file_paths) as x:
files = self._upload(x)
return self._sendFiles(
files=files, message=message, thread_id=thread_id, thread_type=thread_type
) | [
"def",
"sendLocalFiles",
"(",
"self",
",",
"file_paths",
",",
"message",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
")",
":",
"file_paths",
"=",
"require_list",
"(",
"file_paths",
")",
"with",
"get_files_f... | Sends local files to a thread
:param file_paths: Paths of files to upload and send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent files
:raises: FBchatException if request failed | [
"Sends",
"local",
"files",
"to",
"a",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1589-L1608 |
234,135 | carpedm20/fbchat | fbchat/_client.py | Client.sendRemoteVoiceClips | def sendRemoteVoiceClips(
self, clip_urls, message=None, thread_id=None, thread_type=ThreadType.USER
):
"""
Sends voice clips from URLs to a thread
:param clip_urls: URLs of clips to upload and send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent files
:raises: FBchatException if request failed
"""
clip_urls = require_list(clip_urls)
files = self._upload(get_files_from_urls(clip_urls), voice_clip=True)
return self._sendFiles(
files=files, message=message, thread_id=thread_id, thread_type=thread_type
) | python | def sendRemoteVoiceClips(
self, clip_urls, message=None, thread_id=None, thread_type=ThreadType.USER
):
clip_urls = require_list(clip_urls)
files = self._upload(get_files_from_urls(clip_urls), voice_clip=True)
return self._sendFiles(
files=files, message=message, thread_id=thread_id, thread_type=thread_type
) | [
"def",
"sendRemoteVoiceClips",
"(",
"self",
",",
"clip_urls",
",",
"message",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
")",
":",
"clip_urls",
"=",
"require_list",
"(",
"clip_urls",
")",
"files",
"=",
"... | Sends voice clips from URLs to a thread
:param clip_urls: URLs of clips to upload and send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent files
:raises: FBchatException if request failed | [
"Sends",
"voice",
"clips",
"from",
"URLs",
"to",
"a",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1610-L1628 |
234,136 | carpedm20/fbchat | fbchat/_client.py | Client.sendLocalVoiceClips | def sendLocalVoiceClips(
self, clip_paths, message=None, thread_id=None, thread_type=ThreadType.USER
):
"""
Sends local voice clips to a thread
:param clip_paths: Paths of clips to upload and send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent files
:raises: FBchatException if request failed
"""
clip_paths = require_list(clip_paths)
with get_files_from_paths(clip_paths) as x:
files = self._upload(x, voice_clip=True)
return self._sendFiles(
files=files, message=message, thread_id=thread_id, thread_type=thread_type
) | python | def sendLocalVoiceClips(
self, clip_paths, message=None, thread_id=None, thread_type=ThreadType.USER
):
clip_paths = require_list(clip_paths)
with get_files_from_paths(clip_paths) as x:
files = self._upload(x, voice_clip=True)
return self._sendFiles(
files=files, message=message, thread_id=thread_id, thread_type=thread_type
) | [
"def",
"sendLocalVoiceClips",
"(",
"self",
",",
"clip_paths",
",",
"message",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
")",
":",
"clip_paths",
"=",
"require_list",
"(",
"clip_paths",
")",
"with",
"get_fi... | Sends local voice clips to a thread
:param clip_paths: Paths of clips to upload and send
:param message: Additional message
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:return: :ref:`Message ID <intro_message_ids>` of the sent files
:raises: FBchatException if request failed | [
"Sends",
"local",
"voice",
"clips",
"to",
"a",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1630-L1649 |
234,137 | carpedm20/fbchat | fbchat/_client.py | Client.forwardAttachment | def forwardAttachment(self, attachment_id, thread_id=None):
"""
Forwards an attachment
:param attachment_id: Attachment ID to forward
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, None)
data = {
"attachment_id": attachment_id,
"recipient_map[{}]".format(generateOfflineThreadingID()): thread_id,
}
j = self._post(
self.req_url.FORWARD_ATTACHMENT, data, fix_request=True, as_json=True
) | python | def forwardAttachment(self, attachment_id, thread_id=None):
thread_id, thread_type = self._getThread(thread_id, None)
data = {
"attachment_id": attachment_id,
"recipient_map[{}]".format(generateOfflineThreadingID()): thread_id,
}
j = self._post(
self.req_url.FORWARD_ATTACHMENT, data, fix_request=True, as_json=True
) | [
"def",
"forwardAttachment",
"(",
"self",
",",
"attachment_id",
",",
"thread_id",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"None",
")",
"data",
"=",
"{",
"\"attachment_id\"",
":",
"attachme... | Forwards an attachment
:param attachment_id: Attachment ID to forward
:param thread_id: User/Group ID to send to. See :ref:`intro_threads`
:raises: FBchatException if request failed | [
"Forwards",
"an",
"attachment"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1699-L1714 |
234,138 | carpedm20/fbchat | fbchat/_client.py | Client.createGroup | def createGroup(self, message, user_ids):
"""
Creates a group with the given ids
:param message: The initial message
:param user_ids: A list of users to create the group with.
:return: ID of the new group
:raises: FBchatException if request failed
"""
data = self._getSendData(message=self._oldMessage(message))
if len(user_ids) < 2:
raise FBchatUserError("Error when creating group: Not enough participants")
for i, user_id in enumerate(user_ids + [self._uid]):
data["specific_to_list[{}]".format(i)] = "fbid:{}".format(user_id)
message_id, thread_id = self._doSendRequest(data, get_thread_id=True)
if not thread_id:
raise FBchatException(
"Error when creating group: No thread_id could be found"
)
return thread_id | python | def createGroup(self, message, user_ids):
data = self._getSendData(message=self._oldMessage(message))
if len(user_ids) < 2:
raise FBchatUserError("Error when creating group: Not enough participants")
for i, user_id in enumerate(user_ids + [self._uid]):
data["specific_to_list[{}]".format(i)] = "fbid:{}".format(user_id)
message_id, thread_id = self._doSendRequest(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",
"createGroup",
"(",
"self",
",",
"message",
",",
"user_ids",
")",
":",
"data",
"=",
"self",
".",
"_getSendData",
"(",
"message",
"=",
"self",
".",
"_oldMessage",
"(",
"message",
")",
")",
"if",
"len",
"(",
"user_ids",
")",
"<",
"2",
":",
"rais... | Creates a group with the given ids
:param message: The initial message
:param user_ids: A list of users to create the group with.
:return: ID of the new group
:raises: FBchatException if request failed | [
"Creates",
"a",
"group",
"with",
"the",
"given",
"ids"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1716-L1738 |
234,139 | carpedm20/fbchat | fbchat/_client.py | Client.addUsersToGroup | def addUsersToGroup(self, user_ids, thread_id=None):
"""
Adds users to a group.
:param user_ids: One or more user IDs to add
:param thread_id: Group ID to add people to. See :ref:`intro_threads`
:type user_ids: list
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, None)
data = self._getSendData(thread_id=thread_id, thread_type=ThreadType.GROUP)
data["action_type"] = "ma-type:log-message"
data["log_message_type"] = "log:subscribe"
user_ids = require_list(user_ids)
for i, user_id in enumerate(user_ids):
if user_id == self._uid:
raise FBchatUserError(
"Error when adding users: Cannot add self to group thread"
)
else:
data[
"log_message_data[added_participants][{}]".format(i)
] = "fbid:{}".format(user_id)
return self._doSendRequest(data) | python | def addUsersToGroup(self, user_ids, thread_id=None):
thread_id, thread_type = self._getThread(thread_id, None)
data = self._getSendData(thread_id=thread_id, thread_type=ThreadType.GROUP)
data["action_type"] = "ma-type:log-message"
data["log_message_type"] = "log:subscribe"
user_ids = require_list(user_ids)
for i, user_id in enumerate(user_ids):
if user_id == self._uid:
raise FBchatUserError(
"Error when adding users: Cannot add self to group thread"
)
else:
data[
"log_message_data[added_participants][{}]".format(i)
] = "fbid:{}".format(user_id)
return self._doSendRequest(data) | [
"def",
"addUsersToGroup",
"(",
"self",
",",
"user_ids",
",",
"thread_id",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"None",
")",
"data",
"=",
"self",
".",
"_getSendData",
"(",
"thread_id"... | Adds users to a group.
:param user_ids: One or more user IDs to add
:param thread_id: Group ID to add people to. See :ref:`intro_threads`
:type user_ids: list
:raises: FBchatException if request failed | [
"Adds",
"users",
"to",
"a",
"group",
"."
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1740-L1767 |
234,140 | carpedm20/fbchat | fbchat/_client.py | Client.removeUserFromGroup | def removeUserFromGroup(self, user_id, thread_id=None):
"""
Removes users from a group.
:param user_id: User ID to remove
:param thread_id: Group ID to remove people from. See :ref:`intro_threads`
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, None)
data = {"uid": user_id, "tid": thread_id}
j = self._post(self.req_url.REMOVE_USER, data, fix_request=True, as_json=True) | python | def removeUserFromGroup(self, user_id, thread_id=None):
thread_id, thread_type = self._getThread(thread_id, None)
data = {"uid": user_id, "tid": thread_id}
j = self._post(self.req_url.REMOVE_USER, data, fix_request=True, as_json=True) | [
"def",
"removeUserFromGroup",
"(",
"self",
",",
"user_id",
",",
"thread_id",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"None",
")",
"data",
"=",
"{",
"\"uid\"",
":",
"user_id",
",",
"\"... | Removes users from a group.
:param user_id: User ID to remove
:param thread_id: Group ID to remove people from. See :ref:`intro_threads`
:raises: FBchatException if request failed | [
"Removes",
"users",
"from",
"a",
"group",
"."
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1769-L1780 |
234,141 | carpedm20/fbchat | fbchat/_client.py | Client.changeGroupApprovalMode | def changeGroupApprovalMode(self, require_admin_approval, thread_id=None):
"""
Changes group's approval mode
:param require_admin_approval: True or False
:param thread_id: Group ID to remove people from. See :ref:`intro_threads`
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, None)
data = {"set_mode": int(require_admin_approval), "thread_fbid": thread_id}
j = self._post(self.req_url.APPROVAL_MODE, data, fix_request=True, as_json=True) | python | def changeGroupApprovalMode(self, require_admin_approval, thread_id=None):
thread_id, thread_type = self._getThread(thread_id, None)
data = {"set_mode": int(require_admin_approval), "thread_fbid": thread_id}
j = self._post(self.req_url.APPROVAL_MODE, data, fix_request=True, as_json=True) | [
"def",
"changeGroupApprovalMode",
"(",
"self",
",",
"require_admin_approval",
",",
"thread_id",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"None",
")",
"data",
"=",
"{",
"\"set_mode\"",
":",
... | Changes group's approval mode
:param require_admin_approval: True or False
:param thread_id: Group ID to remove people from. See :ref:`intro_threads`
:raises: FBchatException if request failed | [
"Changes",
"group",
"s",
"approval",
"mode"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1814-L1825 |
234,142 | carpedm20/fbchat | fbchat/_client.py | Client._changeGroupImage | def _changeGroupImage(self, image_id, thread_id=None):
"""
Changes a thread image from an image id
:param image_id: ID of uploaded image
:param thread_id: User/Group ID to change image. See :ref:`intro_threads`
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, None)
data = {"thread_image_id": image_id, "thread_id": thread_id}
j = self._post(self.req_url.THREAD_IMAGE, data, fix_request=True, as_json=True)
return image_id | python | def _changeGroupImage(self, image_id, thread_id=None):
thread_id, thread_type = self._getThread(thread_id, None)
data = {"thread_image_id": image_id, "thread_id": thread_id}
j = self._post(self.req_url.THREAD_IMAGE, data, fix_request=True, as_json=True)
return image_id | [
"def",
"_changeGroupImage",
"(",
"self",
",",
"image_id",
",",
"thread_id",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"None",
")",
"data",
"=",
"{",
"\"thread_image_id\"",
":",
"image_id",
... | Changes a thread image from an image id
:param image_id: ID of uploaded image
:param thread_id: User/Group ID to change image. See :ref:`intro_threads`
:raises: FBchatException if request failed | [
"Changes",
"a",
"thread",
"image",
"from",
"an",
"image",
"id"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1864-L1877 |
234,143 | carpedm20/fbchat | fbchat/_client.py | Client.changeGroupImageRemote | def changeGroupImageRemote(self, image_url, thread_id=None):
"""
Changes a thread image from a URL
:param image_url: URL of an image to upload and change
:param thread_id: User/Group ID to change image. See :ref:`intro_threads`
:raises: FBchatException if request failed
"""
(image_id, mimetype), = self._upload(get_files_from_urls([image_url]))
return self._changeGroupImage(image_id, thread_id) | python | def changeGroupImageRemote(self, image_url, thread_id=None):
(image_id, mimetype), = self._upload(get_files_from_urls([image_url]))
return self._changeGroupImage(image_id, thread_id) | [
"def",
"changeGroupImageRemote",
"(",
"self",
",",
"image_url",
",",
"thread_id",
"=",
"None",
")",
":",
"(",
"image_id",
",",
"mimetype",
")",
",",
"=",
"self",
".",
"_upload",
"(",
"get_files_from_urls",
"(",
"[",
"image_url",
"]",
")",
")",
"return",
... | Changes a thread image from a URL
:param image_url: URL of an image to upload and change
:param thread_id: User/Group ID to change image. See :ref:`intro_threads`
:raises: FBchatException if request failed | [
"Changes",
"a",
"thread",
"image",
"from",
"a",
"URL"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1879-L1888 |
234,144 | carpedm20/fbchat | fbchat/_client.py | Client.changeGroupImageLocal | def changeGroupImageLocal(self, image_path, thread_id=None):
"""
Changes a thread image from a local path
:param image_path: Path of an image to upload and change
:param thread_id: User/Group ID to change image. See :ref:`intro_threads`
:raises: FBchatException if request failed
"""
with get_files_from_paths([image_path]) as files:
(image_id, mimetype), = self._upload(files)
return self._changeGroupImage(image_id, thread_id) | python | def changeGroupImageLocal(self, image_path, thread_id=None):
with get_files_from_paths([image_path]) as files:
(image_id, mimetype), = self._upload(files)
return self._changeGroupImage(image_id, thread_id) | [
"def",
"changeGroupImageLocal",
"(",
"self",
",",
"image_path",
",",
"thread_id",
"=",
"None",
")",
":",
"with",
"get_files_from_paths",
"(",
"[",
"image_path",
"]",
")",
"as",
"files",
":",
"(",
"image_id",
",",
"mimetype",
")",
",",
"=",
"self",
".",
"... | Changes a thread image from a local path
:param image_path: Path of an image to upload and change
:param thread_id: User/Group ID to change image. See :ref:`intro_threads`
:raises: FBchatException if request failed | [
"Changes",
"a",
"thread",
"image",
"from",
"a",
"local",
"path"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1890-L1901 |
234,145 | carpedm20/fbchat | fbchat/_client.py | Client.changeThreadTitle | def changeThreadTitle(self, title, thread_id=None, thread_type=ThreadType.USER):
"""
Changes title of a thread.
If this is executed on a user thread, this will change the nickname of that user, effectively changing the title
:param title: New group thread title
:param thread_id: Group ID to change title of. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, thread_type)
if thread_type == ThreadType.USER:
# The thread is a user, so we change the user's nickname
return self.changeNickname(
title, thread_id, thread_id=thread_id, thread_type=thread_type
)
data = {"thread_name": title, "thread_id": thread_id}
j = self._post(self.req_url.THREAD_NAME, data, fix_request=True, as_json=True) | python | def changeThreadTitle(self, title, thread_id=None, thread_type=ThreadType.USER):
thread_id, thread_type = self._getThread(thread_id, thread_type)
if thread_type == ThreadType.USER:
# The thread is a user, so we change the user's nickname
return self.changeNickname(
title, thread_id, thread_id=thread_id, thread_type=thread_type
)
data = {"thread_name": title, "thread_id": thread_id}
j = self._post(self.req_url.THREAD_NAME, data, fix_request=True, as_json=True) | [
"def",
"changeThreadTitle",
"(",
"self",
",",
"title",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"thread_type",
")",
... | Changes title of a thread.
If this is executed on a user thread, this will change the nickname of that user, effectively changing the title
:param title: New group thread title
:param thread_id: Group ID to change title of. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:raises: FBchatException if request failed | [
"Changes",
"title",
"of",
"a",
"thread",
".",
"If",
"this",
"is",
"executed",
"on",
"a",
"user",
"thread",
"this",
"will",
"change",
"the",
"nickname",
"of",
"that",
"user",
"effectively",
"changing",
"the",
"title"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1903-L1923 |
234,146 | carpedm20/fbchat | fbchat/_client.py | Client.changeNickname | def changeNickname(
self, nickname, user_id, thread_id=None, thread_type=ThreadType.USER
):
"""
Changes the nickname of a user in a thread
:param nickname: New nickname
:param user_id: User that will have their nickname changed
:param thread_id: User/Group ID to change color of. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, thread_type)
data = {
"nickname": nickname,
"participant_id": user_id,
"thread_or_other_fbid": thread_id,
}
j = self._post(
self.req_url.THREAD_NICKNAME, data, fix_request=True, as_json=True
) | python | def changeNickname(
self, nickname, user_id, thread_id=None, thread_type=ThreadType.USER
):
thread_id, thread_type = self._getThread(thread_id, thread_type)
data = {
"nickname": nickname,
"participant_id": user_id,
"thread_or_other_fbid": thread_id,
}
j = self._post(
self.req_url.THREAD_NICKNAME, data, fix_request=True, as_json=True
) | [
"def",
"changeNickname",
"(",
"self",
",",
"nickname",
",",
"user_id",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"thr... | Changes the nickname of a user in a thread
:param nickname: New nickname
:param user_id: User that will have their nickname changed
:param thread_id: User/Group ID to change color of. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:raises: FBchatException if request failed | [
"Changes",
"the",
"nickname",
"of",
"a",
"user",
"in",
"a",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1925-L1947 |
234,147 | carpedm20/fbchat | fbchat/_client.py | Client.reactToMessage | def reactToMessage(self, message_id, reaction):
"""
Reacts to a message, or removes reaction
:param message_id: :ref:`Message ID <intro_message_ids>` to react to
:param reaction: Reaction emoji to use, if None removes reaction
:type reaction: models.MessageReaction or None
:raises: FBchatException if request failed
"""
data = {
"action": "ADD_REACTION" if reaction else "REMOVE_REACTION",
"client_mutation_id": "1",
"actor_id": self._uid,
"message_id": str(message_id),
"reaction": reaction.value if reaction else None,
}
data = {"doc_id": 1491398900900362, "variables": json.dumps({"data": data})}
self._post(self.req_url.MESSAGE_REACTION, data, fix_request=True, as_json=True) | python | def reactToMessage(self, message_id, reaction):
data = {
"action": "ADD_REACTION" if reaction else "REMOVE_REACTION",
"client_mutation_id": "1",
"actor_id": self._uid,
"message_id": str(message_id),
"reaction": reaction.value if reaction else None,
}
data = {"doc_id": 1491398900900362, "variables": json.dumps({"data": data})}
self._post(self.req_url.MESSAGE_REACTION, data, fix_request=True, as_json=True) | [
"def",
"reactToMessage",
"(",
"self",
",",
"message_id",
",",
"reaction",
")",
":",
"data",
"=",
"{",
"\"action\"",
":",
"\"ADD_REACTION\"",
"if",
"reaction",
"else",
"\"REMOVE_REACTION\"",
",",
"\"client_mutation_id\"",
":",
"\"1\"",
",",
"\"actor_id\"",
":",
"... | Reacts to a message, or removes reaction
:param message_id: :ref:`Message ID <intro_message_ids>` to react to
:param reaction: Reaction emoji to use, if None removes reaction
:type reaction: models.MessageReaction or None
:raises: FBchatException if request failed | [
"Reacts",
"to",
"a",
"message",
"or",
"removes",
"reaction"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L1981-L1998 |
234,148 | carpedm20/fbchat | fbchat/_client.py | Client.createPlan | def createPlan(self, plan, thread_id=None):
"""
Sets a plan
:param plan: Plan to set
:param thread_id: User/Group ID to send plan to. See :ref:`intro_threads`
:type plan: models.Plan
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, None)
data = {
"event_type": "EVENT",
"event_time": plan.time,
"title": plan.title,
"thread_id": thread_id,
"location_id": plan.location_id or "",
"location_name": plan.location or "",
"acontext": ACONTEXT,
}
j = self._post(self.req_url.PLAN_CREATE, data, fix_request=True, as_json=True) | python | def createPlan(self, plan, thread_id=None):
thread_id, thread_type = self._getThread(thread_id, None)
data = {
"event_type": "EVENT",
"event_time": plan.time,
"title": plan.title,
"thread_id": thread_id,
"location_id": plan.location_id or "",
"location_name": plan.location or "",
"acontext": ACONTEXT,
}
j = self._post(self.req_url.PLAN_CREATE, data, fix_request=True, as_json=True) | [
"def",
"createPlan",
"(",
"self",
",",
"plan",
",",
"thread_id",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"None",
")",
"data",
"=",
"{",
"\"event_type\"",
":",
"\"EVENT\"",
",",
"\"eve... | Sets a plan
:param plan: Plan to set
:param thread_id: User/Group ID to send plan to. See :ref:`intro_threads`
:type plan: models.Plan
:raises: FBchatException if request failed | [
"Sets",
"a",
"plan"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2000-L2020 |
234,149 | carpedm20/fbchat | fbchat/_client.py | Client.editPlan | def editPlan(self, plan, new_plan):
"""
Edits a plan
:param plan: Plan to edit
:param new_plan: New plan
:type plan: models.Plan
:raises: FBchatException if request failed
"""
data = {
"event_reminder_id": plan.uid,
"delete": "false",
"date": new_plan.time,
"location_name": new_plan.location or "",
"location_id": new_plan.location_id or "",
"title": new_plan.title,
"acontext": ACONTEXT,
}
j = self._post(self.req_url.PLAN_CHANGE, data, fix_request=True, as_json=True) | python | def editPlan(self, plan, new_plan):
data = {
"event_reminder_id": plan.uid,
"delete": "false",
"date": new_plan.time,
"location_name": new_plan.location or "",
"location_id": new_plan.location_id or "",
"title": new_plan.title,
"acontext": ACONTEXT,
}
j = self._post(self.req_url.PLAN_CHANGE, data, fix_request=True, as_json=True) | [
"def",
"editPlan",
"(",
"self",
",",
"plan",
",",
"new_plan",
")",
":",
"data",
"=",
"{",
"\"event_reminder_id\"",
":",
"plan",
".",
"uid",
",",
"\"delete\"",
":",
"\"false\"",
",",
"\"date\"",
":",
"new_plan",
".",
"time",
",",
"\"location_name\"",
":",
... | Edits a plan
:param plan: Plan to edit
:param new_plan: New plan
:type plan: models.Plan
:raises: FBchatException if request failed | [
"Edits",
"a",
"plan"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2022-L2040 |
234,150 | carpedm20/fbchat | fbchat/_client.py | Client.deletePlan | def deletePlan(self, plan):
"""
Deletes a plan
:param plan: Plan to delete
:raises: FBchatException if request failed
"""
data = {"event_reminder_id": plan.uid, "delete": "true", "acontext": ACONTEXT}
j = self._post(self.req_url.PLAN_CHANGE, data, fix_request=True, as_json=True) | python | def deletePlan(self, plan):
data = {"event_reminder_id": plan.uid, "delete": "true", "acontext": ACONTEXT}
j = self._post(self.req_url.PLAN_CHANGE, data, fix_request=True, as_json=True) | [
"def",
"deletePlan",
"(",
"self",
",",
"plan",
")",
":",
"data",
"=",
"{",
"\"event_reminder_id\"",
":",
"plan",
".",
"uid",
",",
"\"delete\"",
":",
"\"true\"",
",",
"\"acontext\"",
":",
"ACONTEXT",
"}",
"j",
"=",
"self",
".",
"_post",
"(",
"self",
"."... | Deletes a plan
:param plan: Plan to delete
:raises: FBchatException if request failed | [
"Deletes",
"a",
"plan"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2042-L2050 |
234,151 | carpedm20/fbchat | fbchat/_client.py | Client.changePlanParticipation | def changePlanParticipation(self, plan, take_part=True):
"""
Changes participation in a plan
:param plan: Plan to take part in or not
:param take_part: Whether to take part in the plan
:raises: FBchatException if request failed
"""
data = {
"event_reminder_id": plan.uid,
"guest_state": "GOING" if take_part else "DECLINED",
"acontext": ACONTEXT,
}
j = self._post(
self.req_url.PLAN_PARTICIPATION, data, fix_request=True, as_json=True
) | python | def changePlanParticipation(self, plan, take_part=True):
data = {
"event_reminder_id": plan.uid,
"guest_state": "GOING" if take_part else "DECLINED",
"acontext": ACONTEXT,
}
j = self._post(
self.req_url.PLAN_PARTICIPATION, data, fix_request=True, as_json=True
) | [
"def",
"changePlanParticipation",
"(",
"self",
",",
"plan",
",",
"take_part",
"=",
"True",
")",
":",
"data",
"=",
"{",
"\"event_reminder_id\"",
":",
"plan",
".",
"uid",
",",
"\"guest_state\"",
":",
"\"GOING\"",
"if",
"take_part",
"else",
"\"DECLINED\"",
",",
... | Changes participation in a plan
:param plan: Plan to take part in or not
:param take_part: Whether to take part in the plan
:raises: FBchatException if request failed | [
"Changes",
"participation",
"in",
"a",
"plan"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2052-L2067 |
234,152 | carpedm20/fbchat | fbchat/_client.py | Client.createPoll | def createPoll(self, poll, thread_id=None):
"""
Creates poll in a group thread
:param poll: Poll to create
:param thread_id: User/Group ID to create poll in. See :ref:`intro_threads`
:type poll: models.Poll
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, None)
# We're using ordered dicts, because the Facebook endpoint that parses the POST
# parameters is badly implemented, and deals with ordering the options wrongly.
# This also means we had to change `client._payload_default` to an ordered dict,
# since that's being copied in between this point and the `requests` call
#
# If you can find a way to fix this for the endpoint, or if you find another
# endpoint, please do suggest it ;)
data = OrderedDict([("question_text", poll.title), ("target_id", thread_id)])
for i, option in enumerate(poll.options):
data["option_text_array[{}]".format(i)] = option.text
data["option_is_selected_array[{}]".format(i)] = str(int(option.vote))
j = self._post(self.req_url.CREATE_POLL, data, fix_request=True, as_json=True) | python | def createPoll(self, poll, thread_id=None):
thread_id, thread_type = self._getThread(thread_id, None)
# We're using ordered dicts, because the Facebook endpoint that parses the POST
# parameters is badly implemented, and deals with ordering the options wrongly.
# This also means we had to change `client._payload_default` to an ordered dict,
# since that's being copied in between this point and the `requests` call
#
# If you can find a way to fix this for the endpoint, or if you find another
# endpoint, please do suggest it ;)
data = OrderedDict([("question_text", poll.title), ("target_id", thread_id)])
for i, option in enumerate(poll.options):
data["option_text_array[{}]".format(i)] = option.text
data["option_is_selected_array[{}]".format(i)] = str(int(option.vote))
j = self._post(self.req_url.CREATE_POLL, data, fix_request=True, as_json=True) | [
"def",
"createPoll",
"(",
"self",
",",
"poll",
",",
"thread_id",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"None",
")",
"# We're using ordered dicts, because the Facebook endpoint that parses the POS... | Creates poll in a group thread
:param poll: Poll to create
:param thread_id: User/Group ID to create poll in. See :ref:`intro_threads`
:type poll: models.Poll
:raises: FBchatException if request failed | [
"Creates",
"poll",
"in",
"a",
"group",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2076-L2100 |
234,153 | carpedm20/fbchat | fbchat/_client.py | Client.updatePollVote | def updatePollVote(self, poll_id, option_ids=[], new_options=[]):
"""
Updates a poll vote
:param poll_id: ID of the poll to update vote
:param option_ids: List of the option IDs to vote
:param new_options: List of the new option names
:param thread_id: User/Group ID to change status in. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:raises: FBchatException if request failed
"""
data = {"question_id": poll_id}
for i, option_id in enumerate(option_ids):
data["selected_options[{}]".format(i)] = option_id
for i, option_text in enumerate(new_options):
data["new_options[{}]".format(i)] = option_text
j = self._post(self.req_url.UPDATE_VOTE, data, fix_request=True, as_json=True) | python | def updatePollVote(self, poll_id, option_ids=[], new_options=[]):
data = {"question_id": poll_id}
for i, option_id in enumerate(option_ids):
data["selected_options[{}]".format(i)] = option_id
for i, option_text in enumerate(new_options):
data["new_options[{}]".format(i)] = option_text
j = self._post(self.req_url.UPDATE_VOTE, data, fix_request=True, as_json=True) | [
"def",
"updatePollVote",
"(",
"self",
",",
"poll_id",
",",
"option_ids",
"=",
"[",
"]",
",",
"new_options",
"=",
"[",
"]",
")",
":",
"data",
"=",
"{",
"\"question_id\"",
":",
"poll_id",
"}",
"for",
"i",
",",
"option_id",
"in",
"enumerate",
"(",
"option... | Updates a poll vote
:param poll_id: ID of the poll to update vote
:param option_ids: List of the option IDs to vote
:param new_options: List of the new option names
:param thread_id: User/Group ID to change status in. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type thread_type: models.ThreadType
:raises: FBchatException if request failed | [
"Updates",
"a",
"poll",
"vote"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2102-L2122 |
234,154 | carpedm20/fbchat | fbchat/_client.py | Client.setTypingStatus | def setTypingStatus(self, status, thread_id=None, thread_type=None):
"""
Sets users typing status in a thread
:param status: Specify the typing status
:param thread_id: User/Group ID to change status in. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type status: models.TypingStatus
:type thread_type: models.ThreadType
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, thread_type)
data = {
"typ": status.value,
"thread": thread_id,
"to": thread_id if thread_type == ThreadType.USER else "",
"source": "mercury-chat",
}
j = self._post(self.req_url.TYPING, data, fix_request=True, as_json=True) | python | def setTypingStatus(self, status, thread_id=None, thread_type=None):
thread_id, thread_type = self._getThread(thread_id, thread_type)
data = {
"typ": status.value,
"thread": thread_id,
"to": thread_id if thread_type == ThreadType.USER else "",
"source": "mercury-chat",
}
j = self._post(self.req_url.TYPING, data, fix_request=True, as_json=True) | [
"def",
"setTypingStatus",
"(",
"self",
",",
"status",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"thread_type",
")",
"data",
"=",
"{",
... | Sets users typing status in a thread
:param status: Specify the typing status
:param thread_id: User/Group ID to change status in. See :ref:`intro_threads`
:param thread_type: See :ref:`intro_threads`
:type status: models.TypingStatus
:type thread_type: models.ThreadType
:raises: FBchatException if request failed | [
"Sets",
"users",
"typing",
"status",
"in",
"a",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2124-L2143 |
234,155 | carpedm20/fbchat | fbchat/_client.py | Client.markAsDelivered | def markAsDelivered(self, thread_id, message_id):
"""
Mark a message as delivered
:param thread_id: User/Group ID to which the message belongs. See :ref:`intro_threads`
:param message_id: Message ID to set as delivered. See :ref:`intro_threads`
:return: Whether the request was successful
:raises: FBchatException if request failed
"""
data = {
"message_ids[0]": message_id,
"thread_ids[%s][0]" % thread_id: message_id,
}
r = self._post(self.req_url.DELIVERED, data)
return r.ok | python | def markAsDelivered(self, thread_id, message_id):
data = {
"message_ids[0]": message_id,
"thread_ids[%s][0]" % thread_id: message_id,
}
r = self._post(self.req_url.DELIVERED, data)
return r.ok | [
"def",
"markAsDelivered",
"(",
"self",
",",
"thread_id",
",",
"message_id",
")",
":",
"data",
"=",
"{",
"\"message_ids[0]\"",
":",
"message_id",
",",
"\"thread_ids[%s][0]\"",
"%",
"thread_id",
":",
"message_id",
",",
"}",
"r",
"=",
"self",
".",
"_post",
"(",... | Mark a message as delivered
:param thread_id: User/Group ID to which the message belongs. See :ref:`intro_threads`
:param message_id: Message ID to set as delivered. See :ref:`intro_threads`
:return: Whether the request was successful
:raises: FBchatException if request failed | [
"Mark",
"a",
"message",
"as",
"delivered"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2149-L2164 |
234,156 | carpedm20/fbchat | fbchat/_client.py | Client.removeFriend | def removeFriend(self, friend_id=None):
"""
Removes a specifed friend from your friend list
:param friend_id: The ID of the friend that you want to remove
:return: Returns error if the removing was unsuccessful, returns True when successful.
"""
payload = {"friend_id": friend_id, "unref": "none", "confirm": "Confirm"}
r = self._post(self.req_url.REMOVE_FRIEND, payload)
query = parse_qs(urlparse(r.url).query)
if "err" not in query:
log.debug("Remove was successful!")
return True
else:
log.warning("Error while removing friend")
return False | python | def removeFriend(self, friend_id=None):
payload = {"friend_id": friend_id, "unref": "none", "confirm": "Confirm"}
r = self._post(self.req_url.REMOVE_FRIEND, payload)
query = parse_qs(urlparse(r.url).query)
if "err" not in query:
log.debug("Remove was successful!")
return True
else:
log.warning("Error while removing friend")
return False | [
"def",
"removeFriend",
"(",
"self",
",",
"friend_id",
"=",
"None",
")",
":",
"payload",
"=",
"{",
"\"friend_id\"",
":",
"friend_id",
",",
"\"unref\"",
":",
"\"none\"",
",",
"\"confirm\"",
":",
"\"Confirm\"",
"}",
"r",
"=",
"self",
".",
"_post",
"(",
"sel... | Removes a specifed friend from your friend list
:param friend_id: The ID of the friend that you want to remove
:return: Returns error if the removing was unsuccessful, returns True when successful. | [
"Removes",
"a",
"specifed",
"friend",
"from",
"your",
"friend",
"list"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2217-L2232 |
234,157 | carpedm20/fbchat | fbchat/_client.py | Client.blockUser | def blockUser(self, user_id):
"""
Blocks messages from a specifed user
:param user_id: The ID of the user that you want to block
:return: Whether the request was successful
:raises: FBchatException if request failed
"""
data = {"fbid": user_id}
r = self._post(self.req_url.BLOCK_USER, data)
return r.ok | python | def blockUser(self, user_id):
data = {"fbid": user_id}
r = self._post(self.req_url.BLOCK_USER, data)
return r.ok | [
"def",
"blockUser",
"(",
"self",
",",
"user_id",
")",
":",
"data",
"=",
"{",
"\"fbid\"",
":",
"user_id",
"}",
"r",
"=",
"self",
".",
"_post",
"(",
"self",
".",
"req_url",
".",
"BLOCK_USER",
",",
"data",
")",
"return",
"r",
".",
"ok"
] | Blocks messages from a specifed user
:param user_id: The ID of the user that you want to block
:return: Whether the request was successful
:raises: FBchatException if request failed | [
"Blocks",
"messages",
"from",
"a",
"specifed",
"user"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2234-L2244 |
234,158 | carpedm20/fbchat | fbchat/_client.py | Client.unblockUser | def unblockUser(self, user_id):
"""
Unblocks messages from a blocked user
:param user_id: The ID of the user that you want to unblock
:return: Whether the request was successful
:raises: FBchatException if request failed
"""
data = {"fbid": user_id}
r = self._post(self.req_url.UNBLOCK_USER, data)
return r.ok | python | def unblockUser(self, user_id):
data = {"fbid": user_id}
r = self._post(self.req_url.UNBLOCK_USER, data)
return r.ok | [
"def",
"unblockUser",
"(",
"self",
",",
"user_id",
")",
":",
"data",
"=",
"{",
"\"fbid\"",
":",
"user_id",
"}",
"r",
"=",
"self",
".",
"_post",
"(",
"self",
".",
"req_url",
".",
"UNBLOCK_USER",
",",
"data",
")",
"return",
"r",
".",
"ok"
] | Unblocks messages from a blocked user
:param user_id: The ID of the user that you want to unblock
:return: Whether the request was successful
:raises: FBchatException if request failed | [
"Unblocks",
"messages",
"from",
"a",
"blocked",
"user"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2246-L2256 |
234,159 | carpedm20/fbchat | fbchat/_client.py | Client.moveThreads | def moveThreads(self, location, thread_ids):
"""
Moves threads to specifed location
:param location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER
:param thread_ids: Thread IDs to move. See :ref:`intro_threads`
:return: Whether the request was successful
:raises: FBchatException if request failed
"""
thread_ids = require_list(thread_ids)
if location == ThreadLocation.PENDING:
location = ThreadLocation.OTHER
if location == ThreadLocation.ARCHIVED:
data_archive = dict()
data_unpin = dict()
for thread_id in thread_ids:
data_archive["ids[{}]".format(thread_id)] = "true"
data_unpin["ids[{}]".format(thread_id)] = "false"
r_archive = self._post(self.req_url.ARCHIVED_STATUS, data_archive)
r_unpin = self._post(self.req_url.PINNED_STATUS, data_unpin)
return r_archive.ok and r_unpin.ok
else:
data = dict()
for i, thread_id in enumerate(thread_ids):
data["{}[{}]".format(location.name.lower(), i)] = thread_id
r = self._post(self.req_url.MOVE_THREAD, data)
return r.ok | python | def moveThreads(self, location, thread_ids):
thread_ids = require_list(thread_ids)
if location == ThreadLocation.PENDING:
location = ThreadLocation.OTHER
if location == ThreadLocation.ARCHIVED:
data_archive = dict()
data_unpin = dict()
for thread_id in thread_ids:
data_archive["ids[{}]".format(thread_id)] = "true"
data_unpin["ids[{}]".format(thread_id)] = "false"
r_archive = self._post(self.req_url.ARCHIVED_STATUS, data_archive)
r_unpin = self._post(self.req_url.PINNED_STATUS, data_unpin)
return r_archive.ok and r_unpin.ok
else:
data = dict()
for i, thread_id in enumerate(thread_ids):
data["{}[{}]".format(location.name.lower(), i)] = thread_id
r = self._post(self.req_url.MOVE_THREAD, data)
return r.ok | [
"def",
"moveThreads",
"(",
"self",
",",
"location",
",",
"thread_ids",
")",
":",
"thread_ids",
"=",
"require_list",
"(",
"thread_ids",
")",
"if",
"location",
"==",
"ThreadLocation",
".",
"PENDING",
":",
"location",
"=",
"ThreadLocation",
".",
"OTHER",
"if",
... | Moves threads to specifed location
:param location: models.ThreadLocation: INBOX, PENDING, ARCHIVED or OTHER
:param thread_ids: Thread IDs to move. See :ref:`intro_threads`
:return: Whether the request was successful
:raises: FBchatException if request failed | [
"Moves",
"threads",
"to",
"specifed",
"location"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2258-L2286 |
234,160 | carpedm20/fbchat | fbchat/_client.py | Client.markAsSpam | def markAsSpam(self, thread_id=None):
"""
Mark a thread as spam and delete it
:param thread_id: User/Group ID to mark as spam. See :ref:`intro_threads`
:return: Whether the request was successful
:raises: FBchatException if request failed
"""
thread_id, thread_type = self._getThread(thread_id, None)
r = self._post(self.req_url.MARK_SPAM, {"id": thread_id})
return r.ok | python | def markAsSpam(self, thread_id=None):
thread_id, thread_type = self._getThread(thread_id, None)
r = self._post(self.req_url.MARK_SPAM, {"id": thread_id})
return r.ok | [
"def",
"markAsSpam",
"(",
"self",
",",
"thread_id",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"None",
")",
"r",
"=",
"self",
".",
"_post",
"(",
"self",
".",
"req_url",
".",
"MARK_SPAM... | Mark a thread as spam and delete it
:param thread_id: User/Group ID to mark as spam. See :ref:`intro_threads`
:return: Whether the request was successful
:raises: FBchatException if request failed | [
"Mark",
"a",
"thread",
"as",
"spam",
"and",
"delete",
"it"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2307-L2317 |
234,161 | carpedm20/fbchat | fbchat/_client.py | Client.deleteMessages | def deleteMessages(self, message_ids):
"""
Deletes specifed messages
:param message_ids: Message IDs to delete
:return: Whether the request was successful
:raises: FBchatException if request failed
"""
message_ids = require_list(message_ids)
data = dict()
for i, message_id in enumerate(message_ids):
data["message_ids[{}]".format(i)] = message_id
r = self._post(self.req_url.DELETE_MESSAGES, data)
return r.ok | python | def deleteMessages(self, message_ids):
message_ids = require_list(message_ids)
data = dict()
for i, message_id in enumerate(message_ids):
data["message_ids[{}]".format(i)] = message_id
r = self._post(self.req_url.DELETE_MESSAGES, data)
return r.ok | [
"def",
"deleteMessages",
"(",
"self",
",",
"message_ids",
")",
":",
"message_ids",
"=",
"require_list",
"(",
"message_ids",
")",
"data",
"=",
"dict",
"(",
")",
"for",
"i",
",",
"message_id",
"in",
"enumerate",
"(",
"message_ids",
")",
":",
"data",
"[",
"... | Deletes specifed messages
:param message_ids: Message IDs to delete
:return: Whether the request was successful
:raises: FBchatException if request failed | [
"Deletes",
"specifed",
"messages"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2319-L2332 |
234,162 | carpedm20/fbchat | fbchat/_client.py | Client.muteThreadReactions | def muteThreadReactions(self, mute=True, thread_id=None):
"""
Mutes thread reactions
:param mute: Boolean. True to mute, False to unmute
:param thread_id: User/Group ID to mute. See :ref:`intro_threads`
"""
thread_id, thread_type = self._getThread(thread_id, None)
data = {"reactions_mute_mode": int(mute), "thread_fbid": thread_id}
r = self._post(self.req_url.MUTE_REACTIONS, data, fix_request=True) | python | def muteThreadReactions(self, mute=True, thread_id=None):
thread_id, thread_type = self._getThread(thread_id, None)
data = {"reactions_mute_mode": int(mute), "thread_fbid": thread_id}
r = self._post(self.req_url.MUTE_REACTIONS, data, fix_request=True) | [
"def",
"muteThreadReactions",
"(",
"self",
",",
"mute",
"=",
"True",
",",
"thread_id",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"None",
")",
"data",
"=",
"{",
"\"reactions_mute_mode\"",
... | Mutes thread reactions
:param mute: Boolean. True to mute, False to unmute
:param thread_id: User/Group ID to mute. See :ref:`intro_threads` | [
"Mutes",
"thread",
"reactions"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2353-L2362 |
234,163 | carpedm20/fbchat | fbchat/_client.py | Client.muteThreadMentions | def muteThreadMentions(self, mute=True, thread_id=None):
"""
Mutes thread mentions
:param mute: Boolean. True to mute, False to unmute
:param thread_id: User/Group ID to mute. See :ref:`intro_threads`
"""
thread_id, thread_type = self._getThread(thread_id, None)
data = {"mentions_mute_mode": int(mute), "thread_fbid": thread_id}
r = self._post(self.req_url.MUTE_MENTIONS, data, fix_request=True) | python | def muteThreadMentions(self, mute=True, thread_id=None):
thread_id, thread_type = self._getThread(thread_id, None)
data = {"mentions_mute_mode": int(mute), "thread_fbid": thread_id}
r = self._post(self.req_url.MUTE_MENTIONS, data, fix_request=True) | [
"def",
"muteThreadMentions",
"(",
"self",
",",
"mute",
"=",
"True",
",",
"thread_id",
"=",
"None",
")",
":",
"thread_id",
",",
"thread_type",
"=",
"self",
".",
"_getThread",
"(",
"thread_id",
",",
"None",
")",
"data",
"=",
"{",
"\"mentions_mute_mode\"",
":... | Mutes thread mentions
:param mute: Boolean. True to mute, False to unmute
:param thread_id: User/Group ID to mute. See :ref:`intro_threads` | [
"Mutes",
"thread",
"mentions"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2372-L2381 |
234,164 | carpedm20/fbchat | fbchat/_client.py | Client._pullMessage | def _pullMessage(self):
"""Call pull api with seq value to get message data."""
data = {
"msgs_recv": 0,
"sticky_token": self._sticky,
"sticky_pool": self._pool,
"clientid": self._client_id,
"state": "active" if self._markAlive else "offline",
}
return self._get(self.req_url.STICKY, data, fix_request=True, as_json=True) | python | def _pullMessage(self):
data = {
"msgs_recv": 0,
"sticky_token": self._sticky,
"sticky_pool": self._pool,
"clientid": self._client_id,
"state": "active" if self._markAlive else "offline",
}
return self._get(self.req_url.STICKY, data, fix_request=True, as_json=True) | [
"def",
"_pullMessage",
"(",
"self",
")",
":",
"data",
"=",
"{",
"\"msgs_recv\"",
":",
"0",
",",
"\"sticky_token\"",
":",
"self",
".",
"_sticky",
",",
"\"sticky_pool\"",
":",
"self",
".",
"_pool",
",",
"\"clientid\"",
":",
"self",
".",
"_client_id",
",",
... | Call pull api with seq value to get message data. | [
"Call",
"pull",
"api",
"with",
"seq",
"value",
"to",
"get",
"message",
"data",
"."
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2409-L2418 |
234,165 | carpedm20/fbchat | fbchat/_client.py | Client._parseMessage | def _parseMessage(self, content):
"""Get message and author name from content. May contain multiple messages in the content."""
self._seq = content.get("seq", "0")
if "lb_info" in content:
self._sticky = content["lb_info"]["sticky"]
self._pool = content["lb_info"]["pool"]
if "batches" in content:
for batch in content["batches"]:
self._parseMessage(batch)
if "ms" not in content:
return
for m in content["ms"]:
mtype = m.get("type")
try:
# Things that directly change chat
if mtype == "delta":
self._parseDelta(m)
# Inbox
elif mtype == "inbox":
self.onInbox(
unseen=m["unseen"],
unread=m["unread"],
recent_unread=m["recent_unread"],
msg=m,
)
# Typing
elif mtype == "typ" or mtype == "ttyp":
author_id = str(m.get("from"))
thread_id = m.get("thread_fbid")
if thread_id:
thread_type = ThreadType.GROUP
thread_id = str(thread_id)
else:
thread_type = ThreadType.USER
if author_id == self._uid:
thread_id = m.get("to")
else:
thread_id = author_id
typing_status = TypingStatus(m.get("st"))
self.onTyping(
author_id=author_id,
status=typing_status,
thread_id=thread_id,
thread_type=thread_type,
msg=m,
)
# Delivered
# Seen
# elif mtype == "m_read_receipt":
#
# self.onSeen(m.get('realtime_viewer_fbid'), m.get('reader'), m.get('time'))
elif mtype in ["jewel_requests_add"]:
from_id = m["from"]
self.onFriendRequest(from_id=from_id, msg=m)
# Happens on every login
elif mtype == "qprimer":
self.onQprimer(ts=m.get("made"), msg=m)
# Is sent before any other message
elif mtype == "deltaflow":
pass
# Chat timestamp
elif mtype == "chatproxy-presence":
statuses = dict()
for id_, data in m.get("buddyList", {}).items():
statuses[id_] = ActiveStatus._from_chatproxy_presence(id_, data)
self._buddylist[id_] = statuses[id_]
self.onChatTimestamp(buddylist=statuses, msg=m)
# Buddylist overlay
elif mtype == "buddylist_overlay":
statuses = dict()
for id_, data in m.get("overlay", {}).items():
old_in_game = None
if id_ in self._buddylist:
old_in_game = self._buddylist[id_].in_game
statuses[id_] = ActiveStatus._from_buddylist_overlay(
data, old_in_game
)
self._buddylist[id_] = statuses[id_]
self.onBuddylistOverlay(statuses=statuses, msg=m)
# Unknown message type
else:
self.onUnknownMesssageType(msg=m)
except Exception as e:
self.onMessageError(exception=e, msg=m) | python | def _parseMessage(self, content):
self._seq = content.get("seq", "0")
if "lb_info" in content:
self._sticky = content["lb_info"]["sticky"]
self._pool = content["lb_info"]["pool"]
if "batches" in content:
for batch in content["batches"]:
self._parseMessage(batch)
if "ms" not in content:
return
for m in content["ms"]:
mtype = m.get("type")
try:
# Things that directly change chat
if mtype == "delta":
self._parseDelta(m)
# Inbox
elif mtype == "inbox":
self.onInbox(
unseen=m["unseen"],
unread=m["unread"],
recent_unread=m["recent_unread"],
msg=m,
)
# Typing
elif mtype == "typ" or mtype == "ttyp":
author_id = str(m.get("from"))
thread_id = m.get("thread_fbid")
if thread_id:
thread_type = ThreadType.GROUP
thread_id = str(thread_id)
else:
thread_type = ThreadType.USER
if author_id == self._uid:
thread_id = m.get("to")
else:
thread_id = author_id
typing_status = TypingStatus(m.get("st"))
self.onTyping(
author_id=author_id,
status=typing_status,
thread_id=thread_id,
thread_type=thread_type,
msg=m,
)
# Delivered
# Seen
# elif mtype == "m_read_receipt":
#
# self.onSeen(m.get('realtime_viewer_fbid'), m.get('reader'), m.get('time'))
elif mtype in ["jewel_requests_add"]:
from_id = m["from"]
self.onFriendRequest(from_id=from_id, msg=m)
# Happens on every login
elif mtype == "qprimer":
self.onQprimer(ts=m.get("made"), msg=m)
# Is sent before any other message
elif mtype == "deltaflow":
pass
# Chat timestamp
elif mtype == "chatproxy-presence":
statuses = dict()
for id_, data in m.get("buddyList", {}).items():
statuses[id_] = ActiveStatus._from_chatproxy_presence(id_, data)
self._buddylist[id_] = statuses[id_]
self.onChatTimestamp(buddylist=statuses, msg=m)
# Buddylist overlay
elif mtype == "buddylist_overlay":
statuses = dict()
for id_, data in m.get("overlay", {}).items():
old_in_game = None
if id_ in self._buddylist:
old_in_game = self._buddylist[id_].in_game
statuses[id_] = ActiveStatus._from_buddylist_overlay(
data, old_in_game
)
self._buddylist[id_] = statuses[id_]
self.onBuddylistOverlay(statuses=statuses, msg=m)
# Unknown message type
else:
self.onUnknownMesssageType(msg=m)
except Exception as e:
self.onMessageError(exception=e, msg=m) | [
"def",
"_parseMessage",
"(",
"self",
",",
"content",
")",
":",
"self",
".",
"_seq",
"=",
"content",
".",
"get",
"(",
"\"seq\"",
",",
"\"0\"",
")",
"if",
"\"lb_info\"",
"in",
"content",
":",
"self",
".",
"_sticky",
"=",
"content",
"[",
"\"lb_info\"",
"]... | Get message and author name from content. May contain multiple messages in the content. | [
"Get",
"message",
"and",
"author",
"name",
"from",
"content",
".",
"May",
"contain",
"multiple",
"messages",
"in",
"the",
"content",
"."
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L2966-L3066 |
234,166 | carpedm20/fbchat | fbchat/_client.py | Client.doOneListen | def doOneListen(self, markAlive=None):
"""
Does one cycle of the listening loop.
This method is useful if you want to control fbchat from an external event loop
.. warning::
`markAlive` parameter is deprecated now, use :func:`fbchat.Client.setActiveStatus`
or `markAlive` parameter in :func:`fbchat.Client.listen` instead.
:return: Whether the loop should keep running
:rtype: bool
"""
if markAlive is not None:
self._markAlive = markAlive
try:
if self._markAlive:
self._ping()
content = self._pullMessage()
if content:
self._parseMessage(content)
except KeyboardInterrupt:
return False
except requests.Timeout:
pass
except requests.ConnectionError:
# If the client has lost their internet connection, keep trying every 30 seconds
time.sleep(30)
except FBchatFacebookError as e:
# Fix 502 and 503 pull errors
if e.request_status_code in [502, 503]:
self.req_url.change_pull_channel()
self.startListening()
else:
raise e
except Exception as e:
return self.onListenError(exception=e)
return True | python | def doOneListen(self, markAlive=None):
if markAlive is not None:
self._markAlive = markAlive
try:
if self._markAlive:
self._ping()
content = self._pullMessage()
if content:
self._parseMessage(content)
except KeyboardInterrupt:
return False
except requests.Timeout:
pass
except requests.ConnectionError:
# If the client has lost their internet connection, keep trying every 30 seconds
time.sleep(30)
except FBchatFacebookError as e:
# Fix 502 and 503 pull errors
if e.request_status_code in [502, 503]:
self.req_url.change_pull_channel()
self.startListening()
else:
raise e
except Exception as e:
return self.onListenError(exception=e)
return True | [
"def",
"doOneListen",
"(",
"self",
",",
"markAlive",
"=",
"None",
")",
":",
"if",
"markAlive",
"is",
"not",
"None",
":",
"self",
".",
"_markAlive",
"=",
"markAlive",
"try",
":",
"if",
"self",
".",
"_markAlive",
":",
"self",
".",
"_ping",
"(",
")",
"c... | Does one cycle of the listening loop.
This method is useful if you want to control fbchat from an external event loop
.. warning::
`markAlive` parameter is deprecated now, use :func:`fbchat.Client.setActiveStatus`
or `markAlive` parameter in :func:`fbchat.Client.listen` instead.
:return: Whether the loop should keep running
:rtype: bool | [
"Does",
"one",
"cycle",
"of",
"the",
"listening",
"loop",
".",
"This",
"method",
"is",
"useful",
"if",
"you",
"want",
"to",
"control",
"fbchat",
"from",
"an",
"external",
"event",
"loop"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3076-L3113 |
234,167 | carpedm20/fbchat | fbchat/_client.py | Client.listen | def listen(self, markAlive=None):
"""
Initializes and runs the listening loop continually
:param markAlive: Whether this should ping the Facebook server each time the loop runs
:type markAlive: bool
"""
if markAlive is not None:
self.setActiveStatus(markAlive)
self.startListening()
self.onListening()
while self.listening and self.doOneListen():
pass
self.stopListening() | python | def listen(self, markAlive=None):
if markAlive is not None:
self.setActiveStatus(markAlive)
self.startListening()
self.onListening()
while self.listening and self.doOneListen():
pass
self.stopListening() | [
"def",
"listen",
"(",
"self",
",",
"markAlive",
"=",
"None",
")",
":",
"if",
"markAlive",
"is",
"not",
"None",
":",
"self",
".",
"setActiveStatus",
"(",
"markAlive",
")",
"self",
".",
"startListening",
"(",
")",
"self",
".",
"onListening",
"(",
")",
"w... | Initializes and runs the listening loop continually
:param markAlive: Whether this should ping the Facebook server each time the loop runs
:type markAlive: bool | [
"Initializes",
"and",
"runs",
"the",
"listening",
"loop",
"continually"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3120-L3136 |
234,168 | carpedm20/fbchat | fbchat/_client.py | Client.onMessage | def onMessage(
self,
mid=None,
author_id=None,
message=None,
message_object=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody sends a message
:param mid: The message ID
:param author_id: The ID of the author
:param message: (deprecated. Use `message_object.text` instead)
:param message_object: The message (As a `Message` object)
:param thread_id: Thread ID that the message was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the message was sent to. See :ref:`intro_threads`
:param ts: The timestamp of the message
:param metadata: Extra metadata about the message
:param msg: A full set of the data recieved
:type message_object: models.Message
:type thread_type: models.ThreadType
"""
log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) | python | def onMessage(
self,
mid=None,
author_id=None,
message=None,
message_object=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name)) | [
"def",
"onMessage",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"message",
"=",
"None",
",",
"message_object",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
",",
"ts",
"=",... | Called when the client is listening, and somebody sends a message
:param mid: The message ID
:param author_id: The ID of the author
:param message: (deprecated. Use `message_object.text` instead)
:param message_object: The message (As a `Message` object)
:param thread_id: Thread ID that the message was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the message was sent to. See :ref:`intro_threads`
:param ts: The timestamp of the message
:param metadata: Extra metadata about the message
:param msg: A full set of the data recieved
:type message_object: models.Message
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"sends",
"a",
"message"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3189-L3216 |
234,169 | carpedm20/fbchat | fbchat/_client.py | Client.onColorChange | def onColorChange(
self,
mid=None,
author_id=None,
new_color=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody changes a thread's color
:param mid: The action ID
:param author_id: The ID of the person who changed the color
:param new_color: The new color
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type new_color: models.ThreadColor
:type thread_type: models.ThreadType
"""
log.info(
"Color change from {} in {} ({}): {}".format(
author_id, thread_id, thread_type.name, new_color
)
) | python | def onColorChange(
self,
mid=None,
author_id=None,
new_color=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
log.info(
"Color change from {} in {} ({}): {}".format(
author_id, thread_id, thread_type.name, new_color
)
) | [
"def",
"onColorChange",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"new_color",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
",",
"ts",
"=",
"None",
",",
"metadata",
"=",... | Called when the client is listening, and somebody changes a thread's color
:param mid: The action ID
:param author_id: The ID of the person who changed the color
:param new_color: The new color
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type new_color: models.ThreadColor
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"changes",
"a",
"thread",
"s",
"color"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3218-L3247 |
234,170 | carpedm20/fbchat | fbchat/_client.py | Client.onEmojiChange | def onEmojiChange(
self,
mid=None,
author_id=None,
new_emoji=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody changes a thread's emoji
:param mid: The action ID
:param author_id: The ID of the person who changed the emoji
:param new_emoji: The new emoji
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
"""
log.info(
"Emoji change from {} in {} ({}): {}".format(
author_id, thread_id, thread_type.name, new_emoji
)
) | python | def onEmojiChange(
self,
mid=None,
author_id=None,
new_emoji=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
log.info(
"Emoji change from {} in {} ({}): {}".format(
author_id, thread_id, thread_type.name, new_emoji
)
) | [
"def",
"onEmojiChange",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"new_emoji",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
",",
"ts",
"=",
"None",
",",
"metadata",
"=",... | Called when the client is listening, and somebody changes a thread's emoji
:param mid: The action ID
:param author_id: The ID of the person who changed the emoji
:param new_emoji: The new emoji
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"changes",
"a",
"thread",
"s",
"emoji"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3249-L3277 |
234,171 | carpedm20/fbchat | fbchat/_client.py | Client.onTitleChange | def onTitleChange(
self,
mid=None,
author_id=None,
new_title=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody changes the title of a thread
:param mid: The action ID
:param author_id: The ID of the person who changed the title
:param new_title: The new title
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
"""
log.info(
"Title change from {} in {} ({}): {}".format(
author_id, thread_id, thread_type.name, new_title
)
) | python | def onTitleChange(
self,
mid=None,
author_id=None,
new_title=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
log.info(
"Title change from {} in {} ({}): {}".format(
author_id, thread_id, thread_type.name, new_title
)
) | [
"def",
"onTitleChange",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"new_title",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
",",
"ts",
"=",
"None",
",",
"metadata",
"=",... | Called when the client is listening, and somebody changes the title of a thread
:param mid: The action ID
:param author_id: The ID of the person who changed the title
:param new_title: The new title
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"changes",
"the",
"title",
"of",
"a",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3279-L3307 |
234,172 | carpedm20/fbchat | fbchat/_client.py | Client.onImageChange | def onImageChange(
self,
mid=None,
author_id=None,
new_image=None,
thread_id=None,
thread_type=ThreadType.GROUP,
ts=None,
msg=None,
):
"""
Called when the client is listening, and somebody changes the image of a thread
:param mid: The action ID
:param author_id: The ID of the person who changed the image
:param new_image: The ID of the new image
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
"""
log.info("{} changed thread image in {}".format(author_id, thread_id)) | python | def onImageChange(
self,
mid=None,
author_id=None,
new_image=None,
thread_id=None,
thread_type=ThreadType.GROUP,
ts=None,
msg=None,
):
log.info("{} changed thread image in {}".format(author_id, thread_id)) | [
"def",
"onImageChange",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"new_image",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"GROUP",
",",
"ts",
"=",
"None",
",",
"msg",
"=",
"... | Called when the client is listening, and somebody changes the image of a thread
:param mid: The action ID
:param author_id: The ID of the person who changed the image
:param new_image: The ID of the new image
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"changes",
"the",
"image",
"of",
"a",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3309-L3331 |
234,173 | carpedm20/fbchat | fbchat/_client.py | Client.onNicknameChange | def onNicknameChange(
self,
mid=None,
author_id=None,
changed_for=None,
new_nickname=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody changes the nickname of a person
:param mid: The action ID
:param author_id: The ID of the person who changed the nickname
:param changed_for: The ID of the person whom got their nickname changed
:param new_nickname: The new nickname
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
"""
log.info(
"Nickname change from {} in {} ({}) for {}: {}".format(
author_id, thread_id, thread_type.name, changed_for, new_nickname
)
) | python | def onNicknameChange(
self,
mid=None,
author_id=None,
changed_for=None,
new_nickname=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
log.info(
"Nickname change from {} in {} ({}) for {}: {}".format(
author_id, thread_id, thread_type.name, changed_for, new_nickname
)
) | [
"def",
"onNicknameChange",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"changed_for",
"=",
"None",
",",
"new_nickname",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
",",
"ts... | Called when the client is listening, and somebody changes the nickname of a person
:param mid: The action ID
:param author_id: The ID of the person who changed the nickname
:param changed_for: The ID of the person whom got their nickname changed
:param new_nickname: The new nickname
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"changes",
"the",
"nickname",
"of",
"a",
"person"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3333-L3363 |
234,174 | carpedm20/fbchat | fbchat/_client.py | Client.onAdminAdded | def onAdminAdded(
self,
mid=None,
added_id=None,
author_id=None,
thread_id=None,
thread_type=ThreadType.GROUP,
ts=None,
msg=None,
):
"""
Called when the client is listening, and somebody adds an admin to a group thread
:param mid: The action ID
:param added_id: The ID of the admin who got added
:param author_id: The ID of the person who added the admins
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
"""
log.info("{} added admin: {} in {}".format(author_id, added_id, thread_id)) | python | def onAdminAdded(
self,
mid=None,
added_id=None,
author_id=None,
thread_id=None,
thread_type=ThreadType.GROUP,
ts=None,
msg=None,
):
log.info("{} added admin: {} in {}".format(author_id, added_id, thread_id)) | [
"def",
"onAdminAdded",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"added_id",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"GROUP",
",",
"ts",
"=",
"None",
",",
"msg",
"=",
"No... | Called when the client is listening, and somebody adds an admin to a group thread
:param mid: The action ID
:param added_id: The ID of the admin who got added
:param author_id: The ID of the person who added the admins
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"adds",
"an",
"admin",
"to",
"a",
"group",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3365-L3385 |
234,175 | carpedm20/fbchat | fbchat/_client.py | Client.onAdminRemoved | def onAdminRemoved(
self,
mid=None,
removed_id=None,
author_id=None,
thread_id=None,
thread_type=ThreadType.GROUP,
ts=None,
msg=None,
):
"""
Called when the client is listening, and somebody removes an admin from a group thread
:param mid: The action ID
:param removed_id: The ID of the admin who got removed
:param author_id: The ID of the person who removed the admins
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
"""
log.info("{} removed admin: {} in {}".format(author_id, removed_id, thread_id)) | python | def onAdminRemoved(
self,
mid=None,
removed_id=None,
author_id=None,
thread_id=None,
thread_type=ThreadType.GROUP,
ts=None,
msg=None,
):
log.info("{} removed admin: {} in {}".format(author_id, removed_id, thread_id)) | [
"def",
"onAdminRemoved",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"removed_id",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"GROUP",
",",
"ts",
"=",
"None",
",",
"msg",
"=",
... | Called when the client is listening, and somebody removes an admin from a group thread
:param mid: The action ID
:param removed_id: The ID of the admin who got removed
:param author_id: The ID of the person who removed the admins
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"removes",
"an",
"admin",
"from",
"a",
"group",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3387-L3407 |
234,176 | carpedm20/fbchat | fbchat/_client.py | Client.onApprovalModeChange | def onApprovalModeChange(
self,
mid=None,
approval_mode=None,
author_id=None,
thread_id=None,
thread_type=ThreadType.GROUP,
ts=None,
msg=None,
):
"""
Called when the client is listening, and somebody changes approval mode in a group thread
:param mid: The action ID
:param approval_mode: True if approval mode is activated
:param author_id: The ID of the person who changed approval mode
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
"""
if approval_mode:
log.info("{} activated approval mode in {}".format(author_id, thread_id))
else:
log.info("{} disabled approval mode in {}".format(author_id, thread_id)) | python | def onApprovalModeChange(
self,
mid=None,
approval_mode=None,
author_id=None,
thread_id=None,
thread_type=ThreadType.GROUP,
ts=None,
msg=None,
):
if approval_mode:
log.info("{} activated approval mode in {}".format(author_id, thread_id))
else:
log.info("{} disabled approval mode in {}".format(author_id, thread_id)) | [
"def",
"onApprovalModeChange",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"approval_mode",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"GROUP",
",",
"ts",
"=",
"None",
",",
"msg",... | Called when the client is listening, and somebody changes approval mode in a group thread
:param mid: The action ID
:param approval_mode: True if approval mode is activated
:param author_id: The ID of the person who changed approval mode
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"changes",
"approval",
"mode",
"in",
"a",
"group",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3409-L3432 |
234,177 | carpedm20/fbchat | fbchat/_client.py | Client.onMessageSeen | def onMessageSeen(
self,
seen_by=None,
thread_id=None,
thread_type=ThreadType.USER,
seen_ts=None,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody marks a message as seen
:param seen_by: The ID of the person who marked the message as seen
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param seen_ts: A timestamp of when the person saw the message
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
"""
log.info(
"Messages seen by {} in {} ({}) at {}s".format(
seen_by, thread_id, thread_type.name, seen_ts / 1000
)
) | python | def onMessageSeen(
self,
seen_by=None,
thread_id=None,
thread_type=ThreadType.USER,
seen_ts=None,
ts=None,
metadata=None,
msg=None,
):
log.info(
"Messages seen by {} in {} ({}) at {}s".format(
seen_by, thread_id, thread_type.name, seen_ts / 1000
)
) | [
"def",
"onMessageSeen",
"(",
"self",
",",
"seen_by",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
",",
"seen_ts",
"=",
"None",
",",
"ts",
"=",
"None",
",",
"metadata",
"=",
"None",
",",
"msg",
"=",
"... | Called when the client is listening, and somebody marks a message as seen
:param seen_by: The ID of the person who marked the message as seen
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param seen_ts: A timestamp of when the person saw the message
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"marks",
"a",
"message",
"as",
"seen"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3434-L3460 |
234,178 | carpedm20/fbchat | fbchat/_client.py | Client.onMessageDelivered | def onMessageDelivered(
self,
msg_ids=None,
delivered_for=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody marks messages as delivered
:param msg_ids: The messages that are marked as delivered
:param delivered_for: The person that marked the messages as delivered
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
"""
log.info(
"Messages {} delivered to {} in {} ({}) at {}s".format(
msg_ids, delivered_for, thread_id, thread_type.name, ts / 1000
)
) | python | def onMessageDelivered(
self,
msg_ids=None,
delivered_for=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
log.info(
"Messages {} delivered to {} in {} ({}) at {}s".format(
msg_ids, delivered_for, thread_id, thread_type.name, ts / 1000
)
) | [
"def",
"onMessageDelivered",
"(",
"self",
",",
"msg_ids",
"=",
"None",
",",
"delivered_for",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"ThreadType",
".",
"USER",
",",
"ts",
"=",
"None",
",",
"metadata",
"=",
"None",
",",
"msg",... | Called when the client is listening, and somebody marks messages as delivered
:param msg_ids: The messages that are marked as delivered
:param delivered_for: The person that marked the messages as delivered
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"marks",
"messages",
"as",
"delivered"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3462-L3488 |
234,179 | carpedm20/fbchat | fbchat/_client.py | Client.onMarkedSeen | def onMarkedSeen(
self, threads=None, seen_ts=None, ts=None, metadata=None, msg=None
):
"""
Called when the client is listening, and the client has successfully marked threads as seen
:param threads: The threads that were marked
:param author_id: The ID of the person who changed the emoji
:param seen_ts: A timestamp of when the threads were seen
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
"""
log.info(
"Marked messages as seen in threads {} at {}s".format(
[(x[0], x[1].name) for x in threads], seen_ts / 1000
)
) | python | def onMarkedSeen(
self, threads=None, seen_ts=None, ts=None, metadata=None, msg=None
):
log.info(
"Marked messages as seen in threads {} at {}s".format(
[(x[0], x[1].name) for x in threads], seen_ts / 1000
)
) | [
"def",
"onMarkedSeen",
"(",
"self",
",",
"threads",
"=",
"None",
",",
"seen_ts",
"=",
"None",
",",
"ts",
"=",
"None",
",",
"metadata",
"=",
"None",
",",
"msg",
"=",
"None",
")",
":",
"log",
".",
"info",
"(",
"\"Marked messages as seen in threads {} at {}s\... | Called when the client is listening, and the client has successfully marked threads as seen
:param threads: The threads that were marked
:param author_id: The ID of the person who changed the emoji
:param seen_ts: A timestamp of when the threads were seen
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"the",
"client",
"has",
"successfully",
"marked",
"threads",
"as",
"seen"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3490-L3508 |
234,180 | carpedm20/fbchat | fbchat/_client.py | Client.onPeopleAdded | def onPeopleAdded(
self,
mid=None,
added_ids=None,
author_id=None,
thread_id=None,
ts=None,
msg=None,
):
"""
Called when the client is listening, and somebody adds people to a group thread
:param mid: The action ID
:param added_ids: The IDs of the people who got added
:param author_id: The ID of the person who added the people
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
"""
log.info(
"{} added: {} in {}".format(author_id, ", ".join(added_ids), thread_id)
) | python | def onPeopleAdded(
self,
mid=None,
added_ids=None,
author_id=None,
thread_id=None,
ts=None,
msg=None,
):
log.info(
"{} added: {} in {}".format(author_id, ", ".join(added_ids), thread_id)
) | [
"def",
"onPeopleAdded",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"added_ids",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"ts",
"=",
"None",
",",
"msg",
"=",
"None",
",",
")",
":",
"log",
".",
"info",
"(",
"\... | Called when the client is listening, and somebody adds people to a group thread
:param mid: The action ID
:param added_ids: The IDs of the people who got added
:param author_id: The ID of the person who added the people
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"adds",
"people",
"to",
"a",
"group",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3536-L3557 |
234,181 | carpedm20/fbchat | fbchat/_client.py | Client.onPersonRemoved | def onPersonRemoved(
self,
mid=None,
removed_id=None,
author_id=None,
thread_id=None,
ts=None,
msg=None,
):
"""
Called when the client is listening, and somebody removes a person from a group thread
:param mid: The action ID
:param removed_id: The ID of the person who got removed
:param author_id: The ID of the person who removed the person
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
"""
log.info("{} removed: {} in {}".format(author_id, removed_id, thread_id)) | python | def onPersonRemoved(
self,
mid=None,
removed_id=None,
author_id=None,
thread_id=None,
ts=None,
msg=None,
):
log.info("{} removed: {} in {}".format(author_id, removed_id, thread_id)) | [
"def",
"onPersonRemoved",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"removed_id",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"ts",
"=",
"None",
",",
"msg",
"=",
"None",
",",
")",
":",
"log",
".",
"info",
"(",
... | Called when the client is listening, and somebody removes a person from a group thread
:param mid: The action ID
:param removed_id: The ID of the person who got removed
:param author_id: The ID of the person who removed the person
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"removes",
"a",
"person",
"from",
"a",
"group",
"thread"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3559-L3578 |
234,182 | carpedm20/fbchat | fbchat/_client.py | Client.onGamePlayed | def onGamePlayed(
self,
mid=None,
author_id=None,
game_id=None,
game_name=None,
score=None,
leaderboard=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody plays a game
:param mid: The action ID
:param author_id: The ID of the person who played the game
:param game_id: The ID of the game
:param game_name: Name of the game
:param score: Score obtained in the game
:param leaderboard: Actual leaderboard of the game in the thread
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
"""
log.info(
'{} played "{}" in {} ({})'.format(
author_id, game_name, thread_id, thread_type.name
)
) | python | def onGamePlayed(
self,
mid=None,
author_id=None,
game_id=None,
game_name=None,
score=None,
leaderboard=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
log.info(
'{} played "{}" in {} ({})'.format(
author_id, game_name, thread_id, thread_type.name
)
) | [
"def",
"onGamePlayed",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"game_id",
"=",
"None",
",",
"game_name",
"=",
"None",
",",
"score",
"=",
"None",
",",
"leaderboard",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"t... | Called when the client is listening, and somebody plays a game
:param mid: The action ID
:param author_id: The ID of the person who played the game
:param game_id: The ID of the game
:param game_name: Name of the game
:param score: Score obtained in the game
:param leaderboard: Actual leaderboard of the game in the thread
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"plays",
"a",
"game"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3617-L3651 |
234,183 | carpedm20/fbchat | fbchat/_client.py | Client.onReactionAdded | def onReactionAdded(
self,
mid=None,
reaction=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
msg=None,
):
"""
Called when the client is listening, and somebody reacts to a message
:param mid: Message ID, that user reacted to
:param reaction: Reaction
:param add_reaction: Whether user added or removed reaction
:param author_id: The ID of the person who reacted to the message
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
:type reaction: models.MessageReaction
:type thread_type: models.ThreadType
"""
log.info(
"{} reacted to message {} with {} in {} ({})".format(
author_id, mid, reaction.name, thread_id, thread_type.name
)
) | python | def onReactionAdded(
self,
mid=None,
reaction=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
msg=None,
):
log.info(
"{} reacted to message {} with {} in {} ({})".format(
author_id, mid, reaction.name, thread_id, thread_type.name
)
) | [
"def",
"onReactionAdded",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"reaction",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
",",
"ts",
"=",
"None",
",",
"msg",
"=",
"None",
",",
")",
... | Called when the client is listening, and somebody reacts to a message
:param mid: Message ID, that user reacted to
:param reaction: Reaction
:param add_reaction: Whether user added or removed reaction
:param author_id: The ID of the person who reacted to the message
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
:type reaction: models.MessageReaction
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"reacts",
"to",
"a",
"message"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3653-L3681 |
234,184 | carpedm20/fbchat | fbchat/_client.py | Client.onReactionRemoved | def onReactionRemoved(
self,
mid=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
msg=None,
):
"""
Called when the client is listening, and somebody removes reaction from a message
:param mid: Message ID, that user reacted to
:param author_id: The ID of the person who removed reaction
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
"""
log.info(
"{} removed reaction from {} message in {} ({})".format(
author_id, mid, thread_id, thread_type
)
) | python | def onReactionRemoved(
self,
mid=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
msg=None,
):
log.info(
"{} removed reaction from {} message in {} ({})".format(
author_id, mid, thread_id, thread_type
)
) | [
"def",
"onReactionRemoved",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
",",
"ts",
"=",
"None",
",",
"msg",
"=",
"None",
",",
")",
":",
"log",
".",
"info",
"("... | Called when the client is listening, and somebody removes reaction from a message
:param mid: Message ID, that user reacted to
:param author_id: The ID of the person who removed reaction
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"removes",
"reaction",
"from",
"a",
"message"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3683-L3707 |
234,185 | carpedm20/fbchat | fbchat/_client.py | Client.onBlock | def onBlock(
self, author_id=None, thread_id=None, thread_type=None, ts=None, msg=None
):
"""
Called when the client is listening, and somebody blocks client
:param author_id: The ID of the person who blocked
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
"""
log.info(
"{} blocked {} ({}) thread".format(author_id, thread_id, thread_type.name)
) | python | def onBlock(
self, author_id=None, thread_id=None, thread_type=None, ts=None, msg=None
):
log.info(
"{} blocked {} ({}) thread".format(author_id, thread_id, thread_type.name)
) | [
"def",
"onBlock",
"(",
"self",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
",",
"ts",
"=",
"None",
",",
"msg",
"=",
"None",
")",
":",
"log",
".",
"info",
"(",
"\"{} blocked {} ({}) thread\"",
".",
"for... | Called when the client is listening, and somebody blocks client
:param author_id: The ID of the person who blocked
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"blocks",
"client"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3709-L3724 |
234,186 | carpedm20/fbchat | fbchat/_client.py | Client.onLiveLocation | def onLiveLocation(
self,
mid=None,
location=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
msg=None,
):
"""
Called when the client is listening and somebody sends live location info
:param mid: The action ID
:param location: Sent location info
:param author_id: The ID of the person who sent location info
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
:type location: models.LiveLocationAttachment
:type thread_type: models.ThreadType
"""
log.info(
"{} sent live location info in {} ({}) with latitude {} and longitude {}".format(
author_id, thread_id, thread_type, location.latitude, location.longitude
)
) | python | def onLiveLocation(
self,
mid=None,
location=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
msg=None,
):
log.info(
"{} sent live location info in {} ({}) with latitude {} and longitude {}".format(
author_id, thread_id, thread_type, location.latitude, location.longitude
)
) | [
"def",
"onLiveLocation",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"location",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
",",
"ts",
"=",
"None",
",",
"msg",
"=",
"None",
",",
")",
"... | Called when the client is listening and somebody sends live location info
:param mid: The action ID
:param location: Sent location info
:param author_id: The ID of the person who sent location info
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param msg: A full set of the data recieved
:type location: models.LiveLocationAttachment
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"sends",
"live",
"location",
"info"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3743-L3770 |
234,187 | carpedm20/fbchat | fbchat/_client.py | Client.onUserJoinedCall | def onUserJoinedCall(
self,
mid=None,
joined_id=None,
is_video_call=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody joins a group call
:param mid: The action ID
:param joined_id: The ID of the person who joined the call
:param is_video_call: True if it's video call
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType
"""
log.info(
"{} joined call in {} ({})".format(joined_id, thread_id, thread_type.name)
) | python | def onUserJoinedCall(
self,
mid=None,
joined_id=None,
is_video_call=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
log.info(
"{} joined call in {} ({})".format(joined_id, thread_id, thread_type.name)
) | [
"def",
"onUserJoinedCall",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"joined_id",
"=",
"None",
",",
"is_video_call",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
",",
"ts",
"=",
"None",
",",
"metadata",
"=",
"None",
","... | Called when the client is listening, and somebody joins a group call
:param mid: The action ID
:param joined_id: The ID of the person who joined the call
:param is_video_call: True if it's video call
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"joins",
"a",
"group",
"call"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3836-L3862 |
234,188 | carpedm20/fbchat | fbchat/_client.py | Client.onPollCreated | def onPollCreated(
self,
mid=None,
poll=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody creates a group poll
:param mid: The action ID
:param poll: Created poll
:param author_id: The ID of the person who created the poll
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type poll: models.Poll
:type thread_type: models.ThreadType
"""
log.info(
"{} created poll {} in {} ({})".format(
author_id, poll, thread_id, thread_type.name
)
) | python | def onPollCreated(
self,
mid=None,
poll=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
log.info(
"{} created poll {} in {} ({})".format(
author_id, poll, thread_id, thread_type.name
)
) | [
"def",
"onPollCreated",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"poll",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
",",
"ts",
"=",
"None",
",",
"metadata",
"=",
"None",
",",
"msg",
... | Called when the client is listening, and somebody creates a group poll
:param mid: The action ID
:param poll: Created poll
:param author_id: The ID of the person who created the poll
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type poll: models.Poll
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"creates",
"a",
"group",
"poll"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3864-L3893 |
234,189 | carpedm20/fbchat | fbchat/_client.py | Client.onPollVoted | def onPollVoted(
self,
mid=None,
poll=None,
added_options=None,
removed_options=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody votes in a group poll
:param mid: The action ID
:param poll: Poll, that user voted in
:param author_id: The ID of the person who voted in the poll
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type poll: models.Poll
:type thread_type: models.ThreadType
"""
log.info(
"{} voted in poll {} in {} ({})".format(
author_id, poll, thread_id, thread_type.name
)
) | python | def onPollVoted(
self,
mid=None,
poll=None,
added_options=None,
removed_options=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
log.info(
"{} voted in poll {} in {} ({})".format(
author_id, poll, thread_id, thread_type.name
)
) | [
"def",
"onPollVoted",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"poll",
"=",
"None",
",",
"added_options",
"=",
"None",
",",
"removed_options",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
... | Called when the client is listening, and somebody votes in a group poll
:param mid: The action ID
:param poll: Poll, that user voted in
:param author_id: The ID of the person who voted in the poll
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type poll: models.Poll
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"votes",
"in",
"a",
"group",
"poll"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L3895-L3926 |
234,190 | carpedm20/fbchat | fbchat/_client.py | Client.onPlanDeleted | def onPlanDeleted(
self,
mid=None,
plan=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody deletes a plan
:param mid: The action ID
:param plan: Deleted plan
:param author_id: The ID of the person who deleted the plan
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type plan: models.Plan
:type thread_type: models.ThreadType
"""
log.info(
"{} deleted plan {} in {} ({})".format(
author_id, plan, thread_id, thread_type.name
)
) | python | def onPlanDeleted(
self,
mid=None,
plan=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
log.info(
"{} deleted plan {} in {} ({})".format(
author_id, plan, thread_id, thread_type.name
)
) | [
"def",
"onPlanDeleted",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"plan",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
",",
"ts",
"=",
"None",
",",
"metadata",
"=",
"None",
",",
"msg",
... | Called when the client is listening, and somebody deletes a plan
:param mid: The action ID
:param plan: Deleted plan
:param author_id: The ID of the person who deleted the plan
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type plan: models.Plan
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"deletes",
"a",
"plan"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L4017-L4046 |
234,191 | carpedm20/fbchat | fbchat/_client.py | Client.onPlanParticipation | def onPlanParticipation(
self,
mid=None,
plan=None,
take_part=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""
Called when the client is listening, and somebody takes part in a plan or not
:param mid: The action ID
:param plan: Plan
:param take_part: Whether the person takes part in the plan or not
:param author_id: The ID of the person who will participate in the plan or not
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type plan: models.Plan
:type take_part: bool
:type thread_type: models.ThreadType
"""
if take_part:
log.info(
"{} will take part in {} in {} ({})".format(
author_id, plan, thread_id, thread_type.name
)
)
else:
log.info(
"{} won't take part in {} in {} ({})".format(
author_id, plan, thread_id, thread_type.name
)
) | python | def onPlanParticipation(
self,
mid=None,
plan=None,
take_part=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
if take_part:
log.info(
"{} will take part in {} in {} ({})".format(
author_id, plan, thread_id, thread_type.name
)
)
else:
log.info(
"{} won't take part in {} in {} ({})".format(
author_id, plan, thread_id, thread_type.name
)
) | [
"def",
"onPlanParticipation",
"(",
"self",
",",
"mid",
"=",
"None",
",",
"plan",
"=",
"None",
",",
"take_part",
"=",
"None",
",",
"author_id",
"=",
"None",
",",
"thread_id",
"=",
"None",
",",
"thread_type",
"=",
"None",
",",
"ts",
"=",
"None",
",",
"... | Called when the client is listening, and somebody takes part in a plan or not
:param mid: The action ID
:param plan: Plan
:param take_part: Whether the person takes part in the plan or not
:param author_id: The ID of the person who will participate in the plan or not
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action
:param metadata: Extra metadata about the action
:param msg: A full set of the data recieved
:type plan: models.Plan
:type take_part: bool
:type thread_type: models.ThreadType | [
"Called",
"when",
"the",
"client",
"is",
"listening",
"and",
"somebody",
"takes",
"part",
"in",
"a",
"plan",
"or",
"not"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_client.py#L4048-L4087 |
234,192 | carpedm20/fbchat | fbchat/_graphql.py | graphql_queries_to_json | def graphql_queries_to_json(*queries):
"""
Queries should be a list of GraphQL objects
"""
rtn = {}
for i, query in enumerate(queries):
rtn["q{}".format(i)] = query.value
return json.dumps(rtn) | python | def graphql_queries_to_json(*queries):
rtn = {}
for i, query in enumerate(queries):
rtn["q{}".format(i)] = query.value
return json.dumps(rtn) | [
"def",
"graphql_queries_to_json",
"(",
"*",
"queries",
")",
":",
"rtn",
"=",
"{",
"}",
"for",
"i",
",",
"query",
"in",
"enumerate",
"(",
"queries",
")",
":",
"rtn",
"[",
"\"q{}\"",
".",
"format",
"(",
"i",
")",
"]",
"=",
"query",
".",
"value",
"ret... | Queries should be a list of GraphQL objects | [
"Queries",
"should",
"be",
"a",
"list",
"of",
"GraphQL",
"objects"
] | f480d68b5773473e6daba7f66075ee30e8d737a8 | https://github.com/carpedm20/fbchat/blob/f480d68b5773473e6daba7f66075ee30e8d737a8/fbchat/_graphql.py#L30-L37 |
234,193 | jarun/Buku | bukuserver/server.py | get_tags | def get_tags():
"""get tags."""
tags = getattr(flask.g, 'bukudb', get_bukudb()).get_tag_all()
result = {
'tags': tags[0]
}
if request.path.startswith('/api/'):
res = jsonify(result)
else:
res = render_template('bukuserver/tags.html', result=result)
return res | python | def get_tags():
tags = getattr(flask.g, 'bukudb', get_bukudb()).get_tag_all()
result = {
'tags': tags[0]
}
if request.path.startswith('/api/'):
res = jsonify(result)
else:
res = render_template('bukuserver/tags.html', result=result)
return res | [
"def",
"get_tags",
"(",
")",
":",
"tags",
"=",
"getattr",
"(",
"flask",
".",
"g",
",",
"'bukudb'",
",",
"get_bukudb",
"(",
")",
")",
".",
"get_tag_all",
"(",
")",
"result",
"=",
"{",
"'tags'",
":",
"tags",
"[",
"0",
"]",
"}",
"if",
"request",
"."... | get tags. | [
"get",
"tags",
"."
] | 5f101363cf68f7666d4f5b28f0887ee07e916054 | https://github.com/jarun/Buku/blob/5f101363cf68f7666d4f5b28f0887ee07e916054/bukuserver/server.py#L42-L52 |
234,194 | jarun/Buku | bukuserver/server.py | create_app | def create_app(config_filename=None):
"""create app."""
app = FlaskAPI(__name__)
per_page = int(os.getenv('BUKUSERVER_PER_PAGE', str(views.DEFAULT_PER_PAGE)))
per_page = per_page if per_page > 0 else views.DEFAULT_PER_PAGE
app.config['BUKUSERVER_PER_PAGE'] = per_page
url_render_mode = os.getenv('BUKUSERVER_URL_RENDER_MODE', views.DEFAULT_URL_RENDER_MODE)
if url_render_mode not in ('full', 'netloc'):
url_render_mode = views.DEFAULT_URL_RENDER_MODE
app.config['BUKUSERVER_URL_RENDER_MODE'] = url_render_mode
app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SECRET_KEY') or os.urandom(24)
app.config['BUKUSERVER_DB_FILE'] = os.getenv('BUKUSERVER_DB_FILE')
bukudb = BukuDb(dbfile=app.config['BUKUSERVER_DB_FILE'])
app.app_context().push()
setattr(flask.g, 'bukudb', bukudb)
@app.shell_context_processor
def shell_context():
"""Shell context definition."""
return {'app': app, 'bukudb': bukudb}
app.jinja_env.filters['netloc'] = lambda x: urlparse(x).netloc # pylint: disable=no-member
Bootstrap(app)
admin = Admin(
app, name='Buku Server', template_mode='bootstrap3',
index_view=views.CustomAdminIndexView(
template='bukuserver/home.html', url='/'
)
)
# routing
# api
app.add_url_rule('/api/tags', 'get_tags', tag_list, methods=['GET'])
app.add_url_rule('/api/tags/<tag>', 'update_tag', tag_detail, methods=['GET', 'PUT'])
app.add_url_rule(
'/api/network_handle',
'networkk_handle',
network_handle_detail,
methods=['POST'])
app.add_url_rule('/api/bookmarks', 'bookmarks', bookmarks, methods=['GET', 'POST', 'DELETE'])
app.add_url_rule(
'/api/bookmarks/refresh',
'refresh_bookmarks',
refresh_bookmarks,
methods=['POST'])
app.add_url_rule(
'/api/bookmarks/<id>',
'bookmark_api',
bookmark_api,
methods=['GET', 'PUT', 'DELETE'])
app.add_url_rule(
'/api/bookmarks/<id>/refresh',
'refresh_bookmark',
refresh_bookmark,
methods=['POST'])
app.add_url_rule('/api/bookmarks/<id>/tiny', 'get_tiny_url', get_tiny_url, methods=['GET'])
app.add_url_rule('/api/bookmarks/<id>/long', 'get_long_url', get_long_url, methods=['GET'])
app.add_url_rule(
'/api/bookmarks/<starting_id>/<ending_id>',
'bookmark_range_operations', bookmark_range_operations, methods=['GET', 'PUT', 'DELETE'])
app.add_url_rule(
'/api/bookmarks/search',
'search_bookmarks',
search_bookmarks,
methods=['GET', 'DELETE'])
# non api
admin.add_view(views.BookmarkModelView(
bukudb, 'Bookmarks', page_size=per_page, url_render_mode=url_render_mode))
admin.add_view(views.TagModelView(
bukudb, 'Tags', page_size=per_page))
admin.add_view(views.StatisticView(
bukudb, 'Statistic', endpoint='statistic'))
return app | python | def create_app(config_filename=None):
app = FlaskAPI(__name__)
per_page = int(os.getenv('BUKUSERVER_PER_PAGE', str(views.DEFAULT_PER_PAGE)))
per_page = per_page if per_page > 0 else views.DEFAULT_PER_PAGE
app.config['BUKUSERVER_PER_PAGE'] = per_page
url_render_mode = os.getenv('BUKUSERVER_URL_RENDER_MODE', views.DEFAULT_URL_RENDER_MODE)
if url_render_mode not in ('full', 'netloc'):
url_render_mode = views.DEFAULT_URL_RENDER_MODE
app.config['BUKUSERVER_URL_RENDER_MODE'] = url_render_mode
app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SECRET_KEY') or os.urandom(24)
app.config['BUKUSERVER_DB_FILE'] = os.getenv('BUKUSERVER_DB_FILE')
bukudb = BukuDb(dbfile=app.config['BUKUSERVER_DB_FILE'])
app.app_context().push()
setattr(flask.g, 'bukudb', bukudb)
@app.shell_context_processor
def shell_context():
"""Shell context definition."""
return {'app': app, 'bukudb': bukudb}
app.jinja_env.filters['netloc'] = lambda x: urlparse(x).netloc # pylint: disable=no-member
Bootstrap(app)
admin = Admin(
app, name='Buku Server', template_mode='bootstrap3',
index_view=views.CustomAdminIndexView(
template='bukuserver/home.html', url='/'
)
)
# routing
# api
app.add_url_rule('/api/tags', 'get_tags', tag_list, methods=['GET'])
app.add_url_rule('/api/tags/<tag>', 'update_tag', tag_detail, methods=['GET', 'PUT'])
app.add_url_rule(
'/api/network_handle',
'networkk_handle',
network_handle_detail,
methods=['POST'])
app.add_url_rule('/api/bookmarks', 'bookmarks', bookmarks, methods=['GET', 'POST', 'DELETE'])
app.add_url_rule(
'/api/bookmarks/refresh',
'refresh_bookmarks',
refresh_bookmarks,
methods=['POST'])
app.add_url_rule(
'/api/bookmarks/<id>',
'bookmark_api',
bookmark_api,
methods=['GET', 'PUT', 'DELETE'])
app.add_url_rule(
'/api/bookmarks/<id>/refresh',
'refresh_bookmark',
refresh_bookmark,
methods=['POST'])
app.add_url_rule('/api/bookmarks/<id>/tiny', 'get_tiny_url', get_tiny_url, methods=['GET'])
app.add_url_rule('/api/bookmarks/<id>/long', 'get_long_url', get_long_url, methods=['GET'])
app.add_url_rule(
'/api/bookmarks/<starting_id>/<ending_id>',
'bookmark_range_operations', bookmark_range_operations, methods=['GET', 'PUT', 'DELETE'])
app.add_url_rule(
'/api/bookmarks/search',
'search_bookmarks',
search_bookmarks,
methods=['GET', 'DELETE'])
# non api
admin.add_view(views.BookmarkModelView(
bukudb, 'Bookmarks', page_size=per_page, url_render_mode=url_render_mode))
admin.add_view(views.TagModelView(
bukudb, 'Tags', page_size=per_page))
admin.add_view(views.StatisticView(
bukudb, 'Statistic', endpoint='statistic'))
return app | [
"def",
"create_app",
"(",
"config_filename",
"=",
"None",
")",
":",
"app",
"=",
"FlaskAPI",
"(",
"__name__",
")",
"per_page",
"=",
"int",
"(",
"os",
".",
"getenv",
"(",
"'BUKUSERVER_PER_PAGE'",
",",
"str",
"(",
"views",
".",
"DEFAULT_PER_PAGE",
")",
")",
... | create app. | [
"create",
"app",
"."
] | 5f101363cf68f7666d4f5b28f0887ee07e916054 | https://github.com/jarun/Buku/blob/5f101363cf68f7666d4f5b28f0887ee07e916054/bukuserver/server.py#L519-L591 |
234,195 | jarun/Buku | bukuserver/views.py | CustomAdminIndexView.search | def search(self):
"redirect to bookmark search"
form = forms.HomeForm()
bbm_filter = bs_filters.BookmarkBukuFilter(
all_keywords=False, deep=form.deep.data, regex=form.regex.data)
op_text = bbm_filter.operation()
values_combi = sorted(itertools.product([True, False], repeat=3))
for idx, (all_keywords, deep, regex) in enumerate(values_combi):
if deep == form.deep.data and regex == form.regex.data and not all_keywords:
choosen_idx = idx
url_op_text = op_text.replace(', ', '_').replace(' ', ' ').replace(' ', '_')
key = ''.join(['flt', str(choosen_idx), '_buku_', url_op_text])
kwargs = {key: form.keyword.data}
url = url_for('bookmark.index_view', **kwargs)
return redirect(url) | python | def search(self):
"redirect to bookmark search"
form = forms.HomeForm()
bbm_filter = bs_filters.BookmarkBukuFilter(
all_keywords=False, deep=form.deep.data, regex=form.regex.data)
op_text = bbm_filter.operation()
values_combi = sorted(itertools.product([True, False], repeat=3))
for idx, (all_keywords, deep, regex) in enumerate(values_combi):
if deep == form.deep.data and regex == form.regex.data and not all_keywords:
choosen_idx = idx
url_op_text = op_text.replace(', ', '_').replace(' ', ' ').replace(' ', '_')
key = ''.join(['flt', str(choosen_idx), '_buku_', url_op_text])
kwargs = {key: form.keyword.data}
url = url_for('bookmark.index_view', **kwargs)
return redirect(url) | [
"def",
"search",
"(",
"self",
")",
":",
"form",
"=",
"forms",
".",
"HomeForm",
"(",
")",
"bbm_filter",
"=",
"bs_filters",
".",
"BookmarkBukuFilter",
"(",
"all_keywords",
"=",
"False",
",",
"deep",
"=",
"form",
".",
"deep",
".",
"data",
",",
"regex",
"=... | redirect to bookmark search | [
"redirect",
"to",
"bookmark",
"search"
] | 5f101363cf68f7666d4f5b28f0887ee07e916054 | https://github.com/jarun/Buku/blob/5f101363cf68f7666d4f5b28f0887ee07e916054/bukuserver/views.py#L38-L52 |
234,196 | lepture/mistune | mistune.py | Renderer.autolink | def autolink(self, link, is_email=False):
"""Rendering a given link or email address.
:param link: link content or email address.
:param is_email: whether this is an email or not.
"""
text = link = escape_link(link)
if is_email:
link = 'mailto:%s' % link
return '<a href="%s">%s</a>' % (link, text) | python | def autolink(self, link, is_email=False):
text = link = escape_link(link)
if is_email:
link = 'mailto:%s' % link
return '<a href="%s">%s</a>' % (link, text) | [
"def",
"autolink",
"(",
"self",
",",
"link",
",",
"is_email",
"=",
"False",
")",
":",
"text",
"=",
"link",
"=",
"escape_link",
"(",
"link",
")",
"if",
"is_email",
":",
"link",
"=",
"'mailto:%s'",
"%",
"link",
"return",
"'<a href=\"%s\">%s</a>'",
"%",
"("... | Rendering a given link or email address.
:param link: link content or email address.
:param is_email: whether this is an email or not. | [
"Rendering",
"a",
"given",
"link",
"or",
"email",
"address",
"."
] | 449c2b52961c30665ccba6a822652ec7d0e15938 | https://github.com/lepture/mistune/blob/449c2b52961c30665ccba6a822652ec7d0e15938/mistune.py#L871-L880 |
234,197 | getsentry/sentry-python | sentry_sdk/hub.py | init | def init(*args, **kwargs):
"""Initializes the SDK and optionally integrations.
This takes the same arguments as the client constructor.
"""
global _initial_client
client = Client(*args, **kwargs)
Hub.current.bind_client(client)
rv = _InitGuard(client)
if client is not None:
_initial_client = weakref.ref(client)
return rv | python | def init(*args, **kwargs):
global _initial_client
client = Client(*args, **kwargs)
Hub.current.bind_client(client)
rv = _InitGuard(client)
if client is not None:
_initial_client = weakref.ref(client)
return rv | [
"def",
"init",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"global",
"_initial_client",
"client",
"=",
"Client",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"Hub",
".",
"current",
".",
"bind_client",
"(",
"client",
")",
"rv",
"=",
"_In... | Initializes the SDK and optionally integrations.
This takes the same arguments as the client constructor. | [
"Initializes",
"the",
"SDK",
"and",
"optionally",
"integrations",
"."
] | a1d77722bdce0b94660ebf50b5c4a4645916d084 | https://github.com/getsentry/sentry-python/blob/a1d77722bdce0b94660ebf50b5c4a4645916d084/sentry_sdk/hub.py#L61-L72 |
234,198 | getsentry/sentry-python | sentry_sdk/hub.py | HubMeta.current | def current(self):
# type: () -> Hub
"""Returns the current instance of the hub."""
rv = _local.get(None)
if rv is None:
rv = Hub(GLOBAL_HUB)
_local.set(rv)
return rv | python | def current(self):
# type: () -> Hub
rv = _local.get(None)
if rv is None:
rv = Hub(GLOBAL_HUB)
_local.set(rv)
return rv | [
"def",
"current",
"(",
"self",
")",
":",
"# type: () -> Hub",
"rv",
"=",
"_local",
".",
"get",
"(",
"None",
")",
"if",
"rv",
"is",
"None",
":",
"rv",
"=",
"Hub",
"(",
"GLOBAL_HUB",
")",
"_local",
".",
"set",
"(",
"rv",
")",
"return",
"rv"
] | Returns the current instance of the hub. | [
"Returns",
"the",
"current",
"instance",
"of",
"the",
"hub",
"."
] | a1d77722bdce0b94660ebf50b5c4a4645916d084 | https://github.com/getsentry/sentry-python/blob/a1d77722bdce0b94660ebf50b5c4a4645916d084/sentry_sdk/hub.py#L77-L84 |
234,199 | getsentry/sentry-python | sentry_sdk/hub.py | Hub.get_integration | def get_integration(self, name_or_class):
# type: (Union[str, Integration]) -> Any
"""Returns the integration for this hub by name or class. If there
is no client bound or the client does not have that integration
then `None` is returned.
If the return value is not `None` the hub is guaranteed to have a
client attached.
"""
if isinstance(name_or_class, str):
integration_name = name_or_class
elif name_or_class.identifier is not None:
integration_name = name_or_class.identifier
else:
raise ValueError("Integration has no name")
client = self._stack[-1][0]
if client is not None:
rv = client.integrations.get(integration_name)
if rv is not None:
return rv
initial_client = _initial_client
if initial_client is not None:
initial_client = initial_client()
if (
initial_client is not None
and initial_client is not client
and initial_client.integrations.get(name_or_class) is not None
):
warning = (
"Integration %r attempted to run but it was only "
"enabled on init() but not the client that "
"was bound to the current flow. Earlier versions of "
"the SDK would consider these integrations enabled but "
"this is no longer the case." % (name_or_class,)
)
warn(Warning(warning), stacklevel=3)
logger.warning(warning) | python | def get_integration(self, name_or_class):
# type: (Union[str, Integration]) -> Any
if isinstance(name_or_class, str):
integration_name = name_or_class
elif name_or_class.identifier is not None:
integration_name = name_or_class.identifier
else:
raise ValueError("Integration has no name")
client = self._stack[-1][0]
if client is not None:
rv = client.integrations.get(integration_name)
if rv is not None:
return rv
initial_client = _initial_client
if initial_client is not None:
initial_client = initial_client()
if (
initial_client is not None
and initial_client is not client
and initial_client.integrations.get(name_or_class) is not None
):
warning = (
"Integration %r attempted to run but it was only "
"enabled on init() but not the client that "
"was bound to the current flow. Earlier versions of "
"the SDK would consider these integrations enabled but "
"this is no longer the case." % (name_or_class,)
)
warn(Warning(warning), stacklevel=3)
logger.warning(warning) | [
"def",
"get_integration",
"(",
"self",
",",
"name_or_class",
")",
":",
"# type: (Union[str, Integration]) -> Any",
"if",
"isinstance",
"(",
"name_or_class",
",",
"str",
")",
":",
"integration_name",
"=",
"name_or_class",
"elif",
"name_or_class",
".",
"identifier",
"is... | Returns the integration for this hub by name or class. If there
is no client bound or the client does not have that integration
then `None` is returned.
If the return value is not `None` the hub is guaranteed to have a
client attached. | [
"Returns",
"the",
"integration",
"for",
"this",
"hub",
"by",
"name",
"or",
"class",
".",
"If",
"there",
"is",
"no",
"client",
"bound",
"or",
"the",
"client",
"does",
"not",
"have",
"that",
"integration",
"then",
"None",
"is",
"returned",
"."
] | a1d77722bdce0b94660ebf50b5c4a4645916d084 | https://github.com/getsentry/sentry-python/blob/a1d77722bdce0b94660ebf50b5c4a4645916d084/sentry_sdk/hub.py#L196-L235 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.