Spaces:
Running
Running
Aditya Sharma commited on
Commit ·
3b7c07e
1
Parent(s): 623bd5b
push
Browse files- .gitignore +1 -0
- Dockerfile +19 -0
- README copy.md +9 -0
- main.py +72 -0
- pyproject.toml +15 -0
- uv.lock +0 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.venv
|
Dockerfile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.12-slim-bookworm
|
| 5 |
+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
| 6 |
+
|
| 7 |
+
RUN useradd -m -u 1000 user
|
| 8 |
+
USER user
|
| 9 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 10 |
+
|
| 11 |
+
WORKDIR /app
|
| 12 |
+
|
| 13 |
+
COPY --chown=user . .
|
| 14 |
+
|
| 15 |
+
RUN ls
|
| 16 |
+
|
| 17 |
+
RUN pip3 install uvicorn
|
| 18 |
+
|
| 19 |
+
CMD ["uv", "run", "main.py"]
|
README copy.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: DiscordBot
|
| 3 |
+
emoji: 🌖
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
| 9 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
main.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import threading
|
| 3 |
+
from flask import Flask
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
import discord
|
| 6 |
+
from discord.ext import commands
|
| 7 |
+
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
intents = discord.Intents().default()
|
| 11 |
+
intents.message_content = True
|
| 12 |
+
intents.members = True
|
| 13 |
+
intents.message_content = True
|
| 14 |
+
|
| 15 |
+
bot = commands.Bot(command_prefix="!", intents=intents)
|
| 16 |
+
app = Flask(__name__)
|
| 17 |
+
|
| 18 |
+
async def handle_message(message: discord.Message):
|
| 19 |
+
user = message.author
|
| 20 |
+
content = message.content
|
| 21 |
+
|
| 22 |
+
if not content.startswith("!"):
|
| 23 |
+
return
|
| 24 |
+
|
| 25 |
+
content = content.replace("!", "")
|
| 26 |
+
|
| 27 |
+
command = content.split(" ")
|
| 28 |
+
|
| 29 |
+
if len(command) < 3:
|
| 30 |
+
await message.channel.send("Incorrent format")
|
| 31 |
+
return
|
| 32 |
+
|
| 33 |
+
match command[0]:
|
| 34 |
+
case "repeat":
|
| 35 |
+
try:
|
| 36 |
+
string = command[1]
|
| 37 |
+
repeatTimes = int(command[2])
|
| 38 |
+
|
| 39 |
+
for _ in range(repeatTimes):
|
| 40 |
+
await message.channel.send(string)
|
| 41 |
+
except Exception:
|
| 42 |
+
await message.channel.send("Error occurred!")
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@bot.event
|
| 46 |
+
async def on_message(message):
|
| 47 |
+
# Ignore messages from the bot itself
|
| 48 |
+
if message.author == bot.user:
|
| 49 |
+
return
|
| 50 |
+
|
| 51 |
+
await handle_message(message) # Call your function
|
| 52 |
+
|
| 53 |
+
await bot.process_commands(message)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
@bot.command()
|
| 57 |
+
async def server_id(ctx):
|
| 58 |
+
await ctx.send(f"The server ID is: {ctx.guild.id}")
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def start_flask():
|
| 62 |
+
app.run(port=7860, host="0.0.0.0", debug=False)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
@bot.event
|
| 66 |
+
async def on_ready():
|
| 67 |
+
print(f"Bot logged in as {bot.user}")
|
| 68 |
+
flask_thread = threading.Thread(target=start_flask)
|
| 69 |
+
flask_thread.start()
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
bot.run(os.getenv("DISCORD_BOT_TOKEN"))
|
pyproject.toml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "glfriend"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "Add your description here"
|
| 5 |
+
readme = "README.md"
|
| 6 |
+
requires-python = ">=3.12"
|
| 7 |
+
dependencies = [
|
| 8 |
+
"discord>=2.3.2",
|
| 9 |
+
"flask>=3.1.0",
|
| 10 |
+
"langchain-community>=0.3.23",
|
| 11 |
+
"langchain-google-genai>=2.1.4",
|
| 12 |
+
"langchain-openai>=0.3.17",
|
| 13 |
+
"langchain-pinecone>=0.2.6",
|
| 14 |
+
"uuid>=1.30",
|
| 15 |
+
]
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|