302 lines
11 KiB
Python
302 lines
11 KiB
Python
|
import asyncio
|
|||
|
|
|||
|
import aiohttp
|
|||
|
|
|||
|
import next
|
|||
|
from next.ext import commands
|
|||
|
import config
|
|||
|
from datetime import timedelta
|
|||
|
import random
|
|||
|
|
|||
|
|
|||
|
def convert_to_timedelta(duration_str):
|
|||
|
if duration_str.endswith('h'):
|
|||
|
hours = int(duration_str[:-1])
|
|||
|
return timedelta(hours=hours)
|
|||
|
elif duration_str.endswith('d'):
|
|||
|
days = int(duration_str[:-1])
|
|||
|
return timedelta(days=days)
|
|||
|
elif duration_str.endswith('m'):
|
|||
|
minutes = int(duration_str[:-1])
|
|||
|
return timedelta(minutes=minutes)
|
|||
|
elif duration_str.endswith('s'):
|
|||
|
seconds = int(duration_str[:-1])
|
|||
|
return timedelta(seconds=seconds)
|
|||
|
else:
|
|||
|
raise ValueError("Invalid format. Use 'h' for hours, 'd' for days, 'm' for minutes, 's' for seconds.")
|
|||
|
|
|||
|
|
|||
|
class Client(commands.CommandsClient):
|
|||
|
async def get_prefix(self, message: next.Message):
|
|||
|
return "/"
|
|||
|
|
|||
|
async def on_member_join(self, member: next.Member):
|
|||
|
if member.bot:
|
|||
|
return
|
|||
|
|
|||
|
if not config.auto_role_enabled:
|
|||
|
return
|
|||
|
|
|||
|
server = self.get_server(config.server_id)
|
|||
|
|
|||
|
role = server.get_role(config.role_id)
|
|||
|
|
|||
|
await member.edit(roles=[role])
|
|||
|
|
|||
|
print("Роль выдана участнику с ID:", member.id)
|
|||
|
|
|||
|
|
|||
|
async def on_ready(self):
|
|||
|
prefix = await self.get_prefix(None)
|
|||
|
print(f"Logged in as {self.user.name}#{self.user.discriminator}")
|
|||
|
await self.edit_status(presence=next.PresenceType.busy, text=f"{prefix}help - Babrick bot")
|
|||
|
|
|||
|
|
|||
|
@commands.command()
|
|||
|
async def help(self, ctx: commands.Context):
|
|||
|
prefix = await self.get_prefix(ctx.message)
|
|||
|
embed = next.SendableEmbed(title="Команды", description=f"`{prefix}ban (Пользователь) (Причина)` - бан пользователя\n`{prefix}unban (Пользователь)` - разбан пользователя\n`{prefix}kick (Пользователь)` - кикнут пользователя\n`{prefix}timeout (Пользователь) (Время. Пример: 1m)` - выдать таймаут пользователю\n`{prefix}untimeout (Пользователь)` - снять таймаут пользователю\n`{prefix}drel` - дрель\n`{prefix}say (Текст)` - отправка текста от имени бота (Только для создателя бота)\n`{prefix}user_info` - информация о пользователе\n`{prefix}tsuefa` - игра камень, ножницы, бумага", colour="#9723ad")
|
|||
|
await ctx.send(embed=embed)
|
|||
|
|
|||
|
|
|||
|
@commands.command()
|
|||
|
async def tsuefa(self, ctx: commands.Context):
|
|||
|
all_texts = [":rock: - камень", ":spiral_notepad: - бумага", ":scissors: - ножницы"]
|
|||
|
random.shuffle(all_texts)
|
|||
|
selected_test = random.choice(all_texts)
|
|||
|
embed = next.SendableEmbed(title="Камень, ножницы, бумага", description=f"Бросил: <@{ctx.author.id}>\nВыпало: {selected_test}", colour="#9723ad")
|
|||
|
await ctx.send(embed=embed)
|
|||
|
|
|||
|
@commands.command()
|
|||
|
async def ban(self, ctx: commands.Context, *args):
|
|||
|
if not ctx.author.has_permissions(ban_members=True):
|
|||
|
await ctx.send("У вас недостаточно прав")
|
|||
|
return
|
|||
|
|
|||
|
bot_member = ctx.server.get_member(self.user.id)
|
|||
|
|
|||
|
if not bot_member.has_permissions(ban_members=True):
|
|||
|
await ctx.send("Не достаточно прав у бота")
|
|||
|
return
|
|||
|
|
|||
|
|
|||
|
message = ' '.join(args)
|
|||
|
|
|||
|
ids = ctx.message.raw_mentions
|
|||
|
ban_id = 0
|
|||
|
reason = 'Не указана'
|
|||
|
|
|||
|
if not ids:
|
|||
|
return
|
|||
|
|
|||
|
for id in ids:
|
|||
|
ban_id = id
|
|||
|
break
|
|||
|
|
|||
|
if not ban_id:
|
|||
|
return
|
|||
|
|
|||
|
if ctx.author.id == ban_id:
|
|||
|
await ctx.send("Вы не можете забанить себя")
|
|||
|
return
|
|||
|
|
|||
|
server = ctx.server
|
|||
|
member = server.get_member(ban_id)
|
|||
|
|
|||
|
if message.replace(f"<@{ban_id}>", ""):
|
|||
|
reason = message.replace(f"<@{ban_id}>", "")
|
|||
|
|
|||
|
await member.ban(reason=reason)
|
|||
|
await ctx.send(f"Пользователь <@{ban_id}> был успешно забанен по причине: `{reason}`")
|
|||
|
|
|||
|
print(f"Пользователь под ID {ctx.author.id} забанил пользователь под ID {ban_id} по причине \"{reason}\"")
|
|||
|
|
|||
|
@commands.command()
|
|||
|
async def unban(self, ctx: commands.Context):
|
|||
|
if not ctx.author.has_permissions(ban_members=True):
|
|||
|
await ctx.send("У вас недостаточно прав")
|
|||
|
return
|
|||
|
|
|||
|
bot_member = ctx.server.get_member(self.user.id)
|
|||
|
|
|||
|
if not bot_member.has_permissions(ban_members=True):
|
|||
|
await ctx.send("Не достаточно прав у бота")
|
|||
|
return
|
|||
|
|
|||
|
ids = ctx.message.raw_mentions
|
|||
|
unban_id = 0
|
|||
|
|
|||
|
if not ids:
|
|||
|
return
|
|||
|
|
|||
|
for id in ids:
|
|||
|
unban_id = id
|
|||
|
break
|
|||
|
|
|||
|
if not unban_id:
|
|||
|
return
|
|||
|
|
|||
|
server = ctx.server
|
|||
|
member = server.get_member(unban_id)
|
|||
|
|
|||
|
await member.unban()
|
|||
|
await ctx.send(f"Пользователь <@{unban_id}> был успешно разбанен")
|
|||
|
|
|||
|
print(f"Пользователь под ID {ctx.author.id} разбанил пользователь под ID {unban_id}")
|
|||
|
|
|||
|
|
|||
|
@commands.command()
|
|||
|
async def kick(self, ctx: commands.Context, user):
|
|||
|
if not ctx.author.has_permissions(kick_members=True):
|
|||
|
await ctx.send("У вас недостаточно прав")
|
|||
|
return
|
|||
|
|
|||
|
bot_member = ctx.server.get_member(self.user.id)
|
|||
|
|
|||
|
if not bot_member.has_permissions(kick_members=True):
|
|||
|
await ctx.send("Не достаточно прав у бота")
|
|||
|
return
|
|||
|
|
|||
|
ids = ctx.message.raw_mentions
|
|||
|
kick_id = 0
|
|||
|
|
|||
|
if not ids:
|
|||
|
return
|
|||
|
|
|||
|
for id in ids:
|
|||
|
kick_id = id
|
|||
|
break
|
|||
|
|
|||
|
if not kick_id:
|
|||
|
return
|
|||
|
|
|||
|
if ctx.author.id == kick_id:
|
|||
|
await ctx.send("Вы не можете кикнуть себя")
|
|||
|
return
|
|||
|
|
|||
|
server = ctx.server
|
|||
|
member = server.get_member(kick_id)
|
|||
|
|
|||
|
await member.kick()
|
|||
|
await ctx.send(f"Пользователь <@{kick_id}> был успешно кикнут")
|
|||
|
|
|||
|
print(f"Пользователь под ID {ctx.author.id} кикнул пользователь под ID {kick_id}")
|
|||
|
|
|||
|
|
|||
|
@commands.command()
|
|||
|
async def timeout(self, ctx: commands.Context, user, time):
|
|||
|
if not ctx.author.has_permissions(timeout_members=True):
|
|||
|
await ctx.send("У вас недостаточно прав")
|
|||
|
return
|
|||
|
|
|||
|
bot_member = ctx.server.get_member(self.user.id)
|
|||
|
|
|||
|
if not bot_member.has_permissions(timeout_members=True):
|
|||
|
await ctx.send("Не достаточно прав у бота")
|
|||
|
return
|
|||
|
|
|||
|
ids = ctx.message.raw_mentions
|
|||
|
timeout_id = 0
|
|||
|
|
|||
|
if not ids:
|
|||
|
return
|
|||
|
|
|||
|
for id in ids:
|
|||
|
timeout_id = id
|
|||
|
break
|
|||
|
|
|||
|
if not timeout_id:
|
|||
|
return
|
|||
|
|
|||
|
if ctx.author.id == timeout_id:
|
|||
|
await ctx.send("Вы не можете выдать таймаут себе")
|
|||
|
return
|
|||
|
|
|||
|
server = ctx.server
|
|||
|
member = server.get_member(timeout_id)
|
|||
|
|
|||
|
await member.timeout(convert_to_timedelta(time))
|
|||
|
await ctx.send(f"Пользователю <@{timeout_id}> был успешно выдан таймаут с продолжительностю `{time}`")
|
|||
|
|
|||
|
print(f"Пользователь под ID {ctx.author.id} выдал таймаут на {time} пользователю под ID {timeout_id}")
|
|||
|
|
|||
|
|
|||
|
@commands.command()
|
|||
|
async def untimeout(self, ctx: commands.Context, user):
|
|||
|
if not ctx.author.has_permissions(timeout_members=True):
|
|||
|
await ctx.send("У вас недостаточно прав")
|
|||
|
return
|
|||
|
|
|||
|
bot_member = ctx.server.get_member(self.user.id)
|
|||
|
|
|||
|
if not bot_member.has_permissions(timeout_members=True):
|
|||
|
await ctx.send("Не достаточно прав у бота")
|
|||
|
return
|
|||
|
|
|||
|
ids = ctx.message.raw_mentions
|
|||
|
untimeout_id = 0
|
|||
|
|
|||
|
if not ids:
|
|||
|
return
|
|||
|
|
|||
|
for id in ids:
|
|||
|
untimeout_id = id
|
|||
|
break
|
|||
|
|
|||
|
if not untimeout_id:
|
|||
|
return
|
|||
|
|
|||
|
if ctx.author.id == untimeout_id:
|
|||
|
await ctx.send("Вы не можете снять таймаут у себя")
|
|||
|
return
|
|||
|
|
|||
|
server = ctx.server
|
|||
|
member = server.get_member(untimeout_id)
|
|||
|
|
|||
|
await member.timeout(convert_to_timedelta("0s"))
|
|||
|
await ctx.send(f"Пользователю <@{untimeout_id}> был успешно снят таймаут")
|
|||
|
|
|||
|
print(f"Пользователь под ID {ctx.author.id} снял таймаут пользователю под ID {untimeout_id}")
|
|||
|
|
|||
|
|
|||
|
@commands.command()
|
|||
|
async def say(self, ctx: commands.Context, *args):
|
|||
|
if ctx.author.id != config.owner_id:
|
|||
|
await ctx.send("Вы не создатель бота")
|
|||
|
return
|
|||
|
|
|||
|
message = ' '.join(args)
|
|||
|
|
|||
|
if not message:
|
|||
|
await ctx.send("Вы не ввели текст сообщения")
|
|||
|
return
|
|||
|
|
|||
|
await ctx.send(message)
|
|||
|
|
|||
|
|
|||
|
@commands.command(name="дрель")
|
|||
|
async def drel(self, ctx: commands.Context):
|
|||
|
await ctx.send("дрель я тебя люблю")
|
|||
|
|
|||
|
|
|||
|
@commands.command()
|
|||
|
async def user_info(self, ctx: commands.Context):
|
|||
|
roles = ""
|
|||
|
|
|||
|
for role in ctx.author.roles:
|
|||
|
if not role.name:
|
|||
|
continue
|
|||
|
|
|||
|
roles += role.name + "\n"
|
|||
|
|
|||
|
if roles:
|
|||
|
await ctx.send(f"ID: {ctx.author.id}\nНик: {ctx.author.name}#{ctx.author.discriminator}\nРоли; {roles}")
|
|||
|
else:
|
|||
|
await ctx.send(f"ID: {ctx.author.id}\nНик: {ctx.author.name}#{ctx.author.discriminator}")
|
|||
|
|
|||
|
async def main():
|
|||
|
async with aiohttp.ClientSession() as session:
|
|||
|
client = Client(session, config.token, help_command=None)
|
|||
|
await client.start()
|
|||
|
|
|||
|
asyncio.run(main())
|