-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathSwiper.py
More file actions
110 lines (94 loc) · 2.62 KB
/
Swiper.py
File metadata and controls
110 lines (94 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from .. import loader, utils
import logging
from PIL import Image, ImageOps
import io
logger = logging.getLogger(__name__)
@loader.tds
class SwiperMod(loader.Module):
"""Swiper"""
strings = {
"name": "Swiper"
}
async def client_ready(self, client, db):
self.client = client
@loader.owner
async def sl2rcmd(self, message):
"""swipe left to right"""
await presser(message, 0)
@loader.owner
async def sr2lcmd(self, message):
"""swipe right to left"""
await presser(message, 1)
@loader.owner
async def su2dcmd(self, message):
"""swipe up to down"""
await presser(message, 2)
@loader.owner
async def sd2ucmd(self, message):
"""swipe down to up"""
await presser(message, 3)
async def check_media(message):
reply = await message.get_reply_message()
if not reply:
return False
if not reply.file:
return False
mime = reply.file.mime_type.split("/")[0].lower()
if mime != "image":
return False
return reply
async def presser(message, way):
reply = await check_media(message)
if not reply:
await message.edit("<b>Senpai... please reply to image or not animated sticker!</b>")
return
im = io.BytesIO()
await reply.download_media(im)
im = Image.open(im)
w, h = im.size
out = []
await message.edit("<b>Working hard...</b>")
if way == 0:
for x in range(1, w, w//30):
im1 = im2 = im.copy()
temp = Image.new("RGB", (w, h))
im1 = im1.resize((x, h))
im2 = im2.resize((w-x, h))
temp.paste(im1, (0, 0))
temp.paste(im2, (x, 0))
out.append(temp)
if way == 1:
for x in range(1, w, w//30):
im1 = im2 = im.copy()
temp = Image.new("RGB", (w, h))
im1 = ImageOps.mirror(im1.resize((x, h)))
im2 = ImageOps.mirror(im2.resize((w-x, h)))
temp.paste(im1, (0, 0))
temp.paste(im2, (x, 0))
temp = ImageOps.mirror(temp)
out.append(temp)
if way == 2:
for y in range(1, h, h//30):
im1 = im2 = im.copy()
temp = Image.new("RGB", (w, h))
im1 = im1.resize((w, y))
im2 = im2.resize((w, h-y))
temp.paste(im1, (0, 0))
temp.paste(im2, (0, y))
out.append(temp)
if way == 3:
for y in range(1, h, h//30):
im1 = im2 = im.copy()
temp = Image.new("RGB", (w, h))
im1 = ImageOps.flip(im1.resize((w, y)))
im2 = ImageOps.flip(im2.resize((w, h-y)))
temp.paste(im1, (0, 0))
temp.paste(im2, (0, y))
temp = ImageOps.flip(temp)
out.append(temp)
output = io.BytesIO()
output.name = "output.gif"
out[0].save(output, save_all=True, append_images=out[1:], duration=1)
output.seek(0)
await reply.reply(file=output)
await message.delete()