Added .repeatskip

This commit is contained in:
Kwoth
2022-07-26 16:56:33 +02:00
parent 0f8291c589
commit e20212a6cb
6 changed files with 66 additions and 4 deletions

View File

@@ -13,6 +13,6 @@ public sealed class CmdAttribute : CommandAttribute
MethodName = memberName.ToLowerInvariant(); MethodName = memberName.ToLowerInvariant();
Aliases = CommandNameLoadHelper.GetAliasesFor(memberName); Aliases = CommandNameLoadHelper.GetAliasesFor(memberName);
Remarks = memberName.ToLowerInvariant(); Remarks = memberName.ToLowerInvariant();
// Summary = memberName.ToLowerInvariant(); Summary = memberName.ToLowerInvariant();
} }
} }

View File

@@ -9,6 +9,32 @@ public partial class Utility
[Group] [Group]
public partial class RepeatCommands : NadekoModule<RepeaterService> public partial class RepeatCommands : NadekoModule<RepeaterService>
{ {
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.ManageMessages)]
public async Task RepeatSkip(int index)
{
if (--index < 0)
return;
var result = await _service.ToggleSkipNextAsync(ctx.Guild.Id, index);
if (result is null)
{
await ReplyErrorLocalizedAsync(strs.index_out_of_range);
return;
}
if (result is true)
{
await ReplyConfirmLocalizedAsync(strs.repeater_skip_next);
}
else
{
await ReplyConfirmLocalizedAsync(strs.repeater_dont_skip_next);
}
}
[Cmd] [Cmd]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.ManageMessages)] [UserPerm(GuildPerm.ManageMessages)]
@@ -149,7 +175,7 @@ public partial class Utility
foreach (var runner in repeaters.OrderBy(r => r.Repeater.Id)) foreach (var runner in repeaters.OrderBy(r => r.Repeater.Id))
{ {
var description = GetRepeaterInfoString(runner); var description = GetRepeaterInfoString(runner);
var name = $"#`{++i}`"; var name = $"#`{++i}` {(_service.IsRepeaterSkipped(runner.Repeater.Id) ? "🦘" : "")}";
embed.AddField(name, description); embed.AddField(name, description);
} }

View File

@@ -1,7 +1,6 @@
using LinqToDB; using LinqToDB;
using LinqToDB.EntityFrameworkCore; using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Nadeko.Common;
using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Services.Database.Models; using NadekoBot.Services.Database.Models;
@@ -16,6 +15,7 @@ public sealed class RepeaterService : IReadyExecutor, INService
private readonly DiscordSocketClient _client; private readonly DiscordSocketClient _client;
private readonly LinkedList<RunningRepeater> _repeaterQueue; private readonly LinkedList<RunningRepeater> _repeaterQueue;
private readonly ConcurrentHashSet<int> _noRedundant; private readonly ConcurrentHashSet<int> _noRedundant;
private readonly ConcurrentHashSet<int> _skipNext = new();
private readonly object _queueLocker = new(); private readonly object _queueLocker = new();
@@ -82,7 +82,7 @@ public sealed class RepeaterService : IReadyExecutor, INService
// execute // execute
foreach (var chunk in toExecute.Chunk(5)) foreach (var chunk in toExecute.Chunk(5))
await chunk.Select(Trigger).WhenAll(); await chunk.Where(x => !_skipNext.TryRemove(x.Repeater.Id)).Select(Trigger).WhenAll();
// reinsert // reinsert
foreach (var rep in toExecute) foreach (var rep in toExecute)
@@ -396,6 +396,27 @@ public sealed class RepeaterService : IReadyExecutor, INService
return newValue; return newValue;
} }
public async Task<bool?> ToggleSkipNextAsync(ulong guildId, int index)
{
await using var ctx = _db.GetDbContext();
var toSkip = await ctx.Repeaters
.Where(x => x.GuildId == guildId)
.Skip(index)
.FirstOrDefaultAsyncEF();
if (toSkip is null)
return null;
if (_skipNext.Add(toSkip.Id))
return true;
_skipNext.TryRemove(toSkip.Id);
return false;
}
public bool IsNoRedundant(int repeaterId) public bool IsNoRedundant(int repeaterId)
=> _noRedundant.Contains(repeaterId); => _noRedundant.Contains(repeaterId);
public bool IsRepeaterSkipped(int repeaterId)
=> _skipNext.Contains(repeaterId);
} }

View File

@@ -58,6 +58,9 @@ repeat:
repeatredundant: repeatredundant:
- repeatredun - repeatredun
- repred - repred
repeatskip:
- repeatskip
- repski
rotateplaying: rotateplaying:
- rotateplaying - rotateplaying
- ropl - ropl

View File

@@ -128,6 +128,10 @@ repeatredundant:
desc: "Specify repeater's index (use `{0}repli` to find it) to toggle whether that repeater's message should be reposted if the last message in the channel is the same repeater's message. This is useful if you want to remind everyone to be nice in the channel every so often, but don't want to have the bot spam the channel. This is NOT useful if you want to periodically ping someone." desc: "Specify repeater's index (use `{0}repli` to find it) to toggle whether that repeater's message should be reposted if the last message in the channel is the same repeater's message. This is useful if you want to remind everyone to be nice in the channel every so often, but don't want to have the bot spam the channel. This is NOT useful if you want to periodically ping someone."
args: args:
- "1" - "1"
repeatskip:
desc: "Specify a repeater's ID to toggle whether the next trigger of the repeater will be skipped. This setting is not stored in the database and will get reset if the bot is restarted."
args:
- "3"
rotateplaying: rotateplaying:
desc: "Toggles rotation of playing status of the dynamic strings you previously specified." desc: "Toggles rotation of playing status of the dynamic strings you previously specified."
args: args:
@@ -2162,6 +2166,12 @@ imageonlychannel:
Users who send more than a few non-image messages will be banned from using the channel. Users who send more than a few non-image messages will be banned from using the channel.
args: args:
- "" - ""
linksonlychannel:
desc: |-
Toggles whether the channel only allows links.
Users who send more than a few non-link messages will be banned from using the channel.
args:
- ""
coordreload: coordreload:
desc: "Reloads coordinator config" desc: "Reloads coordinator config"
args: args:

View File

@@ -571,6 +571,8 @@
"repeater_removed": "Repeater #{0} Removed", "repeater_removed": "Repeater #{0} Removed",
"repeater_exceed_limit": "You cannot have more than {0} repeaters per server.", "repeater_exceed_limit": "You cannot have more than {0} repeaters per server.",
"repeater_remove_fail": "Failed removing repeater on that index. Either you've specified invalid index, or repeater was in executing state at that time, in which case, try again in a few seconds.", "repeater_remove_fail": "Failed removing repeater on that index. Either you've specified invalid index, or repeater was in executing state at that time, in which case, try again in a few seconds.",
"repeater_skip_next": "Next trigger of this repeater will be skipped.",
"repeater_dont_skip_next": "Next trigger of this repeater won't be skipped.",
"interval_colon": "Interval:", "interval_colon": "Interval:",
"executes_in_colon": "Executes in:", "executes_in_colon": "Executes in:",
"message_colon": "Message:", "message_colon": "Message:",