-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
220 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,65 @@ | ||
using Discord; | ||
using FMBot.Bot.Models; | ||
using FMBot.Bot.Resources; | ||
using System.Text; | ||
using FMBot.Domain.Models; | ||
using System.Threading.Tasks; | ||
using FMBot.Bot.Services; | ||
|
||
namespace FMBot.Bot.Builders; | ||
|
||
public class GameBuilders | ||
{ | ||
|
||
private readonly UserService _userService; | ||
private readonly GameService _gameService; | ||
private readonly ArtistsService _artistsService; | ||
|
||
public GameBuilders(UserService userService, GameService gameService, ArtistsService artistsService) | ||
{ | ||
this._userService = userService; | ||
this._gameService = gameService; | ||
this._artistsService = artistsService; | ||
} | ||
|
||
public static ResponseModel GameModePick(ContextModel context) | ||
{ | ||
var response = new ResponseModel | ||
{ | ||
ResponseType = ResponseType.Embed, | ||
Components = new ComponentBuilder() | ||
.WithButton("First correct answer wins", InteractionConstants.Game.StartJumbleFirstWins) | ||
.WithButton("Play as group", InteractionConstants.Game.StartJumbleGroup) | ||
}; | ||
|
||
var description = new StringBuilder(); | ||
|
||
description.AppendLine("Start jumble game"); | ||
|
||
response.Embed.WithDescription(description.ToString()); | ||
response.Embed.WithColor(DiscordConstants.InformationColorBlue); | ||
|
||
return response; | ||
} | ||
|
||
public async Task<ResponseModel> StartJumbleFirstWins(ContextModel context, int userId) | ||
{ | ||
var response = new ResponseModel | ||
{ | ||
ResponseType = ResponseType.Embed, | ||
}; | ||
|
||
var topArtists = await this._artistsService.GetUserAllTimeTopArtists(userId, true); | ||
var artist = await this._gameService.PickArtistForJumble(topArtists); | ||
var game = await this._gameService.StartJumbleGame(userId, context.DiscordGuild?.Id, GameType.JumbleFirstWins, artist); | ||
|
||
response.Embed.WithAuthor("Guess the artist - Jumble"); | ||
|
||
var description = new StringBuilder(); | ||
response.Embed.WithDescription($"`{game.jumbled}`"); | ||
response.Embed.AddField("Hint", "aasddasd"); | ||
response.Embed.AddField("Add an answer", "Type your answer in this channel to make a guess"); | ||
response.Embed.WithColor(DiscordConstants.InformationColorBlue); | ||
|
||
return response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace FMBot.Bot.Models; | ||
|
||
public class GameModel | ||
{ | ||
public int GameId { get; set; } | ||
public int StarterUserId { get; set; } | ||
public ulong? DiscordGuildId { get; set; } | ||
|
||
public int HintCount { get; set; } | ||
|
||
public GameType GameType { get; set; } | ||
|
||
public DateTime DateStarted { get; set; } | ||
public DateTime? DateEnded { get; set; } | ||
|
||
public List<GameAnswerModel> Answers { get; set; } | ||
|
||
public string CorrectAnswer { get; set; } | ||
} | ||
|
||
public class GameAnswerModel | ||
{ | ||
public int GameAnswerId { get; set; } | ||
public int GameId { get; set; } | ||
public int UserId { get; set; } | ||
|
||
public bool Correct { get; set; } | ||
|
||
public string Answer { get; set; } | ||
} | ||
|
||
public enum GameType | ||
{ | ||
JumbleFirstWins = 1, | ||
JumbleGroup = 2 | ||
} | ||
|
||
public enum JumbleHintType | ||
{ | ||
Reshuffle = 1, | ||
Description = 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Cryptography; | ||
using System.Threading.Tasks; | ||
using FMBot.Bot.Models; | ||
using FMBot.Domain.Models; | ||
|
||
namespace FMBot.Bot.Services; | ||
|
||
public class GameService | ||
{ | ||
public async Task<string> PickArtistForJumble(List<TopArtist> topArtists) | ||
{ | ||
return "The Beatles"; | ||
} | ||
|
||
public async Task<(GameModel game, string jumbled)> StartJumbleGame(int userId, ulong? discordGuildId, GameType gameType, string artist) | ||
{ | ||
var game = new GameModel | ||
{ | ||
DateStarted = DateTime.UtcNow, | ||
StarterUserId = userId, | ||
DiscordGuildId = discordGuildId, | ||
GameType = gameType, | ||
CorrectAnswer = artist, | ||
HintCount = 0 | ||
}; | ||
|
||
var jumbled = JumbleWords(artist); | ||
|
||
|
||
|
||
return (game, jumbled); | ||
} | ||
|
||
//public async Task<string> GetJumbleHint(int userId, string artist) | ||
//{ | ||
|
||
// var jumbled = JumbleWords(artist); | ||
|
||
|
||
|
||
// return (game, jumbled); | ||
//} | ||
|
||
public static string JumbleWords(string input) | ||
{ | ||
var words = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); | ||
|
||
var jumbledWords = words.Select(JumbleWord); | ||
|
||
return string.Join(" ", jumbledWords); | ||
} | ||
|
||
private static string JumbleWord(string word) | ||
{ | ||
var letters = word.ToCharArray(); | ||
|
||
for (var i = letters.Length - 1; i > 0; i--) | ||
{ | ||
var swapIndex = RandomNumberGenerator.GetInt32(0, i + 1); | ||
(letters[i], letters[swapIndex]) = (letters[swapIndex], letters[i]); | ||
} | ||
|
||
return new string(letters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Threading.Tasks; | ||
using Discord.Interactions; | ||
using FMBot.Bot.Attributes; | ||
using FMBot.Bot.Builders; | ||
using FMBot.Bot.Extensions; | ||
using FMBot.Bot.Models; | ||
using FMBot.Bot.Resources; | ||
using FMBot.Bot.Services; | ||
|
||
namespace FMBot.Bot.SlashCommands; | ||
|
||
public class GameSlashCommands : InteractionModuleBase | ||
{ | ||
private readonly GameBuilders _gameBuilders; | ||
private readonly UserService _userService; | ||
|
||
public GameSlashCommands(GameBuilders gameBuilders, UserService userService) | ||
{ | ||
this._gameBuilders = gameBuilders; | ||
this._userService = userService; | ||
} | ||
|
||
[ComponentInteraction(InteractionConstants.Game.StartJumbleFirstWins)] | ||
public async Task StartJumbleFirstAnswerWins() | ||
{ | ||
var contextUser = await this._userService.GetUserSettingsAsync(this.Context.User); | ||
|
||
var response = await this._gameBuilders.StartJumbleFirstWins(new ContextModel(this.Context), contextUser.UserId); | ||
|
||
await this.Context.UpdateInteractionEmbed(response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters