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

shitpostbot500 + double trigger

parent f8bc9466
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -9,13 +9,14 @@ import usefull
import random
from auth_file import USERNAME, PASSWORD
from googletrans import Translator
import threading
translator = Translator()
quizzes = {}
class Bot(Client):
ahah_liste = ['ahah', 'mdr', 'lol', 'Mort de rire !', 'Trop marrant', 'tu m\'as tué', 'xD', 'PTDR']
what_liste = ['wat', 'What', 'Nani', 'keske', 'dafuk', 'da fuk']
Bot.quizzes = {}
shitpostbot = {}
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs):
self.markAsDelivered(thread_id, message_object.uid)
......@@ -23,14 +24,22 @@ class Bot(Client):
log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name))
if 'Ah' in message_object.text:
self.sendLocalImage('images/ah.png', thread_id=thread_id, thread_type=thread_type)
to_send = self.tests(message_object.text, thread_id=thread_id, thread_type=thread_type, author_id=author_id, channel=self.fetchThreadInfo(thread_id)[thread_id].name)
if (author_id != self.uid or 'BOT :' not in message_object.text) and to_send is not None:
self.send(Message('BOT :' + to_send), thread_id=thread_id, thread_type=thread_type)
self.trigger_double_mots(message_object.text, thread_id, thread_type)
Bot.shitpostbot5000()
@classmethod
def shitpostbot5000(self):
for chan in Bot.shitpostbot:
if Bot.shitpostbot[chan][0].get_status():
if Bot.shitpostbot[chan][0].get_latest():
self.sendLocalImage(Bot.shitpostbot[chan][0].get_out(), thread_id=chan, thread_type=Bot.shitpostbot[chan][1])
def tests(self, texte, thread_id, thread_type, author_id, channel=''):
if texte == '!help':
help_text = 'Ce que je sais faire :\n \
!meteo <ville> ; <pays> ; <dans_n_heure(facultatif)>\n \
......@@ -50,6 +59,7 @@ class Bot(Client):
!memes <image_name_or_url> ; <texte1> ; <texte2(facultatif)> ... not yet implemented\n\
!ping \n\
!translate <phrase> ; <lang_source> ; <lang_dest>\n\
!shitpostbot5000 [status|on|off|random] ... ne pas utiliser PLEASE\n\
!about -> vas-y test-moi !\n'
return help_text
elif '!translate' in texte:
......@@ -79,9 +89,23 @@ class Bot(Client):
else:
return random.choice(['T\'es sur de ton coup là ?', 'chais pas qui c\'est...'])
# SHitpostbot5000
elif texte == '!shitpostbot5000 on':
if thread_id not in Bot.shitpostbot:
Bot.shitpostbot[thread_id] = [useless.Shitpostbot5000(), thread_type]
Bot.shitpostbot[thread_id][0].set_on()
elif texte == '!shitpostbot5000 status':
if thread_id not in Bot.shitpostbot:
return 'Ce truc n\'est pas activé et doit, à mon avis rester éteint...'
else:
return 'Eh oui, c\'est trop tard, le démon est déjà à l\'oeuvre' if Bot.shitpostbot[thread_id][0].get_status() else 'Le diable se repose...'
elif texte == '!shitpostbot5000 off':
if thread_id in Bot.shitpostbot:
Bot.shitpostbot[thread_id][0].set_off()
elif texte == '!shitpostbot5000 random':
self.sendLocalImage(Shitpostbot5000.random(), thread_id=thread_id, thread_type=thread_type)
# pour rigoler
elif any(word.lower() in texte.lower() for word in Bot.what_liste):
return random.choice(Bot.what_liste)
elif '!memes templates' in texte:
return useless.Memes.get_templates()
elif '!memes ' in texte:
......@@ -100,8 +124,8 @@ class Bot(Client):
elif any(word.lower() in texte.lower() for word in ["let\'s go", "c'est parti", "go ", "allons "]):
return 'é zé bardi !'
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)
elif any(word.lower() in texte.lower().split(' ') for word in ['noice', 'nice']):
self.sendEmoji(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:
texte = texte.replace('!kohlanta ', '')
......@@ -110,42 +134,40 @@ class Bot(Client):
return useless.pipo('useless/pipotron.txt')
elif texte == '!ping':
return 'Pong !'
elif any(word.lower() in texte.lower() for word in Bot.ahah_liste):
return random.choice(Bot.ahah_liste)
elif texte == '!rateau':
return useless.getRateau()
# petit jeu de quizz
elif '!quizz' in texte:
if 'start' in texte:
if thread_id not in quizzes.keys():
quizzes[thread_id] = useless.Quizz()
return quizzes[thread_id].start()
elif thread_id not in quizzes.keys():
if thread_id not in Bot.quizzes.keys():
Bot.quizzes[thread_id] = useless.Quizz()
return Bot.quizzes[thread_id].start()
elif thread_id not in Bot.quizzes.keys():
return 'Perdu ! T\'as oublié de lancer une game looser'
if 'new' in texte:
return quizzes[thread_id].new()
return Bot.quizzes[thread_id].new()
if 'scoreboard' in texte:
if texte.replace('!quizz scoreboard ', '') != '':
return quizzes[thread_id].scoreboard(texte.replace('!quizz scoreboard ', ''))
return Bot.quizzes[thread_id].scoreboard(texte.replace('!quizz scoreboard ', ''))
else:
return quizzes[thread_id].scoreboard()
return Bot.quizzes[thread_id].scoreboard()
if 'reset' in texte:
return quizzes[thread_id].reset()
return Bot.quizzes[thread_id].reset()
if 'indice' in texte:
return quizzes[thread_id].indice()
return Bot.quizzes[thread_id].indice()
if 'round' in texte:
return quizzes[thread_id].get_round()
return Bot.quizzes[thread_id].get_round()
if 'question' in texte:
return quizzes[thread_id].get_question()
elif '!q ' in texte and thread_id in quizzes.keys():
return Bot.quizzes[thread_id].get_question()
elif '!q ' in texte and thread_id in Bot.quizzes.keys():
personne = self.fetchUserInfo(author_id)[author_id].name
print(personne)
return quizzes[thread_id].answer(texte.replace('!q ', ''), personne)
elif "!indice" in texte and thread_id in quizzes.keys():
return quizzes[thread_id].indice()
elif "!scoreboard" in texte and thread_id in quizzes.keys():
return quizzes[thread_id].scoreboard()
return Bot.quizzes[thread_id].answer(texte.replace('!q ', ''), personne)
elif "!indice" in texte and thread_id in Bot.quizzes.keys():
return Bot.quizzes[thread_id].indice()
elif "!scoreboard" in texte and thread_id in Bot.quizzes.keys():
return Bot.quizzes[thread_id].scoreboard()
# meteo
elif '!meteo' in texte:
......@@ -170,8 +192,37 @@ class Bot(Client):
return usefull.maps(texte.replace('!maps ', ''))
except:
return 'Houston, on a un problème...'
elif texte == '!about':
elif texte == '!about' or texte == '!cyborg':
return 'Hello, je suis A.N.U.B.I.S. A Not Usefull But Intelligent System, créé par le talentueux LawiK aka Wikle aka Cyborg aka Loïc Dub que je vénère !'
# les triggers en tout genre
elif 'Ah' in texte:
self.sendLocalImage('images/ah.png', thread_id=thread_id, thread_type=thread_type)
elif any(word.lower() in texte.lower() for word in Bot.ahah_liste):
return random.choice(Bot.ahah_liste)
elif any(word.lower() in texte.lower() for word in Bot.what_liste):
return random.choice(Bot.what_liste)
# doit rester à la fin des elif
elif '!' in texte and not any(word in texte for word in [' ! ', '! ', ' !']):
return 'Gné ?'
return None
def trigger_double_mots(self, texte, thread_id, thread_type):
# genre coucou coucou donnera : Oh, coucoucou c'est marrant ça... et faire faire donnera faifaire
texte = texte.split(' ')
indice = len(texte)
voyelles = ['a', 'e', 'i', 'o', 'u', 'y']
for i in range(len(texte) - 1):
if texte[i] == texte[i + 1]:
for v in voyelles:
if texte[i].find(v) != -1:
indice = min(texte[i].find(v), indice)
if texte[i][indice] in voyelles:
indice += 1
mot = texte[i][:indice + 1] + texte[i]
self.sendMessage(message="Oh, {} c'est marrant ça...".format(mot), thread_id=thread_id, thread_type=thread_type)
return None
......
shitpostbot5k_latest.jpg

20,5 ko

......@@ -10,3 +10,4 @@ from .haddock import haddock
from .quizz import Quizz
from .kohlanta import *
from .memes import Memes
from .shitpostbot5k import *
\ No newline at end of file
#!/usr/bin/python3
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
import urllib.request
import datetime
class Shitpostbot5000(object):
def __init__(self, out="shitpostbot5k_latest.jpg"):
self.state = False
self.image = ''
self.date = datetime.datetime.now()
self.out = out
def get_latest(self):
if datetime.datetime.now() > self.date + datetime.timedelta(minutes=30):
html = urlopen('https://www.facebook.com/shitpostbot5k/feed')
bs = BeautifulSoup(html, 'html.parser')
image = bs.find_all('img', {'src': re.compile('.jpg')})[-1]['src']
if image != self.image:
urllib.request.urlretrieve(image, self.out)
self.image = image
self.date = datetime.datetime.now()
return True # new one !
return False # nothing new
def get_status(self):
return self.state
def set_on(self):
self.state = True
def set_off(self):
self.state = False
def get_out(self):
return self.out
@classmethod
def random(self):
html = urlopen('https://www.facebook.com/pg/shitpostbot5k/photos')
bs = BeautifulSoup(html, 'html.parser')
images = bs.find_all('img', {'src': re.compile('.jpg')})
images2 = bs.find_all('image_src')
for image in images:
print(image["src"])
return None
if __name__ == "__main__":
img = Shitpostbot5000()
print(img.get_latest())
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