Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,464 Bytes
78dea1a db21dc3 434f798 db21dc3 78dea1a b7eca85 4b7b722 a3bd5c7 b7eca85 a583920 b7eca85 78dea1a b7eca85 4b7b722 b7eca85 78dea1a b7eca85 78dea1a b7eca85 78dea1a b7eca85 78dea1a b7eca85 78dea1a b7eca85 78dea1a b7eca85 db21dc3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import discord
import threading
import os
import gradio as gr
from discord.ext import commands
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
DISCORD_TOKEN = os.getenv('DISCORD_TOKEN')
SLACK_TOKEN = os.getenv('SLACK_TOKEN')
SLACK_CHANNEL_ID = os.getenv('SLACK_CHANNEL_ID')
TRIGGERS = {
"discord bot": "<@U061W3NRFFA>",
"setfit": "tom aarsen",
"cv": "merve",
}
intents = discord.Intents.all()
intents.messages = True
bot = commands.Bot(command_prefix='!', intents=intents)
slack_client = WebClient(token=SLACK_TOKEN)
@bot.event
async def on_ready():
print(f'Logged in as {bot.user}')
@bot.event
async def on_message(message):
if message.author == bot.user:
return
content = message.content.lower()
for trigger, slack_mention in TRIGGERS.items():
if trigger in content:
await post_to_slack(message.content, slack_mention)
break
async def post_to_slack(content, slack_mention):
try:
response = slack_client.chat_postMessage(
channel=SLACK_CHANNEL_ID,
text=f"{slack_mention} New message in Discord: {content}"
)
except SlackApiError as e:
print(f"Error posting to Slack: {e.response['error']}")
def run_bot():
bot.run(DISCORD_TOKEN)
threading.Thread(target=run_bot).start()
def greet(name):
return "Hello " + name + "!"
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()
|