Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,9 @@ import utils
|
|
| 19 |
|
| 20 |
event = Event()
|
| 21 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
| 22 |
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
| 23 |
HF_TOKEN=os.getenv("HF_TOKEN")
|
| 24 |
|
|
@@ -28,50 +31,40 @@ def get_client(session: Optional[str] = None) -> Client:
|
|
| 28 |
client.session_hash = session
|
| 29 |
return client
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
resolver = AsyncResolver(nameservers=["1.1.1.1", "8.8.8.8"])
|
| 34 |
-
connector = aiohttp.TCPConnector(resolver=resolver)
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
intents.message_content = True
|
| 38 |
-
intents.members = True
|
| 39 |
-
bot = commands.Bot(intents=intents, connector=connector, command_prefix="!")
|
| 40 |
|
| 41 |
-
@bot.event
|
| 42 |
-
async def on_ready():
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
event.set()
|
| 47 |
-
print("------")
|
| 48 |
-
|
| 49 |
-
@bot.command()
|
| 50 |
-
async def test(ctx, *, arg):
|
| 51 |
-
thread = await ctx.create_thread(name=prompt, auto_archive_duration=60)
|
| 52 |
-
loop = asyncio.get_running_loop()
|
| 53 |
-
client = await loop.run_in_executor(None, get_client, None)
|
| 54 |
-
job = client.submit(prompt, api_name="/slow_echo")
|
| 55 |
-
wait([job])
|
| 56 |
-
await ctx.send(arg)
|
| 57 |
-
|
| 58 |
-
# running in thread
|
| 59 |
-
def run_bot():
|
| 60 |
-
if not DISCORD_TOKEN:
|
| 61 |
-
print("DISCORD_TOKEN NOT SET")
|
| 62 |
event.set()
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
|
|
|
|
|
| 19 |
|
| 20 |
event = Event()
|
| 21 |
logging.basicConfig(level=logging.INFO)
|
| 22 |
+
intents = discord.Intents.default()
|
| 23 |
+
intents.message_content = True
|
| 24 |
+
intents.members = True
|
| 25 |
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
| 26 |
HF_TOKEN=os.getenv("HF_TOKEN")
|
| 27 |
|
|
|
|
| 31 |
client.session_hash = session
|
| 32 |
return client
|
| 33 |
|
| 34 |
+
async def main():
|
| 35 |
+
# Setup DNS resolver to avoid potential issues
|
| 36 |
+
resolver = AsyncResolver(nameservers=["1.1.1.1", "8.8.8.8"])
|
| 37 |
+
connector = aiohttp.TCPConnector(resolver=resolver)
|
| 38 |
+
# Setup Discord bot
|
| 39 |
+
bot = commands.Bot(intents=intents, connector=connector, command_prefix="!")
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
@bot.event
|
| 42 |
+
async def on_ready():
|
| 43 |
+
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
|
| 44 |
+
synced = await bot.tree.sync()
|
| 45 |
+
print(f"Synced commands: {', '.join([s.name for s in synced])}.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
event.set()
|
| 47 |
+
print("------")
|
| 48 |
+
|
| 49 |
+
@bot.command()
|
| 50 |
+
async def test(ctx, *, arg):
|
| 51 |
+
thread = await ctx.create_thread(name=prompt, auto_archive_duration=60)
|
| 52 |
+
loop = asyncio.get_running_loop()
|
| 53 |
+
client = await loop.run_in_executor(None, get_client, None)
|
| 54 |
+
job = client.submit(prompt, api_name="/slow_echo")
|
| 55 |
+
wait([job])
|
| 56 |
+
await ctx.send(arg)
|
| 57 |
+
|
| 58 |
+
# running in thread
|
| 59 |
+
def run_bot():
|
| 60 |
+
if not DISCORD_TOKEN:
|
| 61 |
+
print("DISCORD_TOKEN NOT SET")
|
| 62 |
+
event.set()
|
| 63 |
+
else:
|
| 64 |
+
bot.run(DISCORD_TOKEN)
|
| 65 |
+
|
| 66 |
+
utils.keepalive_run()
|
| 67 |
+
await bot.start(os.getenv('DISCORD_TOKEN'))
|
| 68 |
|
| 69 |
+
if __name__ == "__main__":
|
| 70 |
+
asyncio.run(main())
|