def pin_added(body, client, context, logger): context.ack() event = body["event"] channel_id = event["channel_id"] channel_name = client.conversations_info(channel=channel_id)["channel"]["name"] pinned_at = datetime.datetime.fromtimestamp(event["item"]["created"]) pinned_at = pinned_at.strftime("%d/%m/%Y %H:%M:%S") message = event["item"]["message"]["text"] message_by = client.users_info(user=event["item"]["message"]["user"]) message_username = message_by["user"]["profile"]["display_name"] permalink = event["item"]["message"]["permalink"] row = [pinned_at, channel_name, message_username, message, permalink] pins_sheet.append(row)
def message_saver(mention_event, thread_content): thread_start_msg = thread_content.data["messages"][0] txt = thread_start_msg["text"] channel = mention_event["channel"] thread_ts = mention_event["thread_ts"] try: client.reactions_add(channel=channel, timestamp=thread_ts, name="floppy_disk") except SlackApiError: pass username = client.users_info( user=thread_start_msg["user"])["user"]["profile"]["display_name"] dt = datetime.fromtimestamp(float(thread_ts)).strftime("%d/%m/%Y %H:%M:%S") pins_sheet.append([channel, dt, username, txt], subsheet=MESSAGE_SAVER_SHEET) client.chat_postMessage(text=f"```{txt}``` Aldim bunu.", thread_ts=thread_ts, channel=channel)
def add_links_to_sheet(links, channel_name): today_start = datetime.today().replace(minute=0, hour=0, second=0, microsecond=0) inserted_link_count = 0 user_map = {} links.sort(key=lambda tup: tup[1]) for user_id, msg_ts, title, link in links: pinned_at = datetime.fromtimestamp(msg_ts) if pinned_at > today_start: username = user_map.get(user_id) if not username: username = user_map[user_id] = client.users_info( user=user_id)["user"]["profile"]["display_name"] pinned_at = pinned_at.strftime("%d/%m/%Y %H:%M:%S") pins_sheet.append([pinned_at, title, link, username], subsheet=channel_name) inserted_link_count += 1 return inserted_link_count