Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
| import discord | |
| import os | |
| import threading | |
| from discord.ext import commands | |
| import gradio_client | |
| import gradio as gr | |
| from gradio_client import Client | |
| DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None) | |
| intents = discord.Intents.all() | |
| bot = commands.Bot(command_prefix='!', intents=intents) | |
| welcome_list = [] | |
| welcome_messages = [ | |
| "Welcome to the community <:hugging_croissant:1103375763207622656> \n", | |
| "Good to have you with us! :hugging: Got any cool projects you feel like sharing? :eyes: \n", | |
| "Welcome aboard π¦ β΅ \n", | |
| "Hello friends! :wave: Where are you folks from? :globe_with_meridians: <:hugging_earth:968126923408564306> \n", | |
| "Glad you're here! Welcome! π \n", | |
| "Happy to have you with us! <:blobcatlove:1103376097841790986> How much have you played around with ML/AI? :computer: \n", | |
| "New faces, new friends! Welcome! ππ \n" | |
| ] | |
| welcome_messages_counter = 0 | |
| wait_messages_counter = 0 | |
| channel_id = 900017973547388988 # 900017973547388988 = #introduce-yourself | |
| async def on_member_join(member): | |
| global welcome_list | |
| global welcome_messages_counter | |
| welcome_list.append(member.mention) | |
| if len(welcome_list) >= 8: | |
| channel = bot.get_channel(channel_id) | |
| print(f"channel: {channel}") | |
| # Check if the channel has received at least 3 messages from other users (non-bot?) since the last message was sent | |
| count = 0 | |
| print(f"count: {count}") | |
| async for message in channel.history(limit=3): | |
| if message.author.bot: | |
| print(f"This is a bot message! -> {message.content}") | |
| else: | |
| count = count + 1 | |
| print(f"count: {count}") | |
| if count == 3: | |
| print(f"count: {count}") | |
| # 8 users, can change this | |
| message = f'{welcome_messages[welcome_messages_counter]} {welcome_list[0]} {welcome_list[1]} {welcome_list[2]} {welcome_list[3]} {welcome_list[4]} {welcome_list[5]} {welcome_list[6]} {welcome_list[7]}' | |
| if welcome_messages_counter == 6: | |
| welcome_messages_counter = -1 | |
| welcome_messages_counter = welcome_messages_counter + 1 | |
| await channel.send(message) | |
| welcome_list = [] | |
| else: | |
| print(f"welcome_list: {welcome_list}") | |
| async def on_message(message): | |
| if message.channel.id == 900017973547388988: | |
| await message.add_reaction('π€') | |
| await bot.process_commands(message) | |
| DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None) | |
| 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() |