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 +++++++++++++++++++++++++++ shared/commands.py | 11 ++++-- test.py | 28 --------------- tmp/gif.jpg | Bin 0 -> 7200 bytes tmp/gif.mp4 | 0 13 files changed, 191 insertions(+), 142 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 create mode 100644 tmp/gif.jpg create mode 100644 tmp/gif.mp4 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() diff --git a/shared/commands.py b/shared/commands.py index 3f2e3b1..34f9dbb 100644 --- a/shared/commands.py +++ b/shared/commands.py @@ -1,10 +1,17 @@ -from aiogram.types import BotCommand as cmd, BotCommandScopeAllGroupChats as group +from aiogram.types import \ + BotCommand as cmd, \ + BotCommandScopeAllGroupChats as group, \ + BotCommandScopeAllPrivateChats as private commands = { group(): [ cmd('gen', 'Высрвть текст'), cmd('del', 'Смыть говно'), cmd('pin', 'Повесить говно на стенку'), - cmd('chance', 'Установить шанс высирания говна'), + cmd('gif', 'Превратить картинку в gif'), + cmd('chance', 'Установить шанс высирания говна') + ], + private(): [ + cmd('gif', 'Превратить картинку в gif') ] } diff --git a/test.py b/test.py index d7ec5be..e69de29 100644 --- a/test.py +++ b/test.py @@ -1,28 +0,0 @@ -n = int(input()) -lt = [] - -for i in range(n - 1): - lt += [list(map(str, input().split()))] - -lts = [lt[0]] -l = lt[0][0] -r = lt[0][1] -lt.pop(0) - -for i in range(n - 2): - for j in range(len(lt)): - if lt[j][0] == r: - lts += [lt[j]] - lt.pop(j) - r = lts[-1][-1] - break - elif lt[j][1] == l: - lts = [lt[j]] + lts - lt.pop(j) - l = lts[0][0] - break - -for i in range(n - 2, -1, -1): - print(lts[i][1]) - -print(lts[0][0]) diff --git a/tmp/gif.jpg b/tmp/gif.jpg new file mode 100644 index 0000000..194c251 Binary files /dev/null and b/tmp/gif.jpg differ diff --git a/tmp/gif.mp4 b/tmp/gif.mp4 new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3