Skip to content

Commit

Permalink
disable giving up for others
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mk committed Jun 20, 2024
1 parent c419a1d commit 4f1e5eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/FMBot.Bot/Builders/GameBuilders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public GameBuilders(UserService userService, GameService gameService, ArtistsSer

var topArtists = await this._artistsService.GetUserAllTimeTopArtists(userId, true);

if (topArtists.Count(c => c.UserPlaycount > 50) <= 5)
if (topArtists.Count(c => c.UserPlaycount > 30) <= 6)
{
response.Embed.WithColor(DiscordConstants.WarningColorOrange);
response.Embed.WithDescription($"Sorry, you haven't listened to enough artists yet to use this command. Please scrobble more music and try again later.");
Expand Down Expand Up @@ -204,6 +204,14 @@ public async Task<ResponseModel> JumbleGiveUp(ContextModel context, int parsedGa
return response;
}

if (currentGame.StarterUserId != context.ContextUser.UserId)
{
response.Embed.WithDescription("You can't give up on someone else their game.");
response.Embed.WithColor(DiscordConstants.WarningColorOrange);
response.CommandResponse = CommandResponse.NoPermission;
return response;
}

await this._gameService.JumbleEndSession(currentGame);
await this._gameService.CancelToken(context.DiscordChannel.Id);

Expand Down Expand Up @@ -386,7 +394,7 @@ public async Task<ResponseModel> JumbleTimeExpired(ContextModel context, int gam
if (topAlbums.Count(c => c.UserPlaycount > 50) <= 5)
{
response.Embed.WithColor(DiscordConstants.WarningColorOrange);
response.Embed.WithDescription($"Sorry, you haven't listened to enough artists yet to use this command. Please scrobble more music and try again later.");
response.Embed.WithDescription($"Sorry, you haven't listened to enough albums yet to use this command. Please scrobble more music and try again later.");
response.CommandResponse = CommandResponse.NoScrobbles;
return response;
}
Expand Down
21 changes: 17 additions & 4 deletions src/FMBot.Bot/SlashCommands/GameSlashCommands.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Threading.Tasks;
using Discord.Interactions;
using Fergun.Interactive;
using FMBot.Bot.Attributes;
using FMBot.Bot.Builders;
using FMBot.Bot.Extensions;
using FMBot.Bot.Models;
using FMBot.Bot.Resources;
using FMBot.Bot.Services;
using FMBot.Domain.Models;

namespace FMBot.Bot.SlashCommands;

Expand All @@ -14,10 +16,13 @@ public class GameSlashCommands : InteractionModuleBase
private readonly GameBuilders _gameBuilders;
private readonly UserService _userService;

public GameSlashCommands(GameBuilders gameBuilders, UserService userService)
private InteractiveService Interactivity { get; }

public GameSlashCommands(GameBuilders gameBuilders, UserService userService, InteractiveService interactivity)
{
this._gameBuilders = gameBuilders;
this._userService = userService;
this.Interactivity = interactivity;
}

[ComponentInteraction($"{InteractionConstants.Game.AddJumbleHint}-*")]
Expand All @@ -42,8 +47,16 @@ public async Task JumbleReshuffle(string gameId)
public async Task JumbleGiveUp(string gameId)
{
var parsedGameId = int.Parse(gameId);
var response = await this._gameBuilders.JumbleGiveUp(new ContextModel(this.Context), parsedGameId);

await this.Context.UpdateInteractionEmbed(response);
var contextUser = await this._userService.GetUserSettingsAsync(this.Context.User);
var response = await this._gameBuilders.JumbleGiveUp(new ContextModel(this.Context, contextUser), parsedGameId);

if (response.CommandResponse == CommandResponse.NoPermission)
{
await this.Context.SendResponse(this.Interactivity, response, ephemeral: true);
}
else
{
await this.Context.UpdateInteractionEmbed(response);
}
}
}

0 comments on commit 4f1e5eb

Please sign in to comment.