mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 17:58:26 -04:00
Cleaned up some unused/commented code
- Small amount of refactoring - Separated imagesharp extension to ImageSharpExtensions.cs - Using .join Ienumerable extension instead of string.join in some places
This commit is contained in:
@@ -4,7 +4,7 @@ using NadekoBot.Db;
|
||||
namespace NadekoBot.Modules.Administration.Services;
|
||||
|
||||
// todo dateonly timeonly
|
||||
// todo new apis
|
||||
// todo timer
|
||||
public class GameVoiceChannelService : INService
|
||||
{
|
||||
public ConcurrentHashSet<ulong> GameVoiceChannels { get; }
|
||||
|
@@ -41,6 +41,7 @@ public partial class Administration
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
await _service.ClearAllOverrides(ctx.Guild.Id);
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.perm_override_all);
|
||||
@@ -66,8 +67,8 @@ public partial class Administration
|
||||
if (thisPageOverrides.Count == 0)
|
||||
eb.WithDescription(GetText(strs.perm_override_page_none));
|
||||
else
|
||||
eb.WithDescription(string.Join("\n",
|
||||
thisPageOverrides.Select(ov => $"{ov.Command} => {ov.Perm.ToString()}")));
|
||||
eb.WithDescription(thisPageOverrides.Select(ov => $"{ov.Command} => {ov.Perm.ToString()}")
|
||||
.Join("\n"));
|
||||
|
||||
return eb;
|
||||
},
|
||||
|
@@ -1,66 +1,64 @@
|
||||
#nullable disable
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Services;
|
||||
|
||||
public sealed class PlayingRotateService : INService
|
||||
public sealed class PlayingRotateService : INService, IReadyExecutor
|
||||
{
|
||||
private readonly Timer _t;
|
||||
private readonly BotConfigService _bss;
|
||||
private readonly SelfService _selfService;
|
||||
private readonly Replacer _rep;
|
||||
private readonly DbService _db;
|
||||
private readonly Bot _bot;
|
||||
|
||||
public PlayingRotateService(
|
||||
DiscordSocketClient client,
|
||||
DbService db,
|
||||
Bot bot,
|
||||
BotConfigService bss,
|
||||
IEnumerable<IPlaceholderProvider> phProviders,
|
||||
SelfService selfService)
|
||||
{
|
||||
_db = db;
|
||||
_bot = bot;
|
||||
_bss = bss;
|
||||
_selfService = selfService;
|
||||
|
||||
if (client.ShardId == 0)
|
||||
{
|
||||
_rep = new ReplacementBuilder().WithClient(client).WithProviders(phProviders).Build();
|
||||
|
||||
_t = new(RotatingStatuses, new TimerState(), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
|
||||
}
|
||||
}
|
||||
|
||||
private async void RotatingStatuses(object objState)
|
||||
public async Task OnReadyAsync()
|
||||
{
|
||||
try
|
||||
var timer = new PeriodicTimer(TimeSpan.FromMinutes(1));
|
||||
var index = 0;
|
||||
while (await timer.WaitForNextTickAsync())
|
||||
{
|
||||
var state = (TimerState)objState;
|
||||
|
||||
if (!_bss.Data.RotateStatuses) return;
|
||||
|
||||
IReadOnlyList<RotatingPlayingStatus> rotatingStatuses;
|
||||
await using (var uow = _db.GetDbContext())
|
||||
try
|
||||
{
|
||||
rotatingStatuses = uow.RotatingStatus.AsNoTracking().OrderBy(x => x.Id).ToList();
|
||||
if (!_bss.Data.RotateStatuses) return;
|
||||
|
||||
IReadOnlyList<RotatingPlayingStatus> rotatingStatuses;
|
||||
await using (var uow = _db.GetDbContext())
|
||||
{
|
||||
rotatingStatuses = uow.RotatingStatus.AsNoTracking().OrderBy(x => x.Id).ToList();
|
||||
}
|
||||
|
||||
if (rotatingStatuses.Count == 0)
|
||||
return;
|
||||
|
||||
var playingStatus = index >= rotatingStatuses.Count
|
||||
? rotatingStatuses[index = 0]
|
||||
: rotatingStatuses[index++];
|
||||
|
||||
var statusText = _rep.Replace(playingStatus.Status);
|
||||
await _selfService.SetGameAsync(statusText, playingStatus.Type);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Rotating playing status errored: {ErrorMessage}", ex.Message);
|
||||
}
|
||||
|
||||
if (rotatingStatuses.Count == 0)
|
||||
return;
|
||||
|
||||
var playingStatus = state.Index >= rotatingStatuses.Count
|
||||
? rotatingStatuses[state.Index = 0]
|
||||
: rotatingStatuses[state.Index++];
|
||||
|
||||
var statusText = _rep.Replace(playingStatus.Status);
|
||||
await _selfService.SetGameAsync(statusText, playingStatus.Type);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Rotating playing status errored: {ErrorMessage}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,9 +98,4 @@ public sealed class PlayingRotateService : INService
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow.RotatingStatus.AsNoTracking().ToList();
|
||||
}
|
||||
|
||||
private class TimerState
|
||||
{
|
||||
public int Index { get; set; }
|
||||
}
|
||||
}
|
@@ -40,7 +40,9 @@ public partial class Administration
|
||||
}
|
||||
|
||||
var role = (IRole)roleResult.BestMatch;
|
||||
if (role.Position > ((IGuildUser)ctx.User).GetRoles().Select(r => r.Position).Max()
|
||||
if (role.Position > ((IGuildUser)ctx.User).GetRoles()
|
||||
.Select(r => r.Position)
|
||||
.Max()
|
||||
&& ctx.User.Id != ctx.Guild.OwnerId)
|
||||
return null;
|
||||
var emote = x.Last().ToIEmote();
|
||||
|
Reference in New Issue
Block a user