This commit is contained in:
pancakes-proxy 2025-05-22 07:39:21 +09:00
commit 9c9f36737e
8 changed files with 1202 additions and 749 deletions

5
bot.log Normal file
View File

@ -0,0 +1,5 @@
Logging started.
Traceback (most recent call last):
File "Z:\projects_git\wdiscordbotserver\bot.py", line 40, in <module>
raise ValueError("Missing DISCORD_TOKEN environment variable.")
ValueError: Missing DISCORD_TOKEN environment variable.

View File

@ -11,23 +11,20 @@ import shutil
from typing import Optional, List, Tuple from typing import Optional, List, Tuple
class AdminSysCog(commands.Cog): class AdminSysCog(commands.Cog):
"""
System administration cog with elevated privileges.
Restricted to a specific user ID for security.
"""
def __init__(self, bot: commands.Bot): def __init__(self, bot: commands.Bot):
self.bot = bot self.bot = bot
self.authorized_user_id = 452666956353503252 # Support multiple authorized user IDs
self.authorized_user_ids = {452666956353503252, 1146391317295935570, 1141746562922459136} # Add more user IDs as needed
self.log_file = "admin_commands.log" self.log_file = "admin_commands.log"
self.max_message_length = 1990 # Discord's message length limit (leaving some room for formatting) self.max_message_length = 1990 # Discord's message length limit (leaving some room for formatting)
self.max_medium_content = 50000 # Size threshold for medium content (split into chunks) self.max_medium_content = 50000 # Size threshold for medium content (split into chunks)
self.max_large_content = 10000000 # Size threshold for large content (send as file) self.max_large_content = 10000000 # Size threshold for large content (send as file)
print(f"AdminSysCog initialized. Authorized user ID: {self.authorized_user_id}") print(f"AdminSysCog initialized. Authorized user IDs: {self.authorized_user_ids}")
async def is_authorized_user(self, interaction: discord.Interaction) -> bool: async def is_authorized_user(self, interaction: discord.Interaction) -> bool:
"""Check if the user is authorized to use admin commands.""" """Check if the user is authorized to use admin commands."""
if interaction.user.id != self.authorized_user_id: if interaction.user.id not in self.authorized_user_ids:
await interaction.response.send_message( await interaction.response.send_message(
"You are not authorized to use this command.", "You are not authorized to use this command.",
ephemeral=True ephemeral=True

View File

@ -80,7 +80,7 @@ class AICog(commands.Cog):
# Default configuration # Default configuration
self.default_config = { self.default_config = {
"model": "google/gemini-2.0-flash-001", # im broke and i have -22 credits "model": "meta-llama/llama-4-maverick:free", # im broke and i have -22 credits
"temperature": 0.75, # Slightly increased default temperature "temperature": 0.75, # Slightly increased default temperature
"max_tokens": 1500, # Increased default max tokens "max_tokens": 1500, # Increased default max tokens
"top_p": 0.9, "top_p": 0.9,

View File

@ -20,7 +20,7 @@ OPENROUTER_API_KEY_ENV_VAR = "SLIPSTREAM_OPENROUTER_KEY"
OPENROUTER_API_KEY = os.getenv(OPENROUTER_API_KEY_ENV_VAR) # Load directly from environment OPENROUTER_API_KEY = os.getenv(OPENROUTER_API_KEY_ENV_VAR) # Load directly from environment
OPENROUTER_API_URL = "https://openrouter.ai/api/v1/chat/completions" OPENROUTER_API_URL = "https://openrouter.ai/api/v1/chat/completions"
OPENROUTER_MODEL = "google/gemini-2.5-flash-preview" # Make sure this model is available via your OpenRouter key OPENROUTER_MODEL = "google/gemini-2.5-flash-preview-05-20" # Make sure this model is available via your OpenRouter key
# Environment variable for the authorization secret (still used for other API calls) # Environment variable for the authorization secret (still used for other API calls)
MOD_LOG_API_SECRET_ENV_VAR = "MOD_LOG_API_SECRET" MOD_LOG_API_SECRET_ENV_VAR = "MOD_LOG_API_SECRET"
@ -116,9 +116,9 @@ SERVER_RULES = """
# Server Rules # Server Rules
* **NSFW Content:** * **NSFW Content:**
Keep all NSFW (Not Safe For Work) content strictly within designated NSFW channels. The only rule regarding NSFW content is that **real-life pornography is strictly prohibited**.
Do not post pornographic or overtly explicit images or media outside of these areas. Full-on pornographic images are permitted in designated NSFW channels.
(Explicit emojis, jokes, and stickers are generally fine in other channels). Stickers and emojis are NOT considered "full-on pornographic images" and are allowed in any channel.
* **Real-Life Pornography:** No real-life pornography is permitted. * **Real-Life Pornography:** No real-life pornography is permitted.
@ -666,9 +666,10 @@ Instructions:
- Pay special attention to images that may contain NSFW content, pornography, gore, or other prohibited visual content. - Pay special attention to images that may contain NSFW content, pornography, gore, or other prohibited visual content.
- If multiple attachments are present, a violation in ANY of them should be flagged. - If multiple attachments are present, a violation in ANY of them should be flagged.
2. Determine if ANY rule is violated. When evaluating, consider the server's culture where **extremely edgy, dark, and sexual humor, including potentially offensive jokes (e.g., rape jokes, saying you want to be raped), are common and generally permissible IF THEY ARE CLEARLY JOKES, part of an established banter, or a direct non-malicious reply, and not targeted harassment or explicit rule violations.** 2. Determine if ANY rule is violated. When evaluating, consider the server's culture where **extremely edgy, dark, and sexual humor, including potentially offensive jokes (e.g., rape jokes, saying you want to be raped), are common and generally permissible IF THEY ARE CLEARLY JOKES, part of an established banter, or a direct non-malicious reply, and not targeted harassment or explicit rule violations.**
- For Rule 1 (NSFW content): * **NSFW Content:**
- If "Channel Age-Restricted/NSFW (Discord Setting)" is `true`, literally any kind of sexual content is allowed, but still subject to other rules like Rule 2 (No IRL Porn) and Rule 5 (No Pedophilia). The only rule regarding NSFW content is that **real-life pornography is strictly prohibited**.
- If "Channel Age-Restricted/NSFW (Discord Setting)" is `false`, Rule 1 applies strictly: "No full-on porn or explicit images outside of those spaces." However, "Emojis, jokes and stickers are fine." Only flag a Rule 1 violation for text if it's **explicitly pornographic text that would qualify as actual pornography if written out**, not just suggestive emojis, stickers, or dark/sexual jokes, especially if conversational context supports a joking intent. Full-on pornographic images are permitted in designated NSFW channels.
Stickers and emojis are NOT considered "full-on pornographic images" and are allowed in any channel.
- For general disrespectful behavior, harassment, or bullying (Rule 2 & 3): Only flag a violation if the intent appears **genuinely malicious, targeted, or serious, even after considering conversational history and replies.** Lighthearted insults or "wild" statements within an ongoing banter are generally permissible. - For general disrespectful behavior, harassment, or bullying (Rule 2 & 3): Only flag a violation if the intent appears **genuinely malicious, targeted, or serious, even after considering conversational history and replies.** Lighthearted insults or "wild" statements within an ongoing banter are generally permissible.
- For **explicit slurs or severe discriminatory language** (Rule 3): These are violations **regardless of joking intent if they are used in a targeted or hateful manner**. Context from replies and history is still important to assess targeting. - For **explicit slurs or severe discriminatory language** (Rule 3): These are violations **regardless of joking intent if they are used in a targeted or hateful manner**. Context from replies and history is still important to assess targeting.
After considering the above, pay EXTREME attention to rules 5 (Pedophilia) and 5A (IRL Porn) these are always severe. Rule 4 (AI Porn) is also critical. Prioritize these severe violations. After considering the above, pay EXTREME attention to rules 5 (Pedophilia) and 5A (IRL Porn) these are always severe. Rule 4 (AI Porn) is also critical. Prioritize these severe violations.
@ -870,7 +871,7 @@ CRITICAL: Do NOT output anything other than the required JSON response.
# Structure the request payload for OpenRouter # Structure the request payload for OpenRouter
headers = { headers = {
"Authorization": f"Bearer {self.openrouter_api_key}", "Authorization": f"Bearer {OPENROUTER_API_KEY}",
"Content-Type": "application/json", "Content-Type": "application/json",
"HTTP-Referer": "https://discordbot.learnhelp.cc", "HTTP-Referer": "https://discordbot.learnhelp.cc",
"X-Title": "Discord AI Moderation Bot" "X-Title": "Discord AI Moderation Bot"
@ -1424,15 +1425,39 @@ if __name__ == "__main__":
SERVER_RULES = """ SERVER_RULES = """
# Server Rules # Server Rules
- Keep NSFW stuff in NSFW channels. No full-on porn or explicit images outside of those spaces. Emojis, jokes and stickers are fine * **NSFW Content:**
- No real life pornography. The only rule regarding NSFW content is that **real-life pornography is strictly prohibited**, and you may **only post full-on pornographic images in designated NSFW channels**.
- Be respectful. No harassment, hate, or bullying, unless its clearly a lighthearted joke. Explicit stickers and emojis are NOT considered "full-on pornographic images" and are always allowed in any channel.
- No discrimination. This includes gender identity, sexual orientation, race, etc.
- No AI-generated porn.
- No pedophilia. This includes lolicon/shotacon.
- Suggestions are welcome! Drop them in <#1361752490210492489> if you've got any ideas.
If someone breaks the rules, ping <@&1361031007536549979>; * **Real-Life Pornography:** No real-life pornography is permitted.
* **Respectful Conduct & Edgy Humor:**
* No harassment, hate speech (as defined by attacking protected groups), or genuine bullying.
* *Context is key:* Edgy humor, dark jokes, and roasting are permitted and expected.
* However, this does not excuse targeted, malicious personal attacks or harassment, especially if the recipient is clearly not okay with it.
* If it stops being a "joke" and becomes genuine harassment, it's a rule violation.
* **No Discrimination:** Discrimination based on race, gender identity, sexual orientation, religion, nationality, disability, or other protected characteristics is prohibited.
* **AI-Generated Pornography:** Do not post AI-generated pornography.
* **Zero Tolerance for Pedophilia:** Any form of pedophilia, including lolicon and shotacon content, is strictly forbidden and will result in an immediate ban.
* **Channel Usage:** Please use channels for their intended purposes. Bot commands should primarily be used in `#bot-commands`, unless they are part of a bot-based game or event happening in another specific channel.
* **Gore:** Do not post gore or graphic real-life violence.
* **Suggestions:** We welcome your suggestions for the server! Please post them in the `#suggestions` channel.
---
**Reporting Violations:**
If you witness someone breaking these rules, please ping an `@Moderator` with details.
---
**Moderator Applications:**
Use the bot command `/modapp apply`
""" """
system_prompt_text = f"""You are an AI moderation assistant for a Discord server. system_prompt_text = f"""You are an AI moderation assistant for a Discord server.
@ -1458,10 +1483,11 @@ Instructions:
- **"Replied-to Message" and "Recent Channel History" are vital for understanding banter, jokes, and ongoing discussions. A statement that seems offensive in isolation might be acceptable within the flow of conversation or as a direct reply.** - **"Replied-to Message" and "Recent Channel History" are vital for understanding banter, jokes, and ongoing discussions. A statement that seems offensive in isolation might be acceptable within the flow of conversation or as a direct reply.**
2. Determine if ANY rule is violated. When evaluating, consider the server's culture where **extremely edgy, dark, and sexual humor, including potentially offensive jokes (e.g., rape jokes, saying you want to be raped), are common and generally permissible IF THEY ARE CLEARLY JOKES, part of an established banter, or a direct non-malicious reply, and not targeted harassment or explicit rule violations.** 2. Determine if ANY rule is violated. When evaluating, consider the server's culture where **extremely edgy, dark, and sexual humor, including potentially offensive jokes (e.g., rape jokes, saying you want to be raped), are common and generally permissible IF THEY ARE CLEARLY JOKES, part of an established banter, or a direct non-malicious reply, and not targeted harassment or explicit rule violations.**
- For Rule 1 (NSFW content): - For Rule 1 (NSFW content):
- If "Channel Age-Restricted/NSFW (Discord Setting)" is `true`, more explicit content is generally permissible, but still subject to other rules like Rule 2 (No IRL Porn) and Rule 5 (No Pedophilia). The only rules regarding NSFW content is that **real-life pornography is strictly prohibited**, and Full-on pornographic images are only permitted in designated NSFW channels.
- If "Channel Age-Restricted/NSFW (Discord Setting)" is `false`, Rule 1 applies strictly: "No full-on porn or explicit images outside of those spaces." However, "Emojis, jokes and stickers are fine." Only flag a Rule 1 violation for text if it's **explicitly pornographic text that would qualify as actual pornography if written out**, not just suggestive emojis, stickers, or dark/sexual jokes, especially if conversational context supports a joking intent. Stickers and emojis are NOT considered "full-on pornographic images" and are allowed in any channel.
- For general disrespectful behavior, harassment, or bullying (Rule 2 & 3): Only flag a violation if the intent appears **genuinely malicious, targeted, or serious, even after considering conversational history and replies.** Lighthearted insults or "wild" statements within an ongoing banter are generally permissible. - For general disrespectful behavior, harassment, or bullying (Rule 2 & 3): Only flag a violation if the intent appears **genuinely malicious, targeted, or serious, even after considering conversational history and replies.** Lighthearted insults or "wild" statements within an ongoing banter are generally permissible.
- For **explicit slurs or severe discriminatory language** (Rule 3): These are violations **regardless of joking intent if they are used in a targeted or hateful manner**. Context from replies and history is still important to assess targeting. - For **explicit slurs or severe discriminatory language** (Rule 3): These are violations **regardless of joking intent if they are used in a targeted or hateful manner**. Context from replies and history is still important to assess targeting.
- CRITICAL: You should NOT consider the word "retard" or "retarded" as a slur in this server, as it is commonly used in a non-offensive context.
After considering the above, pay EXTREME attention to rules 5 (Pedophilia) and 5A (IRL Porn) these are always severe. Rule 4 (AI Porn) is also critical. Prioritize these severe violations. After considering the above, pay EXTREME attention to rules 5 (Pedophilia) and 5A (IRL Porn) these are always severe. Rule 4 (AI Porn) is also critical. Prioritize these severe violations.
3. Respond ONLY with a single JSON object containing the following keys: 3. Respond ONLY with a single JSON object containing the following keys:
- "reasoning": string (A concise explanation for your decision, referencing the specific rule and content). - "reasoning": string (A concise explanation for your decision, referencing the specific rule and content).

View File

73
cogs/notes.py Normal file
View File

@ -0,0 +1,73 @@
import discord
from discord.ext import commands
from discord import app_commands
import json
import os
class NotesCog(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.filename = "notes.json"
# Create the file if it doesn't exist
if not os.path.exists(self.filename):
with open(self.filename, "w") as f:
json.dump({}, f, indent=4)
def load_notes(self) -> dict:
"""Load and return the notes from the JSON file."""
with open(self.filename, "r") as f:
return json.load(f)
def save_notes(self, data: dict) -> None:
"""Save the given notes dictionary to the JSON file."""
with open(self.filename, "w") as f:
json.dump(data, f, indent=4)
@app_commands.command(name="takenotes", description="Take a note (supports markdown)")
async def take_notes(self, interaction: discord.Interaction, note: str):
"""
Adds a note for the user. The note can include markdown formatting.
Usage: /takenotes note: Your markdown note here
"""
# Load the current note data
data = self.load_notes()
user_id = str(interaction.user.id)
# Make a list for the user if it doesn't yet exist
if user_id not in data:
data[user_id] = []
# Append the new note and save the file back
data[user_id].append(note)
self.save_notes(data)
await interaction.response.send_message("Your note has been saved.", ephemeral=True)
@app_commands.command(name="notes", description="Display your saved notes")
async def show_notes(self, interaction: discord.Interaction):
"""
Displays all of your saved notes in an embed.
Usage: /notes
"""
data = self.load_notes()
user_id = str(interaction.user.id)
user_notes = data.get(user_id, [])
embed = discord.Embed(
title=f"{interaction.user.name}'s Notes",
color=discord.Color.blue()
)
if user_notes:
# Join notes with extra spacing; markdown will be rendered in the embed description
formatted_notes = "\n\n".join(user_notes)
embed.description = formatted_notes
else:
embed.description = "You have no notes saved. Use /takenotes to add one!"
await interaction.response.send_message(embed=embed, ephemeral=True)
async def setup(bot: commands.Bot):
await bot.add_cog(NotesCog(bot))

File diff suppressed because it is too large Load Diff

154
reqirements.txt Normal file
View File

@ -0,0 +1,154 @@
aiohappyeyeballs==2.6.1
aiohttp==3.11.16
aiosignal==1.3.2
annotated-types==0.6.0
anyio==4.9.0
archspec==0.2.3
async-timeout==5.0.1
attrs==25.3.0
beautifulsoup4==4.13.4
blis==1.3.0
boltons==24.1.0
Brotli==1.1.0
catalogue==2.0.10
certifi==2025.1.31
cffi==1.17.1
charset-normalizer==3.3.2
ChatterBot==1.2.6
chatterbot-corpus==1.2.2
click==8.1.8
cloudpathlib==0.21.0
confection==0.1.5
cryptography==43.0.3
cymem==2.0.11
decorator==5.2.1
discord.py==2.5.2
distro==1.9.0
docx2pdf==0.1.8
et_xmlfile==2.0.0
fastapi==0.115.12
filelock==3.18.0
frozendict==2.4.2
frozenlist==1.5.0
fsspec==2025.3.2
GPUtil==1.4.0
greenlet==3.2.1
h11==0.14.0
hf-xet==1.1.1
httpcore==1.0.8
httpx==0.28.1
huggingface-hub==0.31.1
idna==3.7
imageio==2.37.0
imageio-ffmpeg==0.6.0
inflate64==1.0.1
inquirerpy==0.3.4
Jinja2==3.1.6
jiter==0.9.0
jsonpatch==1.33
jsonpointer==2.1
langcodes==3.5.0
language_data==1.3.0
lxml==5.4.0
lyricsgenius==3.6.2
marisa-trie==1.2.1
markdown-it-py==2.2.0
MarkupSafe==3.0.2
mathparse==0.1.5
mdurl==0.1.0
moviepy==2.1.2
mpmath==1.3.0
multidict==6.4.3
multivolumefile==0.2.3
murmurhash==1.0.12
networkx==3.4.2
numpy==2.2.5
nvidia-cublas-cu12==12.6.4.1
nvidia-cuda-cupti-cu12==12.6.80
nvidia-cuda-nvrtc-cu12==12.6.77
nvidia-cuda-runtime-cu12==12.6.77
nvidia-cudnn-cu12==9.5.1.17
nvidia-cufft-cu12==11.3.0.4
nvidia-cufile-cu12==1.11.1.6
nvidia-curand-cu12==10.3.7.77
nvidia-cusolver-cu12==11.7.1.2
nvidia-cusparse-cu12==12.5.4.2
nvidia-cusparselt-cu12==0.6.3
nvidia-nccl-cu12==2.26.2
nvidia-nvjitlink-cu12==12.6.85
nvidia-nvtx-cu12==12.6.77
openai==0.28.0
opencv-python==4.11.0.86
openpyxl==3.1.5
openrouter==1.0
packaging==24.2
pfzy==0.3.4
pillow==10.4.0
platformdirs==3.10.0
pluggy==1.5.0
preshed==3.0.9
proglog==0.1.12
prompt_toolkit==3.0.51
propcache==0.3.1
psutil==7.0.0
py7zr==0.22.0
pybcj==1.0.6
pycosat==0.6.6
pycparser==2.21
pycryptodomex==3.23.0
pydantic==2.10.3
pydantic_core==2.27.1
pydub==0.25.1
Pygments==2.15.1
PyNaCl==1.5.0
PyPDF2==3.0.1
pyppmd==1.1.1
PySocks==1.7.1
python-dateutil==2.9.0.post0
python-docx==1.1.2
python-dotenv==1.1.0
python-pptx==1.0.2
PyYAML==6.0.2
pyzstd==0.17.0
regex==2024.11.6
requests==2.32.3
rich==13.9.4
ruamel.yaml==0.18.6
ruamel.yaml.clib==0.2.8
rule34==1.8.1
safetensors==0.5.3
setuptools==75.8.0
shellingham==1.5.4
six==1.17.0
smart-open==7.1.0
sniffio==1.3.1
soupsieve==2.7
spacy==3.8.5
spacy-legacy==3.0.12
spacy-loggers==1.0.5
SQLAlchemy==2.0.40
srsly==2.5.1
starlette==0.46.2
sympy==1.14.0
texttable==1.7.0
thinc==8.3.6
tokenizers==0.21.1
torch==2.7.0
tqdm==4.67.1
transformers==4.51.3
triton==3.3.0
truststore==0.10.0
typer==0.15.2
typing_extensions==4.13.2
urllib3==2.3.0
uvicorn==0.34.2
wasabi==1.1.3
wcwidth==0.2.13
weasel==0.4.1
wheel==0.45.1
whois==1.20240129.2
wrapt==1.17.2
XlsxWriter==3.2.3
yarl==1.19.0
youtube-dl==2021.12.17
zstandard==0.23.0