.gc will now remove previous plants with the same pw length from the channel and add them to itself. This is to avoid missed gcs. The amount text will be wrong however, as it will only show how much flowers spawned now. The user will get full amount of all gcs previously

This commit is contained in:
Toastie 2024-11-28 19:38:28 +13:00
parent ae338db294
commit e127133612
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
4 changed files with 47 additions and 18 deletions

View file

@ -13,7 +13,7 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
- `.btr rm` to remove a button role from the specified message - `.btr rm` to remove a button role from the specified message
- `.btr rma` to remove all button roles on the specified message - `.btr rma` to remove all button roles on the specified message
- `.btr excl` to toggle exclusive button roles (only 1 role per message or any number) - `.btr excl` to toggle exclusive button roles (only 1 role per message or any number)
- Use `.h` on any of the above for more info - Use `.h btr` for more info
- Added `.wrongsong` which will delete the last queued song. - Added `.wrongsong` which will delete the last queued song.
- Useful in case you made a mistake, or the bot queued a wrong song - Useful in case you made a mistake, or the bot queued a wrong song
- It will reset after a shuffle or fairplay toggle, or similar events. - It will reset after a shuffle or fairplay toggle, or similar events.

View file

@ -391,6 +391,12 @@ public partial class Gambling : GamblingModule<GamblingService>
public Task CurrencyTransactions([Leftover] IUser usr) public Task CurrencyTransactions([Leftover] IUser usr)
=> InternalCurrencyTransactions(usr.Id, 1); => InternalCurrencyTransactions(usr.Id, 1);
[Cmd]
[OwnerOnly]
[Priority(-1)]
public Task CurrencyTransactions([Leftover] ulong userId)
=> InternalCurrencyTransactions(userId, 1);
[Cmd] [Cmd]
[OwnerOnly] [OwnerOnly]
[Priority(1)] [Priority(1)]

View file

@ -59,7 +59,7 @@ public partial class Gambling
} }
var success = await _service.PlantAsync(ctx.Guild.Id, var success = await _service.PlantAsync(ctx.Guild.Id,
ctx.Channel, (ITextChannel)ctx.Channel,
ctx.User.Id, ctx.User.Id,
ctx.User.ToString(), ctx.User.ToString(),
amount, amount,

View file

@ -241,12 +241,18 @@ public class PlantPickService : IEService, IExecNoCommand
await using (stream) await using (stream)
sent = await channel.SendFileAsync(stream, $"currency_image.{ext}", toSend); sent = await channel.SendFileAsync(stream, $"currency_image.{ext}", toSend);
await AddPlantToDatabase(channel.GuildId, var res = await AddPlantToDatabase(channel.GuildId,
channel.Id, channel.Id,
_client.CurrentUser.Id, _client.CurrentUser.Id,
sent.Id, sent.Id,
dropAmount, dropAmount,
pw); pw,
true);
if (res.toDelete.Length > 0)
{
await channel.DeleteMessagesAsync(res.toDelete);
}
} }
} }
} }
@ -335,7 +341,7 @@ public class PlantPickService : IEService, IExecNoCommand
public async Task<bool> PlantAsync( public async Task<bool> PlantAsync(
ulong gid, ulong gid,
IMessageChannel ch, ITextChannel ch,
ulong uid, ulong uid,
string user, string user,
long amount, long amount,
@ -361,6 +367,7 @@ public class PlantPickService : IEService, IExecNoCommand
// if it doesn't fail, put the plant in the database for other people to pick // if it doesn't fail, put the plant in the database for other people to pick
await AddPlantToDatabase(gid, ch.Id, uid, msgId.Value, amount, pass); await AddPlantToDatabase(gid, ch.Id, uid, msgId.Value, amount, pass);
return true; return true;
} }
@ -368,25 +375,41 @@ public class PlantPickService : IEService, IExecNoCommand
return false; return false;
} }
private async Task AddPlantToDatabase( private async Task<(long totalAmount, ulong[] toDelete)> AddPlantToDatabase(
ulong gid, ulong gid,
ulong cid, ulong cid,
ulong uid, ulong uid,
ulong mid, ulong mid,
long amount, long amount,
string pass) string pass,
bool auto = false)
{ {
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
uow.Set<PlantedCurrency>()
.Add(new() PlantedCurrency[] deleted = [];
{ if (!string.IsNullOrWhiteSpace(pass) && auto)
Amount = amount, {
GuildId = gid, deleted = await uow.GetTable<PlantedCurrency>()
ChannelId = cid, .Where(x => x.GuildId == gid
Password = pass, && x.ChannelId == cid
UserId = uid, && x.Password != null
MessageId = mid && x.Password.Length == pass.Length)
}); .DeleteWithOutputAsync();
await uow.SaveChangesAsync(); }
var totalDeletedAmount = deleted.Length == 0 ? 0 : deleted.Sum(x => x.Amount);
await uow.GetTable<PlantedCurrency>()
.InsertAsync(() => new()
{
Amount = totalDeletedAmount + amount,
GuildId = gid,
ChannelId = cid,
Password = pass,
UserId = uid,
MessageId = mid,
});
return (totalDeletedAmount + amount, deleted.Select(x => x.MessageId).ToArray());
} }
} }