mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-11-04 08:34:27 -05:00
- More code cleanup and codestyle updates
- Fixed some possible nullref exceptions - Methods signatures now have up to 3 parameters before breakaing down each parameter in a separate line - Method invocations have the same rule, except the first parameter will be in the same line as the invocation to prevent some ugliness when passing lambas as arguments - Applied many more codestyles - Extensions folder fully reformatted
This commit is contained in:
@@ -8,10 +8,8 @@ public partial class Administration : NadekoModule<AdministrationService>
|
||||
private readonly ImageOnlyChannelService _imageOnly;
|
||||
|
||||
public Administration(ImageOnlyChannelService imageOnly)
|
||||
{
|
||||
_imageOnly = imageOnly;
|
||||
}
|
||||
|
||||
=> _imageOnly = imageOnly;
|
||||
|
||||
public enum List
|
||||
{
|
||||
List = 0,
|
||||
@@ -292,9 +290,7 @@ public partial class Administration : NadekoModule<AdministrationService>
|
||||
[NadekoCommand, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Delete(ITextChannel channel, ulong messageId, StoopidTime time = null)
|
||||
{
|
||||
await InternalMessageAction(channel, messageId, time, msg => msg.DeleteAsync());
|
||||
}
|
||||
=> await InternalMessageAction(channel, messageId, time, msg => msg.DeleteAsync());
|
||||
|
||||
private async Task InternalMessageAction(ITextChannel channel, ulong messageId, StoopidTime time,
|
||||
Func<IMessage, Task> func)
|
||||
|
||||
@@ -61,7 +61,7 @@ public partial class Administration
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.aar_roles(
|
||||
'\n' + existing.Select(x => Format.Bold(x.ToString()))
|
||||
.JoinWith(",\n")));
|
||||
.Join(",\n")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Common;
|
||||
|
||||
@@ -35,10 +34,8 @@ public class AntiAltStats
|
||||
public int Counter => _counter;
|
||||
|
||||
public AntiAltStats(AntiAltSetting setting)
|
||||
{
|
||||
_setting = setting;
|
||||
}
|
||||
|
||||
=> _setting = setting;
|
||||
|
||||
public void Increment() => Interlocked.Increment(ref _counter);
|
||||
|
||||
}
|
||||
@@ -42,11 +42,9 @@ public partial class Administration
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[Priority(0)]
|
||||
public async Task LanguageSet()
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.lang_set_show(
|
||||
=> await ReplyConfirmLocalizedAsync(strs.lang_set_show(
|
||||
Format.Bold(_cultureInfo.ToString()),
|
||||
Format.Bold(_cultureInfo.NativeName)));
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
@@ -113,12 +111,10 @@ public partial class Administration
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
public async Task LanguagesList()
|
||||
{
|
||||
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
|
||||
=> await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
|
||||
.WithTitle(GetText(strs.lang_list))
|
||||
.WithDescription(string.Join("\n",
|
||||
supportedLocales.Select(x => $"{Format.Code(x.Key),-10} => {x.Value}")))).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* list of language codes for reference.
|
||||
|
||||
@@ -8,9 +8,7 @@ public partial class Administration
|
||||
[NadekoCommand, Aliases]
|
||||
[Priority(1)]
|
||||
public async Task PrefixCommand()
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.prefix_current(Format.Code(CmdHandler.GetPrefix(ctx.Guild)))).ConfigureAwait(false);
|
||||
}
|
||||
=> await ReplyConfirmLocalizedAsync(strs.prefix_current(Format.Code(CmdHandler.GetPrefix(ctx.Guild)))).ConfigureAwait(false);
|
||||
|
||||
public enum Set
|
||||
{
|
||||
|
||||
@@ -94,13 +94,13 @@ public partial class Administration
|
||||
return;
|
||||
}
|
||||
|
||||
if (userThreshold < 2 || userThreshold > 30)
|
||||
if (userThreshold is < 2 or > 30)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.raid_cnt(2, 30));
|
||||
return;
|
||||
}
|
||||
|
||||
if (seconds < 2 || seconds > 300)
|
||||
if (seconds is < 2 or > 300)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.raid_time(2, 300));
|
||||
return;
|
||||
@@ -115,7 +115,7 @@ public partial class Administration
|
||||
}
|
||||
|
||||
var time = (int?) punishTime?.Time.TotalMinutes ?? 0;
|
||||
if (time < 0 || time > 60 * 24)
|
||||
if (time is < 0 or > 60 * 24)
|
||||
return;
|
||||
|
||||
var stats = await _service.StartAntiRaidAsync(ctx.Guild.Id, userThreshold, seconds,
|
||||
@@ -175,7 +175,7 @@ public partial class Administration
|
||||
public async Task InternalAntiSpam(int messageCount, PunishmentAction action,
|
||||
StoopidTime timeData = null, IRole role = null)
|
||||
{
|
||||
if (messageCount < 2 || messageCount > 10)
|
||||
if (messageCount is < 2 or > 10)
|
||||
return;
|
||||
|
||||
if (timeData is not null)
|
||||
@@ -187,7 +187,7 @@ public partial class Administration
|
||||
}
|
||||
|
||||
var time = (int?) timeData?.Time.TotalMinutes ?? 0;
|
||||
if (time < 0 || time > 60 * 24)
|
||||
if (time is < 0 or > 60 * 24)
|
||||
return;
|
||||
|
||||
var stats = await _service.StartAntiSpamAsync(ctx.Guild.Id, messageCount, action, time, role?.Id).ConfigureAwait(false);
|
||||
|
||||
@@ -17,7 +17,7 @@ public partial class Administration
|
||||
{
|
||||
var user = await ctx.Guild.GetCurrentUserAsync().ConfigureAwait(false);
|
||||
|
||||
if (parameter == "-s" || parameter == "--safe")
|
||||
if (parameter is "-s" or "--safe")
|
||||
await _service.PruneWhere((ITextChannel)ctx.Channel, 100, x => x.Author.Id == user.Id && !x.IsPinned).ConfigureAwait(false);
|
||||
else
|
||||
await _service.PruneWhere((ITextChannel)ctx.Channel, 100, x => x.Author.Id == user.Id).ConfigureAwait(false);
|
||||
@@ -37,7 +37,7 @@ public partial class Administration
|
||||
if (count > 1000)
|
||||
count = 1000;
|
||||
|
||||
if (parameter == "-s" || parameter == "--safe")
|
||||
if (parameter is "-s" or "--safe")
|
||||
await _service.PruneWhere((ITextChannel)ctx.Channel, count, x => !x.IsPinned).ConfigureAwait(false);
|
||||
else
|
||||
await _service.PruneWhere((ITextChannel)ctx.Channel, count, x => true).ConfigureAwait(false);
|
||||
@@ -69,7 +69,7 @@ public partial class Administration
|
||||
if (count > 1000)
|
||||
count = 1000;
|
||||
|
||||
if (parameter == "-s" || parameter == "--safe")
|
||||
if (parameter is "-s" or "--safe")
|
||||
await _service.PruneWhere((ITextChannel)ctx.Channel, count, m => m.Author.Id == userId && DateTime.UtcNow - m.CreatedAt < twoWeeks && !m.IsPinned).ConfigureAwait(false);
|
||||
else
|
||||
await _service.PruneWhere((ITextChannel)ctx.Channel, count, m => m.Author.Id == userId && DateTime.UtcNow - m.CreatedAt < twoWeeks).ConfigureAwait(false);
|
||||
|
||||
@@ -13,9 +13,7 @@ public partial class Administration
|
||||
public enum Exclude { Excl }
|
||||
|
||||
public RoleCommands(IServiceProvider services)
|
||||
{
|
||||
_services = services;
|
||||
}
|
||||
=> _services = services;
|
||||
|
||||
public async Task InternalReactionRoles(bool exclusive, ulong? messageId, params string[] input)
|
||||
{
|
||||
@@ -326,9 +324,7 @@ public partial class Administration
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[Priority(1)]
|
||||
public async Task RoleColor([Leftover] IRole role)
|
||||
{
|
||||
await SendConfirmAsync("Role Color", role.Color.RawValue.ToString("x6")).ConfigureAwait(false);
|
||||
}
|
||||
=> await SendConfirmAsync("Role Color", role.Color.RawValue.ToString("x6")).ConfigureAwait(false);
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
|
||||
@@ -145,9 +145,7 @@ public partial class Administration
|
||||
}
|
||||
|
||||
private string GetIntervalText(int interval)
|
||||
{
|
||||
return $"[{GetText(strs.interval)}]: {interval}";
|
||||
}
|
||||
=> $"[{GetText(strs.interval)}]: {interval}";
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[OwnerOnly]
|
||||
@@ -298,9 +296,7 @@ public partial class Administration
|
||||
[NadekoCommand, Aliases]
|
||||
[OwnerOnly]
|
||||
public Task Leave([Leftover] string guildStr)
|
||||
{
|
||||
return _service.LeaveGuild(guildStr);
|
||||
}
|
||||
=> _service.LeaveGuild(guildStr);
|
||||
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -450,7 +446,7 @@ public partial class Administration
|
||||
|
||||
if (ids[1].ToUpperInvariant().StartsWith("C:", StringComparison.InvariantCulture))
|
||||
{
|
||||
var cid = ulong.Parse(ids[1].Substring(2));
|
||||
var cid = ulong.Parse(ids[1][2..]);
|
||||
var ch = server.TextChannels.FirstOrDefault(c => c.Id == cid);
|
||||
if (ch is null)
|
||||
return;
|
||||
@@ -460,7 +456,7 @@ public partial class Administration
|
||||
}
|
||||
else if (ids[1].ToUpperInvariant().StartsWith("U:", StringComparison.InvariantCulture))
|
||||
{
|
||||
var uid = ulong.Parse(ids[1].Substring(2));
|
||||
var uid = ulong.Parse(ids[1][2..]);
|
||||
var user = server.Users.FirstOrDefault(u => u.Id == uid);
|
||||
if (user is null)
|
||||
return;
|
||||
|
||||
@@ -23,7 +23,7 @@ public partial class Administration
|
||||
[UserPerm(GuildPerm.ManageGuild)]
|
||||
public async Task BoostDel(int timer = 30)
|
||||
{
|
||||
if (timer < 0 || timer > 600)
|
||||
if (timer is < 0 or > 600)
|
||||
return;
|
||||
|
||||
await _service.SetBoostDel(ctx.Guild.Id, timer);
|
||||
@@ -66,7 +66,7 @@ public partial class Administration
|
||||
[UserPerm(GuildPerm.ManageGuild)]
|
||||
public async Task GreetDel(int timer = 30)
|
||||
{
|
||||
if (timer < 0 || timer > 600)
|
||||
if (timer is < 0 or > 600)
|
||||
return;
|
||||
|
||||
await _service.SetGreetDel(ctx.Guild.Id, timer).ConfigureAwait(false);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Db;
|
||||
|
||||
|
||||
@@ -155,7 +155,5 @@ public static class GuildConfigExtensions
|
||||
}
|
||||
|
||||
public static void SetAutoAssignableRoles(this GuildConfig gc, IEnumerable<ulong> roles)
|
||||
{
|
||||
gc.AutoAssignRoleIds = roles.JoinWith(',');
|
||||
}
|
||||
=> gc.AutoAssignRoleIds = roles.Join(',');
|
||||
}
|
||||
@@ -33,9 +33,7 @@ DELETE FROM Clubs;";
|
||||
private readonly DbService _db;
|
||||
|
||||
public DangerousCommandsService(DbService db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
=> _db = db;
|
||||
|
||||
public async Task<int> ExecuteSql(string sql)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Db;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Services;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Threading.Channels;
|
||||
using LinqToDB;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Services;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Modules.Administration.Common;
|
||||
@@ -23,24 +22,16 @@ public sealed class DummyLogCommandService : ILogCommandService
|
||||
}
|
||||
|
||||
public Task LogServer(ulong guildId, ulong channelId, bool actionValue)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
=> Task.CompletedTask;
|
||||
|
||||
public bool LogIgnore(ulong guildId, ulong itemId, IgnoredItemType itemType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
=> false;
|
||||
|
||||
public LogSetting GetGuildLogSettings(ulong guildId)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
=> default;
|
||||
|
||||
public bool Log(ulong guildId, ulong? channelId, LogType type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
=> false;
|
||||
}
|
||||
|
||||
public sealed class LogCommandService : ILogCommandService
|
||||
@@ -150,9 +141,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
}
|
||||
|
||||
public void AddDeleteIgnore(ulong messageId)
|
||||
{
|
||||
_ignoreMessageIds.Add(messageId);
|
||||
}
|
||||
=> _ignoreMessageIds.Add(messageId);
|
||||
|
||||
public bool LogIgnore(ulong gid, ulong itemId, IgnoredItemType itemType)
|
||||
{
|
||||
@@ -1172,7 +1161,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
break;
|
||||
}
|
||||
|
||||
if (!id.HasValue || id == 0)
|
||||
if (id is null or 0)
|
||||
{
|
||||
UnsetLogSetting(guild.Id, logChannelType);
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Db;
|
||||
|
||||
|
||||
@@ -317,7 +317,11 @@ public class ProtectionService : INService
|
||||
{
|
||||
if (_antiSpamGuilds.TryRemove(guildId, out var removed))
|
||||
{
|
||||
removed.UserStats.ForEach(x => x.Value.Dispose());
|
||||
foreach (var (_, val) in removed.UserStats)
|
||||
{
|
||||
val.Dispose();
|
||||
}
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting)
|
||||
.ThenInclude(x => x.IgnoredChannels));
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
using NadekoBot.Common.Collections;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Services;
|
||||
namespace NadekoBot.Modules.Administration.Services;
|
||||
|
||||
public class PruneService : INService
|
||||
{
|
||||
//channelids where prunes are currently occuring
|
||||
private readonly ConcurrentHashSet<ulong> _pruningGuilds = new();
|
||||
private readonly TimeSpan twoWeeks = TimeSpan.FromDays(14);
|
||||
private readonly TimeSpan _twoWeeks = TimeSpan.FromDays(14);
|
||||
private readonly ILogCommandService _logService;
|
||||
|
||||
public PruneService(ILogCommandService logService)
|
||||
{
|
||||
this._logService = logService;
|
||||
}
|
||||
=> this._logService = logService;
|
||||
|
||||
public async Task PruneWhere(ITextChannel channel, int amount, Func<IMessage, bool> predicate)
|
||||
{
|
||||
channel.ThrowIfNull(nameof(channel));
|
||||
ArgumentNullException.ThrowIfNull(channel, nameof(channel));
|
||||
|
||||
if (amount <= 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(amount));
|
||||
|
||||
@@ -38,7 +35,7 @@ public class PruneService : INService
|
||||
{
|
||||
_logService.AddDeleteIgnore(x.Id);
|
||||
|
||||
if (DateTime.UtcNow - x.CreatedAt < twoWeeks)
|
||||
if (DateTime.UtcNow - x.CreatedAt < _twoWeeks)
|
||||
bulkDeletable.Add(x);
|
||||
else
|
||||
singleDeletable.Add(x);
|
||||
|
||||
@@ -135,9 +135,7 @@ public class RoleCommandsService : INService
|
||||
}
|
||||
|
||||
public bool Get(ulong id, out IndexedCollection<ReactionRoleMessage> rrs)
|
||||
{
|
||||
return _models.TryGetValue(id, out rrs);
|
||||
}
|
||||
=> _models.TryGetValue(id, out rrs);
|
||||
|
||||
public bool Add(ulong id, ReactionRoleMessage rrm)
|
||||
{
|
||||
|
||||
@@ -27,9 +27,7 @@ public class SelfAssignedRolesService : INService
|
||||
}
|
||||
|
||||
public SelfAssignedRolesService(DbService db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
=> _db = db;
|
||||
|
||||
public bool AddNew(ulong guildId, IRole role, int group)
|
||||
{
|
||||
|
||||
@@ -123,12 +123,10 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
}
|
||||
|
||||
private Timer TimerFromAutoCommand(AutoCommand x)
|
||||
{
|
||||
return new(async obj => await ExecuteCommand((AutoCommand) obj).ConfigureAwait(false),
|
||||
=> new(async obj => await ExecuteCommand((AutoCommand) obj).ConfigureAwait(false),
|
||||
x,
|
||||
x.Interval * 1000,
|
||||
x.Interval * 1000);
|
||||
}
|
||||
|
||||
private async Task ExecuteCommand(AutoCommand cmd)
|
||||
{
|
||||
@@ -366,8 +364,7 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
}
|
||||
|
||||
private void HandleStatusChanges()
|
||||
{
|
||||
_pubSub.Sub(_activitySetKey, async data =>
|
||||
=> _pubSub.Sub(_activitySetKey, async data =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -378,7 +375,6 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
|
||||
Log.Warning(ex, "Error setting activity");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Task SetGameAsync(string game, ActivityType type)
|
||||
=> _pubSub.Pub(_activitySetKey, new() {Name = game, Link = null, Type = type});
|
||||
|
||||
@@ -300,7 +300,7 @@ WHERE GuildId={guildId}
|
||||
public bool WarnPunish(ulong guildId, int number, PunishmentAction punish, StoopidTime time, IRole role = null)
|
||||
{
|
||||
// these 3 don't make sense with time
|
||||
if ((punish == PunishmentAction.Softban || punish == PunishmentAction.Kick || punish == PunishmentAction.RemoveRoles) && time != null)
|
||||
if (punish is PunishmentAction.Softban or PunishmentAction.Kick or PunishmentAction.RemoveRoles && time != null)
|
||||
return false;
|
||||
if (number <= 0 || (time != null && time.Time > TimeSpan.FromDays(49)))
|
||||
return false;
|
||||
@@ -427,8 +427,7 @@ WHERE GuildId={guildId}
|
||||
|
||||
public SmartText GetBanUserDmEmbed(ICommandContext context, IGuildUser target, string defaultMessage,
|
||||
string banReason, TimeSpan? duration)
|
||||
{
|
||||
return GetBanUserDmEmbed(
|
||||
=> GetBanUserDmEmbed(
|
||||
(DiscordSocketClient) context.Client,
|
||||
(SocketGuild) context.Guild,
|
||||
(IGuildUser) context.User,
|
||||
@@ -436,7 +435,6 @@ WHERE GuildId={guildId}
|
||||
defaultMessage,
|
||||
banReason,
|
||||
duration);
|
||||
}
|
||||
|
||||
public SmartText GetBanUserDmEmbed(DiscordSocketClient client, SocketGuild guild,
|
||||
IGuildUser moderator, IGuildUser target, string defaultMessage, string banReason, TimeSpan? duration)
|
||||
|
||||
@@ -13,7 +13,7 @@ public partial class Administration
|
||||
{
|
||||
page--;
|
||||
|
||||
if (page < 0 || page > 20)
|
||||
if (page is < 0 or > 20)
|
||||
return;
|
||||
|
||||
var timezones = TimeZoneInfo.GetSystemTimeZones()
|
||||
@@ -56,9 +56,7 @@ public partial class Administration
|
||||
[NadekoCommand, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Timezone()
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.timezone_guild(_service.GetTimeZoneOrUtc(ctx.Guild.Id))).ConfigureAwait(false);
|
||||
}
|
||||
=> await ReplyConfirmLocalizedAsync(strs.timezone_guild(_service.GetTimeZoneOrUtc(ctx.Guild.Id))).ConfigureAwait(false);
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
|
||||
@@ -144,7 +144,7 @@ public partial class Administration
|
||||
[Priority(2)]
|
||||
public async Task WarnExpire(int days, params string[] args)
|
||||
{
|
||||
if (days < 0 || days > 366)
|
||||
if (days is < 0 or > 366)
|
||||
return;
|
||||
|
||||
var opts = OptionsParser.ParseFrom<WarnExpireOptions>(args);
|
||||
|
||||
@@ -95,7 +95,7 @@ public class CustomReactions : NadekoModule<CustomReactionsService>
|
||||
+ (string.IsNullOrWhiteSpace(cr.Reactions)
|
||||
? string.Empty
|
||||
: " // " + string.Join(" ", cr.GetReactions())))
|
||||
.JoinWith('\n');
|
||||
.Join('\n');
|
||||
|
||||
return _eb.Create().WithOkColor()
|
||||
.WithTitle(GetText(strs.custom_reactions))
|
||||
|
||||
@@ -33,8 +33,8 @@ public static class CustomReactionExtensions
|
||||
var rep = new ReplacementBuilder()
|
||||
.WithDefault(ctx.Author, ctx.Channel, (ctx.Channel as ITextChannel)?.Guild as SocketGuild, client)
|
||||
.WithOverride("%target%", () => canMentionEveryone
|
||||
? ctx.Content.Substring(substringIndex).Trim()
|
||||
: ctx.Content.Substring(substringIndex).Trim().SanitizeMentions(true))
|
||||
? ctx.Content[substringIndex..].Trim()
|
||||
: ctx.Content[substringIndex..].Trim().SanitizeMentions(true))
|
||||
.Build();
|
||||
|
||||
var text = SmartText.CreateFrom(cr.Response);
|
||||
@@ -69,11 +69,7 @@ public static class CustomReactionExtensions
|
||||
private static bool isValidWordDivider(this in ReadOnlySpan<char> str, int index)
|
||||
{
|
||||
var ch = str[index];
|
||||
if (ch is >= 'a' and <= 'z')
|
||||
return false;
|
||||
if (ch is >= 'A' and <= 'Z')
|
||||
return false;
|
||||
if (ch is >= '1' and <= '9')
|
||||
if (ch is >= 'a' and <= 'z' or >= 'A' and <= 'Z' or >= '1' and <= '9')
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -713,7 +713,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
|
||||
{
|
||||
GuildId = guildId,
|
||||
Response = cr.Res,
|
||||
Reactions = cr.React?.JoinWith("@@@"),
|
||||
Reactions = cr.React?.Join("@@@"),
|
||||
Trigger = trigger,
|
||||
AllowTarget = cr.At,
|
||||
ContainsAnywhere = cr.Ca,
|
||||
|
||||
@@ -89,7 +89,7 @@ public partial class Gambling
|
||||
dealerIcon = "🏁 ";
|
||||
}
|
||||
|
||||
var cStr = string.Concat(c.Select(x => x.Substring(0, x.Length - 1) + " "));
|
||||
var cStr = string.Concat(c.Select(x => x[..^1] + " "));
|
||||
cStr += "\n" + string.Concat(c.Select(x => x.Last() + " "));
|
||||
var embed = _eb.Create()
|
||||
.WithOkColor()
|
||||
@@ -104,7 +104,7 @@ public partial class Gambling
|
||||
foreach (var p in bj.Players)
|
||||
{
|
||||
c = p.Cards.Select(x => x.GetEmojiString());
|
||||
cStr = "-\t" + string.Concat(c.Select(x => x.Substring(0, x.Length - 1) + " "));
|
||||
cStr = "-\t" + string.Concat(c.Select(x => x[..^1] + " "));
|
||||
cStr += "\n-\t" + string.Concat(c.Select(x => x.Last() + " "));
|
||||
var full = $"{p.DiscordUser.ToString().TrimTo(20)} | Bet: {p.Bet} | Value: {p.GetHandValue()}";
|
||||
if (bj.State == Blackjack.GameState.Ended)
|
||||
|
||||
@@ -18,14 +18,10 @@ public class AnimalRacingUser
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is AnimalRacingUser x
|
||||
=> obj is AnimalRacingUser x
|
||||
? x.UserId == this.UserId
|
||||
: false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.UserId.GetHashCode();
|
||||
}
|
||||
=> this.UserId.GetHashCode();
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public class RaceOptions : INadekoCommandOptions
|
||||
|
||||
public void NormalizeOptions()
|
||||
{
|
||||
if (this.StartTime < 10 || this.StartTime > 120)
|
||||
if (this.StartTime is < 10 or > 120)
|
||||
this.StartTime = 20;
|
||||
}
|
||||
}
|
||||
@@ -203,7 +203,7 @@ public class Blackjack
|
||||
{
|
||||
foreach (var usr in Players)
|
||||
{
|
||||
if (usr.State == User.UserState.Stand || usr.State == User.UserState.Blackjack)
|
||||
if (usr.State is User.UserState.Stand or User.UserState.Blackjack)
|
||||
usr.State = User.UserState.Won;
|
||||
else
|
||||
usr.State = User.UserState.Lost;
|
||||
@@ -226,7 +226,7 @@ public class Blackjack
|
||||
|
||||
foreach (var usr in Players)
|
||||
{
|
||||
if (usr.State == User.UserState.Won || usr.State == User.UserState.Blackjack)
|
||||
if (usr.State is User.UserState.Won or User.UserState.Blackjack)
|
||||
{
|
||||
await _cs.AddAsync(usr.DiscordUser.Id, "BlackJack-win", usr.Bet * 2, gamble: true).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -20,9 +20,7 @@ public abstract class Player
|
||||
}
|
||||
|
||||
public int GetRawHandValue()
|
||||
{
|
||||
return Cards.Sum(x => x.Number == 1 ? 11 : x.Number >= 10 ? 10 : x.Number);
|
||||
}
|
||||
=> Cards.Sum(x => x.Number == 1 ? 11 : x.Number >= 10 ? 10 : x.Number);
|
||||
}
|
||||
|
||||
public class Dealer : Player
|
||||
|
||||
@@ -13,16 +13,12 @@ public class CurrencyRaffleGame
|
||||
public long Amount { get; set; }
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return DiscordUser.GetHashCode();
|
||||
}
|
||||
=> DiscordUser.GetHashCode();
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is User u
|
||||
=> obj is User u
|
||||
? u.DiscordUser == DiscordUser
|
||||
: false;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly HashSet<User> _users = new();
|
||||
@@ -30,9 +26,7 @@ public class CurrencyRaffleGame
|
||||
public Type GameType { get; }
|
||||
|
||||
public CurrencyRaffleGame(Type type)
|
||||
{
|
||||
GameType = type;
|
||||
}
|
||||
=> GameType = type;
|
||||
|
||||
public bool AddUser(IUser usr, long amount)
|
||||
{
|
||||
|
||||
@@ -166,13 +166,11 @@ public class Deck
|
||||
/// Creates a new instance of the BlackJackGame, this allows you to create multiple games running at one time.
|
||||
/// </summary>
|
||||
public Deck()
|
||||
{
|
||||
RefillPool();
|
||||
}
|
||||
=> RefillPool();
|
||||
|
||||
static Deck()
|
||||
{
|
||||
InitHandValues();
|
||||
}
|
||||
=> InitHandValues();
|
||||
|
||||
/// <summary>
|
||||
/// Restart the game of blackjack. It will only refill the pool for now. Probably wont be used, unless you want to have only 1 bjg running at one time,
|
||||
/// then you will restart the same game every time.
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Common.Events;
|
||||
|
||||
@@ -115,9 +114,7 @@ public class GameStatusEvent : ICurrencyEvent
|
||||
}
|
||||
|
||||
private IEmbedBuilder GetEmbed(long pot)
|
||||
{
|
||||
return _embedFunc(CurrencyEvent.Type.GameStatus, _opts, pot);
|
||||
}
|
||||
=> _embedFunc(CurrencyEvent.Type.GameStatus, _opts, pot);
|
||||
|
||||
private async Task OnMessageDeleted(Cacheable<IMessage, ulong> msg, Cacheable<IMessageChannel, ulong> cacheable)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Common.Events;
|
||||
|
||||
@@ -118,9 +117,7 @@ public class ReactionEvent : ICurrencyEvent
|
||||
}
|
||||
|
||||
private IEmbedBuilder GetEmbed(long pot)
|
||||
{
|
||||
return _embedFunc(CurrencyEvent.Type.Reaction, _opts, pot);
|
||||
}
|
||||
=> _embedFunc(CurrencyEvent.Type.Reaction, _opts, pot);
|
||||
|
||||
private async Task OnMessageDeleted(Cacheable<IMessage, ulong> msg, Cacheable<IMessageChannel, ulong> cacheable)
|
||||
{
|
||||
|
||||
@@ -105,14 +105,12 @@ Doesn't have to be ordered.")]
|
||||
public BetRollPair[] Pairs { get; set; } = Array.Empty<BetRollPair>();
|
||||
|
||||
public BetRollConfig()
|
||||
{
|
||||
Pairs = new BetRollPair[]
|
||||
=> Pairs = new BetRollPair[]
|
||||
{
|
||||
new() { WhenAbove = 99, MultiplyBy = 10 },
|
||||
new() { WhenAbove = 90, MultiplyBy = 4 },
|
||||
new() { WhenAbove = 66, MultiplyBy = 2 }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Cloneable]
|
||||
@@ -163,8 +161,7 @@ public partial class WheelOfFortuneSettings
|
||||
public decimal[] Multipliers { get; set; }
|
||||
|
||||
public WheelOfFortuneSettings()
|
||||
{
|
||||
Multipliers = new decimal[]
|
||||
=> Multipliers = new decimal[]
|
||||
{
|
||||
1.7M,
|
||||
1.5M,
|
||||
@@ -175,7 +172,6 @@ public partial class WheelOfFortuneSettings
|
||||
1.2M,
|
||||
2.4M,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Cloneable]
|
||||
@@ -191,8 +187,7 @@ If negative is true, gift will instead reduce waifu value.")]
|
||||
public List<WaifuItemModel> Items { get; set; } = new();
|
||||
|
||||
public WaifuConfig()
|
||||
{
|
||||
Items = new()
|
||||
=> Items = new()
|
||||
{
|
||||
new("🥔", 5, "Potato"),
|
||||
new("🍪", 10, "Cookie"),
|
||||
@@ -231,7 +226,6 @@ If negative is true, gift will instead reduce waifu value.")]
|
||||
new("🚀", 30000, "Spaceship"),
|
||||
new("🌕", 50000, "Moon")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Cloneable]
|
||||
|
||||
@@ -10,9 +10,7 @@ public abstract class GamblingModule<TService> : NadekoModule<TService>
|
||||
protected string CurrencyName => _config.Currency.Name;
|
||||
|
||||
protected GamblingModule(GamblingConfigService gambService)
|
||||
{
|
||||
_lazyConfig = new(() => gambService.Data);
|
||||
}
|
||||
=> _lazyConfig = new(() => gambService.Data);
|
||||
|
||||
private async Task<bool> InternalCheckBet(long amount)
|
||||
{
|
||||
|
||||
@@ -151,14 +151,14 @@ public sealed class Connect4Game : IDisposable
|
||||
try
|
||||
{
|
||||
inputCol -= 1;
|
||||
if (CurrentPhase == Phase.Ended || CurrentPhase == Phase.Joining)
|
||||
if (CurrentPhase is Phase.Ended or Phase.Joining)
|
||||
return false;
|
||||
|
||||
if (!((_players[0].Value.UserId == userId && CurrentPhase == Phase.P1Move)
|
||||
|| (_players[1].Value.UserId == userId && CurrentPhase == Phase.P2Move)))
|
||||
return false;
|
||||
|
||||
if (inputCol < 0 || inputCol > NumberOfColumns) //invalid input
|
||||
if (inputCol is < 0 or > NumberOfColumns) //invalid input
|
||||
return false;
|
||||
|
||||
if (IsColumnFull(inputCol)) //can't play there event?
|
||||
@@ -259,9 +259,9 @@ public sealed class Connect4Game : IDisposable
|
||||
var curCol = col - i;
|
||||
|
||||
//check if current values are in range
|
||||
if (curRow >= NumberOfRows || curRow < 0)
|
||||
if (curRow is >= NumberOfRows or < 0)
|
||||
break;
|
||||
if (curCol < 0 || curCol >= NumberOfColumns)
|
||||
if (curCol is < 0 or >= NumberOfColumns)
|
||||
break;
|
||||
|
||||
var cur = _gameState[curRow + (curCol * NumberOfRows)];
|
||||
@@ -286,9 +286,9 @@ public sealed class Connect4Game : IDisposable
|
||||
var curCol = col + i;
|
||||
|
||||
//check if current values are in range
|
||||
if (curRow >= NumberOfRows || curRow < 0)
|
||||
if (curRow is >= NumberOfRows or < 0)
|
||||
break;
|
||||
if (curCol < 0 || curCol >= NumberOfColumns)
|
||||
if (curCol is < 0 or >= NumberOfColumns)
|
||||
break;
|
||||
|
||||
var cur = _gameState[curRow + (curCol * NumberOfRows)];
|
||||
@@ -328,9 +328,7 @@ public sealed class Connect4Game : IDisposable
|
||||
}
|
||||
|
||||
private void ResetTimer()
|
||||
{
|
||||
_playerTimeoutTimer.Change(TimeSpan.FromSeconds(_options.TurnTimer), TimeSpan.FromSeconds(_options.TurnTimer));
|
||||
}
|
||||
=> _playerTimeoutTimer.Change(TimeSpan.FromSeconds(_options.TurnTimer), TimeSpan.FromSeconds(_options.TurnTimer));
|
||||
|
||||
private void EndGame(Result result, ulong? winId)
|
||||
{
|
||||
@@ -378,7 +376,7 @@ public sealed class Connect4Game : IDisposable
|
||||
{
|
||||
public void NormalizeOptions()
|
||||
{
|
||||
if (TurnTimer < 5 || TurnTimer > 60)
|
||||
if (TurnTimer is < 5 or > 60)
|
||||
TurnTimer = 15;
|
||||
|
||||
if (Bet < 0)
|
||||
|
||||
@@ -86,8 +86,7 @@ public partial class Gambling
|
||||
try { await arg.DeleteAsync().ConfigureAwait(false); } catch { }
|
||||
else
|
||||
{
|
||||
if (game.CurrentPhase == Connect4Game.Phase.Joining
|
||||
|| game.CurrentPhase == Connect4Game.Phase.Ended)
|
||||
if (game.CurrentPhase is Connect4Game.Phase.Joining or Connect4Game.Phase.Ended)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -145,7 +144,7 @@ public partial class Gambling
|
||||
get => _repostCounter;
|
||||
set
|
||||
{
|
||||
if (value < 0 || value > 7)
|
||||
if (value is < 0 or > 7)
|
||||
_repostCounter = 0;
|
||||
else _repostCounter = value;
|
||||
}
|
||||
@@ -169,8 +168,7 @@ public partial class Gambling
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
if (game.CurrentPhase == Connect4Game.Phase.P1Move ||
|
||||
game.CurrentPhase == Connect4Game.Phase.P2Move)
|
||||
if (game.CurrentPhase is Connect4Game.Phase.P1Move or Connect4Game.Phase.P2Move)
|
||||
sb.AppendLine(GetText(strs.connect4_player_to_move(Format.Bold(game.CurrentPlayer.Username))));
|
||||
|
||||
for (var i = Connect4Game.NumberOfRows; i > 0; i--)
|
||||
|
||||
@@ -32,8 +32,7 @@ public partial class Gambling
|
||||
}
|
||||
|
||||
private IEmbedBuilder GetEmbed(CurrencyEvent.Type type, EventOptions opts, long currentPot)
|
||||
{
|
||||
return type switch
|
||||
=> type switch
|
||||
{
|
||||
CurrencyEvent.Type.Reaction => _eb.Create()
|
||||
.WithOkColor()
|
||||
@@ -47,7 +46,6 @@ public partial class Gambling
|
||||
.WithFooter(GetText(strs.event_duration_footer(opts.Hours))),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type))
|
||||
};
|
||||
}
|
||||
|
||||
private string GetReactionDescription(long amount, long potSize)
|
||||
{
|
||||
|
||||
@@ -17,9 +17,7 @@ public partial class Gambling
|
||||
private readonly IImageCache _images;
|
||||
|
||||
public DiceRollCommands(IDataCache data)
|
||||
{
|
||||
_images = data.LocalImages;
|
||||
}
|
||||
=> _images = data.LocalImages;
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
public async Task Roll()
|
||||
@@ -42,35 +40,27 @@ public partial class Gambling
|
||||
[NadekoCommand, Aliases]
|
||||
[Priority(1)]
|
||||
public async Task Roll(int num)
|
||||
{
|
||||
await InternalRoll(num, true).ConfigureAwait(false);
|
||||
}
|
||||
=> await InternalRoll(num, true).ConfigureAwait(false);
|
||||
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[Priority(1)]
|
||||
public async Task Rolluo(int num = 1)
|
||||
{
|
||||
await InternalRoll(num, false).ConfigureAwait(false);
|
||||
}
|
||||
=> await InternalRoll(num, false).ConfigureAwait(false);
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[Priority(0)]
|
||||
public async Task Roll(string arg)
|
||||
{
|
||||
await InternallDndRoll(arg, true).ConfigureAwait(false);
|
||||
}
|
||||
=> await InternallDndRoll(arg, true).ConfigureAwait(false);
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[Priority(0)]
|
||||
public async Task Rolluo(string arg)
|
||||
{
|
||||
await InternallDndRoll(arg, false).ConfigureAwait(false);
|
||||
}
|
||||
=> await InternallDndRoll(arg, false).ConfigureAwait(false);
|
||||
|
||||
private async Task InternalRoll(int num, bool ordered)
|
||||
{
|
||||
if (num < 1 || num > 30)
|
||||
if (num is < 1 or > 30)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.dice_invalid_number(1, 30));
|
||||
return;
|
||||
@@ -201,7 +191,7 @@ public partial class Gambling
|
||||
|
||||
private Image<Rgba32> GetDice(int num)
|
||||
{
|
||||
if (num < 0 || num > 10)
|
||||
if (num is < 0 or > 10)
|
||||
throw new ArgumentOutOfRangeException(nameof(num));
|
||||
|
||||
if (num == 10)
|
||||
|
||||
@@ -14,13 +14,11 @@ public partial class Gambling
|
||||
private readonly IImageCache _images;
|
||||
|
||||
public DrawCommands(IDataCache data)
|
||||
{
|
||||
_images = data.LocalImages;
|
||||
}
|
||||
=> _images = data.LocalImages;
|
||||
|
||||
private async Task<(Stream ImageStream, string ToSend)> InternalDraw(int num, ulong? guildId = null)
|
||||
{
|
||||
if (num < 1 || num > 10)
|
||||
if (num is < 1 or > 10)
|
||||
throw new ArgumentOutOfRangeException(nameof(num));
|
||||
|
||||
var cards = guildId is null ? new() : _allDecks.GetOrAdd(ctx.Guild, s => new());
|
||||
|
||||
@@ -24,7 +24,7 @@ public partial class Gambling
|
||||
[NadekoCommand, Aliases]
|
||||
public async Task Flip(int count = 1)
|
||||
{
|
||||
if (count > 10 || count < 1)
|
||||
if (count is > 10 or < 1)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.flip_invalid(10));
|
||||
return;
|
||||
|
||||
@@ -201,9 +201,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
[NadekoCommand, Aliases]
|
||||
[Priority(0)]
|
||||
public async Task Cash(ulong userId)
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.has(Format.Code(userId.ToString()), $"{GetCurrency(userId)}"));
|
||||
}
|
||||
=> await ReplyConfirmLocalizedAsync(strs.has(Format.Code(userId.ToString()), $"{GetCurrency(userId)}"));
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[Priority(1)]
|
||||
|
||||
@@ -12,9 +12,7 @@ public partial class Gambling
|
||||
private readonly ILogCommandService logService;
|
||||
|
||||
public PlantPickCommands(ILogCommandService logService, GamblingConfigService gss) : base(gss)
|
||||
{
|
||||
this.logService = logService;
|
||||
}
|
||||
=> this.logService = logService;
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
|
||||
@@ -38,7 +38,7 @@ public class GamblingService : INService
|
||||
{
|
||||
var config = _gss.Data;
|
||||
var maxDecay = config.Decay.MaxDecay;
|
||||
if (config.Decay.Percent <= 0 || config.Decay.Percent > 1 || maxDecay < 0)
|
||||
if (config.Decay.Percent is <= 0 or > 1 || maxDecay < 0)
|
||||
return;
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
@@ -156,7 +156,5 @@ WHERE CurrencyAmount > {config.Decay.MinThreshold} AND UserId!={_client.CurrentU
|
||||
}
|
||||
|
||||
public Task<WheelOfFortuneGame.Result> WheelOfFortuneSpinAsync(ulong userId, long bet)
|
||||
{
|
||||
return new WheelOfFortuneGame(userId, bet, _gss.Data, _cs).SpinAsync();
|
||||
}
|
||||
=> new WheelOfFortuneGame(userId, bet, _gss.Data, _cs).SpinAsync();
|
||||
}
|
||||
@@ -11,9 +11,7 @@ public class ShopService : IShopService, INService
|
||||
private readonly DbService _db;
|
||||
|
||||
public ShopService(DbService db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
=> _db = db;
|
||||
|
||||
private IndexedCollection<ShopEntry> GetEntriesInternal(NadekoContext uow, ulong guildId) =>
|
||||
uow.GuildConfigsForId(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using SixLabors.Fonts;
|
||||
using SixLabors.ImageSharp;
|
||||
|
||||
@@ -6,7 +6,5 @@ public class TestGamblingService : InteractionModuleBase
|
||||
{
|
||||
[SlashCommand("test", "uwu")]
|
||||
public async Task Test(string input1, int input2)
|
||||
{
|
||||
await RespondAsync("Bravo " + input1 + input2);
|
||||
}
|
||||
=> await RespondAsync("Bravo " + input1 + input2);
|
||||
}
|
||||
@@ -257,20 +257,21 @@ public partial class Gambling
|
||||
var nobody = GetText(strs.nobody);
|
||||
var itemsStr = !wi.Items.Any()
|
||||
? "-"
|
||||
: string.Join("\n", wi.Items
|
||||
.Where(x => waifuItems.TryGetValue(x.ItemEmoji, out _))
|
||||
.OrderBy(x => waifuItems[x.ItemEmoji].Price)
|
||||
.GroupBy(x => x.ItemEmoji)
|
||||
.Select(x => $"{x.Key} x{x.Count(),-3}")
|
||||
.Chunk(2)
|
||||
.Select(x => string.Join(" ", x)));
|
||||
: string.Join("\n",
|
||||
wi.Items.Where(x => waifuItems.TryGetValue(x.ItemEmoji, out _))
|
||||
.OrderBy(x => waifuItems[x.ItemEmoji].Price)
|
||||
.GroupBy(x => x.ItemEmoji)
|
||||
.Select(x => $"{x.Key} x{x.Count(),-3}")
|
||||
.Chunk(2)
|
||||
.Select(x => string.Join(" ", x))
|
||||
);
|
||||
|
||||
var fansStr = wi
|
||||
.Fans
|
||||
.Shuffle()
|
||||
.Take(30)
|
||||
.Select(x => wi.Claims.Contains(x) ? $"{x} 💞" : x)
|
||||
.JoinWith('\n');
|
||||
.Join('\n');
|
||||
|
||||
if (string.IsNullOrWhiteSpace(fansStr))
|
||||
fansStr = "-";
|
||||
@@ -309,15 +310,16 @@ public partial class Gambling
|
||||
.WithTitle(GetText(strs.waifu_gift_shop))
|
||||
.WithOkColor();
|
||||
|
||||
waifuItems
|
||||
.OrderBy(x => x.Negative)
|
||||
waifuItems.OrderBy(x => x.Negative)
|
||||
.ThenBy(x => x.Price)
|
||||
.Skip(9 * cur)
|
||||
.Take(9)
|
||||
.ForEach(x => embed
|
||||
.AddField($"{(!x.Negative ? string.Empty : "\\💔")} {x.ItemEmoji} {x.Name}",
|
||||
.ToList()
|
||||
.ForEach(x => embed.AddField($"{(!x.Negative ? string.Empty : "\\💔")} {x.ItemEmoji} {x.Name}",
|
||||
Format.Bold(x.Price.ToString()) + _config.Currency.Sign,
|
||||
true));
|
||||
true
|
||||
)
|
||||
);
|
||||
|
||||
return embed;
|
||||
}, waifuItems.Count, 9);
|
||||
|
||||
@@ -12,9 +12,7 @@ public partial class Games
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public AcropobiaCommands(DiscordSocketClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
=> _client = client;
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
@@ -80,11 +78,9 @@ public partial class Games
|
||||
}
|
||||
|
||||
private Task Game_OnUserVoted(string user)
|
||||
{
|
||||
return SendConfirmAsync(
|
||||
=> SendConfirmAsync(
|
||||
GetText(strs.acrophobia),
|
||||
GetText(strs.acro_vote_cast(Format.Bold(user))));
|
||||
}
|
||||
|
||||
private async Task Game_OnVotingStarted(AcrophobiaGame game, ImmutableArray<KeyValuePair<AcrophobiaUser, int>> submissions)
|
||||
{
|
||||
|
||||
@@ -11,9 +11,7 @@ public partial class Games
|
||||
private readonly DbService _db;
|
||||
|
||||
public ChatterBotCommands(DbService db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
=> _db = db;
|
||||
|
||||
[NoPublicBot]
|
||||
[NadekoCommand, Aliases]
|
||||
|
||||
@@ -15,9 +15,9 @@ public sealed class AcrophobiaGame : IDisposable
|
||||
|
||||
public void NormalizeOptions()
|
||||
{
|
||||
if (SubmissionTime < 15 || SubmissionTime > 300)
|
||||
if (SubmissionTime is < 15 or > 300)
|
||||
SubmissionTime = 60;
|
||||
if (VoteTime < 15 || VoteTime > 120)
|
||||
if (VoteTime is < 15 or > 120)
|
||||
VoteTime = 30;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,10 @@ public class AcrophobiaUser
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return UserId.GetHashCode();
|
||||
}
|
||||
=> UserId.GetHashCode();
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is AcrophobiaUser x
|
||||
=> obj is AcrophobiaUser x
|
||||
? x.UserId == this.UserId
|
||||
: false;
|
||||
}
|
||||
}
|
||||
@@ -88,8 +88,7 @@ public sealed class HangmanService : IHangmanService, ILateExecutor
|
||||
if (state.GuessResult == HangmanGame.GuessResult.NoAction)
|
||||
return;
|
||||
|
||||
if (state.GuessResult == HangmanGame.GuessResult.Incorrect
|
||||
|| state.GuessResult == HangmanGame.GuessResult.AlreadyTried)
|
||||
if (state.GuessResult is HangmanGame.GuessResult.Incorrect or HangmanGame.GuessResult.AlreadyTried)
|
||||
{
|
||||
_cdCache.Set(msg.Author.Id, string.Empty, new MemoryCacheEntryOptions()
|
||||
{
|
||||
|
||||
@@ -34,9 +34,7 @@ public sealed class NunchiGame : IDisposable
|
||||
private Timer _killTimer;
|
||||
|
||||
public NunchiGame(ulong creatorId, string creatorName)
|
||||
{
|
||||
_participants.Add((creatorId, creatorName));
|
||||
}
|
||||
=> _participants.Add((creatorId, creatorName));
|
||||
|
||||
public async Task<bool> Join(ulong userId, string userName)
|
||||
{
|
||||
|
||||
@@ -59,7 +59,5 @@ public class PollRunner
|
||||
}
|
||||
|
||||
public void End()
|
||||
{
|
||||
OnVoted = null;
|
||||
}
|
||||
=> OnVoted = null;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public class TicTacToe
|
||||
{
|
||||
public void NormalizeOptions()
|
||||
{
|
||||
if (TurnTimer < 5 || TurnTimer > 60)
|
||||
if (TurnTimer is < 5 or > 60)
|
||||
TurnTimer = 15;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class TicTacToe
|
||||
|
||||
public async Task Start(IGuildUser user)
|
||||
{
|
||||
if (_phase == Phase.Started || _phase == Phase.Ended)
|
||||
if (_phase is Phase.Started or Phase.Ended)
|
||||
{
|
||||
await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_already_running)).ConfigureAwait(false);
|
||||
return;
|
||||
|
||||
@@ -86,9 +86,7 @@ public class TriviaGame
|
||||
|
||||
questionMessage = await Channel.EmbedAsync(questionEmbed).ConfigureAwait(false);
|
||||
}
|
||||
catch (HttpException ex) when (ex.HttpCode == System.Net.HttpStatusCode.NotFound ||
|
||||
ex.HttpCode == System.Net.HttpStatusCode.Forbidden ||
|
||||
ex.HttpCode == System.Net.HttpStatusCode.BadRequest)
|
||||
catch (HttpException ex) when (ex.HttpCode is System.Net.HttpStatusCode.NotFound or System.Net.HttpStatusCode.Forbidden or System.Net.HttpStatusCode.BadRequest)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -116,7 +114,7 @@ public class TriviaGame
|
||||
await questionMessage.ModifyAsync(m => m.Embed = questionEmbed.WithFooter(CurrentQuestion.GetHint()).Build())
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (HttpException ex) when (ex.HttpCode == System.Net.HttpStatusCode.NotFound || ex.HttpCode == System.Net.HttpStatusCode.Forbidden)
|
||||
catch (HttpException ex) when (ex.HttpCode is System.Net.HttpStatusCode.NotFound or System.Net.HttpStatusCode.Forbidden)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ public class TriviaOptions : INadekoCommandOptions
|
||||
{
|
||||
if (WinRequirement < 0)
|
||||
WinRequirement = 10;
|
||||
if (QuestionTimer < 10 || QuestionTimer > 300)
|
||||
if (QuestionTimer is < 10 or > 300)
|
||||
QuestionTimer = 30;
|
||||
if (Timeout < 0 || Timeout > 20)
|
||||
if (Timeout is < 0 or > 20)
|
||||
Timeout = 10;
|
||||
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class TriviaQuestion
|
||||
str = Regex.Replace(str, "^\\s+", "");
|
||||
str = Regex.Replace(str, "\\s+$", "");
|
||||
//Trim the really long answers
|
||||
str = str.Length <= maxStringLength ? str : str.Substring(0, maxStringLength);
|
||||
str = str.Length <= maxStringLength ? str : str[..maxStringLength];
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public class TypingGame
|
||||
|
||||
public void NormalizeOptions()
|
||||
{
|
||||
if (StartTime < 3 || StartTime > 30)
|
||||
if (StartTime is < 3 or > 30)
|
||||
StartTime = 5;
|
||||
}
|
||||
}
|
||||
@@ -123,9 +123,7 @@ public class TypingGame
|
||||
}
|
||||
|
||||
private void HandleAnswers()
|
||||
{
|
||||
_client.MessageReceived += AnswerReceived;
|
||||
}
|
||||
=> _client.MessageReceived += AnswerReceived;
|
||||
|
||||
private Task AnswerReceived(SocketMessage imsg)
|
||||
{
|
||||
|
||||
@@ -76,9 +76,7 @@ public partial class Games : NadekoModule<GamesService>
|
||||
}
|
||||
|
||||
private double NextDouble(double x, double y)
|
||||
{
|
||||
return (_rng.NextDouble() * (y - x)) + x;
|
||||
}
|
||||
=> (_rng.NextDouble() * (y - x)) + x;
|
||||
|
||||
private GirlRating GetGirl(ulong uid)
|
||||
{
|
||||
@@ -139,13 +137,11 @@ public partial class Games : NadekoModule<GamesService>
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
public async Task Linux(string guhnoo, string loonix)
|
||||
{
|
||||
await SendConfirmAsync(
|
||||
=> await SendConfirmAsync(
|
||||
$@"I'd just like to interject for moment. What you're refering to as {loonix}, is in fact, {guhnoo}/{loonix}, or as I've recently taken to calling it, {guhnoo} plus {loonix}. {loonix} is not an operating system unto itself, but rather another free component of a fully functioning {guhnoo} system made useful by the {guhnoo} corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX.
|
||||
|
||||
Many computer users run a modified version of the {guhnoo} system every day, without realizing it. Through a peculiar turn of events, the version of {guhnoo} which is widely used today is often called {loonix}, and many of its users are not aware that it is basically the {guhnoo} system, developed by the {guhnoo} Project.
|
||||
|
||||
There really is a {loonix}, and these people are using it, but it is just a part of the system they use. {loonix} is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. {loonix} is normally used in combination with the {guhnoo} operating system: the whole system is basically {guhnoo} with {loonix} added, or {guhnoo}/{loonix}. All the so-called {loonix} distributions are really distributions of {guhnoo}/{loonix}."
|
||||
).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -11,22 +11,18 @@ public partial class Games
|
||||
[NadekoCommand, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Hangmanlist()
|
||||
{
|
||||
await SendConfirmAsync(
|
||||
=> await SendConfirmAsync(
|
||||
GetText(strs.hangman_types(Prefix)),
|
||||
_service.GetHangmanTypes().JoinWith('\n'));
|
||||
}
|
||||
_service.GetHangmanTypes().Join('\n'));
|
||||
|
||||
private static string Draw(HangmanGame.State state)
|
||||
{
|
||||
return $@". ┌─────┐
|
||||
=> $@". ┌─────┐
|
||||
.┃...............┋
|
||||
.┃...............┋
|
||||
.┃{(state.Errors > 0 ? ".............😲" : "")}
|
||||
.┃{(state.Errors > 1 ? "............./" : "")} {(state.Errors > 2 ? "|" : "")} {(state.Errors > 3 ? "\\" : "")}
|
||||
.┃{(state.Errors > 4 ? "............../" : "")} {(state.Errors > 5 ? "\\" : "")}
|
||||
/-\";
|
||||
}
|
||||
|
||||
public static IEmbedBuilder GetEmbed(IEmbedBuilderService eb, HangmanGame.State state)
|
||||
{
|
||||
@@ -35,21 +31,21 @@ public partial class Games
|
||||
.WithOkColor()
|
||||
.AddField("Hangman", Draw(state))
|
||||
.AddField("Guess", Format.Code(state.Word))
|
||||
.WithFooter(state.missedLetters.JoinWith(' '));
|
||||
.WithFooter(state.missedLetters.Join(' '));
|
||||
|
||||
if (state.Phase == HangmanGame.Phase.Ended && state.Failed)
|
||||
return eb.Create()
|
||||
.WithErrorColor()
|
||||
.AddField("Hangman", Draw(state))
|
||||
.AddField("Guess", Format.Code(state.Word))
|
||||
.WithFooter(state.missedLetters.JoinWith(' '));
|
||||
.WithFooter(state.missedLetters.Join(' '));
|
||||
else
|
||||
{
|
||||
return eb.Create()
|
||||
.WithOkColor()
|
||||
.AddField("Hangman", Draw(state))
|
||||
.AddField("Guess", Format.Code(state.Word))
|
||||
.WithFooter(state.missedLetters.JoinWith(' '));
|
||||
.WithFooter(state.missedLetters.Join(' '));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,7 @@ public partial class Games
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public NunchiCommands(DiscordSocketClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
=> _client = client;
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
@@ -91,16 +89,12 @@ public partial class Games
|
||||
}
|
||||
|
||||
private Task Nunchi_OnRoundStarted(NunchiGame arg, int cur)
|
||||
{
|
||||
return ConfirmLocalizedAsync(strs.nunchi_round_started(
|
||||
=> ConfirmLocalizedAsync(strs.nunchi_round_started(
|
||||
Format.Bold(arg.ParticipantCount.ToString()),
|
||||
Format.Bold(cur.ToString())));
|
||||
}
|
||||
|
||||
private Task Nunchi_OnUserGuessed(NunchiGame arg)
|
||||
{
|
||||
return ConfirmLocalizedAsync(strs.nunchi_next_number(Format.Bold(arg.CurrentNumber.ToString())));
|
||||
}
|
||||
=> ConfirmLocalizedAsync(strs.nunchi_next_number(Format.Bold(arg.CurrentNumber.ToString())));
|
||||
|
||||
private Task Nunchi_OnRoundEnded(NunchiGame arg1, (ulong Id, string Name)? arg2)
|
||||
{
|
||||
@@ -112,8 +106,6 @@ public partial class Games
|
||||
}
|
||||
|
||||
private Task Nunchi_OnGameStarted(NunchiGame arg)
|
||||
{
|
||||
return ConfirmLocalizedAsync(strs.nunchi_started(Format.Bold(arg.ParticipantCount.ToString())));
|
||||
}
|
||||
=> ConfirmLocalizedAsync(strs.nunchi_started(Format.Bold(arg.ParticipantCount.ToString())));
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,7 @@ public partial class Games
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public PollCommands(DiscordSocketClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
=> _client = client;
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[UserPerm(GuildPerm.ManageMessages)]
|
||||
|
||||
@@ -64,11 +64,11 @@ public class ChatterBotService : IEarlyBehavior
|
||||
string message;
|
||||
if (msg.Content.StartsWith(normalMention, StringComparison.InvariantCulture))
|
||||
{
|
||||
message = msg.Content.Substring(normalMention.Length).Trim();
|
||||
message = msg.Content[normalMention.Length..].Trim();
|
||||
}
|
||||
else if (msg.Content.StartsWith(nickMention, StringComparison.InvariantCulture))
|
||||
{
|
||||
message = msg.Content.Substring(nickMention.Length).Trim();
|
||||
message = msg.Content[nickMention.Length..].Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -94,14 +94,12 @@ public class GamesService : INService
|
||||
}
|
||||
|
||||
public string GetEightballResponse(ulong userId, string question)
|
||||
{
|
||||
return _8BallCache.GetOrCreate($"8ball:{userId}:{question}", e =>
|
||||
=> _8BallCache.GetOrCreate($"8ball:{userId}:{question}", e =>
|
||||
{
|
||||
e.Size = question.Length;
|
||||
e.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(12);
|
||||
return EightBallResponses[_rng.Next(0, EightBallResponses.Count)];;
|
||||
});
|
||||
}
|
||||
|
||||
public TypingArticle RemoveTypingArticle(int index)
|
||||
{
|
||||
|
||||
@@ -12,9 +12,7 @@ public partial class Games
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public TicTacToeCommands(DiscordSocketClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
=> _client = client;
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
|
||||
@@ -82,6 +82,7 @@ public class Help : NadekoModule<HelpService>
|
||||
|
||||
localModules
|
||||
.OrderBy(module => module.Name)
|
||||
.ToList()
|
||||
.ForEach(module => embed.AddField($"{GetModuleEmoji(module.Name)} {module.Name}",
|
||||
GetText(GetModuleLocStr(module.Name)) + "\n" +
|
||||
Format.Code(GetText(strs.module_footer(Prefix, module.Name.ToLowerInvariant()))),
|
||||
@@ -406,17 +407,13 @@ public class Help : NadekoModule<HelpService>
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
public async Task Guide()
|
||||
{
|
||||
await ConfirmLocalizedAsync(strs.guide(
|
||||
=> await ConfirmLocalizedAsync(strs.guide(
|
||||
"https://nadeko.bot/commands",
|
||||
"http://nadekobot.readthedocs.io/en/latest/"));
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
public async Task Donate()
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.donate(PatreonUrl, PaypalUrl));
|
||||
}
|
||||
=> await ReplyConfirmLocalizedAsync(strs.donate(PatreonUrl, PaypalUrl));
|
||||
}
|
||||
|
||||
internal class CommandJsonObject
|
||||
|
||||
@@ -154,16 +154,12 @@ public class HelpService : ILateExecutor, INService
|
||||
}
|
||||
|
||||
public static string GetPreconditionString(ChannelPerm perm)
|
||||
{
|
||||
return (perm.ToString() + " Channel Permission")
|
||||
=> (perm.ToString() + " Channel Permission")
|
||||
.Replace("Guild", "Server", StringComparison.InvariantCulture);
|
||||
}
|
||||
|
||||
public static string GetPreconditionString(GuildPerm perm)
|
||||
{
|
||||
return (perm.ToString() + " Server Permission")
|
||||
=> (perm.ToString() + " Server Permission")
|
||||
.Replace("Guild", "Server", StringComparison.InvariantCulture);
|
||||
}
|
||||
|
||||
private string GetText(LocStr str, IGuild guild, params object[] replacements) =>
|
||||
_strings.GetText(str, guild?.Id);
|
||||
|
||||
@@ -77,9 +77,7 @@ public sealed class MultimediaTimer : IDisposable
|
||||
}
|
||||
|
||||
private void CallbackInternal(uint uTimerId, uint uMsg, int dwUser, int dw1, int dw2)
|
||||
{
|
||||
_callback(_state);
|
||||
}
|
||||
=> _callback(_state);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
@@ -424,29 +424,19 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
}
|
||||
|
||||
public void EnqueueTrack(ITrackInfo track, string queuer)
|
||||
{
|
||||
_queue.Enqueue(track, queuer, out _);
|
||||
}
|
||||
=> _queue.Enqueue(track, queuer, out _);
|
||||
|
||||
public void EnqueueTracks(IEnumerable<ITrackInfo> tracks, string queuer)
|
||||
{
|
||||
_queue.EnqueueMany(tracks, queuer);
|
||||
}
|
||||
=> _queue.EnqueueMany(tracks, queuer);
|
||||
|
||||
public void SetRepeat(PlayerRepeatType type)
|
||||
{
|
||||
Repeat = type;
|
||||
}
|
||||
=> Repeat = type;
|
||||
|
||||
public void ShuffleQueue()
|
||||
{
|
||||
_queue.Shuffle(_rng);
|
||||
}
|
||||
=> _queue.Shuffle(_rng);
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
IsStopped = true;
|
||||
}
|
||||
=> IsStopped = true;
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
@@ -484,7 +474,7 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
public void SetVolume(int newVolume)
|
||||
{
|
||||
var normalizedVolume = newVolume / 100f;
|
||||
if (normalizedVolume < 0f || normalizedVolume > 1f)
|
||||
if (normalizedVolume is < 0f or > 1f)
|
||||
throw new ArgumentOutOfRangeException(nameof(newVolume), "Volume must be in range 0-100");
|
||||
|
||||
_volume = normalizedVolume;
|
||||
|
||||
@@ -10,10 +10,8 @@ public sealed class RedisTrackCacher : ITrackCacher
|
||||
private readonly ConnectionMultiplexer _multiplexer;
|
||||
|
||||
public RedisTrackCacher(ConnectionMultiplexer multiplexer)
|
||||
{
|
||||
_multiplexer = multiplexer;
|
||||
}
|
||||
|
||||
=> _multiplexer = multiplexer;
|
||||
|
||||
public async Task<string?> GetOrCreateStreamLink(
|
||||
string id,
|
||||
MusicPlatform platform,
|
||||
|
||||
@@ -27,9 +27,7 @@ public sealed class VoiceProxy : IVoiceProxy
|
||||
private VoiceGateway _gateway;
|
||||
|
||||
public VoiceProxy(VoiceGateway initial)
|
||||
{
|
||||
_gateway = initial;
|
||||
}
|
||||
=> _gateway = initial;
|
||||
|
||||
public bool SendPcmFrame(VoiceClient vc, Span<byte> data, int length)
|
||||
{
|
||||
@@ -86,24 +84,16 @@ public sealed class VoiceProxy : IVoiceProxy
|
||||
}
|
||||
|
||||
public void SetGateway(VoiceGateway gateway)
|
||||
{
|
||||
_gateway = gateway;
|
||||
}
|
||||
=> _gateway = gateway;
|
||||
|
||||
public Task StartSpeakingAsync()
|
||||
{
|
||||
return RunGatewayAction(gw => gw.SendSpeakingAsync(VoiceSpeaking.State.Microphone));
|
||||
}
|
||||
=> RunGatewayAction(gw => gw.SendSpeakingAsync(VoiceSpeaking.State.Microphone));
|
||||
|
||||
public Task StopSpeakingAsync()
|
||||
{
|
||||
return RunGatewayAction(gw => gw.SendSpeakingAsync(VoiceSpeaking.State.None));
|
||||
}
|
||||
=> RunGatewayAction(gw => gw.SendSpeakingAsync(VoiceSpeaking.State.None));
|
||||
|
||||
public async Task StartGateway()
|
||||
{
|
||||
await _gateway.Start();
|
||||
}
|
||||
=> await _gateway.Start();
|
||||
|
||||
public Task StopGateway()
|
||||
{
|
||||
|
||||
@@ -11,10 +11,8 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
private readonly ILogCommandService _logService;
|
||||
|
||||
public Music(ILogCommandService _logService)
|
||||
{
|
||||
this._logService = _logService;
|
||||
}
|
||||
|
||||
=> this._logService = _logService;
|
||||
|
||||
private async Task<bool> ValidateAsync()
|
||||
{
|
||||
var user = (IGuildUser) ctx.User;
|
||||
@@ -209,7 +207,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Volume(int vol)
|
||||
{
|
||||
if (vol < 0 || vol > 100)
|
||||
if (vol is < 0 or > 100)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.volume_input_invalid);
|
||||
return;
|
||||
@@ -313,7 +311,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
|
||||
return $"`{index + 1}.` {v.PrettyFullName()}";
|
||||
})
|
||||
.JoinWith('\n');
|
||||
.Join('\n');
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(add))
|
||||
desc = add + "\n" + desc;
|
||||
@@ -353,7 +351,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
|
||||
var resultsString = videos
|
||||
.Select((x, i) => $"`{i + 1}.`\n\t{Format.Bold(x.Title)}\n\t{x.Url}")
|
||||
.JoinWith('\n');
|
||||
.Join('\n');
|
||||
|
||||
var msg = await SendConfirmAsync(resultsString);
|
||||
|
||||
|
||||
@@ -44,10 +44,8 @@ public sealed class AyuVoiceStateService : INService
|
||||
}
|
||||
|
||||
private Task InvokeSendVoiceStateUpdateAsync(ulong guildId, ulong? channelId = null, bool isDeafened = false, bool isMuted = false)
|
||||
{
|
||||
// return _voiceStateUpdate(guildId, channelId, isDeafened, isMuted);
|
||||
return (Task) _sendVoiceStateUpdateMethodInfo.Invoke(_dnetApiClient, new object[] {guildId, channelId, isMuted, isDeafened, null});
|
||||
}
|
||||
=> (Task) _sendVoiceStateUpdateMethodInfo.Invoke(_dnetApiClient, new object[] {guildId, channelId, isMuted, isDeafened, null});
|
||||
|
||||
private Task SendLeaveVoiceChannelInternalAsync(ulong guildId)
|
||||
=> InvokeSendVoiceStateUpdateAsync(guildId);
|
||||
|
||||
@@ -407,7 +407,7 @@ public sealed class MusicService : IMusicService
|
||||
|
||||
public async Task SetVolumeAsync(ulong guildId, int value)
|
||||
{
|
||||
if (value < 0 || value > 100)
|
||||
if (value is < 0 or > 100)
|
||||
throw new ArgumentOutOfRangeException(nameof(value));
|
||||
|
||||
await ModifySettingsInternalAsync(guildId, (settings, newValue) =>
|
||||
@@ -438,12 +438,10 @@ public sealed class MusicService : IMusicService
|
||||
}
|
||||
|
||||
public Task SetMusicQualityAsync(ulong guildId, QualityPreset preset)
|
||||
{
|
||||
return ModifySettingsInternalAsync(guildId, (settings, _) =>
|
||||
=> ModifySettingsInternalAsync(guildId, (settings, _) =>
|
||||
{
|
||||
settings.QualityPreset = preset;
|
||||
}, preset);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -16,9 +16,7 @@ public sealed partial class YtLoader
|
||||
};
|
||||
|
||||
public YtLoader(IHttpClientFactory httpFactory)
|
||||
{
|
||||
_httpFactory = httpFactory;
|
||||
}
|
||||
=> _httpFactory = httpFactory;
|
||||
|
||||
// public async Task<TrackInfo> LoadTrackByIdAsync(string videoId)
|
||||
// {
|
||||
@@ -115,13 +113,13 @@ public sealed partial class YtLoader
|
||||
|
||||
private Memory<byte> GetScriptResponseSpan(byte[] response)
|
||||
{
|
||||
var responseSpan = response.AsSpan().Slice(140_000);
|
||||
var responseSpan = response.AsSpan()[140_000..];
|
||||
var startIndex = responseSpan.IndexOf(YT_RESULT_INITIAL_DATA);
|
||||
if (startIndex == -1)
|
||||
return null; // todo future try selecting html
|
||||
startIndex += YT_RESULT_INITIAL_DATA.Length;
|
||||
|
||||
var endIndex = 140_000 + startIndex + responseSpan.Slice(startIndex + 20_000).IndexOf(YT_RESULT_JSON_END) + 20_000;
|
||||
var endIndex = 140_000 + startIndex + responseSpan[(startIndex + 20_000)..].IndexOf(YT_RESULT_JSON_END) + 20_000;
|
||||
startIndex += 140_000;
|
||||
return response.AsMemory(
|
||||
startIndex,
|
||||
|
||||
@@ -8,7 +8,5 @@ public readonly struct DapiTag
|
||||
|
||||
[JsonConstructor]
|
||||
public DapiTag(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
=> Name = name;
|
||||
}
|
||||
@@ -7,9 +7,7 @@ public abstract class DapiImageDownloader : ImageDownloader<DapiImageObject>
|
||||
protected readonly string _baseUrl;
|
||||
|
||||
public DapiImageDownloader(Booru booru, HttpClient http, string baseUrl) : base(booru, http)
|
||||
{
|
||||
_baseUrl = baseUrl;
|
||||
}
|
||||
=> _baseUrl = baseUrl;
|
||||
|
||||
public abstract Task<bool> IsTagValid(string tag, CancellationToken cancel = default);
|
||||
protected async Task<bool> AllTagsValid(string[] tags, CancellationToken cancel = default)
|
||||
|
||||
@@ -8,9 +8,7 @@ public sealed class KonachanImageDownloader : ImageDownloader<DapiImageObject>
|
||||
|
||||
public KonachanImageDownloader(HttpClient http)
|
||||
: base(Booru.Konachan, http)
|
||||
{
|
||||
_baseUrl = "https://konachan.com";
|
||||
}
|
||||
=> _baseUrl = "https://konachan.com";
|
||||
|
||||
public override async Task<List<DapiImageObject>> DownloadImagesAsync(string[] tags, int page, bool isExplicit = false, CancellationToken cancel = default)
|
||||
{
|
||||
|
||||
@@ -8,9 +8,8 @@ public sealed class YandereImageDownloader : ImageDownloader<DapiImageObject>
|
||||
|
||||
public YandereImageDownloader(HttpClient http)
|
||||
: base(Booru.Yandere, http)
|
||||
{
|
||||
_baseUrl = "https://yande.re";
|
||||
}
|
||||
=> _baseUrl = "https://yande.re";
|
||||
|
||||
public override async Task<List<DapiImageObject>> DownloadImagesAsync(string[] tags, int page, bool isExplicit = false, CancellationToken cancel = default)
|
||||
{
|
||||
var tagString = ImageDownloaderHelper.GetTagString(tags, isExplicit);
|
||||
|
||||
@@ -25,9 +25,7 @@ public class ImageData : IComparable<ImageData>
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return FileUrl;
|
||||
}
|
||||
=> FileUrl;
|
||||
|
||||
public override int GetHashCode() => FileUrl.GetHashCode();
|
||||
public override bool Equals(object obj)
|
||||
|
||||
@@ -8,11 +8,9 @@ public class Rule34Object : IImageData
|
||||
public int Score { get; init; }
|
||||
|
||||
public ImageData ToCachedImageData(Booru type)
|
||||
{
|
||||
return new(
|
||||
=> new(
|
||||
$"https://img.rule34.xxx//images/{Directory}/{Image}",
|
||||
Booru.Rule34,
|
||||
Tags.Split(' '),
|
||||
Score.ToString());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Modules.Searches.Common;
|
||||
using NadekoBot.Modules.Searches.Common;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace NadekoBot.Modules.Nsfw;
|
||||
@@ -377,7 +376,7 @@ public class NSFW : NadekoModule<ISearchImagesService>
|
||||
.Shuffle()
|
||||
.Select(tag => $"[{tag.Name}]({tag.Url})")
|
||||
.TakeWhile(tag => (count += tag.Length) < 1000)
|
||||
.JoinWith(" ");
|
||||
.Join(" ");
|
||||
|
||||
var embed = _eb.Create()
|
||||
.WithTitle(g.Title)
|
||||
|
||||
@@ -68,6 +68,7 @@ public class SearchImageCacher : INService
|
||||
.Distinct()
|
||||
.Shuffle()
|
||||
.Take(50)
|
||||
.ToList()
|
||||
.ForEach(x => typeUsedTags.Add(x));
|
||||
|
||||
foreach (var img in images)
|
||||
|
||||
@@ -53,9 +53,7 @@ public class SearchImagesService : ISearchImagesService, INService
|
||||
}
|
||||
|
||||
private Task<UrlReply> GetNsfwImageAsync(ulong? guildId, bool forceExplicit, string[] tags, Booru dapi, CancellationToken cancel = default)
|
||||
{
|
||||
return GetNsfwImageAsync(guildId ?? 0, tags ?? Array.Empty<string>(), forceExplicit, dapi, cancel);
|
||||
}
|
||||
=> GetNsfwImageAsync(guildId ?? 0, tags ?? Array.Empty<string>(), forceExplicit, dapi, cancel);
|
||||
|
||||
private bool IsValidTag(string tag) => tag.All(x => x != '+' && x != '?' && x != '/'); // tags mustn't contain + or ? or /
|
||||
|
||||
|
||||
@@ -12,10 +12,8 @@ public partial class Permissions
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public BlacklistCommands(DiscordSocketClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
=> _client = client;
|
||||
|
||||
private async Task ListBlacklistInternal(string title, BlacklistType type, int page = 0)
|
||||
{
|
||||
if (page < 0)
|
||||
@@ -65,7 +63,7 @@ public partial class Permissions
|
||||
|
||||
return _eb.Create()
|
||||
.WithTitle(title)
|
||||
.WithDescription(pageItems.JoinWith('\n'))
|
||||
.WithDescription(pageItems.Join('\n'))
|
||||
.WithOkColor();
|
||||
}, items.Length, 10);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Common.TypeReaders;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Modules.Permissions.Services;
|
||||
@@ -31,7 +30,7 @@ public partial class Permissions
|
||||
public async Task CmdCooldown(CommandOrCrInfo command, int secs)
|
||||
{
|
||||
var channel = (ITextChannel)ctx.Channel;
|
||||
if (secs < 0 || secs > 3600)
|
||||
if (secs is < 0 or > 3600)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.invalid_second_param_between(0, 3600));
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Modules.Permissions.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Db;
|
||||
@@ -14,9 +13,7 @@ public partial class Permissions
|
||||
private readonly DbService _db;
|
||||
|
||||
public FilterCommands(DbService db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
=> _db = db;
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
|
||||
@@ -12,9 +12,7 @@ public partial class Permissions : NadekoModule<PermissionService>
|
||||
private readonly DbService _db;
|
||||
|
||||
public Permissions(DbService db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
=> _db = db;
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
@@ -203,7 +201,7 @@ public partial class Permissions : NadekoModule<PermissionService>
|
||||
|
||||
return;
|
||||
}
|
||||
catch (Exception e) when (e is ArgumentOutOfRangeException || e is IndexOutOfRangeException)
|
||||
catch (Exception e) when (e is ArgumentOutOfRangeException or IndexOutOfRangeException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Permissions.Services;
|
||||
@@ -12,11 +11,9 @@ public class CmdCdService : ILateBlocker, INService
|
||||
public int Priority { get; } = 0;
|
||||
|
||||
public CmdCdService(Bot bot)
|
||||
{
|
||||
CommandCooldowns = new(
|
||||
=> CommandCooldowns = new(
|
||||
bot.AllGuildConfigs.ToDictionary(k => k.GuildId,
|
||||
v => new ConcurrentHashSet<CommandCooldown>(v.CommandCooldowns)));
|
||||
}
|
||||
|
||||
public Task<bool> TryBlock(IGuild guild, IUser user, string commandName)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Db;
|
||||
|
||||
@@ -11,9 +11,7 @@ public class GlobalPermissionService : ILateBlocker, INService
|
||||
public HashSet<string> BlockedModules => _bss.Data.Blocked.Modules;
|
||||
|
||||
public GlobalPermissionService(BotConfigService bss)
|
||||
{
|
||||
_bss = bss;
|
||||
}
|
||||
=> _bss = bss;
|
||||
|
||||
|
||||
public Task<bool> TryBlockLate(ICommandContext ctx, string moduleName, CommandInfo command)
|
||||
|
||||
@@ -75,8 +75,7 @@ public class PermissionService : ILateBlocker, INService
|
||||
}
|
||||
|
||||
public void UpdateCache(GuildConfig config)
|
||||
{
|
||||
Cache.AddOrUpdate(config.GuildId, new PermissionCache()
|
||||
=> Cache.AddOrUpdate(config.GuildId, new PermissionCache()
|
||||
{
|
||||
Permissions = new(config.Permissions),
|
||||
PermRole = config.PermissionRole,
|
||||
@@ -88,7 +87,6 @@ public class PermissionService : ILateBlocker, INService
|
||||
old.Verbose = config.VerbosePermissions;
|
||||
return old;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<bool> TryBlockLate(ICommandContext ctx, string moduleName, CommandInfo command)
|
||||
{
|
||||
|
||||
@@ -20,5 +20,5 @@ public class AnimeResult
|
||||
public string AverageScore { get; set; }
|
||||
|
||||
public string Link => "http://anilist.co/anime/" + Id;
|
||||
public string Synopsis => Description?.Substring(0, Description.Length > 500 ? 500 : Description.Length) + "...";
|
||||
public string Synopsis => Description?[..(Description.Length > 500 ? 500 : Description.Length)] + "...";
|
||||
}
|
||||
@@ -33,12 +33,8 @@ public class ImageCacherObject : IComparable<ImageCacherObject>
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return FileUrl;
|
||||
}
|
||||
=> FileUrl;
|
||||
|
||||
public int CompareTo(ImageCacherObject other)
|
||||
{
|
||||
return string.Compare(FileUrl, other.FileUrl, StringComparison.InvariantCulture);
|
||||
}
|
||||
=> string.Compare(FileUrl, other.FileUrl, StringComparison.InvariantCulture);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user