-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify.py
60 lines (49 loc) · 1.83 KB
/
modify.py
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
import colour
import colorsys
import discord
from util import get_current_color, log_and_respond, update_role
from create import color_user
async def modify_rgb(
ctx: discord.ApplicationContext,
r: int = None,
g: int = None,
b: int = None,
):
user: discord.User | discord.Member = ctx.user
role = get_current_color(user)
new_color = discord.Colour.from_rgb(
int(constrain(0, r if r is not None else role.color.r, 255)),
int(constrain(0, g if g is not None else role.color.g, 255)),
int(constrain(0, b if b is not None else role.color.b, 255)),
)
return await modify_color(ctx, role, new_color)
async def modify_hsv(
ctx: discord.ApplicationContext,
hue: float | None = None,
saturation: float | None = None,
value: float | None = None,
):
user: discord.User | discord.Member = ctx.user
role = get_current_color(user)
r, g, b = role.color.to_rgb()
h, s, v = colorsys.rgb_to_hsv(r / 255, g / 255, b / 255)
new_color = discord.Colour.from_hsv(
constrain(0, hue if hue is not None else h, 1),
constrain(0, saturation if saturation is not None else s, 1),
constrain(0, value if value is not None else v, 1),
)
return await modify_color(ctx, role, new_color)
async def modify_color(
ctx: discord.ApplicationContext, role: discord.Role, new_color: discord.Colour
):
user: discord.User | discord.Member = ctx.user
role = get_current_color(user)
if len(role.members) > 1:
return await color_user(ctx, ctx.user, str(new_color))
else:
await update_role(role, name=str(new_color), color=new_color)
return await log_and_respond(
ctx, f"Modified {user.name}'s current color to {str(new_color)}"
)
def constrain(min_value, value, max_value):
return min(max(value, min_value), max_value)