fix command and messages and add quotes functions

This commit is contained in:
Milka64 2019-09-29 19:55:33 +02:00
parent 3c24bf434e
commit c62385f79b
2 changed files with 40 additions and 16 deletions

BIN
Benjamin_Prejent.mp3 Normal file

Binary file not shown.

View file

@ -6,6 +6,8 @@ import random
import discord
from discord.ext import commands
import os
def quotes():
quotes = [
"Pour savoir sy a du vent, il faut mettre son doigt dans le cul du coq.",
@ -20,18 +22,18 @@ def quotes():
response = random.choice(quotes)
return response
def main():
client = discord.Client()
token = "NjI3MTM3NDY1MDA5ODMxOTQ2.XY4Raw.pw8sAen3bNR5aYsoTChQOudM0L8"
class Mybot(discord.Client):
bot = commands.Bot(command_prefix='!')
@bot.command(name='ping', help='Responds with a random quote')
async def ping(ctx):
await ctx.send('pong')
async def join(ctx):
author = message.author
channel = author.voice_channel
await self.join_voice_channel(channel)
@bot.command(name='test', help='Responds with a random quote')
async def nine_nine(ctx):
async def ping(self, message):
await message.channel.send('pong')
async def test(self, message):
quotes = [
"Pour savoir sy a du vent, il faut mettre son doigt dans le cul du coq.",
"Y'a des méchants ?",
@ -43,17 +45,39 @@ def main():
]
response = random.choice(quotes)
await ctx.send(response)
await message.channel.send(response)
@bot.event
async def on_message(message):
async def on_message(self, message):
print(message.content)
if message.author == bot.user:
if message.author == self.user:
return
if message.content.startswith('!') and not message.content.startswith('!on_'):
try:
print('self.' + message.content[1:] + '(message)')
await eval('self.' + message.content[1:] + '(message)')
except:
await message.channel.send("%s ? Ouais, c'est pas faux !" % message.content[1:])
if message.content == 'pwet':
await message.channel.send('pong')
elif 'ben' in str(message.author):
await message.channel.send(quotes())
else:
if self.user in message.mentions and len(message.mentions) < 3:
path = '/tmp/%s.log' % message.channel
with open(path, 'a') as f :
f.write(message.content + '\n')
with open(path, 'r') as f :
lines = f.read().splitlines()
response = random.choice(lines).replace(str(self.user.id), str(message.author.id))
await message.channel.send(response)
return
def main():
token = "NjI3MTM3NDY1MDA5ODMxOTQ2.XY4Raw.pw8sAen3bNR5aYsoTChQOudM0L8"
client = Mybot()
client.run(token)
bot.run(token)
if __name__ == "__main__":
main()