small cleanup
This commit is contained in:
parent
7399e8bac1
commit
a6c2ec0511
12 changed files with 49 additions and 66 deletions
|
@ -114,7 +114,7 @@ public sealed class Bot : IBot
|
||||||
// svcs.Components.Remove<IPlanner, Planner>();
|
// svcs.Components.Remove<IPlanner, Planner>();
|
||||||
// svcs.Components.Add<IPlanner, RemovablePlanner>();
|
// svcs.Components.Add<IPlanner, RemovablePlanner>();
|
||||||
|
|
||||||
svcs.AddSingleton<IBotCredentials, IBotCredentials>(_ => _credsProvider.GetCreds());
|
svcs.AddSingleton<IBotCredentials>(_ => _credsProvider.GetCreds());
|
||||||
svcs.AddSingleton<DbService, DbService>(_db);
|
svcs.AddSingleton<DbService, DbService>(_db);
|
||||||
svcs.AddSingleton<IBotCredsProvider>(_credsProvider);
|
svcs.AddSingleton<IBotCredsProvider>(_credsProvider);
|
||||||
svcs.AddSingleton<DiscordSocketClient>(Client);
|
svcs.AddSingleton<DiscordSocketClient>(Client);
|
||||||
|
|
|
@ -546,7 +546,7 @@ public partial class Administration
|
||||||
text = await repSvc.ReplaceAsync(text, repCtx);
|
text = await repSvc.ReplaceAsync(text, repCtx);
|
||||||
await Response().Channel(ch).Text(text).SendAsync();
|
await Response().Channel(ch).Text(text).SendAsync();
|
||||||
|
|
||||||
await ctx.OkAsync();;
|
await ctx.OkAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
|
|
@ -31,7 +31,6 @@ public class PlantPickService : IEService, IExecNoCommand
|
||||||
|
|
||||||
public PlantPickService(
|
public PlantPickService(
|
||||||
DbService db,
|
DbService db,
|
||||||
CommandHandler cmd,
|
|
||||||
IBotStrings strings,
|
IBotStrings strings,
|
||||||
IImageCache images,
|
IImageCache images,
|
||||||
FontProvider fonts,
|
FontProvider fonts,
|
||||||
|
@ -107,7 +106,6 @@ public class PlantPickService : IEService, IExecNoCommand
|
||||||
/// Get a random currency image stream, with an optional password sticked onto it.
|
/// Get a random currency image stream, with an optional password sticked onto it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pass">Optional password to add to top left corner.</param>
|
/// <param name="pass">Optional password to add to top left corner.</param>
|
||||||
/// <param name="extension">Extension of the file, defaults to png</param>
|
|
||||||
/// <returns>Stream of the currency image</returns>
|
/// <returns>Stream of the currency image</returns>
|
||||||
public async Task<(Stream, string)> GetRandomCurrencyImageAsync(string pass)
|
public async Task<(Stream, string)> GetRandomCurrencyImageAsync(string pass)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@ using EllieBot.Modules.Gambling.Common;
|
||||||
using EllieBot.Modules.Gambling.Common.Waifu;
|
using EllieBot.Modules.Gambling.Common.Waifu;
|
||||||
using EllieBot.Modules.Gambling.Services;
|
using EllieBot.Modules.Gambling.Services;
|
||||||
using EllieBot.Db.Models;
|
using EllieBot.Db.Models;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace EllieBot.Modules.Gambling;
|
namespace EllieBot.Modules.Gambling;
|
||||||
|
|
||||||
|
@ -152,12 +153,12 @@ public partial class Gambling
|
||||||
await Response().Confirm(strs.waifu_divorced_notlike(N(amount))).SendAsync();
|
await Response().Confirm(strs.waifu_divorced_notlike(N(amount))).SendAsync();
|
||||||
else if (result == DivorceResult.NotYourWife)
|
else if (result == DivorceResult.NotYourWife)
|
||||||
await Response().Error(strs.waifu_not_yours).SendAsync();
|
await Response().Error(strs.waifu_not_yours).SendAsync();
|
||||||
else
|
else if (remaining is { } rem)
|
||||||
{
|
{
|
||||||
await Response()
|
await Response()
|
||||||
.Error(strs.waifu_recent_divorce(
|
.Error(strs.waifu_recent_divorce(
|
||||||
Format.Bold(((int)remaining?.TotalHours).ToString()),
|
Format.Bold(((int)rem.TotalHours).ToString()),
|
||||||
Format.Bold(remaining?.Minutes.ToString())))
|
Format.Bold(rem.Minutes.ToString())))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,7 +238,7 @@ public partial class Gambling
|
||||||
private string GetLbString(WaifuLbResult w)
|
private string GetLbString(WaifuLbResult w)
|
||||||
{
|
{
|
||||||
var claimer = "no one";
|
var claimer = "no one";
|
||||||
var status = string.Empty;
|
string status;
|
||||||
|
|
||||||
var waifuUsername = w.Username.TrimTo(20);
|
var waifuUsername = w.Username.TrimTo(20);
|
||||||
var claimerUsername = w.Claimer?.TrimTo(20);
|
var claimerUsername = w.Claimer?.TrimTo(20);
|
||||||
|
@ -376,7 +377,8 @@ public partial class Gambling
|
||||||
if (sucess)
|
if (sucess)
|
||||||
{
|
{
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm(strs.waifu_gift(Format.Bold($"{GetCountString(items)}{items.Item} {items.Item.ItemEmoji}"),
|
.Confirm(strs.waifu_gift(
|
||||||
|
Format.Bold($"{GetCountString(items)}{items.Item} {items.Item.ItemEmoji}"),
|
||||||
Format.Bold(waifu.ToString())))
|
Format.Bold(waifu.ToString())))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,9 +107,9 @@ public partial class Games
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private EmbedBuilder? questionEmbed = null;
|
private EmbedBuilder? questionEmbed;
|
||||||
private IUserMessage? questionMessage = null;
|
private IUserMessage? questionMessage;
|
||||||
private bool showHowToQuit = false;
|
private bool showHowToQuit;
|
||||||
|
|
||||||
private void RegisterEvents(TriviaGame trivia)
|
private void RegisterEvents(TriviaGame trivia)
|
||||||
{
|
{
|
|
@ -11,12 +11,19 @@ public sealed class TriviaGame
|
||||||
private readonly IQuestionPool _questionPool;
|
private readonly IQuestionPool _questionPool;
|
||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
|
|
||||||
public event Func<TriviaGame, TriviaQuestion, Task> OnQuestion = static delegate { return Task.CompletedTask; };
|
public event Func<TriviaGame, TriviaQuestion, Task> OnQuestion = static delegate { return Task.CompletedTask; };
|
||||||
public event Func<TriviaGame, TriviaQuestion, Task> OnHint = static delegate { return Task.CompletedTask; };
|
public event Func<TriviaGame, TriviaQuestion, Task> OnHint = static delegate { return Task.CompletedTask; };
|
||||||
public event Func<TriviaGame, Task> OnStats = static delegate { return Task.CompletedTask; };
|
public event Func<TriviaGame, Task> OnStats = static delegate { return Task.CompletedTask; };
|
||||||
public event Func<TriviaGame, TriviaUser, TriviaQuestion, bool, Task> OnGuess = static delegate { return Task.CompletedTask; };
|
|
||||||
|
public event Func<TriviaGame, TriviaUser, TriviaQuestion, bool, Task> OnGuess = static delegate
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
};
|
||||||
|
|
||||||
public event Func<TriviaGame, TriviaQuestion, Task> OnTimeout = static delegate { return Task.CompletedTask; };
|
public event Func<TriviaGame, TriviaQuestion, Task> OnTimeout = static delegate { return Task.CompletedTask; };
|
||||||
public event Func<TriviaGame, Task> OnEnded = static delegate { return Task.CompletedTask; };
|
public event Func<TriviaGame, Task> OnEnded = static delegate { return Task.CompletedTask; };
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private bool _isStopped;
|
private bool _isStopped;
|
||||||
|
@ -24,7 +31,7 @@ public sealed class TriviaGame
|
||||||
public TriviaQuestion? CurrentQuestion { get; set; }
|
public TriviaQuestion? CurrentQuestion { get; set; }
|
||||||
|
|
||||||
|
|
||||||
private readonly ConcurrentDictionary<ulong, int> _users = new ();
|
private readonly ConcurrentDictionary<ulong, int> _users = new();
|
||||||
|
|
||||||
private readonly Channel<(TriviaUser User, string Input)> _inputs
|
private readonly Channel<(TriviaUser User, string Input)> _inputs
|
||||||
= Channel.CreateUnbounded<(TriviaUser, string)>(new UnboundedChannelOptions
|
= Channel.CreateUnbounded<(TriviaUser, string)>(new UnboundedChannelOptions
|
||||||
|
@ -41,8 +48,8 @@ public sealed class TriviaGame
|
||||||
_questionPool = _opts.IsPokemon
|
_questionPool = _opts.IsPokemon
|
||||||
? new PokemonQuestionPool(cache)
|
? new PokemonQuestionPool(cache)
|
||||||
: new DefaultQuestionPool(cache);
|
: new DefaultQuestionPool(cache);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RunAsync()
|
public async Task RunAsync()
|
||||||
{
|
{
|
||||||
await GameLoop();
|
await GameLoop();
|
||||||
|
@ -50,7 +57,8 @@ public sealed class TriviaGame
|
||||||
|
|
||||||
private async Task GameLoop()
|
private async Task GameLoop()
|
||||||
{
|
{
|
||||||
Task TimeOutFactory() => Task.Delay(_opts.QuestionTimer * 1000 / 2);
|
Task TimeOutFactory()
|
||||||
|
=> Task.Delay(_opts.QuestionTimer * 1000 / 2);
|
||||||
|
|
||||||
var errorCount = 0;
|
var errorCount = 0;
|
||||||
var inactivity = 0;
|
var inactivity = 0;
|
||||||
|
@ -91,7 +99,8 @@ public sealed class TriviaGame
|
||||||
{
|
{
|
||||||
// clear out all of the past guesses
|
// clear out all of the past guesses
|
||||||
while (_inputs.Reader.TryRead(out _))
|
while (_inputs.Reader.TryRead(out _))
|
||||||
;
|
{
|
||||||
|
}
|
||||||
|
|
||||||
await OnQuestion(this, question);
|
await OnQuestion(this, question);
|
||||||
}
|
}
|
||||||
|
@ -213,7 +222,7 @@ public sealed class TriviaGame
|
||||||
|
|
||||||
public async Task TriggerQuestionAsync()
|
public async Task TriggerQuestionAsync()
|
||||||
{
|
{
|
||||||
if(CurrentQuestion is TriviaQuestion q)
|
if (CurrentQuestion is TriviaQuestion q)
|
||||||
await OnQuestion(this, q);
|
await OnQuestion(this, q);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -61,8 +61,8 @@ public class RadioResolver : IRadioResolver
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var m = _m3URegex.Match(file);
|
var m = _m3URegex.Match(file);
|
||||||
var res = m.Groups["url"]?.ToString();
|
var res = m.Groups["url"].ToString();
|
||||||
return res?.Trim();
|
return res.Trim();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
@ -76,8 +76,8 @@ public class RadioResolver : IRadioResolver
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var m = _asxRegex.Match(file);
|
var m = _asxRegex.Match(file);
|
||||||
var res = m.Groups["url"]?.ToString();
|
var res = m.Groups["url"].ToString();
|
||||||
return res?.Trim();
|
return res.Trim();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
@ -91,8 +91,8 @@ public class RadioResolver : IRadioResolver
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var m = _xspfRegex.Match(file);
|
var m = _xspfRegex.Match(file);
|
||||||
var res = m.Groups["url"]?.ToString();
|
var res = m.Groups["url"].ToString();
|
||||||
return res?.Trim();
|
return res.Trim();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,16 +19,11 @@ public sealed class PatronageService
|
||||||
public int Priority
|
public int Priority
|
||||||
=> int.MinValue;
|
=> int.MinValue;
|
||||||
|
|
||||||
private static readonly PatronTier[] _tiers = Enum.GetValues<PatronTier>();
|
|
||||||
|
|
||||||
private readonly PatronageConfig _pConf;
|
private readonly PatronageConfig _pConf;
|
||||||
private readonly DbService _db;
|
private readonly DbService _db;
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
private readonly ISubscriptionHandler _subsHandler;
|
private readonly ISubscriptionHandler _subsHandler;
|
||||||
|
|
||||||
private static readonly TypedKey<long> _quotaKey
|
|
||||||
= new($"quota:last_hourly_reset");
|
|
||||||
|
|
||||||
private readonly IBotCache _cache;
|
private readonly IBotCache _cache;
|
||||||
private readonly IBotCredsProvider _creds;
|
private readonly IBotCredsProvider _creds;
|
||||||
private readonly IMessageSenderService _sender;
|
private readonly IMessageSenderService _sender;
|
||||||
|
@ -133,19 +128,19 @@ public sealed class PatronageService
|
||||||
// user is charged again for this month
|
// user is charged again for this month
|
||||||
// if his sub would end in teh future, extend it by one month.
|
// if his sub would end in teh future, extend it by one month.
|
||||||
// if it's not, just add 1 month to the last charge date
|
// if it's not, just add 1 month to the last charge date
|
||||||
var count = await ctx.GetTable<PatronUser>()
|
await ctx.GetTable<PatronUser>()
|
||||||
.Where(x => x.UniquePlatformUserId
|
.Where(x => x.UniquePlatformUserId
|
||||||
== subscriber.UniquePlatformUserId)
|
== subscriber.UniquePlatformUserId)
|
||||||
.UpdateAsync(old => new()
|
.UpdateAsync(old => new()
|
||||||
{
|
{
|
||||||
UserId = subscriber.UserId,
|
UserId = subscriber.UserId,
|
||||||
AmountCents = subscriber.Cents,
|
AmountCents = subscriber.Cents,
|
||||||
LastCharge = lastChargeUtc,
|
LastCharge = lastChargeUtc,
|
||||||
ValidThru = old.ValidThru >= todayDate
|
ValidThru = old.ValidThru >= todayDate
|
||||||
// ? Sql.DateAdd(Sql.DateParts.Month, 1, old.ValidThru).Value
|
// ? Sql.DateAdd(Sql.DateParts.Month, 1, old.ValidThru).Value
|
||||||
? old.ValidThru.AddMonths(1)
|
? old.ValidThru.AddMonths(1)
|
||||||
: dateInOneMonth,
|
: dateInOneMonth,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
dbPatron.UserId = subscriber.UserId;
|
dbPatron.UserId = subscriber.UserId;
|
||||||
|
|
|
@ -65,18 +65,6 @@ public partial class Searches
|
||||||
var change = (stock.Price - stock.Close).ToString("N2", Culture);
|
var change = (stock.Price - stock.Close).ToString("N2", Culture);
|
||||||
var changePercent = (1 - (stock.Close / stock.Price)).ToString("P1", Culture);
|
var changePercent = (1 - (stock.Close / stock.Price)).ToString("P1", Culture);
|
||||||
|
|
||||||
var sign50 = stock.Change50d >= 0
|
|
||||||
? "\\🔼"
|
|
||||||
: "\\🔻";
|
|
||||||
|
|
||||||
var change50 = (stock.Change50d).ToString("P1", Culture);
|
|
||||||
|
|
||||||
var sign200 = stock.Change200d >= 0
|
|
||||||
? "\\🔼"
|
|
||||||
: "\\🔻";
|
|
||||||
|
|
||||||
var change200 = (stock.Change200d).ToString("P1", Culture);
|
|
||||||
|
|
||||||
var price = stock.Price.ToString("C2", localCulture);
|
var price = stock.Price.ToString("C2", localCulture);
|
||||||
|
|
||||||
var eb = _sender.CreateEmbed()
|
var eb = _sender.CreateEmbed()
|
||||||
|
|
|
@ -19,7 +19,6 @@ public sealed class GiveawayService : IEService, IReadyExecutor
|
||||||
private readonly IMemoryCache _cache;
|
private readonly IMemoryCache _cache;
|
||||||
private SortedSet<GiveawayModel> _giveawayCache = new SortedSet<GiveawayModel>();
|
private SortedSet<GiveawayModel> _giveawayCache = new SortedSet<GiveawayModel>();
|
||||||
private readonly EllieRandom _rng;
|
private readonly EllieRandom _rng;
|
||||||
private readonly ConcurrentDictionary<int, GiveawayRerollData> _rerolls = new();
|
|
||||||
|
|
||||||
public GiveawayService(DbService db, IBotCredentials creds, DiscordSocketClient client,
|
public GiveawayService(DbService db, IBotCredentials creds, DiscordSocketClient client,
|
||||||
IMessageSenderService sender, IBotStrings strings, ILocalization localization, IMemoryCache cache)
|
IMessageSenderService sender, IBotStrings strings, ILocalization localization, IMemoryCache cache)
|
||||||
|
|
|
@ -20,14 +20,6 @@ public static class DryIocExtensions
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IContainer AddSingleton<TSvc, TImpl>(this IContainer container, Func<IResolverContext, TSvc> factory)
|
|
||||||
where TImpl : TSvc
|
|
||||||
{
|
|
||||||
container.RegisterDelegate(factory, Reuse.Singleton);
|
|
||||||
|
|
||||||
return container;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IContainer AddSingleton<TImpl>(this IContainer container)
|
public static IContainer AddSingleton<TImpl>(this IContainer container)
|
||||||
{
|
{
|
||||||
container.Register<TImpl>(Reuse.Singleton);
|
container.Register<TImpl>(Reuse.Singleton);
|
|
@ -34,7 +34,7 @@ public sealed class MarmaladeNinjectIocModule : IIocModule, IDisposable
|
||||||
if (isLoaded)
|
if (isLoaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var (type, data) in _types)
|
foreach (var (type, _) in _types)
|
||||||
{
|
{
|
||||||
var attribute = type.GetCustomAttribute<svcAttribute>()!;
|
var attribute = type.GetCustomAttribute<svcAttribute>()!;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue