add color to server
This commit is contained in:
parent
8fc179c406
commit
000f040652
1 changed files with 25 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ public static partial class Module
|
||||||
[PrimaryKey]
|
[PrimaryKey]
|
||||||
public Identity Identity;
|
public Identity Identity;
|
||||||
public string? Name;
|
public string? Name;
|
||||||
|
public string? Color;
|
||||||
public bool Online;
|
public bool Online;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,6 +43,30 @@ public static partial class Module
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Reducer]
|
||||||
|
public static void SetColor(ReducerContext ctx, string color)
|
||||||
|
{
|
||||||
|
color = ValidateColor(color);
|
||||||
|
|
||||||
|
var user = ctx.Db.User.Identity.Find(ctx.Sender);
|
||||||
|
|
||||||
|
if (user is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
user.Color = color;
|
||||||
|
ctx.Db.User.Identity.Update(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ValidateColor(string color)
|
||||||
|
{
|
||||||
|
if (color[0] == '#' && color.Length != 4 || color.Length != 7)
|
||||||
|
{
|
||||||
|
throw new Exception("Invalid Hex color code");
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
[Reducer]
|
[Reducer]
|
||||||
public static void SendMessage(ReducerContext ctx, string text)
|
public static void SendMessage(ReducerContext ctx, string text)
|
||||||
{
|
{
|
||||||
|
|
@ -113,4 +138,3 @@ public static partial class Module
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue