mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
More target-typed new and redundant paranthesis cleanup
This commit is contained in:
@@ -21,14 +21,14 @@ public class ImageCacherObject : IComparable<ImageCacherObject>
|
||||
}
|
||||
this.SearchType = type;
|
||||
this.Rating = obj.Rating;
|
||||
this.Tags = new HashSet<string>((obj.Tags ?? obj.TagString).Split(' '));
|
||||
this.Tags = new((obj.Tags ?? obj.TagString).Split(' '));
|
||||
}
|
||||
|
||||
public ImageCacherObject(string url, Booru type, string tags, string rating)
|
||||
{
|
||||
this.SearchType = type;
|
||||
this.FileUrl = url;
|
||||
this.Tags = new HashSet<string>(tags.Split(' '));
|
||||
this.Tags = new(tags.Split(' '));
|
||||
this.Rating = rating;
|
||||
}
|
||||
|
||||
|
@@ -24,12 +24,12 @@ public class NotifChecker
|
||||
{
|
||||
_multi = multi;
|
||||
_key = $"{uniqueCacheKey}_followed_streams_data";
|
||||
_streamProviders = new Dictionary<FollowedStream.FType, Provider>()
|
||||
_streamProviders = new()
|
||||
{
|
||||
{FollowedStream.FType.Twitch, new TwitchProvider(httpClientFactory)},
|
||||
{FollowedStream.FType.Picarto, new PicartoProvider(httpClientFactory)}
|
||||
};
|
||||
_offlineBuffer = new HashSet<(FollowedStream.FType, string)>();
|
||||
_offlineBuffer = new();
|
||||
if (isMaster)
|
||||
{
|
||||
CacheClearAllData();
|
||||
@@ -181,7 +181,7 @@ public class NotifChecker
|
||||
var db = _multi.GetDatabase();
|
||||
if (!db.KeyExists(_key))
|
||||
{
|
||||
return new Dictionary<StreamDataKey, StreamData?>();
|
||||
return new();
|
||||
}
|
||||
|
||||
return db.HashGetAll(_key)
|
||||
|
@@ -54,7 +54,7 @@ public class PicartoProvider : Provider
|
||||
public async override Task<List<StreamData>> GetStreamDataAsync(List<string> logins)
|
||||
{
|
||||
if (logins.Count == 0)
|
||||
return new List<StreamData>();
|
||||
return new();
|
||||
|
||||
using (var http = _httpClientFactory.CreateClient())
|
||||
{
|
||||
@@ -63,7 +63,7 @@ public class PicartoProvider : Provider
|
||||
{
|
||||
try
|
||||
{
|
||||
http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
http.DefaultRequestHeaders.Accept.Add(new("application/json"));
|
||||
// get id based on the username
|
||||
var res = await http.GetAsync($"https://api.picarto.tv/v1/channel/name/{login}");
|
||||
|
||||
@@ -88,7 +88,7 @@ public class PicartoProvider : Provider
|
||||
|
||||
private StreamData ToStreamData(PicartoChannelResponse stream)
|
||||
{
|
||||
return new StreamData()
|
||||
return new()
|
||||
{
|
||||
StreamType = FollowedStream.FType.Picarto,
|
||||
Name = stream.Name,
|
||||
|
@@ -53,7 +53,7 @@ public class TwitchProvider : Provider
|
||||
public override async Task<List<StreamData>> GetStreamDataAsync(List<string> logins)
|
||||
{
|
||||
if (logins.Count == 0)
|
||||
return new List<StreamData>();
|
||||
return new();
|
||||
|
||||
using (var http = _httpClientFactory.CreateClient())
|
||||
{
|
||||
@@ -86,7 +86,7 @@ public class TwitchProvider : Provider
|
||||
var chStr = await http.GetStringAsync($"https://api.twitch.tv/kraken/channels/{user.Id}");
|
||||
var ch = JsonConvert.DeserializeObject<TwitchResponseV5.Channel>(chStr)!;
|
||||
|
||||
toReturn.Add(new StreamData
|
||||
toReturn.Add(new()
|
||||
{
|
||||
StreamType = FollowedStream.FType.Twitch,
|
||||
Name = ch.DisplayName,
|
||||
@@ -116,7 +116,7 @@ public class TwitchProvider : Provider
|
||||
|
||||
private StreamData ToStreamData(TwitchResponseV5.Stream stream)
|
||||
{
|
||||
return new StreamData()
|
||||
return new()
|
||||
{
|
||||
StreamType = FollowedStream.FType.Twitch,
|
||||
Name = stream.Channel.DisplayName,
|
||||
|
@@ -95,7 +95,7 @@ public partial class Searches
|
||||
return;
|
||||
}
|
||||
|
||||
await ctx.SendPaginatedConfirmAsync(0, (cur) =>
|
||||
await ctx.SendPaginatedConfirmAsync(0, cur =>
|
||||
{
|
||||
var embed = _eb.Create()
|
||||
.WithOkColor();
|
||||
|
@@ -67,7 +67,7 @@ public partial class Searches
|
||||
characters.RemoveAll(c => c.League != league);
|
||||
}
|
||||
|
||||
await ctx.SendPaginatedConfirmAsync(page, (curPage) =>
|
||||
await ctx.SendPaginatedConfirmAsync(page, curPage =>
|
||||
{
|
||||
var embed = _eb.Create()
|
||||
.WithAuthor($"Characters on {usr}'s account",
|
||||
|
@@ -461,7 +461,7 @@ public partial class Searches : NadekoModule<SearchesService>
|
||||
if (items.Any())
|
||||
{
|
||||
|
||||
await ctx.SendPaginatedConfirmAsync(0, (p) =>
|
||||
await ctx.SendPaginatedConfirmAsync(0, p =>
|
||||
{
|
||||
var item = items[p];
|
||||
return _eb.Create().WithOkColor()
|
||||
|
@@ -45,7 +45,7 @@ public class SearchesService : INService
|
||||
_cache = cache;
|
||||
_fonts = fonts;
|
||||
_creds = creds;
|
||||
_rng = new NadekoRandom();
|
||||
_rng = new();
|
||||
|
||||
//joke commands
|
||||
if (File.Exists("data/wowjokes.json"))
|
||||
@@ -70,7 +70,7 @@ public class SearchesService : INService
|
||||
}
|
||||
else
|
||||
{
|
||||
_yomamaJokes = new List<string>();
|
||||
_yomamaJokes = new();
|
||||
Log.Warning("data/yomama.txt is missing. .yomama command won't work");
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class SearchesService : INService
|
||||
}
|
||||
|
||||
private void DrawAvatar(Image bg, Image avatarImage)
|
||||
=> bg.Mutate(x => x.Grayscale().DrawImage(avatarImage, new Point(83, 139), new GraphicsOptions()));
|
||||
=> bg.Mutate(x => x.Grayscale().DrawImage(avatarImage, new(83, 139), new GraphicsOptions()));
|
||||
|
||||
public async Task<byte[]> GetRipPictureFactory((string text, Uri avatarUrl) arg)
|
||||
{
|
||||
@@ -119,7 +119,7 @@ public class SearchesService : INService
|
||||
}
|
||||
|
||||
bg.Mutate(x => x.DrawText(
|
||||
new TextGraphicsOptions()
|
||||
new()
|
||||
{
|
||||
TextOptions = new TextOptions
|
||||
{
|
||||
@@ -130,12 +130,12 @@ public class SearchesService : INService
|
||||
text,
|
||||
_fonts.RipFont,
|
||||
SixLabors.ImageSharp.Color.Black,
|
||||
new PointF(25, 225)));
|
||||
new(25, 225)));
|
||||
|
||||
//flowa
|
||||
using (var flowers = Image.Load(_imgs.RipOverlay.ToArray()))
|
||||
{
|
||||
bg.Mutate(x => x.DrawImage(flowers, new Point(0, 0), new GraphicsOptions()));
|
||||
bg.Mutate(x => x.DrawImage(flowers, new(0, 0), new GraphicsOptions()));
|
||||
}
|
||||
|
||||
return bg.ToStream().ToArray();
|
||||
@@ -362,7 +362,7 @@ public class SearchesService : INService
|
||||
}
|
||||
catch { storeUrl = "<url can't be found>"; }
|
||||
|
||||
return new MtgData
|
||||
return new()
|
||||
{
|
||||
Description = card.Text,
|
||||
Name = card.Name,
|
||||
@@ -573,7 +573,7 @@ public class SearchesService : INService
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly HtmlParser _googleParser = new HtmlParser(new HtmlParserOptions()
|
||||
private static readonly HtmlParser _googleParser = new HtmlParser(new()
|
||||
{
|
||||
IsScripting = false,
|
||||
IsEmbedded = false,
|
||||
@@ -630,7 +630,7 @@ public class SearchesService : INService
|
||||
.Where(x => x != null)
|
||||
.ToList();
|
||||
|
||||
return new GoogleSearchResultData(
|
||||
return new(
|
||||
results.AsReadOnly(),
|
||||
fullQueryLink,
|
||||
totalResults);
|
||||
@@ -681,7 +681,7 @@ public class SearchesService : INService
|
||||
.Where(x => x != null)
|
||||
.ToList();
|
||||
|
||||
return new GoogleSearchResultData(
|
||||
return new(
|
||||
results.AsReadOnly(),
|
||||
fullQueryLink,
|
||||
"0");
|
||||
|
@@ -61,7 +61,7 @@ public sealed class StreamNotificationService : INService
|
||||
_creds = creds;
|
||||
_pubSub = pubSub;
|
||||
_eb = eb;
|
||||
_streamTracker = new NotifChecker(httpFactory, redis, creds.RedisKey(), client.ShardId == 0);
|
||||
_streamTracker = new(httpFactory, redis, creds.RedisKey(), client.ShardId == 0);
|
||||
|
||||
_streamsOnlineKey = new("streams.online");
|
||||
_streamsOfflineKey = new("streams.offline");
|
||||
@@ -78,7 +78,7 @@ public sealed class StreamNotificationService : INService
|
||||
.Where(x => ids.Contains(x.GuildId))
|
||||
.ToList();
|
||||
|
||||
_offlineNotificationServers = new ConcurrentHashSet<ulong>(guildConfigs
|
||||
_offlineNotificationServers = new(guildConfigs
|
||||
.Where(gc => gc.NotifyStreamOffline)
|
||||
.Select(x => x.GuildId)
|
||||
.ToList());
|
||||
@@ -125,7 +125,7 @@ public sealed class StreamNotificationService : INService
|
||||
_streamTracker.OnStreamsOffline += OnStreamsOffline;
|
||||
_streamTracker.OnStreamsOnline += OnStreamsOnline;
|
||||
_ = _streamTracker.RunAsync();
|
||||
_notifCleanupTimer = new Timer(_ =>
|
||||
_notifCleanupTimer = new(_ =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -155,7 +155,7 @@ public sealed class StreamNotificationService : INService
|
||||
uow.SaveChanges();
|
||||
|
||||
foreach(var loginToDelete in kvp.Value)
|
||||
_streamTracker.UntrackStreamByKey(new StreamDataKey(kvp.Key, loginToDelete));
|
||||
_streamTracker.UntrackStreamByKey(new(kvp.Key, loginToDelete));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,7 +191,7 @@ public sealed class StreamNotificationService : INService
|
||||
}
|
||||
else
|
||||
{
|
||||
_trackCounter[key] = new HashSet<ulong>()
|
||||
_trackCounter[key] = new()
|
||||
{
|
||||
info.GuildId
|
||||
};
|
||||
@@ -405,7 +405,7 @@ public sealed class StreamNotificationService : INService
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams));
|
||||
|
||||
// add it to the database
|
||||
fs = new FollowedStream()
|
||||
fs = new()
|
||||
{
|
||||
Type = data.StreamType,
|
||||
Username = data.UniqueName,
|
||||
@@ -504,14 +504,14 @@ public sealed class StreamNotificationService : INService
|
||||
}
|
||||
else
|
||||
{
|
||||
return map[guildId] = new HashSet<FollowedStream>();
|
||||
return map[guildId] = new();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_shardTrackedStreams[key] = new Dictionary<ulong, HashSet<FollowedStream>>()
|
||||
_shardTrackedStreams[key] = new()
|
||||
{
|
||||
{guildId, new HashSet<FollowedStream>()}
|
||||
{guildId, new()}
|
||||
};
|
||||
return _shardTrackedStreams[key][guildId];
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ public sealed class TranslateService : ITranslateService, ILateExecutor, IReadyE
|
||||
if (string.IsNullOrWhiteSpace(msg.Content))
|
||||
return;
|
||||
|
||||
if (msg is IUserMessage { Channel: ITextChannel tch } um)
|
||||
if (msg is { Channel: ITextChannel tch } um)
|
||||
{
|
||||
if (!_atcs.TryGetValue(tch.Id, out var autoDelete))
|
||||
return;
|
||||
|
@@ -106,7 +106,7 @@ public partial class Searches
|
||||
}
|
||||
}
|
||||
|
||||
await ctx.SendPaginatedConfirmAsync(page, (cur) =>
|
||||
await ctx.SendPaginatedConfirmAsync(page, cur =>
|
||||
{
|
||||
var elements = streams.Skip(cur * 12).Take(12)
|
||||
.ToList();
|
||||
|
Reference in New Issue
Block a user