classification par ordre alphabetique du bot

This commit is contained in:
BFlow 2020-04-28 14:36:20 +02:00
parent 991849e907
commit e46ea1f626

View file

@ -27,119 +27,25 @@ class Mybot(commands.Cog):
self.sounds_history = [] self.sounds_history = []
self.play_next.start() self.play_next.start()
@commands.command() @tasks.loop(seconds=1.5)
async def join(self, ctx): async def play_next(self):
channel = [x for x in self.bot.get_all_channels() if x.name == "Général"][0] if self.sounds:
await channel.connect() audio_file, ctx = self.sounds[0]
await asyncio.sleep(2) source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(audio_file))
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)
self.sounds.pop(0)
self.sounds_history.reverse()
self.sounds_history.append((audio_file, ctx))
self.sounds_history.reverse()
if len(self.sounds_history) > 5:
self.sounds_history = self.sounds_history[:5]
#Les commandes interagir avec le bot.
@commands.command() @commands.command()
async def disconnect(self, ctx): async def disconnect(self, ctx):
await ctx.guild.voice_client.disconnect() await ctx.guild.voice_client.disconnect()
@commands.guild_only()
@commands.command()
async def joke(self, ctx, folder=None):
user = ctx.message.author.name
if not folder or not ctx.message.content:
audio_file = random.choice([f for f in Path(here + '/Audio/').glob('**/*.mp3')])
else:
folder = folder.lower()
audio_file = random.choice([f for f in Path(here + '/Audio/').glob('**/*.mp3') if folder in str(f).lower()])
self.sounds.append((audio_file,ctx))
@commands.command()
async def repeat(self, ctx):
#if ctx.message.author.name == self.bot.user.name:
# return
user = ctx.message.author.name
source = self.sounds_history[0]
self.sounds.append(source)
@commands.command(help='Gif me')
async def gif(self, ctx):
query = ctx.message.content.replace('!gif ','')
print(query)
api_instance = giphy_client.DefaultApi()
api_key = "udhL9Rgdme3HpAoFhWVZoYM0l0XwkzLz"
lang = 'fr'
try:
api_response = api_instance.gifs_search_get(api_key, query, lang=lang, limit=10)
api_response.to_dict()['data'][0]
get_url = random.choice(api_response.to_dict()['data'])
get_url['url']
await ctx.channel.send(get_url['url'])
except ApiException as e:
await ctx.channel.send("Exception when calling DefaultApi->gifs_search_get: %s\n" % e)
@commands.command()
async def welcome(self, ctx):
#if ctx.message.author.name == self.bot.user.name:
# return
user = ctx.message.author.name
print(user)
try:
audio_file = random.choice([f for f in os.listdir(here + '/Audio/%s/' % user) if f.endswith('.mp3')])
audio_file = here + '/Audio/%s/' % user + audio_file
except:
audio_file = random.choice([f for f in Path(here + '/Audio/').glob('**/*.mp3')])
self.sounds.append((audio_file,ctx))
@commands.command(help='Update local repo')
async def update(self, message):
output = Popen('git pull'.split(), stdout=PIPE).communicate()[0]
await message.channel.send(output.decode('utf-8'))
@commands.command(help='Restart Bot')
async def restart(self, ctx):
await self.bot.logout()
@commands.command(help='Restart Bot')
async def restart_queue(self, ctx):
self.play_next.restart()
@commands.command(help='check if bot always online')
async def ping(self, message):
await message.channel.send('pong')
@commands.command(help='count lines numbers in quote file')
async def lines(self, ctx):
path = here + '/' + ctx.channel
with open(path, 'r') as f:
lines = f.read().splitlines()
nb_lines = len(lines)
with ctx.channel.typing():
await asyncio.sleep(0.5)
await ctx.channel.send("j'ai %s lignes dans mon stock" % nb_lines)
@commands.command(help='slap this ass')
async def slap(self, ctx, user=None):
slap_multiple = [
"%s prend un coup de pied au cul",
"Descente du coude sur %s",
"%s est propulsé par dessus la TROISIEME CORDE!",
"Le mec en rose, c'est moi et le mec en jaune c'est %s! https://giphy.com/gifs/gSIz6gGLhguOY",
]
if not user or not ctx.message.mentions:
online_members = []
members = ctx.guild.members
for member in members:
if str(member.status) == "online":
online_members.append(member)
user = random.choice(online_members)
user = user.mention
elif ctx.message.mentions:
user = ctx.message.mentions[0]
user = user.mention
if user == self.bot.user.mention:
with ctx.channel.typing():
await asyncio.sleep(0.5)
await ctx.channel.send("je tribuche par terre et je sais pas comment")
else:
with ctx.channel.typing():
await asyncio.sleep(len(slap_multiple)/4)
await ctx.channel.send(random.choice(slap_multiple) % user)
@commands.command(help="Interrogation issues \n Args: list, search[mot clé] et add[nom de l'issue]") @commands.command(help="Interrogation issues \n Args: list, search[mot clé] et add[nom de l'issue]")
async def issue(self, ctx, *args): async def issue(self, ctx, *args):
if args: if args:
@ -171,6 +77,102 @@ class Mybot(commands.Cog):
else: else:
await ctx.channel.send('unknown command') await ctx.channel.send('unknown command')
@commands.command()
async def join(self, ctx):
channel = [x for x in self.bot.get_all_channels() if x.name == "Général"][0]
await channel.connect()
await asyncio.sleep(2)
@commands.command(help='count lines numbers in quote file')
async def lines(self, ctx):
path = here + '/' + ctx.channel
with open(path, 'r') as f:
lines = f.read().splitlines()
nb_lines = len(lines)
with ctx.channel.typing():
await asyncio.sleep(0.5)
await ctx.channel.send("j'ai %s lignes dans mon stock" % nb_lines)
@commands.command(help='check if bot always online')
async def ping(self, message):
await message.channel.send('pong')
@commands.command()
async def repeat(self, ctx):
# if ctx.message.author.name == self.bot.user.name:
# return
user = ctx.message.author.name
source = self.sounds_history[0]
self.sounds.append(source)
@commands.command(help='Restart Bot')
async def restart(self, ctx):
await self.bot.logout()
@commands.command(help='Restart Bot')
async def restart_queue(self, ctx):
self.play_next.restart()
@commands.command(help='Update local repo')
async def update(self, message):
output = Popen('git pull'.split(), stdout=PIPE).communicate()[0]
await message.channel.send(output.decode('utf-8'))
#Les commandes pour faire mumuse avec le bot.
@commands.command(help="randomsur l'avenir des gens.")
async def avenir(self, ctx):
list_mot = ("tu seras curé, tu t'occuperas plus spécialement du catéchisme. ",
"tu seras animateur de soirées pour les gays pride. ",
"tu seras gynecologue dans une maison de retraite.",
"tu iras vivre en thaïland à cause de ton job. car tu seras ladyboy dans un bar.",
"tu sera DSI chez jacky et Michel",
"tu seras arroseur de plante aquatique.")
choix = random.choice(list_mot)
with ctx.channel.typing():
await asyncio.sleep(len(choix) / 4)
await ctx.channel.send(choix)
@commands.command(help="optionnal args : ")
async def contrepeterie(self, ctx, *args):
response = None
path = here + '/ressources/contrepeteries.txt'
lines = open(path).read().splitlines()
myline = random.choice(lines)
try:
response = "%s" % (myline)
except:
response = "Unknow error, try: !contrepeterie [mot clef]"
await ctx.send(response)
@commands.command(help='Gif me')
async def gif(self, ctx):
query = ctx.message.content.replace('!gif ', '')
print(query)
api_instance = giphy_client.DefaultApi()
api_key = "udhL9Rgdme3HpAoFhWVZoYM0l0XwkzLz"
lang = 'fr'
try:
api_response = api_instance.gifs_search_get(api_key, query, lang=lang, limit=10)
api_response.to_dict()['data'][0]
get_url = random.choice(api_response.to_dict()['data'])
get_url['url']
await ctx.channel.send(get_url['url'])
except ApiException as e:
await ctx.channel.send("Exception when calling DefaultApi->gifs_search_get: %s\n" % e)
@commands.guild_only()
@commands.command()
async def joke(self, ctx, folder=None):
user = ctx.message.author.name
if not folder or not ctx.message.content:
audio_file = random.choice([f for f in Path(here + '/Audio/').glob('**/*.mp3')])
else:
folder = folder.lower()
audio_file = random.choice([f for f in Path(here + '/Audio/').glob('**/*.mp3') if folder in str(f).lower()])
self.sounds.append((audio_file, ctx))
@commands.command(help="optionnal args : [livre] [character]") @commands.command(help="optionnal args : [livre] [character]")
async def kaamelott(self, ctx, *args): async def kaamelott(self, ctx, *args):
response = None response = None
@ -188,7 +190,7 @@ class Mybot(commands.Cog):
if args: if args:
perso = ' '.join(args) perso = ' '.join(args)
if perso and livre: if perso and livre:
url = 'https://kaamelott.chaudie.re/api/random/livre/%s/personnage/%s' % (livre,perso) url = 'https://kaamelott.chaudie.re/api/random/livre/%s/personnage/%s' % (livre, perso)
elif perso: elif perso:
url = 'https://kaamelott.chaudie.re/api/random/personnage/%s' % perso url = 'https://kaamelott.chaudie.re/api/random/personnage/%s' % perso
else: else:
@ -200,19 +202,6 @@ class Mybot(commands.Cog):
response = "Unknow error, try: !kaamelott [livre] [character]" response = "Unknow error, try: !kaamelott [livre] [character]"
await ctx.send(response) await ctx.send(response)
@commands.command(help="optionnal args : ")
async def contrepeterie(self, ctx, *args):
response = None
path = here + '/ressources/contrepeteries.txt'
lines = open(path).read().splitlines()
myline =random.choice(lines)
try:
response = "%s" % (myline)
except:
response = "Unknow error, try: !contrepeterie [mot clef]"
await ctx.send(response)
@commands.command(help="Je menotte une cornemuse et je fume Eddy Malou") @commands.command(help="Je menotte une cornemuse et je fume Eddy Malou")
async def kamoulox(self, ctx): async def kamoulox(self, ctx):
sans_verbe = get_word('nom').text + " " + get_word('complement').get('m') + " et " + get_word('nom').text + " " + get_word('complement').get('m') + "." sans_verbe = get_word('nom').text + " " + get_word('complement').get('m') + " et " + get_word('nom').text + " " + get_word('complement').get('m') + "."
@ -304,39 +293,49 @@ class Mybot(commands.Cog):
channel = [x for x in self.bot.get_all_channels() if x.name == "général"][0] channel = [x for x in self.bot.get_all_channels() if x.name == "général"][0]
await channel.send(sentence) await channel.send(sentence)
@commands.command(help='slap this ass')
@tasks.loop(seconds=1.5) async def slap(self, ctx, user=None):
async def play_next(self): slap_multiple = [
if self.sounds: "%s prend un coup de pied au cul",
audio_file,ctx = self.sounds[0] "Descente du coude sur %s",
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(audio_file)) "%s est propulsé par dessus la TROISIEME CORDE!",
if not ctx.voice_client.is_playing() and ctx.voice_client.is_connected(): "Le mec en rose, c'est moi et le mec en jaune c'est %s! https://giphy.com/gifs/gSIz6gGLhguOY",
ctx.voice_client.play(source, after=lambda e: print('Player error: %s' % e) if e else None) ]
self.sounds.pop(0) if not user or not ctx.message.mentions:
self.sounds_history.reverse() online_members = []
self.sounds_history.append((audio_file,ctx)) members = ctx.guild.members
self.sounds_history.reverse() for member in members:
if len(self.sounds_history) >5: if str(member.status) == "online":
self.sounds_history = self.sounds_history[:5] online_members.append(member)
user = random.choice(online_members)
@commands.command(help= "randomsur l'avenir des gens.") user = user.mention
async def avenir(self, ctx): elif ctx.message.mentions:
user = ctx.message.mentions[0]
list_mot = ("tu seras curé, tu t'occuperas plus spécialement du catéchisme. ", user = user.mention
"tu seras animateur de soirées pour les gays pride. ", if user == self.bot.user.mention:
"tu seras gynecologue dans une maison de retraite.",
"tu iras vivre en thaïland à cause de ton job. car tu seras ladyboy dans un bar.",
"tu sera DSI chez jacky et Michel",
"tu seras arroseur de plante aquatique.")
choix = random.choice(list_mot)
with ctx.channel.typing(): with ctx.channel.typing():
await asyncio.sleep(len(choix)/4) await asyncio.sleep(0.5)
await ctx.channel.send(choix) await ctx.channel.send("je tribuche par terre et je sais pas comment")
else:
with ctx.channel.typing():
await asyncio.sleep(len(slap_multiple) / 4)
await ctx.channel.send(random.choice(slap_multiple) % user)
@commands.command()
async def welcome(self, ctx):
# if ctx.message.author.name == self.bot.user.name:
# return
user = ctx.message.author.name
print(user)
try:
audio_file = random.choice([f for f in os.listdir(here + '/Audio/%s/' % user) if f.endswith('.mp3')])
audio_file = here + '/Audio/%s/' % user + audio_file
except:
audio_file = random.choice([f for f in Path(here + '/Audio/').glob('**/*.mp3')])
self.sounds.append((audio_file, ctx))
def get_word(word_type): def get_word(word_type):
"""Chercher les mots pour la fonction kamoulox dans le fichier xml"""
content = [] content = []
with open(here + "/ressources/base_kml.xml", "r", encoding="ISO-8859-1") as file: with open(here + "/ressources/base_kml.xml", "r", encoding="ISO-8859-1") as file:
content = file.readlines() content = file.readlines()
@ -398,6 +397,7 @@ def get_word(word_type):
result = 'Nique bien ta mère!' result = 'Nique bien ta mère!'
return result return result
#Le do[main]e du bot.
def main(): def main():
token = "NjI3MTM3NDY1MDA5ODMxOTQ2.XY4Raw.pw8sAen3bNR5aYsoTChQOudM0L8" token = "NjI3MTM3NDY1MDA5ODMxOTQ2.XY4Raw.pw8sAen3bNR5aYsoTChQOudM0L8"
bot = commands.Bot(command_prefix='!') bot = commands.Bot(command_prefix='!')
@ -406,6 +406,44 @@ def main():
if "test" in argv[-1]: if "test" in argv[-1]:
test=True test=True
@aiocron.crontab('50 9-23/1 * * *')
async def kron():
kron_choice = random.choice(["kaamelott", "slap", "kamoulox", False, False, False])
if kron_choice:
await asyncio.sleep(random.choice(range(3550)))
for channel in bot.get_all_channels():
if channel.name == "général":
current_chan = channel
ctx = await bot.get_context(current_chan.last_message)
ctx.message.content = ""
print(ctx.message.content)
random_cmd = bot.get_command(kron_choice)
await random_cmd.invoke(ctx)
@bot.event
async def on_message(message):
print(message.content)
if message.author == bot.user:
return
else:
if bot.user in message.mentions \
and len(message.mentions) < 3 \
and len(message.content.splitlines()) == 1:
path = '/data/log/%s.log' % message.channel
with open(path, 'r') as f:
lines = f.read().splitlines()
if not message.content in lines:
with open(path, 'a') as f:
f.write(message.content + '\n')
response = random.choice(lines).replace(str(bot.user.id), str(message.author.id))
with message.channel.typing():
if "http" in response:
await asyncio.sleep(len(response) / 5)
else:
await asyncio.sleep(len(response) / 4)
await message.channel.send(response)
await bot.process_commands(message)
@bot.event @bot.event
async def on_ready(): async def on_ready():
print('yeah baby!') print('yeah baby!')
@ -423,19 +461,17 @@ def main():
for member in channel.members: for member in channel.members:
await member.edit(mute=False) await member.edit(mute=False)
@aiocron.crontab('50 9-23/1 * * *') @bot.event
async def kron(): async def on_voice_state_update(member, before, after):
kron_choice = random.choice(["kaamelott","slap","kamoulox",False, False, False]) if before.channel is None and after.channel:
if kron_choice:
await asyncio.sleep(random.choice(range(3550)))
for channel in bot.get_all_channels(): for channel in bot.get_all_channels():
if channel.name == "général": if channel.name == "général":
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.content = "" ctx.message.author = member
print(ctx.message.content) welcome = bot.get_command('welcome')
random_cmd = bot.get_command(kron_choice) await asyncio.sleep(2)
await random_cmd.invoke(ctx) await welcome.invoke(ctx)
@aiocron.crontab('*/5 * * * *') @aiocron.crontab('*/5 * * * *')
async def pipelette(): async def pipelette():
@ -452,42 +488,6 @@ def main():
joke = bot.get_command('joke') joke = bot.get_command('joke')
await joke.invoke(ctx) await joke.invoke(ctx)
@bot.event
async def on_message(message):
print(message.content)
if message.author == bot.user:
return
else:
if bot.user in message.mentions \
and len(message.mentions) < 3 \
and len(message.content.splitlines()) == 1:
path = '/data/log/%s.log' % message.channel
with open(path, 'r') as f :
lines = f.read().splitlines()
if not message.content in lines:
with open(path, 'a') as f :
f.write(message.content + '\n')
response = random.choice(lines).replace(str(bot.user.id), str(message.author.id))
with message.channel.typing():
if "http" in response:
await asyncio.sleep(len(response)/5)
else:
await asyncio.sleep(len(response)/4)
await message.channel.send(response)
await bot.process_commands(message)
@bot.event
async def on_voice_state_update(member,before,after):
if before.channel is None and after.channel:
for channel in bot.get_all_channels():
if channel.name == "général":
current_chan = channel
ctx = await bot.get_context(current_chan.last_message)
ctx.message.author = member
welcome = bot.get_command('welcome')
await asyncio.sleep(2)
await welcome.invoke(ctx)
bot.add_cog(Mybot(bot)) bot.add_cog(Mybot(bot))
bot.run(token) bot.run(token)