diff --git a/data/Futura.ttc b/data/Futura.ttc new file mode 100644 index 0000000..3df9d83 Binary files /dev/null and b/data/Futura.ttc differ diff --git a/data/vzhuh_sample.png b/data/vzhuh_sample.png new file mode 100644 index 0000000..7c76f44 Binary files /dev/null and b/data/vzhuh_sample.png differ diff --git a/requirements.txt b/requirements.txt index de1d83a..578514e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ python-telegram-bot==5.3.0 redis==2.10.5 +Pillow==4.1.0 diff --git a/src/handler/commands/__init__.py b/src/handler/commands/__init__.py index 6e1ec01..c3a67de 100644 --- a/src/handler/commands/__init__.py +++ b/src/handler/commands/__init__.py @@ -6,6 +6,14 @@ from src.handler.commands.get_stats import GetStats from src.handler.commands.moderate import Moderate from src.handler.commands.chance import Chance +from src.handler.commands.butts import Butts +from src.handler.commands.boobs import Boobs +from src.handler.commands.meow import Meow +from src.handler.commands.woof import Woof +from src.handler.commands.borscht import Borscht +from src.handler.commands.xkcd import XKCD +from src.handler.commands.vzhuh import Vzhuh + commands = {} for clazz in Base.__subclasses__(): command_name = getattr(clazz, 'name') diff --git a/src/handler/commands/boobs.py b/src/handler/commands/boobs.py new file mode 100644 index 0000000..6cb5643 --- /dev/null +++ b/src/handler/commands/boobs.py @@ -0,0 +1,16 @@ +from .base import Base +import json +from urllib.request import urlopen + + +class Boobs(Base): + name = 'boobs' + aliases = ['80085', '(.)(.)'] + + @staticmethod + def execute(bot, command): + response = urlopen('http://api.oboobs.ru/noise/1') + data = json.loads(response.read().decode('utf-8')) + url = 'http://media.oboobs.ru/' + data[0]['preview'] + + bot.send_photo(chat_id=command.chat_id, photo=url) diff --git a/src/handler/commands/borscht.py b/src/handler/commands/borscht.py new file mode 100644 index 0000000..515dcba --- /dev/null +++ b/src/handler/commands/borscht.py @@ -0,0 +1,23 @@ +from .base import Base +import json +from src.utils import random_element +from urllib.request import urlopen + + +class Borscht(Base): + name = 'borscht' + images = None + + @staticmethod + def execute(bot, command): + if Borscht.images is None: + Borscht.images = Borscht.__preload() + + bot.send_photo(chat_id=command.chat_id, photo=random_element(Borscht.images)) + + @staticmethod + def __preload(): + response = urlopen('https://api.cognitive.microsoft.com/bing/v5.0/images/search?q=%D0%B1%D0%BE%D1%80%D1%89&mkt=en-us&safe-search=strict&image-type=photo&subscription-key=dd95294bc02748a1ab5152d36fdbbdac') + data = json.loads(response.read().decode('utf-8')) + + return list(map(lambda e: e['contentUrl'], data['value'])) diff --git a/src/handler/commands/butts.py b/src/handler/commands/butts.py new file mode 100644 index 0000000..b7d2d52 --- /dev/null +++ b/src/handler/commands/butts.py @@ -0,0 +1,16 @@ +from .base import Base +import json +from urllib.request import urlopen + + +class Butts(Base): + name = 'butts' + aliases = ['(_._)', '(_*_)', '(Y)'] + + @staticmethod + def execute(bot, command): + response = urlopen('http://api.obutts.ru/noise/1') + data = json.loads(response.read().decode('utf-8')) + url = 'http://media.obutts.ru/' + data[0]['preview'] + + bot.send_photo(chat_id=command.chat_id, photo=url) diff --git a/src/handler/commands/meow.py b/src/handler/commands/meow.py new file mode 100644 index 0000000..f1649f5 --- /dev/null +++ b/src/handler/commands/meow.py @@ -0,0 +1,15 @@ +from .base import Base +from urllib.request import build_opener, HTTPRedirectHandler + + +class Meow(Base): + name = 'meow' + aliases = [':3', '=3'] + + @staticmethod + def execute(bot, command): + opener = build_opener(HTTPRedirectHandler) + request = opener.open('http://thecatapi.com/api/images/get?format=src') + url = request.url + + bot.send_photo(chat_id=command.chat_id, photo=url) diff --git a/src/handler/commands/vzhuh.py b/src/handler/commands/vzhuh.py new file mode 100644 index 0000000..b395b60 --- /dev/null +++ b/src/handler/commands/vzhuh.py @@ -0,0 +1,40 @@ +from .base import Base +from PIL import Image, ImageFont, ImageDraw + + +class Vzhuh(Base): + name = 'vzhuh' + + @staticmethod + def execute(bot, command): + text = Vzhuh.format_text('вжух ' + ' '.join(command.args)) + Vzhuh.create_image(text) + + bot.send_photo(chat_id=command.chat_id, photo=open('data/sample-out.png', 'rb')) + + @staticmethod + def format_text(text): + result = [] + current_part = '' + if len(text) > 8: + parts = text.upper().split(' ') + for part in parts: + if len(current_part) + len(part) <= 10: + current_part += part + ' ' + else: + result.append(current_part) + result.append(part) + current_part = '' + result.append(current_part) + else: + result.append(text) + + return '\r\n'.join(result) + + @staticmethod + def create_image(text): + img = Image.open("data/vzhuh_sample.png") + draw = ImageDraw.Draw(img) + font = ImageFont.truetype("data/Futura.ttc", 40, index=2) + draw.text((222, 280), text, (0, 0, 0), font=font) + img.save('data/sample-out.png') diff --git a/src/handler/commands/woof.py b/src/handler/commands/woof.py new file mode 100644 index 0000000..ea073a0 --- /dev/null +++ b/src/handler/commands/woof.py @@ -0,0 +1,15 @@ +from .base import Base +from urllib.request import urlopen, Request + + +class Woof(Base): + name = 'woof' + + @staticmethod + def execute(bot, command): + req = Request("http://loremflickr.com/500/410/dog", headers={'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"}) + output = open("data/woof-photo.jpg", "wb") + output.write(urlopen(req).read()) + output.close() + + bot.send_photo(chat_id=command.chat_id, photo=open('data/woof-photo.jpg', 'rb')) diff --git a/src/handler/commands/xkcd.py b/src/handler/commands/xkcd.py new file mode 100644 index 0000000..fb079d0 --- /dev/null +++ b/src/handler/commands/xkcd.py @@ -0,0 +1,16 @@ +from .base import Base +import json +import random +from urllib.request import urlopen + + +class XKCD(Base): + name = 'xkcd' + + @staticmethod + def execute(bot, command): + last_id = json.loads(urlopen("http://xkcd.com/info.0.json").read().decode('utf-8'))['num'] + id = random.randint(1, last_id) + url = json.loads(urlopen('http://xkcd.com/' + str(id) + '/info.0.json').read().decode('utf-8'))['img'] + + bot.send_photo(chat_id=command.chat_id, photo=url)