mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Code cleanup
This commit is contained in:
@@ -34,7 +34,7 @@ public partial class BanStickerSet
|
||||
|
||||
public async Task<bool> PreCommand(ParamParser.StickerSet.Param? stickerSetParam = null)
|
||||
{
|
||||
if (stickerSetParam != null && !stickerSetParam.IsValid)
|
||||
if (stickerSetParam is { IsValid: false })
|
||||
{
|
||||
await Reply("Неверный набор стикеров.");
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BotFramework;
|
||||
using BotFramework.Attributes;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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($"⚠️ <b>Combot Anti-Spam</b>\n\n");
|
||||
messageText.Append("⚠️ <b>Combot Anti-Spam</b>\n\n");
|
||||
messageText.Append($"User {member.ToHtml(true)} is spammer.\n");
|
||||
messageText.Append(
|
||||
$"More details you can find on <a href=\"https://cas.chat/query?u={member.Id}\">CAS site</a>.");
|
||||
|
||||
@@ -29,9 +29,10 @@ public class ContentStore : Module
|
||||
{
|
||||
services.AddOption<AllowNsfw>();
|
||||
|
||||
var kittiesConfig = Configuration.GetSection("KittiesService");
|
||||
services.AddHttpClient<IKittiesApi, KittiesApi>(c =>
|
||||
{
|
||||
var kittiesConfig = Configuration.GetSection("KittiesService");
|
||||
|
||||
c.BaseAddress = kittiesConfig.GetValue<Uri>("Uri");
|
||||
c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
|
||||
"Bearer",
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -3,7 +3,6 @@ global using GuessCache = Kruzya.TelegramBot.Core.Cache.MemoryCache<Telegram.Bot
|
||||
|
||||
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Kruzya.TelegramBot.Core.Options;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using BotFramework;
|
||||
using Castle.Core.Internal;
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Guess : CommonHandler
|
||||
{
|
||||
ChatId = Chat.Id,
|
||||
DeleteAt = DateTime.UtcNow.AddSeconds(20),
|
||||
MessageId = Message.MessageId
|
||||
MessageId = Message!.MessageId
|
||||
});
|
||||
|
||||
var cooldownOption = await _db.UserValues.FindOrCreateOption(Chat.Id, From.Id, "guessCooldown");
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace West.Entertainment.Handler;
|
||||
namespace West.Entertainment.Handler;
|
||||
|
||||
public class GuessData
|
||||
{
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using BotFramework.Enums;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
@@ -14,7 +13,6 @@ using Kruzya.TelegramBot.Core.AutoDelete;
|
||||
using System.Collections.Concurrent;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using Telegram.Bot.Types;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Kruzya.TelegramBot.Core.Handler;
|
||||
|
||||
namespace West.Entertainment.Handler;
|
||||
@@ -46,7 +44,7 @@ public class Roll : CommonHandler
|
||||
{
|
||||
ChatId = Chat.Id,
|
||||
DeleteAt = DateTime.UtcNow.AddSeconds(20),
|
||||
MessageId = Message.MessageId
|
||||
MessageId = Message!.MessageId
|
||||
});
|
||||
|
||||
if (cd > DateTime.Now)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/// This file is a part of RSS Bot for Telegram.
|
||||
/// License: MIT
|
||||
/// Author: CrazyHackGUT aka Kruzya (Sergey Gut) <kruzefag@gmail.com>
|
||||
///
|
||||
// This file is a part of RSS Bot for Telegram.
|
||||
// License: MIT
|
||||
// Author: CrazyHackGUT aka Kruzya (Sergey Gut) <kruzefag@gmail.com>
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
/// This file is a part of RSS Bot for Telegram.
|
||||
/// License: MIT
|
||||
/// Author: CrazyHackGUT aka Kruzya (Sergey Gut) <kruzefag@gmail.com>
|
||||
///
|
||||
// This file is a part of RSS Bot for Telegram.
|
||||
// License: MIT
|
||||
// Author: CrazyHackGUT aka Kruzya (Sergey Gut) <kruzefag@gmail.com>
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/// This file is a part of RSS Bot for Telegram.
|
||||
/// License: MIT
|
||||
/// Author: CrazyHackGUT aka Kruzya (Sergey Gut) <kruzefag@gmail.com>
|
||||
///
|
||||
// This file is a part of RSS Bot for Telegram.
|
||||
// License: MIT
|
||||
// Author: CrazyHackGUT aka Kruzya (Sergey Gut) <kruzefag@gmail.com>
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Web;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/// This file is a part of RSS Bot for Telegram.
|
||||
/// License: MIT
|
||||
/// Author: CrazyHackGUT aka Kruzya (Sergey Gut) <kruzefag@gmail.com>
|
||||
///
|
||||
// This file is a part of RSS Bot for Telegram.
|
||||
// License: MIT
|
||||
// Author: CrazyHackGUT aka Kruzya (Sergey Gut) <kruzefag@gmail.com>
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.\n<b>Reason</b>: <pre>Spam suspicion</pre>", parseMode: ParseMode.Html)
|
||||
});
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Kruzya.TelegramBot.Core;
|
||||
|
||||
namespace UserGroupTag
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user