mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
change: gambling commands now show amount bet. Slightly changed the layout. Updated some gambling strings
add: added .btr excl
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using NadekoBot.Db.Models;
|
||||
using NadekoBot.Common.TypeReaders.Models;
|
||||
using NadekoBot.Db.Models;
|
||||
using NadekoBot.Modules.Administration.Services;
|
||||
using System.Text;
|
||||
using ContextType = Discord.Commands.ContextType;
|
||||
@@ -7,6 +8,7 @@ namespace NadekoBot.Modules.Administration;
|
||||
|
||||
public partial class Administration
|
||||
{
|
||||
[Group("btr")]
|
||||
public partial class ButtonRoleCommands : NadekoModule<ButtonRolesService>
|
||||
{
|
||||
private List<ActionRowBuilder> GetActionRows(IReadOnlyList<ButtonRole> roles)
|
||||
@@ -228,7 +230,7 @@ public partial class Administration
|
||||
{
|
||||
eb.WithPendingColor()
|
||||
.WithDescription(GetText(strs.btnrole_none));
|
||||
|
||||
|
||||
return eb;
|
||||
}
|
||||
|
||||
@@ -265,5 +267,30 @@ public partial class Administration
|
||||
})
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[BotPerm(GuildPerm.ManageRoles)]
|
||||
[RequireUserPermission(GuildPerm.ManageRoles)]
|
||||
public Task BtnRoleExclusive(MessageLink link, PermissionAction exclusive)
|
||||
=> BtnRoleExclusive(link.Message.Id, exclusive);
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[BotPerm(GuildPerm.ManageRoles)]
|
||||
[RequireUserPermission(GuildPerm.ManageRoles)]
|
||||
public async Task BtnRoleExclusive(ulong messageId, PermissionAction exclusive)
|
||||
{
|
||||
var res = await _service.SetExclusiveButtonRoles(ctx.Guild.Id, messageId, exclusive.Value);
|
||||
|
||||
if (res)
|
||||
{
|
||||
await Response().Confirm(strs.btnrole_exclusive).SendAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await Response().Confirm(strs.btnrole_multiple).SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -42,32 +42,49 @@ public sealed class ButtonRolesService : INService, IReadyExecutor
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
var buttonRole = await uow.GetTable<ButtonRole>()
|
||||
.Where(x => x.ButtonId == smc.Data.CustomId && x.MessageId == smc.Message.Id)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
|
||||
if (buttonRole is null)
|
||||
return;
|
||||
|
||||
var guild = _client.GetGuild(buttonRole.GuildId);
|
||||
if (guild is null)
|
||||
return;
|
||||
|
||||
var role = guild.GetRole(buttonRole.RoleId);
|
||||
if (role is null)
|
||||
return;
|
||||
|
||||
if (smc.User is not IGuildUser user)
|
||||
return;
|
||||
|
||||
if (user.GetRoles().Any(x => x.Id == role.Id))
|
||||
try
|
||||
{
|
||||
await user.RemoveRoleAsync(role.Id);
|
||||
return;
|
||||
}
|
||||
await using var uow = _db.GetDbContext();
|
||||
var buttonRole = await uow.GetTable<ButtonRole>()
|
||||
.Where(x => x.ButtonId == smc.Data.CustomId && x.MessageId == smc.Message.Id)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
|
||||
await user.AddRoleAsync(role.Id);
|
||||
if (buttonRole is null)
|
||||
return;
|
||||
|
||||
var guild = _client.GetGuild(buttonRole.GuildId);
|
||||
if (guild is null)
|
||||
return;
|
||||
|
||||
var role = guild.GetRole(buttonRole.RoleId);
|
||||
if (role is null)
|
||||
return;
|
||||
|
||||
if (smc.User is not IGuildUser user)
|
||||
return;
|
||||
|
||||
if (user.GetRoles().Any(x => x.Id == role.Id))
|
||||
{
|
||||
await user.RemoveRoleAsync(role.Id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (buttonRole.Exclusive)
|
||||
{
|
||||
var otherRoles = await uow.GetTable<ButtonRole>()
|
||||
.Where(x => x.GuildId == smc.GuildId && x.MessageId == smc.Message.Id)
|
||||
.Select(x => x.RoleId)
|
||||
.ToListAsyncLinqToDB();
|
||||
|
||||
await user.RemoveRolesAsync(otherRoles);
|
||||
}
|
||||
|
||||
await user.AddRoleAsync(role.Id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Unable to handle button role interaction for user {UserId}", inter.User.Id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -108,7 +125,8 @@ public sealed class ButtonRolesService : INService, IReadyExecutor
|
||||
: 1,
|
||||
Emote = emoteStr,
|
||||
Label = string.Empty,
|
||||
ButtonId = $"{BTN_PREFIX}:{guildId}:{guid}"
|
||||
ButtonId = $"{BTN_PREFIX}:{guildId}:{guid}",
|
||||
Exclusive = (uow.GetTable<ButtonRole>().Where(x => x.GuildId == guildId && x.MessageId == messageId).All(x => x.Exclusive))
|
||||
},
|
||||
_ => new()
|
||||
{
|
||||
@@ -151,4 +169,16 @@ public sealed class ButtonRolesService : INService, IReadyExecutor
|
||||
.OrderBy(x => x.Id)
|
||||
.ToListAsyncLinqToDB();
|
||||
}
|
||||
|
||||
public async Task<bool> SetExclusiveButtonRoles(ulong guildId, ulong messageId, bool exclusive)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
return await uow.GetTable<ButtonRole>()
|
||||
.Where(x => x.GuildId == guildId && x.MessageId == messageId)
|
||||
.UpdateAsync((_) => new()
|
||||
{
|
||||
Exclusive = exclusive
|
||||
})
|
||||
> 0;
|
||||
}
|
||||
}
|
@@ -57,7 +57,7 @@ public partial class Gambling
|
||||
i.Dispose();
|
||||
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor();
|
||||
.WithOkColor();
|
||||
|
||||
var toSend = string.Empty;
|
||||
if (cardObjects.Count == 5)
|
||||
@@ -172,13 +172,14 @@ public partial class Gambling
|
||||
}
|
||||
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithAuthor(ctx.User)
|
||||
.WithDescription(result.Card.GetEmoji())
|
||||
.AddField(GetText(strs.guess), GetGuessInfo(val, col), true)
|
||||
.AddField(GetText(strs.card), GetCardInfo(result.Card), true)
|
||||
.AddField(GetText(strs.won), N((long)result.Won), false)
|
||||
.WithImageUrl("attachment://card.png");
|
||||
.WithOkColor()
|
||||
.WithAuthor(ctx.User)
|
||||
.WithDescription(result.Card.GetEmoji())
|
||||
.AddField(GetText(strs.guess), GetGuessInfo(val, col), true)
|
||||
.AddField(GetText(strs.card), GetCardInfo(result.Card), false)
|
||||
.AddField(GetText(strs.bet), N(amount), true)
|
||||
.AddField(GetText(strs.won), N((long)result.Won), true)
|
||||
.WithImageUrl("attachment://card.png");
|
||||
|
||||
using var img = await GetCardImageAsync(result.Card);
|
||||
await using var imgStream = await img.ToStreamAsync();
|
||||
|
@@ -56,7 +56,7 @@ public partial class Gambling
|
||||
var tailsArr = await _images.GetTailsImageAsync();
|
||||
|
||||
var result = await _service.FlipAsync(count);
|
||||
|
||||
|
||||
for (var i = 0; i < result.Length; i++)
|
||||
{
|
||||
if (result[i].Side == 0)
|
||||
@@ -77,18 +77,18 @@ public partial class Gambling
|
||||
i.Dispose();
|
||||
|
||||
var imgName = $"coins.{format.FileExtensions.First()}";
|
||||
|
||||
|
||||
var msg = count != 1
|
||||
? Format.Bold(GetText(strs.flip_results(count, headCount, tailCount)))
|
||||
: GetText(strs.flipped(headCount > 0
|
||||
? Format.Bold(GetText(strs.heads))
|
||||
: Format.Bold(GetText(strs.tails))));
|
||||
|
||||
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithAuthor(ctx.User)
|
||||
.WithDescription(msg)
|
||||
.WithImageUrl($"attachment://{imgName}");
|
||||
.WithOkColor()
|
||||
.WithAuthor(ctx.User)
|
||||
.WithDescription(msg)
|
||||
.WithImageUrl($"attachment://{imgName}");
|
||||
|
||||
await ctx.Channel.SendFileAsync(stream,
|
||||
imgName,
|
||||
@@ -123,18 +123,22 @@ public partial class Gambling
|
||||
var won = (long)result.Won;
|
||||
if (won > 0)
|
||||
{
|
||||
str = Format.Bold(GetText(strs.flip_guess(N(won))));
|
||||
str = Format.Bold(GetText(strs.betflip_guess));
|
||||
}
|
||||
else
|
||||
{
|
||||
str = Format.Bold(GetText(strs.better_luck));
|
||||
}
|
||||
|
||||
await Response().Embed(CreateEmbed()
|
||||
.WithAuthor(ctx.User)
|
||||
.WithDescription(str)
|
||||
.WithOkColor()
|
||||
.WithImageUrl(imageToSend.ToString())).SendAsync();
|
||||
await Response()
|
||||
.Embed(CreateEmbed()
|
||||
.WithAuthor(ctx.User)
|
||||
.WithDescription(str)
|
||||
.AddField(GetText(strs.bet), N(amount), true)
|
||||
.AddField(GetText(strs.won), N((long)result.Won), true)
|
||||
.WithOkColor()
|
||||
.WithImageUrl(imageToSend.ToString()))
|
||||
.SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
@@ -718,7 +718,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
string str;
|
||||
if (win > 0)
|
||||
{
|
||||
str = GetText(strs.br_win(N(win), result.Threshold + (result.Roll == 100 ? " 👑" : "")));
|
||||
str = GetText(strs.betroll_win(result.Threshold + (result.Roll == 100 ? " 👑" : "")));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -728,7 +728,9 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
var eb = CreateEmbed()
|
||||
.WithAuthor(ctx.User)
|
||||
.WithDescription(Format.Bold(str))
|
||||
.AddField(GetText(strs.roll2), result.Roll.ToString(CultureInfo.InvariantCulture))
|
||||
.AddField(GetText(strs.roll2), result.Roll.ToString(CultureInfo.InvariantCulture), true)
|
||||
.AddField(GetText(strs.bet), N(amount), true)
|
||||
.AddField(GetText(strs.won), N((long)result.Won), true)
|
||||
.WithOkColor();
|
||||
|
||||
await Response().Embed(eb).SendAsync();
|
||||
@@ -922,8 +924,8 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithDescription(sb.ToString())
|
||||
.AddField(GetText(strs.multiplier), $"{result.Multiplier:0.##}x", true)
|
||||
.AddField(GetText(strs.won), $"{(long)result.Won}", true)
|
||||
.AddField(GetText(strs.bet), N(amount), true)
|
||||
.AddField(GetText(strs.won), $"{N((long)result.Won)}", true)
|
||||
.WithAuthor(ctx.User);
|
||||
|
||||
|
||||
|
@@ -66,10 +66,10 @@ public partial class Gambling
|
||||
|
||||
|
||||
var eb = CreateEmbed()
|
||||
.WithAuthor(ctx.User)
|
||||
.WithDescription(Format.Bold(text))
|
||||
.WithImageUrl($"attachment://result.png")
|
||||
.WithOkColor();
|
||||
.WithAuthor(ctx.User)
|
||||
.WithDescription(Format.Bold(text))
|
||||
.WithImageUrl($"attachment://result.png")
|
||||
.WithOkColor();
|
||||
|
||||
var bb = new ButtonBuilder(emote: Emoji.Parse("🔁"), customId: "slot:again", label: "Pull Again");
|
||||
var inter = _inter.Create(ctx.User.Id,
|
||||
@@ -168,7 +168,8 @@ public partial class Gambling
|
||||
await using (var uow = _db.GetDbContext())
|
||||
{
|
||||
ownedAmount = uow.Set<DiscordUser>()
|
||||
.FirstOrDefault(x => x.UserId == ctx.User.Id)?.CurrencyAmount
|
||||
.FirstOrDefault(x => x.UserId == ctx.User.Id)
|
||||
?.CurrencyAmount
|
||||
?? 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user