Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
testing adding attachments
Browse files
app.py
CHANGED
|
@@ -81,36 +81,34 @@ async def on_message(message):
|
|
| 81 |
|
| 82 |
# Check if the message is in a thread
|
| 83 |
if isinstance(message.channel, discord.Thread):
|
| 84 |
-
print("1")
|
| 85 |
discord_thread_id = message.channel.id
|
| 86 |
-
print("2")
|
| 87 |
# Check if there's an existing Slack thread for this Discord thread
|
| 88 |
# (the only Slack threads created should be for forum channel threads, not just any thread)
|
| 89 |
if discord_thread_id in thread_mapping:
|
| 90 |
-
print("3")
|
| 91 |
slack_thread_ts = thread_mapping[discord_thread_id]
|
| 92 |
# post to slack only if thread already exists
|
| 93 |
-
post_to_slack_forum_version(SLACK_CHANNEL_ID, message.content, message.author, thread_ts=slack_thread_ts)
|
| 94 |
|
| 95 |
|
| 96 |
@bot.event
|
| 97 |
async def on_thread_create(thread):
|
| 98 |
# (discord) must be the child thread of the CORRECT forum channel(s) (not just any thread, or any forum channel)
|
| 99 |
if isinstance(thread.parent, discord.ForumChannel) and thread.parent.id in {ASK_FOR_HELP_CHANNEL_ID, GRADIO_CHANNEL_ID}:
|
| 100 |
-
print("4")
|
| 101 |
discord_thread_id = thread.id
|
| 102 |
slack_thread_ts = post_to_slack_create_thread(
|
| 103 |
SLACK_CHANNEL_ID,
|
| 104 |
f"New forum thread started in {thread.parent.name} by {thread.owner}: *{thread.name}*\n"
|
| 105 |
f"{thread.jump_url}"
|
| 106 |
)
|
| 107 |
-
print("5")
|
| 108 |
if slack_thread_ts:
|
| 109 |
thread_mapping[discord_thread_id] = slack_thread_ts
|
| 110 |
|
| 111 |
|
| 112 |
-
def post_to_slack_forum_version(channel, text, author, thread_ts=None):
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
| 114 |
text = f"{author}" + ": " + text
|
| 115 |
try:
|
| 116 |
response = slack_client.chat_postMessage(
|
|
@@ -125,7 +123,6 @@ def post_to_slack_forum_version(channel, text, author, thread_ts=None):
|
|
| 125 |
|
| 126 |
|
| 127 |
def post_to_slack_create_thread(channel, text, thread_ts=None):
|
| 128 |
-
print("6")
|
| 129 |
try:
|
| 130 |
response = slack_client.chat_postMessage(
|
| 131 |
channel=channel,
|
|
|
|
| 81 |
|
| 82 |
# Check if the message is in a thread
|
| 83 |
if isinstance(message.channel, discord.Thread):
|
|
|
|
| 84 |
discord_thread_id = message.channel.id
|
|
|
|
| 85 |
# Check if there's an existing Slack thread for this Discord thread
|
| 86 |
# (the only Slack threads created should be for forum channel threads, not just any thread)
|
| 87 |
if discord_thread_id in thread_mapping:
|
|
|
|
| 88 |
slack_thread_ts = thread_mapping[discord_thread_id]
|
| 89 |
# post to slack only if thread already exists
|
| 90 |
+
post_to_slack_forum_version(message, SLACK_CHANNEL_ID, message.content, message.author, thread_ts=slack_thread_ts)
|
| 91 |
|
| 92 |
|
| 93 |
@bot.event
|
| 94 |
async def on_thread_create(thread):
|
| 95 |
# (discord) must be the child thread of the CORRECT forum channel(s) (not just any thread, or any forum channel)
|
| 96 |
if isinstance(thread.parent, discord.ForumChannel) and thread.parent.id in {ASK_FOR_HELP_CHANNEL_ID, GRADIO_CHANNEL_ID}:
|
|
|
|
| 97 |
discord_thread_id = thread.id
|
| 98 |
slack_thread_ts = post_to_slack_create_thread(
|
| 99 |
SLACK_CHANNEL_ID,
|
| 100 |
f"New forum thread started in {thread.parent.name} by {thread.owner}: *{thread.name}*\n"
|
| 101 |
f"{thread.jump_url}"
|
| 102 |
)
|
|
|
|
| 103 |
if slack_thread_ts:
|
| 104 |
thread_mapping[discord_thread_id] = slack_thread_ts
|
| 105 |
|
| 106 |
|
| 107 |
+
def post_to_slack_forum_version(message, channel, text, author, thread_ts=None):
|
| 108 |
+
if message.attachments:
|
| 109 |
+
for attachment in message.attachments:
|
| 110 |
+
attachment_url = attachment.url
|
| 111 |
+
text += f"\nAttachment: {attachment_url}"
|
| 112 |
text = f"{author}" + ": " + text
|
| 113 |
try:
|
| 114 |
response = slack_client.chat_postMessage(
|
|
|
|
| 123 |
|
| 124 |
|
| 125 |
def post_to_slack_create_thread(channel, text, thread_ts=None):
|
|
|
|
| 126 |
try:
|
| 127 |
response = slack_client.chat_postMessage(
|
| 128 |
channel=channel,
|