mirror of
https://github.com/Jetsparrow/jetherald.git
synced 2026-01-20 23:56:08 +03:00
Fix infos
This commit is contained in:
parent
7785fe1766
commit
54c126353a
@ -8,7 +8,7 @@ namespace JetHerald.Commands
|
|||||||
{
|
{
|
||||||
public class CreateTopicCommand : IChatCommand
|
public class CreateTopicCommand : IChatCommand
|
||||||
{
|
{
|
||||||
Db db;
|
readonly Db db;
|
||||||
|
|
||||||
public CreateTopicCommand(Db db)
|
public CreateTopicCommand(Db db)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,7 +6,7 @@ namespace JetHerald.Commands
|
|||||||
{
|
{
|
||||||
public class DeleteTopicCommand : IChatCommand
|
public class DeleteTopicCommand : IChatCommand
|
||||||
{
|
{
|
||||||
Db db;
|
readonly Db db;
|
||||||
|
|
||||||
public DeleteTopicCommand(Db db)
|
public DeleteTopicCommand(Db db)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,7 +6,7 @@ namespace JetHerald
|
|||||||
{
|
{
|
||||||
public class ListCommand : IChatCommand
|
public class ListCommand : IChatCommand
|
||||||
{
|
{
|
||||||
Db db;
|
readonly Db db;
|
||||||
|
|
||||||
public ListCommand(Db db)
|
public ListCommand(Db db)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,7 +5,7 @@ namespace JetHerald
|
|||||||
{
|
{
|
||||||
public class SubscribeCommand : IChatCommand
|
public class SubscribeCommand : IChatCommand
|
||||||
{
|
{
|
||||||
Db db;
|
readonly Db db;
|
||||||
|
|
||||||
public SubscribeCommand(Db db)
|
public SubscribeCommand(Db db)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,7 +5,7 @@ namespace JetHerald
|
|||||||
{
|
{
|
||||||
public class UnsubscribeCommand : IChatCommand
|
public class UnsubscribeCommand : IChatCommand
|
||||||
{
|
{
|
||||||
Db db;
|
readonly Db db;
|
||||||
|
|
||||||
public UnsubscribeCommand(Db db)
|
public UnsubscribeCommand(Db db)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -19,7 +19,7 @@ namespace JetHerald
|
|||||||
class NamespacedIdHandler : SqlMapper.TypeHandler<NamespacedId>
|
class NamespacedIdHandler : SqlMapper.TypeHandler<NamespacedId>
|
||||||
{
|
{
|
||||||
public override void SetValue(IDbDataParameter parameter, NamespacedId value) => parameter.Value = value.ToString();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,24 +40,22 @@ namespace JetHerald
|
|||||||
|
|
||||||
public async Task<int> DeleteTopic(string name, string adminToken)
|
public async Task<int> DeleteTopic(string name, string adminToken)
|
||||||
{
|
{
|
||||||
using (var c = GetConnection())
|
using var c = GetConnection();
|
||||||
{
|
return await c.ExecuteAsync(
|
||||||
return await c.ExecuteAsync(
|
" DELETE" +
|
||||||
" DELETE" +
|
" FROM topic" +
|
||||||
" FROM topic" +
|
" WHERE Name = @name AND AdminToken = @adminToken",
|
||||||
" WHERE Name = @name AND AdminToken = @adminToken",
|
new { name, adminToken });
|
||||||
new { name, adminToken });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Topic> GetTopic(string name)
|
public async Task<Topic> GetTopic(string name)
|
||||||
{
|
{
|
||||||
using (var c = GetConnection())
|
using var c = GetConnection();
|
||||||
return await c.QuerySingleOrDefaultAsync<Topic>(
|
return await c.QuerySingleOrDefaultAsync<Topic>(
|
||||||
"SELECT *" +
|
"SELECT *" +
|
||||||
" FROM topic" +
|
" FROM topic" +
|
||||||
" WHERE Name = @name",
|
" WHERE Name = @name",
|
||||||
new { name });
|
new { name });
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Topic> GetTopicForSub(string token, NamespacedId chat)
|
public async Task<Topic> GetTopicForSub(string token, NamespacedId chat)
|
||||||
@ -147,7 +145,7 @@ namespace JetHerald
|
|||||||
ON DUPLICATE KEY UPDATE
|
ON DUPLICATE KEY UPDATE
|
||||||
ExpiryTime = CURRENT_TIMESTAMP() + INTERVAL @timeoutSeconds SECOND;
|
ExpiryTime = CURRENT_TIMESTAMP() + INTERVAL @timeoutSeconds SECOND;
|
||||||
",
|
",
|
||||||
new { topicId, heart, @timeoutSeconds});
|
new { topicId, heart, @timeoutSeconds });
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<HeartAttack>> ProcessHeartAttacks()
|
public async Task<IEnumerable<HeartAttack>> ProcessHeartAttacks()
|
||||||
@ -159,7 +157,7 @@ namespace JetHerald
|
|||||||
public async Task MarkHeartAttackReported(ulong id, byte status = 1)
|
public async Task MarkHeartAttackReported(ulong id, byte status = 1)
|
||||||
{
|
{
|
||||||
using var c = GetConnection();
|
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; }
|
Options.ConnectionStrings Config { get; }
|
||||||
MySqlConnection GetConnection() => new MySqlConnection(Config.DefaultConnection);
|
MySqlConnection GetConnection() => new(Config.DefaultConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace JetHerald
|
namespace JetHerald
|
||||||
{
|
{
|
||||||
public struct NamespacedId
|
public struct NamespacedId
|
||||||
{
|
{
|
||||||
public string Namespace { get; init; }
|
public string Namespace { get; init; }
|
||||||
public string Id { get; init; }
|
public string Id { get; init; }
|
||||||
|
|
||||||
public NamespacedId(string str)
|
public NamespacedId(string str)
|
||||||
{
|
{
|
||||||
var ind = str.IndexOf("://");
|
var ind = str.IndexOf("://");
|
||||||
@ -22,10 +22,10 @@ namespace JetHerald
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static NamespacedId Telegram(long id)
|
public static NamespacedId Telegram(long id)
|
||||||
=> new NamespacedId("telegram", $"{id}");
|
=> new("telegram", $"{id}");
|
||||||
|
|
||||||
public static NamespacedId Discord(ulong id)
|
public static NamespacedId Discord(ulong id)
|
||||||
=> new NamespacedId("discord", $"{id}");
|
=> new("discord", $"{id}");
|
||||||
|
|
||||||
public override string ToString() => $"{Namespace}://{Id}";
|
public override string ToString() => $"{Namespace}://{Id}";
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ namespace JetHerald
|
|||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
=> obj is NamespacedId nsid && this == nsid;
|
=> 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;
|
=> a.Namespace == b.Namespace && a.Id == b.Id;
|
||||||
|
|
||||||
public static bool operator !=(NamespacedId a, NamespacedId b)
|
public static bool operator !=(NamespacedId a, NamespacedId b)
|
||||||
|
|||||||
@ -5,9 +5,9 @@ namespace JetHerald
|
|||||||
{
|
{
|
||||||
public static class TokenHelper
|
public static class TokenHelper
|
||||||
{
|
{
|
||||||
static RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
|
static readonly RNGCryptoServiceProvider rng = new();
|
||||||
static byte[] buf = new byte[24];
|
static readonly byte[] buf = new byte[24];
|
||||||
static readonly object SyncLock = new object();
|
static readonly object SyncLock = new();
|
||||||
|
|
||||||
public static string GetToken()
|
public static string GetToken()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user