Skip to content

Commit

Permalink
Reply to previous roll message
Browse files Browse the repository at this point in the history
  • Loading branch information
vicr123 committed May 11, 2024
1 parent ff398ef commit 222349c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
2 changes: 2 additions & 0 deletions DiscordMonies/Game/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public GamePlayer GetById(Snowflake userId)
public List<IUnresolvedMatter> UnresolvedMatters { get; } = [];

public IList<TradeTable> TradeTables { get; } = [];

public Snowflake? LastRollMessage { get; set; }
}

public enum GameAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
using Remora.Discord.API.Abstractions.Objects;
using Remora.Discord.API.Abstractions.Rest;
using Remora.Discord.API.Objects;
using Remora.Discord.Commands.Feedback.Services;
using Remora.Discord.Extensions.Formatting;
using Remora.Rest.Core;

namespace DiscordMonies.Game.UnresolvedMatters.DiceRoll;

public class DiceRollMatterHandler(GameState state, IFeedbackService service, BoardRenderer renderer) : IUnresolvedMatterResolver<DiceRollMatter>
public class DiceRollMatterHandler(GameState state, IDiscordRestChannelAPI restChannelApi, BoardRenderer renderer) : IUnresolvedMatterResolver<DiceRollMatter>
{
public async Task Resolve(DiceRollMatter matter)
{
if (state.Dice.DoubleRoll)
{
await service.SendAsync(state.ThreadId, $"{Mention.User(state.CurrentPlayer)}",
var sendResult = await restChannelApi.CreateMessageAsync(state.ThreadId, $"{Mention.User(state.CurrentPlayer)}, it's your turn.",
embeds: new([Embeds.TurnAdvancedDoubles(state.CurrentPlayer)]),
options: new()
{
Attachments = new([renderer.RenderToRemoraAttachment([new(state.CurrentPlayer.CurrentSpace, state.CurrentPlayer.Color.Color)])]),
MessageComponents = new([
new ActionRowComponent([
Buttons.Roll()
])
components: new([
new ActionRowComponent([
Buttons.Roll()
])
});
]),
attachments: new([
renderer.RenderToRemoraAttachment([
new(state.CurrentPlayer.CurrentSpace, state.CurrentPlayer.Color.Color)
])
]),
messageReference: state.LastRollMessage is null ? default(Optional<IMessageReference>) : new MessageReference(state.LastRollMessage.Value)
);
state.LastRollMessage = sendResult.Entity.ID;
return;
}

Expand All @@ -46,14 +50,18 @@ await service.SendAsync(state.ThreadId, $"{Mention.User(state.CurrentPlayer)}",
}
}

await service.SendAsync(state.ThreadId, $"{Mention.User(state.CurrentPlayer)}",
var result = await restChannelApi.CreateMessageAsync(state.ThreadId, $"{Mention.User(state.CurrentPlayer)}, it's your turn.",
embeds: new([Embeds.TurnAdvanced(state.CurrentPlayer)]),
options: new()
{
Attachments = new([renderer.RenderToRemoraAttachment([new(state.CurrentPlayer.CurrentSpace, state.CurrentPlayer.Color.Color)])]),
MessageComponents = new([
new ActionRowComponent(buttons)
components: new([
new ActionRowComponent(buttons)
]),
attachments: new([
renderer.RenderToRemoraAttachment([
new(state.CurrentPlayer.CurrentSpace, state.CurrentPlayer.Color.Color)
])
});
]),
messageReference: state.LastRollMessage is null ? default(Optional<IMessageReference>) : new MessageReference(state.LastRollMessage.Value)
);
state.LastRollMessage = result.Entity.ID;
}
}

0 comments on commit 222349c

Please sign in to comment.