Added stores for connections. Added requests for groups, group chatters, group permissions & connections. Using TTS Voice State store.
This commit is contained in:
51
Requests/CreateGroup.cs
Normal file
51
Requests/CreateGroup.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests.Messages;
|
||||
using HermesSocketServer.Models;
|
||||
using HermesSocketServer.Store;
|
||||
using HermesSocketServer.Store.Internal;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace HermesSocketServer.Requests
|
||||
{
|
||||
public class CreateGroup : IRequest
|
||||
{
|
||||
public string Name => "create_group";
|
||||
public string[] RequiredKeys => ["name", "priority"];
|
||||
private readonly DatabaseTable _table;
|
||||
private readonly Database _database;
|
||||
private ILogger _logger;
|
||||
|
||||
public CreateGroup([FromKeyedServices("ChatterGroup")] DatabaseTable table, Database database, ILogger logger)
|
||||
{
|
||||
_table = table;
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
||||
{
|
||||
var id = Guid.NewGuid();
|
||||
string name = data["name"].ToString()!;
|
||||
if (!int.TryParse(data["priority"].ToString()!, out var priority))
|
||||
return Task.FromResult(RequestResult.Failed("Priority needs to be an integer."));
|
||||
|
||||
var group = new Group()
|
||||
{
|
||||
Id = id.ToString(),
|
||||
UserId = channel.Id,
|
||||
Name = name,
|
||||
Priority = priority,
|
||||
};
|
||||
|
||||
bool result = channel.Groups.Set(id.ToString(), group);
|
||||
if (result)
|
||||
{
|
||||
var store = new ChatterGroupStore(channel.Id, group.Id, _table, _database, _logger);
|
||||
channel.Groups.Chatters.Add(group.Id, store);
|
||||
_logger.Information($"Added group to channel [group id: {id}][name: {name}][priority: {priority}][channel: {channel.Id}]");
|
||||
return Task.FromResult(RequestResult.Successful(group));
|
||||
}
|
||||
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user