0% found this document useful (0 votes)
15 views7 pages

Message

Uploaded by

samimahdadi8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views7 pages

Message

Uploaded by

samimahdadi8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

import discord

from discord.ext import commands, tasks


from discord.ui import Button, View
import json
import os
import datetime
import asyncio
import sys
import signal

TOKEN = 'BOT_TOKEN_HERE'

intents = discord.Intents.all()
bot = commands.Bot(command_prefix='/', intents=intents)

STATS_FILE = 'rizz_stats.json'
LOGS_FILE = 'mod_logs.json'
PROBATION_DATA_FILE = 'probation_data.json'

stats = {}
mod_logs = {}
probation_data = {}
bot_messages = []

def load_stats():
global stats
if os.path.exists(STATS_FILE):
with open(STATS_FILE, 'r') as f:
stats = json.load(f)

def save_stats():
with open(STATS_FILE, 'w') as f:
json.dump(stats, f)

def load_logs():
global mod_logs
if os.path.exists(LOGS_FILE):
with open(LOGS_FILE, 'r') as f:
mod_logs = json.load(f)

def save_logs():
with open(LOGS_FILE, 'w') as f:
json.dump(mod_logs, f)

def load_probation_data():
try:
with open(PROBATION_DATA_FILE, 'r') as f:
return json.load(f)
except FileNotFoundError:
return {}

def save_probation_data(data):
with open(PROBATION_DATA_FILE, 'w') as f:
json.dump(data, f, indent=4)

probation_data = load_probation_data()
def stop_bot(signal, frame):
global should_stop
should_stop = True
save_logs()
asyncio.run_coroutine_threadsafe(on_shutdown(), bot.loop)
asyncio.run_coroutine_threadsafe(bot.close(), bot.loop)
sys.exit(0)

def has_role_or_higher(*role_names):
async def predicate(interaction: discord.Interaction):
user_roles = [role.name for role in interaction.user.roles]
return any(role in user_roles for role in role_names)
return discord.app_commands.check(predicate)

@bot.event
async def on_ready():
load_stats()
load_logs()
load_probation_data()
global bot_messages
bot_messages = []
print("Bot is ready")
await
bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening,
name="Developed by whoknowslol._"))
try:
await bot.tree.sync()
commands_synced = len(bot.tree.get_commands())
print(f"Synced Commands: {commands_synced}")
except Exception as e:
print(f"An error occurred while syncing commands: {e}")
delete_bot_messages.start()

@bot.event
async def on_shutdown():
save_stats()
save_logs()
save_probation_data()

@bot.event
async def on_message(message):
if message.author == bot.user:
bot_messages.append(message)

def log_mod_action(user_id, action, moderator, reason=None):


if user_id not in mod_logs:
mod_logs[user_id] = []
log_entry = {
"action": action,
"moderator": moderator,
"timestamp": datetime.datetime.utcnow().isoformat()
}
if reason:
log_entry["reason"] = reason
mod_logs[user_id].append(log_entry)
save_logs()

@bot.tree.command(name="rizztrack", description="Check your or another user's rizz


level")
async def rizztrack(interaction: discord.Interaction, user: discord.Member = None):
if user is None:
user = interaction.user
user_id = str(user.id)

rizz_level = stats.get(user_id, 0)

if isinstance(rizz_level, dict):
rizz_level = rizz_level.get('rizzed', 0)

if not isinstance(rizz_level, int):


rizz_level = 0

await interaction.response.send_message(f"{user.mention} has {rizz_level} rizz


points.")

@bot.tree.command(name="test", description="Responds with pong!")


async def test(interaction: discord.Interaction):
await interaction.response.send_message("Pong!")

@bot.tree.command(name="hello", description="Replies with a greeting message")


async def hello(interaction: discord.Interaction):
user = interaction.user
await interaction.response.send_message(f"Hello, {user.mention}!")

@bot.tree.command(name="rizz", description="Rizz up another user")


async def rizz(interaction: discord.Interaction, user: discord.User):
view = View()
yes_button = Button(label="Yes", style=discord.ButtonStyle.green)
no_button = Button(label="No", style=discord.ButtonStyle.red)
view.add_item(yes_button)
view.add_item(no_button)

async def yes_callback(interaction: discord.Interaction):


if interaction.user == user:
stats[str(interaction.user.id)] = stats.get(str(interaction.user.id),
0) + 1
save_stats()
await interaction.response.send_message(f"You have rizzed up
{user.mention} Now make babies! 💀")
else:
await interaction.response.send_message("Stop tryna get a free point
💀", ephemeral=True)

async def no_callback(interaction: discord.Interaction):


if interaction.user == user:
stats[str(interaction.user.id)] = stats.get(str(interaction.user.id),
0) - 1
save_stats()
await interaction.response.send_message("You have failed -1 point for
you I'm disappointed! 😡")
else:
await interaction.response.send_message("Stop tryna get a free point
💀", ephemeral=True)

yes_button.callback = yes_callback
no_button.callback = no_callback
await interaction.response.send_message(f"Are you rizzed up, {user.mention}?",
view=view)

@bot.tree.command(name="lock", description="Lock the current channel")


@has_role_or_higher("Head Moderator", "Administrator", "Founder", "Staff Manager",
"Moderator")
async def lock(interaction: discord.Interaction):
channel = interaction.channel
role_name = "Moderator"
seagull_role = discord.utils.get(interaction.guild.roles, name=role_name)
if seagull_role:
overwrite = discord.PermissionOverwrite(send_messages=False)
try:
await channel.set_permissions(seagull_role, overwrite=overwrite)
log_mod_action(str(channel.id), "lock", interaction.user.id)
await interaction.response.send_message("Channel locked",
ephemeral=True)
except discord.Forbidden:
await interaction.response.send_message("I do not have permission to
lock this channel.", ephemeral=True)
except Exception as e:
await interaction.response.send_message(f"An error occurred: {e}",
ephemeral=True)
else:
await interaction.response.send_message(f"Role '{role_name}' not found.",
ephemeral=True)

@bot.tree.command(name="unlock", description="Unlock the current channel")


@has_role_or_higher("Head Moderator", "Administrator", "Founder", "Staff Manager",
"Moderator")
async def unlock(interaction: discord.Interaction):
channel = interaction.channel
role_name = "Moderator"
seagull_role = discord.utils.get(interaction.guild.roles, name=role_name)
if seagull_role:
try:
await channel.set_permissions(seagull_role, send_messages=True)
log_mod_action(str(channel.id), "unlock", interaction.user.id)
await interaction.response.send_message("Channel unlocked",
ephemeral=True)
except discord.Forbidden:
await interaction.response.send_message("I do not have permission to
unlock this channel.", ephemeral=True)
except Exception as e:
await interaction.response.send_message(f"An error occurred: {e}",
ephemeral=True)
else:
await interaction.response.send_message(f"Role '{role_name}' not found.",
ephemeral=True)

@bot.tree.command(name="probate", description="Put a user on probation")


@has_role_or_higher("Head Moderator", "Administrator", "Founder", "Staff Manager")
async def probate(interaction: discord.Interaction, user: discord.Member, reason:
str):
probation_role = discord.utils.get(interaction.guild.roles, name="Probationary
Moderator")
if probation_role not in user.roles:
previous_roles_ids = [role.id for role in user.roles if role.name in
["Moderator", "Trial Moderator"]]
probation_data[str(user.id)] = {
"previous_roles": previous_roles_ids
}
save_probation_data(probation_data)

roles_to_remove = [discord.utils.get(interaction.guild.roles,
name="Moderator"),
discord.utils.get(interaction.guild.roles, name="Trial
Moderator")]
await user.remove_roles(*roles_to_remove)
await user.add_roles(probation_role)

await interaction.response.send_message(f"{user.mention} has been put on


probation for: {reason}")
else:
await interaction.response.send_message(f"{user.mention} is already on
probation.", ephemeral=True)

@bot.tree.command(name="unprobate", description="Remove probation from a user")


@has_role_or_higher("Head Moderator", "Administrator", "Founder", "Staff Manager")
async def unprobate(interaction: discord.Interaction, user: discord.Member):
probation_role = discord.utils.get(interaction.guild.roles, name="Probationary
Moderator")

if probation_role in user.roles:
if str(user.id) in probation_data:
previous_roles_ids = probation_data[str(user.id)].get("previous_roles",
[])
previous_roles = [interaction.guild.get_role(role_id) for role_id in
previous_roles_ids]
probation_data.pop(str(user.id))
save_probation_data(probation_data)

await user.remove_roles(probation_role)
await user.add_roles(*previous_roles)

await interaction.response.send_message(f"{user.mention} has been


removed from probation.")
else:
await interaction.response.send_message(f"{user.mention} was not on
probation.", ephemeral=True)
else:
await interaction.response.send_message(f"{user.mention} is not on
probation.", ephemeral=True)

@bot.tree.command(name="help", description="List all available commands")


async def help_command(interaction: discord.Interaction):
commands = [
"/rizztrack - Check your or another user's rizz level",
"/test - Responds with pong!",
"/hello - Replies with a greeting message",
"/rizz - Rizz up another user",
"/lock - Lock the current channel",
"/unlock - Unlock the current channel",
"/probate - Put a user on probation",
"/unprobate - Remove probation from a user",
"/modlogs - View the moderation logs for a specific user or all logs"
]
embed = discord.Embed(title="Help Command", description="Here are the available
commands:", color=discord.Color.green())
embed.add_field(name="Commands", value="\n".join(commands), inline=False)
await interaction.response.send_message(embed=embed, ephemeral=True)

@bot.tree.command(name="modlogs", description="View the moderation logs for a


specific user or all logs")
@has_role_or_higher("Head Moderator", "Administrator", "Founder", "Staff Manager",
"Moderator")
async def modlogs(interaction: discord.Interaction, user: discord.Member = None):
try:
with open('mod_logs.json', 'r') as file:
data = json.load(file)

embed = discord.Embed(title="Moderator Logs", color=discord.Color.blue())

if user:
user_id = str(user.id)
actions = data.get(user_id, [])

if actions:
actions_text = ""
for action in actions:
moderator_id = action.get('moderator')
moderator_mention = f"<@{moderator_id}>" if moderator_id else
"Unknown"
action_str = f"**Action:** {action.get('action', 'N/A')}\n" \
f"**Moderator:** {moderator_mention}\n" \
f"**Timestamp:** {action.get('timestamp', 'N/A')}\
n" \
f"**Reason:** {action.get('reason', 'N/A')}\n\n"
actions_text += action_str

embed.add_field(name=f"Logs for {user}", value=actions_text or "No


logs found for this user.", inline=False)
else:
embed.add_field(name=f"Logs for {user}", value="No logs found for
this user.", inline=False)
else:
if data:
for user_id, actions in data.items():
user = interaction.guild.get_member(int(user_id))
user_name = user.mention if user else f"User ID {user_id}"
actions_text = ""
for action in actions:
moderator_id = action.get('moderator')
moderator_mention = f"<@{moderator_id}>" if moderator_id
else "Unknown"
action_str = f"**Action:** {action.get('action', 'N/A')}\n"
\
f"**Moderator:** {moderator_mention}\n" \
f"**Timestamp:** {action.get('timestamp',
'N/A')}\n" \
f"**Reason:** {action.get('reason', 'N/A')}\n\
n"
actions_text += action_str

embed.add_field(name=f"Logs for {user_name}",


value=actions_text or "No logs found.", inline=False)
else:
embed.add_field(name="Logs", value="No logs available.",
inline=False)

await interaction.response.send_message(embed=embed)
except Exception as e:
await interaction.response.send_message(f"An error occurred: {e}",
ephemeral=True)

@tasks.loop(minutes=1)
async def delete_bot_messages():
for message in bot_messages:
if message.author == bot.user:
try:
await message.delete()
except discord.NotFound:
pass
bot_messages.clear()

signal.signal(signal.SIGINT, stop_bot)
signal.signal(signal.SIGTERM, stop_bot)

bot.run(TOKEN)

You might also like