mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-15 02:22:43 -04:00
Changed the verbiage to role as it sounds a bit better and gave guest role a descriptor "Rat"
This commit is contained in:
@@ -7,21 +7,21 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace KfChatDotNetBot.Commands;
|
namespace KfChatDotNetBot.Commands;
|
||||||
|
|
||||||
public class SetRightCommand : ICommand
|
public class SetRoleCommand : ICommand
|
||||||
{
|
{
|
||||||
public List<Regex> Patterns => [
|
public List<Regex> Patterns => [
|
||||||
new Regex(@"^admin role set (?<user>\d+) (?<right>\d+)$"),
|
new Regex(@"^admin role set (?<user>\d+) (?<role>\d+)$"),
|
||||||
new Regex(@"^admin right set (?<user>\d+) (?<right>\d+)$")
|
new Regex(@"^admin right set (?<user>\d+) (?<role>\d+)$")
|
||||||
];
|
];
|
||||||
|
|
||||||
public string? HelpText => "Set a user's right";
|
public string? HelpText => "Set a user's role";
|
||||||
public UserRight RequiredRight => UserRight.Admin;
|
public UserRight RequiredRight => UserRight.Admin;
|
||||||
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
||||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||||
{
|
{
|
||||||
await using var db = new ApplicationDbContext();
|
await using var db = new ApplicationDbContext();
|
||||||
var targetUserId = Convert.ToInt32(arguments["user"].Value);
|
var targetUserId = Convert.ToInt32(arguments["user"].Value);
|
||||||
var right = (UserRight)Convert.ToInt32(arguments["right"].Value);
|
var role = (UserRight)Convert.ToInt32(arguments["role"].Value);
|
||||||
var targetUser = await db.Users.FirstOrDefaultAsync(u => u.KfId == targetUserId, cancellationToken: ctx);
|
var targetUser = await db.Users.FirstOrDefaultAsync(u => u.KfId == targetUserId, cancellationToken: ctx);
|
||||||
if (targetUser == null)
|
if (targetUser == null)
|
||||||
{
|
{
|
||||||
@@ -29,9 +29,9 @@ public class SetRightCommand : ICommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
targetUser.UserRight = right;
|
targetUser.UserRight = role;
|
||||||
await db.SaveChangesAsync(ctx);
|
await db.SaveChangesAsync(ctx);
|
||||||
botInstance.SendChatMessage($"@{message.Author.Username}, {targetUser.KfUsername}'s right set to {right.Humanize()}", true);
|
botInstance.SendChatMessage($"@{message.Author.Username}, {targetUser.KfUsername}'s role set to {role.Humanize()}", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public enum UserRight
|
|||||||
Admin = 1000,
|
Admin = 1000,
|
||||||
[Description("True and Honest")]
|
[Description("True and Honest")]
|
||||||
TrueAndHonest = 100,
|
TrueAndHonest = 100,
|
||||||
|
[Description("Rat")]
|
||||||
Guest = 10,
|
Guest = 10,
|
||||||
Loser = 0
|
Loser = 0
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user