public async Task CreateKeys(ulong amount) { using var db = new SkuldDbContextFactory().CreateDbContext(); StringBuilder message = new StringBuilder($"Keycodes:"); message.AppendLine(); for (ulong x = 0; x < amount; x++) { var key = new DonatorKey { KeyCode = Guid.NewGuid() }; db.DonatorKeys.Add(key); message.AppendLine($"Keycode: {key.KeyCode}"); } DogStatsd.Increment("donatorkeys.generated", (int)amount); await db.SaveChangesAsync().ConfigureAwait(false); await message.QueueMessageAsync( Context, type : Services.Messaging.Models.MessageType.DMS ).ConfigureAwait(false); }
public async Task SellKeyAsync(IContext e) { var unit = e.GetService <IUnitOfWork>(); var transactionService = e.GetService <ITransactionService>(); var keyRepository = unit.GetRepository <DonatorKey>(); if (e.GetArgumentPack().Take(out Guid guid)) { DonatorKey key = await DonatorKey.GetKeyAsync(keyRepository, guid); await keyRepository.DeleteAsync(key); await unit.CommitAsync(); await transactionService.CreateTransactionAsync( new TransactionRequest.Builder() .WithAmount(KeyBuybackPrice) .WithReceiver((long)e.GetAuthor().Id) .WithSender(AppProps.Currency.BankId) .Build()); await e.SuccessEmbed( e.GetLocale().GetString("key_sold_success", KeyBuybackPrice)) .QueueAsync(e, e.GetChannel()); } }
public async Task CreateKeyAsync(CommandContext e) { var context = e.GetService <MikiDbContext>(); DonatorKey key = (await context.DonatorKey.AddAsync(new DonatorKey() { StatusTime = new TimeSpan(int.Parse(e.Arguments.Pack.TakeAll()), 0, 0, 0, 0) })).Entity; await context.SaveChangesAsync(); e.Channel.QueueMessage($"key generated for {e.Arguments.Pack.TakeAll()} days `{key.Key}`"); }
public async Task CreateKeyAsync(IContext e) { var context = e.GetService <MikiDbContext>(); DonatorKey key = (await context.DonatorKey.AddAsync(new DonatorKey() { StatusTime = new TimeSpan(int.Parse(e.GetArgumentPack().Pack.TakeAll()), 0, 0, 0, 0) })).Entity; await context.SaveChangesAsync(); e.GetChannel().QueueMessage( e, null, $"Key generated for {key.StatusTime.TotalDays} days `{key.Key}`"); }
public async Task CreateKeyAsync(EventContext e) { using (var context = new MikiContext()) { DonatorKey key = (await context.DonatorKey.AddAsync(new DonatorKey() { StatusTime = new TimeSpan(int.Parse(e.Arguments.ToString()), 0, 0, 0, 0) })).Entity; await context.SaveChangesAsync(); e.Channel.QueueMessageAsync($"key generated for {e.Arguments.ToString()} days `{key.Key}`"); } }
public async Task RedeemKeyAsync(EventContext e) { using (var context = new MikiContext()) { long id = (long)e.Author.Id; DonatorKey key = await context.DonatorKey.FindAsync(Guid.Parse(e.arguments)); IsDonator donatorStatus = await context.IsDonator.FindAsync(id); if (key != null) { if (donatorStatus == null) { donatorStatus = (await context.IsDonator.AddAsync(new IsDonator() { UserId = id })).Entity; } if (donatorStatus.ValidUntil > DateTime.Now) { donatorStatus.ValidUntil += key.StatusTime; } else { donatorStatus.ValidUntil = DateTime.Now + key.StatusTime; } Utils.Embed.SetTitle($"🎉 Congratulations, {e.Author.Username}") .SetColor(226, 46, 68) .SetDescription($"You have successfully redeemed a donator key, I've given you **{key.StatusTime.TotalDays}** days of donator status.") .AddInlineField("When does my status expire?", donatorStatus.ValidUntil.ToLongDateString()) .SetThumbnailUrl("https://i.imgur.com/OwwA5fV.png") .QueueToChannel(e.Channel); context.DonatorKey.Remove(key); await context.SaveChangesAsync(); } else { await e.Channel.SendMessageAsync("invalid key"); } } }
public async Task SellKeyAsync(CommandContext e) { var context = e.GetService <MikiDbContext>(); long id = (long)e.Author.Id; if (e.Arguments.Take(out Guid guid)) { DonatorKey key = await DonatorKey.GetKeyAsync(context, guid); User u = await User.GetAsync(context, id, e.Author.Username); await u.AddCurrencyAsync(30000, e.Channel); context.DonatorKey.Remove(key); await context.SaveChangesAsync(); await Utils.SuccessEmbed(e, e.Locale.GetString("key_sold_success", 30000)) .QueueToChannelAsync(e.Channel); } }
public async Task RedeemKeyAsync(IContext e) { if (e.HasFeatureEnabled("redeemkey_using_payment_service")) { await RedeemKeyV2Async(e); return; } var unit = e.GetService <IUnitOfWork>(); var donatorRepository = unit.GetRepository <IsDonator>(); var keyRepository = unit.GetRepository <DonatorKey>(); var locale = e.GetLocale(); long id = (long)e.GetAuthor().Id; if (!e.GetArgumentPack().Take(out Guid guid)) { throw new InvalidKeyFormatException(); } DonatorKey key = await DonatorKey.GetKeyAsync(keyRepository, guid); IsDonator donatorStatus = await donatorRepository.GetAsync(id); if (donatorStatus == null) { donatorStatus = new IsDonator { UserId = id, KeysRedeemed = 1, ValidUntil = DateTime.UtcNow + key.StatusTime }; await donatorRepository.AddAsync(donatorStatus); } else { donatorStatus.KeysRedeemed++; if (donatorStatus.ValidUntil > DateTime.Now) { donatorStatus.ValidUntil += key.StatusTime; } else { donatorStatus.ValidUntil = DateTime.Now + key.StatusTime; } await donatorRepository.EditAsync(donatorStatus); } await keyRepository.DeleteAsync(key); await unit.CommitAsync(); await new EmbedBuilder { Title = $"🎉 {locale.GetString("common_success", e.GetAuthor().Username)}", Color = new Color(226, 46, 68), Description = locale.GetString("key_redeem_success", $"**{key.StatusTime.TotalDays}**"), ThumbnailUrl = "https://i.imgur.com/OwwA5fV.png" }.AddInlineField("When does my status expire?", donatorStatus.ValidUntil.ToLongDateString()) .ToEmbed().QueueAsync(e, e.GetChannel()); var achievementManager = e.GetService <AchievementService>(); var donatorAchievement = achievementManager.GetAchievement(AchievementIds.DonatorId); if (donatorStatus.KeysRedeemed >= 1 && donatorStatus.KeysRedeemed < 5) { await achievementManager.UnlockAsync(donatorAchievement, e.GetAuthor().Id); } else if (donatorStatus.KeysRedeemed >= 5 && donatorStatus.KeysRedeemed < 25) { await achievementManager.UnlockAsync(donatorAchievement, e.GetAuthor().Id, 1) .ConfigureAwait(false); } else if (donatorStatus.KeysRedeemed >= 25) { await achievementManager.UnlockAsync(donatorAchievement, e.GetAuthor().Id, 2); } }
public async Task RedeemKeyAsync(EventContext e) { using (var context = new MikiContext()) { long id = (long)e.Author.Id; if (e.Arguments.Take(out Guid guid)) { DonatorKey key = await DonatorKey.GetKeyAsync(context, guid); IsDonator donatorStatus = await context.IsDonator.FindAsync(id); if (donatorStatus == null) { donatorStatus = (await context.IsDonator.AddAsync(new IsDonator() { UserId = id })).Entity; } donatorStatus.KeysRedeemed++; if (donatorStatus.ValidUntil > DateTime.Now) { donatorStatus.ValidUntil += key.StatusTime; } else { donatorStatus.ValidUntil = DateTime.Now + key.StatusTime; } await new EmbedBuilder() { Title = ($"🎉 Congratulations, {e.Author.Username}"), Color = new Color(226, 46, 68), Description = ($"You have successfully redeemed a donator key, I've given you **{key.StatusTime.TotalDays}** days of donator status."), ThumbnailUrl = ("https://i.imgur.com/OwwA5fV.png") }.AddInlineField("When does my status expire?", donatorStatus.ValidUntil.ToLongDateString()) .ToEmbed().QueueToChannelAsync(e.Channel); context.DonatorKey.Remove(key); await context.SaveChangesAsync(); // cheap hack. var achievementManager = AchievementManager.Instance; var achievements = achievementManager.GetContainerById("donator").Achievements; if (donatorStatus.KeysRedeemed == 1) { await achievementManager.UnlockAsync(achievements[0], e.Channel, e.Author, 0); } else if (donatorStatus.KeysRedeemed == 5) { await achievementManager.UnlockAsync(achievements[1], e.Channel, e.Author, 1); } else if (donatorStatus.KeysRedeemed == 25) { await achievementManager.UnlockAsync(achievements[2], e.Channel, e.Author, 2); } } } }
public DonatorModule() { WebhookManager.OnEvent += async(value) => { if (value.auth_code == "DBL_VOTE") { using (var context = new MikiContext()) { DblVoteObject voteObject = value.data.ToObject <DblVoteObject>(); if (voteObject.Type == "upvote") { IUser user = Bot.Instance.Client.GetUser(voteObject.UserId); if (user == null) { throw new RabbitException(); } User u = await User.GetAsync(context, user); if (!await Global.RedisClient.ExistsAsync($"dbl:vote:{voteObject.UserId}")) { u.DblVotes++; await Global.RedisClient.AddAsync($"dbl:vote:{voteObject.UserId}", 1, new TimeSpan(1, 0, 0, 0)); int addedCurrency = 100 * ((await u.IsDonatorAsync(context)) ? 2 : 1); u.Currency += addedCurrency; await context.SaveChangesAsync(); DogStatsd.Increment("votes.dbl"); new EmbedBuilder() { Title = "Thanks for voting!", Description = ($"We've given you {addedCurrency} mekos to your profile"), Color = new Color(64, 255, 64) }.Build().QueueToUser(user); } var achievements = AchievementManager.Instance.GetContainerById("voter"); switch (u.DblVotes) { case 1: { await achievements.Achievements[0].UnlockAsync(user); } break; case 25: { await achievements.Achievements[1].UnlockAsync(user, 1); } break; case 200: { await achievements.Achievements[2].UnlockAsync(user, 2); } break; } } } } if (value.auth_code == "KOFI_DONATE") { KofiObject kofi = value.data.ToObject <KofiObject>(); if (ulong.TryParse(kofi.Message.Split(' ').Last(), out ulong uid)) { IUser user = Bot.Instance.Client.GetUser(uid); List <string> allKeys = new List <string>(); for (int i = 0; i < kofi.Amount / 3; i++) { allKeys.Add(DonatorKey.GenerateNew().Key.ToString()); } new EmbedBuilder() { Title = "You donated through ko-fi!", Description = "I work hard for miki's quality, thank you for helping me keep the bot running!" }.AddField("- Veld#0001", "Here are your key(s)!\n\n`" + string.Join("\n", allKeys) + "`") .AddField("How to redeem this key?", $"use this command `>redeemkey`") .Build().QueueToUser(user); } } if (value.auth_code == "PATREON_PLEDGES") { List <PatreonPledgeObject> pledgeObjects = value.data.ToObject <List <PatreonPledgeObject> >(); foreach (PatreonPledgeObject pledge in pledgeObjects) { IUser user = Bot.Instance.Client.GetUser(pledge.UserId); EmbedBuilder embed = new EmbedBuilder() { Title = "You donation came through patreon!", Description = "I work hard for miki's quality, thank you for helping me keep the bot running! - Veld#0001" }; int max_per_embed = 20; for (int i = 0; i < Math.Ceiling((double)pledge.KeysRewarded / max_per_embed); i++) { List <string> allKeys = new List <string>(); for (int j = i * max_per_embed; j < Math.Min(i * max_per_embed + max_per_embed, pledge.KeysRewarded); j++) { allKeys.Add(DonatorKey.GenerateNew().Key.ToString()); } embed.AddInlineField("Here are your key(s)!", $"`{string.Join("\n", allKeys)}`"); } embed.AddField("How to redeem this key?", $"use this command `>redeemkey`", false) .Build().QueueToUser(user); } } if (value.auth_code == "PATREON_DELETE") { PatreonPledge p = value.data.ToObject <PatreonPledge>(); if (ulong.TryParse(p.Included[0].attributes.ToObject <UserAttribute>().DiscordUserId, out ulong s)) { new EmbedBuilder() { Title = "Sad to see you leave!", Description = "However, I won't hold it against you, thank you for your timely support and I hope you'll happily continue using Miki" }.Build().QueueToUser(Bot.Instance.Client.GetUser(s)); } else { throw new RabbitException(); } } if (value.auth_code == "PATREON_CREATE") { PatreonPledge p = value.data.ToObject <PatreonPledge>(); if (ulong.TryParse(p.Included[0].attributes.ToObject <UserAttribute>().DiscordUserId, out ulong s)) { new EmbedBuilder() { Title = "Welcome to the family", Description = ("In maximal 24 hours you will receive another DM with key(s) depending on your patron amount. (5$/key). Thank you for your support!") }.Build().QueueToUser(Bot.Instance.Client.GetUser(s)); } else { throw new RabbitException(); } } }; }