Usings and namespace cleanup

This commit is contained in:
jetsparrow 2024-11-15 19:19:40 +03:00
parent d2e8ed4d69
commit 2cc286ad9c
29 changed files with 1415 additions and 1530 deletions

View File

@ -1,15 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Perfusion;
using JetKarmaBot.Services.Handling;
using NLog;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using NLog;
using JetKarmaBot.Services.Handling;
using JetKarmaBot.Models;
namespace JetKarmaBot.Commands
{
namespace JetKarmaBot.Commands;
class AwardCommand : IChatCommand
{
public IReadOnlyCollection<string> Names => new[] { "award", "revoke" };
@ -159,4 +154,3 @@ namespace JetKarmaBot.Commands
}
};
}
}

View File

@ -1,13 +1,9 @@
using System.Collections.Generic;
using Perfusion;
using JetKarmaBot.Services.Handling;
using NLog;
using System.Linq;
using System.Threading.Tasks;
using JetKarmaBot.Services.Handling;
using JetKarmaBot.Models;
namespace JetKarmaBot.Commands
{
namespace JetKarmaBot.Commands;
class LocaleCommand : IChatCommand
{
public IReadOnlyCollection<string> Names => new[] { "changelocale", "locale" };
@ -77,4 +73,3 @@ namespace JetKarmaBot.Commands
}
};
}
}

View File

@ -1,9 +1,7 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
namespace JetKarmaBot.Commands;
namespace JetKarmaBot.Commands
{
public class CommandString
{
public CommandString(string command, params string[] parameters)
@ -48,4 +46,3 @@ namespace JetKarmaBot.Commands
throw new ArgumentException($"\"{s}\" is not a command");
}
}
}

View File

@ -1,13 +1,9 @@
using System.Collections.Generic;
using Perfusion;
using Microsoft.EntityFrameworkCore;
using JetKarmaBot.Services.Handling;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using JetKarmaBot.Models;
namespace JetKarmaBot.Commands
{
namespace JetKarmaBot.Commands;
public class CurrenciesCommand : IChatCommand
{
[Inject] Localization Locale { get; set; }
@ -30,4 +26,3 @@ namespace JetKarmaBot.Commands
return true;
}
}
}

View File

@ -1,12 +1,7 @@
using System.Collections.Generic;
using Perfusion;
using JetKarmaBot.Services.Handling;
using Telegram.Bot.Types.Enums;
using System.Threading.Tasks;
using JetKarmaBot.Models;
using JetKarmaBot.Services.Handling;
namespace JetKarmaBot.Commands;
namespace JetKarmaBot.Commands
{
public class HelpCommand : IChatCommand
{
[Inject] Localization Locale { get; set; }
@ -41,4 +36,3 @@ namespace JetKarmaBot.Commands
}
}
}
}

View File

@ -1,9 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using JetKarmaBot.Services.Handling;
using JetKarmaBot.Services.Handling;
namespace JetKarmaBot.Commands;
namespace JetKarmaBot.Commands
{
public interface IChatCommand
{
IReadOnlyCollection<string> Names { get; }
@ -29,4 +27,3 @@ namespace JetKarmaBot.Commands
String,
Integer,
}
}

View File

@ -1,13 +1,9 @@
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Perfusion;
using JetKarmaBot.Services.Handling;
using JetKarmaBot.Models;
namespace JetKarmaBot.Commands
{
namespace JetKarmaBot.Commands;
class LeaderboardCommand : IChatCommand
{
public IReadOnlyCollection<string> Names => new[] { "leaderboard" };
@ -67,4 +63,3 @@ namespace JetKarmaBot.Commands
}
};
}
}

View File

@ -1,13 +1,9 @@
using System.Linq;
using System.Collections.Generic;
using Perfusion;
using JetKarmaBot.Services.Handling;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using JetKarmaBot.Services.Handling;
using JetKarmaBot.Models;
namespace JetKarmaBot.Commands
{
namespace JetKarmaBot.Commands;
class StatusCommand : IChatCommand
{
public IReadOnlyCollection<string> Names => ["status"];
@ -53,4 +49,3 @@ namespace JetKarmaBot.Commands
public IReadOnlyCollection<ChatCommandArgument> Arguments => [];
}
}

View File

@ -2,10 +2,9 @@
using Newtonsoft.Json;
using JsonNet.PrivateSettersContractResolvers;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace JetKarmaBot
{
namespace JetKarmaBot;
public class Config : ConfigBase
{
public Config(string path) : base(path) { }
@ -74,5 +73,4 @@ namespace JetKarmaBot
}
}
}
}

View File

@ -1,15 +1,12 @@
using System.Collections.Generic;
namespace JetKarmaBot;
namespace JetKarmaBot
{
public static class IReadOnlyDictionaryExtensions
{
public static TValue GetOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dict, TKey key)
{
TValue res = default(TValue);
TValue res = default;
if (key != null)
dict.TryGetValue(key, out res);
return res;
}
}
}

View File

@ -3,8 +3,8 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
// ReSharper disable once CheckNamespace
namespace JsonNet.PrivateSettersContractResolvers
{
namespace JsonNet.PrivateSettersContractResolvers;
public class PrivateSetterContractResolver : DefaultContractResolver
{
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
@ -42,4 +42,3 @@ namespace JsonNet.PrivateSettersContractResolvers
return property?.GetSetMethod(true) != null;
}
}
}

View File

@ -0,0 +1,6 @@
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Threading;
global using System.Threading.Tasks;
global using Perfusion;

View File

@ -3,18 +3,14 @@ using JetKarmaBot.Models;
using JetKarmaBot.Services;
using JetKarmaBot.Services.Handling;
using NLog;
using Perfusion;
using System;
using System.Threading;
using System.Threading.Tasks;
using Telegram.Bot;
using Telegram.Bot.Polling;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
namespace JetKarmaBot
{
namespace JetKarmaBot;
public class JetKarmaBot : IDisposable
{
[Inject] Config Config { get; set; }
@ -139,4 +135,3 @@ namespace JetKarmaBot
#endregion
}
}

View File

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations.Schema;
namespace JetKarmaBot.Models;
namespace JetKarmaBot.Models
{
public partial class Award
{
public int AwardId { get; set; }
@ -22,4 +20,3 @@ namespace JetKarmaBot.Models
[ForeignKey("ToId")]
public virtual User To { get; set; }
}
}

View File

@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
namespace JetKarmaBot.Models;
namespace JetKarmaBot.Models
{
public partial class AwardType
{
public AwardType()
@ -18,4 +15,3 @@ namespace JetKarmaBot.Models
public virtual ICollection<Award> Awards { get; set; }
}
}

View File

@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
namespace JetKarmaBot.Models;
namespace JetKarmaBot.Models
{
public partial class Chat
{
public Chat()
@ -16,4 +13,3 @@ namespace JetKarmaBot.Models
public virtual ICollection<Award> Awards { get; set; }
}
}

View File

@ -1,10 +1,7 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Perfusion;
using Microsoft.EntityFrameworkCore;
namespace JetKarmaBot.Models;
namespace JetKarmaBot.Models
{
[Transient]
public partial class KarmaContext : DbContext
{
@ -180,4 +177,3 @@ namespace JetKarmaBot.Models
});
}
}
}

View File

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations.Schema;
namespace JetKarmaBot.Models;
namespace JetKarmaBot.Models
{
public partial class User
{
public User()
@ -20,4 +18,3 @@ namespace JetKarmaBot.Models
[InverseProperty("To")]
public virtual ICollection<Award> AwardsTo { get; set; }
}
}

View File

@ -1,14 +1,9 @@
using System;
using System.Reflection;
using System.Runtime.Loader;
using System.Threading;
using JetKarmaBot.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using NLog;
using Perfusion;
using JetKarmaBot.Models;
namespace JetKarmaBot;
namespace JetKarmaBot
{
public static class Program
{
private static Logger log = LogManager.GetCurrentClassLogger();
@ -76,4 +71,3 @@ namespace JetKarmaBot
return (int)ExitCode.Ok;
}
}
}

View File

@ -1,14 +1,9 @@
using JetKarmaBot.Commands;
using NLog;
using Perfusion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NLog;
using Telegram.Bot;
using JetKarmaBot.Commands;
namespace JetKarmaBot.Services.Handling;
namespace JetKarmaBot.Services.Handling
{
public class ChatCommandRouter : IRequestHandler
{
public class Feature
@ -108,4 +103,3 @@ namespace JetKarmaBot.Services.Handling
Dictionary<string, IChatCommand> commands = new Dictionary<string, IChatCommand>();
}
}

View File

@ -1,10 +1,5 @@
using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Perfusion;
namespace JetKarmaBot.Services.Handling;
namespace JetKarmaBot.Services.Handling
{
public class DatabaseHandler : IRequestHandler
{
[Inject] private KarmaContextFactory Db;
@ -20,4 +15,3 @@ namespace JetKarmaBot.Services.Handling
}
}
}
}

View File

@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NLog;
using Perfusion;
namespace JetKarmaBot.Services.Handling
{
namespace JetKarmaBot.Services.Handling;
public interface IRequestHandler
{
Task Handle(RequestContext ctx, Func<RequestContext, Task> next);
@ -39,4 +35,3 @@ namespace JetKarmaBot.Services.Handling
handlerStack.Add(handler);
}
}
}

View File

@ -1,15 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using JetKarmaBot.Commands;
using JetKarmaBot.Models;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types;
using JetKarmaBot.Commands;
namespace JetKarmaBot.Services.Handling;
namespace JetKarmaBot.Services.Handling
{
public class RequestContext : IServiceProvider
{
public ITelegramBotClient Client { get; }
@ -36,4 +30,3 @@ namespace JetKarmaBot.Services.Handling
replyParameters: new ReplyParameters { MessageId = EventArgs.Message.MessageId }
);
}
}

View File

@ -1,10 +1,8 @@
using System;
using System.Threading.Tasks;
using JetKarmaBot.Models;
using Microsoft.EntityFrameworkCore;
using JetKarmaBot.Models;
namespace JetKarmaBot.Services.Handling;
namespace JetKarmaBot.Services.Handling
{
public class SaveData : IRequestHandler
{
public async Task Handle(RequestContext ctx, Func<RequestContext, Task> next)
@ -33,4 +31,3 @@ namespace JetKarmaBot.Services.Handling
(await db.Users.FindAsync(u.Id)).Username = un;
}
}
}

View File

@ -1,14 +1,8 @@
using Perfusion;
using System.Collections.Generic;
using System;
using System.Threading.Tasks;
using JetKarmaBot.Models;
using System.Threading;
using System.Linq;
using NLog;
using JetKarmaBot.Models;
namespace JetKarmaBot.Services.Handling;
namespace JetKarmaBot.Services.Handling
{
[Singleton]
public class TimeoutManager : IRequestHandler
{
@ -130,4 +124,3 @@ namespace JetKarmaBot.Services.Handling
+ (t.GenericTypeArguments.Length > 0 ? "<" + string.Join(",", t.GenericTypeArguments.Select(getTypeName)) + ">" : "");
}
}
}

View File

@ -1,12 +1,10 @@
using JetKarmaBot.Models;
using Perfusion;
namespace JetKarmaBot.Services
{
namespace JetKarmaBot.Services;
public class KarmaContextFactory
{
[Inject] IContainer C { get; set; }
public KarmaContext GetContext() => C.GetInstance<KarmaContext>();
}
}

View File

@ -1,15 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using Newtonsoft.Json.Linq;
using NLog;
using Perfusion;
namespace JetKarmaBot
{
namespace JetKarmaBot;
public class Localization : IReadOnlyDictionary<string, Locale>
{
private Dictionary<string, Locale> locales = new Dictionary<string, Locale>();
@ -168,4 +164,3 @@ namespace JetKarmaBot
SerializationInfo info,
StreamingContext context) : base(info, context) { }
}
}

View File

@ -1,10 +1,7 @@
using System;
using System.Linq;
using NLog;
using Perfusion;
namespace JetKarmaBot
{
namespace JetKarmaBot;
public class LogInfo : ObjectInfo
{
public override ObjectInfo Clone() => new LogInfo();
@ -19,4 +16,3 @@ namespace JetKarmaBot
+ (t.GenericTypeArguments.Length > 0 ? "<" + string.Join(",", t.GenericTypeArguments.Select(getTypeName)) + ">" : "");
}
}
}

View File

@ -1,10 +1,8 @@
using System;
using Microsoft.Extensions.Logging;
using NLog;
using Perfusion;
namespace JetKarmaBot
{
namespace JetKarmaBot;
public class NLoggerFactory : ILoggerFactory
{
[Inject]
@ -100,4 +98,3 @@ namespace JetKarmaBot
{
}
}
}