fix some stuff
This commit is contained in:
parent
112760299f
commit
a9cc9e20c0
1 changed files with 47 additions and 9 deletions
|
@ -43,7 +43,12 @@ stream_handler.setLevel(logging.INFO)
|
||||||
logger.addHandler(stream_handler)
|
logger.addHandler(stream_handler)
|
||||||
|
|
||||||
|
|
||||||
class Mybot(commands.Cog):
|
ffmpeg_options = {
|
||||||
|
'options': '-vn -loglevel debug',
|
||||||
|
}
|
||||||
|
|
||||||
|
#class Mybot(commands.Cog):
|
||||||
|
class Mybot(discord.Client):
|
||||||
#Fonctions necesaires pour Kabot.
|
#Fonctions necesaires pour Kabot.
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -66,13 +71,18 @@ class Mybot(commands.Cog):
|
||||||
self.sounds = []
|
self.sounds = []
|
||||||
self.nickname = nickname
|
self.nickname = nickname
|
||||||
self.sounds_history = []
|
self.sounds_history = []
|
||||||
self.play_next.start()
|
#self.play_next.start()
|
||||||
|
|
||||||
@tasks.loop(seconds=1.5)
|
async def setup_hook(self) -> None:
|
||||||
|
# create the background task and run it in the background
|
||||||
|
self.bg_task = self.loop.create_task(self.play_next())
|
||||||
|
|
||||||
|
#@tasks.loop(seconds=1.5)
|
||||||
async def play_next(self):
|
async def play_next(self):
|
||||||
if self.sounds:
|
if self.sounds:
|
||||||
audio_file, ctx = self.sounds[0]
|
audio_file, ctx = self.sounds[0]
|
||||||
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(audio_file))
|
print(type(audio_file))
|
||||||
|
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(audio_file,**ffmpeg_options))
|
||||||
if not ctx.voice_client.is_playing() and ctx.voice_client.is_connected():
|
if not ctx.voice_client.is_playing() and ctx.voice_client.is_connected():
|
||||||
ctx.voice_client.play(source, after=lambda e: print('Player error: %s' % e) if e else None)
|
ctx.voice_client.play(source, after=lambda e: print('Player error: %s' % e) if e else None)
|
||||||
self.sounds.pop(0)
|
self.sounds.pop(0)
|
||||||
|
@ -591,6 +601,9 @@ def get_word(word_type):
|
||||||
|
|
||||||
#Le do[main]e de Kabot.
|
#Le do[main]e de Kabot.
|
||||||
def main():
|
def main():
|
||||||
|
intents = discord.Intents.default()
|
||||||
|
intents.members = True
|
||||||
|
intents.messages = True
|
||||||
logger.info("Initialisation de Kabot")
|
logger.info("Initialisation de Kabot")
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
@ -632,6 +645,8 @@ def main():
|
||||||
gif_token = config['giphy']['token']
|
gif_token = config['giphy']['token']
|
||||||
bot = commands.Bot(
|
bot = commands.Bot(
|
||||||
command_prefix='!',
|
command_prefix='!',
|
||||||
|
intents=intents,
|
||||||
|
audio_path="/home/mika/kabot-audio",
|
||||||
)
|
)
|
||||||
|
|
||||||
test = False
|
test = False
|
||||||
|
@ -658,6 +673,7 @@ def main():
|
||||||
if message.author == bot.user:
|
if message.author == bot.user:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
print(message.content)
|
||||||
if bot.user in message.mentions \
|
if bot.user in message.mentions \
|
||||||
and len(message.mentions) < 3 \
|
and len(message.mentions) < 3 \
|
||||||
and len(message.content.splitlines()) == 1:
|
and len(message.content.splitlines()) == 1:
|
||||||
|
@ -669,6 +685,7 @@ def main():
|
||||||
f.write(message.content + '\n')
|
f.write(message.content + '\n')
|
||||||
response = random.choice(lines).replace(str(bot.user.id), str(message.author.id))
|
response = random.choice(lines).replace(str(bot.user.id), str(message.author.id))
|
||||||
if response.startswith('!'):
|
if response.startswith('!'):
|
||||||
|
print('test')
|
||||||
command_name = response.split()[0].replace('!', '')
|
command_name = response.split()[0].replace('!', '')
|
||||||
cmd = bot.get_command(command_name)
|
cmd = bot.get_command(command_name)
|
||||||
await cmd.invoke(message)
|
await cmd.invoke(message)
|
||||||
|
@ -681,6 +698,25 @@ def main():
|
||||||
await message.channel.send(response)
|
await message.channel.send(response)
|
||||||
await bot.process_commands(message)
|
await bot.process_commands(message)
|
||||||
|
|
||||||
|
@bot.command()
|
||||||
|
async def join(interaction: discord.Interaction):
|
||||||
|
channel = [x for x in bot.get_all_channels() if x.name == voice_channel][0]
|
||||||
|
await channel.connect()
|
||||||
|
await asyncio.sleep(2)
|
||||||
|
|
||||||
|
@bot.command()
|
||||||
|
async def welcome(interaction: discord.Interaction):
|
||||||
|
# if ctx.message.author.name == self.bot.user.name:
|
||||||
|
# return
|
||||||
|
user = interaction.message.author.name
|
||||||
|
print(user)
|
||||||
|
try:
|
||||||
|
audio_file = random.choice([f for f in os.listdir(bot.audio_path + '/%s/' % user) if f.endswith('.mp3')])
|
||||||
|
audio_file = bot.audio_path + '/%s/' % user + audio_file
|
||||||
|
except:
|
||||||
|
audio_file = random.choice([f"{f}" for f in Path(bot.audio_path + '/').glob('**/*.mp3')])
|
||||||
|
bot.sounds.append((audio_file, interaction))
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print('yeah baby!')
|
print('yeah baby!')
|
||||||
|
@ -693,8 +729,8 @@ def main():
|
||||||
await bot.user.edit(nick=nickname)
|
await bot.user.edit(nick=nickname)
|
||||||
await current_chan.send('Le troll est dans la place !')
|
await current_chan.send('Le troll est dans la place !')
|
||||||
ctx = await bot.get_context(current_chan.last_message)
|
ctx = await bot.get_context(current_chan.last_message)
|
||||||
join = bot.get_command('join')
|
#join = bot.get_command('join')
|
||||||
await join.invoke(ctx)
|
#await join.invoke(ctx)
|
||||||
for channel in bot.get_all_channels():
|
for channel in bot.get_all_channels():
|
||||||
if channel.name == voice_channel:
|
if channel.name == voice_channel:
|
||||||
for member in channel.members:
|
for member in channel.members:
|
||||||
|
@ -708,9 +744,9 @@ def main():
|
||||||
current_chan = channel
|
current_chan = channel
|
||||||
ctx = await bot.get_context(current_chan.last_message)
|
ctx = await bot.get_context(current_chan.last_message)
|
||||||
ctx.message.author = member
|
ctx.message.author = member
|
||||||
welcome = bot.get_command('welcome')
|
#welcome = bot.get_command('welcome')
|
||||||
await asyncio.sleep(2)
|
await asyncio.sleep(2)
|
||||||
await welcome.invoke(ctx)
|
#await welcome.invoke(ctx)
|
||||||
|
|
||||||
@aiocron.crontab('*/5 * * * *')
|
@aiocron.crontab('*/5 * * * *')
|
||||||
async def pipelette():
|
async def pipelette():
|
||||||
|
@ -726,7 +762,9 @@ def main():
|
||||||
ctx.message.content = ""
|
ctx.message.content = ""
|
||||||
joke = bot.get_command('joke')
|
joke = bot.get_command('joke')
|
||||||
await joke.invoke(ctx)
|
await joke.invoke(ctx)
|
||||||
|
@bot.command(help='check if bot always online')
|
||||||
|
async def ping(ctx):
|
||||||
|
await ctx.channel.send('pong')
|
||||||
bot.add_cog(
|
bot.add_cog(
|
||||||
Mybot(
|
Mybot(
|
||||||
bot,
|
bot,
|
||||||
|
|
Loading…
Reference in a new issue