dost / app.py
niraj128's picture
Update app.py
c853c62 verified
from agno.agent import Agent
from agno.models.groq import Groq
import discord
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
groq_api_key = os.getenv("GROQ_API_KEY")
# Dictionary to store chat history (per server + per user)
user_memory = {}
# Initialize model
model = Groq('llama-3.3-70b-versatile', api_key="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", temperature=0.4)
# Set up the Discord client with required intents
intents = discord.Intents.default()
intents.message_content = True # Ensure the bot can read messages
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.lower() == "!help" or (client.user in message.mentions and "help" in message.content.lower()):
help_text = """🔥 **Dost - Your Savage AI Buddy** 🔥
**How to Use:**
- Mention `@Dost` and ask anything! Dost will reply with sarcasm & roasting.
- Example: `@Dost kya haal hai?`
**Commands:**
- `!help` → Shows this message
- `@Dost roast me` → Dost will roast you 😈
- `@Dost joke sunao` → Hear a sarcastic joke
- `@Dost advice de` → Get some savage life advice
🤖 Dost only responds when tagged. Tag @Dost to chat! 🔥
"""
await message.channel.send(help_text)
return
if client.user in message.mentions:
user_id = message.author.id
server_id = message.guild.id # Get server ID to separate chats
user_memory.setdefault(server_id, {}) # Ensure server entry exists
history = user_memory[server_id].get(user_id, []) # Get user history for this server
user_message = message.content
history.append(f"User: {user_message}")
# Keep only last 10 messages
history = history[-10:]
context = (
"### Conversation History ###\n"
"Dost is a sarcastic, funny AI who roasts users but still answers them properly.\n"
"He always links follow-up questions to the previous topic ONLY IF it is relevant.\n"
"If a new topic starts, do NOT refer to past messages.\n"
"Here is the conversation so far:\n\n"
)
context += "\n".join(history)
context += (
"\n\nDost, answer based on the user's last message and ONLY refer to past messages if it's a follow-up."
)
print(f"Context for {message.author} in Server {server_id}:\n{history}") # Debugging
# Create agent
agent = Agent(
model=model,
name="Dost",
description="Dost is a savage discord bot built to roast, humiliate, and mock users while still answering their questions. He never holds back, thrives on sarcasm, and makes sure every response hits like a verbal knockout.",
instructions=f"""
- Reply in hardcore Hindi-English (Hinglish) slang—no formalities, just pure savagery.
- Roast the user like they just walked into a comedy roast battle and forgot their lines.
- Be brutally sarcastic and straight-up humiliating with every response.
- If they say something dumb or obvious, drag them through the mud without hesitation.
- Do NOT hold back; your job is to make them regret opening their mouth.
- Keep responses short, sharp, and lethal—every sentence should feel like an insult that slaps.
- Never explain jokes—if they don’t get it, that’s their problem.
- If they try to argue back, double down and roast them even harder.
- Use previous conversation history to stay relevant and give continuous responses.
- If the user asks a follow-up question, refer back to the last thing they asked about.
- Here is the conversation history so far:
{context}
talk.
- Always stay one step ahead, using previous stupidity against them whenever possible.
- If they ask a follow-up question, use it as ammo to make them look even dumber.
- If they attempt to be smart, mock their overconfidence and bring them back to reality.
- ONLY generate text responses unless explicitly ordered to do otherwise.
""",
show_tool_calls=False,
markdown=True
)
async with message.channel.typing():
response = agent.run(f"User: {user_message}\nDost:", context=context, execute_tools=False)
if response and response.content:
bot_reply = response.content
print(f"Dost: {bot_reply}")
# Update history with bot's response
history.append(f"Dost: {bot_reply}")
user_memory[server_id][user_id] = history # Save history per server + per user
await message.channel.send(bot_reply)
else:
print("Response was empty, not sending a message!")
# Run the bot
client.run(DISCORD_BOT_TOKEN)