def post_auto_comment(msg, user, url=None, ids=None): if not GlobalVars.metasmoke_key: return response = None if url is not None: params = {"key": GlobalVars.metasmoke_key, "urls": url, "filter": "GFGJGHFJNFGNHKNIKHGGOMILHKLJIFFN"} response = Metasmoke.get("/api/v2.0/posts/urls", params=params).json() elif ids is not None: post_id, site = ids site = parsing.api_parameter_from_link(site) params = {"key": GlobalVars.metasmoke_key, "filter": "GFGJGHFJNFGNHKNIKHGGOMILHKLJIFFN"} try: response = Metasmoke.get("/api/v2.0/posts/uid/{}/{}".format(site, post_id), params=params).json() except AttributeError: response = None if response and "items" in response and len(response["items"]) > 0: ms_id = response["items"][0]["id"] params = {"key": GlobalVars.metasmoke_key, "text": msg[:1].upper() + msg[1:], # Capitalise the first letter of the comment "chat_user_id": user.id, "chat_host": user._client.host} Metasmoke.post("/api/v2.0/comments/post/{}".format(ms_id), params=params)
def resolve_ms_link(post_url): identifier = (api_parameter_from_link(post_url), post_id_from_link(post_url)) if identifier in GlobalVars.metasmoke_ids: if isinstance(GlobalVars.metasmoke_ids[identifier], int): ms_url = (GlobalVars.metasmoke_host.rstrip("/") + "/post/{}").format(GlobalVars.metasmoke_ids[identifier]) return ms_url elif GlobalVars.metasmoke_ids[identifier] is None: return None else: del GlobalVars.metasmoke_ids[identifier] ms_posts = metasmoke.Metasmoke.get_post_bodies_from_ms(post_url) if not ms_posts: # Empty ms_post_id = None ms_url = None else: ms_post_id = max([post['id'] for post in ms_posts]) ms_url = (GlobalVars.metasmoke_host.rstrip("/") + "/post/{}").format(ms_post_id) GlobalVars.metasmoke_ids[ identifier] = ms_post_id # Store numeric IDs, strings are hard to handle _dump_pickle("metasmokePostIds.p", GlobalVars.metasmoke_ids) return ms_url
def post_auto_comment(msg, user, url=None, ids=None): if not GlobalVars.metasmoke_key: return response = None if url is not None: params = {"key": GlobalVars.metasmoke_key, "urls": url, "filter": "GFGJGHFJNFGNHKNIKHGGOMILHKLJIFFN"} response = Metasmoke.get("/api/v2.0/posts/urls", params=params).json() elif ids is not None: post_id, site = ids site = parsing.api_parameter_from_link(site) params = {"key": GlobalVars.metasmoke_key, "filter": "GFGJGHFJNFGNHKNIKHGGOMILHKLJIFFN"} try: response = Metasmoke.get("/api/v2.0/posts/uid/{}/{}".format(site, post_id), params=params).json() except AttributeError: response = None if response and "items" in response and len(response["items"]) > 0: ms_id = response["items"][0]["id"] params = {"key": GlobalVars.metasmoke_key, "text": msg, "chat_user_id": user.id, "chat_host": user._client.host} Metasmoke.post("/api/v2.0/comments/post/{}".format(ms_id), params=params)
def resolve_ms_link(post_url): identifier = (api_parameter_from_link(post_url), post_id_from_link(post_url)) if identifier in GlobalVars.metasmoke_ids: if isinstance(GlobalVars.metasmoke_ids[identifier], int): ms_url = (GlobalVars.metasmoke_host.rstrip("/") + "/post/{}").format( GlobalVars.metasmoke_ids[identifier]) return ms_url elif GlobalVars.metasmoke_ids[identifier] is None: return None else: del GlobalVars.metasmoke_ids[identifier] ms_posts = metasmoke.Metasmoke.get_post_bodies_from_ms(post_url) if not ms_posts: # Empty ms_post_id = None ms_url = None else: ms_post_id = max([post['id'] for post in ms_posts]) ms_url = (GlobalVars.metasmoke_host.rstrip("/") + "/post/{}").format(ms_post_id) GlobalVars.metasmoke_ids[identifier] = ms_post_id # Store numeric IDs, strings are hard to handle _dump_pickle("metasmokePostIds.p", GlobalVars.metasmoke_ids) return ms_url