public async Task ShowSubsAsync() { using (var db = new Database.UserContext(Config)) { var botuser = await db.GetCachedFullUserAsync(Context.User.Id); var rsubs = botuser.TimeStatuses.Where(x => x.Type.IsSubType()); string subs = "brak"; if (rsubs.Count() > 0) { subs = ""; foreach (var sub in rsubs) { subs += $"{sub.ToView()}\n"; } } await ReplyAsync("", embed : $"**Subskrypcje** {Context.User.Mention}:\n\n{subs.TrimToLength(1950)}".ToEmbedMessage(EMType.Info).Build()); } }
public async Task ShowSiteStatisticAsync([Summary("użytkownik(opcjonalne)")] SocketGuildUser user = null) { var usr = user ?? Context.User as SocketGuildUser; if (usr == null) { return; } using (var db = new Database.UserContext(Config)) { var botUser = await db.GetCachedFullUserAsync(usr.Id); if (botUser == null) { await ReplyAsync("", embed : "Ta osoba nie ma profilu bota.".ToEmbedMessage(EMType.Error).Build()); return; } if (botUser?.Shinden == 0) { await ReplyAsync("", embed : "Ta osoba nie połączyła konta bota z kontem na stronie.".ToEmbedMessage(EMType.Error).Build()); return; } using (var stream = await _shinden.GetSiteStatisticAsync(botUser.Shinden, usr)) { if (stream == null) { await ReplyAsync("", embed : $"Brak połączenia z Shindenem!".ToEmbedMessage(EMType.Error).Build()); return; } await Context.Channel.SendFileAsync(stream, $"{usr.Id}.png", $"{Shden.API.Url.GetProfileURL(botUser.Shinden)}"); } } }
public async Task ShowWalletAsync([Summary("użytkownik(opcjonalne)")] SocketUser user = null) { var usr = user ?? Context.User; if (usr == null) { return; } using (var db = new Database.UserContext(Config)) { var botuser = await db.GetCachedFullUserAsync(usr.Id); if (botuser == null) { await ReplyAsync("", embed : "Ta osoba nie ma profilu bota.".ToEmbedMessage(EMType.Error).Build()); return; } await ReplyAsync("", embed : $"**Portfel** {usr.Mention}:\n\n {botuser?.ScCnt} **SC**\n{botuser?.TcCnt} **TC**".ToEmbedMessage(EMType.Info).Build()); } }
public async Task ShowStatsAsync([Summary("użytkownik(opcjonalne)")] SocketUser user = null) { var usr = user ?? Context.User; if (usr == null) { return; } using (var db = new Database.UserContext(Config)) { var botuser = await db.GetCachedFullUserAsync(usr.Id); if (botuser == null) { await ReplyAsync("", embed : "Ta osoba nie ma profilu bota.".ToEmbedMessage(EMType.Error).Build()); return; } await ReplyAsync("", embed : botuser.GetStatsView(usr).Build()); } }
public async Task TransferCardAsync([Summary("id użytkownika")] ulong id, [Summary("liczba kart")] uint count, [Summary("czas w minutach")] uint duration = 5) { var emote = new Emoji("🎰"); var time = DateTime.Now.AddMinutes(duration); var mention = ""; using (var db = new Database.GuildConfigContext(_config)) { var config = await db.GetCachedGuildFullConfigAsync(Context.Guild.Id); if (config != null) { var wRole = Context.Guild.GetRole(config.WaifuRole); if (wRole != null) { mention = wRole.Mention; } } } var msg = await ReplyAsync(mention, embed : $"Loteria kart. Zareaguj {emote} aby wziąć udział.\n\nKoniec `{time.ToShortTimeString()}:{time.Second.ToString("00")}`".ToEmbedMessage(EMType.Bot).Build()); await msg.AddReactionAsync(emote); await Task.Delay(TimeSpan.FromMinutes(duration)); await msg.RemoveReactionAsync(emote, Context.Client.CurrentUser); var reactions = await msg.GetReactionUsersAsync(emote, 300).FlattenAsync(); var users = reactions.ToList(); IUser winner = null; using (var db = new Database.UserContext(_config)) { var watch = Stopwatch.StartNew(); while (winner == null) { if (watch.ElapsedMilliseconds > 60000) { throw new Exception("Timeout"); } if (users.Count < 1) { await msg.ModifyAsync(x => x.Embed = "Na loterie nie stawił się żaden użytkownik!".ToEmbedMessage(EMType.Error).Build()); return; } var selected = Services.Fun.GetOneRandomFrom(users); var dUser = await db.GetCachedFullUserAsync(selected.Id); if (dUser != null) { if (!dUser.IsBlacklisted) { winner = selected; } } else { users.Remove(selected); } } } var exe = new Executable("lotery", new Task(async() => { using (var db = new Database.UserContext(Config)) { var user = await db.GetUserOrCreateAsync(id); if (user == null) { await msg.ModifyAsync(x => x.Embed = "Nie odnaleziono kart do rozdania!".ToEmbedMessage(EMType.Error).Build()); return; } var loteryCards = user.GameDeck.Cards.ToList(); if (loteryCards.Count < 1) { await msg.ModifyAsync(x => x.Embed = "Nie odnaleziono kart do rozdania!".ToEmbedMessage(EMType.Error).Build()); return; } var winnerUser = await db.GetUserOrCreateAsync(winner.Id); if (winnerUser == null) { await msg.ModifyAsync(x => x.Embed = "Nie odnaleziono docelowego użytkownika!".ToEmbedMessage(EMType.Error).Build()); return; } int counter = 0; var cardsIds = new List <string>(); foreach (var thisCard in loteryCards) { cardsIds.Add(thisCard.GetString(false, false, true)); thisCard.Active = false; thisCard.InCage = false; thisCard.TagList.Clear(); user.GameDeck.Cards.Remove(thisCard); winnerUser.GameDeck.Cards.Add(thisCard); winnerUser.GameDeck.RemoveCharacterFromWishList(thisCard.Character); winnerUser.GameDeck.RemoveCardFromWishList(thisCard.Id); if (++counter == count) { break; } } await db.SaveChangesAsync(); QueryCacheManager.ExpireTag(new string[] { $"user-{Context.User.Id}", "users", $"user-{id}" }); await msg.ModifyAsync(x => x.Embed = $"Loterie wygrywa {winner.Mention}.\nOtrzymuje: {string.Join("\n", cardsIds)}".TrimToLength(2000).ToEmbedMessage(EMType.Success).Build()); } })); await _executor.TryAdd(exe, TimeSpan.FromSeconds(1)); await msg.RemoveAllReactionsAsync(); }
public async Task <List <Card> > OpenAPackAsync(int packNumber) { var currUser = ControllerContext.HttpContext.User; if (currUser.HasClaim(x => x.Type == "DiscordId")) { if (ulong.TryParse(currUser.Claims.First(x => x.Type == "DiscordId").Value, out var discordId)) { var cards = new List <Card>(); using (var db = new Database.UserContext(_config)) { var botUserCh = await db.GetCachedFullUserAsync(discordId); if (botUserCh == null) { await "User not found!".ToResponse(404).ExecuteResultAsync(ControllerContext); return(null); } if (botUserCh.GameDeck.BoosterPacks.Count < packNumber || packNumber <= 0) { await "Boosterpack not found!".ToResponse(404).ExecuteResultAsync(ControllerContext); return(null); } var pack = botUserCh.GameDeck.BoosterPacks.ToArray()[packNumber - 1]; cards = await _waifu.OpenBoosterPackAsync(null, pack); } var exe = new Executable($"api-packet-open u{discordId}", new Task(async() => { using (var db = new Database.UserContext(_config)) { var botUser = await db.GetUserOrCreateAsync(discordId); var bPack = botUser.GameDeck.BoosterPacks.ToArray()[packNumber - 1]; botUser.GameDeck.BoosterPacks.Remove(bPack); if (bPack.CardSourceFromPack == CardSource.Activity || bPack.CardSourceFromPack == CardSource.Migration) { botUser.Stats.OpenedBoosterPacksActivity += 1; } else { botUser.Stats.OpenedBoosterPacks += 1; } foreach (var card in cards) { card.Affection += botUser.GameDeck.AffectionFromKarma(); card.FirstIdOwner = botUser.Id; botUser.GameDeck.Cards.Add(card); botUser.GameDeck.RemoveCharacterFromWishList(card.Character); } await db.SaveChangesAsync(); QueryCacheManager.ExpireTag(new string[] { $"user-{botUser.Id}", "users" }); } })); await _executor.TryAdd(exe, TimeSpan.FromSeconds(1)); exe.Wait(); await Task.Delay(2000); return(cards); } } await "The appropriate claim was not found".ToResponse(403).ExecuteResultAsync(ControllerContext); return(null); }