New improved slots, improve admin commands, GetInteraction()
This commit is contained in:
		
							parent
							
								
									2404fd42db
								
							
						
					
					
						commit
						893fe1133d
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -456,3 +456,4 @@ $RECYCLE.BIN/ | ||||
| !.vscode/extensions.json | ||||
| *.org | ||||
| /.paket/load/ | ||||
| /Images/ | ||||
|  | ||||
							
								
								
									
										18
									
								
								Bot/Admin.fs
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								Bot/Admin.fs
									
									
									
									
									
								
							| @ -1,10 +1,24 @@ | ||||
| module Degenz.Admin | ||||
| 
 | ||||
| open System.Threading.Tasks | ||||
| open DSharpPlus | ||||
| open DSharpPlus.Entities | ||||
| open DSharpPlus.EventArgs | ||||
| open DSharpPlus.SlashCommands | ||||
| open DSharpPlus.SlashCommands.Attributes | ||||
| open Degenz.Messaging | ||||
| 
 | ||||
| let handleGuildDownloadReady (_ : DiscordClient) (event : GuildDownloadCompletedEventArgs) = | ||||
|     task { | ||||
|         let ( _ , guild ) = event.Guilds.TryGetValue(GuildEnvironment.guildId) | ||||
|         let! commands = guild.GetApplicationCommandsAsync() | ||||
|         let ( _ , adminRole ) = guild.Roles.TryGetValue(GuildEnvironment.roleAdmin) | ||||
| 
 | ||||
|         let permission = DiscordApplicationCommandPermission(adminRole, true) | ||||
|         let commands = commands |> Seq.map (fun com -> DiscordGuildApplicationCommandPermissions(com.Id, [ permission ])) | ||||
|         do! guild.BatchEditApplicationCommandPermissionsAsync(commands) |> Async.AwaitTask |> Async.Ignore | ||||
|     } :> Task | ||||
| 
 | ||||
| type AdminBot() = | ||||
|     inherit ApplicationCommandModule () | ||||
| 
 | ||||
| @ -15,10 +29,10 @@ type AdminBot() = | ||||
|         else | ||||
|             Messaging.sendSimpleResponse ctx $"You are not admin" |> Async.StartAsTask :> Task | ||||
| 
 | ||||
|     [<SlashCommand("admin-invites", "Get total invites from a specific user")>] | ||||
|     [<SlashCommand("admin-invites", "Get total invites from a specific user", false)>] | ||||
|     member this.GetAttributions (ctx : InteractionContext, [<Option("player", "The player you want to check")>] user : DiscordUser) = | ||||
|         enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.getInvitedUsersForId) | ||||
| 
 | ||||
|     [<SlashCommand("admin-whitelist-stock", "Set whitelist stock")>] | ||||
|     [<SlashCommand("admin-whitelist-stock", "Set whitelist stock", false)>] | ||||
|     member this.SetStock (ctx : InteractionContext, [<Option("amount", "Set the amount of WL available for purchase")>] amount : int64) = | ||||
|         enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.setWhitelistStock (int amount)) | ||||
|  | ||||
							
								
								
									
										51
									
								
								Bot/Bot.fs
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								Bot/Bot.fs
									
									
									
									
									
								
							| @ -3,6 +3,7 @@ module Degenz.Bot | ||||
| open System.IO | ||||
| open System.Threading.Tasks | ||||
| open DSharpPlus | ||||
| open DSharpPlus.Entities | ||||
| open DSharpPlus.SlashCommands | ||||
| open Degenz | ||||
| open Emzi0767.Utilities | ||||
| @ -16,9 +17,9 @@ let hackerBattleConfig = DiscordConfiguration() | ||||
| let storeConfig = DiscordConfiguration() | ||||
| let stealConfig = DiscordConfiguration() | ||||
| let inviterConfig = DiscordConfiguration() | ||||
| let slotsConfig = DiscordConfiguration() | ||||
| let adminConfig = DiscordConfiguration() | ||||
| //let slotMachineConfig = DiscordConfiguration() | ||||
| //hackerBattleConfig.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace | ||||
| //adminConfig.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace | ||||
| //storeConfig.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace | ||||
| 
 | ||||
| hackerBattleConfig.TokenType <- TokenType.Bot | ||||
| @ -33,6 +34,9 @@ stealConfig.Intents <- DiscordIntents.All | ||||
| inviterConfig.TokenType <- TokenType.Bot | ||||
| inviterConfig.Intents <- DiscordIntents.All | ||||
| 
 | ||||
| slotsConfig.TokenType <- TokenType.Bot | ||||
| slotsConfig.Intents <- DiscordIntents.All | ||||
| 
 | ||||
| adminConfig.TokenType <- TokenType.Bot | ||||
| adminConfig.Intents <- DiscordIntents.All | ||||
| 
 | ||||
| @ -40,31 +44,29 @@ hackerBattleConfig.Token <- GuildEnvironment.tokenHackerBattle | ||||
| storeConfig.Token <- GuildEnvironment.tokenStore | ||||
| stealConfig.Token <- GuildEnvironment.tokenSteal | ||||
| inviterConfig.Token <- GuildEnvironment.tokenInviter | ||||
| slotsConfig.Token <- GuildEnvironment.tokenSlots | ||||
| adminConfig.Token <- GuildEnvironment.tokenAdmin | ||||
| //slotMachineConfig.Token <- Environment.GetEnvironmentVariable("BOT_SLOT_MACHINE") | ||||
| 
 | ||||
| let hackerBattleBot = new DiscordClient(hackerBattleConfig) | ||||
| let storeBot = new DiscordClient(storeConfig) | ||||
| let stealBot = new DiscordClient(stealConfig) | ||||
| let inviterBot = new DiscordClient(inviterConfig) | ||||
| let slotsBot = new DiscordClient(slotsConfig) | ||||
| let adminBot = new DiscordClient(adminConfig) | ||||
| //let slotMachineBot = new DiscordClient(slotMachineConfig) | ||||
| 
 | ||||
| //let clients = [| hackerBattleBot ; storeBot ; slotMachineBot |] | ||||
| let hackerCommands = hackerBattleBot.UseSlashCommands() | ||||
| let storeCommands = storeBot.UseSlashCommands() | ||||
| let stealCommands = stealBot.UseSlashCommands() | ||||
| let inviterCommands = inviterBot.UseSlashCommands() | ||||
| let slotsCommands = slotsBot.UseSlashCommands() | ||||
| let adminCommands = adminBot.UseSlashCommands() | ||||
| //let sc3 = slotMachineBot.UseSlashCommands() | ||||
| 
 | ||||
| hackerCommands.RegisterCommands<HackerBattle.HackerGame>(guild); | ||||
| storeCommands.RegisterCommands<Store.Store>(guild); | ||||
| stealCommands.RegisterCommands<Thief.StealGame>(guild); | ||||
| inviterCommands.RegisterCommands<InviteTracker.Inviter>(guild); | ||||
| adminCommands.RegisterCommands<Admin.AdminBot>(guild); | ||||
| //hackerCommands.RegisterCommands<RPSGame>(guild); | ||||
| //sc3.RegisterCommands<SlotMachine>(guild); | ||||
| slotsCommands.RegisterCommands<SlotMachine.SlotMachine>(guild); | ||||
| adminCommands.RegisterCommands<Admin.AdminBot>(guild) | ||||
| 
 | ||||
| hackerBattleBot.add_ComponentInteractionCreated(AsyncEventHandler(HackerBattle.handleButtonEvent)) | ||||
| hackerBattleBot.add_MessageCreated(AsyncEventHandler(HackerBattle.handleMessageCreated)) | ||||
| @ -72,7 +74,8 @@ storeBot.add_ComponentInteractionCreated(AsyncEventHandler(Store.handleStoreEven | ||||
| stealBot.add_ComponentInteractionCreated(AsyncEventHandler(Thief.handleStealButton)) | ||||
| inviterBot.add_GuildMemberAdded(AsyncEventHandler(InviteTracker.handleGuildMemberAdded)) | ||||
| inviterBot.add_ComponentInteractionCreated(AsyncEventHandler(InviteTracker.handleButtonEvent)) | ||||
| //inviterBot.add_GuildMemberRemoved(AsyncEventHandler(InviteTracker.handleGuildMemberRemoved)) | ||||
| slotsBot.add_ComponentInteractionCreated(AsyncEventHandler(SlotMachine.handleSpin)) | ||||
| adminBot.add_GuildDownloadCompleted(AsyncEventHandler(Admin.handleGuildDownloadReady)) | ||||
| 
 | ||||
| let asdf (_ : DiscordClient) (event : DSharpPlus.EventArgs.InteractionCreateEventArgs) = | ||||
|     async { | ||||
| @ -90,21 +93,25 @@ let asdf (_ : DiscordClient) (event : DSharpPlus.EventArgs.InteractionCreateEven | ||||
|       :> Task | ||||
| //hackerBattleBot.add_InteractionCreated(AsyncEventHandler(asdf)) | ||||
| 
 | ||||
| slotsBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously | ||||
| 
 | ||||
| //hackerBattleBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously | ||||
| //GuildEnvironment.botUserHackerBattle <- Some hackerBattleBot.CurrentUser | ||||
| 
 | ||||
| //storeBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously | ||||
| //GuildEnvironment.botUserArmory <- Some storeBot.CurrentUser | ||||
| 
 | ||||
| //inviterBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously | ||||
| //GuildEnvironment.botClientRecruit <- Some inviterBot | ||||
| 
 | ||||
| 
 | ||||
| //adminBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously | ||||
| //stealBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously | ||||
| 
 | ||||
| //if guild <> 922419263275425832uL then | ||||
| //    Trainer.sendInitialEmbed hackerBattleBot | ||||
| //    InviteTracker.sendInitialEmbed inviterBot | ||||
| 
 | ||||
| hackerBattleBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously | ||||
| GuildEnvironment.botUserHackerBattle <- Some hackerBattleBot.CurrentUser | ||||
| 
 | ||||
| storeBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously | ||||
| GuildEnvironment.botUserArmory <- Some storeBot.CurrentUser | ||||
| 
 | ||||
| inviterBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously | ||||
| GuildEnvironment.botClientRecruit <- Some inviterBot | ||||
| 
 | ||||
| adminBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously | ||||
| //stealBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously | ||||
| SlotMachine.sendInitialEmbed slotsBot | ||||
| 
 | ||||
| let rec loop areBotsRunning = | ||||
|     async { | ||||
|  | ||||
| @ -103,7 +103,7 @@ let tryFindPlayer (discordId : uint64) = async { | ||||
|         return None | ||||
| } | ||||
| 
 | ||||
| let updatePlayerCurrency addAmount (player : PlayerData) = | ||||
| let updatePlayerCurrency (addAmount : int<GBT>) (player : PlayerData) = | ||||
|     connStr | ||||
|     |> Sql.connect | ||||
|     |> Sql.parameters [ | ||||
| @ -257,7 +257,7 @@ let getWhitelistItem () = | ||||
|     |> Sql.query """ | ||||
|             SELECT stock, price FROM item WHERE symbol = 'WHITELIST' | ||||
|         """ | ||||
|     |> Sql.executeRowAsync (fun read -> {| Stock = read.int "stock" ; Price = read.int "price" |}) | ||||
|     |> Sql.executeRowAsync (fun read -> {| Stock = read.int "stock" ; Price = (read.int "price") * 1<GBT> |}) | ||||
|     |> Async.AwaitTask | ||||
| 
 | ||||
| let updateWhitelistStock () = async { | ||||
|  | ||||
| @ -1,76 +1,202 @@ | ||||
| module Degenz.SlotMachine | ||||
| 
 | ||||
| open System | ||||
| open System.IO | ||||
| open System.Threading.Tasks | ||||
| open DSharpPlus | ||||
| open DSharpPlus.Entities | ||||
| open DSharpPlus.EventArgs | ||||
| open DSharpPlus.SlashCommands | ||||
| open Degenz.Messaging | ||||
| open Degenz.Types | ||||
| 
 | ||||
| let slots = [| "https://i.ibb.co/pKqZdr7/cherry.png" ; "https://i.ibb.co/JnghQsL/lemon.jpg" ; "https://i.ibb.co/1JTFPSs/seven.png" |] | ||||
| let slots = | ||||
| //    [| | ||||
| //    "https://s7.gifyu.com/images/A-bottle-of-pills.png" | ||||
| //    "https://s7.gifyu.com/images/an-eye.png" | ||||
| //    "https://s7.gifyu.com/images/anon-face-mask.png" | ||||
| //    "https://s7.gifyu.com/images/a-piece-of-sushi.png" | ||||
| //    "https://s7.gifyu.com/images/Circuit-board.png" | ||||
| //    "https://s7.gifyu.com/images/OBEY.png" | ||||
| //    "https://s7.gifyu.com/images/old-tv-screen.png" | ||||
| //    "https://s7.gifyu.com/images/pizza.png" | ||||
| //    "https://s7.gifyu.com/images/ramen.png" | ||||
| //    "https://s7.gifyu.com/images/rat.png" | ||||
| //|] | ||||
|     [| | ||||
|     "https://s7.gifyu.com/images/A-bottle-of-pills0a3006d0170e08df.png" | ||||
|     "https://s7.gifyu.com/images/an-eyec362d8152ae2382b.png" | ||||
|     "https://s7.gifyu.com/images/anon-face-mask6c7624821c89fc08.png" | ||||
|     "https://s7.gifyu.com/images/a-piece-of-sushi77071d30f60a89c6.png" | ||||
|     "https://s7.gifyu.com/images/Circuit-board89056017b80f1d13.png" | ||||
|     "https://s7.gifyu.com/images/OBEYf2a8234109836c03.png" | ||||
|     "https://s7.gifyu.com/images/old-tv-screendc6bc9d4b6c1fd65.png" | ||||
|     "https://s7.gifyu.com/images/pizza030ffc00ff50da0e.png" | ||||
|     "https://s7.gifyu.com/images/ramen08336d448018c98f.png" | ||||
|     "https://s7.gifyu.com/images/rat14f65f54f0d75036.png" | ||||
| |] | ||||
| let slotsLocal = | ||||
|     [| | ||||
|     "/home/joe/Development/DegenzGame/Images/SlotMachine/new/A bottle of pills.png" | ||||
|     "/home/joe/Development/DegenzGame/Images/SlotMachine/new/a piece of sushi.png" | ||||
|     "/home/joe/Development/DegenzGame/Images/SlotMachine/new/an eye.png" | ||||
|     "/home/joe/Development/DegenzGame/Images/SlotMachine/new/anon face mask.png" | ||||
|     "/home/joe/Development/DegenzGame/Images/SlotMachine/new/Circuit board.png" | ||||
|     "/home/joe/Development/DegenzGame/Images/SlotMachine/new/OBEY.png" | ||||
|     "/home/joe/Development/DegenzGame/Images/SlotMachine/new/old tv screen.png" | ||||
|     "/home/joe/Development/DegenzGame/Images/SlotMachine/new/pizza.png" | ||||
|     "/home/joe/Development/DegenzGame/Images/SlotMachine/new/ramen.png" | ||||
|     "/home/joe/Development/DegenzGame/Images/SlotMachine/new/rat.png" | ||||
| |] | ||||
| 
 | ||||
| type SlotMachine() = | ||||
|     inherit ApplicationCommandModule () | ||||
| let PlayPrice = 10<GBT> | ||||
| let twoOfAKindPrize = 100<GBT> | ||||
| let threeOfAKindPrize = 1000<GBT> | ||||
| let fourOfAKindPrize = 10000<GBT> | ||||
| 
 | ||||
|     [<SlashCommand("spin", "Want to try your luck?")>] | ||||
|     member this.Spin (ctx : InteractionContext) = | ||||
|         PlayerInteractions.executePlayerAction (DiscordInteractionContext ctx) (fun player -> async { | ||||
| let spin (ctx : IDiscordContext) = | ||||
|      PlayerInteractions.executePlayerAction ctx (fun player -> async { | ||||
|         let sleepTime = 1000 | ||||
|         let random = Random(System.Guid.NewGuid().GetHashCode()) | ||||
|             let results = [ random.Next(0, 3) ; random.Next(0, 3) ; random.Next(0, 3)] | ||||
|         let slotCount = slots.Length | ||||
|         let results = [ random.Next(0, slotCount) ; random.Next(0, slotCount) ; random.Next(0, slotCount) ] | ||||
| 
 | ||||
|         let winConditions = (results.[0] = results.[1] && results.[0] = results.[2]) | ||||
|                             || (results.[0] <> results.[1] && results.[1] <> results.[2] && results.[0] <> results.[2]) | ||||
| 
 | ||||
|             if winConditions then | ||||
|                 do! DbService.updatePlayer { player with Bank = player.Bank + 10<GBT> } | ||||
|                     |> Async.Ignore | ||||
|             else | ||||
|                 do! DbService.updatePlayer { player with Bank = max (player.Bank - 1<GBT>) 0<GBT> } | ||||
|                     |> Async.Ignore | ||||
|         if winConditions | ||||
|             then do! DbService.updatePlayerCurrency twoOfAKindPrize player |> Async.Ignore | ||||
|             else do! DbService.updatePlayerCurrency -PlayPrice player |> Async.Ignore | ||||
| 
 | ||||
|         let embed1 = DiscordEmbedBuilder() | ||||
|         embed1.ImageUrl <- slots.[results.[0]] | ||||
|         let embed2 = DiscordEmbedBuilder() | ||||
|         embed2.ImageUrl <- slots.[results.[1]] | ||||
|         let embed3 = DiscordEmbedBuilder() | ||||
|         embed3.ImageUrl <- slots.[results.[2]] | ||||
|         let embed4 = DiscordEmbedBuilder() | ||||
|         embed4.Title <- "Slot Machine" | ||||
|         embed4.Description <- "You hit the jackpot!" | ||||
| 
 | ||||
|             do! ctx.Interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource) | ||||
|                 |> Async.AwaitTask | ||||
|         let iCtx = ctx.GetInteraction() | ||||
| 
 | ||||
|             do! Async.Sleep sleepTime | ||||
|         let builder = DiscordFollowupMessageBuilder() | ||||
|             let embed = DiscordEmbedBuilder() | ||||
|             embed.ImageUrl <- slots.[results.[0]] | ||||
|             builder.AddEmbed(embed.Build()) |> ignore | ||||
|             do! ctx.Interaction.CreateFollowupMessageAsync(builder) | ||||
|                 |> Async.AwaitTask | ||||
|                 |> Async.Ignore | ||||
| //        let embed = DiscordEmbedBuilder() | ||||
| //        embed.ImageUrl <- slots.[results.[0]] | ||||
| //        builder.AddEmbed(embed.Build()) |> ignore | ||||
| 
 | ||||
|             do! Async.Sleep sleepTime | ||||
|             let builder = DiscordFollowupMessageBuilder() | ||||
|             embed.ImageUrl <- slots.[results.[1]] | ||||
|             builder.AddEmbed(embed.Build()) |> ignore | ||||
|             do! ctx.Interaction.CreateFollowupMessageAsync(builder) | ||||
|                 |> Async.AwaitTask | ||||
|                 |> Async.Ignore | ||||
|         builder.Content <- "Spinning!" | ||||
|         builder.IsEphemeral <- true | ||||
| 
 | ||||
|             do! Async.Sleep sleepTime | ||||
|             let builder = DiscordFollowupMessageBuilder() | ||||
|             embed.ImageUrl <- slots.[results.[2]] | ||||
|             builder.AddEmbed(embed.Build()) |> ignore | ||||
|             do! ctx.Interaction.CreateFollowupMessageAsync(builder) | ||||
|                 |> Async.AwaitTask | ||||
|                 |> Async.Ignore | ||||
|         let! followUp = iCtx.CreateFollowupMessageAsync(builder) |> Async.AwaitTask | ||||
|         do! Async.Sleep 1500 | ||||
|         use f1 = new FileStream(slotsLocal.[0], FileMode.Open) | ||||
|         let! _ = iCtx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().AddFile(f1)) |> Async.AwaitTask | ||||
|         do! Async.Sleep 1500 | ||||
|         use f2 = new FileStream(slotsLocal.[1], FileMode.Open) | ||||
|         let! _ = iCtx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().AddFile(f2)) |> Async.AwaitTask | ||||
|         do! Async.Sleep 1500 | ||||
|         use f3 = new FileStream(slotsLocal.[2], FileMode.Open) | ||||
|         let! _ = iCtx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().AddFile(f3)) |> Async.AwaitTask | ||||
| 
 | ||||
|             if winConditions then | ||||
|                 do! Async.Sleep sleepTime | ||||
|                 let builder = DiscordFollowupMessageBuilder() | ||||
|                 builder.Content <- "You win 10 GBT!" | ||||
|                 do! ctx.Interaction.CreateFollowupMessageAsync(builder) | ||||
|                     |> Async.AwaitTask | ||||
|                     |> Async.Ignore | ||||
|             else | ||||
|                 do! Async.Sleep sleepTime | ||||
|                 let builder = DiscordFollowupMessageBuilder() | ||||
|                 builder.Content <- "You lose 0.5 GBT! Try your luck again!" | ||||
|                 do! ctx.Interaction.CreateFollowupMessageAsync(builder) | ||||
|                     |> Async.AwaitTask | ||||
|                     |> Async.Ignore | ||||
|         do! Async.Sleep 1500 | ||||
| 
 | ||||
|         let! _ = iCtx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().AddEmbed(embed1)) |> Async.AwaitTask | ||||
|         do! Async.Sleep 1500 | ||||
|         let! _ = iCtx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().AddEmbeds([embed1.Build() ; embed2.Build()])) |> Async.AwaitTask | ||||
|         do! Async.Sleep 1500 | ||||
|         let! _ = iCtx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().AddEmbeds([embed1.Build() ; embed2.Build() ; embed3.Build() ])) |> Async.AwaitTask | ||||
|         do! Async.Sleep 1500 | ||||
|         let! _ = iCtx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().AddEmbeds([embed1.Build() ; embed2.Build() ; embed3.Build() ; embed4.Build() ])) |> Async.AwaitTask | ||||
|         return () | ||||
| 
 | ||||
| //        do! Async.Sleep sleepTime | ||||
| //        let builder = DiscordFollowupMessageBuilder() | ||||
| //        let embed = DiscordEmbedBuilder() | ||||
| //        embed.ImageUrl <- slots.[results.[0]] | ||||
| //        builder.AddEmbed(embed.Build()) |> ignore | ||||
| // | ||||
| //        do! Async.Sleep sleepTime | ||||
| //        let builder = DiscordFollowupMessageBuilder() | ||||
| //        embed.ImageUrl <- slots.[results.[1]] | ||||
| //        builder.AddEmbed(embed.Build()) |> ignore | ||||
| // | ||||
| //        do! Async.Sleep sleepTime | ||||
| //        let builder = DiscordFollowupMessageBuilder() | ||||
| //        embed.ImageUrl <- slots.[results.[2]] | ||||
| //        builder.AddEmbed(embed.Build()) |> ignore | ||||
| // | ||||
| //        if winConditions then | ||||
| //            do! Async.Sleep sleepTime | ||||
| //            let builder = DiscordFollowupMessageBuilder() | ||||
| //            builder.Content <- "You win 10 GBT!" | ||||
| //            do! ctx.FollowUp(builder) | ||||
| //                |> Async.AwaitTask | ||||
| //                |> Async.Ignore | ||||
| //        else | ||||
| //            do! Async.Sleep sleepTime | ||||
| //            let builder = DiscordFollowupMessageBuilder() | ||||
| //            builder.Content <- "You lose 0.5 GBT! Try your luck again!" | ||||
| //            do! ctx.FollowUp(builder) | ||||
| //                |> Async.AwaitTask | ||||
| //                |> Async.Ignore | ||||
|     }) | ||||
| 
 | ||||
| let handleSpin (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) = | ||||
|     task { | ||||
|         do! spin (DiscordEventContext event) | ||||
|     } :> Task | ||||
| 
 | ||||
| let spinCommand (ctx : IDiscordContext) = | ||||
|     async { | ||||
|         try | ||||
|             let builder = DiscordInteractionResponseBuilder() | ||||
|             builder.Content <- "The message" | ||||
|             builder.IsEphemeral <- true | ||||
|             let button = DiscordButtonComponent(ButtonStyle.Success, $"spin", $"Spin Me Right Around") :> DiscordComponent | ||||
|             builder.AddComponents [| button |] |> ignore | ||||
|             do! ctx.Respond(InteractionResponseType.ChannelMessageWithSource, builder) | ||||
|                 |> Async.AwaitTask | ||||
|                 |> Async.Ignore | ||||
|         with e -> | ||||
|             printfn $"Error trying to get channel Casino\n\n{e.Message}" | ||||
|     } |> Async.StartAsTask :> Task | ||||
| 
 | ||||
| let sendInitialEmbed (client : DiscordClient)  = | ||||
|     async { | ||||
|         try | ||||
|             let! channel = client.GetChannelAsync(961472561319903352uL) |> Async.AwaitTask | ||||
|             let builder = DiscordMessageBuilder() | ||||
|             let embed = DiscordEmbedBuilder() | ||||
|             embed.Title <- "Degenz Slot Machine" | ||||
|             embed.Description <- "Hello I am an embed" | ||||
|             embed.ImageUrl <- "https://i.kym-cdn.com/photos/images/original/001/169/608/a43.gif" | ||||
| 
 | ||||
|             builder.AddEmbed(embed) |> ignore | ||||
| 
 | ||||
|             let button = DiscordButtonComponent(ButtonStyle.Success, $"spin", $"Spin Me Right Around") :> DiscordComponent | ||||
|             builder.AddComponents [| button |] |> ignore | ||||
|             do! channel.SendMessageAsync(builder) | ||||
|                 |> Async.AwaitTask | ||||
|                 |> Async.Ignore | ||||
|         with e -> | ||||
|             printfn $"Error trying to get channel Training Dojo\n\n{e.Message}" | ||||
|     } |> Async.RunSynchronously | ||||
| 
 | ||||
| type SlotMachine() = | ||||
|     inherit ApplicationCommandModule () | ||||
| 
 | ||||
|     let enforceChannel (ctx : IDiscordContext) (spinFn : IDiscordContext -> Task) = | ||||
|         match ctx.GetChannel().Id with | ||||
|         | id when id = 961472561319903352uL -> spinFn ctx | ||||
|         | _ -> | ||||
|             task { | ||||
|                 let msg = $"You must go to <#961472561319903352> channel to spin" | ||||
|                 do! Messaging.sendSimpleResponse ctx msg | ||||
|             } | ||||
| 
 | ||||
|     [<SlashCommand("spin", "Want to try your luck?")>] | ||||
|     member this.Spin (ctx : InteractionContext) = enforceChannel (DiscordInteractionContext ctx) spinCommand | ||||
| 
 | ||||
|     [<SlashCommand("spin-simple", "Want to try your luck?")>] | ||||
|     member this.SpinSimple (ctx : InteractionContext) = enforceChannel (DiscordInteractionContext ctx) spin | ||||
|  | ||||
| @ -22,6 +22,7 @@ let tokenSteal = getVar "TOKEN_STEAL" | ||||
| let tokenHackerBattle = getVar "TOKEN_HACKER_BATTLE" | ||||
| let tokenStore = getVar "TOKEN_STORE" | ||||
| let tokenInviter = getVar "TOKEN_INVITER" | ||||
| let tokenSlots = getVar "TOKEN_SLOTS" | ||||
| let tokenAdmin = getVar "TOKEN_ADMINBOT" | ||||
| let tokenMixpanel = getVar "TOKEN_MIXPANEL" | ||||
| let channelEventsHackerBattle = getId "CHANNEL_EVENTS_HACKER_BATTLE" | ||||
|  | ||||
| @ -301,7 +301,7 @@ let acceptInvite (ctx : IDiscordContext) (invitedPlayer : PlayerData) = | ||||
|                 let! player = DbService.tryFindPlayer invite.Inviter | ||||
|                 match player with | ||||
|                 | Some player -> | ||||
|                     do! DbService.updatePlayerCurrency (int InviteRewardAmount) player |> Async.Ignore | ||||
|                     do! DbService.updatePlayerCurrency InviteRewardAmount player |> Async.Ignore | ||||
|                     do! match GuildEnvironment.botClientRecruit with | ||||
|                         | Some recruitBot -> async { | ||||
|                             let builder = DiscordMessageBuilder() | ||||
| @ -341,13 +341,13 @@ Your NFT will be your In-Game Character that provides you with unique traits, an | ||||
|                 |> Async.AwaitTask | ||||
|                 |> Async.Ignore | ||||
|         with e -> | ||||
|             printfn $"Error trying to get channel Training Dojo\n\n{e.Message}" | ||||
|             printfn $"Error trying to get channel Whitelist\n\n{e.Message}" | ||||
|     } |> Async.RunSynchronously | ||||
| 
 | ||||
| type WhitelistResult = | ||||
|     | NotInGame | ||||
|     | NotAHacker | ||||
|     | NotEnoughGBT of currentAmount : int | ||||
|     | NotEnoughGBT of currentAmount : int<GBT> | ||||
|     | NotEnoughStock | ||||
|     | Granted of PlayerData | ||||
|     | AlreadyWhitelisted | ||||
| @ -360,12 +360,12 @@ let tryGrantWhitelist (ctx : IDiscordContext) stock price = | ||||
|             let hasWhitelist = Seq.contains (ctx.GetGuild().GetRole(GuildEnvironment.roleWhitelist)) user.Roles | ||||
|             let isHacker = Seq.contains (ctx.GetGuild().GetRole(GuildEnvironment.roleHacker)) user.Roles | ||||
| 
 | ||||
|             match hasWhitelist , player.Active , isHacker , stock > 0 , int player.Bank >= price with | ||||
|             match hasWhitelist , player.Active , isHacker , stock > 0 , player.Bank >= price with | ||||
|             | true , _ , _ , _ , _  -> return AlreadyWhitelisted | ||||
|             | _ , false , _ , _ , _ -> return NotInGame | ||||
|             | _ , _ , false , _ , _ -> return NotAHacker | ||||
|             | _ , _ , _ , false , _ -> return NotEnoughStock | ||||
|             | _ , _ , _ , _ , false -> return NotEnoughGBT (int player.Bank) | ||||
|             | _ , _ , _ , _ , false -> return NotEnoughGBT player.Bank | ||||
|             | _ , _ , _ , _ , _     -> return Granted player | ||||
|         | None -> return NotInGame | ||||
|     } | ||||
| @ -505,7 +505,7 @@ let handleBuyWhitelist (ctx : IDiscordContext) = | ||||
|                 embed.Color <- DiscordColor.Green | ||||
| 
 | ||||
|                 let recruitBtn = DiscordButtonComponent(ButtonStyle.Danger, $"ShowRecruitmentEmbed", $"Recruit Now") :> DiscordComponent | ||||
|                 builder.AddComponents ([ recruitBtn ]) |> ignore | ||||
|                 builder.AddComponents [ recruitBtn ] |> ignore | ||||
|                 let role = ctx.GetGuild().GetRole(GuildEnvironment.roleWhitelist) | ||||
|                 do! ctx.GetDiscordMember().GrantRoleAsync(role) | ||||
|                 let! _ = DbService.updatePlayerCurrency -wlItem.Price player | ||||
|  | ||||
| @ -23,6 +23,7 @@ type IDiscordContext = | ||||
|     abstract member FollowUp : DiscordFollowupMessageBuilder -> Task | ||||
|     abstract member GetDiscordMember : unit -> DiscordMember | ||||
|     abstract member GetGuild : unit -> DiscordGuild | ||||
|     abstract member GetInteraction : unit -> DiscordInteraction | ||||
|     abstract member GetInteractionId : unit -> string | ||||
|     abstract member GetChannel : unit -> DiscordChannel | ||||
|     abstract member GetContext : unit -> obj | ||||
| @ -43,6 +44,7 @@ type DiscordInteractionContext(ctx : InteractionContext) = | ||||
|             } |> Async.StartAsTask :> Task | ||||
|         member this.GetDiscordMember() = ctx.Member | ||||
|         member this.GetGuild() = ctx.Guild | ||||
|         member this.GetInteraction() = ctx.Interaction | ||||
|         member this.GetInteractionId() = string ctx.InteractionId | ||||
|         member this.GetChannel() = ctx.Channel | ||||
|         member this.GetContext() = ctx | ||||
| @ -63,6 +65,7 @@ type DiscordEventContext(ctx : ComponentInteractionCreateEventArgs) = | ||||
|             } |> Async.StartAsTask :> Task | ||||
|         member this.GetDiscordMember() = ctx.User :?> DiscordMember | ||||
|         member this.GetGuild() = ctx.Guild | ||||
|         member this.GetInteraction() = ctx.Interaction | ||||
|         member this.GetInteractionId() = ctx.Id | ||||
|         member this.GetChannel() = ctx.Channel | ||||
|         member this.GetContext() = ctx | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user