mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[entertainment] use thread safe random, update /roll number range
This commit is contained in:
@@ -5,6 +5,7 @@ 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;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -18,8 +19,9 @@ namespace West.Entertainment.Handler.Fun
|
||||
private readonly CoreContext _db;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
private readonly ThreadSafeRandom _rng;
|
||||
|
||||
protected virtual TimeSpan Cooldown => TimeSpan.FromMinutes(new Random().Next(10, 1337));
|
||||
protected virtual TimeSpan Cooldown => TimeSpan.FromMinutes(_rng.Next(10, 1337));
|
||||
|
||||
protected Message? Message => RawUpdate.Message;
|
||||
|
||||
@@ -30,10 +32,11 @@ namespace West.Entertainment.Handler.Fun
|
||||
get;
|
||||
}
|
||||
|
||||
protected AbstractAnimationReply(CoreContext db, ILogger logger)
|
||||
protected AbstractAnimationReply(CoreContext db, ILogger logger, ThreadSafeRandom rng)
|
||||
{
|
||||
_db = db;
|
||||
_logger = logger;
|
||||
_rng = rng;
|
||||
}
|
||||
|
||||
protected abstract string GetAnimationName();
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using BotFramework.Attributes;
|
||||
using BotFramework.Enums;
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Telegram.Bot;
|
||||
@@ -15,7 +16,7 @@ namespace West.Entertainment.Handler.Fun
|
||||
{
|
||||
protected override TimeSpan Cooldown => TimeSpan.Zero;
|
||||
|
||||
public Bayan(CoreContext db, ILogger<Bayan> logger) : base(db, logger) { }
|
||||
public Bayan(CoreContext db, ILogger<Bayan> logger, ThreadSafeRandom rng) : base(db, logger, rng) { }
|
||||
|
||||
protected override Regex AnimationMatch
|
||||
=> new("^баян$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using BotFramework.Attributes;
|
||||
using BotFramework.Enums;
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -9,7 +10,7 @@ namespace West.Entertainment.Handler.Fun
|
||||
{
|
||||
public class JavaScript : AbstractAnimationReply
|
||||
{
|
||||
public JavaScript(CoreContext db, ILogger<JavaScript> logger) : base(db, logger) { }
|
||||
public JavaScript(CoreContext db, ILogger<JavaScript> logger, ThreadSafeRandom rng) : base(db, logger, rng) { }
|
||||
|
||||
protected override Regex AnimationMatch => new(
|
||||
@"((?<![\w])(жс|js|v8)(?![\w]))|жаваскрипт|javascript|жопаскрипт|жиес|жиэс|nodejs",
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using BotFramework.Attributes;
|
||||
using BotFramework.Enums;
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -28,6 +29,6 @@ namespace West.Entertainment.Handler.Fun
|
||||
await HandleAnimation();
|
||||
}
|
||||
|
||||
public Python(CoreContext db, ILogger<Python> logger) : base(db, logger) { }
|
||||
public Python(CoreContext db, ILogger<Python> logger, ThreadSafeRandom rng) : base(db, logger, rng) { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user