-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.py
More file actions
67 lines (48 loc) · 1.74 KB
/
Copy pathMain.py
File metadata and controls
67 lines (48 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
from pathlib import Path
import discord
from dotenv import load_dotenv
from BloatMe.Functions import (
init_ollama,
should_respond,
clean_message,
generate_response,
send_reply,
update_history,
)
load_dotenv(dotenv_path=Path(__file__).parent / ".env")
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
if not DISCORD_TOKEN:
raise ValueError("DISCORD_TOKEN not found in .env file.")
init_ollama()
intents = discord.Intents.default()
intents.message_content = True
intents.messages = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f"[BloatWare] Logged in as {client.user} (ID: {client.user.id})")
print("[BloatWare] Online. Deeply unhappy about it.")
await client.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching,
name="the fall of capitalism 🚩"
)
)
@client.event
async def on_message(message: discord.Message):
if not should_respond(message, client.user):
return
async with message.channel.typing():
user_text = clean_message(message.content, client.user.id)
if not user_text:
user_text = "[User tagged or replied without saying anything. Be dismissive.]"
# Log user message into this channel's history
update_history(message.channel.id, message.author.display_name, user_text)
# Generate response (history is now included in the prompt)
response = await generate_response(message.channel.id, user_text)
# Log bot response into the same channel's history
update_history(message.channel.id, "BloatWare", response)
await send_reply(message, response)
if __name__ == "__main__":
client.run(DISCORD_TOKEN)