Пример #1
0
        public async Task ForceUpdateCardsAsync([Summary("WID kart")] params ulong[] ids)
        {
            using (var db = new Database.UserContext(Config))
            {
                var cards = db.Cards.Where(x => ids.Any(c => c == x.Id)).ToList();
                if (cards.Count < 1)
                {
                    await ReplyAsync("", embed : $"{Context.User.Mention} nie odnaleziono kart.".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                foreach (var card in cards)
                {
                    try
                    {
                        await card.Update(null, _shClient);

                        _waifu.DeleteCardImageIfExist(card);
                    }
                    catch (Exception) { }
                }

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"users" });

                await ReplyAsync("", embed : $"Zaktualizowano {cards.Count} kart.".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #2
0
        public async Task TransferCardAsync([Summary("użytkownik")] SocketGuildUser user, [Summary("WIDs")] params ulong[] wids)
        {
            using (var db = new Database.UserContext(Config))
            {
                var thisCards = db.Cards.Include(x => x.TagList).Where(x => wids.Any(c => c == x.Id)).ToList();
                if (thisCards.Count < 1)
                {
                    await ReplyAsync("", embed : "Nie odnaleziono kart!".ToEmbedMessage(EMType.Bot).Build());

                    return;
                }

                string reply = $"Karta {thisCards.First().GetString(false, false, true)} została przeniesiona.";
                if (thisCards.Count > 1)
                {
                    reply = $"Przeniesiono {thisCards.Count} kart.";
                }

                foreach (var thisCard in thisCards)
                {
                    thisCard.Active = false;
                    thisCard.InCage = false;
                    thisCard.TagList.Clear();
                    thisCard.GameDeckId = user.Id;
                }

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{Context.User.Id}", "users" });

                await ReplyAsync("", embed : reply.ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #3
0
        public async Task GiveDailyScAsync()
        {
            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(Context.User.Id);

                var daily = botuser.TimeStatuses.FirstOrDefault(x => x.Type == Database.Models.StatusType.Daily);
                if (daily == null)
                {
                    daily = new Database.Models.TimeStatus
                    {
                        Type   = Database.Models.StatusType.Daily,
                        EndsAt = DateTime.MinValue
                    };
                    botuser.TimeStatuses.Add(daily);
                }

                if (daily.IsActive())
                {
                    var timeTo = (int)daily.RemainingMinutes();
                    await ReplyAsync("", embed : $"{Context.User.Mention} następne drobne możesz otrzymać dopiero za {timeTo / 60}h {timeTo % 60}m!".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                daily.EndsAt   = DateTime.Now.AddHours(20);
                botuser.ScCnt += 100;

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}" });

                await ReplyAsync("", embed : $"{Context.User.Mention} łap drobne na waciki!".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #4
0
        public async Task GiveHourlyScAsync()
        {
            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(Context.User.Id);

                var hourly = botuser.TimeStatuses.FirstOrDefault(x => x.Type == Database.Models.StatusType.Hourly);
                if (hourly == null)
                {
                    hourly = new Database.Models.TimeStatus
                    {
                        Type   = Database.Models.StatusType.Hourly,
                        EndsAt = DateTime.MinValue
                    };
                    botuser.TimeStatuses.Add(hourly);
                }

                if (hourly.IsActive())
                {
                    var timeTo = (int)hourly.RemainingSeconds();
                    await ReplyAsync("", embed : $"{Context.User.Mention} następne zaskórniaki możesz otrzymać dopiero za {timeTo / 60}m {timeTo % 60}s!".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                hourly.EndsAt  = DateTime.Now.AddHours(1);
                botuser.ScCnt += 5;

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });

                await ReplyAsync("", embed : $"{Context.User.Mention} łap piątaka!".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #5
0
        public async Task TransferCardAsync([Summary("WID")] ulong wid, [Summary("użytkownik")] SocketGuildUser user)
        {
            using (var db = new Database.UserContext(Config))
            {
                var thisCard = db.Cards.FirstOrDefault(x => x.Id == wid);
                if (thisCard == null)
                {
                    await ReplyAsync("", embed : $"Karta o WID: `{wid}` nie istnieje.".ToEmbedMessage(EMType.Bot).Build());

                    return;
                }

                var oldOwnerId = thisCard.GameDeckId;
                var targetUser = await db.GetUserOrCreateAsync(user.Id);

                var fromUser = await db.GetUserOrCreateAsync(oldOwnerId);

                thisCard.Active = false;
                thisCard.InCage = false;
                thisCard.Tags   = null;

                fromUser.GameDeck.Cards.Remove(thisCard);
                targetUser.GameDeck.Cards.Add(thisCard);
                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{Context.User.Id}", "users", $"user-{oldOwnerId}" });

                await ReplyAsync("", embed : $"Karta {thisCard.GetString(false, false, true)} została przeniesiona.".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #6
0
        public async Task PlayOnSlotMachineAsync([Summary("typ(info - wyświetla informacje)")] string type = "game")
        {
            if (type != "game")
            {
                await ReplyAsync("", false, $"{_fun.GetSlotMachineGameInfo()}".ToEmbedMessage(EMType.Info).Build());

                return;
            }

            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(Context.User.Id);

                var machine = new SlotMachine(botuser);

                var toPay = machine.ToPay();
                if (botuser.ScCnt < toPay)
                {
                    await ReplyAsync("", embed : $"{Context.User.Mention} brakuje Ci SC, aby za tyle zagrać.".ToEmbedMessage(EMType.Error).Build());

                    return;
                }
                var win = machine.Play(new SlotEqualRandom());
                botuser.ScCnt += win - toPay;

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });

                await ReplyAsync("", embed : $"{_fun.GetSlotMachineResult(machine.Draw(), Context.User, botuser, win)}".ToEmbedMessage(EMType.Bot).Build());
            }
        }
Пример #7
0
        public async Task RestoreCardsAsync([Summary("użytkownik")] SocketGuildUser user)
        {
            using (var db = new Database.UserContext(Config))
            {
                var bUser = await db.GetUserOrCreateAsync(user.Id);

                var thisCards = db.Cards.Include(x => x.TagList).Where(x => (x.LastIdOwner == user.Id || (x.FirstIdOwner == user.Id && x.LastIdOwner == 0)) && x.GameDeckId == 1).ToList();
                if (thisCards.Count < 1)
                {
                    await ReplyAsync("", embed : "Nie odnaleziono kart!".ToEmbedMessage(EMType.Bot).Build());

                    return;
                }

                string reply = $"Karta {thisCards.First().GetString(false, false, true)} została przeniesiona.";
                if (thisCards.Count > 1)
                {
                    reply = $"Przeniesiono {thisCards.Count} kart.";
                }

                foreach (var thisCard in thisCards)
                {
                    thisCard.Active = false;
                    thisCard.InCage = false;
                    thisCard.TagList.Clear();
                    thisCard.GameDeckId = user.Id;
                }

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{Context.User.Id}", "users" });

                await ReplyAsync("", embed : reply.ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #8
0
        public async Task ChangeBackgroundAsync([Summary("bezpośredni adres do obrazka (450 x 150)")] string imgUrl)
        {
            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(Context.User.Id);

                if (botuser.ScCnt < 5000)
                {
                    await ReplyAsync("", embed : $"{Context.User.Mention} nie posiadasz wystarczającej liczby SC!".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                if (await _profile.SaveProfileImageAsync(imgUrl, $"./GOut/Saved/BG{botuser.Id}.png", 450, 150, true))
                {
                    botuser.BackgroundProfileUri = $"./GOut/Saved/BG{botuser.Id}.png";
                }
                else
                {
                    await ReplyAsync("", embed : "Nie wykryto obrazka! Upewnij się, że podałeś poprawny adres!".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                botuser.ScCnt -= 5000;

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });

                await ReplyAsync("", embed : $"Zmieniono tło profilu użytkownika: {Context.User.Mention}!".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #9
0
        public async Task SlotMachineSettingsAsync([Summary("typ nastaw(info - wyświetla informacje)")] SlotMachineSetting setting = SlotMachineSetting.Info, [Summary("wartość nastawy")] string value = "info")
        {
            if (setting == SlotMachineSetting.Info)
            {
                await ReplyAsync("", false, $"{_fun.GetSlotMachineInfo()}".ToEmbedMessage(EMType.Info).Build());

                return;
            }

            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(Context.User.Id);

                if (!botuser.ApplySlotMachineSetting(setting, value))
                {
                    await ReplyAsync("", embed : $"Podano niewłaściwą wartość parametru!".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });
            }

            await ReplyAsync("", embed : $"{Context.User.Mention} zmienił nastawy automatu.".ToEmbedMessage(EMType.Success).Build());
        }
Пример #10
0
        public async Task GenerateItemAsync([Summary("użytkownik")] SocketGuildUser user, [Summary("przedmiot")] ItemType itemType, [Summary("liczba przedmiotów")] uint count = 1,
                                            [Summary("jakość przedmiotu")] Quality quality = Quality.Broken)
        {
            var item = itemType.ToItem(count, quality);

            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(user.Id);

                var thisItem = botuser.GameDeck.Items.FirstOrDefault(x => x.Type == item.Type && x.Quality == item.Quality);
                if (thisItem == null)
                {
                    thisItem = item;
                    botuser.GameDeck.Items.Add(thisItem);
                }
                else
                {
                    thisItem.Count += count;
                }

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });

                string cnt = (count > 1) ? $" x{count}" : "";
                await ReplyAsync("", embed : $"{user.Mention} otrzymał _{item.Name}_{cnt}.".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #11
0
        public async Task AddGlobalEmotesAsync()
        {
            var user = Context.User as SocketGuildUser;

            if (user == null)
            {
                return;
            }

            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(user.Id);

                if (botuser.TcCnt < 4000)
                {
                    await ReplyAsync("", embed : $"{user.Mention} nie posiadasz wystarczającej liczby TC!".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                using (var cdb = new Database.GuildConfigContext(Config))
                {
                    var gConfig = await cdb.GetCachedGuildFullConfigAsync(Context.Guild.Id);

                    var gRole = Context.Guild.GetRole(gConfig.GlobalEmotesRole);
                    if (gRole == null)
                    {
                        await ReplyAsync("", embed : "Serwer nie ma ustawionej roli globalnych emotek.".ToEmbedMessage(EMType.Bot).Build());

                        return;
                    }

                    var global = botuser.TimeStatuses.FirstOrDefault(x => x.Type == Database.Models.StatusType.Globals && x.Guild == Context.Guild.Id);
                    if (global == null)
                    {
                        global = new Database.Models.TimeStatus
                        {
                            Type   = StatusType.Globals,
                            Guild  = Context.Guild.Id,
                            EndsAt = DateTime.Now,
                        };
                        botuser.TimeStatuses.Add(global);
                    }

                    if (!user.Roles.Contains(gRole))
                    {
                        await user.AddRoleAsync(gRole);
                    }

                    global.EndsAt  = global.EndsAt.AddMonths(1);
                    botuser.TcCnt -= 4000;
                }

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });

                await ReplyAsync("", embed : $"{user.Mention} wykupił miesiąc globalnych emotek!".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #12
0
        public async Task ChangeTitleCardAsync([Summary("WID")] ulong wid, [Summary("tytuł")][Remainder] string title = null)
        {
            using (var db = new Database.UserContext(Config))
            {
                var thisCard = db.Cards.FirstOrDefault(x => x.Id == wid);
                if (thisCard == null)
                {
                    await ReplyAsync("", embed : $"Taka karta nie istnieje.".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                if (title != null)
                {
                    thisCard.Title = title;
                }
                else
                {
                    var res = await _shClient.GetCharacterInfoAsync(thisCard.Character);

                    if (res.IsSuccessStatusCode())
                    {
                        thisCard.Title = res.Body?.Relations?.OrderBy(x => x.Id)?.FirstOrDefault()?.Title ?? "????";
                    }
                }

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { "users" });

                await ReplyAsync("", embed : $"Nowy tytuł to: `{thisCard.Title}`".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #13
0
        public async Task FactoryUserAsync([Summary("id użytkownika")] ulong id, [Summary("czy usunąć karty?")] bool cards = false)
        {
            using (var db = new Database.UserContext(Config))
            {
                var fakeu = await db.GetUserOrCreateAsync(1);

                var user = await db.GetUserOrCreateAsync(id);

                if (!cards)
                {
                    foreach (var card in user.GameDeck.Cards)
                    {
                        card.InCage = false;
                        card.TagList.Clear();
                        card.LastIdOwner = id;
                        fakeu.GameDeck.Cards.Add(card);
                    }
                    user.GameDeck.Cards.Clear();
                }

                db.Users.Remove(user);
                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { "users", $"user-{id}" });
            }

            await ReplyAsync("", embed : $"Użytkownik o id: `{id}` został wymazany.".ToEmbedMessage(EMType.Success).Build());
        }
Пример #14
0
        public async Task ConnectAsync([Summary("adres do profilu")] string url)
        {
            switch (_shinden.ParseUrlToShindenId(url, out var shindenId))
            {
            case Services.UrlParsingError.InvalidUrl:
                await ReplyAsync("", embed : "Wygląda na to, że podałeś niepoprawny link.".ToEmbedMessage(EMType.Error).Build());

                return;

            case Services.UrlParsingError.InvalidUrlForum:
                await ReplyAsync("", embed : "Wygląda na to, że podałeś link do forum zamiast strony.".ToEmbedMessage(EMType.Error).Build());

                return;

            default:
            case Services.UrlParsingError.None:
                break;
            }

            var response = await _shclient.User.GetAsync(shindenId);

            if (response.IsSuccessStatusCode())
            {
                var user = response.Body;
                var userNameInDiscord = (Context.User as SocketGuildUser).Nickname ?? Context.User.Username;

                if (!user.Name.Equals(userNameInDiscord))
                {
                    await ReplyAsync("", embed : "Wykryto próbę podszycia się. Nieładnie!".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                using (var db = new Database.UserContext(Config))
                {
                    if (db.Users.Any(x => x.Shinden == shindenId))
                    {
                        await ReplyAsync("", embed : "Wygląda na to, że ktoś już połączył się z tym kontem.".ToEmbedMessage(EMType.Error).Build());

                        return;
                    }

                    var botuser = await db.GetUserOrCreateAsync(Context.User.Id);

                    botuser.Shinden = shindenId;

                    await db.SaveChangesAsync();

                    QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}" });
                }

                await ReplyAsync("", embed : "Konta zostały połączone.".ToEmbedMessage(EMType.Success).Build());

                return;
            }

            await ReplyAsync("", embed : $"Brak połączenia z Shindenem! ({response.Code})".ToEmbedMessage(EMType.Error).Build());
        }
Пример #15
0
        public async Task FactoryUserAsync([Summary("id użytkownika")] ulong id, [Summary("wartość tc")] long value)
        {
            using (var db = new Database.UserContext(Config))
            {
                var user = await db.GetUserOrCreateAsync(id);

                foreach (var card in user.GameDeck.Cards.OrderByDescending(x => x.CreationDate).ToList())
                {
                    value -= 50;
                    user.GameDeck.Cards.Remove(card);

                    if (value <= 0)
                    {
                        break;
                    }
                }

                if (value > 0)
                {
                    var kct = value / 50;
                    if (user.GameDeck.Karma > 0)
                    {
                        user.GameDeck.Karma -= kct;
                        if (user.GameDeck.Karma < 0)
                        {
                            user.GameDeck.Karma = 0;
                        }
                    }
                    else
                    {
                        user.GameDeck.Karma += kct;
                        if (user.GameDeck.Karma > 0)
                        {
                            user.GameDeck.Karma = 0;
                        }
                    }

                    user.GameDeck.CTCnt -= kct;
                    if (user.GameDeck.CTCnt < 0)
                    {
                        user.GameDeck.CTCnt = 0;
                        kct = 0;
                    }

                    if (kct > 0)
                    {
                        user.GameDeck.Items.Clear();
                    }
                }

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { "users", $"user-{id}" });
            }

            await ReplyAsync("", embed : $"Użytkownik o id: `{id}` został zrównany.".ToEmbedMessage(EMType.Success).Build());
        }
Пример #16
0
        public async Task AddQuestionAsync([FromBody] Database.Models.Question question)
        {
            using (var db = new Database.UserContext(_config))
            {
                db.Questions.Add(question);
                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"quiz" });
            }
            await "Question added!".ToResponse(200).ExecuteResultAsync(ControllerContext);
        }
Пример #17
0
        public async Task TransferCardAsync([Summary("użytkownik")] SocketGuildUser user)
        {
            using (var db = new Database.UserContext(Config))
            {
                var targetUser = await db.GetUserOrCreateAsync(user.Id);

                targetUser.IsBlacklisted = !targetUser.IsBlacklisted;
                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{Context.User.Id}", "users" });

                await ReplyAsync("", embed : $"{user.Mention} - blacklist: {targetUser.IsBlacklisted}".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #18
0
        public async Task FactoryUserAsync([Summary("id użytkownika")] ulong id)
        {
            using (var db = new Database.UserContext(Config))
            {
                var user = await db.GetUserOrCreateAsync(id);

                db.Users.Remove(user);
                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { "users" });
            }

            await ReplyAsync("", embed : $"Użytkownik o id: `{id}` został wymazany.".ToEmbedMessage(EMType.Success).Build());
        }
Пример #19
0
        public async Task TossCoinAsync([Summary("strona monety(orzeł/reszka)")] Services.CoinSide side, [Summary("ilość SC (maks. stawka 10000)")] int amount)
        {
            if (amount <= 0 || amount > 10000)
            {
                await ReplyAsync("", embed : $"{Context.User.Mention} możesz rzucić za maksymalnie 10000 SC!".ToEmbedMessage(EMType.Error).Build());

                return;
            }

            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(Context.User.Id);

                if (botuser.ScCnt < amount)
                {
                    await ReplyAsync("", embed : $"{Context.User.Mention} nie posiadasz wystarczającej liczby SC!".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                botuser.ScCnt -= amount;
                var thrown = _fun.RandomizeSide();
                var embed  = $"{Context.User.Mention} pudło! Obecnie posiadasz {botuser.ScCnt} SC.".ToEmbedMessage(EMType.Error);

                botuser.Stats.Tail += (thrown == CoinSide.Tail) ? 1 : 0;
                botuser.Stats.Head += (thrown == CoinSide.Head) ? 1 : 0;

                if (thrown == side)
                {
                    ++botuser.Stats.Hit;
                    botuser.ScCnt            += amount * 2;
                    botuser.Stats.IncomeInSc += amount;
                    embed = $"{Context.User.Mention} trafiony zatopiony! Obecnie posiadasz {botuser.ScCnt} SC.".ToEmbedMessage(EMType.Success);
                }
                else
                {
                    ++botuser.Stats.Misd;
                    botuser.Stats.ScLost     += amount;
                    botuser.Stats.IncomeInSc -= amount;
                }

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });

                await ReplyAsync("", embed : embed.Build());

                await Context.Channel.SendFileAsync($"./Pictures/coin{(int)thrown}.png");
            }
        }
Пример #20
0
        public async Task ChangeUserExpAsync([Summary("użytkownik")] SocketGuildUser user, [Summary("liczba punktów doświadczenia")] long amount)
        {
            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(user.Id);

                botuser.ExpCnt += amount;

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });

                await ReplyAsync("", embed : $"{user.Mention} ma teraz {botuser.ExpCnt} punktów doświadczenia.".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #21
0
        public async Task GiveUserScAsync([Summary("użytkownik")] SocketGuildUser user, [Summary("liczba SC(min. 1000)")] uint value)
        {
            if (value < 1000)
            {
                await ReplyAsync("", embed : "Nie można podarować mniej jak 1000 SC.".ToEmbedMessage(EMType.Error).Build());

                return;
            }

            if (user.Id == Context.User.Id)
            {
                await ReplyAsync("", embed : "Coś tutaj nie gra.".ToEmbedMessage(EMType.Error).Build());

                return;
            }

            using (var db = new Database.UserContext(Config))
            {
                if (!db.Users.Any(x => x.Id == user.Id))
                {
                    await ReplyAsync("", embed : "Ta osoba nie ma profilu bota.".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                var targetUser = await db.GetUserOrCreateAsync(user.Id);

                var thisUser = await db.GetUserOrCreateAsync(Context.User.Id);

                if (thisUser.ScCnt < value)
                {
                    await ReplyAsync("", embed : $"{Context.User.Mention} nie masz wystarczającej ilości SC.".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                thisUser.ScCnt -= value;

                var newScCnt = (value * 60) / 100;
                targetUser.ScCnt += newScCnt;

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{thisUser.Id}", "users", $"user-{targetUser.Id}" });

                await ReplyAsync("", embed : $"{Context.User.Mention} podarował {user.Mention} {newScCnt} SC".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #22
0
        public async Task ChangeUserLevelAsync([Summary("użytkownik")] SocketGuildUser user, [Summary("poziom")] long level)
        {
            using (var db = new Database.UserContext(Config))
            {
                var bUser = await db.GetUserOrCreateAsync(user.Id);

                bUser.Level  = level;
                bUser.ExpCnt = Services.ExperienceManager.CalculateExpForLevel(level);

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{Context.User.Id}", "users" });

                await ReplyAsync("", embed : $"{user.Mention} ustawiono {level} poziom.".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #23
0
        public async Task ToggleWaifuViewInProfileAsync()
        {
            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(Context.User.Id);

                botuser.ShowWaifuInProfile = !botuser.ShowWaifuInProfile;

                string result = botuser.ShowWaifuInProfile ? "załączony" : "wyłączony";

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });

                await ReplyAsync("", embed : $"Podgląd waifu w profilu {Context.User.Mention} został {result}.".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #24
0
        public async Task RemoveQuestionAsync(ulong id)
        {
            using (var db = new Database.UserContext(_config))
            {
                var question = await db.Questions.Include(x => x.Answer).FirstOrDefaultAsync(x => x.Id == id);

                if (question != null)
                {
                    db.Questions.Remove(question);
                    await db.SaveChangesAsync();

                    QueryCacheManager.ExpireTag(new string[] { $"quiz" });

                    await "Question removed!".ToResponse(200).ExecuteResultAsync(ControllerContext);
                    return;
                }
            }
            await "Question not found!".ToResponse(404).ExecuteResultAsync(ControllerContext);
        }
Пример #25
0
        public async Task <bool> OnAccept(SessionContext context)
        {
            var players = new List <PlayerInfo> {
                P1, P2
            };

            var    fight    = _waifu.MakeFightAsync(players);
            string deathLog = _waifu.GetDeathLog(fight, players);

            bool   isWinner  = fight.Winner != null;
            string winString = isWinner ? $"Zwycięża {fight.Winner.User.Mention}!": "Remis!";

            if (await Message.Channel.GetMessageAsync(Message.Id) is IUserMessage msg)
            {
                await msg.ModifyAsync(x => x.Embed = $"{DuelName}{deathLog.TrimToLength(1400)}{winString}".ToEmbedMessage(EMType.Error).Build());
            }

            using (var db = new Database.UserContext(_config))
            {
                var user1 = await db.GetUserOrCreateAsync(P1.User.Id);

                var user2 = await db.GetUserOrCreateAsync(P2.User.Id);

                user1.GameDeck.PvPStats.Add(new CardPvPStats
                {
                    Type   = FightType.Versus,
                    Result = isWinner ? (fight.Winner.User.Id == user1.Id ? FightResult.Win : FightResult.Lose) : FightResult.Draw
                });

                user2.GameDeck.PvPStats.Add(new CardPvPStats
                {
                    Type   = FightType.Versus,
                    Result = isWinner ? (fight.Winner.User.Id == user2.Id ? FightResult.Win : FightResult.Lose) : FightResult.Draw
                });

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{user1.Id}", $"user-{user2.Id}", "users" });
            }

            Dispose();
            return(true);
        }
Пример #26
0
        public async Task GenerateCardAsync([Summary("użytkownik")] SocketGuildUser user, [Summary("id postaci na shinden(nie podanie - losowo)")] ulong id = 0,
                                            [Summary("jakość karty(nie podanie - losowo)")] Rarity rarity = Rarity.E)
        {
            var character = (id == 0) ? await _waifu.GetRandomCharacterAsync() : (await _shClient.GetCharacterInfoAsync(id)).Body;

            var card = (rarity == Rarity.E) ? _waifu.GenerateNewCard(character) : _waifu.GenerateNewCard(character, rarity);

            card.Source = CardSource.GodIntervention;
            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(user.Id);

                botuser.GameDeck.Cards.Add(card);

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });

                await ReplyAsync("", embed : $"{user.Mention} otrzymał {card.GetString(false, false, true)}.".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #27
0
        public async Task ChangeStyleAsync([Summary("typ stylu ( 0 - statystyki, 1 - obrazek, 2 - brzydkie)")] ProfileType type, [Summary("bezpośredni adres do obrazka gdy wybrany styl 1 lub 2(325 x 272)")] string imgUrl = null)
        {
            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(Context.User.Id);

                if (botuser.ScCnt < 3000)
                {
                    await ReplyAsync("", embed : $"{Context.User.Mention} nie posiadasz wystarczającej liczby SC!".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                switch (type)
                {
                case ProfileType.Img:
                case ProfileType.StatsWithImg:
                    if (await _profile.SaveProfileImageAsync(imgUrl, $"./GOut/Saved/SR{botuser.Id}.png", 325, 272))
                    {
                        botuser.StatsReplacementProfileUri = $"./GOut/Saved/SR{botuser.Id}.png";
                        break;
                    }
                    await ReplyAsync("", embed : "Nie wykryto obrazka! Upewnij się, że podałeś poprawny adres!".ToEmbedMessage(EMType.Error).Build());

                    return;

                default:
                    break;
                }

                botuser.ScCnt      -= 3000;
                botuser.ProfileType = type;

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });

                await ReplyAsync("", embed : $"Zmieniono styl profilu użytkownika: {Context.User.Mention}!".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #28
0
        private async Task <bool> HandleUserReactionInAccept(SocketReaction reaction, PlayerInfo player, IUserMessage msg)
        {
            bool end = false;

            if (reaction.UserId == player.User.Id)
            {
                if (reaction.Emote.Equals(AcceptEmote))
                {
                    if (State != ExchangeStatus.AcceptP2)
                    {
                        RestartTimer();
                        State = ExchangeStatus.AcceptP2;
                        Tips  = $"{P2.User.Mention} daj {AcceptEmote} aby zaakceptować, lub {DeclineEmote} aby odrzucić.";
                    }
                    else
                    {
                        Tips = $"Wymiana zakończona!";
                        end  = true;

                        using (var db = new Database.UserContext(_config))
                        {
                            var user1 = await db.GetUserOrCreateAsync(P1.User.Id);

                            var user2 = await db.GetUserOrCreateAsync(P2.User.Id);

                            foreach (var c in P1.Cards)
                            {
                                var card = user1.GameDeck.Cards.FirstOrDefault(x => x.Id == c.Id);
                                if (card != null)
                                {
                                    card.Tags   = null;
                                    card.Active = false;
                                    user1.GameDeck.Cards.Remove(card);
                                    user2.GameDeck.Cards.Add(card);
                                }
                            }

                            foreach (var c in P2.Cards)
                            {
                                var card = user2.GameDeck.Cards.FirstOrDefault(x => x.Id == c.Id);
                                if (card != null)
                                {
                                    card.Tags   = null;
                                    card.Active = false;
                                    user2.GameDeck.Cards.Remove(card);
                                    user1.GameDeck.Cards.Add(card);
                                }
                            }

                            await db.SaveChangesAsync();

                            QueryCacheManager.ExpireTag(new string[] { $"user-{P1.User.Id}", $"user-{P2.User.Id}", "users" });
                        }
                    }
                }
                else if (reaction.Emote.Equals(DeclineEmote))
                {
                    RestartTimer();
                    Tips = $"{player.User.Mention} odrzucił propozycje wymiany!";
                    end  = true;
                }

                if (msg != null)
                {
                    await msg.ModifyAsync(x => x.Embed = BuildEmbed());
                }
            }
            return(end);
        }
Пример #29
0
        public async Task ToggleColorRoleAsync([Summary("kolor z listy(brak - lista)")] FColor color = FColor.None, [Summary("waluta(SC/TC)")] SCurrency currency = SCurrency.Tc)
        {
            var user = Context.User as SocketGuildUser;

            if (user == null)
            {
                return;
            }

            if (color == FColor.None)
            {
                using (var img = _profile.GetColorList(currency))
                {
                    await Context.Channel.SendFileAsync(img, "list.png");

                    return;
                }
            }

            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(user.Id);

                var points = currency == SCurrency.Tc ? botuser.TcCnt : botuser.ScCnt;
                if (points < color.Price(currency))
                {
                    await ReplyAsync("", embed : $"{user.Mention} nie posiadasz wystarczającej liczby {currency.ToString().ToUpper()}!".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                var colort = botuser.TimeStatuses.FirstOrDefault(x => x.Type == Database.Models.StatusType.Color && x.Guild == Context.Guild.Id);
                if (colort == null)
                {
                    colort = new Database.Models.TimeStatus
                    {
                        Type   = Database.Models.StatusType.Color,
                        Guild  = Context.Guild.Id,
                        EndsAt = DateTime.Now,
                    };
                    botuser.TimeStatuses.Add(colort);
                }

                await _profile.RomoveUserColorAsync(user);

                if (color == FColor.CleanColor)
                {
                    colort.EndsAt = DateTime.Now;
                }
                else
                {
                    using (var cdb = new Database.GuildConfigContext(Config))
                    {
                        var gConfig = await cdb.GetCachedGuildFullConfigAsync(Context.Guild.Id);

                        if (!await _profile.SetUserColorAsync(user, gConfig.AdminRole, color))
                        {
                            await ReplyAsync("", embed : $"Coś poszło nie tak!".ToEmbedMessage(EMType.Error).Build());

                            return;
                        }

                        colort.EndsAt = colort.EndsAt.AddMonths(1);

                        if (currency == SCurrency.Tc)
                        {
                            botuser.TcCnt -= color.Price(currency);
                        }
                        else
                        {
                            botuser.ScCnt -= color.Price(currency);
                        }
                    }
                }

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });

                await ReplyAsync("", embed : $"{user.Mention} wykupił kolor!".ToEmbedMessage(EMType.Success).Build());
            }
        }
Пример #30
0
        private async Task <bool> HandleReactionAsync(SessionContext context)
        {
            bool end = false;

            if (context.Message.Id != Message.Id)
            {
                return(false);
            }

            if (await Message.Channel.GetMessageAsync(Message.Id) is IUserMessage msg)
            {
                var reaction = context.ReactionAdded ?? context.ReactionRemoved;
                if (reaction == null)
                {
                    return(false);
                }

                if (reaction.Emote.Equals(DeclineEmote))
                {
                    await msg.ModifyAsync(x => x.Embed = $"{Name}\n\nOdrzucono tworzenie karty.".ToEmbedMessage(EMType.Bot).Build());

                    QueryCacheManager.ExpireTag(new string[] { $"user-{P1.User.Id}", "users" });

                    return(true);
                }

                if (reaction.Emote.Equals(AcceptEmote))
                {
                    bool error = true;

                    if (P1.Accepted)
                    {
                        error = false;
                        using (var db = new Database.UserContext(_config))
                        {
                            var user = await db.GetUserOrCreateAsync(P1.User.Id);

                            var newCard = _waifu.GenerateNewCard(P1.User, await _waifu.GetRandomCharacterAsync(), GetRarityFromValue(GetValue()));

                            newCard.Source    = CardSource.Crafting;
                            newCard.Affection = user.GameDeck.AffectionFromKarma();

                            foreach (var item in P1.Items)
                            {
                                var thisItem = user.GameDeck.Items.FirstOrDefault(x => x.Type == item.Type);
                                if (thisItem == null)
                                {
                                    error = true;
                                    break;
                                }

                                if (thisItem.Count < item.Count)
                                {
                                    error = true;
                                    break;
                                }
                                thisItem.Count -= item.Count;
                                if (thisItem.Count < 1)
                                {
                                    user.GameDeck.Items.Remove(thisItem);
                                }
                            }

                            user.GameDeck.Cards.Add(newCard);

                            await db.SaveChangesAsync();

                            await msg.ModifyAsync(x => x.Embed = $"{Name}\n\n**Utworzono:** {newCard.GetString(false, false, true)}".ToEmbedMessage(EMType.Success).Build());
                        }
                    }

                    if (error)
                    {
                        await msg.ModifyAsync(x => x.Embed = $"{Name}\n\nBrakuje przedmiotów, tworzenie karty nie powiodło się.".ToEmbedMessage(EMType.Bot).Build());
                    }

                    QueryCacheManager.ExpireTag(new string[] { $"user-{P1.User.Id}", "users" });

                    return(true);
                }

                try
                {
                    await msg.RemoveReactionAsync(reaction.Emote, context.User);
                }
                catch (Exception) { }
            }

            return(end);
        }