diff --git a/Core/Cache/ICacheStorage.cs b/Core/Cache/ICacheStorage.cs index aeca6a1..691e44b 100644 --- a/Core/Cache/ICacheStorage.cs +++ b/Core/Cache/ICacheStorage.cs @@ -1,6 +1,4 @@ -using System; - -namespace Kruzya.TelegramBot.Core.Cache +namespace Kruzya.TelegramBot.Core.Cache { public interface ICacheStorage { diff --git a/Core/Cache/MemoryCache.cs b/Core/Cache/MemoryCache.cs index a81a62a..bed4a6b 100644 --- a/Core/Cache/MemoryCache.cs +++ b/Core/Cache/MemoryCache.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading; -using SQLitePCL; namespace Kruzya.TelegramBot.Core.Cache { @@ -32,7 +30,7 @@ namespace Kruzya.TelegramBot.Core.Cache /// /// /// - private Dictionary> dict = new Dictionary>(); + private readonly Dictionary> _dict = new(); /// /// The TTL for all entries if not set. @@ -51,20 +49,20 @@ namespace Kruzya.TelegramBot.Core.Cache public bool TryGetValue(TKey key, out TValue value) { value = default; - if (!dict.ContainsKey(key)) + if (!_dict.ContainsKey(key)) { return false; } CacheEntry temp; - if (!dict.TryGetValue(key, out temp)) + if (!_dict.TryGetValue(key, out temp)) { return false; } if (temp.IsExpired()) { - dict.Remove(key); + _dict.Remove(key); return false; } @@ -90,12 +88,12 @@ namespace Kruzya.TelegramBot.Core.Cache public void SetValue(TKey key, TValue value, int timeToLive) { - if (dict.ContainsKey(key)) + if (_dict.ContainsKey(key)) { - dict.Remove(key); + _dict.Remove(key); } - dict.Add(key, new CacheEntry() + _dict.Add(key, new CacheEntry() { Created = DateTime.Now, ExpiresAt = timeToLive, diff --git a/Core/Data/BotUser.cs b/Core/Data/BotUser.cs index dcde794..220d471 100644 --- a/Core/Data/BotUser.cs +++ b/Core/Data/BotUser.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace Kruzya.TelegramBot.Core.Data diff --git a/Core/Data/BotUserValue.cs b/Core/Data/BotUserValue.cs index 595c167..39ae94c 100644 --- a/Core/Data/BotUserValue.cs +++ b/Core/Data/BotUserValue.cs @@ -1,12 +1,8 @@ using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Runtime.Serialization.Formatters.Binary; using System.Text.Json; using System.Text.Json.Serialization; -using System.Xml.Serialization; namespace Kruzya.TelegramBot.Core.Data { diff --git a/Core/Extensions/ChatExtension.cs b/Core/Extensions/ChatExtension.cs index db1501c..1d20bce 100644 --- a/Core/Extensions/ChatExtension.cs +++ b/Core/Extensions/ChatExtension.cs @@ -1,5 +1,4 @@ -using System; -using Telegram.Bot.Types; +using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; namespace Kruzya.TelegramBot.Core.Extensions; diff --git a/Core/Extensions/RepositoryExtension.cs b/Core/Extensions/RepositoryExtension.cs index e44e2c4..a9863a1 100644 --- a/Core/Extensions/RepositoryExtension.cs +++ b/Core/Extensions/RepositoryExtension.cs @@ -1,7 +1,4 @@ -using System.Threading.Tasks; -using Kruzya.TelegramBot.Core.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore; namespace Kruzya.TelegramBot.Core.Extensions { diff --git a/Core/Service/AbstractTimedHostedService.cs b/Core/Service/AbstractTimedHostedService.cs index c8b0016..847b613 100644 --- a/Core/Service/AbstractTimedHostedService.cs +++ b/Core/Service/AbstractTimedHostedService.cs @@ -1,14 +1,9 @@ using System; -using System.Text; using System.Threading; using System.Threading.Tasks; -using BotFramework; using BotFramework.Abstractions; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Telegram.Bot; -using Telegram.Bot.Exceptions; -using Telegram.Bot.Types; namespace Kruzya.TelegramBot.Core.Service { diff --git a/Core/Service/MemoryAntiFloodService.cs b/Core/Service/MemoryAntiFloodService.cs index b7d5269..5ea42ec 100644 --- a/Core/Service/MemoryAntiFloodService.cs +++ b/Core/Service/MemoryAntiFloodService.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Configuration; diff --git a/modules/ChatManagement/Handler/BanStickerSet.Utils.cs b/modules/ChatManagement/Handler/BanStickerSet.Utils.cs index bfc1397..78e1d85 100644 --- a/modules/ChatManagement/Handler/BanStickerSet.Utils.cs +++ b/modules/ChatManagement/Handler/BanStickerSet.Utils.cs @@ -34,7 +34,7 @@ public partial class BanStickerSet public async Task PreCommand(ParamParser.StickerSet.Param? stickerSetParam = null) { - if (stickerSetParam != null && !stickerSetParam.IsValid) + if (stickerSetParam is { IsValid: false }) { await Reply("Неверный набор стикеров."); return false; diff --git a/modules/ChatManagement/Handler/Greet.cs b/modules/ChatManagement/Handler/Greet.cs index 6048837..d51e051 100644 --- a/modules/ChatManagement/Handler/Greet.cs +++ b/modules/ChatManagement/Handler/Greet.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using System.Threading.Tasks; using BotFramework; using BotFramework.Attributes; diff --git a/modules/ChatManagement/Handler/Warn.cs b/modules/ChatManagement/Handler/Warn.cs index d8694ab..25234f6 100644 --- a/modules/ChatManagement/Handler/Warn.cs +++ b/modules/ChatManagement/Handler/Warn.cs @@ -1,6 +1,4 @@ -#nullable enable - -using System.Threading.Tasks; +using System.Threading.Tasks; using BotFramework.Attributes; using BotFramework.Enums; using Kruzya.TelegramBot.Core.Data; diff --git a/modules/CombotAntiSpam/UserJoinHandler.cs b/modules/CombotAntiSpam/UserJoinHandler.cs index 78c7d30..0bec76a 100644 --- a/modules/CombotAntiSpam/UserJoinHandler.cs +++ b/modules/CombotAntiSpam/UserJoinHandler.cs @@ -3,10 +3,8 @@ using System.Threading.Tasks; using BotFramework; using BotFramework.Attributes; using BotFramework.Enums; -using BotFramework.Setup; using Kruzya.TelegramBot.CombotAntiSpam.Combot; using Kruzya.TelegramBot.Core.Extensions; -using Microsoft.Extensions.Logging; using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; @@ -15,8 +13,7 @@ namespace Kruzya.TelegramBot.CombotAntiSpam; public class UserJoinHandler : BotEventHandler { - protected ICombotClient _combotClient; - protected ILogger _logger; + private readonly ICombotClient _combotClient; public UserJoinHandler(ICombotClient combotClient) { @@ -27,17 +24,9 @@ public class UserJoinHandler : BotEventHandler [Message(MessageFlag.HasNewChatMembers)] public async Task OnUserJoined() { - // var canKickMembers = (await Bot.GetChatMemberAsync(Chat, (await Bot.GetMeAsync()).Id)).CanRestrictMembers == true; - var meUserId = (await Bot.GetMeAsync()).Id; - var meChatMember = await Bot.GetChatMemberAsync(Chat, meUserId); + var canKickMembers = await Bot.IsUserAdminAsync(Chat, await Bot.GetMeAsync()); - var canKickMembers = false; - if (meChatMember is ChatMemberAdministrator adminMember) - { - canKickMembers = adminMember.CanRestrictMembers; - } - - foreach (var member in RawUpdate.Message.NewChatMembers) + foreach (var member in RawUpdate.Message!.NewChatMembers!) { if (!(await _combotClient.IsSpammerAsync(member))) { @@ -45,7 +34,7 @@ public class UserJoinHandler : BotEventHandler } var messageText = new StringBuilder(); - messageText.Append($"⚠️ Combot Anti-Spam\n\n"); + messageText.Append("⚠️ Combot Anti-Spam\n\n"); messageText.Append($"User {member.ToHtml(true)} is spammer.\n"); messageText.Append( $"More details you can find on CAS site."); diff --git a/modules/ContentStore/ContentStore.cs b/modules/ContentStore/ContentStore.cs index 2a00e5c..1e0a3df 100644 --- a/modules/ContentStore/ContentStore.cs +++ b/modules/ContentStore/ContentStore.cs @@ -29,9 +29,10 @@ public class ContentStore : Module { services.AddOption(); - var kittiesConfig = Configuration.GetSection("KittiesService"); services.AddHttpClient(c => { + var kittiesConfig = Configuration.GetSection("KittiesService"); + c.BaseAddress = kittiesConfig.GetValue("Uri"); c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Bearer", diff --git a/modules/ContentStore/Service/Kitties/GayKittiesService.cs b/modules/ContentStore/Service/Kitties/GayKittiesService.cs index 43f6591..ec48a1d 100644 --- a/modules/ContentStore/Service/Kitties/GayKittiesService.cs +++ b/modules/ContentStore/Service/Kitties/GayKittiesService.cs @@ -1,6 +1,4 @@ -using Kruzya.TelegramBot.Core.Data; -using Microsoft.Extensions.Configuration; -using West.TelegramBot.ContentStore.API; +using West.TelegramBot.ContentStore.API; using West.TelegramBot.ContentStore.Model; using West.TelegramBot.ContentStore.Option; diff --git a/modules/ContentStore/Service/Kitties/StraightKittiesService.cs b/modules/ContentStore/Service/Kitties/StraightKittiesService.cs index 3f68b2d..3677932 100644 --- a/modules/ContentStore/Service/Kitties/StraightKittiesService.cs +++ b/modules/ContentStore/Service/Kitties/StraightKittiesService.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Configuration; -using West.TelegramBot.ContentStore.API; +using West.TelegramBot.ContentStore.API; using West.TelegramBot.ContentStore.Model; using West.TelegramBot.ContentStore.Option; diff --git a/modules/ContentStore/Service/OBoobsService.cs b/modules/ContentStore/Service/OBoobsService.cs index 0f1e461..b1863ed 100644 --- a/modules/ContentStore/Service/OBoobsService.cs +++ b/modules/ContentStore/Service/OBoobsService.cs @@ -1,6 +1,4 @@ -using Kruzya.TelegramBot.Core.Data; -using Kruzya.TelegramBot.Core.Extensions; -using Newtonsoft.Json; +using Newtonsoft.Json; using Telegram.Bot.Types; using West.TelegramBot.ContentStore.Model; using West.TelegramBot.ContentStore.Option; diff --git a/modules/Entertainment/Entertainment.cs b/modules/Entertainment/Entertainment.cs index 0203fdd..d184b4b 100644 --- a/modules/Entertainment/Entertainment.cs +++ b/modules/Entertainment/Entertainment.cs @@ -3,7 +3,6 @@ global using GuessCache = Kruzya.TelegramBot.Core.Cache.MemoryCache DateTime.Now) diff --git a/modules/RichSiteSummary/Data/Feed.cs b/modules/RichSiteSummary/Data/Feed.cs index d93db1e..c5cb296 100644 --- a/modules/RichSiteSummary/Data/Feed.cs +++ b/modules/RichSiteSummary/Data/Feed.cs @@ -1,7 +1,7 @@ -/// This file is a part of RSS Bot for Telegram. -/// License: MIT -/// Author: CrazyHackGUT aka Kruzya (Sergey Gut) -/// +// This file is a part of RSS Bot for Telegram. +// License: MIT +// Author: CrazyHackGUT aka Kruzya (Sergey Gut) +// using System; using System.Collections.Generic; diff --git a/modules/RichSiteSummary/Data/Post.cs b/modules/RichSiteSummary/Data/Post.cs index 443626c..5589072 100644 --- a/modules/RichSiteSummary/Data/Post.cs +++ b/modules/RichSiteSummary/Data/Post.cs @@ -1,12 +1,11 @@ -/// This file is a part of RSS Bot for Telegram. -/// License: MIT -/// Author: CrazyHackGUT aka Kruzya (Sergey Gut) -/// +// This file is a part of RSS Bot for Telegram. +// License: MIT +// Author: CrazyHackGUT aka Kruzya (Sergey Gut) +// using System; using System.ComponentModel.DataAnnotations; using System.Text; -using System.Web; using Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule; using Telegram.Bot.Types.Enums; diff --git a/modules/RichSiteSummary/Data/RepresentableEntity.cs b/modules/RichSiteSummary/Data/RepresentableEntity.cs index 4a498ee..973159d 100644 --- a/modules/RichSiteSummary/Data/RepresentableEntity.cs +++ b/modules/RichSiteSummary/Data/RepresentableEntity.cs @@ -1,7 +1,7 @@ -/// This file is a part of RSS Bot for Telegram. -/// License: MIT -/// Author: CrazyHackGUT aka Kruzya (Sergey Gut) -/// +// This file is a part of RSS Bot for Telegram. +// License: MIT +// Author: CrazyHackGUT aka Kruzya (Sergey Gut) +// using System; using System.Web; diff --git a/modules/RichSiteSummary/Data/Subscriber.cs b/modules/RichSiteSummary/Data/Subscriber.cs index 364a8a1..9db6bdd 100644 --- a/modules/RichSiteSummary/Data/Subscriber.cs +++ b/modules/RichSiteSummary/Data/Subscriber.cs @@ -1,7 +1,7 @@ -/// This file is a part of RSS Bot for Telegram. -/// License: MIT -/// Author: CrazyHackGUT aka Kruzya (Sergey Gut) -/// +// This file is a part of RSS Bot for Telegram. +// License: MIT +// Author: CrazyHackGUT aka Kruzya (Sergey Gut) +// using System; using System.ComponentModel.DataAnnotations; diff --git a/modules/RichSiteSummary/Handler/FeedList.cs b/modules/RichSiteSummary/Handler/FeedList.cs index 25a04c7..70dc9f6 100644 --- a/modules/RichSiteSummary/Handler/FeedList.cs +++ b/modules/RichSiteSummary/Handler/FeedList.cs @@ -5,7 +5,6 @@ using System.Text; using System.Threading.Tasks; using BotFramework.Attributes; using BotFramework.Enums; -using BotFramework.Setup; using Kruzya.TelegramBot.Core.Extensions; using Kruzya.TelegramBot.RichSiteSummary.Data; using Microsoft.EntityFrameworkCore; diff --git a/modules/RichSiteSummary/RichSiteSummary.cs b/modules/RichSiteSummary/RichSiteSummary.cs index f316e8c..282e25f 100644 --- a/modules/RichSiteSummary/RichSiteSummary.cs +++ b/modules/RichSiteSummary/RichSiteSummary.cs @@ -1,5 +1,4 @@ -using System; -using BotFramework; +using BotFramework; using Kruzya.TelegramBot.Core; using Kruzya.TelegramBot.Core.Extensions; using Kruzya.TelegramBot.RichSiteSummary.Data; @@ -7,7 +6,6 @@ using Kruzya.TelegramBot.RichSiteSummary.Service; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Telegram.Bot.Types; namespace Kruzya.TelegramBot.RichSiteSummary { diff --git a/modules/RichSiteSummary/Service/RssFetch.cs b/modules/RichSiteSummary/Service/RssFetch.cs index aae7319..cd1832f 100644 --- a/modules/RichSiteSummary/Service/RssFetch.cs +++ b/modules/RichSiteSummary/Service/RssFetch.cs @@ -5,7 +5,6 @@ using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using System.Xml.Linq; using System.Text.RegularExpressions; using System.Linq; using CodeHollow.FeedReader; @@ -20,8 +19,6 @@ using Telegram.Bot.Types.Enums; using Feed = Kruzya.TelegramBot.RichSiteSummary.Data.Feed; using CodeHollow.FeedReader.Feeds; -using CodeHollow.FeedReader.Feeds.Itunes; -using CodeHollow.FeedReader.Feeds.MediaRSS; namespace Kruzya.TelegramBot.RichSiteSummary.Service { diff --git a/modules/RichSiteSummary/Service/Unsubscriber.cs b/modules/RichSiteSummary/Service/Unsubscriber.cs index 2b74353..620d521 100644 --- a/modules/RichSiteSummary/Service/Unsubscriber.cs +++ b/modules/RichSiteSummary/Service/Unsubscriber.cs @@ -2,13 +2,11 @@ using System.Collections.Concurrent; using System.Linq; using System.Threading.Tasks; -using BotFramework; using BotFramework.Abstractions; using Kruzya.TelegramBot.Core.Service; using Kruzya.TelegramBot.RichSiteSummary.Data; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Telegram.Bot; using Telegram.Bot.Types; namespace Kruzya.TelegramBot.RichSiteSummary.Service diff --git a/modules/RichSiteSummary/UrchinTrackingModule/UtmUtility.cs b/modules/RichSiteSummary/UrchinTrackingModule/UtmUtility.cs index 8a97a02..a945c55 100644 --- a/modules/RichSiteSummary/UrchinTrackingModule/UtmUtility.cs +++ b/modules/RichSiteSummary/UrchinTrackingModule/UtmUtility.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Web; -using Microsoft.EntityFrameworkCore.Internal; namespace Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule { diff --git a/modules/UrlLimitations/MessageExtension.cs b/modules/UrlLimitations/MessageExtension.cs index def68f9..1306321 100644 --- a/modules/UrlLimitations/MessageExtension.cs +++ b/modules/UrlLimitations/MessageExtension.cs @@ -1,7 +1,6 @@ using System; using System.Linq; using System.Threading.Tasks; -using BotFramework; using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; diff --git a/modules/UrlLimitations/MessageHandler.cs b/modules/UrlLimitations/MessageHandler.cs index 8cbe9ce..98a2703 100644 --- a/modules/UrlLimitations/MessageHandler.cs +++ b/modules/UrlLimitations/MessageHandler.cs @@ -4,8 +4,6 @@ using System.Threading.Tasks; using BotFramework; using BotFramework.Attributes; using BotFramework.Enums; -using BotFramework.Setup; -using Kruzya.TelegramBot.Core.Cache; using Kruzya.TelegramBot.Core.Data; using Kruzya.TelegramBot.Core.Extensions; using Microsoft.Extensions.Logging; @@ -49,12 +47,12 @@ namespace Kruzya.TelegramBot.UrlLimitations 0 || await message.HasUnknownMention(Bot)) { var targetChat = new ChatId(Chat.Id); - Task.WaitAll(new Task[] { + Task.WaitAll( Bot.BanChatMemberAsync(new ChatId(Chat.Id), From.Id, DateTime.Now.AddDays(1)), Bot.DeleteMessageAsync(targetChat, message.MessageId), Bot.SendTextMessageAsync(targetChat, $"Member {From.ToHtml(true)} has been banned.\nReason:
Spam suspicion
", parseMode: ParseMode.Html) - }); + ); } } } diff --git a/modules/UrlLimitations/UrlLimitations.cs b/modules/UrlLimitations/UrlLimitations.cs index 0ce910f..b916538 100644 --- a/modules/UrlLimitations/UrlLimitations.cs +++ b/modules/UrlLimitations/UrlLimitations.cs @@ -1,8 +1,4 @@ -using System; -using Kruzya.TelegramBot.Core; -using Kruzya.TelegramBot.Core.Data; -using Kruzya.TelegramBot.Core.Extensions; -using Microsoft.Extensions.DependencyInjection; +using Kruzya.TelegramBot.Core; namespace Kruzya.TelegramBot.UrlLimitations { diff --git a/modules/UrlLimitations/UserJoinHandler.cs b/modules/UrlLimitations/UserJoinHandler.cs index 29dad15..317a892 100644 --- a/modules/UrlLimitations/UserJoinHandler.cs +++ b/modules/UrlLimitations/UserJoinHandler.cs @@ -3,11 +3,8 @@ using System.Threading.Tasks; using BotFramework; using BotFramework.Attributes; using BotFramework.Enums; -using BotFramework.Setup; -using Kruzya.TelegramBot.Core.Cache; using Kruzya.TelegramBot.Core.Data; using Kruzya.TelegramBot.Core.Extensions; -using Telegram.Bot.Types.Enums; namespace Kruzya.TelegramBot.UrlLimitations { diff --git a/modules/UserGroupTag/Handler.cs b/modules/UserGroupTag/Handler.cs index 14ceae0..fb829b8 100644 --- a/modules/UserGroupTag/Handler.cs +++ b/modules/UserGroupTag/Handler.cs @@ -7,7 +7,6 @@ using BotFramework; using BotFramework.Attributes; using BotFramework.Enums; using BotFramework.Utils; -using Castle.Core.Internal; using Kruzya.TelegramBot.Core.Cache; using Kruzya.TelegramBot.Core.Data; using Kruzya.TelegramBot.Core.Extensions; diff --git a/modules/UserGroupTag/UserGroupTag.cs b/modules/UserGroupTag/UserGroupTag.cs index a08b61d..e7a7c04 100644 --- a/modules/UserGroupTag/UserGroupTag.cs +++ b/modules/UserGroupTag/UserGroupTag.cs @@ -1,5 +1,4 @@ -using System; -using Kruzya.TelegramBot.Core; +using Kruzya.TelegramBot.Core; namespace UserGroupTag {