<commit_before>﻿using System;
using System.Threading.Tasks;
using Discord.Commands;
using Discord.Rest;
using SoraBot_v2.Data;
using SoraBot_v2.Extensions;
using SoraBot_v2.Services;

namespace SoraBot_v2.Module
{
    [Name("Gambling")]
    public class GamblingModule : ModuleBase<SocketCommandContext>
    {
        private readonly CoinService _coinService;

        public GamblingModule(CoinService coinService)
        {
            _coinService = coinService;
        }

        [Command("coinflip"), Alias("cf"),
         Summary("Flips a coin!")]
        public async Task FlipCoin(int bet, [Remainder]string side)
        {
            using var soraContext = new SoraContext();
            var userDb = Utility.GetOrCreateUser(Context.User.Id, soraContext);

            if (bet > _coinService.GetAmount(Context.User.Id))
            {
                await this.ReplySoraEmbedResponse(Utility.RedFailiureEmbed, Utility.FailiureEmoji, 
                    $"You don't have enough money for this bet! You currently have {userDb.Money} SC");
                return;
            }

            side = side.Trim(); // just in case D.net doesn't do that
            if (!string.Equals(side, "heads", StringComparison.InvariantCultureIgnoreCase)
                && !string.Equals(side, "tails", StringComparison.InvariantCultureIgnoreCase))
            {
                await this.ReplySoraEmbedResponse(Utility.RedFailiureEmbed, Utility.FailiureEmoji,
                    $"The side you chose is invalid. Please use `heads` or `tails`");
                return;
            }
                
            Random random = new Random();

            bool userWon = side.Equals(random.Next(100) % 2 == 0 ? "heads" : "tails",
                StringComparison.InvariantCultureIgnoreCase);
            var lck = _coinService.GetOrCreateLock(Context.User.Id);
            int winnings = userWon ? bet * 2 : -bet;
            if (!await _coinService.AddCoinAmount(userDb, winnings))
            {
                await this.ReplySoraEmbedResponse(Utility.RedFailiureEmbed, Utility.FailiureEmoji,
                    "Failed to acquire your Sora coin information. Please try again.");
                return;
            }
                
            await soraContext.SaveChangesAsync();

            if (userWon)
            {
                await this.ReplySoraEmbedResponse(Utility.GreenSuccessEmbed, Utility.PartyEmoji,
                    $"Congratulations! You won {winnings}!");
            }
            else
            {
                await this.ReplySoraEmbedResponse(Utility.YellowWarningEmbed, Utility.NoEmoji,
                    $"You lost :(");
            }
        }
    }<commit_msg>forgot to remove unused lock<commit_after>﻿using System;
using System.Threading.Tasks;
using Discord.Commands;
using Discord.Rest;
using SoraBot_v2.Data;
using SoraBot_v2.Extensions;
using SoraBot_v2.Services;

namespace SoraBot_v2.Module
{
    [Name("Gambling")]
    public class GamblingModule : ModuleBase<SocketCommandContext>
    {
        private readonly CoinService _coinService;

        public GamblingModule(CoinService coinService)
        {
            _coinService = coinService;
        }

        [Command("coinflip"), Alias("cf"),
         Summary("Flips a coin!")]
        public async Task FlipCoin(int bet, [Remainder]string side)
        {
            using var soraContext = new SoraContext();
            var userDb = Utility.GetOrCreateUser(Context.User.Id, soraContext);

            if (bet > _coinService.GetAmount(Context.User.Id))
            {
                await this.ReplySoraEmbedResponse(Utility.RedFailiureEmbed, Utility.FailiureEmoji, 
                    $"You don't have enough money for this bet! You currently have {userDb.Money} SC");
                return;
            }

            side = side.Trim(); // just in case D.net doesn't do that
            if (!string.Equals(side, "heads", StringComparison.InvariantCultureIgnoreCase)
                && !string.Equals(side, "tails", StringComparison.InvariantCultureIgnoreCase))
            {
                await this.ReplySoraEmbedResponse(Utility.RedFailiureEmbed, Utility.FailiureEmoji,
                    $"The side you chose is invalid. Please use `heads` or `tails`");
                return;
            }
                
            Random random = new Random();

            bool userWon = side.Equals(random.Next(100) % 2 == 0 ? "heads" : "tails",
                StringComparison.InvariantCultureIgnoreCase);
            int winnings = userWon ? bet * 2 : -bet;
            if (!await _coinService.AddCoinAmount(userDb, winnings))
            {
                await this.ReplySoraEmbedResponse(Utility.RedFailiureEmbed, Utility.FailiureEmoji,
                    "Failed to acquire your Sora coin information. Please try again.");
                return;
            }
                
            await soraContext.SaveChangesAsync();

            if (userWon)
            {
                await this.ReplySoraEmbedResponse(Utility.GreenSuccessEmbed, Utility.PartyEmoji,
                    $"Congratulations! You won {winnings}!");
            }
            else
            {
                await this.ReplySoraEmbedResponse(Utility.YellowWarningEmbed, Utility.NoEmoji,
                    $"You lost :(");
            }
        }
    }
{'fraction_non_alphanumeric': 0.0909260642270351, 'fraction_numerical': 0.0037341299477221808, 'mean_word_length': 1.9241266375545851, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4144265', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1425, 'n_words': 317}