-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
154 lines (114 loc) · 5.59 KB
/
bot.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import discord
import random
import os
import config as c
from discord import app_commands
from discord.ext import commands
from datetime import datetime, timedelta
import logging as log
# Configurar el sistema de logging
log.basicConfig(level=log.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# permissions
intents = discord.Intents.default()
# Allows the bot to read message content to process commands. This is essential if your bot will respond to messages.
intents.message_content = True
# Necessary if your bot needs to react to events related to members, such as when someone joins or leaves the server.
intents.members = True
# Required for handling events related to guilds, such as server configuration updates or when roles are added or
# removed.
intents.guilds = True
# Enables the bot to detect and respond to reactions on messages.
intents.reactions = True
DISCORD_TOKEN = os.environ["discord_token"]
# Configura tu bot con los intents y el prefijo
bot = commands.Bot(command_prefix='y!', intents=intents, help_command=None)
@bot.event
async def on_ready():
log.info(f'{bot.user} está listo.')
bot.start_time = datetime.now()
try:
synced = await bot.tree.sync()
log.info(f'Sincronizados {len(synced)} comando(s)')
except Exception as e:
log.error(f'Fallo al sincronizar los comandos: {e}')
@bot.tree.command(name="status")
async def status(interaction: discord.Interaction):
"""Muestra información detallada del estado del bot"""
latency = bot.latency # Latencia en segundos
status = "En línea ✅️" if bot.is_ready() else "Desconectado ❌"
uptime = datetime.now() - bot.start_time
days = uptime.days
hours, remainder = divmod(uptime.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
embed = discord.Embed(
title="Información del bot",
description=f"Datos relevantes para el funcionamiento del bot \n\n"
f"**Estado del bot: **{status}\n"
f"**Latencia: **{latency * 1000:.2f} ms\n"
f"**Tiempo en línea: **{days} días, {hours} horas, {minutes} minutos, {seconds} segundos\n\n",
color=discord.Color.from_rgb(239, 0, 5)
)
current_directory = os.getcwd()
log.info(current_directory)
image_path = os.path.join('img', 'yakuza-logo.PNG')
complete_path = os.path.join(current_directory, image_path)
log.info(image_path)
embed.set_thumbnail(url=complete_path)
embed.set_footer(text="Powered by: ⛩️Yakuza⛩️ - La Palma RP🌴")
with open(complete_path, 'rb') as f:
file = discord.File(f, filename='yakuza-logo.PNG')
embed.set_thumbnail(url='attachment://yakuza-logo.PNG')
await interaction.response.send_message(file=file, embed=embed)
@bot.tree.command(name="rank-up")
async def rank_up(interaction: discord.Interaction, member: discord.Member, new_role: discord.Role):
""" Asciende a un miembro de la Yakuza y muestra un mensaje sobre ello """
for category, subranks in c.config["ranks"].items():
possible_roles = [category] + (subranks or [])
member_roles = member.roles
if any(role.name in possible_roles for role in member_roles):
roles_to_remove = [role for role in member_roles if role.name == category or (subranks and role.name in subranks)]
if roles_to_remove:
await member.remove_roles(*roles_to_remove)
# Asigna el nuevo rango
await member.add_roles(new_role)
for category, subranks in c.config["ranks"].items():
if subranks and new_role.name in subranks:
category_role = discord.utils.get(member.guild.roles, name=category)
if category_role:
await member.add_roles(category_role)
if new_role.name == "ASCENSO A KYODAI":
random_answer = give_random_answer("rank_up", "bot_answers_phase")
else:
random_answer = give_random_answer("rank_up")
await interaction.response.send_message(random_answer.format(member.mention, new_role.mention))
@bot.tree.command(name="rank-down")
async def rank_down(interaction: discord.Interaction, member: discord.Member, new_role: discord.Role):
""" Desciende el rango a un miembro de la Yakuza y muestra un mensaje sobre ello """
for category, subranks in c.config["ranks"].items():
possible_roles = [category] + (subranks or [])
member_roles = member.roles
if any(role.name in possible_roles for role in member_roles):
roles_to_remove = [role for role in member_roles if role.name == category or (subranks and role.name in subranks)]
if roles_to_remove:
await member.remove_roles(*roles_to_remove)
# Asigna el nuevo rango
await member.add_roles(new_role)
for category, subranks in c.config["ranks"].items():
if subranks and new_role.name in subranks:
category_role = discord.utils.get(member.guild.roles, name=category)
if category_role:
await member.add_roles(category_role)
if new_role.name == "ASCENSO A KYODAI":
random_answer = give_random_answer("rank_down", "bot_answers_phase")
else:
random_answer = give_random_answer("rank_down")
await interaction.response.send_message(random_answer.format(member.mention, new_role.mention))
def give_random_answer(command, sub_command="bot_answers"):
if c.config is not None:
bot_anwser = random.choice(c.config["commands"][command][sub_command])
print(f'Respuesta escogida: {bot_anwser}')
return bot_anwser
def run_bot():
bot.run(DISCORD_TOKEN)
if __name__ == "__main__":
run_bot()