Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
| import discord | |
| import os | |
| import threading | |
| from discord.ext import commands | |
| import json | |
| import time | |
| import matplotlib.pyplot as plt | |
| from io import BytesIO | |
| 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) | |
| async def on_ready(): | |
| print(f'Logged in as {bot.user.name}') | |
| async def save_messages(ctx, channel_id: int): | |
| if ctx.author.id == 811235357663297546: | |
| channel = bot.get_channel(channel_id) | |
| if not channel: | |
| await ctx.send("Channel not found.") | |
| return | |
| messages = [] | |
| async for message in channel.history(limit=None): | |
| messages.append(message) | |
| with open("gradio-questions.json", 'w', encoding='utf-8') as file: | |
| for message in messages: | |
| file.write(f"{message.content}\n") | |
| await ctx.send(f"Messages from {channel.name} saved to gradio-questions.json") | |
| with open("gradio-questions.json", 'rb') as file: | |
| discord_file = discord.File(file) | |
| await ctx.send(file=discord_file) | |
| async def save_forum(ctx, channel_id: int): | |
| if ctx.author.id == 811235357663297546: | |
| channel = bot.get_channel(channel_id) | |
| threads = channel.threads | |
| messages = [] | |
| for thread in threads: | |
| #messages.append(thread.name) | |
| async for message in thread.history(limit=None): | |
| messages.append(message) | |
| messages = messages.reverse() | |
| print(messages) # debug | |
| with open("gradio-questions.json", 'w', encoding='utf-8') as file: | |
| for message in messages: | |
| file.write(f"{message.content}\n") | |
| await ctx.send(f"Messages from {channel.name} saved to gradio-questions.json") | |
| with open("gradio-questions.json", 'rb') as file: | |
| discord_file = discord.File(file) | |
| await ctx.send(file=discord_file) | |
| """""" | |
| 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() |