520 #27
1 changed files with 14 additions and 4 deletions
|
@ -9,7 +9,9 @@ public sealed class PlayingRotateService : IEService, IReadyExecutor
|
||||||
{
|
{
|
||||||
private readonly BotConfigService _bss;
|
private readonly BotConfigService _bss;
|
||||||
private readonly SelfService _selfService;
|
private readonly SelfService _selfService;
|
||||||
|
|
||||||
private readonly IReplacementService _repService;
|
private readonly IReplacementService _repService;
|
||||||
|
|
||||||
// private readonly Replacer _rep;
|
// private readonly Replacer _rep;
|
||||||
private readonly DbService _db;
|
private readonly DbService _db;
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
|
@ -27,14 +29,13 @@ public sealed class PlayingRotateService : IEService, IReadyExecutor
|
||||||
_selfService = selfService;
|
_selfService = selfService;
|
||||||
_repService = repService;
|
_repService = repService;
|
||||||
_client = client;
|
_client = client;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnReadyAsync()
|
public async Task OnReadyAsync()
|
||||||
{
|
{
|
||||||
if (_client.ShardId != 0)
|
if (_client.ShardId != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
using var timer = new PeriodicTimer(TimeSpan.FromMinutes(1));
|
using var timer = new PeriodicTimer(TimeSpan.FromMinutes(1));
|
||||||
var index = 0;
|
var index = 0;
|
||||||
while (await timer.WaitForNextTickAsync())
|
while (await timer.WaitForNextTickAsync())
|
||||||
|
@ -57,7 +58,7 @@ public sealed class PlayingRotateService : IEService, IReadyExecutor
|
||||||
? rotatingStatuses[index = 0]
|
? rotatingStatuses[index = 0]
|
||||||
: rotatingStatuses[index++];
|
: rotatingStatuses[index++];
|
||||||
|
|
||||||
var statusText = await _repService.ReplaceAsync(playingStatus.Status, new (client: _client));
|
var statusText = await _repService.ReplaceAsync(playingStatus.Status, new(client: _client));
|
||||||
await _selfService.SetActivityAsync(statusText, (ActivityType)playingStatus.Type);
|
await _selfService.SetActivityAsync(statusText, (ActivityType)playingStatus.Type);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -72,7 +73,11 @@ public sealed class PlayingRotateService : IEService, IReadyExecutor
|
||||||
ArgumentOutOfRangeException.ThrowIfNegative(index);
|
ArgumentOutOfRangeException.ThrowIfNegative(index);
|
||||||
|
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
var toRemove = await uow.Set<RotatingPlayingStatus>().AsQueryable().AsNoTracking().Skip(index).FirstOrDefaultAsync();
|
var toRemove = await uow.Set<RotatingPlayingStatus>()
|
||||||
|
.AsQueryable()
|
||||||
|
.AsNoTracking()
|
||||||
|
.Skip(index)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
if (toRemove is null)
|
if (toRemove is null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -94,6 +99,11 @@ public sealed class PlayingRotateService : IEService, IReadyExecutor
|
||||||
await uow.SaveChangesAsync();
|
await uow.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DisableRotatePlaying()
|
||||||
|
{
|
||||||
|
_bss.ModifyConfig(bs => { bs.RotateStatuses = false; });
|
||||||
|
}
|
||||||
|
|
||||||
public bool ToggleRotatePlaying()
|
public bool ToggleRotatePlaying()
|
||||||
{
|
{
|
||||||
var enabled = false;
|
var enabled = false;
|
||||||
|
|
Loading…
Reference in a new issue