vote has no cooldown, fixed some responses, improved voting logic
This commit is contained in:
parent
aaf8522987
commit
07df2ed450
4 changed files with 6 additions and 40 deletions
src/EllieBot
|
@ -152,29 +152,12 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
return;
|
||||
}
|
||||
|
||||
if (await _vrs.LastVoted(ctx.User.Id) is { } remainder)
|
||||
{
|
||||
// Get correct time form remainder
|
||||
var interaction = CreateRemindMeInteraction(remainder.TotalMilliseconds);
|
||||
|
||||
// Removes timely button if there is a timely reminder in DB
|
||||
if (_service.UserHasTimelyReminder(ctx.User.Id))
|
||||
{
|
||||
interaction = null;
|
||||
}
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var relativeTag = TimestampTag.FromDateTime(now.Add(remainder), TimestampTagStyles.Relative);
|
||||
await Response().Pending(strs.vote_already_claimed(relativeTag)).Interaction(interaction).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var (amount, msg) = await _service.GetAmountAndMessage(ctx.User.Id, reward);
|
||||
|
||||
var prepend = GetText(strs.vote_suggest(Format.Bold(N(amount))));
|
||||
msg = prepend + "\n\n" + msg;
|
||||
|
||||
var inter = CreateRemindMeInteraction(6) as EllieButtonInteractionHandler;
|
||||
var inter = CreateRemindMeInteraction(12) as EllieButtonInteractionHandler;
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithDescription(msg);
|
||||
|
|
|
@ -10,15 +10,11 @@ public class VoteRewardService(
|
|||
GamblingConfigService gcs,
|
||||
GamblingService gs,
|
||||
CurrencyService cs,
|
||||
IBotCache cache,
|
||||
DiscordSocketClient client,
|
||||
IMessageSenderService sender,
|
||||
IBotCreds creds
|
||||
) : IEService, IReadyExecutor
|
||||
{
|
||||
private TypedKey<DateTime> VoteKey(ulong userId)
|
||||
=> new($"vote:{userId}");
|
||||
|
||||
private Server? _app;
|
||||
private IMessageChannel? _voteFeedChannel;
|
||||
|
||||
|
@ -63,13 +59,6 @@ public class VoteRewardService(
|
|||
if (reward <= 0)
|
||||
return;
|
||||
|
||||
var key = VoteKey(userId);
|
||||
if (!await cache.AddAsync(key, DateTime.UtcNow, expiry: TimeSpan.FromHours(6)))
|
||||
{
|
||||
Log.Information("User {UserId} has already voted in the last 6 hours", userId);
|
||||
return;
|
||||
}
|
||||
|
||||
(reward, var msg) = await gs.GetAmountAndMessage(userId, reward);
|
||||
await cs.AddAsync(userId, reward, new("vote", requestType.ToString()));
|
||||
|
||||
|
@ -79,7 +68,8 @@ public class VoteRewardService(
|
|||
{
|
||||
var user = await client.GetUserAsync(userId);
|
||||
|
||||
await sender.Response(user)
|
||||
await sender
|
||||
.Response(user)
|
||||
.Confirm(strs.vote_reward(N(reward)) + "\n\n" + msg)
|
||||
.SendAsync();
|
||||
}
|
||||
|
@ -108,15 +98,6 @@ public class VoteRewardService(
|
|||
});
|
||||
}
|
||||
|
||||
public async Task<TimeSpan?> LastVoted(ulong userId)
|
||||
{
|
||||
var key = VoteKey(userId);
|
||||
var last = await cache.GetAsync(key);
|
||||
return last.Match(
|
||||
static x => DateTime.UtcNow.Subtract(x),
|
||||
static _ => default(TimeSpan?));
|
||||
}
|
||||
|
||||
private string N(long amount)
|
||||
=> CurrencyHelper.N(amount, CultureInfo.InvariantCulture, gcs.Data.Currency.Sign);
|
||||
}
|
||||
|
|
|
@ -1661,6 +1661,9 @@ questlog:
|
|||
- questlog
|
||||
- qlog
|
||||
- myquests
|
||||
- quest
|
||||
- quests
|
||||
- dailies
|
||||
fishshop:
|
||||
- fishshop
|
||||
- fishop
|
||||
|
|
|
@ -930,7 +930,6 @@
|
|||
"autodc_disable": "I will no longer disconnect from the voice channel when there are no more tracks to play.",
|
||||
"timely_none": "Bot owner didn't specify a timely reward.",
|
||||
"timely_already_claimed": "You've already claimed your timely reward. You can get it again {0}.",
|
||||
"vote_already_claimed": "You've already voted. You can vote again {0}.",
|
||||
"timely": "You've claimed your {0}. You can claim again in {1}h",
|
||||
"timely_set": "Users will be able to claim {0} every {1}h",
|
||||
"timely_set_none": "Users will not be able to claim any timely currency.",
|
||||
|
|
Loading…
Add table
Reference in a new issue