-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolors.py
More file actions
76 lines (66 loc) · 1.78 KB
/
Copy pathcolors.py
File metadata and controls
76 lines (66 loc) · 1.78 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
"""Colors module"""
from io import BytesIO
from PIL import Image, ImageColor
from telegram import Bot, Update
import core
PLUGINVERSION = 2
# Always name this variable as `plugin`
# If you dont, module loader will fail to load the plugin!
plugin = core.Plugin()
@plugin.command(command="/color",
description="Create color samples",
inline_supported=True,
required_args=1,
hidden=False)
def rgb(b: Bot, u: Update, user, args):
"""
Create color samples.
Supports both HEX and RGB
Example:
User:
/color #FF0000
OctoBot:
[ Photo ]
OctoBot:
#FF0000
User:
/color 255 0 0
OctoBot:
[ Photo ]
OctoBot Dev:
[255, 0, 0]
User:
/color 0xFF 0x0 0x0
OctoBot:
[ Photo ]
OctoBot:
[255, 0, 0]
"""
if not args:
return
if args[0].startswith("#"):
color = args[0]
try:
usercolor = ImageColor.getrgb(color)
except Exception:
return core.message("Invalid Color Code supplied", failed=True)
elif args[0].startswith("0x"):
if len(args) > 2:
usercolor = int(args[0][2:], 16), int(
args[1][2:], 16), int(args[2][2:], 16)
else:
color = "#"+args[0][2:]
usercolor = ImageColor.getrgb(color)
else:
try:
usercolor = int(args[0]), int(args[1]), int(args[2])
except IndexError:
return core.message(text="balu basta")
except ValueError:
return core.message(text="Invalid Color Code supplied")
color = usercolor
im = Image.new(mode="RGB", size=(128, 128), color=usercolor)
file = BytesIO()
im.save(file, "PNG")
file.seek(0)
return core.message(text=color, photo=file)