DocSpace-buildtools/common/services/ASC.TelegramService/Commands/UserCommands.cs

43 lines
1.1 KiB
C#
Raw Normal View History

2022-03-15 16:59:24 +00:00
namespace ASC.TelegramService.Commands;
2022-02-17 11:16:52 +00:00
[Scope]
public class UserCommands : CommandContext
{
private readonly CachedTelegramDao _cachedTelegramDao;
2020-09-24 14:30:27 +00:00
2022-02-17 11:16:52 +00:00
public UserCommands(IOptionsSnapshot<CachedTelegramDao> cachedTelegramDao)
{
_cachedTelegramDao = cachedTelegramDao.Value;
}
2020-09-24 14:30:27 +00:00
2022-02-17 11:16:52 +00:00
[Command("start")]
public Task StartCommand(string token)
{
if (string.IsNullOrEmpty(token)) return Task.CompletedTask;
2022-01-12 09:56:00 +00:00
2022-02-17 11:16:52 +00:00
return InternalStartCommand(token);
}
2020-09-24 14:30:27 +00:00
2022-02-17 11:16:52 +00:00
private async Task InternalStartCommand(string token)
{
var user = MemoryCache.Default.Get(token);
if (user != null)
2022-01-12 09:56:00 +00:00
{
2022-02-17 11:16:52 +00:00
MemoryCache.Default.Remove(token);
MemoryCache.Default.Remove((string)user);
var split = ((string)user).Split(':');
2020-09-24 14:30:27 +00:00
2022-02-17 11:16:52 +00:00
var guid = Guid.Parse(split[0]);
var tenant = int.Parse(split[1]);
2020-09-24 14:30:27 +00:00
2022-02-17 11:16:52 +00:00
if (tenant == TenantId)
{
_cachedTelegramDao.RegisterUser(guid, tenant, Context.User.Id);
await ReplyAsync("Ok!");
return;
2020-09-24 14:30:27 +00:00
}
}
2022-02-17 11:16:52 +00:00
await ReplyAsync("Error");
2020-09-24 14:30:27 +00:00
}
}