PEP8
This commit is contained in:
parent
785a2aae77
commit
ea6e11745c
@ -1,35 +1,49 @@
|
|||||||
#dummy module
|
# dummy module
|
||||||
import asyncio
|
|
||||||
import fractale.source.main
|
|
||||||
import random
|
|
||||||
import discord
|
import discord
|
||||||
import os
|
|
||||||
from PIL import Image
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
class MainClass():
|
class MainClass():
|
||||||
def __init__(self, client, modules, owners, prefix):
|
def __init__(self, client, modules, owners, prefix):
|
||||||
self.client = client
|
self.client = client
|
||||||
self.modules = modules
|
self.modules = modules
|
||||||
self.owners = owners
|
self.owners = owners
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
self.events=['on_message'] #events list
|
self.events = ['on_message'] # events list
|
||||||
self.command="%sfractale"%self.prefix #command prefix (can be empty to catch every single messages)
|
self.command = "%sfractale" % self.prefix # command prefix (can be empty to catch every single messages)
|
||||||
|
|
||||||
self.name="Fractale"
|
self.name = "Fractale"
|
||||||
self.description="Module de génération de fractales"
|
self.description = "Module de génération de fractales"
|
||||||
self.interactive=True
|
self.interactive = True
|
||||||
self.color=0x78ffc3
|
self.color = 0x78ffc3
|
||||||
self.fractals={
|
self.fractals = {
|
||||||
"von_koch_curve_flake":{"Type":"Figures", "Max":((5000,5000), 5000, 10), "Min":((0,0),0,1), "Default":"(2500 2500) 2000 5 #ffffff 1", "Indication":"(départ) (arrivée) longueur iterations color bg stroke", "ParseData":"pfixi"},
|
"von_koch_curve_flake": {"Type": "Figures", "Max": ((5000, 5000), 5000, 10), "Min": ((0, 0), 0, 1),
|
||||||
"von_koch_curve":{"Type":"Figures", "Max":((5000,5000),(5000,5000),10), "Min":((0,0),(0,0),1), "Default":"(0 2500) (5000 2500) 5 #ffffff 1", "Indication":"(départ) (arrivée) iterations color bg stroke", "ParseData":"ppixi"},
|
"Default": "(2500 2500) 2000 5 #ffffff 1",
|
||||||
"blanc_manger":{"Type":"Figures", "Max":((5000,5000),(5000,5000),10), "Min":((0,0),(0,0),1), "Default":"(1000 1000) (4000 4000) 7 #ffffff 1", "Indication":"(départ) (arrivée) iterations color bg stroke", "ParseData":"ppixi"},
|
"Indication": "(départ) (arrivée) longueur iterations color bg stroke",
|
||||||
"dragon":{"Type":"Lsystem", "Max":((5000,5000), 2500,19), "Min":((0,0),1,1), "Default":"(2500 2500)", "Indication":"(origine) longueur iterations color bg stroke", "ParseData":"pfixi"},
|
"ParseData": "pfixi"},
|
||||||
"sierpinski_triangle":{"Type":"Lsystem", "Max":((5000,5000),2500,11), "Min":((0,0),0,1), "Default":"(0 0)", "Indication":"(origine) longueur iterations color bg stroke", "ParseData":"pfixi"},
|
"von_koch_curve": {"Type": "Figures", "Max": ((5000, 5000), (5000, 5000), 10), "Min": ((0, 0), (0, 0), 1),
|
||||||
"fractal_plant":{"Type":"Lsystem", "Max":((5000,5000),2500,8), "Min":((0,0),0,1), "Default":"(0 2500)", "Indication":"(origine) longueur iterations color bg stroke", "ParseData":"pfixi"},
|
"Default": "(0 2500) (5000 2500) 5 #ffffff 1",
|
||||||
"koch_curve_right_angle":{"Type":"Lsystem", "Max":((5000,5000),2500,9), "Min":((0,0),0,1), "Default":"(0 5000)", "Indication":"(origine) longueur iterations color bg stroke", "ParseData":"pfixi"},
|
"Indication": "(départ) (arrivée) iterations color bg stroke", "ParseData": "ppixi"},
|
||||||
"fractal_binary_tree":{"Type":"Lsystem", "Max":((5000,5000),2500,15), "Min":((0,0),0,1), "Default":"(0 0)", "Indication":"(origine) longueur iterations color bg stroke", "ParseData":"pfixi"}
|
"blanc_manger": {"Type": "Figures", "Max": ((5000, 5000), (5000, 5000), 10), "Min": ((0, 0), (0, 0), 1),
|
||||||
}
|
"Default": "(1000 1000) (4000 4000) 7 #ffffff 1",
|
||||||
self.help="""\
|
"Indication": "(départ) (arrivée) iterations color bg stroke", "ParseData": "ppixi"},
|
||||||
|
"dragon": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 19), "Min": ((0, 0), 1, 1),
|
||||||
|
"Default": "(2500 2500)", "Indication": "(origine) longueur iterations color bg stroke",
|
||||||
|
"ParseData": "pfixi"},
|
||||||
|
"sierpinski_triangle": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 11), "Min": ((0, 0), 0, 1),
|
||||||
|
"Default": "(0 0)", "Indication": "(origine) longueur iterations color bg stroke",
|
||||||
|
"ParseData": "pfixi"},
|
||||||
|
"fractal_plant": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 8), "Min": ((0, 0), 0, 1),
|
||||||
|
"Default": "(0 2500)", "Indication": "(origine) longueur iterations color bg stroke",
|
||||||
|
"ParseData": "pfixi"},
|
||||||
|
"koch_curve_right_angle": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 9), "Min": ((0, 0), 0, 1),
|
||||||
|
"Default": "(0 5000)",
|
||||||
|
"Indication": "(origine) longueur iterations color bg stroke",
|
||||||
|
"ParseData": "pfixi"},
|
||||||
|
"fractal_binary_tree": {"Type": "Lsystem", "Max": ((5000, 5000), 2500, 15), "Min": ((0, 0), 0, 1),
|
||||||
|
"Default": "(0 0)", "Indication": "(origine) longueur iterations color bg stroke",
|
||||||
|
"ParseData": "pfixi"}
|
||||||
|
}
|
||||||
|
self.help = """\
|
||||||
</prefix>fractale info <fractale>
|
</prefix>fractale info <fractale>
|
||||||
=> Affiche les informations relatives à la fractale spécifiée. (paramètres attendus, paramètres par défaut, type des arguments)
|
=> Affiche les informations relatives à la fractale spécifiée. (paramètres attendus, paramètres par défaut, type des arguments)
|
||||||
|
|
||||||
@ -41,17 +55,17 @@ class MainClass():
|
|||||||
|
|
||||||
-> Valeurs possible pour <fractale>
|
-> Valeurs possible pour <fractale>
|
||||||
```..: Toutes les fractales:
|
```..: Toutes les fractales:
|
||||||
%s```"""%'\n'.join(['......: %s'%t for t in self.fractals.keys()])
|
%s```""" % '\n'.join(['......: %s' % t for t in self.fractals.keys()])
|
||||||
|
|
||||||
async def on_message(self, message):
|
async def on_message(self, message):
|
||||||
args=message.content.split(" ")
|
args = message.content.split(" ")
|
||||||
if len(args)==1:
|
if len(args) == 1:
|
||||||
await self.modules['help'][1].send_help(message.channel, self)
|
await self.modules['help'][1].send_help(message.channel, self)
|
||||||
elif len(args)==2:
|
elif len(args) == 2:
|
||||||
pass
|
pass
|
||||||
elif len(args)==3:
|
elif len(args) == 3:
|
||||||
if args[1]=="" and args[2] in self.fractals.keys():
|
if args[1] == "" and args[2] in self.fractals.keys():
|
||||||
description="""\
|
description = """\
|
||||||
La fractale {nom} attend les arguments suivant :
|
La fractale {nom} attend les arguments suivant :
|
||||||
`{arguments}`
|
`{arguments}`
|
||||||
avec le type suivant:
|
avec le type suivant:
|
||||||
@ -61,98 +75,111 @@ Attention, les coordonnées des points doivent être entre parentheses et son co
|
|||||||
|
|
||||||
Les arguments valent par défaut :
|
Les arguments valent par défaut :
|
||||||
`{defaut}`""".format(nom=args[2])
|
`{defaut}`""".format(nom=args[2])
|
||||||
await message.channel.send(embed=discord.Embed(title="[%s] - Infos : *%s*"%(self.name,args[2]), description=""))
|
await message.channel.send(
|
||||||
|
embed=discord.Embed(title="[%s] - Infos : *%s*" % (self.name, args[2]), description=""))
|
||||||
else:
|
else:
|
||||||
await self.modules['help'][1].send_help(message.channel, self)
|
await self.modules['help'][1].send_help(message.channel, self)
|
||||||
#parsed_data=self.parse(message.content[len("%sfractale "%self.prefix):])))
|
# parsed_data=self.parse(message.content[len("%sfractale "%self.prefix):])))
|
||||||
|
|
||||||
async def send_fractal(self, message, command):
|
async def send_fractal(self, message, command):
|
||||||
return #TODO Coder la fonction
|
return # TODO Coder la fonction
|
||||||
|
|
||||||
def parse(self, inp):
|
def parse(self, inp):
|
||||||
retDic={"Success":False, "Message":"", "Result":()}
|
retDic = {"Success": False, "Message": "", "Result": ()}
|
||||||
#Parsing the fractal name and storing the corresponding dic into a variable
|
# Parsing the fractal name and storing the corresponding dic into a variable
|
||||||
try:
|
try:
|
||||||
fractal=self.fractals[inp.split(' ')[0]]
|
fractal = self.fractals[inp.split(' ')[0]]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
retDic.update({"Success":False, "Message":"La fractale %s n'existe pas."%inp.split(' ')[0]})
|
retDic.update({"Success": False, "Message": "La fractale %s n'existe pas." % inp.split(' ')[0]})
|
||||||
return(retDic)
|
return (retDic)
|
||||||
arg=' '.join(inp.split(' ')[1:]) #Stuff after the fractal name
|
arg = ' '.join(inp.split(' ')[1:]) # Stuff after the fractal name
|
||||||
#checking for incoherent parentheses usage
|
# checking for incoherent parentheses usage
|
||||||
parentheses_count=0
|
parentheses_count = 0
|
||||||
for i,char in enumerate(arg):
|
for i, char in enumerate(arg):
|
||||||
if char=='(':
|
if char == '(':
|
||||||
parentheses_count+=1
|
parentheses_count += 1
|
||||||
elif char==')':
|
elif char == ')':
|
||||||
parentheses_count-=1
|
parentheses_count -= 1
|
||||||
if not(-1<parentheses_count<2):
|
if not (-1 < parentheses_count < 2):
|
||||||
retDic.update({"Success":False, "Message":"Usage invalide de parentheses au charactère numéro %s (à partir d'après le nom de la fractale)."%i})
|
retDic.update({"Success": False,
|
||||||
return(retDic)
|
"Message": "Usage invalide de parentheses au charactère numéro %s (à partir d'après le nom de la fractale)." % i})
|
||||||
|
return (retDic)
|
||||||
|
|
||||||
#Here, we have a coherent parentheses usage
|
# Here, we have a coherent parentheses usage
|
||||||
if ',' in arg:
|
if ',' in arg:
|
||||||
retDic.update({"Success":False, "Message":"Les virgules n'ont pas leur place dans les paramètres de génération. Il ne doit y avoir que des espaces uniques."})
|
retDic.update({"Success": False,
|
||||||
return(retDic)
|
"Message": "Les virgules n'ont pas leur place dans les paramètres de génération. Il ne doit y avoir que des espaces uniques."})
|
||||||
|
return (retDic)
|
||||||
|
|
||||||
#parsing the fractal
|
# parsing the fractal
|
||||||
args=arg.replace(')','').replace('(','').split(' ')
|
args = arg.replace(')', '').replace('(', '').split(' ')
|
||||||
parsed_args=[]
|
parsed_args = []
|
||||||
i=0
|
i = 0
|
||||||
for parse in fractal['ParseData'] :
|
for parse in fractal['ParseData']:
|
||||||
if parse=='p':
|
if parse == 'p':
|
||||||
if args[i]!='*':
|
if args[i] != '*':
|
||||||
try:
|
try:
|
||||||
int(args[i])
|
int(args[i])
|
||||||
int(args[i+1])
|
int(args[i + 1])
|
||||||
except:
|
except:
|
||||||
retDic.update({"Success":False, "Message":"Les valeurs ne sont pas du bon type. (nombre entiers attendus pour les coordonnées d'un point)"})
|
retDic.update({"Success": False,
|
||||||
return(retDic)
|
"Message": "Les valeurs ne sont pas du bon type. (nombre entiers attendus pour les coordonnées d'un point)"})
|
||||||
parsed_args.append((int(args[i]),int(args[i+1])))
|
return (retDic)
|
||||||
i+=2
|
parsed_args.append((int(args[i]), int(args[i + 1])))
|
||||||
|
i += 2
|
||||||
else:
|
else:
|
||||||
parsed_args.append(self.parse(inp.split(' ')[0]+' '+fractal['Default'])['Result'][len(parsed_args)])
|
parsed_args.append(
|
||||||
i+=1
|
self.parse(inp.split(' ')[0] + ' ' + fractal['Default'])['Result'][len(parsed_args)])
|
||||||
|
i += 1
|
||||||
|
|
||||||
elif parse=='f':
|
elif parse == 'f':
|
||||||
if args[i]!='*':
|
if args[i] != '*':
|
||||||
try:
|
try:
|
||||||
float(args[i])
|
float(args[i])
|
||||||
except:
|
except:
|
||||||
retDic.update({"Success":False, "Message":"Les valeurs ne sont pas du bon type. (Nombre à virgule flottante attendu (mettre un point pour la virgule))"})
|
retDic.update({"Success": False,
|
||||||
return(retDic)
|
"Message": "Les valeurs ne sont pas du bon type. (Nombre à virgule flottante attendu (mettre un point pour la virgule))"})
|
||||||
|
return (retDic)
|
||||||
parsed_args.append(float(args[i]))
|
parsed_args.append(float(args[i]))
|
||||||
i+=1
|
i += 1
|
||||||
else:
|
else:
|
||||||
parsed_args.append(self.parse(inp.split(' ')[0]+' '+fractal['Default'])['Result'][len(parsed_args)])
|
parsed_args.append(
|
||||||
i+=1
|
self.parse(inp.split(' ')[0] + ' ' + fractal['Default'])['Result'][len(parsed_args)])
|
||||||
|
i += 1
|
||||||
|
|
||||||
elif parse=='i':
|
elif parse == 'i':
|
||||||
if args[i]!='*':
|
if args[i] != '*':
|
||||||
try:
|
try:
|
||||||
int(args[i])
|
int(args[i])
|
||||||
except:
|
except:
|
||||||
print(args[i])
|
print(args[i])
|
||||||
print(i)
|
print(i)
|
||||||
retDic.update({"Success":False, "Message":"Les valeurs ne sont pas du bon type. (Nombre entier attendu)"})
|
retDic.update({"Success": False,
|
||||||
return(retDic)
|
"Message": "Les valeurs ne sont pas du bon type. (Nombre entier attendu)"})
|
||||||
|
return (retDic)
|
||||||
parsed_args.append(int(args[i]))
|
parsed_args.append(int(args[i]))
|
||||||
i+=1
|
i += 1
|
||||||
else:
|
else:
|
||||||
parsed_args.append(self.parse(inp.split(' ')[0]+' '+fractal['Default'])['Result'][len(parsed_args)])
|
parsed_args.append(
|
||||||
i+=1
|
self.parse(inp.split(' ')[0] + ' ' + fractal['Default'])['Result'][len(parsed_args)])
|
||||||
|
i += 1
|
||||||
|
|
||||||
elif parse=='x':
|
elif parse == 'x':
|
||||||
if args[i]!='*':
|
if args[i] != '*':
|
||||||
try:
|
try:
|
||||||
if '#' in args[i]:
|
if '#' in args[i]:
|
||||||
int(args[i].replace('#','0x'),16)
|
int(args[i].replace('#', '0x'), 16)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
retDic.update({"Success":False, "Message":"Les valeurs ne sont pas du bon type. (Valeur hexadécimale attendue)"})
|
retDic.update({"Success": False,
|
||||||
return(retDic)
|
"Message": "Les valeurs ne sont pas du bon type. (Valeur hexadécimale attendue)"})
|
||||||
parsed_args.append(int(args[i].replace('#','0x'),16))
|
return (retDic)
|
||||||
i+=1
|
parsed_args.append(int(args[i].replace('#', '0x'), 16))
|
||||||
|
i += 1
|
||||||
else:
|
else:
|
||||||
parsed_args.append(self.parse(inp.split(' ')[0]+' '+fractal['Default'])['Result'][len(parsed_args)])
|
parsed_args.append(
|
||||||
i+=1
|
self.parse(inp.split(' ')[0] + ' ' + fractal['Default'])['Result'][len(parsed_args)])
|
||||||
retDic.update({"Success":True, "Result":parsed_args})
|
i += 1
|
||||||
return(retDic)
|
retDic.update({"Success": True, "Result": parsed_args})
|
||||||
|
return (retDic)
|
||||||
|
Loading…
Reference in New Issue
Block a user