From 1f8b8b67b81c5ae86980d9129f3a88db61165698 Mon Sep 17 00:00:00 2001 From: Igor <50257429+igorechek06@users.noreply.github.com> Date: Fri, 15 Oct 2021 14:07:38 +0900 Subject: Фотки в gif для абьюз телеграм MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/__init__.py | 7 ++-- handlers/all.py | 16 +++++++++ handlers/ananas_only.py | 2 +- handlers/gen.py | 51 +++++++++++++++++++++++++++ handlers/generate.py | 92 ------------------------------------------------- handlers/gif.py | 41 ++++++++++++++++++++++ handlers/msg.py | 17 +++++++++ handlers/on_message.py | 17 --------- handlers/poll.py | 51 +++++++++++++++++++++++++++ 9 files changed, 182 insertions(+), 112 deletions(-) create mode 100644 handlers/all.py create mode 100644 handlers/gen.py delete mode 100644 handlers/generate.py create mode 100644 handlers/gif.py create mode 100644 handlers/msg.py delete mode 100644 handlers/on_message.py create mode 100644 handlers/poll.py (limited to 'handlers') diff --git a/handlers/__init__.py b/handlers/__init__.py index bf57f77..05e50a2 100644 --- a/handlers/__init__.py +++ b/handlers/__init__.py @@ -1,3 +1,6 @@ from . import ananas_only -from . import on_message -from . import generate +from . import msg +from . import poll +from . import gif +from . import gen +from . import all diff --git a/handlers/all.py b/handlers/all.py new file mode 100644 index 0000000..10ba92d --- /dev/null +++ b/handlers/all.py @@ -0,0 +1,16 @@ +from shared.instances import dp +from aiogram import types as t + + +@dp.errors_handler() +async def errors_handler(upd: t.Update, err: Exception): + txt = "Я хз что произошло, но да \n" + txt += f" {err.__class__.__name__}: {' '.join(err.args)}" + + if upd.message: + await upd.message.answer(txt) + elif upd.callback_query: + await upd.callback_query.answer(txt) + else: + return + return True diff --git a/handlers/ananas_only.py b/handlers/ananas_only.py index 7426593..a6ee13c 100644 --- a/handlers/ananas_only.py +++ b/handlers/ananas_only.py @@ -4,7 +4,7 @@ from utils import filters as f @dp.my_chat_member_handler(f.user.add_member) -async def pososi(upd: t.ChatMemberUpdated): +async def пососи(upd: t.ChatMemberUpdated): if upd.chat.id not in (-1001444484622, -1001197098429): await upd.bot.send_message(upd.chat.id, 'https://www.youtube.com/watch?v=xdDhmagsXrc') await upd.chat.leave() diff --git a/handlers/gen.py b/handlers/gen.py new file mode 100644 index 0000000..822b4ad --- /dev/null +++ b/handlers/gen.py @@ -0,0 +1,51 @@ +import mc +from aiogram import types as t + +from shared import instances as ins +from shared.instances import dp, bot +from utils import filters as f + + +@dp.message_handler(f.message.is_chat, commands=["gen"]) +async def сгенерировать_хуету(msg: t.Message): + await msg.answer(получить_говно()) + + +@dp.message_handler(f.message.is_chat, commands=["del"]) +async def удалить_хуету(msg: t.Message): + await msg.delete() + + if msg.reply_to_message: + if msg.reply_to_message.from_user.id in [bot.id, msg.from_user.id]: + await msg.reply_to_message.delete() + else: + await msg.answer("Ты умник, можно только свои или мои удалять") + else: + await msg.answer("Ты умник, ответь на сообщение") + + +@dp.message_handler(commands=["chance"]) +async def изменить_шанс_срания(msg: t.Message): + if msg.get_args(): + try: + chance = int(msg.get_args().split()[0]) + if 0 <= chance <= 100: + ins.gen_chance = chance + else: + raise RuntimeError() + + await msg.answer(f"Теперь я сру с шансом в: {chance}%") + except Exception: + await msg.answer("Я хз что не так, но я знаю что ты дебил \n /chance <ЧИСЛО ОТ 0 ДО 100>") + else: + await msg.answer(f"Я сру с шансом в: {ins.gen_chance}%") + + +@dp.message_handler(f.message.chance, f.message.is_chat, content_types=[t.ContentType.ANY]) +async def срать_сообщение_с_шансом(msg: t.Message): + await msg.answer(получить_говно()) + + +def получить_говно() -> str: + samples = mc.util.load_txt_samples('samples.txt', separator='§') + return mc.StringGenerator(samples=samples).generate_string().capitalize() diff --git a/handlers/generate.py b/handlers/generate.py deleted file mode 100644 index 7f58185..0000000 --- a/handlers/generate.py +++ /dev/null @@ -1,92 +0,0 @@ -from datetime import datetime, timedelta - -import mc -from shared.instances import dp, bot -from aiogram import types as t -from utils import filters as f -from shared import instances as ins - -pin_reply_markup = t.InlineKeyboardMarkup().add( - t.InlineKeyboardButton("Проверить сейчас", callback_data="chek") -) - - -@dp.message_handler(f.message.is_chat, commands=['gen']) -async def сгенерировать_хуету(msg: t.Message): - samples = mc.util.load_txt_samples('samples.txt', separator='§') - await msg.answer(mc.StringGenerator(samples=samples).generate_string()) - - -@dp.message_handler(f.message.is_chat, commands=["del"]) -async def удалить_хуету(msg: t.Message): - await msg.delete() - - if msg.reply_to_message: - if msg.reply_to_message.from_user.id in [bot.id, msg.from_user.id]: - await msg.reply_to_message.delete() - else: - await msg.answer("Ты умник, можно только свои или мои удалять") - else: - await msg.answer("Ты умник, ответь на сообщение") - - -@dp.message_handler(f.message.is_chat, commands=["pin"]) -async def закрепить_хуету(msg: t.Message): - await msg.delete() - if msg.reply_to_message: - await msg.reply_to_message.reply_poll( - "Закрепить ?", - [ - "Да", - "УДАЛИ НАХУЙ", - "Нет" - ], - close_date=datetime.now() + timedelta(minutes=10), - reply_markup=pin_reply_markup - ) - else: - await msg.answer("Ты умник, ответь на сообщение") - - -@dp.message_handler(commands=["chance"]) -async def закрепить_хуту(msg: t.Message): - if msg.get_args(): - try: - chance = int(msg.get_args().split()[0]) - if 0 <= chance <= 100: - ins.gen_chance = chance - else: - raise RuntimeError() - - await msg.answer(f"Теперь я сру с шансом в: {chance}%") - except Exception: - await msg.answer("Я хз что не так, но я знаю что ты дебил \n /chance <ЧИСЛО ОТ 0 ДО 100>") - else: - await msg.answer(f"Я сру с шансом в: {ins.gen_chance}%") - - -@dp.message_handler(f.message.chance, f.message.is_chat, content_types=[t.ContentType.ANY]) -async def срать_сообщение_с_шансом(msg: t.Message): - await сгенерировать_хуету(msg) - - -@dp.callback_query_handler(f.message.is_chat, lambda clb: clb.data == "chek") -async def проверить_опрос(clb: t.CallbackQuery): - poll = clb.message.poll - msg = clb.message - - if poll.total_voter_count <= 0: - await clb.answer("Видишь голоса? Вот и я невижу") - else: - if not poll.is_closed: - await bot.stop_poll(msg.chat.id, msg.message_id) - await msg.delete_reply_markup() - - yes = poll.options[0].voter_count - delete = poll.options[1].voter_count - win = max(yes, delete) - - if win == yes: - await msg.pin() - elif win == delete: - await msg.delete() diff --git a/handlers/gif.py b/handlers/gif.py new file mode 100644 index 0000000..3961502 --- /dev/null +++ b/handlers/gif.py @@ -0,0 +1,41 @@ +from os import system as run + +from aiogram import types as t +from aiogram.dispatcher import filters + +from handlers.gen import получить_говно +from shared.instances import dp + + +@dp.message_handler( + filters.Command("gif", ignore_caption=False), + content_types=[t.ContentType.PHOTO, t.ContentType.DOCUMENT, t.ContentType.TEXT], + commands=["gif"] +) +async def высрать_гиф(msg: t.Message): + tmp = "tmp/" + inp = tmp + "gif.jpg" + out = tmp + "gif.mp4" + + try: + if msg.text: + photo = msg.reply_to_message.photo + document = msg.reply_to_message.document + else: + photo = msg.photo + document = msg.document + + if photo: + await photo[-1].download(destination_file=inp) + elif document: + await document.download(destination_file=inp) + else: + raise RuntimeError() + except Exception: + await msg.reply("Чел, ответь на фото или пришли мне его") + return + + run(f"ffmpeg -loglevel quiet -y -i {inp} {out}") + + with open(out, "rb") as file: + await msg.reply_animation(file, caption=получить_говно()) diff --git a/handlers/msg.py b/handlers/msg.py new file mode 100644 index 0000000..58f3213 --- /dev/null +++ b/handlers/msg.py @@ -0,0 +1,17 @@ +from shared.instances import dp +from aiogram import types as t +from utils import filters as f + + +async def сосалка(msg: t.Message): + text = msg.text or msg.caption + if text.startswith('/'): + return False + with open('samples.txt', 'a+') as file: + file.write(text.lower().replace('§', '') + '§') + return False + + +@dp.message_handler(f.message.is_chat, f.message.has_text, сосалка, content_types=[t.ContentType.ANY]) +async def ХУЙ(): + pass diff --git a/handlers/on_message.py b/handlers/on_message.py deleted file mode 100644 index 5a216e2..0000000 --- a/handlers/on_message.py +++ /dev/null @@ -1,17 +0,0 @@ -from shared.instances import dp -from aiogram import types as t -from utils import filters as f - - -async def сосалка(msg: t.Message): - text = msg.text or msg.caption - if text.startswith('/'): - return False - with open('samples.txt', 'a+') as file: - file.write(text.replace('§', '') + '§') - return False - - -@dp.message_handler(f.message.is_chat, f.message.has_text, сосалка, content_types=[t.ContentType.ANY]) -async def ХУЙ(): - pass diff --git a/handlers/poll.py b/handlers/poll.py new file mode 100644 index 0000000..f6fb962 --- /dev/null +++ b/handlers/poll.py @@ -0,0 +1,51 @@ +from datetime import datetime, timedelta + +from shared.instances import dp, bot +from utils import filters as f +from aiogram import types as t + +pin_reply_markup = t.InlineKeyboardMarkup().add( + t.InlineKeyboardButton("Проверить сейчас", callback_data="chek") +) + + +@dp.message_handler(f.message.is_chat, commands=["pin"]) +async def закрепить_хуету(msg: t.Message): + await msg.delete() + if msg.reply_to_message: + await msg.reply_to_message.reply_poll( + "Закрепить ?", + [ + "Да", + "УДАЛИ НАХУЙ", + "Нет" + ], + close_date=datetime.now() + timedelta(minutes=10), + reply_markup=pin_reply_markup + ) + else: + await msg.answer("Ты умник, ответь на сообщение") + + +@dp.callback_query_handler(f.message.is_chat, lambda clb: clb.data == "chek") +async def проверить_опрос(clb: t.CallbackQuery): + poll = clb.message.poll + msg = clb.message + + if poll.total_voter_count <= 0: + await clb.answer("Видишь голоса? Вот и я невижу") + else: + if not poll.is_closed: + await bot.stop_poll(msg.chat.id, msg.message_id) + poll.is_closed = True + yes = poll.options[0].voter_count + delete = poll.options[1].voter_count + win = max(yes, delete) + + if win == yes: + await msg.reply_to_message.pin() + elif win == delete: + await msg.reply_to_message.delete() + + if poll.is_closed: + await msg.delete() -- cgit v1.2.3