Skip to content

Commit

Permalink
update of lavalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bergaman9 committed Jan 8, 2024
1 parent d3bde90 commit a0e5797
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .idea/contro-bot.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 48 additions & 36 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import asyncio
import os
import discord
from discord.ext import commands

from datetime import datetime, timedelta
import datetime, time
import time
from datetime import timedelta

import asyncio
import discord
import dotenv
import wavelink
from discord.ext import commands
from wavelink.ext import spotify
import dotenv

from utils import create_embed

dotenv.load_dotenv()
TOKEN = os.getenv("CONTRO_TOKEN")


class Bot(commands.Bot):

def __init__(self) -> None:
Expand All @@ -24,39 +24,42 @@ def __init__(self) -> None:

super().__init__(command_prefix=">", intents=intents, help_command=None)

async def setup_hook(self) -> None:
# Lavalink sunucularını bir liste içerisinde tanımla
lavalink_servers = [
{"uri": "wss://narco.buses.rocks:2269", "password": "glasshost1984", "secure": False},
{"uri": "wss://lava.horizxon.tech:80", "password": "horizxon.tech", "secure": False},
{"uri": "wss://104.167.222.158:11487", "password": "reedrouxmusicisgay", "secure": False},
{"uri": "wss://lava1.horizxon.tech:443", "password": "horizxon.tech", "secure": True},
{"uri": "wss://lava2.horizxon.tech:443", "password": "horizxon.tech", "secure": True},
]

# SpotifyClient'ı bir kere oluştur
sc = spotify.SpotifyClient(
client_id='0c7f24e228844860a8a920d2e69ed11d',
client_secret='be5c4415a8bc461a83f744822a803edf'
)

# Her bir sunucuya bağlanmayı dene
for server in lavalink_servers:
try:
node: wavelink.Node = wavelink.Node(uri=server["uri"], password=server["password"], secure=False)
await wavelink.NodePool.connect(client=self, nodes=[node], spotify=sc)
print(f"Connected to lavalink {node.uri}")
break # Eğer başarılı bir bağlantı kurulduysa döngüyü kır
except Exception as e:
print(f"Failed to connect to {server['uri']}. Error: {e}")
# async def setup_hook(self) -> None:
# # Lavalink sunucularını bir liste içerisinde tanımla
# lavalink_servers = [
# {"uri": "wss://narco.buses.rocks:2269", "password": "glasshost1984", "secure": False},
# {"uri": "wss://lava.horizxon.tech:80", "password": "horizxon.tech", "secure": False},
# {"uri": "wss://104.167.222.158:11487", "password": "reedrouxmusicisgay", "secure": False},
# {"uri": "wss://lava1.horizxon.tech:443", "password": "horizxon.tech", "secure": True},
# {"uri": "wss://lava2.horizxon.tech:443", "password": "horizxon.tech", "secure": True},
# ]
#
# # SpotifyClient'ı bir kere oluştur
# sc = spotify.SpotifyClient(
# client_id='0c7f24e228844860a8a920d2e69ed11d',
# client_secret='be5c4415a8bc461a83f744822a803edf'
# )
#
# # Her bir sunucuya bağlanmayı dene
# for server in lavalink_servers:
# try:
# node: wavelink.Node = wavelink.Node(uri=server["uri"], password=server["password"], secure=False)
# await wavelink.NodePool.connect(client=self, nodes=[node], spotify=sc)
# print(f"Connected to lavalink {node.uri}")
# break # Eğer başarılı bir bağlantı kurulduysa döngüyü kır
# except Exception as e:
# print(f"Failed to connect to {server['uri']}. Error: {e}")


bot = Bot()


@bot.event
async def on_ready():
bot.startTime = time.time()
await bot.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.watching, name=f'{len(bot.guilds)} server'))
await bot.change_presence(status=discord.Status.online,
activity=discord.Activity(type=discord.ActivityType.watching,
name=f'{len(bot.guilds)} server'))
await bot.tree.sync()
count = len(bot.guilds)
print(f'Logged on as {count}, your bot {bot.user}!')
Expand All @@ -66,12 +69,13 @@ async def on_ready():
async def hello(interaction: discord.Interaction, user: discord.Member):
await interaction.response.send_message(f"Hello {user}")


@bot.event
async def on_message(message):

# komutları mesaj olarak görmesin diye
await bot.process_commands(message)


@bot.event
async def on_member_update(before, after):
guild_id = 306081207278501890
Expand All @@ -80,7 +84,8 @@ async def on_member_update(before, after):
if discord.utils.get(after.roles, name="Çavuş") and discord.utils.get(before.roles, name="Er"):
await after.remove_roles(discord.utils.get(after.roles, name="Er"))

if discord.utils.get(after.roles, name="Çavuş") is None and discord.utils.get(before.roles, name="Çavuş") is not None:
if discord.utils.get(after.roles, name="Çavuş") is None and discord.utils.get(before.roles,
name="Çavuş") is not None:
await after.add_roles(discord.utils.get(after.guild.roles, name="Er"))

# if after.guild == guild:
Expand All @@ -99,24 +104,28 @@ async def on_member_update(before, after):
# role = discord.utils.get(after.guild.roles, name="Çekiliş")
# await after.remove_roles(role)


@bot.command()
async def uptime(ctx):
uptime = str(timedelta(seconds=int(round(time.time() - bot.startTime))))
embed = discord.Embed(title="Uptime", description=uptime, color=ctx.author.color)
await ctx.send(embed=embed)


@bot.command()
@commands.is_owner()
async def load(ctx, extension):
await bot.load_extension(f'cogs.{extension}')
await ctx.send(create_embed(description=f"Loaded cog!", color=discord.Color.green()))


@bot.command()
@commands.is_owner()
async def unload(ctx, extension):
await bot.unload_extension(f'cogs.{extension}')
await ctx.send(embed=create_embed(description=f"Unloaded cog!", color=discord.Color.green()))


@bot.command()
@commands.is_owner()
async def reload(ctx, extension):
Expand All @@ -127,13 +136,16 @@ async def reload(ctx, extension):
except Exception as e:
await ctx.send(embed=create_embed(description=f"Error: {e}", color=discord.Color.red()))


async def cogs_load():
for fn in os.listdir("./cogs"):
if fn.endswith(".py"):
await bot.load_extension(f"cogs.{fn[:-3]}")


async def main():
await cogs_load()
await bot.start(TOKEN)

asyncio.run(main())

asyncio.run(main())

0 comments on commit a0e5797

Please sign in to comment.