forked from CFC-Servers/cfc_chat_transit
Send easy string colors
This commit is contained in:
parent
9374550419
commit
2ab2942735
@ -31,17 +31,14 @@ with ChatTransit.WebSocket
|
||||
.onError = (message) => Logger\error "Websocket Error!", message
|
||||
\open!
|
||||
|
||||
ChatTransit.GetTeamColorCode = (teamName) =>
|
||||
ChatTransit.GetTeamColor = (teamName) =>
|
||||
return @TeamColorCache[teamName] if @TeamColorCache[teamName]
|
||||
|
||||
color = GetColor teamName
|
||||
r, g, b = color\Unpack!
|
||||
teamColor = tostring GetColor teamName
|
||||
|
||||
calculated = lshift(r, 16) + lshift(g, 8) + b
|
||||
@TeamColorCache[teamName] = teamColor
|
||||
|
||||
@TeamColorCache[teamName] = calculated
|
||||
|
||||
calculated
|
||||
teamColor
|
||||
|
||||
ChatTransit.ReceiveMessage = (ply, text, teamChat) =>
|
||||
return if teamChat
|
||||
@ -51,7 +48,6 @@ ChatTransit.ReceiveMessage = (ply, text, teamChat) =>
|
||||
@Logger\debug "Received message for #{ply\Nick!}, '#{text}'"
|
||||
|
||||
teamName = ply\Team!
|
||||
rankColor = @GetTeamColorCode teamName
|
||||
avatar = ply.PlayerSummary.response.players[1].avatarfull
|
||||
steamName = ply\Nick!
|
||||
steamId = ply\SteamID64!
|
||||
@ -60,7 +56,6 @@ ChatTransit.ReceiveMessage = (ply, text, teamChat) =>
|
||||
struct =
|
||||
Realm: Realm
|
||||
Content: text
|
||||
RankColor: rankColor
|
||||
Avatar: avatar
|
||||
SteamName: steamName
|
||||
SteamId: steamId
|
||||
|
@ -8,7 +8,7 @@ AvatarServiceAddress = string.Replace AvatarServiceAddress, "\n", ""
|
||||
class AvatarService
|
||||
new: (@Logger) =>
|
||||
|
||||
sendAvatar: (avatarUrl, success, failed) =>
|
||||
processAvatar: (avatarUrl, outlineColor, success, failed) =>
|
||||
HTTP
|
||||
:success
|
||||
:failed
|
||||
@ -25,11 +25,12 @@ class AvatarService
|
||||
|
||||
outlineAvatar: (ply, data) =>
|
||||
avatar = data.response.players[1].avatarfull
|
||||
outlineColor = ChatTransit\GetTeamColorCode ply\Team!
|
||||
|
||||
success = (code, body) -> setOutlinedAvatar ply, response
|
||||
failed = (err) -> @Logger\error err
|
||||
|
||||
@sendAvatar avatar, success, failed
|
||||
@processAvatar avatar, success, failed
|
||||
|
||||
ChatTransit.AvatarService = AvatarService ChatTransit.Logger
|
||||
|
||||
|
@ -5,25 +5,29 @@ import requests
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
transparent = (255, 255, 255, 0)
|
||||
|
||||
@app.route("/outline", methods=["POST"])
|
||||
def outline():
|
||||
|
||||
# TODO:
|
||||
# - Convert received image to RGBA
|
||||
# - Figure out the circle drawing
|
||||
# - Figure out how to convert the color to R,G,B,A
|
||||
# - Place image in directory with a uuid or something, respond with full link to that file
|
||||
|
||||
content = request.json
|
||||
image_url = content["avatarUrl"]
|
||||
outline_color = content["outlineColor"]
|
||||
|
||||
outline_color = content["outlineColor"] # "255 255 255 255"
|
||||
outline_color = outline_color.split(" ") # [255, 255, 255, 255]
|
||||
outline_color = tuple(outline_color) # (255, 255, 255, 255)
|
||||
|
||||
avatar = Image.open(requests.get(image_url, stream=True).raw)
|
||||
|
||||
x, y = avatar.size
|
||||
eX, eY = 30, 60 #Size of Bounding Box for ellipse
|
||||
|
||||
bbox = (x/2 - eX/2, y/2 - eY/2, x/2 + eX/2, y/2 + eY/2)
|
||||
bbox = (x/2 - eX/2, y/2 - eY/2, x/2 + eX/2, y/2 + eY/2)
|
||||
draw = ImageDraw.Draw(avatar)
|
||||
draw.ellipse(bbox, fill=(255,255,255,0), outline=(255,0,0,255), width=25)
|
||||
draw.ellipse(bbox, fill=transparent, outline=outline_color, width=25)
|
||||
del draw
|
||||
|
@ -14,7 +14,6 @@ var discord *discordgo.Session
|
||||
type MessageStruct struct {
|
||||
Realm string
|
||||
Content string
|
||||
RankColor float64
|
||||
Avatar string
|
||||
SteamName string
|
||||
SteamId string
|
||||
|
Loading…
Reference in New Issue
Block a user