xpyct_bot/main.py

347 lines
12 KiB
Python
Raw Normal View History

2022-05-10 16:44:44 +02:00
#from webserver import keep_alive
2021-10-05 14:06:16 +02:00
import os
2021-10-29 10:37:50 +02:00
try:
2021-10-29 11:15:33 +02:00
import nextcord
2021-10-29 10:37:50 +02:00
except ImportError:
2021-10-29 11:15:33 +02:00
print("Trying to Install required module: nextcord[voice]\n")
2022-05-06 11:16:05 +02:00
os.system("python -m pip install --upgrade nextcord[voice]")
2021-10-05 14:06:16 +02:00
import nextcord
from nextcord.ext import commands
import json
2021-10-19 16:55:59 +02:00
import asyncio
2021-10-20 10:34:44 +02:00
from urllib.parse import quote_plus
2021-10-29 10:37:50 +02:00
from speedtest import Speedtest
2021-11-01 14:56:05 +01:00
import string
2021-11-05 09:19:30 +01:00
from discord_together import DiscordTogether
2021-10-05 14:06:16 +02:00
2021-10-31 09:45:11 +01:00
def get_prefix(bot, message):
with open("prefix.json", "r") as f:
prefix = json.load(f)
return prefix[str(message.guild.id)]
2021-10-19 16:57:37 +02:00
PREFIX = "$"
2021-10-31 09:45:11 +01:00
intents = nextcord.Intents().all()
2021-11-01 14:56:05 +01:00
bot = commands.Bot(command_prefix=get_prefix, intents=intents)
2021-11-05 09:19:30 +01:00
bot.remove_command("help")
version = "Bot v2.4"
2021-10-31 09:45:11 +01:00
@bot.event
async def on_guild_join(guild):
with open("prefix.json", "r") as f:
prefix = json.load(f)
prefix[str(guild.id)] = "$"
with open("prefix.json", "w") as f:
json.dump(prefix, f, indent=4)
@bot.event
async def on_guild_remove(guild):
with open("prefix.json", "r") as f:
prefix = json.load(f)
prefix.pop(str(guild.id))
with open("prefix.json", "w") as f:
json.dump(prefix, f, indent=4)
2021-11-01 14:56:05 +01:00
@bot.event
async def on_message(message):
if {i.lower().translate(str.maketrans('','', string. punctuation)) for i in message.content.split(' ')}\
.intersection(set(json.load(open('cenz.json')))) != set():
await message.channel.send(f'{message.author.mention}, yyy… кого по губам отшлепать??')
await message.delete()
await bot.process_commands(message)
2021-10-31 09:45:11 +01:00
@bot.command()
@commands.has_permissions(administrator=True)
async def setprefix(ctx, new: str):
with open("prefix.json", "r") as f:
prefix = json.load(f)
prefix[str(ctx.guild.id)] = new
with open("prefix.json", "w") as f:
json.dump(prefix, f, indent=4)
await ctx.send(f"Новый префикс `{new}`")
2021-10-29 11:15:33 +02:00
2021-10-05 14:06:16 +02:00
@bot.event
async def on_ready():
2021-11-05 09:19:30 +01:00
bot.togetherControl = await DiscordTogether("DISCORD_TOKEN")
2021-10-29 11:15:33 +02:00
print(f"Bot logged as {bot.user} | {version}")
await bot.change_presence(
status=nextcord.Status.online, activity=nextcord.Game("$help")
)
2021-10-14 09:12:25 +02:00
2021-10-05 14:06:16 +02:00
2021-10-30 15:44:34 +02:00
@bot.command(pass_context=True)
2021-10-05 14:06:16 +02:00
async def help(ctx):
2021-10-30 15:44:34 +02:00
author = ctx.message.author
test_e = nextcord.Embed(
colour=nextcord.Colour.orange()
2021-10-29 11:15:33 +02:00
)
2021-10-31 09:45:11 +01:00
test_e.set_author(name=f"Мои команды:")
2021-10-30 15:44:34 +02:00
test_e.add_field(name="help", value="Помощь с командами", inline=False)
test_e.add_field(name="ping", value="Отображение пинга")
test_e.add_field(name="clear", value="(Либо purge или clean) очистка чата")
test_e.add_field(name="hello", value="Бот поздоровается с вами")
test_e.add_field(name="github", value="Ссылка на мой GitHub")
test_e.add_field(name="ver", value="Версия бота")
test_e.add_field(name="say", value="Пересказывание чего-либо от имени бота")
test_e.add_field(name="serverinfo", value="Информация о сервере")
test_e.add_field(name="send_m", value="Отправка сообщений в ЛС от имени бота")
test_e.add_field(name="nitro", value="NOT a free nitro")
test_e.add_field(name="guess", value="Угадай число")
2021-11-05 09:19:30 +01:00
test_e.add_field(name="монета", value="Орёл или Решка?")
2021-10-30 15:44:34 +02:00
test_e.add_field(name="play", value="Играет музыку. Пример: $play Never Gonna Give You Up")
test_e.add_field(name="loop", value="Ставит повтор воспроизведения")
test_e.add_field(name="stop", value="Остановка воспроизведения (НЕ ПАУЗА)")
test_e.add_field(name="pause", value="Ставит воспроизведение на паузу")
2021-11-01 14:56:05 +01:00
await ctx.reply("Я отправил список команд тебе в ЛС", delete_after=5.0)
2021-10-30 15:44:34 +02:00
await author.send(embed=test_e)
2021-10-29 11:15:33 +02:00
@bot.command(
aliases=[
"Ping",
"PING",
"pING",
"ping",
"Пинг",
"ПИНГ",
"пИНГ",
"пинг",
"Понг",
"ПОНГ",
"пОНГ",
"понг",
]
)
2021-10-14 09:12:25 +02:00
async def __ping(
ctx,
): # Объявление асинхронной функции __ping с возможностью публикации сообщения
2021-10-29 11:15:33 +02:00
ping = bot.ws.latency # Получаем пинг клиента
2021-10-14 09:12:25 +02:00
2021-10-29 11:15:33 +02:00
ping_emoji = "🟩🔳🔳🔳🔳" # Эмоция пинга, если он меньше 100ms
2021-10-05 14:06:16 +02:00
2021-10-29 11:15:33 +02:00
if ping > 0.10000000000000000:
ping_emoji = "🟧🟩🔳🔳🔳" # Эмоция пинга, если он больше 100ms
2021-10-05 14:06:16 +02:00
2021-10-29 11:15:33 +02:00
if ping > 0.15000000000000000:
ping_emoji = "🟥🟧🟩🔳🔳" # Эмоция пинга, если он больше 150ms
2021-10-05 14:06:16 +02:00
2021-10-29 11:15:33 +02:00
if ping > 0.20000000000000000:
ping_emoji = "🟥🟥🟧🟩🔳" # Эмоция пинга, если он больше 200ms
2021-10-05 14:06:16 +02:00
2021-10-29 11:15:33 +02:00
if ping > 0.25000000000000000:
ping_emoji = "🟥🟥🟥🟧🟩" # Эмоция пинга, если он больше 250ms
2021-10-05 14:06:16 +02:00
2021-10-29 11:15:33 +02:00
if ping > 0.30000000000000000:
ping_emoji = "🟥🟥🟥🟥🟧" # Эмоция пинга, если он больше 300ms
2021-10-05 14:06:16 +02:00
2021-10-29 11:15:33 +02:00
if ping > 0.35000000000000000:
ping_emoji = "🟥🟥🟥🟥🟥" # Эмоция пинга, если он больше 350ms
2021-10-14 09:12:25 +02:00
2021-10-29 11:15:33 +02:00
message = await ctx.send(
"Пожалуйста, подождите. . ."
) # Переменная message с первоначальным сообщением
await message.edit(
content=f"Понг! {ping_emoji} `{ping * 1000:.0f}ms` :ping_pong:"
) # Редактирование первого сообщения на итоговое (На сам пинг)
print(
f"[Logs:utils] На данный момент пинг {ping * 1000:.0f}ms | {PREFIX}ping"
) # Вывод пинга в консоль
2021-10-05 14:06:16 +02:00
@bot.command()
async def hello(ctx):
2021-10-29 11:15:33 +02:00
author = ctx.message.author
await ctx.send(f"Привет, {author.mention}!")
print(f"[Logs:utils] Приветствие было выведено | {PREFIX}hello")
2021-10-14 09:12:25 +02:00
2021-10-30 09:54:54 +02:00
@bot.command()
async def link(ctx):
await ctx.send("Ссылка на добавления бота на свой сервер: https://discord.com/api/oauth2/authorize?client_id=833720975069282344&permissions=0&scope=applications.commands%20bot")
2021-10-05 14:06:16 +02:00
@bot.command()
async def ver(ctx):
2021-10-29 11:15:33 +02:00
await ctx.send(f"{version} | Сделано CreeperXP#0363")
print(f"[Logs:utils] Информация о боте была выведена | {PREFIX}ver")
2021-10-14 09:12:25 +02:00
2021-10-05 14:06:16 +02:00
@bot.command()
2021-11-01 14:56:05 +01:00
@commands.has_permissions(administrator=True)
2021-10-05 14:06:16 +02:00
async def say(ctx, *, text):
2021-11-05 09:19:30 +01:00
await ctx.message.delete
2021-11-01 14:56:05 +01:00
await ctx.send(embed=nextcord.Embed(description=text))
print(f"[Logs:utils] Сообщение пересказано ботом | {PREFIX}say")
2021-10-14 09:12:25 +02:00
2021-10-29 13:03:52 +02:00
2021-10-05 14:06:16 +02:00
@bot.command()
async def serverinfo(ctx):
2021-10-29 11:15:33 +02:00
role_count = len(ctx.guild.roles)
serverinfoEmbed = nextcord.Embed(color=ctx.author.color)
serverinfoEmbed.add_field(name="Название", value=f"{ctx.guild.name}", inline=False)
serverinfoEmbed.add_field(
name="Кол-во юзеров", value=f"{ctx.guild.member_count}", inline=False
)
serverinfoEmbed.add_field(
name="Уровень безопасности",
value=f"{ctx.guild.verification_level}",
inline=False,
)
serverinfoEmbed.add_field(name="Кол-во ролей", value=f"{role_count}", inline=False)
serverinfoEmbed.add_field(name="ID сервера", value=f"{ctx.guild.id}", inline=False)
await ctx.send(embed=serverinfoEmbed)
2021-10-29 13:03:52 +02:00
2021-10-05 14:06:16 +02:00
2021-10-29 11:15:33 +02:00
@bot.command(aliases=["clear", "purge"])
2021-11-01 14:56:05 +01:00
@commands.has_permissions(administrator=True)
2021-10-05 14:06:16 +02:00
async def clean(ctx, amount=None):
2021-10-29 11:15:33 +02:00
await ctx.channel.purge(limit=int(amount) + 1)
print(f"[Logs:utils] {amount} сообщений удалено | {PREFIX}clean")
2021-10-14 09:12:25 +02:00
2021-10-05 14:06:16 +02:00
class Confirm(nextcord.ui.View):
2021-10-29 11:15:33 +02:00
def __init__(self):
super().__init__()
self.value = None
@nextcord.ui.button(label="Да", style=nextcord.ButtonStyle.danger)
async def confirm(
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
):
await interaction.response.send_message(
"https://github.com/CreeperXP/xpyct_bot", ephemeral=True
)
self.value = True
self.stop()
@nextcord.ui.button(label="Нет", style=nextcord.ButtonStyle.blurple)
async def cancel(
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
):
await interaction.response.send_message("Ну ладно :(", ephemeral=True)
self.value = False
self.stop()
2021-10-05 14:06:16 +02:00
2021-10-14 09:12:25 +02:00
2021-10-05 14:06:16 +02:00
@bot.command()
async def github(ctx):
2021-10-29 11:15:33 +02:00
view = Confirm()
await ctx.send("Перейти на GiHub?", view=view)
2021-10-05 14:06:16 +02:00
2021-10-29 11:15:33 +02:00
await view.wait()
2021-10-05 14:06:16 +02:00
2021-10-29 11:15:33 +02:00
if not view.value == None:
print("Timed Out")
if view.value == True:
print("Ссылка выведена")
if view.value == False:
print("Ссылка не выведена")
print(f"[Logs:utils] Ссылка на GitHub была выведена | {PREFIX}github")
2021-10-14 09:12:25 +02:00
2021-10-05 14:06:16 +02:00
@bot.command()
2021-11-01 14:56:05 +01:00
@commands.has_permissions(administrator=True)
2021-10-05 14:06:16 +02:00
async def send_m(ctx, member: nextcord.Member, *, text):
2021-11-01 14:56:05 +01:00
await member.send(
f"От {ctx.author.name}:", embed=nextcord.Embed(description=text)
)
print(
f"[Logs:utils] Сообщение от {ctx.author.name} было отправлено {member.name} | {PREFIX}send_m"
)
2021-10-14 09:12:25 +02:00
2021-10-05 14:06:16 +02:00
2021-10-20 10:34:44 +02:00
class Google(nextcord.ui.View):
def __init__(self, query: str):
super().__init__()
query = quote_plus(query)
2021-10-29 11:15:33 +02:00
url = f"https://www.google.com/search?q={query}"
self.add_item(nextcord.ui.Button(label="Google", url=url))
2021-10-20 10:34:44 +02:00
class Yandex(nextcord.ui.View):
def __init__(self, query: str):
super().__init__()
query = quote_plus(query)
2021-10-29 11:15:33 +02:00
url = f"https://yandex.ua/search/?text={query}"
self.add_item(nextcord.ui.Button(label="Яндекс", url=url))
2021-10-20 10:34:44 +02:00
2021-10-29 11:15:33 +02:00
@bot.command(aliases=["поиск", "гугл"])
2021-10-20 10:34:44 +02:00
async def google(ctx, *, query: str):
2021-10-29 11:15:33 +02:00
await ctx.reply(f"Результаты запроса `{query}`", view=Google(query))
2021-10-20 10:34:44 +02:00
2021-10-29 11:15:33 +02:00
@bot.command(aliases=["яндекс", "yndx"])
2021-10-20 10:34:44 +02:00
async def yandex(ctx, *, query: str):
2021-10-29 11:15:33 +02:00
await ctx.reply(f"Результаты запроса `{query}`", view=Yandex(query))
2021-10-20 10:34:44 +02:00
2021-10-29 10:37:50 +02:00
st = Speedtest()
dl_speed = int(st.download() / 8000)
up_speed = int(st.upload() / 8000)
2021-10-29 11:15:33 +02:00
ethernet_speed = (
f"Скорость закачки: {dl_speed} kb/s \n" f"Скорость выгрузки: {up_speed} kb/s"
)
2021-10-29 10:37:50 +02:00
2021-10-29 11:15:33 +02:00
@bot.command(aliases=["esp"])
2021-10-29 10:37:50 +02:00
async def ethspeed(ctx):
2021-10-29 11:15:33 +02:00
await ctx.send(ethernet_speed)
2021-10-29 10:37:50 +02:00
2021-10-20 13:07:59 +02:00
2021-10-30 09:54:54 +02:00
@bot.command(aliases=["нитро", "nitro"])
async def freenitro(ctx):
embed=nextcord.Embed(description=f"Click on the link and get a free nitro!\nhttps://clck.ru/9TFat")
await ctx.reply(embed=embed)
2021-10-31 09:45:11 +01:00
2021-11-05 09:19:30 +01:00
@bot.command(aliases=["youtube", "ютуб"])
async def yt(ctx):
link = await bot.togetherControl.create_link(ctx.author.voice.channel.id, 'youtube')
await ctx.send(f"{link}")
2022-05-06 11:16:05 +02:00
@bot.command()
async def timer(ctx, time: int): #таймер
await ctx.send(f"Таймер запущен на {time} секунд")
await asyncio.sleep(time)
await ctx.send(f"Таймер завершен")
2021-11-05 09:19:30 +01:00
2021-10-29 11:15:33 +02:00
# COGS
2021-10-20 13:07:59 +02:00
2021-10-20 10:34:44 +02:00
2021-10-19 17:28:42 +02:00
@bot.command() ## Стандартное объявление комманды
async def load(ctx, extensions): ## объявление функции
2021-10-29 11:15:33 +02:00
bot.load_extension(f"cogs.{extensions}") ## загрузка доплонений
await ctx.send("loaded")
2021-10-19 16:27:25 +02:00
@bot.command()
async def unload(ctx, extensions):
2021-10-29 11:15:33 +02:00
bot.unload_extension(f"cogs.{extensions}")
await ctx.send("unloaded")
2021-10-19 17:28:42 +02:00
2021-10-19 16:27:25 +02:00
@bot.command()
async def reload(ctx, extensions):
2021-10-29 11:15:33 +02:00
bot.unload_extension(f"cogs.{extensions}") # отгружаем ког
bot.load_extension(f"cogs.{extensions}") # загружаем
await ctx.send("reloaded")
2021-10-19 16:27:25 +02:00
2021-10-19 16:55:59 +02:00
for filename in os.listdir("./cogs"):
2021-10-29 11:15:33 +02:00
if filename.endswith(".py"):
bot.load_extension(f"cogs.{filename[:-3]}")
2021-10-08 13:08:49 +02:00
2021-10-31 10:08:24 +01:00
2022-05-10 16:44:44 +02:00
#keep_alive()
2021-10-19 17:28:42 +02:00
bot.run(os.getenv("DISCORD_TOKEN"))