From 54c126353a2485b1ff71d52d73f661aaf0cc80f0 Mon Sep 17 00:00:00 2001 From: Basique Evangelist Date: Tue, 27 Apr 2021 23:40:33 +0300 Subject: [PATCH] Fix infos --- JetHerald/Commands/CreateTopicCommand.cs | 2 +- JetHerald/Commands/DeleteTopicCommand.cs | 2 +- JetHerald/Commands/ListCommand.cs | 2 +- JetHerald/Commands/SubscribeCommand.cs | 2 +- JetHerald/Commands/UnsubscribeCommand.cs | 2 +- JetHerald/DapperMappers.cs | 2 +- JetHerald/Db.cs | 32 +++++++++++------------- JetHerald/NamespacedId.cs | 10 ++++---- JetHerald/TokenHelper.cs | 6 ++--- 9 files changed, 29 insertions(+), 31 deletions(-) diff --git a/JetHerald/Commands/CreateTopicCommand.cs b/JetHerald/Commands/CreateTopicCommand.cs index 06b62c9..4753366 100644 --- a/JetHerald/Commands/CreateTopicCommand.cs +++ b/JetHerald/Commands/CreateTopicCommand.cs @@ -8,7 +8,7 @@ namespace JetHerald.Commands { public class CreateTopicCommand : IChatCommand { - Db db; + readonly Db db; public CreateTopicCommand(Db db) { diff --git a/JetHerald/Commands/DeleteTopicCommand.cs b/JetHerald/Commands/DeleteTopicCommand.cs index 6e87e78..366112d 100644 --- a/JetHerald/Commands/DeleteTopicCommand.cs +++ b/JetHerald/Commands/DeleteTopicCommand.cs @@ -6,7 +6,7 @@ namespace JetHerald.Commands { public class DeleteTopicCommand : IChatCommand { - Db db; + readonly Db db; public DeleteTopicCommand(Db db) { diff --git a/JetHerald/Commands/ListCommand.cs b/JetHerald/Commands/ListCommand.cs index a6e29ff..d8f9346 100644 --- a/JetHerald/Commands/ListCommand.cs +++ b/JetHerald/Commands/ListCommand.cs @@ -6,7 +6,7 @@ namespace JetHerald { public class ListCommand : IChatCommand { - Db db; + readonly Db db; public ListCommand(Db db) { diff --git a/JetHerald/Commands/SubscribeCommand.cs b/JetHerald/Commands/SubscribeCommand.cs index f2f91c0..974b86c 100644 --- a/JetHerald/Commands/SubscribeCommand.cs +++ b/JetHerald/Commands/SubscribeCommand.cs @@ -5,7 +5,7 @@ namespace JetHerald { public class SubscribeCommand : IChatCommand { - Db db; + readonly Db db; public SubscribeCommand(Db db) { diff --git a/JetHerald/Commands/UnsubscribeCommand.cs b/JetHerald/Commands/UnsubscribeCommand.cs index 828243e..86065d1 100644 --- a/JetHerald/Commands/UnsubscribeCommand.cs +++ b/JetHerald/Commands/UnsubscribeCommand.cs @@ -5,7 +5,7 @@ namespace JetHerald { public class UnsubscribeCommand : IChatCommand { - Db db; + readonly Db db; public UnsubscribeCommand(Db db) { diff --git a/JetHerald/DapperMappers.cs b/JetHerald/DapperMappers.cs index e22223b..775c873 100644 --- a/JetHerald/DapperMappers.cs +++ b/JetHerald/DapperMappers.cs @@ -19,7 +19,7 @@ namespace JetHerald class NamespacedIdHandler : SqlMapper.TypeHandler { public override void SetValue(IDbDataParameter parameter, NamespacedId value) => parameter.Value = value.ToString(); - public override NamespacedId Parse(object value) => new NamespacedId((string)value); + public override NamespacedId Parse(object value) => new((string)value); } } } \ No newline at end of file diff --git a/JetHerald/Db.cs b/JetHerald/Db.cs index 012e7e3..d87174d 100644 --- a/JetHerald/Db.cs +++ b/JetHerald/Db.cs @@ -40,24 +40,22 @@ namespace JetHerald public async Task DeleteTopic(string name, string adminToken) { - using (var c = GetConnection()) - { - return await c.ExecuteAsync( - " DELETE" + - " FROM topic" + - " WHERE Name = @name AND AdminToken = @adminToken", - new { name, adminToken }); - } + using var c = GetConnection(); + return await c.ExecuteAsync( + " DELETE" + + " FROM topic" + + " WHERE Name = @name AND AdminToken = @adminToken", + new { name, adminToken }); } public async Task GetTopic(string name) { - using (var c = GetConnection()) - return await c.QuerySingleOrDefaultAsync( - "SELECT *" + - " FROM topic" + - " WHERE Name = @name", - new { name }); + using var c = GetConnection(); + return await c.QuerySingleOrDefaultAsync( + "SELECT *" + + " FROM topic" + + " WHERE Name = @name", + new { name }); } public async Task GetTopicForSub(string token, NamespacedId chat) @@ -147,7 +145,7 @@ namespace JetHerald ON DUPLICATE KEY UPDATE ExpiryTime = CURRENT_TIMESTAMP() + INTERVAL @timeoutSeconds SECOND; ", - new { topicId, heart, @timeoutSeconds}); + new { topicId, heart, @timeoutSeconds }); } public async Task> ProcessHeartAttacks() @@ -159,7 +157,7 @@ namespace JetHerald public async Task MarkHeartAttackReported(ulong id, byte status = 1) { using var c = GetConnection(); - await c.ExecuteAsync("UPDATE heartattack SET Status = @status WHERE HeartattackId = @id", new {id, status}); + await c.ExecuteAsync("UPDATE heartattack SET Status = @status WHERE HeartattackId = @id", new { id, status }); } @@ -171,6 +169,6 @@ namespace JetHerald } Options.ConnectionStrings Config { get; } - MySqlConnection GetConnection() => new MySqlConnection(Config.DefaultConnection); + MySqlConnection GetConnection() => new(Config.DefaultConnection); } } diff --git a/JetHerald/NamespacedId.cs b/JetHerald/NamespacedId.cs index a8c8b3e..af63c3b 100644 --- a/JetHerald/NamespacedId.cs +++ b/JetHerald/NamespacedId.cs @@ -2,11 +2,11 @@ namespace JetHerald { - public struct NamespacedId + public struct NamespacedId { public string Namespace { get; init; } public string Id { get; init; } - + public NamespacedId(string str) { var ind = str.IndexOf("://"); @@ -22,10 +22,10 @@ namespace JetHerald } public static NamespacedId Telegram(long id) - => new NamespacedId("telegram", $"{id}"); + => new("telegram", $"{id}"); public static NamespacedId Discord(ulong id) - => new NamespacedId("discord", $"{id}"); + => new("discord", $"{id}"); public override string ToString() => $"{Namespace}://{Id}"; @@ -34,7 +34,7 @@ namespace JetHerald public override bool Equals(object obj) => obj is NamespacedId nsid && this == nsid; - public static bool operator == (NamespacedId a, NamespacedId b) + public static bool operator ==(NamespacedId a, NamespacedId b) => a.Namespace == b.Namespace && a.Id == b.Id; public static bool operator !=(NamespacedId a, NamespacedId b) diff --git a/JetHerald/TokenHelper.cs b/JetHerald/TokenHelper.cs index aae69f7..f2d4cc6 100644 --- a/JetHerald/TokenHelper.cs +++ b/JetHerald/TokenHelper.cs @@ -5,9 +5,9 @@ namespace JetHerald { public static class TokenHelper { - static RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); - static byte[] buf = new byte[24]; - static readonly object SyncLock = new object(); + static readonly RNGCryptoServiceProvider rng = new(); + static readonly byte[] buf = new byte[24]; + static readonly object SyncLock = new(); public static string GetToken() {