part 3 of the response rework

This commit is contained in:
Kwoth
2024-04-29 21:03:40 +00:00
parent d28c7b500d
commit daa2177559
65 changed files with 508 additions and 625 deletions

View File

@@ -12,12 +12,15 @@ public class CurrencyEventsService : INService
private readonly GamblingConfigService _configService;
private readonly ConcurrentDictionary<ulong, ICurrencyEvent> _events = new();
private readonly IMessageSenderService _sender;
public CurrencyEventsService(DiscordSocketClient client, ICurrencyService cs, GamblingConfigService configService)
public CurrencyEventsService(DiscordSocketClient client, ICurrencyService cs, GamblingConfigService configService,
IMessageSenderService sender)
{
_client = client;
_cs = cs;
_configService = configService;
_sender = sender;
}
public async Task<bool> TryCreateEventAsync(
@@ -34,9 +37,9 @@ public class CurrencyEventsService : INService
ICurrencyEvent ce;
if (type == CurrencyEvent.Type.Reaction)
ce = new ReactionEvent(_client, _cs, g, ch, opts, _configService.Data, embed);
ce = new ReactionEvent(_client, _cs, g, ch, opts, _configService.Data, _sender, embed);
else if (type == CurrencyEvent.Type.GameStatus)
ce = new GameStatusEvent(_client, _cs, g, ch, opts, embed);
ce = new GameStatusEvent(_client, _cs, g, ch, opts, _sender, embed);
else
return false;

View File

@@ -36,6 +36,7 @@ public class GameStatusEvent : ICurrencyEvent
private readonly object _stopLock = new();
private readonly object _potLock = new();
private readonly IMessageSenderService _sender;
public GameStatusEvent(
DiscordSocketClient client,
@@ -43,6 +44,7 @@ public class GameStatusEvent : ICurrencyEvent
SocketGuild g,
ITextChannel ch,
EventOptions opt,
IMessageSenderService sender,
Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> embedFunc)
{
_client = client;
@@ -54,6 +56,7 @@ public class GameStatusEvent : ICurrencyEvent
_isPotLimited = PotSize > 0;
_channel = ch;
_opts = opt;
_sender = sender;
// generate code
_code = new(_sneakyGameStatusChars.Shuffle().Take(5).ToArray());
@@ -106,7 +109,7 @@ public class GameStatusEvent : ICurrencyEvent
public async Task StartEvent()
{
msg = await _channel.EmbedAsync(GetEmbed(_opts.PotSize));
msg = await _sender.Response(_channel).Embed(GetEmbed(_opts.PotSize)).SendAsync();
await _client.SetGameAsync(_code);
_client.MessageDeleted += OnMessageDeleted;
_client.MessageReceived += HandleMessage;

View File

@@ -30,6 +30,7 @@ public class ReactionEvent : ICurrencyEvent
private readonly object _stopLock = new();
private readonly object _potLock = new();
private readonly IMessageSenderService _sender;
public ReactionEvent(
DiscordSocketClient client,
@@ -38,6 +39,7 @@ public class ReactionEvent : ICurrencyEvent
ITextChannel ch,
EventOptions opt,
GamblingConfig config,
IMessageSenderService sender,
Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> embedFunc)
{
_client = client;
@@ -51,6 +53,7 @@ public class ReactionEvent : ICurrencyEvent
_noRecentlyJoinedServer = false;
_opts = opt;
_config = config;
_sender = sender;
_t = new(OnTimerTick, null, Timeout.InfiniteTimeSpan, TimeSpan.FromSeconds(2));
if (_opts.Hours > 0)
@@ -102,7 +105,7 @@ public class ReactionEvent : ICurrencyEvent
emote = parsedEmote;
else
emote = new Emoji(_config.Currency.Sign);
msg = await _channel.EmbedAsync(GetEmbed(_opts.PotSize));
msg = await _sender.Response(_channel).Embed(GetEmbed(_opts.PotSize)).SendAsync();
await msg.AddReactionAsync(emote);
_client.MessageDeleted += OnMessageDeleted;
_client.ReactionAdded += HandleReaction;