mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
vars and target-typed new
This commit is contained in:
@@ -89,7 +89,7 @@ public class IndexedCollection<T> : IList<T> where T : class, IIndexed
|
||||
{
|
||||
if (removed = Source.Remove(item))
|
||||
{
|
||||
for (int i = 0; i < Source.Count; i++)
|
||||
for (var i = 0; i < Source.Count; i++)
|
||||
{
|
||||
if (Source[i].Index != i)
|
||||
Source[i].Index = i;
|
||||
@@ -104,7 +104,7 @@ public class IndexedCollection<T> : IList<T> where T : class, IIndexed
|
||||
lock (_locker)
|
||||
{
|
||||
Source.Insert(index, item);
|
||||
for (int i = index; i < Source.Count; i++)
|
||||
for (var i = index; i < Source.Count; i++)
|
||||
{
|
||||
Source[i].Index = i;
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class IndexedCollection<T> : IList<T> where T : class, IIndexed
|
||||
lock (_locker)
|
||||
{
|
||||
Source.RemoveAt(index);
|
||||
for (int i = index; i < Source.Count; i++)
|
||||
for (var i = index; i < Source.Count; i++)
|
||||
{
|
||||
Source[i].Index = i;
|
||||
}
|
||||
|
@@ -69,7 +69,7 @@ public class ReplacementBuilder
|
||||
_reps.TryAdd("%members%", () => g != null && g is SocketGuild sg ? sg.MemberCount.ToString() : "?");
|
||||
_reps.TryAdd("%server_time%", () =>
|
||||
{
|
||||
TimeZoneInfo to = TimeZoneInfo.Local;
|
||||
var to = TimeZoneInfo.Local;
|
||||
if (g != null)
|
||||
{
|
||||
if (GuildTimezoneService.AllServices.TryGetValue(client.CurrentUser.Id, out var tz))
|
||||
@@ -88,7 +88,7 @@ public class ReplacementBuilder
|
||||
_reps.TryAdd("%server.boost_level%", () => ((int)g.PremiumTier).ToString());
|
||||
_reps.TryAdd("%server.time%", () =>
|
||||
{
|
||||
TimeZoneInfo to = TimeZoneInfo.Local;
|
||||
var to = TimeZoneInfo.Local;
|
||||
if (g != null)
|
||||
{
|
||||
if (GuildTimezoneService.AllServices.TryGetValue(client.CurrentUser.Id, out var tz))
|
||||
|
@@ -22,7 +22,7 @@ public class StoopidTime
|
||||
throw new ArgumentException("Invalid string input format.");
|
||||
}
|
||||
|
||||
string output = "";
|
||||
var output = string.Empty;
|
||||
var namesAndValues = new Dictionary<string, int>();
|
||||
|
||||
foreach (var groupName in _regex.GetGroupNames())
|
||||
|
@@ -14,10 +14,10 @@ public class MultilineScalarFlowStyleEmitter : ChainedEventEmitter
|
||||
|
||||
if (typeof(string).IsAssignableFrom(eventInfo.Source.Type))
|
||||
{
|
||||
string value = eventInfo.Source.Value as string;
|
||||
var value = eventInfo.Source.Value as string;
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
bool isMultiLine = value.IndexOfAny(new char[] { '\r', '\n', '\x85', '\x2028', '\x2029' }) >= 0;
|
||||
var isMultiLine = value.IndexOfAny(new char[] { '\r', '\n', '\x85', '\x2028', '\x2029' }) >= 0;
|
||||
if (isMultiLine)
|
||||
eventInfo = new ScalarEventInfo(eventInfo.Source)
|
||||
{
|
||||
|
@@ -9,7 +9,7 @@ public class ClubInfo : DbEntity
|
||||
public string Name { get; set; }
|
||||
public int Discrim { get; set; }
|
||||
|
||||
public string ImageUrl { get; set; } = "";
|
||||
public string ImageUrl { get; set; } = string.Empty;
|
||||
public int MinimumLevelReq { get; set; } = 5;
|
||||
public int Xp { get; set; } = 0;
|
||||
|
||||
|
@@ -20,7 +20,7 @@ public class WaifuInfo : DbEntity
|
||||
public override string ToString()
|
||||
{
|
||||
var claimer = "no one";
|
||||
var status = "";
|
||||
var status = string.Empty;
|
||||
|
||||
var waifuUsername = Waifu.Username.TrimTo(20);
|
||||
var claimerUsername = Claimer?.Username.TrimTo(20);
|
||||
@@ -61,7 +61,7 @@ public class WaifuLbResult
|
||||
public override string ToString()
|
||||
{
|
||||
var claimer = "no one";
|
||||
var status = "";
|
||||
var status = string.Empty;
|
||||
|
||||
var waifuUsername = Username.TrimTo(20);
|
||||
var claimerUsername = Claimer?.TrimTo(20);
|
||||
|
@@ -14,7 +14,7 @@ public class NadekoContextFactory : IDesignTimeDbContextFactory<NadekoContext>
|
||||
{
|
||||
LogSetup.SetupLogger(-2);
|
||||
var optionsBuilder = new DbContextOptionsBuilder<NadekoContext>();
|
||||
IBotCredentials creds = new BotCredsProvider().GetCreds();
|
||||
var creds = new BotCredsProvider().GetCreds();
|
||||
var builder = new SqliteConnectionStringBuilder(creds.Db.ConnectionString);
|
||||
builder.DataSource = Path.Combine(AppContext.BaseDirectory, builder.DataSource);
|
||||
optionsBuilder.UseSqlite(builder.ToString());
|
||||
|
@@ -261,7 +261,7 @@ public partial class Administration
|
||||
if (string.IsNullOrWhiteSpace(ignoredString))
|
||||
ignoredString = "none";
|
||||
|
||||
string add = "";
|
||||
var add = string.Empty;
|
||||
if (settings.MuteTime > 0)
|
||||
{
|
||||
add = $" ({TimeSpan.FromMinutes(settings.MuteTime):hh\\hmm\\m})";
|
||||
|
@@ -92,7 +92,7 @@ public partial class Administration
|
||||
if (ctx.User.Id != guser.Guild.OwnerId && guser.GetRoles().Max(x => x.Position) <= role.Position)
|
||||
return;
|
||||
|
||||
bool success = _service.RemoveSar(role.Guild.Id, role.Id);
|
||||
var success = _service.RemoveSar(role.Guild.Id, role.Id);
|
||||
if (!success)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.self_assign_not).ConfigureAwait(false);
|
||||
@@ -124,7 +124,7 @@ public partial class Administration
|
||||
|
||||
foreach (var kvp in roleGroups)
|
||||
{
|
||||
var groupNameText = "";
|
||||
var groupNameText = string.Empty;
|
||||
if (!groups.TryGetValue(kvp.Key, out var name))
|
||||
{
|
||||
groupNameText = Format.Bold(GetText(strs.self_assign_group(kvp.Key)));
|
||||
@@ -168,7 +168,7 @@ public partial class Administration
|
||||
[BotPerm(GuildPerm.ManageRoles)]
|
||||
public async Task Togglexclsar()
|
||||
{
|
||||
bool areExclusive = _service.ToggleEsar(ctx.Guild.Id);
|
||||
var areExclusive = _service.ToggleEsar(ctx.Guild.Id);
|
||||
if (areExclusive)
|
||||
await ReplyConfirmLocalizedAsync(strs.self_assign_excl).ConfigureAwait(false);
|
||||
else
|
||||
@@ -184,7 +184,7 @@ public partial class Administration
|
||||
if (level < 0)
|
||||
return;
|
||||
|
||||
bool succ = _service.SetLevelReq(ctx.Guild.Id, role, level);
|
||||
var succ = _service.SetLevelReq(ctx.Guild.Id, role, level);
|
||||
|
||||
if (!succ)
|
||||
{
|
||||
|
@@ -332,7 +332,7 @@ public partial class Administration
|
||||
[OwnerOnly]
|
||||
public async Task Restart()
|
||||
{
|
||||
bool success = _coord.RestartBot();
|
||||
var success = _coord.RestartBot();
|
||||
if (!success)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.restart_fail).ConfigureAwait(false);
|
||||
|
@@ -73,7 +73,7 @@ DELETE FROM Clubs;";
|
||||
{
|
||||
if (reader.HasRows)
|
||||
{
|
||||
for (int i = 0; i < reader.FieldCount; i++)
|
||||
for (var i = 0; i < reader.FieldCount; i++)
|
||||
{
|
||||
result.ColumnNames.Add(reader.GetName(i));
|
||||
}
|
||||
|
@@ -153,7 +153,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
|
||||
public LogSetting GetGuildLogSettings(ulong guildId)
|
||||
{
|
||||
GuildLogSettings.TryGetValue(guildId, out LogSetting logSetting);
|
||||
GuildLogSettings.TryGetValue(guildId, out var logSetting);
|
||||
return logSetting;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
|
||||
public bool LogIgnore(ulong gid, ulong itemId, IgnoredItemType itemType)
|
||||
{
|
||||
int removed = 0;
|
||||
var removed = 0;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var logSetting = uow.LogSettingsFor(gid);
|
||||
@@ -197,7 +197,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
|
||||
private string CurrentTime(IGuild g)
|
||||
{
|
||||
DateTime time = DateTime.UtcNow;
|
||||
var time = DateTime.UtcNow;
|
||||
if (g != null)
|
||||
time = TimeZoneInfo.ConvertTime(time, _tz.GetTimeZoneOrUtc(g.Id));
|
||||
|
||||
@@ -243,7 +243,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
|
||||
var g = after.Guild;
|
||||
|
||||
if (!GuildLogSettings.TryGetValue(g.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(g.Id, out var logSetting)
|
||||
|| (logSetting.UserUpdatedId is null))
|
||||
return;
|
||||
|
||||
@@ -375,7 +375,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
if (beforeVch == afterVch)
|
||||
return;
|
||||
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting)
|
||||
|| (logSetting.LogVoicePresenceTTSId is null))
|
||||
return;
|
||||
|
||||
@@ -384,7 +384,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
.ConfigureAwait(false)) is null)
|
||||
return;
|
||||
|
||||
var str = "";
|
||||
var str = string.Empty;
|
||||
if (beforeVch?.Guild == afterVch?.Guild)
|
||||
{
|
||||
str = GetText(logChannel.Guild, strs.log_vc_moved(usr.Username, beforeVch?.Name, afterVch?.Name));
|
||||
@@ -415,7 +415,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting)
|
||||
|| (logSetting.UserMutedId is null))
|
||||
return;
|
||||
|
||||
@@ -423,7 +423,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)
|
||||
.ConfigureAwait(false)) is null)
|
||||
return;
|
||||
var mutes = "";
|
||||
var mutes = string.Empty;
|
||||
var mutedLocalized = GetText(logChannel.Guild, strs.muted_sn);
|
||||
switch (muteType)
|
||||
{
|
||||
@@ -459,7 +459,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting)
|
||||
|| (logSetting.UserMutedId is null))
|
||||
return;
|
||||
|
||||
@@ -468,7 +468,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
.ConfigureAwait(false)) is null)
|
||||
return;
|
||||
|
||||
var mutes = "";
|
||||
var mutes = string.Empty;
|
||||
var unmutedLocalized = GetText(logChannel.Guild, strs.unmuted_sn);
|
||||
switch (muteType)
|
||||
{
|
||||
@@ -511,7 +511,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
if (users.Length == 0)
|
||||
return;
|
||||
|
||||
if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out var logSetting)
|
||||
|| (logSetting.LogOtherId is null))
|
||||
return;
|
||||
ITextChannel logChannel;
|
||||
@@ -519,7 +519,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
.ConfigureAwait(false)) is null)
|
||||
return;
|
||||
|
||||
var punishment = "";
|
||||
var punishment = string.Empty;
|
||||
switch (action)
|
||||
{
|
||||
case PunishmentAction.Mute:
|
||||
@@ -579,7 +579,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out var logSetting)
|
||||
|| logSetting.LogIgnores.Any(ilc => ilc.LogItemId == after.Id && ilc.ItemType == IgnoredItemType.User))
|
||||
return;
|
||||
|
||||
@@ -680,7 +680,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
|
||||
var after = (IGuildChannel) cafter;
|
||||
|
||||
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out var logSetting)
|
||||
|| (logSetting.ChannelUpdatedId is null)
|
||||
|| logSetting.LogIgnores.Any(ilc => ilc.LogItemId == after.Id && ilc.ItemType == IgnoredItemType.Channel))
|
||||
return;
|
||||
@@ -731,7 +731,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
if (!(ich is IGuildChannel ch))
|
||||
return;
|
||||
|
||||
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting)
|
||||
|| (logSetting.ChannelDestroyedId is null)
|
||||
|| logSetting.LogIgnores.Any(ilc => ilc.LogItemId == ch.Id && ilc.ItemType == IgnoredItemType.Channel))
|
||||
return;
|
||||
@@ -771,7 +771,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
if (!(ich is IGuildChannel ch))
|
||||
return;
|
||||
|
||||
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting)
|
||||
|| logSetting.ChannelCreatedId is null)
|
||||
return;
|
||||
|
||||
@@ -816,7 +816,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
if (beforeVch == afterVch)
|
||||
return;
|
||||
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting)
|
||||
|| (logSetting.LogVoicePresenceId is null)
|
||||
|| logSetting.LogIgnores.Any(ilc => ilc.LogItemId == iusr.Id && ilc.ItemType == IgnoredItemType.User))
|
||||
return;
|
||||
@@ -869,7 +869,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting)
|
||||
|| (logSetting.UserLeftId is null)
|
||||
|| logSetting.LogIgnores.Any(ilc => ilc.LogItemId == usr.Id && ilc.ItemType == IgnoredItemType.User))
|
||||
return;
|
||||
@@ -904,7 +904,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting)
|
||||
|| (logSetting.UserJoinedId is null))
|
||||
return;
|
||||
|
||||
@@ -945,7 +945,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!GuildLogSettings.TryGetValue(guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(guild.Id, out var logSetting)
|
||||
|| (logSetting.UserUnbannedId is null)
|
||||
|| logSetting.LogIgnores.Any(ilc => ilc.LogItemId == usr.Id && ilc.ItemType == IgnoredItemType.User))
|
||||
return;
|
||||
@@ -980,7 +980,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!GuildLogSettings.TryGetValue(guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(guild.Id, out var logSetting)
|
||||
|| (logSetting.UserBannedId is null)
|
||||
|| logSetting.LogIgnores.Any(ilc => ilc.LogItemId == usr.Id && ilc.ItemType == IgnoredItemType.User))
|
||||
return;
|
||||
@@ -1028,7 +1028,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
if (!(ch is ITextChannel channel))
|
||||
return;
|
||||
|
||||
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out var logSetting)
|
||||
|| (logSetting.MessageDeletedId is null)
|
||||
|| logSetting.LogIgnores.Any(ilc => ilc.LogItemId == channel.Id && ilc.ItemType == IgnoredItemType.Channel))
|
||||
return;
|
||||
@@ -1086,7 +1086,7 @@ public sealed class LogCommandService : ILogCommandService
|
||||
if (before.Author.IsBot)
|
||||
return;
|
||||
|
||||
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out LogSetting logSetting)
|
||||
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out var logSetting)
|
||||
|| (logSetting.MessageUpdatedId is null)
|
||||
|| logSetting.LogIgnores.Any(ilc => ilc.LogItemId == channel.Id && ilc.ItemType == IgnoredItemType.Channel))
|
||||
return;
|
||||
|
@@ -156,7 +156,7 @@ public class MuteService : INService
|
||||
{
|
||||
try
|
||||
{
|
||||
MutedUsers.TryGetValue(usr.Guild.Id, out ConcurrentHashSet<ulong> muted);
|
||||
MutedUsers.TryGetValue(usr.Guild.Id, out var muted);
|
||||
|
||||
if (muted is null || !muted.Contains(usr.Id))
|
||||
return Task.CompletedTask;
|
||||
@@ -198,7 +198,7 @@ public class MuteService : INService
|
||||
{
|
||||
UserId = usr.Id
|
||||
});
|
||||
if (MutedUsers.TryGetValue(usr.Guild.Id, out ConcurrentHashSet<ulong> muted))
|
||||
if (MutedUsers.TryGetValue(usr.Guild.Id, out var muted))
|
||||
muted.Add(usr.Id);
|
||||
|
||||
config.UnmuteTimers.RemoveWhere(x => x.UserId == usr.Id);
|
||||
@@ -242,7 +242,7 @@ public class MuteService : INService
|
||||
{
|
||||
uow.Remove(toRemove);
|
||||
}
|
||||
if (MutedUsers.TryGetValue(guildId, out ConcurrentHashSet<ulong> muted))
|
||||
if (MutedUsers.TryGetValue(guildId, out var muted))
|
||||
muted.TryRemove(usrId);
|
||||
|
||||
config.UnmuteTimers.RemoveWhere(x => x.UserId == usrId);
|
||||
@@ -442,10 +442,10 @@ public class MuteService : INService
|
||||
|
||||
public void StopTimer(ulong guildId, ulong userId, TimerType type)
|
||||
{
|
||||
if (!Un_Timers.TryGetValue(guildId, out ConcurrentDictionary<(ulong, TimerType), Timer> userTimer))
|
||||
if (!Un_Timers.TryGetValue(guildId, out var userTimer))
|
||||
return;
|
||||
|
||||
if (userTimer.TryRemove((userId, type), out Timer removed))
|
||||
if (userTimer.TryRemove((userId, type), out var removed))
|
||||
{
|
||||
removed.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
}
|
||||
|
@@ -131,7 +131,7 @@ public class SelfAssignedRolesService : INService
|
||||
|
||||
public async Task<bool> SetNameAsync(ulong guildId, int group, string name)
|
||||
{
|
||||
bool set = false;
|
||||
var set = false;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow.GuildConfigsForId(guildId, y => y.Include(x => x.SelfAssignableRoleGroupNames));
|
||||
|
@@ -58,7 +58,7 @@ public class UserPunishService : INService
|
||||
Weight = weight,
|
||||
};
|
||||
|
||||
int warnings = 1;
|
||||
var warnings = 1;
|
||||
List<WarningPunishment> ps;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
@@ -299,7 +299,7 @@ WHERE GuildId={guildId}
|
||||
|
||||
public async Task<bool> WarnClearAsync(ulong guildId, ulong userId, int index, string moderator)
|
||||
{
|
||||
bool toReturn = true;
|
||||
var toReturn = true;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
if (index == 0)
|
||||
|
@@ -194,10 +194,10 @@ public class VcRoleService : INService
|
||||
ulong guildId;
|
||||
guildId = newVc?.Guild.Id ?? oldVc.Guild.Id;
|
||||
|
||||
if (VcRoles.TryGetValue(guildId, out ConcurrentDictionary<ulong, IRole> guildVcRoles))
|
||||
if (VcRoles.TryGetValue(guildId, out var guildVcRoles))
|
||||
{
|
||||
//remove old
|
||||
if (oldVc != null && guildVcRoles.TryGetValue(oldVc.Id, out IRole role))
|
||||
if (oldVc != null && guildVcRoles.TryGetValue(oldVc.Id, out var role))
|
||||
{
|
||||
Assign(false, gusr, role);
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ public partial class Administration
|
||||
{
|
||||
var guild = (SocketGuild)ctx.Guild;
|
||||
string text;
|
||||
if (_service.VcRoles.TryGetValue(ctx.Guild.Id, out ConcurrentDictionary<ulong, IRole> roles))
|
||||
if (_service.VcRoles.TryGetValue(ctx.Guild.Id, out var roles))
|
||||
{
|
||||
if (!roles.Any())
|
||||
{
|
||||
|
@@ -199,7 +199,7 @@ public class CustomReactions : NadekoModule<CustomReactionsService>
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> succ = new List<string>();
|
||||
var succ = new List<string>();
|
||||
foreach (var emojiStr in emojiStrs)
|
||||
{
|
||||
|
||||
|
@@ -403,7 +403,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
|
||||
{
|
||||
var pc = _perms.GetCacheFor(guild.Id);
|
||||
if (!pc.Permissions.CheckPermissions(msg, cr.Trigger, "ActualCustomReactions",
|
||||
out int index))
|
||||
out var index))
|
||||
{
|
||||
if (pc.Verbose)
|
||||
{
|
||||
|
@@ -58,7 +58,7 @@ public class Deck
|
||||
{
|
||||
get
|
||||
{
|
||||
var str = "";
|
||||
var str = string.Empty;
|
||||
|
||||
if (Number <= 10 && Number > 1)
|
||||
{
|
||||
@@ -106,7 +106,7 @@ public class Deck
|
||||
|
||||
public string GetEmojiString()
|
||||
{
|
||||
var str = "";
|
||||
var str = string.Empty;
|
||||
|
||||
str += _regIndicators[this.Number - 1];
|
||||
str += _suitToSuitChar[this.Suit];
|
||||
|
@@ -71,7 +71,7 @@ public class GameStatusEvent : ICurrencyEvent
|
||||
private async void OnTimerTick(object state)
|
||||
{
|
||||
var potEmpty = PotEmptied;
|
||||
List<ulong> toAward = new List<ulong>();
|
||||
var toAward = new List<ulong>();
|
||||
while (_toAward.TryDequeue(out var x))
|
||||
{
|
||||
toAward.Add(x);
|
||||
|
@@ -67,7 +67,7 @@ public class ReactionEvent : ICurrencyEvent
|
||||
private async void OnTimerTick(object state)
|
||||
{
|
||||
var potEmpty = PotEmptied;
|
||||
List<ulong> toAward = new List<ulong>();
|
||||
var toAward = new List<ulong>();
|
||||
while (_toAward.TryDequeue(out var x))
|
||||
{
|
||||
toAward.Add(x);
|
||||
|
@@ -79,7 +79,7 @@ public sealed class Connect4Game : IDisposable
|
||||
_cs = cs;
|
||||
|
||||
_rng = new NadekoRandom();
|
||||
for (int i = 0; i < NumberOfColumns * NumberOfRows; i++)
|
||||
for (var i = 0; i < NumberOfColumns * NumberOfRows; i++)
|
||||
{
|
||||
_gameState[i] = Field.Empty;
|
||||
}
|
||||
@@ -169,7 +169,7 @@ public sealed class Connect4Game : IDisposable
|
||||
return false;
|
||||
|
||||
var start = NumberOfRows * inputCol;
|
||||
for (int i = start; i < start + NumberOfRows; i++)
|
||||
for (var i = start; i < start + NumberOfRows; i++)
|
||||
{
|
||||
if (_gameState[i] == Field.Empty)
|
||||
{
|
||||
@@ -181,12 +181,12 @@ public sealed class Connect4Game : IDisposable
|
||||
//check winnning condition
|
||||
// ok, i'll go from [0-2] in rows (and through all columns) and check upward if 4 are connected
|
||||
|
||||
for (int i = 0; i < NumberOfRows - 3; i++)
|
||||
for (var i = 0; i < NumberOfRows - 3; i++)
|
||||
{
|
||||
if (CurrentPhase == Phase.Ended)
|
||||
break;
|
||||
|
||||
for (int j = 0; j < NumberOfColumns; j++)
|
||||
for (var j = 0; j < NumberOfColumns; j++)
|
||||
{
|
||||
if (CurrentPhase == Phase.Ended)
|
||||
break;
|
||||
@@ -194,7 +194,7 @@ public sealed class Connect4Game : IDisposable
|
||||
var first = _gameState[i + j * NumberOfRows];
|
||||
if (first != Field.Empty)
|
||||
{
|
||||
for (int k = 1; k < 4; k++)
|
||||
for (var k = 1; k < 4; k++)
|
||||
{
|
||||
var next = _gameState[i + k + j * NumberOfRows];
|
||||
if (next == first)
|
||||
@@ -211,12 +211,12 @@ public sealed class Connect4Game : IDisposable
|
||||
}
|
||||
|
||||
// i'll go [0-1] in columns (and through all rows) and check to the right if 4 are connected
|
||||
for (int i = 0; i < NumberOfColumns - 3; i++)
|
||||
for (var i = 0; i < NumberOfColumns - 3; i++)
|
||||
{
|
||||
if (CurrentPhase == Phase.Ended)
|
||||
break;
|
||||
|
||||
for (int j = 0; j < NumberOfRows; j++)
|
||||
for (var j = 0; j < NumberOfRows; j++)
|
||||
{
|
||||
if (CurrentPhase == Phase.Ended)
|
||||
break;
|
||||
@@ -224,7 +224,7 @@ public sealed class Connect4Game : IDisposable
|
||||
var first = _gameState[j + i * NumberOfRows];
|
||||
if (first != Field.Empty)
|
||||
{
|
||||
for (int k = 1; k < 4; k++)
|
||||
for (var k = 1; k < 4; k++)
|
||||
{
|
||||
var next = _gameState[j + (i + k) * NumberOfRows];
|
||||
if (next == first)
|
||||
@@ -239,12 +239,12 @@ public sealed class Connect4Game : IDisposable
|
||||
}
|
||||
|
||||
//need to check diagonal now
|
||||
for (int col = 0; col < NumberOfColumns; col++)
|
||||
for (var col = 0; col < NumberOfColumns; col++)
|
||||
{
|
||||
if (CurrentPhase == Phase.Ended)
|
||||
break;
|
||||
|
||||
for (int row = 0; row < NumberOfRows; row++)
|
||||
for (var row = 0; row < NumberOfRows; row++)
|
||||
{
|
||||
if (CurrentPhase == Phase.Ended)
|
||||
break;
|
||||
@@ -256,7 +256,7 @@ public sealed class Connect4Game : IDisposable
|
||||
var same = 1;
|
||||
|
||||
//top left
|
||||
for (int i = 1; i < 4; i++)
|
||||
for (var i = 1; i < 4; i++)
|
||||
{
|
||||
//while going top left, rows are increasing, columns are decreasing
|
||||
var curRow = row + i;
|
||||
@@ -283,7 +283,7 @@ public sealed class Connect4Game : IDisposable
|
||||
same = 1;
|
||||
|
||||
//top right
|
||||
for (int i = 1; i < 4; i++)
|
||||
for (var i = 1; i < 4; i++)
|
||||
{
|
||||
//while going top right, rows are increasing, columns are increasing
|
||||
var curRow = row + i;
|
||||
@@ -361,7 +361,7 @@ public sealed class Connect4Game : IDisposable
|
||||
private bool IsColumnFull(int column)
|
||||
{
|
||||
var start = NumberOfRows * column;
|
||||
for (int i = start; i < start + NumberOfRows; i++)
|
||||
for (var i = start; i < start + NumberOfRows; i++)
|
||||
{
|
||||
if (_gameState[i] == Field.Empty)
|
||||
return false;
|
||||
|
@@ -84,7 +84,7 @@ public partial class Gambling
|
||||
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
bool success = false;
|
||||
var success = false;
|
||||
if (int.TryParse(arg.Content, out var col))
|
||||
{
|
||||
success = await game.Input(arg.Author.Id, col).ConfigureAwait(false);
|
||||
@@ -181,9 +181,9 @@ public partial class Gambling
|
||||
game.CurrentPhase == Connect4Game.Phase.P2Move)
|
||||
sb.AppendLine(GetText(strs.connect4_player_to_move(Format.Bold(game.CurrentPlayer.Username))));
|
||||
|
||||
for (int i = Connect4Game.NumberOfRows; i > 0; i--)
|
||||
for (var i = Connect4Game.NumberOfRows; i > 0; i--)
|
||||
{
|
||||
for (int j = 0; j < Connect4Game.NumberOfColumns; j++)
|
||||
for (var j = 0; j < Connect4Game.NumberOfColumns; j++)
|
||||
{
|
||||
var cur = game.GameState[i + (j * Connect4Game.NumberOfRows) - 1];
|
||||
|
||||
@@ -197,7 +197,7 @@ public partial class Gambling
|
||||
sb.AppendLine();
|
||||
}
|
||||
|
||||
for (int i = 0; i < Connect4Game.NumberOfColumns; i++)
|
||||
for (var i = 0; i < Connect4Game.NumberOfColumns; i++)
|
||||
{
|
||||
sb.Append(numbers[i]);
|
||||
}
|
||||
|
@@ -136,14 +136,14 @@ public partial class Gambling
|
||||
{
|
||||
Match match;
|
||||
if ((match = fudgeRegex.Match(arg)).Length != 0 &&
|
||||
int.TryParse(match.Groups["n1"].ToString(), out int n1) &&
|
||||
int.TryParse(match.Groups["n1"].ToString(), out var n1) &&
|
||||
n1 > 0 && n1 < 500)
|
||||
{
|
||||
var rng = new NadekoRandom();
|
||||
|
||||
var rolls = new List<char>();
|
||||
|
||||
for (int i = 0; i < n1; i++)
|
||||
for (var i = 0; i < n1; i++)
|
||||
{
|
||||
rolls.Add(_fateRolls[rng.Next(0, _fateRolls.Length)]);
|
||||
}
|
||||
@@ -158,16 +158,16 @@ public partial class Gambling
|
||||
{
|
||||
var rng = new NadekoRandom();
|
||||
if (int.TryParse(match.Groups["n1"].ToString(), out n1) &&
|
||||
int.TryParse(match.Groups["n2"].ToString(), out int n2) &&
|
||||
int.TryParse(match.Groups["n2"].ToString(), out var n2) &&
|
||||
n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0)
|
||||
{
|
||||
if (!int.TryParse(match.Groups["add"].Value, out int add))
|
||||
if (!int.TryParse(match.Groups["add"].Value, out var add))
|
||||
add = 0;
|
||||
if (!int.TryParse(match.Groups["sub"].Value, out int sub))
|
||||
if (!int.TryParse(match.Groups["sub"].Value, out var sub))
|
||||
sub = 0;
|
||||
|
||||
var arr = new int[n1];
|
||||
for (int i = 0; i < n1; i++)
|
||||
for (var i = 0; i < n1; i++)
|
||||
{
|
||||
arr[i] = rng.Next(1, n2 + 1);
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ public partial class Gambling
|
||||
if (num < 1 || num > 10)
|
||||
throw new ArgumentOutOfRangeException(nameof(num));
|
||||
|
||||
Deck cards = guildId is null ? new Deck() : _allDecks.GetOrAdd(ctx.Guild, (s) => new Deck());
|
||||
var cards = guildId is null ? new Deck() : _allDecks.GetOrAdd(ctx.Guild, (s) => new Deck());
|
||||
var images = new List<Image<Rgba32>>();
|
||||
var cardObjects = new List<Deck.Card>();
|
||||
for (var i = 0; i < num; i++)
|
||||
|
@@ -197,7 +197,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString() ?? $"{userId}")))
|
||||
.WithOkColor();
|
||||
|
||||
var desc = "";
|
||||
var desc = string.Empty;
|
||||
foreach (var tr in trs)
|
||||
{
|
||||
var type = tr.Amount > 0 ? "🔵" : "🔴";
|
||||
@@ -517,7 +517,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
|
||||
var (opts, _) = OptionsParser.ParseFrom(new LbOpts(), args);
|
||||
|
||||
List<DiscordUser> cleanRichest = new List<DiscordUser>();
|
||||
var cleanRichest = new List<DiscordUser>();
|
||||
// it's pointless to have clean on dm context
|
||||
if (ctx.Guild is null)
|
||||
{
|
||||
|
@@ -84,7 +84,7 @@ public partial class Gambling
|
||||
#endif
|
||||
public async Task GenCurrency()
|
||||
{
|
||||
bool enabled = _service.ToggleCurrencyGeneration(ctx.Guild.Id, ctx.Channel.Id);
|
||||
var enabled = _service.ToggleCurrencyGeneration(ctx.Guild.Id, ctx.Channel.Id);
|
||||
if (enabled)
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.curgen_enabled).ConfigureAwait(false);
|
||||
|
@@ -31,8 +31,8 @@ public class CurrencyEventsService : INService
|
||||
public async Task<bool> TryCreateEventAsync(ulong guildId, ulong channelId, CurrencyEvent.Type type,
|
||||
EventOptions opts, Func<CurrencyEvent.Type, EventOptions, long, IEmbedBuilder> embed)
|
||||
{
|
||||
SocketGuild g = _client.GetGuild(guildId);
|
||||
SocketTextChannel ch = g?.GetChannel(channelId) as SocketTextChannel;
|
||||
var g = _client.GetGuild(guildId);
|
||||
var ch = g?.GetChannel(channelId) as SocketTextChannel;
|
||||
if (ch is null)
|
||||
return false;
|
||||
|
||||
|
@@ -59,7 +59,7 @@ public partial class Gambling
|
||||
var embed = _eb.Create().WithOkColor()
|
||||
.WithTitle(GetText(strs.shop));
|
||||
|
||||
for (int i = 0; i < theseEntries.Length; i++)
|
||||
for (var i = 0; i < theseEntries.Length; i++)
|
||||
{
|
||||
var entry = theseEntries[i];
|
||||
embed.AddField(
|
||||
@@ -292,8 +292,8 @@ public partial class Gambling
|
||||
Text = itemText
|
||||
};
|
||||
ShopEntry entry;
|
||||
bool rightType = false;
|
||||
bool added = false;
|
||||
var rightType = false;
|
||||
var added = false;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
|
||||
|
@@ -122,7 +122,7 @@ public partial class Gambling
|
||||
return;
|
||||
//multi vs how many times it occured
|
||||
var dict = new Dictionary<int, int>();
|
||||
for (int i = 0; i < tests; i++)
|
||||
for (var i = 0; i < tests; i++)
|
||||
{
|
||||
var res = SlotMachine.Pull();
|
||||
if (dict.ContainsKey(res.Multiplier))
|
||||
@@ -133,7 +133,7 @@ public partial class Gambling
|
||||
|
||||
var sb = new StringBuilder();
|
||||
const int bet = 1;
|
||||
int payout = 0;
|
||||
var payout = 0;
|
||||
foreach (var key in dict.Keys.OrderByDescending(x => x))
|
||||
{
|
||||
sb.AppendLine($"x{key} occured {dict[key]} times. {dict[key] * 1.0f / tests * 100}%");
|
||||
|
@@ -106,7 +106,7 @@ public sealed class AcrophobiaGame : IDisposable
|
||||
|
||||
var lettersArr = new char[wordCount];
|
||||
|
||||
for (int i = 0; i < wordCount; i++)
|
||||
for (var i = 0; i < wordCount; i++)
|
||||
{
|
||||
var randChar = (char)_rng.Next(65, 91);
|
||||
lettersArr[i] = randChar == 'X' ? (char)_rng.Next(65, 88) : randChar;
|
||||
@@ -160,7 +160,7 @@ public sealed class AcrophobiaGame : IDisposable
|
||||
if (inputWords.Length != StartingLetters.Length) // number of words must be the same as the number of the starting letters
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < StartingLetters.Length; i++)
|
||||
for (var i = 0; i < StartingLetters.Length; i++)
|
||||
{
|
||||
var letter = StartingLetters[i];
|
||||
|
||||
|
@@ -33,7 +33,7 @@ public class PollRunner
|
||||
return false;
|
||||
|
||||
// has to be an integer
|
||||
if (!int.TryParse(msg.Content, out int vote))
|
||||
if (!int.TryParse(msg.Content, out var vote))
|
||||
return false;
|
||||
--vote;
|
||||
if (vote < 0 || vote >= Poll.Answers.Count)
|
||||
|
@@ -250,7 +250,7 @@ public class TicTacToe
|
||||
|
||||
_phase = Phase.Ended;
|
||||
}
|
||||
var reason = "";
|
||||
var reason = string.Empty;
|
||||
|
||||
if (_phase == Phase.Ended) // if user won, stop receiving moves
|
||||
{
|
||||
|
@@ -46,15 +46,15 @@ public class TriviaQuestion
|
||||
return true;
|
||||
}
|
||||
|
||||
int levDistanceClean = CleanAnswer.LevenshteinDistance(cleanGuess);
|
||||
int levDistanceNormal = Answer.LevenshteinDistance(guess);
|
||||
var levDistanceClean = CleanAnswer.LevenshteinDistance(cleanGuess);
|
||||
var levDistanceNormal = Answer.LevenshteinDistance(guess);
|
||||
return JudgeGuess(CleanAnswer.Length, cleanGuess.Length, levDistanceClean)
|
||||
|| JudgeGuess(Answer.Length, guess.Length, levDistanceNormal);
|
||||
}
|
||||
|
||||
private static bool JudgeGuess(int guessLength, int answerLength, int levDistance)
|
||||
{
|
||||
foreach (Tuple<int, int> level in strictness)
|
||||
foreach (var level in strictness)
|
||||
{
|
||||
if (guessLength <= level.Item1 || answerLength <= level.Item1)
|
||||
{
|
||||
|
@@ -105,7 +105,7 @@ public partial class Games
|
||||
.OrderByDescending(x => x.votes)
|
||||
.ToArray();
|
||||
|
||||
for (int i = 0; i < stats.Length; i++)
|
||||
for (var i = 0; i < stats.Length; i++)
|
||||
{
|
||||
var (Index, votes, Text) = stats[i];
|
||||
sb.AppendLine(GetText(strs.poll_result(
|
||||
|
@@ -60,7 +60,7 @@ public class ChatterBotService : IEarlyBehavior
|
||||
if (channel is null)
|
||||
return null;
|
||||
|
||||
if (!ChatterBotGuilds.TryGetValue(channel.Guild.Id, out Lazy<IChatterBotSession> lazyCleverbot))
|
||||
if (!ChatterBotGuilds.TryGetValue(channel.Guild.Id, out var lazyCleverbot))
|
||||
return null;
|
||||
|
||||
cleverbot = lazyCleverbot.Value;
|
||||
@@ -107,7 +107,7 @@ public class ChatterBotService : IEarlyBehavior
|
||||
return false;
|
||||
try
|
||||
{
|
||||
var message = PrepareMessage(usrMsg, out IChatterBotSession cbs);
|
||||
var message = PrepareMessage(usrMsg, out var cbs);
|
||||
if (message is null || cbs is null)
|
||||
return false;
|
||||
|
||||
@@ -115,7 +115,7 @@ public class ChatterBotService : IEarlyBehavior
|
||||
if (!pc.Permissions.CheckPermissions(usrMsg,
|
||||
"cleverbot",
|
||||
"Games".ToLowerInvariant(),
|
||||
out int index))
|
||||
out var index))
|
||||
{
|
||||
if (pc.Verbose)
|
||||
{
|
||||
|
@@ -48,7 +48,7 @@ public partial class Games
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task TypeStop()
|
||||
{
|
||||
if (_service.RunningContests.TryRemove(ctx.Guild.Id, out TypingGame game))
|
||||
if (_service.RunningContests.TryRemove(ctx.Guild.Id, out var game))
|
||||
{
|
||||
await game.Stop().ConfigureAwait(false);
|
||||
return;
|
||||
|
@@ -34,7 +34,7 @@ public partial class Games
|
||||
await _sem.WaitAsync(1000).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
if (_service.TicTacToeGames.TryGetValue(channel.Id, out TicTacToe game))
|
||||
if (_service.TicTacToeGames.TryGetValue(channel.Id, out var game))
|
||||
{
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
|
@@ -72,7 +72,7 @@ public partial class Games
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Tl()
|
||||
{
|
||||
if (_service.RunningTrivias.TryGetValue(ctx.Guild.Id, out TriviaGame trivia))
|
||||
if (_service.RunningTrivias.TryGetValue(ctx.Guild.Id, out var trivia))
|
||||
{
|
||||
await SendConfirmAsync(GetText(strs.leaderboard), trivia.GetLeaderboard()).ConfigureAwait(false);
|
||||
return;
|
||||
@@ -87,7 +87,7 @@ public partial class Games
|
||||
{
|
||||
var channel = (ITextChannel)ctx.Channel;
|
||||
|
||||
if (_service.RunningTrivias.TryGetValue(channel.Guild.Id, out TriviaGame trivia))
|
||||
if (_service.RunningTrivias.TryGetValue(channel.Guild.Id, out var trivia))
|
||||
{
|
||||
await trivia.StopGame().ConfigureAwait(false);
|
||||
return;
|
||||
|
@@ -283,7 +283,7 @@ public class Help : NadekoModule<HelpService>
|
||||
|
||||
if (com is null)
|
||||
{
|
||||
IMessageChannel ch = channel is ITextChannel
|
||||
var ch = channel is ITextChannel
|
||||
? await ((IGuildUser)ctx.User).GetOrCreateDMChannelAsync().ConfigureAwait(false)
|
||||
: channel;
|
||||
try
|
||||
|
@@ -135,7 +135,7 @@ public class HelpService : ILateExecutor, INService
|
||||
var userPerm = (UserPermAttribute)cmd.Preconditions
|
||||
.FirstOrDefault(ca => ca is UserPermAttribute);
|
||||
|
||||
string userPermString = string.Empty;
|
||||
var userPermString = string.Empty;
|
||||
if (userPerm is not null)
|
||||
{
|
||||
if (userPerm.UserPermissionAttribute.ChannelPermission is ChannelPermission cPerm)
|
||||
|
@@ -106,7 +106,7 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
{
|
||||
// wait until a song is available in the queue
|
||||
// or until the queue is resumed
|
||||
var track = _queue.GetCurrent(out int index);
|
||||
var track = _queue.GetCurrent(out var index);
|
||||
|
||||
if (track is null || IsStopped)
|
||||
{
|
||||
|
@@ -85,7 +85,7 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
return Enqueue(trackInfo, queuer, out index);
|
||||
}
|
||||
|
||||
LinkedListNode<QueuedTrackInfo> currentNode = _tracks.First!;
|
||||
var currentNode = _tracks.First!;
|
||||
int i;
|
||||
for (i = 1; i <= _index; i++)
|
||||
{
|
||||
|
@@ -280,7 +280,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
|
||||
IEmbedBuilder printAction(int curPage)
|
||||
{
|
||||
string desc = string.Empty;
|
||||
var desc = string.Empty;
|
||||
var current = mp.GetCurrentTrack(out var currentIndex);
|
||||
if (current is not null)
|
||||
{
|
||||
@@ -288,7 +288,7 @@ public sealed partial class Music : NadekoModule<IMusicService>
|
||||
}
|
||||
|
||||
var repeatType = mp.Repeat;
|
||||
var add = "";
|
||||
var add = string.Empty;
|
||||
if (mp.IsStopped)
|
||||
add += Format.Bold(GetText(strs.queue_stopped(Format.Code(Prefix + "play")))) + "\n";
|
||||
// var mps = mp.MaxPlaytimeSeconds;
|
||||
|
@@ -11,7 +11,7 @@ public static class PermissionExtensions
|
||||
{
|
||||
var perms = permsEnumerable as List<Permissionv2> ?? permsEnumerable.ToList();
|
||||
|
||||
for (int i = perms.Count - 1; i >= 0; i--)
|
||||
for (var i = perms.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var perm = perms[i];
|
||||
|
||||
@@ -68,7 +68,7 @@ public static class PermissionExtensions
|
||||
|
||||
public static string GetCommand(this Permissionv2 perm, string prefix, SocketGuild guild = null)
|
||||
{
|
||||
var com = "";
|
||||
var com = string.Empty;
|
||||
switch (perm.PrimaryTarget)
|
||||
{
|
||||
case PrimaryPermissionType.User:
|
||||
|
@@ -33,7 +33,7 @@ public sealed class FilterService : IEarlyBehavior
|
||||
|
||||
public ConcurrentHashSet<string> FilteredWordsForChannel(ulong channelId, ulong guildId)
|
||||
{
|
||||
ConcurrentHashSet<string> words = new ConcurrentHashSet<string>();
|
||||
var words = new ConcurrentHashSet<string>();
|
||||
if (WordFilteringChannels.Contains(channelId))
|
||||
ServerFilteredWords.TryGetValue(guildId, out words);
|
||||
return words;
|
||||
|
@@ -119,8 +119,8 @@ public class PermissionService : ILateBlocker, INService
|
||||
{
|
||||
var resetCommand = commandName == "resetperms";
|
||||
|
||||
PermissionCache pc = GetCacheFor(guild.Id);
|
||||
if (!resetCommand && !pc.Permissions.CheckPermissions(msg, commandName, moduleName, out int index))
|
||||
var pc = GetCacheFor(guild.Id);
|
||||
if (!resetCommand && !pc.Permissions.CheckPermissions(msg, commandName, moduleName, out var index))
|
||||
{
|
||||
if (pc.Verbose)
|
||||
{
|
||||
|
@@ -35,8 +35,8 @@
|
||||
// if (_token != default && (DateTime.UtcNow - _token.Expiry) > TimeSpan.FromHours(1))
|
||||
// return;
|
||||
//
|
||||
// const string clientId = "";
|
||||
// const string clientSecret = "";
|
||||
// const string clientId = string.Empty;
|
||||
// const string clientSecret = string.Empty;
|
||||
//
|
||||
// var client = _httpClientFactory.CreateClient();
|
||||
// var res = await client.PostAsync("https://id.twitch.tv/oauth2/token" +
|
||||
|
@@ -55,7 +55,7 @@ public partial class Searches
|
||||
|
||||
await ctx.SendPaginatedConfirmAsync(page, curPage =>
|
||||
{
|
||||
var templates = "";
|
||||
var templates = string.Empty;
|
||||
foreach (var template in data.Skip(curPage * 15).Take(15))
|
||||
{
|
||||
templates += $"**{template.Name}:**\n key: `{template.Id}`\n";
|
||||
|
@@ -85,7 +85,7 @@ public partial class Searches
|
||||
{
|
||||
var sb = new System.Text.StringBuilder();
|
||||
sb.AppendLine($"```{"#",-5}{"Character Name",-23}{"League",-10}{"Class",-13}{"Level",-3}");
|
||||
for (int i = 0; i < tempList.Count; i++)
|
||||
for (var i = 0; i < tempList.Count; i++)
|
||||
{
|
||||
var character = tempList[i];
|
||||
|
||||
@@ -131,7 +131,7 @@ public partial class Searches
|
||||
|
||||
var sb = new System.Text.StringBuilder();
|
||||
sb.AppendLine($"```{"#",-5}{"League Name",-23}");
|
||||
for (int i = 0; i < leagues.Count; i++)
|
||||
for (var i = 0; i < leagues.Count; i++)
|
||||
{
|
||||
var league = leagues[i];
|
||||
|
||||
@@ -168,8 +168,8 @@ public partial class Searches
|
||||
{
|
||||
var obj = JObject.Parse(await http.GetStringAsync(res).ConfigureAwait(false));
|
||||
|
||||
float chaosEquivalent = 0.0F;
|
||||
float conversionEquivalent = 0.0F;
|
||||
var chaosEquivalent = 0.0F;
|
||||
var conversionEquivalent = 0.0F;
|
||||
|
||||
// poe.ninja API does not include a "chaosEquivalent" property for Chaos Orbs.
|
||||
if (cleanCurrency == "Chaos Orb")
|
||||
|
@@ -36,7 +36,7 @@ public partial class Searches
|
||||
[NadekoCommand, Aliases]
|
||||
public async Task Place(PlaceType placeType, uint width = 0, uint height = 0)
|
||||
{
|
||||
var url = "";
|
||||
var url = string.Empty;
|
||||
switch (placeType)
|
||||
{
|
||||
case PlaceType.Cage:
|
||||
|
@@ -75,7 +75,7 @@ public partial class Searches : NadekoModule<SearchesService>
|
||||
}
|
||||
else
|
||||
{
|
||||
Func<double, double> f = StandardConversions.CelsiusToFahrenheit;
|
||||
var f = StandardConversions.CelsiusToFahrenheit;
|
||||
|
||||
var tz = ctx.Guild is null
|
||||
? TimeZoneInfo.Utc
|
||||
@@ -616,7 +616,7 @@ public partial class Searches : NadekoModule<SearchesService>
|
||||
|
||||
using (var img = new Image<Rgba32>(colorObjects.Length * 50, 50))
|
||||
{
|
||||
for (int i = 0; i < colorObjects.Length; i++)
|
||||
for (var i = 0; i < colorObjects.Length; i++)
|
||||
{
|
||||
var x = i * 50;
|
||||
img.Mutate(m => m.FillPolygon(colorObjects[i], new PointF[] {
|
||||
|
@@ -72,7 +72,7 @@ public class FeedsService : INService
|
||||
.Reverse() // start from the oldest
|
||||
.ToList();
|
||||
|
||||
if (!_lastPosts.TryGetValue(kvp.Key, out DateTime lastFeedUpdate))
|
||||
if (!_lastPosts.TryGetValue(kvp.Key, out var lastFeedUpdate))
|
||||
{
|
||||
lastFeedUpdate = _lastPosts[kvp.Key] =
|
||||
items.Any() ? items[items.Count - 1].LastUpdate : DateTime.UtcNow;
|
||||
|
@@ -77,7 +77,7 @@ public class SearchesService : INService
|
||||
|
||||
public async Task<Stream> GetRipPictureAsync(string text, Uri imgUrl)
|
||||
{
|
||||
byte[] data = await _cache.GetOrAddCachedDataAsync($"nadeko_rip_{text}_{imgUrl}",
|
||||
var data = await _cache.GetOrAddCachedDataAsync($"nadeko_rip_{text}_{imgUrl}",
|
||||
GetRipPictureFactory,
|
||||
(text, imgUrl),
|
||||
TimeSpan.FromDays(1)).ConfigureAwait(false);
|
||||
@@ -388,7 +388,7 @@ public class SearchesService : INService
|
||||
return new MtgData[0];
|
||||
|
||||
var tasks = new List<Task<MtgData>>(cards.Length);
|
||||
for (int i = 0; i < cards.Length; i++)
|
||||
for (var i = 0; i < cards.Length; i++)
|
||||
{
|
||||
var card = cards[i];
|
||||
|
||||
|
@@ -83,7 +83,7 @@ public partial class Searches
|
||||
return;
|
||||
}
|
||||
|
||||
List<FollowedStream> streams = new List<FollowedStream>();
|
||||
var streams = new List<FollowedStream>();
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var all = uow
|
||||
|
@@ -133,9 +133,9 @@ public partial class Utility
|
||||
if (page < 0)
|
||||
return;
|
||||
|
||||
int startCount = page * activityPerPage;
|
||||
var startCount = page * activityPerPage;
|
||||
|
||||
StringBuilder str = new StringBuilder();
|
||||
var str = new StringBuilder();
|
||||
foreach (var kvp in CmdHandler.UserMessagesSent.OrderByDescending(kvp => kvp.Value).Skip(page * activityPerPage).Take(activityPerPage))
|
||||
{
|
||||
str.AppendLine(GetText(strs.activity_line(
|
||||
|
@@ -187,7 +187,7 @@ public partial class Utility
|
||||
var executesInString = Format.Bold(executesIn.ToPrettyStringHM());
|
||||
var message = Format.Sanitize(runner.Repeater.Message.TrimTo(50));
|
||||
|
||||
string description = "";
|
||||
var description = string.Empty;
|
||||
if (_service.IsNoRedundant(runner.Repeater.Id))
|
||||
{
|
||||
description = Format.Underline(Format.Bold(GetText(strs.no_redundant))) + "\n\n";
|
||||
|
@@ -67,7 +67,7 @@ public class CommandMapService : IInputTransformer, INService
|
||||
|
||||
if (guild != null)
|
||||
{
|
||||
if (AliasMaps.TryGetValue(guild.Id, out ConcurrentDictionary<string, string> maps))
|
||||
if (AliasMaps.TryGetValue(guild.Id, out var maps))
|
||||
{
|
||||
var keys = maps.Keys
|
||||
.OrderByDescending(x => x.Length);
|
||||
|
@@ -69,7 +69,7 @@ public class StreamRoleService : INService
|
||||
{
|
||||
userName.ThrowIfNull(nameof(userName));
|
||||
|
||||
bool success = false;
|
||||
var success = false;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
|
||||
|
@@ -39,7 +39,7 @@ public partial class Utility
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task StreamRoleKeyword([Leftover]string keyword = null)
|
||||
{
|
||||
string kw = await this._service.SetKeyword(ctx.Guild, keyword).ConfigureAwait(false);
|
||||
var kw = await this._service.SetKeyword(ctx.Guild, keyword).ConfigureAwait(false);
|
||||
|
||||
if(string.IsNullOrWhiteSpace(keyword))
|
||||
await ReplyConfirmLocalizedAsync(strs.stream_role_kw_reset).ConfigureAwait(false);
|
||||
|
@@ -81,7 +81,7 @@ public partial class Utility : NadekoModule
|
||||
.Take(60)
|
||||
.ToArray()).ConfigureAwait(false);
|
||||
|
||||
int i = 0;
|
||||
var i = 0;
|
||||
if (arr.Length == 0)
|
||||
await ReplyErrorLocalizedAsync(strs.nobody_playing_game).ConfigureAwait(false);
|
||||
else
|
||||
@@ -140,7 +140,7 @@ public partial class Utility : NadekoModule
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task CheckPerms(MeOrBot who = MeOrBot.Me)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
var builder = new StringBuilder();
|
||||
var user = who == MeOrBot.Me
|
||||
? (IGuildUser)ctx.User
|
||||
: ((SocketGuild)ctx.Guild).CurrentUser;
|
||||
|
@@ -62,7 +62,7 @@ public partial class Xp
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_service.CreateClub(ctx.User, clubName, out ClubInfo club))
|
||||
if (!_service.CreateClub(ctx.User, clubName, out var club))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.club_create_error).ConfigureAwait(false);
|
||||
return;
|
||||
@@ -109,7 +109,7 @@ public partial class Xp
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_service.GetClubByName(clubName, out ClubInfo club))
|
||||
if (!_service.GetClubByName(clubName, out var club))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.club_not_exists).ConfigureAwait(false);
|
||||
return;
|
||||
@@ -226,7 +226,7 @@ public partial class Xp
|
||||
if (string.IsNullOrWhiteSpace(clubName))
|
||||
return;
|
||||
|
||||
if (!_service.GetClubByName(clubName, out ClubInfo club))
|
||||
if (!_service.GetClubByName(clubName, out var club))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.club_not_exists).ConfigureAwait(false);
|
||||
return;
|
||||
@@ -345,7 +345,7 @@ public partial class Xp
|
||||
[NadekoCommand, Aliases]
|
||||
public async Task ClubDisband()
|
||||
{
|
||||
if (_service.Disband(ctx.User.Id, out ClubInfo club))
|
||||
if (_service.Disband(ctx.User.Id, out var club))
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.club_disbanded(Format.Bold(club.ToString())));
|
||||
}
|
||||
|
@@ -339,7 +339,7 @@ public partial class Xp : NadekoModule<XpService>
|
||||
await ctx.Channel.TriggerTypingAsync();
|
||||
|
||||
var socketGuild = ((SocketGuild)ctx.Guild);
|
||||
List<UserXpStats> allUsers = new List<UserXpStats>();
|
||||
var allUsers = new List<UserXpStats>();
|
||||
if (opts.Clean)
|
||||
{
|
||||
await ctx.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||
@@ -370,14 +370,14 @@ public partial class Xp : NadekoModule<XpService>
|
||||
return embed.WithDescription("-");
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < users.Count; i++)
|
||||
for (var i = 0; i < users.Count; i++)
|
||||
{
|
||||
var levelStats = new LevelStats(users[i].Xp + users[i].AwardedXp);
|
||||
var user = ((SocketGuild)ctx.Guild).GetUser(users[i].UserId);
|
||||
|
||||
var userXpData = users[i];
|
||||
|
||||
var awardStr = "";
|
||||
var awardStr = string.Empty;
|
||||
if (userXpData.AwardedXp > 0)
|
||||
awardStr = $"(+{userXpData.AwardedXp})";
|
||||
else if (userXpData.AwardedXp < 0)
|
||||
@@ -408,7 +408,7 @@ public partial class Xp : NadekoModule<XpService>
|
||||
embed.WithDescription("-");
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < users.Length; i++)
|
||||
for (var i = 0; i < users.Length; i++)
|
||||
{
|
||||
var user = users[i];
|
||||
embed.AddField(
|
||||
|
@@ -94,9 +94,9 @@ public class CurrencyService : ICurrencyService, INService
|
||||
|
||||
public async Task AddBulkAsync(IEnumerable<ulong> userIds, IEnumerable<string> reasons, IEnumerable<long> amounts, bool gamble = false)
|
||||
{
|
||||
ulong[] idArray = userIds as ulong[] ?? userIds.ToArray();
|
||||
string[] reasonArray = reasons as string[] ?? reasons.ToArray();
|
||||
long[] amountArray = amounts as long[] ?? amounts.ToArray();
|
||||
var idArray = userIds as ulong[] ?? userIds.ToArray();
|
||||
var reasonArray = reasons as string[] ?? reasons.ToArray();
|
||||
var amountArray = amounts as long[] ?? amounts.ToArray();
|
||||
|
||||
if (idArray.Length != reasonArray.Length || reasonArray.Length != amountArray.Length)
|
||||
throw new ArgumentException("Cannot perform bulk operation. Arrays are not of equal length.");
|
||||
@@ -104,7 +104,7 @@ public class CurrencyService : ICurrencyService, INService
|
||||
var userIdHashSet = new HashSet<ulong>(idArray.Length);
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
for (int i = 0; i < idArray.Length; i++)
|
||||
for (var i = 0; i < idArray.Length; i++)
|
||||
{
|
||||
// i have to prevent same user changing more than once as it will cause db error
|
||||
if (userIdHashSet.Add(idArray[i]))
|
||||
@@ -126,7 +126,7 @@ public class CurrencyService : ICurrencyService, INService
|
||||
var userIdHashSet = new HashSet<ulong>(idArray.Length);
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
for (int i = 0; i < idArray.Length; i++)
|
||||
for (var i = 0; i < idArray.Length; i++)
|
||||
{
|
||||
// i have to prevent same user changing more than once as it will cause db error
|
||||
if (userIdHashSet.Add(idArray[i]))
|
||||
|
@@ -23,7 +23,7 @@ public class FontProvider : INService
|
||||
{
|
||||
try
|
||||
{
|
||||
string fontsfolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts);
|
||||
var fontsfolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts);
|
||||
FallBackFonts.Add(_fonts.Install(Path.Combine(fontsfolder, "seguiemj.ttf")));
|
||||
FallBackFonts.AddRange(_fonts.InstallCollection(Path.Combine(fontsfolder, "msgothic.ttc")));
|
||||
FallBackFonts.AddRange(_fonts.InstallCollection(Path.Combine(fontsfolder, "segoe.ttc")));
|
||||
|
@@ -151,7 +151,7 @@ public class GoogleApiService : IGoogleApiService, INService
|
||||
|
||||
string nextPageToken = null;
|
||||
|
||||
List<string> toReturn = new List<string>(count);
|
||||
var toReturn = new List<string>(count);
|
||||
|
||||
do
|
||||
{
|
||||
@@ -178,7 +178,7 @@ public class GoogleApiService : IGoogleApiService, INService
|
||||
await Task.Yield();
|
||||
var videoIdsList = videoIds as List<string> ?? videoIds.ToList();
|
||||
|
||||
Dictionary<string, TimeSpan> toReturn = new Dictionary<string, TimeSpan>();
|
||||
var toReturn = new Dictionary<string, TimeSpan>();
|
||||
|
||||
if (!videoIdsList.Any())
|
||||
return toReturn;
|
||||
|
@@ -174,7 +174,7 @@ public class RedisCache : IDataCache
|
||||
{
|
||||
var _db = Redis.GetDatabase();
|
||||
|
||||
RedisValue data = await _db.StringGetAsync(key).ConfigureAwait(false);
|
||||
var data = await _db.StringGetAsync(key).ConfigureAwait(false);
|
||||
if (!data.HasValue)
|
||||
{
|
||||
var obj = await factory(param).ConfigureAwait(false);
|
||||
|
@@ -21,7 +21,7 @@ public sealed class RedisImagesCache : IImageCache, IReadyExecutor
|
||||
private IDatabase _db => _con.GetDatabase();
|
||||
|
||||
private const string _basePath = "data/";
|
||||
private const string _cardsPath = "data/images/cards";
|
||||
private const string _cardsPath = $"{_basePath}images/cards";
|
||||
|
||||
public ImageUrls ImageUrls { get; private set; }
|
||||
|
||||
|
@@ -18,7 +18,7 @@ public class SoundCloudApiService : INService
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
throw new ArgumentNullException(nameof(url));
|
||||
|
||||
string response = "";
|
||||
var response = string.Empty;
|
||||
|
||||
using (var http = _httpFactory.CreateClient())
|
||||
{
|
||||
@@ -37,7 +37,7 @@ public class SoundCloudApiService : INService
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
throw new ArgumentNullException(nameof(query));
|
||||
|
||||
var response = "";
|
||||
var response = string.Empty;
|
||||
using (var http = _httpFactory.CreateClient())
|
||||
{
|
||||
response = await http.GetStringAsync(new Uri($"https://scapi.nadeko.bot/tracks?q={Uri.EscapeDataString(query)}")).ConfigureAwait(false);
|
||||
@@ -55,17 +55,17 @@ public class SoundCloudApiService : INService
|
||||
|
||||
public class SoundCloudVideo
|
||||
{
|
||||
public string Kind { get; set; } = "";
|
||||
public string Kind { get; set; } = string.Empty;
|
||||
public long Id { get; set; } = 0;
|
||||
public SoundCloudUser User { get; set; } = new SoundCloudUser();
|
||||
public string Title { get; set; } = "";
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string FullName => User.Name + " - " + Title;
|
||||
public bool? Streamable { get; set; } = false;
|
||||
public int Duration { get; set; }
|
||||
[JsonProperty("permalink_url")]
|
||||
public string TrackLink { get; set; } = "";
|
||||
public string TrackLink { get; set; } = string.Empty;
|
||||
[JsonProperty("artwork_url")]
|
||||
public string ArtworkUrl { get; set; } = "";
|
||||
public string ArtworkUrl { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class SoundCloudUser
|
||||
|
@@ -103,8 +103,8 @@ public static class Extensions
|
||||
// https://github.com/SixLabors/Samples/blob/master/ImageSharp/AvatarWithRoundedCorner/Program.cs
|
||||
public static IImageProcessingContext ApplyRoundedCorners(this IImageProcessingContext ctx, float cornerRadius)
|
||||
{
|
||||
Size size = ctx.GetCurrentSize();
|
||||
IPathCollection corners = BuildCorners(size.Width, size.Height, cornerRadius);
|
||||
var size = ctx.GetCurrentSize();
|
||||
var corners = BuildCorners(size.Width, size.Height, cornerRadius);
|
||||
|
||||
ctx.SetGraphicsOptions(new GraphicsOptions()
|
||||
{
|
||||
@@ -125,18 +125,18 @@ public static class Extensions
|
||||
var rect = new RectangularPolygon(-0.5f, -0.5f, cornerRadius, cornerRadius);
|
||||
|
||||
// then cut out of the square a circle so we are left with a corner
|
||||
IPath cornerTopLeft = rect.Clip(new EllipsePolygon(cornerRadius - 0.5f, cornerRadius - 0.5f, cornerRadius));
|
||||
var cornerTopLeft = rect.Clip(new EllipsePolygon(cornerRadius - 0.5f, cornerRadius - 0.5f, cornerRadius));
|
||||
|
||||
// corner is now a corner shape positions top left
|
||||
//lets make 3 more positioned correctly, we can do that by translating the original around the center of the image
|
||||
|
||||
float rightPos = imageWidth - cornerTopLeft.Bounds.Width + 1;
|
||||
float bottomPos = imageHeight - cornerTopLeft.Bounds.Height + 1;
|
||||
var rightPos = imageWidth - cornerTopLeft.Bounds.Width + 1;
|
||||
var bottomPos = imageHeight - cornerTopLeft.Bounds.Height + 1;
|
||||
|
||||
// move it across the width of the image - the width of the shape
|
||||
IPath cornerTopRight = cornerTopLeft.RotateDegree(90).Translate(rightPos, 0);
|
||||
IPath cornerBottomLeft = cornerTopLeft.RotateDegree(-90).Translate(0, bottomPos);
|
||||
IPath cornerBottomRight = cornerTopLeft.RotateDegree(180).Translate(rightPos, bottomPos);
|
||||
var cornerTopRight = cornerTopLeft.RotateDegree(90).Translate(rightPos, 0);
|
||||
var cornerBottomLeft = cornerTopLeft.RotateDegree(-90).Translate(0, bottomPos);
|
||||
var cornerBottomRight = cornerTopLeft.RotateDegree(180).Translate(rightPos, bottomPos);
|
||||
|
||||
return new PathCollection(cornerTopLeft, cornerBottomLeft, cornerTopRight, cornerBottomRight);
|
||||
}
|
||||
|
@@ -11,8 +11,8 @@ public static class StringExtensions
|
||||
{
|
||||
public static string PadBoth(this string str, int length)
|
||||
{
|
||||
int spaces = length - str.Length;
|
||||
int padLeft = spaces / 2 + str.Length;
|
||||
var spaces = length - str.Length;
|
||||
var padLeft = spaces / 2 + str.Length;
|
||||
return str.PadLeft(padLeft).PadRight(length);
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ namespace Ayu.Discord.Gateway
|
||||
var bufferWriter = new ArrayBufferWriter<byte>(CHUNK_SIZE);
|
||||
try
|
||||
{
|
||||
using (_ws = new ClientWebSocket())
|
||||
using (_ws = new())
|
||||
{
|
||||
await _ws.ConnectAsync(url, cancel).ConfigureAwait(false);
|
||||
// WebsocketConnected!.Invoke(this);
|
||||
@@ -94,10 +94,10 @@ namespace Ayu.Discord.Gateway
|
||||
var ws = _ws;
|
||||
if (ws is null)
|
||||
throw new WebSocketException("Websocket is disconnected.");
|
||||
for (int i = 0; i < data.Length; i += 4096)
|
||||
for (var i = 0; i < data.Length; i += 4096)
|
||||
{
|
||||
var count = i + 4096 > data.Length ? data.Length - i : 4096;
|
||||
await ws.SendAsync(new ArraySegment<byte>(data, i, count),
|
||||
await ws.SendAsync(new(data, i, count),
|
||||
WebSocketMessageType.Text,
|
||||
i + count >= data.Length,
|
||||
CancellationToken.None).ConfigureAwait(false);
|
||||
@@ -115,7 +115,7 @@ namespace Ayu.Discord.Gateway
|
||||
if (ws is null)
|
||||
throw new WebSocketException("Websocket is disconnected.");
|
||||
|
||||
await ws.SendAsync(new ArraySegment<byte>(data, 0, data.Length),
|
||||
await ws.SendAsync(new(data, 0, data.Length),
|
||||
WebSocketMessageType.Binary,
|
||||
true,
|
||||
CancellationToken.None).ConfigureAwait(false);
|
||||
|
@@ -37,7 +37,7 @@ namespace Ayu.Discord.Voice
|
||||
this.channels = (int) channels;
|
||||
this.bitDepth = (int) bitDepthEnum;
|
||||
|
||||
this.Encoder = new LibOpusEncoder(this.sampleRate, this.channels, this.bitRate, this.frameDelay);
|
||||
this.Encoder = new(this.sampleRate, this.channels, this.bitRate, this.frameDelay);
|
||||
|
||||
Encode = bitDepthEnum switch
|
||||
{
|
||||
|
@@ -46,14 +46,14 @@ namespace Ayu.Discord.Voice
|
||||
private IPEndPoint? _udpEp;
|
||||
|
||||
public uint Ssrc { get; private set; }
|
||||
public string Ip { get; private set; } = "";
|
||||
public string Ip { get; private set; } = string.Empty;
|
||||
public int Port { get; private set; } = 0;
|
||||
public byte[] SecretKey { get; private set; } = Array.Empty<byte>();
|
||||
public string Mode { get; private set; } = "";
|
||||
public string Mode { get; private set; } = string.Empty;
|
||||
public ushort Sequence { get; set; }
|
||||
public uint NonceSequence { get; set; }
|
||||
public uint Timestamp { get; set; }
|
||||
public string MyIp { get; private set; } = "";
|
||||
public string MyIp { get; private set; } = string.Empty;
|
||||
public ushort MyPort { get; private set; }
|
||||
private bool shouldResume = false;
|
||||
|
||||
@@ -74,21 +74,21 @@ namespace Ayu.Discord.Voice
|
||||
//Log.Information("g: {GuildId} u: {UserId} sess: {Session} tok: {Token} ep: {Endpoint}",
|
||||
// guildId, userId, session, token, endpoint);
|
||||
|
||||
this._websocketUrl = new Uri($"wss://{_endpoint.Replace(":80", "")}?v=4");
|
||||
this._channel = Channel.CreateUnbounded<QueueItem>(new UnboundedChannelOptions
|
||||
this._websocketUrl = new($"wss://{_endpoint.Replace(":80", "")}?v=4");
|
||||
this._channel = Channel.CreateUnbounded<QueueItem>(new()
|
||||
{
|
||||
SingleReader = true,
|
||||
SingleWriter = false,
|
||||
AllowSynchronousContinuations = false,
|
||||
});
|
||||
|
||||
ConnectingFinished = new TaskCompletionSource<bool>();
|
||||
ConnectingFinished = new();
|
||||
|
||||
_rng = new Random();
|
||||
_rng = new();
|
||||
|
||||
_ws = new SocketClient();
|
||||
_udpClient = new UdpClient();
|
||||
_stopCancellationSource = new CancellationTokenSource();
|
||||
_ws = new();
|
||||
_udpClient = new();
|
||||
_stopCancellationSource = new();
|
||||
_stopCancellationToken = _stopCancellationSource.Token;
|
||||
|
||||
_ws.PayloadReceived += _ws_PayloadReceived;
|
||||
@@ -216,7 +216,7 @@ namespace Ayu.Discord.Voice
|
||||
private Task ResumeAsync()
|
||||
{
|
||||
shouldResume = false;
|
||||
return SendCommandPayloadAsync(new VoicePayload
|
||||
return SendCommandPayloadAsync(new()
|
||||
{
|
||||
OpCode = VoiceOpCode.Resume,
|
||||
Data = JToken.FromObject(new VoiceResume
|
||||
@@ -234,7 +234,7 @@ namespace Ayu.Discord.Voice
|
||||
|
||||
//Log.Information("Received ready {GuildId}, {Session}, {Token}", guildId, session, token);
|
||||
|
||||
_udpEp = new IPEndPoint(IPAddress.Parse(ready.Ip), ready.Port);
|
||||
_udpEp = new(IPAddress.Parse(ready.Ip), ready.Port);
|
||||
|
||||
var ssrcBytes = BitConverter.GetBytes(Ssrc);
|
||||
var ipDiscoveryData = new byte[70];
|
||||
@@ -265,7 +265,7 @@ namespace Ayu.Discord.Voice
|
||||
private Task HandleHelloAsync(VoiceHello data)
|
||||
{
|
||||
_receivedAck = true;
|
||||
_heartbeatTimer = new Timer(async _ =>
|
||||
_heartbeatTimer = new(async _ =>
|
||||
{
|
||||
await SendHeartbeatAsync();
|
||||
}, default, data.HeartbeatInterval, data.HeartbeatInterval);
|
||||
@@ -279,7 +279,7 @@ namespace Ayu.Discord.Voice
|
||||
}
|
||||
|
||||
private Task IdentifyAsync()
|
||||
=> SendCommandPayloadAsync(new VoicePayload
|
||||
=> SendCommandPayloadAsync(new()
|
||||
{
|
||||
OpCode = VoiceOpCode.Identify,
|
||||
Data = JToken.FromObject(new VoiceIdentify
|
||||
@@ -292,13 +292,13 @@ namespace Ayu.Discord.Voice
|
||||
});
|
||||
|
||||
private Task SelectProtocol()
|
||||
=> SendCommandPayloadAsync(new VoicePayload
|
||||
=> SendCommandPayloadAsync(new()
|
||||
{
|
||||
OpCode = VoiceOpCode.SelectProtocol,
|
||||
Data = JToken.FromObject(new SelectProtocol
|
||||
{
|
||||
Protocol = "udp",
|
||||
Data = new SelectProtocol.ProtocolData()
|
||||
Data = new()
|
||||
{
|
||||
Address = MyIp,
|
||||
Port = MyPort,
|
||||
@@ -319,7 +319,7 @@ namespace Ayu.Discord.Voice
|
||||
}
|
||||
|
||||
_receivedAck = false;
|
||||
await SendCommandPayloadAsync(new VoicePayload
|
||||
await SendCommandPayloadAsync(new()
|
||||
{
|
||||
OpCode = VoiceOpCode.Heartbeat,
|
||||
Data = JToken.FromObject(_rng.Next())
|
||||
@@ -327,7 +327,7 @@ namespace Ayu.Discord.Voice
|
||||
}
|
||||
|
||||
public Task SendSpeakingAsync(VoiceSpeaking.State speaking)
|
||||
=> SendCommandPayloadAsync(new VoicePayload
|
||||
=> SendCommandPayloadAsync(new()
|
||||
{
|
||||
OpCode = VoiceOpCode.Speaking,
|
||||
Data = JToken.FromObject(new VoiceSpeaking
|
||||
|
Reference in New Issue
Block a user