Skip to content
Extraits de code Groupes Projets
Valider 7394c059 rédigé par Loïc Wikle DUBARD's avatar Loïc Wikle DUBARD
Parcourir les fichiers

memes impleented

parent bcb28388
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
**Ajout:** **Ajout:**
- script bot.py quasi complet - script bot.py quasi complet
- quizz marche - quizz marche
- le bot fait des memes !!
--- ---
......
...@@ -38,7 +38,7 @@ class Bot(Client): ...@@ -38,7 +38,7 @@ class Bot(Client):
!useless \n \ !useless \n \
!chuck \n\ !chuck \n\
!nordpress \n \ !nordpress \n \
!quizz [start|new|reset|scoreboard|indice|round|question] ... not yet implemented\n \ !quizz [start|new|reset|scoreboard|indice|round|question] \n \
!q <reponse> pour répondre au quizz\n\ !q <reponse> pour répondre au quizz\n\
!haddock \n \ !haddock \n \
!philo \n \ !philo \n \
...@@ -84,11 +84,21 @@ class Bot(Client): ...@@ -84,11 +84,21 @@ class Bot(Client):
return random.choice(Bot.what_liste) return random.choice(Bot.what_liste)
elif '!memes ' in texte: elif '!memes ' in texte:
texte = texte.replace('!memes ', '').split(' ; ') texte = texte.replace('!memes ', '').split(' ; ')
useless.memes(texte) if len(texte) == 3:
self.sendLocalImage('meme.png', thread_id=thread_id, thread_type=thread_type) image, text1, text2 = texte
elif len(text) == 2:
image, text1 = texte
text2 = ''
try:
meme = useless.Memes(image, text1, text2)
meme.process()
self.sendLocalImage(meme.get_result(), thread_id=thread_id, thread_type=thread_type)
except:
self.send(Message(text='Ya un petit problème dans la plantation...'), thread_id=thread_id, thread_type=thread_type)
elif any(word.lower() in texte.lower() for word in ["let\'s go", "c'est parti", "go ", "allons "]): elif any(word.lower() in texte.lower() for word in ["let\'s go", "c'est parti", "go ", "allons "]):
return 'é zé bardi !' return 'é zé bardi !'
elif any(word.lower() in texte.lower() for word in ['noice ', 'nice ', 'ok']): elif any(word.lower() in texte.lower() for word in ['noice ', 'nice ']):
self.send(Message(text="👍", emoji_size=EmojiSize.LARGE), thread_id=thread_id, thread_type=thread_type) self.send(Message(text="👍", emoji_size=EmojiSize.LARGE), thread_id=thread_id, thread_type=thread_type)
# self.send(Message(emoji_size=EmojiSize.LARGE), thread_id=thread_id, thread_type=thread_type) # self.send(Message(emoji_size=EmojiSize.LARGE), thread_id=thread_id, thread_type=thread_type)
elif '!kohlanta' in texte: elif '!kohlanta' in texte:
......
Fichier ajouté
...@@ -2,3 +2,5 @@ requests ...@@ -2,3 +2,5 @@ requests
fbchat fbchat
wikipedia wikipedia
googletrans googletrans
textwrap3
pillow
\ No newline at end of file
sample_out.jpg

18,6 ko

...@@ -9,3 +9,4 @@ from .pipotron import pipo ...@@ -9,3 +9,4 @@ from .pipotron import pipo
from .haddock import haddock from .haddock import haddock
from .quizz import Quizz from .quizz import Quizz
from .kohlanta import * from .kohlanta import *
from .memes import Memes
\ No newline at end of file
Fichier ajouté
...@@ -5,45 +5,53 @@ import PIL ...@@ -5,45 +5,53 @@ import PIL
from PIL import ImageFont from PIL import ImageFont
from PIL import Image from PIL import Image
from PIL import ImageDraw from PIL import ImageDraw
import urllib
import urllib.request
import textwrap3
class Memes(object): class Memes(object):
images = { images = {
"10guy": ["10guy.jpg"], "10guy": "10guy.jpg",
"euh": ["images/euh.jpg"], "euh": "images/euh.jpg",
"gangbang": ["gangbang.jpg"], "gangbang": "gangbang.jpg",
"killyou": ["killyou.jpg"], "killyou": "killyou.jpg",
"maths": ["maths.jpg"], "maths": "maths.jpg",
"mdr": ["mdr.jpg"], "mdr": "mdr.jpg",
"ohlala": ["ohlala.jpg"], "ohlala": "ohlala.jpg",
"ohlala2": ["ohlala2.jpg"], "ohlala2": "ohlala2.jpg",
"salt": ["salt.jpg"], "salt": "salt.jpg",
"smart": ["smart.jpg"], "smart": "smart.jpg",
"speechless": ["speechless.jpg"], "speechless": "speechless.jpg",
"suicide": ["suicide.jpg"], "suicide": "suicide.jpg",
"surprised": ["suprised.jpg"], "surprised": "suprised.jpg",
"goodchoice": ["goodchoice.jpg"], "goodchoice": "goodchoice.jpg",
"nanithefuck": ["nanithefuck.jpg"], "nanithefuck": "nanithefuck.jpg",
"badsurprise": ["badsurprise.jpg"], "badsurprise": "badsurprise.jpg",
"boyfriend": ["boyfriend.jpg"], "boyfriend": "boyfriend.jpg",
"thisisfine": ["thisisfine.jpg"], "thisisfine": "thisisfine.jpg",
"thisisnotfine": ["thisisnotfine.jpg"], "thisisnotfine": "thisisnotfine.jpg",
"depressing": ["depressing.jpg"], "depressing": "depressing.jpg",
"avengers": ["avengers.jpg"], "avengers": "avengers.jpg",
"godblessing": ["godblessings.jpg"], "godblessing": "godblessings.jpg",
"homer": ["homer.jpg"], "homer": "homer.jpg",
"thanos": ["thanos.jpg"], "thanos": "thanos.jpg",
"trash": ["trash.jpg"], "trash": "trash.jpg",
"whatisthis": ["whatisthis.png"] "whatisthis": "whatisthis.png"
} }
def __init__(self, name, text1, text2='', rep='images/memes_images/'): def __init__(self, image, text1, text2='', rep='images/memes_images/', out='sample_out.jpg'):
self.name = name if image.startswith("http://") or image.startswith("https://"):
urllib.request.urlretrieve(image, "sample_in.jpg")
self.fichier = "sample_in.jpg"
else:
assert image in Memes.images, "Can\'t open image..."
self.fichier = rep + Memes.images[image]
self.text1 = text1 self.text1 = text1
self.text2 = text2 self.text2 = text2
self.out = out
@staticmethod def ecrire(self, draw, text, font, pos):
def ecrire(draw, text, font, pos):
x, y = pos x, y = pos
for adj in range(3): for adj in range(3):
# move right # move right
...@@ -66,9 +74,36 @@ class Memes(object): ...@@ -66,9 +74,36 @@ class Memes(object):
# create normal text on image # create normal text on image
draw.text(pos, text, fill="white", font=font) draw.text(pos, text, fill="white", font=font)
def get_image(self): def process(self, textsize=30):
pass # lettres_par_ligne = int(40 / textsize * 30)
img = Image.open(self.fichier) # on ouvre l'image
img = img.resize((500, int(img.size[1] * 500 / img.size[0]))) # on la redimensionne propotionnellement pour quelle soit de largeur 500
draw = ImageDraw.Draw(img) # pour pouvoir modifier l'image
print(img.size)
W, H = img.size
font = ImageFont.truetype("impact.ttf", textsize)
para1 = textwrap3.wrap(self.text1, width=30) # le dessin du texte 1
current_h1, pad = 10, 10
para2 = textwrap3.wrap(self.text2, width=30) # le dessin du texte 2
w, h = draw.textsize(self.text2, font=font) # just to get the next line
current_h2, pad = H - 10 - len(para2) * h, 10
# là on ecrit pour de vrai
for line in para1:
w, h = draw.textsize(line, font=font)
self.ecrire(draw, line, font, ((W - w) / 2, current_h1))
current_h1 += h + pad
for line in para2:
w, h = draw.textsize(line, font=font)
self.ecrire(draw, line, font, ((W - w) / 2, current_h2))
current_h2 += h + pad
img.save(self.out) # bon ben on enregistre
def get_result(self):
return self.out
if __name__ == '__main__': if __name__ == '__main__':
meme1 = Memes(smart, 'test1', 'test2') meme1 = Memes('smart', 'test1 lol !', 'test2 mdr ?')
img = meme1.get_image() file = meme1.process()
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter