Ejemplo n.º 1
0
            public static async Task FlowerReactionEvent(CommandContext Context)
            {
                var msg = await Context.Channel.SendConfirmAsync("Flower reaction event started!",
                                                                 "Add 🌸 reaction to this message to get 100" + NadekoBot.BotConfig.CurrencySign,
                                                                 footer : "This event is active for 24 hours.")
                          .ConfigureAwait(false);

                try { await msg.AddReactionAsync("🌸").ConfigureAwait(false); }
                catch
                {
                    try { await msg.AddReactionAsync("🌸").ConfigureAwait(false); }
                    catch
                    {
                        try { await msg.DeleteAsync().ConfigureAwait(false); }
                        catch { return; }
                    }
                }
                using (msg.OnReaction(async(r) =>
                {
                    try
                    {
                        if (r.Emoji.Name == "🌸" && r.User.IsSpecified && ((DateTime.UtcNow - r.User.Value.CreatedAt).TotalDays > 5) && _flowerReactionAwardedUsers.Add(r.User.Value.Id))
                        {
                            try { await CurrencyHandler.AddCurrencyAsync(r.User.Value, "Flower Reaction Event", 100, false).ConfigureAwait(false); } catch { }
                        }
                    }
                    catch { }
                }))
                {
                    await Task.Delay(TimeSpan.FromHours(24)).ConfigureAwait(false);

                    try { await msg.DeleteAsync().ConfigureAwait(false); } catch { }
                    _flowerReactionAwardedUsers.Clear();
                }
            }
Ejemplo n.º 2
0
            public async Task Plant()
            {
                var removed = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)Context.User, $"Planted a {NadekoBot.BotConfig.CurrencyName}", 1, false).ConfigureAwait(false);

                if (!removed)
                {
                    await Context.Channel.SendErrorAsync($"You don't have any {NadekoBot.BotConfig.CurrencyPluralName}.").ConfigureAwait(false);

                    return;
                }

                var          file = GetRandomCurrencyImagePath();
                IUserMessage msg;
                var          vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(NadekoBot.BotConfig.CurrencyName[0]);

                var msgToSend = $"Oh how Nice! **{Context.User.Username}** planted {(vowelFirst ? "an" : "a")} {NadekoBot.BotConfig.CurrencyName}. Pick it using {NadekoBot.ModulePrefixes[typeof(Games).Name]}pick";

                if (file == null)
                {
                    msg = await Context.Channel.SendConfirmAsync(NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);
                }
                else
                {
                    msg = await Context.Channel.SendFileAsync(File.Open(file, FileMode.OpenOrCreate), new FileInfo(file).Name, msgToSend).ConfigureAwait(false);
                }
                plantedFlowers.AddOrUpdate(Context.Channel.Id, new List <IUserMessage>()
                {
                    msg
                }, (id, old) => { old.Add(msg); return(old); });
            }
Ejemplo n.º 3
0
            public async Task Pick()
            {
                var channel = (ITextChannel)Context.Channel;

                if (!(await channel.Guild.GetCurrentUserAsync()).GetPermissions(channel).ManageMessages || !usersRecentlyPicked.Add(Context.User.Id))
                {
                    return;
                }

                try
                {
                    List <IUserMessage> msgs;

                    try { await Context.Message.DeleteAsync().ConfigureAwait(false); } catch { }
                    if (!plantedFlowers.TryRemove(channel.Id, out msgs))
                    {
                        return;
                    }

                    await Task.WhenAll(msgs.Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false);

                    await CurrencyHandler.AddCurrencyAsync((IGuildUser)Context.User, "Picked flower(s).", msgs.Count, false).ConfigureAwait(false);

                    var msg = await channel.SendConfirmAsync($"**{Context.User}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false);

                    msg.DeleteAfter(10);
                }
                finally
                {
                    await Task.Delay(60000);

                    usersRecentlyPicked.TryRemove(Context.User.Id);
                }
            }
Ejemplo n.º 4
0
                public async Task JoinRace(IGuildUser u, int amount = 0)
                {
                    var animal = "";

                    if (!animals.TryDequeue(out animal))
                    {
                        await raceChannel.SendMessageAsync($"{u.Mention} `There is no running race on this server.`");

                        return;
                    }
                    var p = new Participant(u, animal, amount);

                    if (participants.Contains(p))
                    {
                        await raceChannel.SendMessageAsync($"{u.Mention} `You already joined this race.`");

                        return;
                    }
                    if (Started)
                    {
                        await raceChannel.SendMessageAsync($"{u.Mention} `Race is already started`");

                        return;
                    }
                    if (amount > 0)
                    {
                        if (!await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)u, "BetRace", amount, true).ConfigureAwait(false))
                        {
                            try { await raceChannel.SendMessageAsync($"{u.Mention} You don't have enough {Gambling.CurrencyName}s.").ConfigureAwait(false); } catch { }
                            return;
                        }
                    }
                    participants.Add(p);
                    await raceChannel.SendMessageAsync($"{u.Mention} **joined the race as a {p.Animal}" + (amount > 0 ? $" and bet {amount} {CurrencySign}!**" : "**"));
                }
Ejemplo n.º 5
0
            public async Task Pick(IUserMessage imsg)
            {
                var channel = (ITextChannel)imsg.Channel;

                if (!channel.Guild.GetCurrentUser().GetPermissions(channel).ManageMessages)
                {
                    await channel.SendMessageAsync("`I need manage channel permissions in order to process this command.`").ConfigureAwait(false);

                    return;
                }

                List <IUserMessage> msgs;

                try { await imsg.DeleteAsync().ConfigureAwait(false); } catch { }
                if (!plantedFlowers.TryRemove(channel.Id, out msgs))
                {
                    return;
                }

                await Task.WhenAll(msgs.Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false);

                await CurrencyHandler.AddCurrencyAsync((IGuildUser)imsg.Author, "Picked flower(s).", msgs.Count, false).ConfigureAwait(false);

                var msg = await channel.SendMessageAsync($"**{imsg.Author.Username}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false);

                var t = Task.Run(async() =>
                {
                    await Task.Delay(10000).ConfigureAwait(false);
                    try { await msg.DeleteAsync().ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
                });
            }
Ejemplo n.º 6
0
            public async Task Pick()
            {
                var channel = (ITextChannel)Context.Channel;

                if (!(await channel.Guild.GetCurrentUserAsync()).GetPermissions(channel).ManageMessages)
                {
                    return;
                }

                List <IUserMessage> msgs;

                try { await Context.Message.DeleteAsync().ConfigureAwait(false); } catch { }
                if (!plantedFlowers.TryRemove(channel.Id, out msgs))
                {
                    return;
                }

                await Task.WhenAll(msgs.Where(m => m != null).Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false);

                await CurrencyHandler.AddCurrencyAsync((IGuildUser)Context.User, $"Picked {NadekoBot.BotConfig.CurrencyPluralName}", msgs.Count, false).ConfigureAwait(false);

                var msg = await ReplyConfirmLocalized("picked", msgs.Count + NadekoBot.BotConfig.CurrencySign)
                          .ConfigureAwait(false);

                msg.DeleteAfter(10);
            }
Ejemplo n.º 7
0
            public async Task Plant(IUserMessage imsg)
            {
                var channel = (ITextChannel)imsg.Channel;

                var removed = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)imsg.Author, "Planted a flower.", 1, false).ConfigureAwait(false);

                if (!removed)
                {
                    await channel.SendMessageAsync($"You don't have any {Gambling.Gambling.CurrencyPluralName}.").ConfigureAwait(false);

                    return;
                }

                var          file = GetRandomCurrencyImagePath();
                IUserMessage msg;
                var          vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(Gambling.Gambling.CurrencyName[0]);

                var msgToSend = $"Oh how Nice! **{imsg.Author.Username}** planted {(vowelFirst ? "an" : "a")} {Gambling.Gambling.CurrencyName}. Pick it using {FaultyBot.ModulePrefixes[typeof(Games).Name]}pick";

                if (file == null)
                {
                    msg = await channel.SendMessageAsync(Gambling.Gambling.CurrencySign).ConfigureAwait(false);
                }
                else
                {
                    msg = await channel.SendFileAsync(file, msgToSend).ConfigureAwait(false);
                }
                plantedFlowers.AddOrUpdate(channel.Id, new List <IUserMessage>()
                {
                    msg
                }, (id, old) => { old.Add(msg); return(old); });
            }
Ejemplo n.º 8
0
            public async Task Betflip(int amount, string guess)
            {
                var guessStr = guess.Trim().ToUpperInvariant();

                if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS")
                {
                    return;
                }

                if (amount < NadekoBot.BotConfig.MinimumBetAmount)
                {
                    await Context.Channel.SendErrorAsync($"You can't bet less than {NadekoBot.BotConfig.MinimumBetAmount}{CurrencySign}.")
                    .ConfigureAwait(false);

                    return;
                }
                var removed = await CurrencyHandler.RemoveCurrencyAsync(Context.User, "Betflip Gamble", amount, false).ConfigureAwait(false);

                if (!removed)
                {
                    await Context.Channel.SendErrorAsync($"{Context.User.Mention} You don't have enough {CurrencyPluralName}.").ConfigureAwait(false);

                    return;
                }
                //heads = true
                //tails = false

                //todo this seems stinky, no time to look at it right now
                var  isHeads = guessStr == "HEADS" || guessStr == "H";
                bool result  = false;
                IEnumerable <byte> imageToSend;

                if (rng.Next(0, 2) == 1)
                {
                    imageToSend = _images.Heads;
                    result      = true;
                }
                else
                {
                    imageToSend = _images.Tails;
                }

                string str;

                if (isHeads == result)
                {
                    var toWin = (int)Math.Round(amount * NadekoBot.BotConfig.BetflipMultiplier);
                    str = $"{Context.User.Mention}`You guessed it!` You won {toWin}{CurrencySign}";
                    await CurrencyHandler.AddCurrencyAsync(Context.User, "Betflip Gamble", toWin, false).ConfigureAwait(false);
                }
                else
                {
                    str = $"{Context.User.Mention}`Better luck next time.`";
                }
                using (var toSend = imageToSend.ToStream())
                {
                    await Context.Channel.SendFileAsync(toSend, "result.png", str).ConfigureAwait(false);
                }
            }
Ejemplo n.º 9
0
        public async Task Heal(IUserMessage umsg, IGuildUser targetUser = null)
        {
            var        channel = (ITextChannel)umsg.Channel;
            IGuildUser user    = (IGuildUser)umsg.Author;

            if (targetUser == null)
            {
                await channel.SendMessageAsync("No such person.").ConfigureAwait(false);

                return;
            }

            if (Stats.ContainsKey(targetUser.Id))
            {
                var targetStats = Stats[targetUser.Id];
                if (targetStats.Hp == targetStats.MaxHp)
                {
                    await channel.SendMessageAsync($"{targetUser.Mention} already has full HP!").ConfigureAwait(false);

                    return;
                }
                //Payment~
                var amount = 1;

                var target = (targetUser.Id == user.Id) ? "yourself" : targetUser.Mention;
                if (amount > 0)
                {
                    if (!await CurrencyHandler.RemoveCurrencyAsync(user, $"Poke-Heal {target}", amount, true).ConfigureAwait(false))
                    {
                        try { await channel.SendMessageAsync($"{user.Mention} You don't have enough {CurrencyName}s.").ConfigureAwait(false); } catch { }
                        return;
                    }
                }

                //healing
                targetStats.Hp = targetStats.MaxHp;
                if (targetStats.Hp < 0)
                {
                    //Could heal only for half HP?
                    Stats[targetUser.Id].Hp = (targetStats.MaxHp / 2);
                    if (target == "yourself")
                    {
                        await channel.SendMessageAsync($"You revived yourself with one {CurrencySign}").ConfigureAwait(false);
                    }
                    else
                    {
                        await channel.SendMessageAsync($"{user.Mention} revived {targetUser.Mention} with one {CurrencySign}").ConfigureAwait(false);
                    }
                    return;
                }
                await channel.SendMessageAsync($"{user.Mention} healed {targetUser.Mention} with one {CurrencySign}").ConfigureAwait(false);

                return;
            }
            else
            {
                await channel.SendMessageAsync($"{targetUser.Mention} already has full HP!").ConfigureAwait(false);
            }
        }
Ejemplo n.º 10
0
    void Start()
    {
        currencyHandler = FindObjectOfType <CurrencyHandler>();
        Debug.Log(currencyHandler);

        uiInformations = FindObjectOfType <UIInformations>();
        Debug.Log(uiInformations);
    }
Ejemplo n.º 11
0
        public Currency(JSONProxy.Item item) : base(item)
        {
            this.Type       = ProxyMapper.GetOrbType(item);
            this.ChaosValue = CurrencyHandler.GetChaosValue(this.Type);
            this.StackInfo  = ProxyMapper.GetStackInfo(item.Properties);

            this.UniqueIDHash = base.getHash();
        }
Ejemplo n.º 12
0
            public async Task Betflip(int amount, string guess)
            {
                var guessStr = guess.Trim().ToUpperInvariant();

                if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS")
                {
                    return;
                }

                if (amount < NadekoBot.BotConfig.MinimumBetAmount)
                {
                    await ReplyErrorLocalized("min_bet_limit", NadekoBot.BotConfig.MinimumBetAmount + CurrencySign).ConfigureAwait(false);

                    return;
                }
                var removed = await CurrencyHandler.RemoveCurrencyAsync(Context.User, "Betflip Gamble", amount, false).ConfigureAwait(false);

                if (!removed)
                {
                    await ReplyErrorLocalized("not_enough", CurrencyPluralName).ConfigureAwait(false);

                    return;
                }
                //heads = true
                //tails = false

                //todo this seems stinky, no time to look at it right now
                var isHeads = guessStr == "HEADS" || guessStr == "H";
                var result  = false;
                IEnumerable <byte> imageToSend;

                if (rng.Next(0, 2) == 1)
                {
                    imageToSend = _images.Heads;
                    result      = true;
                }
                else
                {
                    imageToSend = _images.Tails;
                }

                string str;

                if (isHeads == result)
                {
                    var toWin = (int)Math.Round(amount * NadekoBot.BotConfig.BetflipMultiplier);
                    str = Context.User.Mention + " " + GetText("flip_guess", toWin + CurrencySign);
                    await CurrencyHandler.AddCurrencyAsync(Context.User, GetText("betflip_gamble"), toWin, false).ConfigureAwait(false);
                }
                else
                {
                    str = Context.User.Mention + " " + GetText("better_luck");
                }
                using (var toSend = imageToSend.ToStream())
                {
                    await Context.Channel.SendFileAsync(toSend, "result.png", str).ConfigureAwait(false);
                }
            }
Ejemplo n.º 13
0
        public async Task Heal(IGuildUser targetUser = null)
        {
            IGuildUser user = (IGuildUser)Context.User;

            if (targetUser == null)
            {
                await ReplyErrorLocalized("user_not_found").ConfigureAwait(false);

                return;
            }

            if (_stats.ContainsKey(targetUser.Id))
            {
                var targetStats = _stats[targetUser.Id];
                if (targetStats.Hp == targetStats.MaxHp)
                {
                    await ReplyErrorLocalized("already_full", Format.Bold(targetUser.ToString())).ConfigureAwait(false);

                    return;
                }
                //Payment~
                var amount = 1;

                var target = (targetUser.Id == user.Id) ? "yourself" : targetUser.Mention;
                if (amount > 0)
                {
                    if (!await CurrencyHandler.RemoveCurrencyAsync(user, $"Poke-Heal {target}", amount, true).ConfigureAwait(false))
                    {
                        await ReplyErrorLocalized("no_currency", NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }
                }

                //healing
                targetStats.Hp = targetStats.MaxHp;
                if (targetStats.Hp < 0)
                {
                    //Could heal only for half HP?
                    _stats[targetUser.Id].Hp = (targetStats.MaxHp / 2);
                    if (target == "yourself")
                    {
                        await ReplyConfirmLocalized("revive_yourself", NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }

                    await ReplyConfirmLocalized("revive_other", Format.Bold(targetUser.ToString()), NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);
                }
                await ReplyConfirmLocalized("healed", Format.Bold(targetUser.ToString()), NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);
            }
            else
            {
                await ErrorLocalized("already_full", Format.Bold(targetUser.ToString()));
            }
        }
Ejemplo n.º 14
0
            public async Task Betflip(int amount, string guess)
            {
                var guessStr = guess.Trim().ToUpperInvariant();

                if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS")
                {
                    return;
                }

                if (amount < NadekoBot.BotConfig.MinimumBetAmount)
                {
                    await Context.Channel.SendErrorAsync($"You can't bet less than {NadekoBot.BotConfig.MinimumBetAmount}{CurrencySign}.")
                    .ConfigureAwait(false);

                    return;
                }
                var removed = await CurrencyHandler.RemoveCurrencyAsync(Context.User, "Betflip Gamble", amount, false).ConfigureAwait(false);

                if (!removed)
                {
                    await Context.Channel.SendErrorAsync($"{Context.User.Mention} You don't have enough {CurrencyPluralName}.").ConfigureAwait(false);

                    return;
                }
                //heads = true
                //tails = false

                var    isHeads = guessStr == "HEADS" || guessStr == "H";
                bool   result  = false;
                string imgPathToSend;

                if (rng.Next(0, 2) == 1)
                {
                    imgPathToSend = headsPath;
                    result        = true;
                }
                else
                {
                    imgPathToSend = tailsPath;
                }

                string str;

                if (isHeads == result)
                {
                    var toWin = (int)Math.Round(amount * NadekoBot.BotConfig.BetflipMultiplier);
                    str = $"{Context.User.Mention}`You guessed it!` You won {toWin}{CurrencySign}";
                    await CurrencyHandler.AddCurrencyAsync(Context.User, "Betflip Gamble", toWin, false).ConfigureAwait(false);
                }
                else
                {
                    str = $"{Context.User.Mention}`Better luck next time.`";
                }

                await Context.Channel.SendFileAsync(File.Open(imgPathToSend, FileMode.OpenOrCreate), new FileInfo(imgPathToSend).Name, str).ConfigureAwait(false);
            }
Ejemplo n.º 15
0
            private async Task AnswerReceived(SocketMessage imsg)
            {
                try
                {
                    if (imsg.Author.IsBot)
                    {
                        return;
                    }
                    var msg = imsg as SocketUserMessage;
                    if (msg == null)
                    {
                        return;
                    }

                    if (this.Channel == null || this.Channel.Id != this.Channel.Id)
                    {
                        return;
                    }

                    var guess = msg.Content;

                    var distance = CurrentSentence.LevenshteinDistance(guess);
                    var decision = Judge(distance, guess.Length);
                    if (decision && !finishedUserIds.Contains(msg.Author.Id))
                    {
                        var wpm = CurrentSentence.Length / WORD_VALUE / sw.Elapsed.Seconds * 60;
                        finishedUserIds.Add(msg.Author.Id);
                        await this.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
                                                      .WithTitle((string)$"{msg.Author} finished the race!")
                                                      .AddField(efb => efb.WithName("Place").WithValue($"#{finishedUserIds.Count}").WithIsInline(true))
                                                      .AddField(efb => efb.WithName("WPM").WithValue($"{wpm:F2} *[{sw.Elapsed.Seconds.ToString()}sec]*").WithIsInline(true))
                                                      .AddField(efb => efb.WithName((string)"Errors").WithValue((string)distance.ToString()).WithIsInline((bool)true)))
                        .ConfigureAwait(false);

                        //  give reward for the finishing people
                        int reward = TypeStartCurrencyRewardTracker;
                        if (reward > 0)
                        {
                            await CurrencyHandler.AddCurrencyAsync(msg.Author, "TypeStart Score Points", reward, false).ConfigureAwait(false);

                            await Channel.SendConfirmAsync($"**{msg.Author}** earned {reward} {NadekoBot.BotConfig.CurrencySign}!").ConfigureAwait(false);

                            if (TypeStartCurrencyRewardTracker > 1)
                            {
                                TypeStartCurrencyRewardTracker -= 1;
                            }
                        }

                        if (finishedUserIds.Count % 4 == 0)
                        {
                            await this.Channel.SendConfirmAsync($":exclamation: A lot of people finished, here is the text for those still typing:\n\n**{Format.Sanitize(CurrentSentence.Replace(" ", " \x200B")).SanitizeMentions()}**").ConfigureAwait(false);
                        }
                    }
                }
                catch (Exception ex) { _log.Warn(ex); }
            }
Ejemplo n.º 16
0
                public AnimalRace(ulong serverId, ITextChannel ch)
                {
                    this._log        = LogManager.GetCurrentClassLogger();
                    this.serverId    = serverId;
                    this.raceChannel = ch;
                    if (!AnimalRaces.TryAdd(serverId, this))
                    {
                        Fail = true;
                        return;
                    }

                    using (var uow = DbHandler.UnitOfWork())
                    {
                        animals = new ConcurrentQueue <string>(uow.BotConfig.GetOrCreate().RaceAnimals.Select(ra => ra.Icon).Shuffle());
                    }


                    var cancelSource = new CancellationTokenSource();
                    var token        = cancelSource.Token;
                    var fullgame     = CheckForFullGameAsync(token);

                    Task.Run(async() =>
                    {
                        try
                        {
                            try { await raceChannel.SendMessageAsync($"🏁`Race is starting in 20 seconds or when the room is full. Type {NadekoBot.ModulePrefixes[typeof(Gambling).Name]}jr to join the race.`"); } catch (Exception ex) { _log.Warn(ex); }
                            var t   = await Task.WhenAny(Task.Delay(20000, token), fullgame);
                            Started = true;
                            cancelSource.Cancel();
                            if (t == fullgame)
                            {
                                try { await raceChannel.SendMessageAsync("🏁`Race full, starting right now!`"); } catch (Exception ex) { _log.Warn(ex); }
                            }
                            else if (participants.Count > 1)
                            {
                                try { await raceChannel.SendMessageAsync("🏁`Game starting with " + participants.Count + " participants.`"); } catch (Exception ex) { _log.Warn(ex); }
                            }
                            else
                            {
                                try { await raceChannel.SendMessageAsync("🏁`Race failed to start since there was not enough participants.`"); } catch (Exception ex) { _log.Warn(ex); }
                                var p = participants.FirstOrDefault();

                                if (p != null)
                                {
                                    await CurrencyHandler.AddCurrencyAsync(p.User, "BetRace", p.AmountBet, true).ConfigureAwait(false);
                                }
                                End();
                                return;
                            }
                            await Task.Run(StartRace);
                            End();
                        }
                        catch { }
                    });
                }
Ejemplo n.º 17
0
        public async Task Award(int amount, ulong usrId)
        {
            if (amount <= 0)
            {
                return;
            }

            await CurrencyHandler.AddCurrencyAsync(usrId, $"Awarded by bot owner. ({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false);

            await Context.Channel.SendConfirmAsync($"{Context.User.Mention} successfully awarded {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} to <@{usrId}>!").ConfigureAwait(false);
        }
Ejemplo n.º 18
0
        public async Task Award(int amount, ulong usrId)
        {
            if (amount <= 0)
            {
                return;
            }

            await CurrencyHandler.AddCurrencyAsync(usrId, $"Awarded by bot owner. ({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false);

            await ReplyConfirmLocalized("awarded", amount + CurrencySign, $"<@{usrId}>").ConfigureAwait(false);
        }
Ejemplo n.º 19
0
        public async Task Award(int amount, ulong usrId)
        {
            if (amount <= 0)
            {
                return;
            }

            await CurrencyHandler.AddCurrencyAsync(usrId, $"Awarded by bot owner. ({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false);

            await Context.Channel.SendConfirmAsync($"{Context.User.Mention} awarded {amount}{CurrencySign} to <@{usrId}>!").ConfigureAwait(false);
        }
Ejemplo n.º 20
0
        public void ShouldReturnErrorWhenNotExistisCurrency()
        {
            var handle  = new CurrencyHandler(new FakeCurrencyRepository());
            var command = new CreateCurrencyCommand();

            command.Amount              = 10;
            command.CurrencyOrigin      = "AAA";
            command.CurrencyDestination = "BBB";

            handle.Handle(command);
            Assert.AreEqual(false, handle.Valid);
        }
Ejemplo n.º 21
0
        public async Task BetRoll(IUserMessage umsg, long amount)
        {
            var channel = (ITextChannel)umsg.Channel;

            if (amount < 1)
            {
                return;
            }

            var guildUser = (IGuildUser)umsg.Author;

            long userFlowers;

            using (var uow = DbHandler.UnitOfWork())
            {
                userFlowers = uow.Currency.GetOrCreate(umsg.Author.Id).Amount;
            }

            if (userFlowers < amount)
            {
                await channel.SendMessageAsync($"{guildUser.Mention} You don't have enough {Gambling.CurrencyPluralName}. You only have {userFlowers}{Gambling.CurrencySign}.").ConfigureAwait(false);

                return;
            }

            await CurrencyHandler.RemoveCurrencyAsync(guildUser, "Betroll Gamble", amount, false).ConfigureAwait(false);

            var rng = new NadekoRandom().Next(0, 101);
            var str = $"{guildUser.Mention} `You rolled {rng}.` ";

            if (rng < 67)
            {
                str += "Better luck next time.";
            }
            else if (rng < 91)
            {
                str += $"Congratulations! You won {amount * 2}{Gambling.CurrencySign} for rolling above 66";
                await CurrencyHandler.AddCurrencyAsync(guildUser, "Betroll Gamble", amount * 2, false).ConfigureAwait(false);
            }
            else if (rng < 100)
            {
                str += $"Congratulations! You won {amount * 3}{Gambling.CurrencySign} for rolling above 90.";
                await CurrencyHandler.AddCurrencyAsync(guildUser, "Betroll Gamble", amount * 3, false).ConfigureAwait(false);
            }
            else
            {
                str += $"👑 Congratulations! You won {amount * 10}{Gambling.CurrencySign} for rolling **100**. 👑";
                await CurrencyHandler.AddCurrencyAsync(guildUser, "Betroll Gamble", amount * 10, false).ConfigureAwait(false);
            }

            await channel.SendMessageAsync(str).ConfigureAwait(false);
        }
Ejemplo n.º 22
0
            public async Task Plant(int amount = 1)
            {
                if (amount < 1)
                {
                    return;
                }

                var removed = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)Context.User, $"Planted a {NadekoBot.BotConfig.CurrencyName}", amount, false).ConfigureAwait(false);

                if (!removed)
                {
                    await ReplyErrorLocalized("not_enough", NadekoBot.BotConfig.CurrencySign).ConfigureAwait(false);

                    return;
                }

                var imgData = GetRandomCurrencyImage();

                //todo upload all currency images to transfer.sh and use that one as cdn
                //and then

                var msgToSend = GetText("planted",
                                        Format.Bold(Context.User.ToString()),
                                        amount + NadekoBot.BotConfig.CurrencySign,
                                        Prefix);

                if (amount > 1)
                {
                    msgToSend += " " + GetText("pick_pl", Prefix);
                }
                else
                {
                    msgToSend += " " + GetText("pick_sn", Prefix);
                }

                IUserMessage msg;

                using (var toSend = imgData.Value.ToStream())
                {
                    msg = await Context.Channel.SendFileAsync(toSend, imgData.Key, msgToSend).ConfigureAwait(false);
                }

                var msgs = new IUserMessage[amount];

                msgs[0] = msg;

                plantedFlowers.AddOrUpdate(Context.Channel.Id, msgs.ToList(), (id, old) =>
                {
                    old.AddRange(msgs);
                    return(old);
                });
            }
Ejemplo n.º 23
0
        public async Task Award(IUserMessage umsg, int amount, ulong usrId)
        {
            var channel = (ITextChannel)umsg.Channel;

            if (amount <= 0)
            {
                return;
            }

            await CurrencyHandler.AddCurrencyAsync(usrId, $"Awarded by bot owner. ({umsg.Author.Username}/{umsg.Author.Id})", amount).ConfigureAwait(false);

            await channel.SendMessageAsync($"{umsg.Author.Mention} successfully awarded {amount} {(amount == 1 ? Gambling.CurrencyName : Gambling.CurrencyPluralName)} to <@{usrId}>!").ConfigureAwait(false);
        }
Ejemplo n.º 24
0
        public async Task Award(IUserMessage umsg, int amount, [Remainder] IRole role)
        {
            var channel = (ITextChannel)umsg.Channel;
            var users   = channel.Guild.GetUsers()
                          .Where(u => u.Roles.Contains(role))
                          .ToList();
            await Task.WhenAll(users.Select(u => CurrencyHandler.AddCurrencyAsync(u.Id,
                                                                                  $"Awarded by bot owner to **{role.Name}** role. ({umsg.Author.Username}/{umsg.Author.Id})",
                                                                                  amount)))
            .ConfigureAwait(false);

            await channel.SendMessageAsync($"Awarded `{amount}` {Gambling.CurrencyPluralName} to `{users.Count}` users from `{role.Name}` role.")
            .ConfigureAwait(false);
        }
Ejemplo n.º 25
0
        public async Task Award(int amount, [Remainder] IRole role)
        {
            var channel = (ITextChannel)Context.Channel;
            var users   = (await Context.Guild.GetUsersAsync())
                          .Where(u => u.GetRoles().Contains(role))
                          .ToList();
            await Task.WhenAll(users.Select(u => CurrencyHandler.AddCurrencyAsync(u.Id,
                                                                                  $"Awarded by bot owner to **{role.Name}** role. ({Context.User.Username}/{Context.User.Id})",
                                                                                  amount)))
            .ConfigureAwait(false);

            await Context.Channel.SendConfirmAsync($"Awarded `{amount}` {CurrencyPluralName} to `{users.Count}` users from `{role.Name}` role.")
            .ConfigureAwait(false);
        }
Ejemplo n.º 26
0
//    [SerializeField] private bool overdrawn = false;

    // Use this for initialization
    void Awake()
    {
        //Singleton
        if (instanceCount++ == 0)
        {
            instance = this;
        }
        else
        {
            Destroy(this);
        }

        gold = startingGold;
    }
Ejemplo n.º 27
0
        public void Initialize()
        {
            OutcomeHandler outcomeHandler = new OutcomeHandler(outcomeRepository);

            commandHandlers.AddAll(outcomeHandler);

            CategoryHandler categoryHandler = new CategoryHandler(categoryRepository);

            commandHandlers.AddAll(categoryHandler);

            CurrencyHandler currencyHandler = new CurrencyHandler(currencyListRepository);

            commandHandlers.AddAll(currencyHandler);
        }
Ejemplo n.º 28
0
        public async Task Award(int amount, [Remainder] IRole role)
        {
            var users = (await Context.Guild.GetUsersAsync())
                        .Where(u => u.GetRoles().Contains(role))
                        .ToList();
            await Task.WhenAll(users.Select(u => CurrencyHandler.AddCurrencyAsync(u.Id,
                                                                                  $"Awarded by bot owner to **{role.Name}** role. ({Context.User.Username}/{Context.User.Id})",
                                                                                  amount)))
            .ConfigureAwait(false);

            await ReplyConfirmLocalized("mass_award",
                                        amount + CurrencySign,
                                        Format.Bold(users.Count.ToString()),
                                        Format.Bold(role.Name)).ConfigureAwait(false);
        }
Ejemplo n.º 29
0
        public async Task BetRoll(long amount)
        {
            if (amount < 1)
            {
                return;
            }

            long userFlowers;

            using (var uow = DbHandler.UnitOfWork())
            {
                userFlowers = uow.Currency.GetOrCreate(Context.User.Id).Amount;
            }

            if (userFlowers < amount)
            {
                await Context.Channel.SendErrorAsync($"{Context.User.Mention} You don't have enough {CurrencyPluralName}. You only have {userFlowers}{CurrencySign}.").ConfigureAwait(false);

                return;
            }

            await CurrencyHandler.RemoveCurrencyAsync(Context.User, "Betroll Gamble", amount, false).ConfigureAwait(false);

            var rng = new NadekoRandom().Next(0, 101);
            var str = $"{Context.User.Mention} `You rolled {rng}.` ";

            if (rng < 67)
            {
                str += "Better luck next time.";
            }
            else if (rng < 91)
            {
                str += $"Congratulations! You won {amount * NadekoBot.BotConfig.Betroll67Multiplier}{CurrencySign} for rolling above 66";
                await CurrencyHandler.AddCurrencyAsync(Context.User, "Betroll Gamble", (int)(amount *NadekoBot.BotConfig.Betroll67Multiplier), false).ConfigureAwait(false);
            }
            else if (rng < 100)
            {
                str += $"Congratulations! You won {amount * NadekoBot.BotConfig.Betroll91Multiplier}{CurrencySign} for rolling above 90.";
                await CurrencyHandler.AddCurrencyAsync(Context.User, "Betroll Gamble", (int)(amount *NadekoBot.BotConfig.Betroll91Multiplier), false).ConfigureAwait(false);
            }
            else
            {
                str += $"👑 Congratulations! You won {amount * NadekoBot.BotConfig.Betroll100Multiplier}{CurrencySign} for rolling **100**. 👑";
                await CurrencyHandler.AddCurrencyAsync(Context.User, "Betroll Gamble", (int)(amount *NadekoBot.BotConfig.Betroll100Multiplier), false).ConfigureAwait(false);
            }

            await Context.Channel.SendConfirmAsync(str).ConfigureAwait(false);
        }
Ejemplo n.º 30
0
        public async Task Take(long amount, [Remainder] ulong usrId)
        {
            if (amount <= 0)
            {
                return;
            }

            if (await CurrencyHandler.RemoveCurrencyAsync(usrId, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false))
            {
                await Context.Channel.SendConfirmAsync($"{Context.User.Mention} successfully took {amount} {(amount == 1 ? CurrencyName : CurrencyPluralName)} from <@{usrId}>!").ConfigureAwait(false);
            }
            else
            {
                await Context.Channel.SendErrorAsync($"{Context.User.Mention} was unable to take {amount} {(amount == 1 ? CurrencyName : CurrencyPluralName)} from `{usrId}` because the user doesn't have that much {CurrencyPluralName}!").ConfigureAwait(false);
            }
        }