Skip to content

Commit 96d6340

Browse files
Create amongus.py
1 parent 6814f7a commit 96d6340

File tree

1 file changed

+212
-0
lines changed

1 file changed

+212
-0
lines changed

fun/amongus.py

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# From CatUB
2+
import asyncio
3+
import re
4+
from io import BytesIO
5+
from random import choice, randint
6+
from textwrap import wrap
7+
8+
from PIL import Image, ImageDraw, ImageFont
9+
from click import edit
10+
import requests
11+
from pyrogram import Client, filters, enums
12+
from pyrogram.types import Message
13+
14+
from utils.scripts import edit_or_reply, ReplyCheck
15+
from utils.misc import modules_help, prefix
16+
17+
18+
async def amongus_gen(text: str, clr: int) -> str:
19+
url = (
20+
"https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/Amongus/"
21+
)
22+
font = ImageFont.truetype(
23+
BytesIO(
24+
requests.get(
25+
"https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/fonts/bold.ttf"
26+
).content
27+
),
28+
60,
29+
)
30+
imposter = Image.open(BytesIO(requests.get(f"{url}{clr}.png").content))
31+
text_ = "\n".join("\n".join(wrap(part, 30)) for part in text.split("\n"))
32+
bbox = ImageDraw.Draw(Image.new("RGB", (1, 1))).multiline_textbbox(
33+
(0, 0), text_, font, stroke_width=2
34+
)
35+
w, h = bbox[2], bbox[3]
36+
text = Image.new("RGBA", (w + 30, h + 30))
37+
ImageDraw.Draw(text).multiline_text(
38+
(15, 15), text_, "#FFF", font, stroke_width=2, stroke_fill="#000"
39+
)
40+
w = imposter.width + text.width + 10
41+
h = max(imposter.height, text.height)
42+
image = Image.new("RGBA", (w, h))
43+
image.paste(imposter, (0, h - imposter.height), imposter)
44+
image.paste(text, (w - text.width, 0), text)
45+
image.thumbnail((512, 512))
46+
output = BytesIO()
47+
output.name = "imposter.webp"
48+
image.save(output, "WebP")
49+
output.seek(0)
50+
return output
51+
52+
53+
async def get_imposter_img(text: str) -> BytesIO:
54+
background = requests.get(
55+
f"https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/imposter/impostor{randint(1, 22)}.png"
56+
).content
57+
font = requests.get(
58+
"https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/fonts/roboto_regular.ttf"
59+
).content
60+
font = BytesIO(font)
61+
font = ImageFont.truetype(font, 30)
62+
image = Image.new("RGBA", (1, 1), (0, 0, 0, 0))
63+
draw = ImageDraw.Draw(image)
64+
bbox = ImageDraw.Draw(Image.new("RGB", (1, 1))).multiline_textbbox(
65+
(0, 0), text, font, stroke_width=2
66+
)
67+
w, h = bbox[2], bbox[3]
68+
image = Image.open(BytesIO(background))
69+
x, y = image.size
70+
draw = ImageDraw.Draw(image)
71+
draw.multiline_text(
72+
((x - w) // 2, (y - h) // 2), text=text, font=font, fill="white", align="center"
73+
)
74+
output = BytesIO()
75+
output.name = "impostor.png"
76+
image.save(output, "PNG")
77+
output.seek(0)
78+
return output
79+
80+
81+
@Client.on_message(filters.command("amongus", prefix) & filters.me)
82+
async def amongus_cmd(client: Client, message: Message):
83+
text = " ".join(message.command[1:]) if len(message.command) > 1 else ""
84+
reply = message.reply_to_message
85+
await message.edit("tun tun tun...")
86+
if not text and reply:
87+
text = reply.text or reply.caption or ""
88+
89+
clr = re.findall(r"-c\d+", text)
90+
try:
91+
clr = clr[0]
92+
clr = clr.replace("-c", "")
93+
text = text.replace(f"-c{clr}", "")
94+
clr = int(clr)
95+
if clr > 12 or clr < 1:
96+
clr = randint(1, 12)
97+
except IndexError:
98+
clr = randint(1, 12)
99+
100+
if not text:
101+
if not reply:
102+
text = f"{message.from_user.first_name} Was a traitor!"
103+
else:
104+
text = f"{reply.from_user.first_name} Was a traitor!"
105+
106+
imposter_file = await amongus_gen(text, clr)
107+
await message.delete()
108+
await client.send_sticker(
109+
message.chat.id,
110+
imposter_file,
111+
reply_to_message_id=ReplyCheck(message),
112+
)
113+
114+
115+
@Client.on_message(filters.command("imposter", prefix) & filters.me)
116+
async def imposter_cmd(client: Client, message: Message):
117+
remain = randint(1, 2)
118+
imps = ["wasn't the impostor", "was the impostor"]
119+
120+
if message.reply_to_message:
121+
user = message.reply_to_message.from_user
122+
text = f"{user.first_name} {choice(imps)}."
123+
else:
124+
args = message.text.split()[1:]
125+
if args:
126+
text = " ".join(args)
127+
else:
128+
text = f"{message.from_user.first_name} {choice(imps)}."
129+
130+
text += f"\n{remain} impostor(s) remain."
131+
imposter_file = await get_imposter_img(text)
132+
await message.delete()
133+
await client.send_photo(
134+
message.chat.id,
135+
imposter_file,
136+
reply_to_message_id=ReplyCheck(message),
137+
)
138+
139+
140+
@Client.on_message(filters.command(["imp", "impn"], prefix) & filters.me)
141+
async def imp_animation(client: Client, message: Message):
142+
name = " ".join(message.command[1:]) if len(message.command) > 1 else "Unknown"
143+
cmd = message.command[0].lower()
144+
145+
text1 = await edit_or_reply(message, "Uhmm... Something is wrong here!!")
146+
await asyncio.sleep(2)
147+
await text1.delete()
148+
149+
stcr1 = await client.send_sticker(message.chat.id, "CAADAQADRwADnjOcH98isYD5RJTwAg")
150+
text2 = await message.reply(
151+
f"<b>{message.from_user.first_name}:</b> I have to call discussion"
152+
)
153+
await asyncio.sleep(3)
154+
await stcr1.delete()
155+
await text2.delete()
156+
157+
stcr2 = await client.send_sticker(message.chat.id, "CAADAQADRgADnjOcH9odHIXtfgmvAg")
158+
text3 = await message.reply(
159+
f"<b>{message.from_user.first_name}:</b> We have to eject the imposter or will lose"
160+
)
161+
await asyncio.sleep(3)
162+
await stcr2.delete()
163+
await text3.delete()
164+
165+
stcr3 = await client.send_sticker(message.chat.id, "CAADAQADOwADnjOcH77v3Ap51R7gAg")
166+
text4 = await message.reply("<b>Others:</b> Where???")
167+
await asyncio.sleep(2)
168+
await text4.edit("<b>Others:</b> Who??")
169+
await asyncio.sleep(2)
170+
await text4.edit(
171+
f"<b>{message.from_user.first_name}:</b> Its {name}, I saw {name} using vent,"
172+
)
173+
await asyncio.sleep(3)
174+
await text4.edit(f"<b>Others:</b> Okay.. Vote {name}")
175+
await asyncio.sleep(2)
176+
await stcr3.delete()
177+
await text4.delete()
178+
179+
stcr4 = await client.send_sticker(message.chat.id, "CAADAQADLwADnjOcH-wxu-ehy6NRAg")
180+
event = await message.reply(f"{name} is ejected.......")
181+
182+
# Ejection animation
183+
for _ in range(9):
184+
await asyncio.sleep(0.5)
185+
curr_pos = _ + 1
186+
spaces_before = "ㅤ" * curr_pos
187+
await event.edit(f"{spaces_before}{'ㅤ' * (9 - curr_pos)}")
188+
189+
await asyncio.sleep(0.5)
190+
await event.edit("ㅤㅤㅤㅤㅤㅤㅤㅤㅤ")
191+
await asyncio.sleep(0.2)
192+
await stcr4.delete()
193+
194+
if cmd == "imp":
195+
text = f".    。    •   ゚  。   .\n .      .     。   。 .  \n\n .    。   ඞ 。 .    •     •\n\n{name} was an Imposter. 。 .     。 . 。 . \n  . 。   . \n ' 0 Impostor remains   。 .   . 。 . 。   . 。   . . . , 。\n  ゚   .  . ,   。   .   . 。"
196+
sticker_id = "CAADAQADLQADnjOcH39IqwyR6Q_0Ag"
197+
else:
198+
text = f".    。    •   ゚  。   .\n .      .     。   。 .  \n\n .    。   ඞ 。 .    •     •\n\n{name} was not an Imposter. 。 .     。 . 。 . \n  . 。   . \n ' 1 Impostor remains   。 .   . 。 . 。   . 。   . . . , 。\n  ゚   .  . ,   。   .   . 。"
199+
sticker_id = "CAADAQADQAADnjOcH-WOkB8DEctJAg"
200+
201+
await event.edit(text)
202+
await asyncio.sleep(4)
203+
await event.delete()
204+
await client.send_sticker(message.chat.id, sticker_id)
205+
206+
207+
modules_help["amongus"] = {
208+
"amongus": "Create Among Us themed sticker [text/reply] [-c1 to -c12 for colors]",
209+
"imposter": "Create Among Us imposter image [username/reply]",
210+
"imp": "Create Among Us ejection animation (imposter)",
211+
"impn": "Create Among Us ejection animation (not imposter)",
212+
}

0 commit comments

Comments
 (0)