.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:
parent
ae338db294
commit
e127133612
4 changed files with 47 additions and 18 deletions
|
@ -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 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)
|
||||
- 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.
|
||||
- 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.
|
||||
|
|
|
@ -391,6 +391,12 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
public Task CurrencyTransactions([Leftover] IUser usr)
|
||||
=> InternalCurrencyTransactions(usr.Id, 1);
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
[Priority(-1)]
|
||||
public Task CurrencyTransactions([Leftover] ulong userId)
|
||||
=> InternalCurrencyTransactions(userId, 1);
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
[Priority(1)]
|
||||
|
|
|
@ -59,7 +59,7 @@ public partial class Gambling
|
|||
}
|
||||
|
||||
var success = await _service.PlantAsync(ctx.Guild.Id,
|
||||
ctx.Channel,
|
||||
(ITextChannel)ctx.Channel,
|
||||
ctx.User.Id,
|
||||
ctx.User.ToString(),
|
||||
amount,
|
||||
|
|
|
@ -241,12 +241,18 @@ public class PlantPickService : IEService, IExecNoCommand
|
|||
await using (stream)
|
||||
sent = await channel.SendFileAsync(stream, $"currency_image.{ext}", toSend);
|
||||
|
||||
await AddPlantToDatabase(channel.GuildId,
|
||||
var res = await AddPlantToDatabase(channel.GuildId,
|
||||
channel.Id,
|
||||
_client.CurrentUser.Id,
|
||||
sent.Id,
|
||||
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(
|
||||
ulong gid,
|
||||
IMessageChannel ch,
|
||||
ITextChannel ch,
|
||||
ulong uid,
|
||||
string user,
|
||||
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
|
||||
await AddPlantToDatabase(gid, ch.Id, uid, msgId.Value, amount, pass);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -368,25 +375,41 @@ public class PlantPickService : IEService, IExecNoCommand
|
|||
return false;
|
||||
}
|
||||
|
||||
private async Task AddPlantToDatabase(
|
||||
private async Task<(long totalAmount, ulong[] toDelete)> AddPlantToDatabase(
|
||||
ulong gid,
|
||||
ulong cid,
|
||||
ulong uid,
|
||||
ulong mid,
|
||||
long amount,
|
||||
string pass)
|
||||
string pass,
|
||||
bool auto = false)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
uow.Set<PlantedCurrency>()
|
||||
.Add(new()
|
||||
|
||||
PlantedCurrency[] deleted = [];
|
||||
if (!string.IsNullOrWhiteSpace(pass) && auto)
|
||||
{
|
||||
Amount = amount,
|
||||
deleted = await uow.GetTable<PlantedCurrency>()
|
||||
.Where(x => x.GuildId == gid
|
||||
&& x.ChannelId == cid
|
||||
&& x.Password != null
|
||||
&& x.Password.Length == pass.Length)
|
||||
.DeleteWithOutputAsync();
|
||||
}
|
||||
|
||||
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
|
||||
MessageId = mid,
|
||||
});
|
||||
await uow.SaveChangesAsync();
|
||||
|
||||
return (totalDeletedAmount + amount, deleted.Select(x => x.MessageId).ToArray());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue