public async Task GiveReputationAsync(EventContext e) { using (var context = new MikiContext()) { User giver = await context.Users.FindAsync(e.Author.Id.ToDbLong()); var repObject = await Global.RedisClient.GetAsync <ReputationObject>($"user:{giver.Id}:rep"); if (repObject == null) { repObject = new ReputationObject() { LastReputationGiven = DateTime.Now, ReputationPointsLeft = 3 }; await Global.RedisClient.UpsertAsync( $"user:{giver.Id}:rep", repObject, DateTime.UtcNow.AddDays(1).Date - DateTime.UtcNow ); } ArgObject arg = e.Arguments.FirstOrDefault(); if (arg == null) { TimeSpan pointReset = (DateTime.Now.AddDays(1).Date - DateTime.Now); new EmbedBuilder() { Title = (e.Locale.GetString("miki_module_accounts_rep_header")), Description = (e.Locale.GetString("miki_module_accounts_rep_description")) }.AddInlineField(e.Locale.GetString("miki_module_accounts_rep_total_received"), giver.Reputation.ToString()) .AddInlineField(e.Locale.GetString("miki_module_accounts_rep_reset"), pointReset.ToTimeString(e.Locale).ToString()) .AddInlineField(e.Locale.GetString("miki_module_accounts_rep_remaining"), repObject.ReputationPointsLeft.ToString()) .ToEmbed().QueueToChannel(e.Channel); return; } else { Dictionary <IDiscordUser, short> usersMentioned = new Dictionary <IDiscordUser, short>(); EmbedBuilder embed = new EmbedBuilder(); int totalAmountGiven = 0; bool mentionedSelf = false; while (true || totalAmountGiven <= repObject.ReputationPointsLeft) { if (arg == null) { break; } IDiscordUser u = await arg.GetUserAsync(e.Guild); short amount = 1; if (u == null) { break; } arg = arg?.Next(); if ((arg?.AsInt() ?? -1) != -1) { amount = (short)arg.AsInt().Value; arg = arg.Next(); } else if (Utils.IsAll(arg)) { amount = repObject.ReputationPointsLeft; arg = arg.Next(); } if (u.Id == e.Author.Id) { mentionedSelf = true; continue; } totalAmountGiven += amount; if (usersMentioned.Keys.Where(x => x.Id == u.Id).Count() > 0) { usersMentioned[usersMentioned.Keys.Where(x => x.Id == u.Id).First()] += amount; } else { usersMentioned.Add(u, amount); } } if (mentionedSelf) { embed.Footer = new EmbedFooter() { Text = e.Locale.GetString("warning_mention_self"), }; } if (usersMentioned.Count == 0) { return; } else { if (totalAmountGiven <= 0) { e.ErrorEmbedResource("miki_module_accounts_rep_error_zero") .ToEmbed().QueueToChannel(e.Channel); return; } if (usersMentioned.Sum(x => x.Value) > repObject.ReputationPointsLeft) { e.ErrorEmbedResource("error_rep_limit", usersMentioned.Count, usersMentioned.Sum(x => x.Value), repObject.ReputationPointsLeft) .ToEmbed().QueueToChannel(e.Channel); return; } } embed.Title = (e.Locale.GetString("miki_module_accounts_rep_header")); embed.Description = (e.Locale.GetString("rep_success")); foreach (var user in usersMentioned) { User receiver = await User.GetAsync(context, user.Key); receiver.Reputation += user.Value; embed.AddInlineField( receiver.Name, string.Format("{0} => {1} (+{2})", receiver.Reputation - user.Value, receiver.Reputation, user.Value) ); } repObject.ReputationPointsLeft -= (short)usersMentioned.Sum(x => x.Value); await Global.RedisClient.UpsertAsync( $"user:{giver.Id}:rep", repObject, DateTime.UtcNow.AddDays(1).Date - DateTime.UtcNow ); embed.AddInlineField(e.Locale.GetString("miki_module_accounts_rep_points_left"), repObject.ReputationPointsLeft.ToString()) .ToEmbed().QueueToChannel(e.Channel); await context.SaveChangesAsync(); } } }
public async Task StartSlots(EventContext e, int bet) { using (var context = new MikiContext()) { User u = await context.Users.FindAsync(e.Author.Id.ToDbLong()); Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong()); int moneyReturned = 0; if (bet <= 0) { return; } string[] objects = { "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "β", "β", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", }; IDiscordEmbed embed = Utils.Embed .SetAuthor(locale.GetString(Locale.SlotsHeader) + " | " + e.Author.Username, e.Author.AvatarUrl, "https://patreon.com/mikibot"); string[] objectsChosen = { objects[MikiRandom.Next(objects.Length)], objects[MikiRandom.Next(objects.Length)], objects[MikiRandom.Next(objects.Length)] }; Dictionary <string, int> score = new Dictionary <string, int>(); foreach (string o in objectsChosen) { if (score.ContainsKey(o)) { score[o]++; continue; } score.Add(o, 1); } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 0.5f); } else if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 1f); } } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 0.8f); } else if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 1.5f); } } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 1f); } else if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 2f); } } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 1f); } if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 4f); } } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 1.2f); } if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 6f); } } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 1.5f); } if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 10f); } } if (score.ContainsKey("β")) { if (score["β"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 2f); } if (score["β"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 12f); } } if (moneyReturned == 0) { moneyReturned = -bet; embed.AddField(locale.GetString("miki_module_fun_slots_lose_header"), locale.GetString("miki_module_fun_slots_lose_amount", bet, u.Currency - bet)); } else { embed.AddField(locale.GetString(Locale.SlotsWinHeader), locale.GetString(Locale.SlotsWinMessage, moneyReturned, u.Currency + moneyReturned)); } embed.Description = string.Join(" ", objectsChosen); await u.AddCurrencyAsync(moneyReturned, e.Channel); await context.SaveChangesAsync(); await embed.SendToChannel(e.Channel); } }
public async Task BuyProfileBackgroundAsync(EventContext e) { ArgObject arguments = e.Arguments.FirstOrDefault(); if (arguments.TryParseInt(out int id)) { if (id >= Global.Backgrounds.Backgrounds.Count || id < 0) { e.ErrorEmbed("This background does not exist!") .ToEmbed() .QueueToChannel(e.Channel); return; } Background background = Global.Backgrounds.Backgrounds[id]; var embed = new EmbedBuilder() .SetTitle("Buy Background") .SetImage(background.ImageUrl); if (background.Price > 0) { embed.SetDescription($"This background for your profile will cost {background.Price} mekos, Type `>buybackground {id} yes` to buy."); } else { embed.SetDescription($"This background is not for sale."); } arguments = arguments.Next(); if (arguments?.Argument.ToLower() == "yes") { if (background.Price > 0) { using (var context = new MikiContext()) { User user = await User.GetAsync(context, e.Author); long userId = (long)e.Author.Id; BackgroundsOwned bo = await context.BackgroundsOwned.FindAsync(userId, background.Id); if (bo == null) { await user.AddCurrencyAsync(-background.Price, e.Channel); await context.BackgroundsOwned.AddAsync(new BackgroundsOwned() { UserId = e.Author.Id.ToDbLong(), BackgroundId = background.Id, }); await context.SaveChangesAsync(); e.SuccessEmbed("Background purchased!") .QueueToChannel(e.Channel); } else { throw new BackgroundOwnedException(); } } } } else { embed.ToEmbed() .QueueToChannel(e.Channel); } } }
public async Task SetGuildConfig(EventContext e) { using (MikiContext context = new MikiContext()) { GuildUser g = await context.GuildUsers.FindAsync(e.Guild.Id.ToDbLong()); ArgObject arg = e.Arguments.FirstOrDefault(); if (arg == null) { // TODO: error message return; } switch (arg.Argument) { case "expneeded": { arg = arg.Next(); if (arg != null) { if (int.TryParse(arg.Argument, out int value)) { g.MinimalExperienceToGetRewards = value; Utils.Embed .SetTitle(e.GetResource("miki_terms_config")) .SetDescription(e.GetResource("guildconfig_expneeded", value)) .ToEmbed().QueueToChannel(e.Channel); } } } break; case "visible": { arg = arg.Next(); if (arg != null) { bool?result = arg.AsBoolean(); if (!result.HasValue) { return; } g.VisibleOnLeaderboards = result.Value; string resourceString = g.VisibleOnLeaderboards ? "guildconfig_visibility_true" : "guildconfig_visibility_false"; Utils.Embed .SetTitle(e.GetResource("miki_terms_config")) .SetDescription(resourceString) .ToEmbed().QueueToChannel(e.Channel); } } break; } await context.SaveChangesAsync(); } }
public async Task RedeemKeyAsync(EventContext e) { using (var context = new MikiContext()) { long id = (long)e.Author.Id; Guid guid = Guid.Parse(e.Arguments.Join().Argument); DonatorKey key = await context.DonatorKey.FindAsync(guid); IsDonator donatorStatus = await context.IsDonator.FindAsync(id); if (key != null) { 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; } 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().QueueToChannel(e.Channel); context.DonatorKey.Remove(key); await context.SaveChangesAsync(); // cheap hack. var achievements = AchievementManager.Instance.GetContainerById("donator"); if (donatorStatus.KeysRedeemed == 1) { await achievements.Achievements[0].UnlockAsync(e.Channel, e.Author, 0); } else if (donatorStatus.KeysRedeemed == 5) { await achievements.Achievements[1].UnlockAsync(e.Channel, e.Author, 1); } else if (donatorStatus.KeysRedeemed == 25) { await achievements.Achievements[2].UnlockAsync(e.Channel, e.Author, 2); } } else { e.ErrorEmbed("Your donation key is invalid!"); } } }
public async Task CheckAsync(IDiscordMessage e) { if (e.Author.IsBot) { return; } if (!lastTimeExpGranted.ContainsKey(e.Author.Id)) { lastTimeExpGranted.Add(e.Author.Id, DateTime.MinValue); } if (lastTimeExpGranted[e.Author.Id].AddMinutes(1) < DateTime.Now) { int addedExperience = MikiRandom.Next(2, 5); await MeruUtils.TryAsync(async() => { User a; LocalExperience experience; long userId = e.Author.Id.ToDbLong(); int currentGlobalLevel = 0; int currentLocalLevel = 0; using (var context = new MikiContext()) { a = await context.Users.FindAsync(e.Author.Id.ToDbLong()); if (a == null) { a = await User.CreateAsync(e); } experience = await context.Experience.FindAsync(e.Guild.Id.ToDbLong(), userId); if (experience == null) { experience = await LocalExperience.CreateAsync(context, e.Guild.Id.ToDbLong(), e.Author.Id.ToDbLong()); } if (experience.LastExperienceTime == null) { experience.LastExperienceTime = DateTime.Now; } GuildUser guildUser = await context.GuildUsers.FindAsync(e.Guild.Id.ToDbLong()); if (guildUser == null) { long guildId = e.Guild.Id.ToDbLong(); int?userCount = Bot.instance.Client.GetGuild(e.Guild.Id).Users.Count; int?value = await context.Experience .Where(x => x.ServerId == guildId) .SumAsync(x => x.Experience); guildUser = new GuildUser(); guildUser.Name = e.Guild.Name; guildUser.Id = guildId; guildUser.Experience = value ?? 0; guildUser.UserCount = userCount ?? 0; guildUser.LastRivalRenewed = Utils.MinDbValue; guildUser.MinimalExperienceToGetRewards = 100; guildUser = context.GuildUsers.Add(guildUser); } currentLocalLevel = User.CalculateLevel(experience.Experience); currentGlobalLevel = User.CalculateLevel(a.Total_Experience); experience.Experience += addedExperience; a.Total_Experience += addedExperience; guildUser.Experience += addedExperience; await context.SaveChangesAsync(); } if (currentLocalLevel != User.CalculateLevel(experience.Experience)) { await LevelUpLocalAsync(e, a, currentLocalLevel + 1); } if (currentGlobalLevel != User.CalculateLevel(a.Total_Experience)) { await LevelUpGlobalAsync(e, a, currentGlobalLevel + 1); } lastTimeExpGranted[e.Author.Id] = DateTime.Now; }); } }
public async Task SetRoleLevelAsync(EventContext e) { using (var context = new MikiContext()) { Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong()); List <string> allArgs = new List <string>(); allArgs.AddRange(e.arguments.Split(' ')); if (allArgs.Count >= 2) { int levelrequirement = int.Parse(allArgs[allArgs.Count - 1]); allArgs.RemoveAt(allArgs.Count - 1); IDiscordRole role = e.Guild.Roles .Find(r => r.Name.ToLower() == string.Join(" ", allArgs).TrimEnd(' ').TrimStart(' ').ToLower()); if (role == null) { await e.ErrorEmbed(e.GetResource("error_role_not_found")) .SendToChannel(e.Channel); return; } LevelRole lr = await context.LevelRoles.FindAsync(e.Guild.Id.ToDbLong(), role.Id.ToDbLong()); if (lr == null) { lr = context.LevelRoles.Add(new LevelRole() { GuildId = e.Guild.Id.ToDbLong(), RoleId = role.Id.ToDbLong(), RequiredLevel = levelrequirement }); IDiscordEmbed embed = Utils.Embed; embed.Title = "Added Role!"; embed.Description = $"I'll give someone the role {role.Name} when he/she reaches level {levelrequirement}!"; if (!e.CurrentUser.HasPermissions(e.Channel, DiscordGuildPermission.ManageRoles)) { embed.AddInlineField(e.GetResource("miki_warning"), e.GetResource("setrolelevel_error_no_permissions", $"`{e.GetResource("permission_manage_roles")}`")); } await embed.SendToChannel(e.Channel); } else { lr.RequiredLevel = levelrequirement; IDiscordEmbed embed = Utils.Embed; embed.Title = "Updated Role!"; embed.Description = $"I'll give someone the role {role.Name} when he/she reaches level {levelrequirement}!"; await embed.SendToChannel(e.Channel); } await context.SaveChangesAsync(); } else { await Utils.ErrorEmbed(locale, "Make sure to fill out both the role and the level when creating this!") .SendToChannel(e.Channel); } } }
public async Task MarryAsync(EventContext e) { long askerId = 0; long receiverId = 0; ArgObject args = e.Arguments.FirstOrDefault(); if (args == null) { return; } IDiscordGuildUser user = await args.GetUserAsync(e.Guild); if (user == null) { e.Channel.QueueMessageAsync("Couldn't find this person.."); return; } if (user.Id == (await e.Guild.GetSelfAsync()).Id) { e.Channel.QueueMessageAsync("(Β΄γ»Ογ»`)"); return; } using (MikiContext context = new MikiContext()) { MarriageRepository repository = new MarriageRepository(context); User mentionedPerson = await User.GetAsync(context, user.Id.ToDbLong(), user.Username); User currentUser = await DatabaseHelpers.GetUserAsync(context, e.Author); askerId = currentUser.Id; receiverId = mentionedPerson.Id; if (currentUser == null || mentionedPerson == null) { e.ErrorEmbed(e.Locale.GetString("miki_module_accounts_marry_error_null")).ToEmbed().QueueToChannel(e.Channel); return; } if (mentionedPerson.Banned) { e.ErrorEmbed("This person has been banned from Miki.").ToEmbed().QueueToChannel(e.Channel); return; } if (mentionedPerson.Id == currentUser.Id) { e.ErrorEmbed(e.Locale.GetString("miki_module_accounts_marry_error_null")).ToEmbed().QueueToChannel(e.Channel); return; } if (await repository.ExistsAsync(mentionedPerson.Id, currentUser.Id)) { e.ErrorEmbed(e.Locale.GetString("miki_module_accounts_marry_error_exists")).ToEmbed().QueueToChannel(e.Channel); return; } await repository.ProposeAsync(askerId, receiverId); await context.SaveChangesAsync(); } Utils.Embed .SetTitle("π" + e.Locale.GetString("miki_module_accounts_marry_text", $"**{e.Author.Username}**", $"**{user.Username}**")) .SetDescription(e.Locale.GetString("miki_module_accounts_marry_text2", user.Username, e.Author.Username)) .SetColor(0.4f, 0.4f, 0.8f) .SetThumbnail("https://i.imgur.com/TKZSKIp.png") .AddInlineField("β To accept", $">acceptmarriage @user") .AddInlineField("β To decline", $">declinemarriage @user") .SetFooter("Take your time though! This proposal won't disappear", "") .ToEmbed().QueueToChannel(e.Channel); }
public async Task BuyProfileBackgroundAsync(EventContext e) { int?backgroundId = e.Arguments.First().AsInt(); if (backgroundId.HasValue) { Background background = Global.Backgrounds.Backgrounds[backgroundId.Value]; var embed = new EmbedBuilder(); embed.SetTitle("Buy Background"); if (background.Price > 0) { embed.SetDescription($"This background for your profile will cost {background.Price} mekos, Type yes to buy."); } else { embed.SetDescription($"This background is not for sale."); } embed.SetImage(background.ImageUrl) .ToEmbed().QueueToChannel(e.Channel); if (background.Price > 0) { IDiscordMessage msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession()); if (msg.Content.ToLower()[0] == 'y') { using (var context = new MikiContext()) { User user = await User.GetAsync(context, e.Author); long userId = e.Author.Id.ToDbLong(); BackgroundsOwned bo = await context.BackgroundsOwned.FindAsync(userId, background.Id); if (bo == null) { await user.AddCurrencyAsync(-background.Price, e.Channel); await context.BackgroundsOwned.AddAsync(new BackgroundsOwned() { UserId = e.Author.Id.ToDbLong(), BackgroundId = background.Id, }); await context.SaveChangesAsync(); Utils.SuccessEmbed(e.Channel.Id, "Background purchased!") .QueueToChannel(e.Channel); } else { throw new BackgroundOwnedException(); } } } } } }
public async Task LotteryAsync(EventContext e) { ArgObject arg = e.Arguments.FirstOrDefault(); if (arg == null) { long totalTickets = await(Global.RedisClient as StackExchangeCacheClient).Client.GetDatabase(0).ListLengthAsync(lotteryKey); long yourTickets = 0; string latestWinner = (Global.RedisClient as StackExchangeCacheClient).Client.GetDatabase(0).StringGet("lottery:winner"); if (await lotteryDict.ContainsAsync(e.Author.Id)) { yourTickets = long.Parse(await lotteryDict.GetAsync(e.Author.Id)); } string timeLeft = taskScheduler?.GetInstance(0, lotteryId).TimeLeft.ToTimeString(e.Locale, true) ?? "1h?m?s - will be fixed soon!"; new EmbedBuilder() { Title = "π Lottery", Description = "Make the biggest gamble, and get paid off massively if legit.", Color = new Color(119, 178, 85) }.AddInlineField("Tickets Owned", yourTickets.ToString()) .AddInlineField("Drawing In", timeLeft) .AddInlineField("Total Tickets", totalTickets.ToString()) .AddInlineField("Ticket price", $"{100} mekos") .AddInlineField("Latest Winner", latestWinner ?? "no name") .AddInlineField("How to buy?", ">lottery buy [amount]") .ToEmbed().QueueToChannel(e.Channel); return; } switch (arg.Argument.ToLower()) { case "buy": { arg = arg.Next(); int amount = arg?.AsInt() ?? 1; if (amount < 1) { amount = 1; } using (var context = new MikiContext()) { User u = await DatabaseHelpers.GetUserAsync(context, e.Author); if (amount * 100 > u.Currency) { e.ErrorEmbedResource("miki_mekos_insufficient") .ToEmbed().QueueToChannel(e.Channel); return; } await u.AddCurrencyAsync(-amount * 100, e.Channel); RedisValue[] tickets = new RedisValue[amount]; for (int i = 0; i < amount; i++) { tickets[i] = e.Author.Id.ToString(); } await(Global.RedisClient as StackExchangeCacheClient).Client.GetDatabase(0).ListRightPushAsync(lotteryKey, tickets); int totalTickets = 0; if (await lotteryDict.ContainsAsync(e.Author.Id.ToString())) { totalTickets = int.Parse(await lotteryDict.GetAsync(e.Author.Id.ToString())); } await lotteryDict.AddAsync(e.Author.Id, amount + totalTickets); await context.SaveChangesAsync(); e.SuccessEmbed($"Successfully bought {amount} tickets!") .QueueToChannel(e.Channel); } } break; } }
public async Task AcceptMarriageAsync(EventContext e) { IDiscordUser user = await e.Arguments.Join().GetUserAsync(e.Guild); if (user == null) { e.ErrorEmbed("I couldn't find this user!") .ToEmbed().QueueToChannel(e.Channel); } if (user.Id == e.Author.Id) { e.ErrorEmbed("Please mention someone else than yourself.") .ToEmbed().QueueToChannel(e.Channel); return; } using (var context = new MikiContext()) { MarriageRepository repository = new MarriageRepository(context); User accepter = await DatabaseHelpers.GetUserAsync(context, e.Author); User asker = await DatabaseHelpers.GetUserAsync(context, user); UserMarriedTo marriage = await repository.GetEntryAsync(accepter.Id, asker.Id); if (marriage != null) { if (accepter.MarriageSlots < (await repository.GetMarriagesAsync(accepter.Id)).Count) { e.Channel.QueueMessageAsync($"{e.Author.Username} do not have enough Marriage slots, sorry :("); return; } if (asker.MarriageSlots < (await repository.GetMarriagesAsync(asker.Id)).Count) { e.Channel.QueueMessageAsync($"{asker.Name} does not have enough Marriage slots, sorry :("); return; } if (marriage.ReceiverId != e.Author.Id.ToDbLong()) { e.Channel.QueueMessageAsync($"You can not accept your own responses!"); return; } if (marriage.Marriage.IsProposing) { marriage.Marriage.AcceptProposal(); await context.SaveChangesAsync(); new EmbedBuilder() { Title = ("β€οΈ Happily married"), Color = new Color(190, 25, 49), Description = ($"Much love to { e.Author.Username } and { user.Username } in their future adventures together!") }.ToEmbed().QueueToChannel(e.Channel); } else { e.ErrorEmbed("You're already married to this person ya doofus!") .ToEmbed().QueueToChannel(e.Channel); } } else { e.Channel.QueueMessageAsync("This user hasn't proposed to you!"); return; } } }
public async Task StartSlots(EventContext e, int bet) { using (var context = new MikiContext()) { User u = await context.Users.FindAsync(e.Author.Id.ToDbLong()); int moneyReturned = 0; string[] objects = { "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "β", "β", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", }; EmbedBuilder embed = new EmbedBuilder() .SetAuthor(e.Locale.GetString(LocaleTags.SlotsHeader) + " | " + e.Author.Username, e.Author.GetAvatarUrl(), "https://patreon.com/mikibot"); string[] objectsChosen = { objects[MikiRandom.Next(objects.Length)], objects[MikiRandom.Next(objects.Length)], objects[MikiRandom.Next(objects.Length)] }; Dictionary <string, int> score = new Dictionary <string, int>(); foreach (string o in objectsChosen) { if (score.ContainsKey(o)) { score[o]++; continue; } score.Add(o, 1); } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 0.5f); } else if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 1f); } } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 0.8f); } else if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 1.5f); } } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 1f); } else if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 2f); } } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 1f); } if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 4f); } } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 1.2f); } if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 6f); } } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 1.5f); } if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 10f); } } if (score.ContainsKey("β")) { if (score["β"] == 2) { moneyReturned = (int)Math.Ceiling(bet * 2f); } if (score["β"] == 3) { moneyReturned = (int)Math.Ceiling(bet * 12f); await AchievementManager.Instance.GetContainerById("slots").CheckAsync(new BasePacket() { discordChannel = e.Channel, discordUser = e.Author }); } } if (moneyReturned == 0) { moneyReturned = -bet; embed.AddField(e.Locale.GetString("miki_module_fun_slots_lose_header"), e.Locale.GetString("miki_module_fun_slots_lose_amount", bet, u.Currency - bet)); } else { embed.AddField(e.Locale.GetString(LocaleTags.SlotsWinHeader), e.Locale.GetString(LocaleTags.SlotsWinMessage, moneyReturned, u.Currency + moneyReturned)); } embed.Description = string.Join(" ", objectsChosen); await u.AddCurrencyAsync(moneyReturned, e.Channel); await context.SaveChangesAsync(); embed.ToEmbed().QueueToChannel(e.Channel); } }
private async Task StartFlip(EventContext e, int bet) { if (e.Arguments.Count < 2) { e.ErrorEmbed("Please pick either `heads` or `tails`!") .ToEmbed().QueueToChannel(e.Channel); return; } string sideParam = e.Arguments.Get(1).Argument.ToLower(); int pickedSide = -1; if (sideParam[0] == 'h') { pickedSide = 1; } else if (sideParam[0] == 't') { pickedSide = 0; } if (pickedSide == -1) { e.ErrorEmbed("This is not a valid option!") .ToEmbed().QueueToChannel(e.Channel); return; } string headsUrl = "https://miki-cdn.nyc3.digitaloceanspaces.com/commands/miki-default-heads.png"; string tailsUrl = "https://miki-cdn.nyc3.digitaloceanspaces.com/commands/miki-default-tails.png"; if (e.Arguments.Contains("-bonus")) { headsUrl = "https://miki-cdn.nyc3.digitaloceanspaces.com/commands/miki-secret-heads.png"; tailsUrl = "https://miki-cdn.nyc3.digitaloceanspaces.com/commands/miki-secret-tails.png"; } int side = MikiRandom.Next(2); string imageUrl = side == 1 ? headsUrl : tailsUrl; bool win = (side == pickedSide); int currencyNow = 0; using (MikiContext context = new MikiContext()) { User u = await context.Users.FindAsync(e.Author.Id.ToDbLong()); if (!win) { bet = -bet; } u.Currency += bet; currencyNow = u.Currency; await context.SaveChangesAsync(); } string output = ""; if (win) { output = e.Locale.GetString("flip_description_win", $"`{bet}`"); } else { output = e.Locale.GetString("flip_description_lose"); } output += "\n" + e.Locale.GetString("miki_blackjack_new_balance", currencyNow); DiscordEmbed embed = Utils.Embed .SetAuthor(e.Locale.GetString("flip_header") + " | " + e.Author.Username, e.Author.GetAvatarUrl(), "https://patreon.com/mikibot") .SetDescription(output) .SetThumbnail(imageUrl) .ToEmbed(); embed.QueueToChannel(e.Channel); }
public async Task StartRPS(EventContext e, int bet) { float rewardMultiplier = 1f; if (e.Arguments.Count < 2) { e.ErrorEmbed("You need to choose a weapon!") .ToEmbed().QueueToChannel(e.Channel); } else { User user; RPSManager rps = RPSManager.Instance; EmbedBuilder resultMessage = Utils.Embed .SetTitle("Rock, Paper, Scissors!"); if (rps.TryParse(e.Arguments.Get(1).Argument, out RPSWeapon playerWeapon)) { RPSWeapon botWeapon = rps.GetRandomWeapon(); resultMessage.SetDescription($"{playerWeapon.Name.ToUpper()} {playerWeapon.Emoji} vs. {botWeapon.Emoji} {botWeapon.Name.ToUpper()}"); switch (rps.CalculateVictory(playerWeapon, botWeapon)) { case RPSManager.VictoryStatus.WIN: { using (var context = new MikiContext()) { user = await context.Users.FindAsync(e.Author.Id.ToDbLong()); if (user != null) { await user.AddCurrencyAsync((int)(bet *rewardMultiplier), e.Channel); await context.SaveChangesAsync(); } } resultMessage.Description += $"\n\nYou won `{(int)(bet * rewardMultiplier)}` mekos! Your new balance is `{user.Currency}`."; } break; case RPSManager.VictoryStatus.LOSE: { using (var context = new MikiContext()) { user = await context.Users.FindAsync(e.Author.Id.ToDbLong()); if (user != null) { await user.AddCurrencyAsync(-bet, e.Channel, null); await context.SaveChangesAsync(); } } resultMessage.Description += $"\n\nYou lost `{bet}` mekos ! Your new balance is `{user.Currency}`."; } break; case RPSManager.VictoryStatus.DRAW: { resultMessage.Description += $"\n\nIt's a draw! no mekos were lost!."; } break; } } else { resultMessage.SetDescription("Invalid weapon!").ToEmbed() .QueueToChannel(e.Channel); return; } resultMessage.ToEmbed().QueueToChannel(e.Channel); } }
public async Task GiveMekosAsync(EventContext e) { if (e.Arguments.Count < 2) { e.ErrorEmbedResource("give_error_no_arg") .ToEmbed().QueueToChannel(e.Channel); return; } ArgObject arg = e.Arguments.FirstOrDefault(); IDiscordUser user = null; if (arg != null) { user = await arg.GetUserAsync(e.Guild); } if (user == null) { e.ErrorEmbedResource("give_error_no_mention") .ToEmbed().QueueToChannel(e.Channel); return; } arg = arg.Next(); int?amount = arg?.AsInt() ?? null; if (amount == null) { e.ErrorEmbedResource("give_error_amount_unparsable") .ToEmbed().QueueToChannel(e.Channel); return; } if (amount <= 0) { e.ErrorEmbedResource("give_error_min_mekos") .ToEmbed().QueueToChannel(e.Channel); return; } using (MikiContext context = new MikiContext()) { User sender = await User.GetAsync(context, e.Author); User receiver = await User.GetAsync(context, user); if (amount.Value <= sender.Currency) { await sender.AddCurrencyAsync(-amount.Value, e.Channel, sender); await receiver.AddCurrencyAsync(amount.Value, e.Channel, sender); new EmbedBuilder() { Title = "Γ°ΕΈβΒΈ transaction", Description = e.Locale.GetString("give_description", sender.Name, receiver.Name, amount.Value), Color = new Color(255, 140, 0), }.ToEmbed().QueueToChannel(e.Channel); await context.SaveChangesAsync(); } else { e.ErrorEmbedResource("user_error_insufficient_mekos") .ToEmbed().QueueToChannel(e.Channel); } } }
public async Task IAmAsync(EventContext e) { using (var context = new MikiContext()) { string roleName = e.Arguments.ToString(); List <IDiscordRole> roles = await GetRolesByName(e.Guild, roleName); IDiscordRole role = null; if (roles.Count > 1) { List <LevelRole> levelRoles = await context.LevelRoles.Where(x => x.GuildId == (long)e.Guild.Id).ToListAsync(); if (levelRoles.Where(x => x.GetRoleAsync().Result.Name.ToLower() == roleName.ToLower()).Count() > 1) { e.ErrorEmbed("two roles configured have the same name.") .ToEmbed().QueueToChannel(e.Channel); return; } else { role = levelRoles.Where(x => x.GetRoleAsync().Result.Name.ToLower() == roleName.ToLower()).FirstOrDefault().GetRoleAsync().Result; } } else { role = roles.FirstOrDefault(); } if (role == null) { e.ErrorEmbedResource("error_role_null") .ToEmbed().QueueToChannel(e.Channel); return; } IDiscordGuildUser author = await e.Guild.GetMemberAsync(e.Author.Id); if (author.RoleIds.Contains(role.Id)) { e.ErrorEmbed(e.Locale.GetString("error_role_already_given")) .ToEmbed().QueueToChannel(e.Channel); return; } LevelRole newRole = await context.LevelRoles.FindAsync(e.Guild.Id.ToDbLong(), role.Id.ToDbLong()); User user = (await context.Users.FindAsync(e.Author.Id.ToDbLong())); IDiscordGuildUser discordUser = await e.Guild.GetMemberAsync(user.Id.FromDbLong()); LocalExperience localUser = await LocalExperience.GetAsync(context, e.Guild.Id.ToDbLong(), discordUser.Id.ToDbLong(), discordUser.Username); if (!newRole?.Optable ?? false) { await e.ErrorEmbed(e.Locale.GetString("error_role_forbidden")) .ToEmbed().SendToChannel(e.Channel); return; } int level = User.CalculateLevel(localUser.Experience); if (newRole.RequiredLevel > level) { await e.ErrorEmbed(e.Locale.GetString("error_role_level_low", newRole.RequiredLevel - level)) .ToEmbed().SendToChannel(e.Channel); return; } if (newRole.RequiredRole != 0 && !discordUser.RoleIds.Contains(newRole.RequiredRole.FromDbLong())) { var requiredRole = await e.Guild.GetRoleAsync(newRole.RequiredRole.FromDbLong()); e.ErrorEmbed( e.Locale.GetString( "error_role_required", $"**{requiredRole.Name}**" ) ).ToEmbed().QueueToChannel(e.Channel); return; } if (newRole.Price > 0) { if (user.Currency >= newRole.Price) { await user.AddCurrencyAsync(-newRole.Price); await context.SaveChangesAsync(); } else { await e.ErrorEmbed(e.Locale.GetString("user_error_insufficient_mekos")) .ToEmbed().SendToChannel(e.Channel); return; } } var me = await e.Guild.GetSelfAsync(); if (!await me.HasPermissionsAsync(GuildPermission.ManageRoles)) { e.ErrorEmbed(e.Locale.GetString("permission_error_low", "give roles")).ToEmbed() .QueueToChannel(e.Channel); return; } if (newRole.GetRoleAsync().Result.Position >= await me.GetHierarchyAsync()) { e.ErrorEmbed(e.Locale.GetString("permission_error_low", "give roles")).ToEmbed() .QueueToChannel(e.Channel); return; } await author.AddRoleAsync(newRole.GetRoleAsync().Result); new EmbedBuilder() .SetTitle("I AM") .SetColor(128, 255, 128) .SetDescription($"You're a(n) {role.Name} now!") .ToEmbed().QueueToChannel(e.Channel); } }
public async Task GetDailyAsync(EventContext e) { using (var context = new MikiContext()) { User u = await User.GetAsync(context, e.Author); if (u == null) { e.ErrorEmbed(e.Locale.GetString("user_error_no_account")) .ToEmbed().QueueToChannel(e.Channel); return; } int dailyAmount = 100; int dailyStreakAmount = 20; if (await u.IsDonatorAsync(context)) { dailyAmount *= 2; dailyStreakAmount *= 2; } if (u.LastDailyTime.AddHours(23) >= DateTime.Now) { var time = (u.LastDailyTime.AddHours(23) - DateTime.Now).ToTimeString(e.Locale); e.ErrorEmbed($"You already claimed your daily today! Please wait another `{time}` before using it again.") .AddInlineField("Need more mekos?", "Vote for us every day on [DiscordBots](https://discordbots.org/bot/160105994217586689/vote) for a bonus daily!") .ToEmbed().QueueToChannel(e.Channel); return; } int streak = 0; string redisKey = $"user:{e.Author.Id}:daily"; if (await Global.RedisClient.ExistsAsync(redisKey)) { streak = await Global.RedisClient.GetAsync <int>(redisKey); streak++; } int amount = dailyAmount + (dailyStreakAmount * Math.Min(100, streak)); await u.AddCurrencyAsync(amount, e.Channel); u.LastDailyTime = DateTime.Now; var embed = Utils.Embed.SetTitle("Γ°ΕΈβΒ° Daily") .SetDescription($"Received **{amount}** Mekos! You now have `{u.Currency}` Mekos") .SetColor(253, 216, 136); if (streak > 0) { embed.AddInlineField("Streak!", $"You're on a {streak} day daily streak!"); } embed.ToEmbed().QueueToChannel(e.Channel); await Global.RedisClient.UpsertAsync(redisKey, streak, new TimeSpan(48, 0, 0)); await context.SaveChangesAsync(); } }
public async Task IAmListAsync(EventContext e) { using (var context = new MikiContext()) { int page = Math.Max((e.Arguments.Join()?.TakeInt() ?? 0) - 1, 0); long guildId = e.Guild.Id.ToDbLong(); List <LevelRole> roles = await context.LevelRoles .Where(x => x.GuildId == guildId) .OrderBy(x => x.RoleId) .Skip(page * 25) .Take(25) .ToListAsync(); StringBuilder stringBuilder = new StringBuilder(); var guildRoles = await e.Guild.GetRolesAsync(); List <Tuple <IDiscordRole, LevelRole> > availableRoles = roles .Where(x => guildRoles.Any(y => x.RoleId == (long)y.Id)) .Select(x => new Tuple <IDiscordRole, LevelRole>(guildRoles .Single(y => x.RoleId == (long)y.Id), x) ).ToList(); foreach (var role in availableRoles) { if (role.Item2.Optable) { if (role.Item1 == null) { context.LevelRoles.Remove(role.Item2); continue; } stringBuilder.Append($"`{role.Item1.Name.PadRight(20)}|`"); if (role.Item2.RequiredLevel > 0) { stringBuilder.Append($"β{role.Item2.RequiredLevel} "); } if (role.Item2.Automatic) { stringBuilder.Append($"βοΈ"); } if (role.Item2.RequiredRole != 0) { var roleRequired = await e.Guild.GetRoleAsync(role.Item2.RequiredRole.FromDbLong()); stringBuilder.Append($"π¨`{roleRequired?.Name ?? "non-existing role"}`"); } if (role.Item2.Price != 0) { stringBuilder.Append($"πΈ{role.Item2.Price} "); } stringBuilder.AppendLine(); } } if (stringBuilder.Length == 0) { stringBuilder.Append(e.Locale.GetString("miki_placeholder_null")); } await context.SaveChangesAsync(); new EmbedBuilder().SetTitle("π Available Roles") .SetDescription(stringBuilder.ToString()) .SetColor(204, 214, 221) .SetFooter("page " + (page + 1)) .ToEmbed().QueueToChannel(e.Channel); } }
public async Task GiveReputationAsync(EventContext e) { using (var context = new MikiContext()) { User giver = await context.Users.FindAsync(e.Author.Id.ToDbLong()); if (e.message.MentionedUserIds.Count == 0) { TimeSpan pointReset = (DateTime.Now.AddDays(1).Date - DateTime.Now); await Utils.Embed .SetTitle("Reputation") .SetDescription( "Here are your statistics on reputation points!\n\nTo give someone reputation, do `>rep <mention>`") .AddInlineField("Total Rep Received", giver.Reputation.ToString()) .AddInlineField("Rep points reset in:", pointReset.ToTimeString(e.Channel.GetLocale())) .SendToChannel(e.Channel); return; } User receiver = await context.Users.FindAsync(e.message.MentionedUserIds.First().ToDbLong()); if (giver.LastReputationGiven.Day != DateTime.Now.Day) { giver.ReputationPointsLeft = 3; giver.LastReputationGiven = DateTime.Now; } if (giver.Id == receiver.Id) { await Utils.Embed .SetTitle("Reputation") .SetDescription($"You cannot rep yourself.") .SendToChannel(e.Channel); return; } if (giver.ReputationPointsLeft > 0) { giver.ReputationPointsLeft--; receiver.Reputation++; await Utils.Embed .SetTitle("Reputation") .SetDescription( $"{giver.Name} has given {receiver.Name} 1 reputation! {receiver.Name} now has {receiver.Reputation} points!") .AddInlineField("Points left for today", giver.ReputationPointsLeft.ToString()) .SendToChannel(e.Channel); } else { await Utils.Embed .SetTitle("Reputation") .SetDescription($"You're out of points for today!") .SendToChannel(e.Channel); } await context.SaveChangesAsync(); } }
/*public async Task ConfigRoleInteractiveAsync(EventContext e) * { * using (var context = new MikiContext()) * { * EmbedBuilder sourceEmbed = Utils.Embed.SetTitle("β Interactive Mode") * .SetDescription("Type out the role name you want to config") * .SetColor(138, 182, 239); * IDiscordMessage sourceMessage = await sourceEmbed.ToEmbed().SendToChannel(e.Channel); * IDiscordMessage msg = null; * * while (true) * { * msg = await e.EventSystem.GetCommandHandler<MessageListener>().WaitForNextMessage(e.CreateSession()); * * if (msg.Content.Length < 20) * { * break; * } * else * { * await sourceMessage.EditAsync(new EditMessageArgs * { * embed = e.ErrorEmbed("That role name is way too long! Try again.") * .ToEmbed() * }); * } * } * * string roleName = msg.Content; * * List<IDiscordRole> rolesFound = await GetRolesByName(e.Guild, roleName.ToLower()); * IDiscordRole role = null; * * if(rolesFound.Count == 0) * { * // Hey, I couldn't find this role, Can I make a new one? * await sourceMessage.EditAsync(new EditMessageArgs * { * embed = e.ErrorEmbed($"There's no role that is named `{roleName}`, Shall I create it? Y/N").ToEmbed() * }); * * msg = await e.EventSystem.GetCommandHandler<MessageListener>().WaitForNextMessage(e.CreateSession()); * * if (msg.Content.ToLower()[0] != 'y') * { * throw new RoleNullException(); * } * * role = await e.Guild.CreateRoleAsync(new CreateRoleArgs * { * Name = roleName, * }); * } * else if (rolesFound.Count > 1) * { * string roleIds = string.Join("\n", rolesFound.Select(x => $"`{x.Name}`: {x.Id}")); * * if (roleIds.Length > 1024) * { * roleIds = roleIds.Substring(0, 1024); * } * * sourceEmbed = Utils.Embed.SetTitle("β Interactive Mode") * .SetDescription("I found multiple roles with that name, which one would you like? please enter the ID") * .AddInlineField("Roles - Ids", roleIds) * .SetColor(138, 182, 239); * * sourceMessage = await sourceEmbed.ToEmbed().SendToChannel(e.Channel); * while(true) * { * msg = await e.EventSystem.GetCommandHandler<MessageListener>().WaitForNextMessage(e.CreateSession()); * if (ulong.TryParse(msg.Content, out ulong id)) * { * role = rolesFound.Where(x => x.Id == id) * .FirstOrDefault(); * * if (role != null) * { * break; * } * else * { * await sourceMessage.EditAsync(new EditMessageArgs { * embed = e.ErrorEmbed("I couldn't find that role id in the list. Try again!") * .AddInlineField("Roles - Ids", string.Join("\n", roleIds)).ToEmbed() * }); * } * } * else * { * await sourceMessage.EditAsync(new EditMessageArgs * { * embed = e.ErrorEmbed("I couldn't find that role. Try again!") * .AddInlineField("Roles - Ids", string.Join("\n", roleIds)).ToEmbed() * }); * } * } * } * else * { * role = rolesFound.FirstOrDefault(); * } * * LevelRole newRole = await context.LevelRoles.FindAsync(e.Guild.Id.ToDbLong(), role.Id.ToDbLong()); * if(newRole == null) * { * newRole = (await context.LevelRoles.AddAsync(new LevelRole() * { * RoleId = role.Id.ToDbLong(), * GuildId = e.Guild.Id.ToDbLong() * })).Entity; * } * * sourceEmbed = Utils.Embed.SetTitle("β Interactive Mode") * .SetDescription("Is there a role that is needed to get this role? Type out the role name, or `-` to skip") * .SetColor(138, 182, 239); * * sourceMessage = await sourceEmbed.ToEmbed().SendToChannel(e.Channel); * * while (true) * { * msg = await e.EventSystem.GetCommandHandler<MessageListener>().WaitForNextMessage(e.CreateSession()); * * rolesFound = (await GetRolesByName(e.Guild, msg.Content.ToLower())); * IDiscordRole parentRole = null; * * if (rolesFound.Count > 1) * { * string roleIds = string.Join("\n", rolesFound.Select(x => $"`{x.Name}`: {x.Id}")); * * if (roleIds.Length > 1024) * { * roleIds = roleIds.Substring(0, 1024); * } * * sourceEmbed = Utils.Embed.SetTitle("β Interactive Mode") * .SetDescription("I found multiple roles with that name, which one would you like? please enter the ID") * .AddInlineField("Roles - Ids", roleIds) * .SetColor(138, 182, 239); * * sourceMessage = await sourceEmbed.ToEmbed().SendToChannel(e.Channel); * while (true) * { * msg = await e.EventSystem.GetCommandHandler<MessageListener>().WaitForNextMessage(e.CreateSession()); * if (ulong.TryParse(msg.Content, out ulong id)) * { * parentRole = rolesFound.Where(x => x.Id == id) * .FirstOrDefault(); * * if (parentRole != null) * { * break; * } * else * { * await sourceMessage.EditAsync(new EditMessageArgs { * embed = e.ErrorEmbed("I couldn't find that role id in the list. Try again!") * .AddInlineField("Roles - Ids", string.Join("\n", roleIds)).ToEmbed() * }) ; * } * } * else * { * await sourceMessage.EditAsync(new EditMessageArgs * { * embed = e.ErrorEmbed("I couldn't find that role. Try again!") * .AddInlineField("Roles - Ids", string.Join("\n", roleIds)).ToEmbed() * }); * } * } * } * else * { * parentRole = rolesFound.FirstOrDefault(); * } * * if (parentRole != null || msg.Content == "-") * { * newRole.RequiredRole = (long?)parentRole?.Id ?? 0; * break; * } * * await sourceMessage.EditAsync(new EditMessageArgs * { * embed = e.ErrorEmbed("I couldn't find that role. Try again!").ToEmbed() * }); * } * * sourceEmbed = Utils.Embed.SetTitle("β Interactive Mode") * .SetDescription($"Is there a level requirement? type a number, if there is no requirement type 0") * .SetColor(138, 182, 239); * * sourceMessage = await sourceEmbed.ToEmbed().SendToChannel(e.Channel); * * while (true) * { * msg = await e.EventSystem.GetCommandHandler<MessageListener>().WaitForNextMessage(e.CreateSession()); * * if (int.TryParse(msg.Content, out int r)) * { * if (r >= 0) * { * newRole.RequiredLevel = r; * break; * } * else * { * await sourceMessage.EditAsync(new EditMessageArgs * { * embed = sourceEmbed.SetDescription($"Please pick a number above 0. Try again") * .ToEmbed() * }); * } * } * else * { * await sourceMessage.EditAsync(new EditMessageArgs * { * embed = sourceEmbed.SetDescription($"Are you sure `{msg.Content}` is a number? Try again").ToEmbed() * }); * } * } * * sourceEmbed = Utils.Embed.SetTitle("β Interactive Mode") * .SetDescription($"Should I give them when the user level ups? type `yes`, otherwise it will be considered as no") * .SetColor(138, 182, 239); * * sourceMessage = await sourceEmbed.ToEmbed().SendToChannel(e.Channel); * * msg = await e.EventSystem.GetCommandHandler<MessageListener>().WaitForNextMessage(e.CreateSession()); * if (msg == null) * { * return; * } * * newRole.Automatic = msg.Content.ToLower()[0] == 'y'; * * sourceEmbed = Utils.Embed.SetTitle("β Interactive Mode") * .SetDescription($"Should users be able to opt in? type `yes`, otherwise it will be considered as no") * .SetColor(138, 182, 239); * * sourceMessage = await sourceEmbed.ToEmbed().SendToChannel(e.Channel); * * msg = await e.EventSystem.GetCommandHandler<MessageListener>().WaitForNextMessage(e.CreateSession()); * * newRole.Optable = msg.Content.ToLower()[0] == 'y'; * * if (newRole.Optable) * { * sourceEmbed = Utils.Embed.SetTitle("β Interactive Mode") * .SetDescription($"Do you want the user to pay mekos for the role? Enter any amount. Enter 0 to keep the role free.") * .SetColor(138, 182, 239); * * sourceMessage = await sourceEmbed.ToEmbed().SendToChannel(e.Channel); * * while (true) * { * msg = await e.EventSystem.GetCommandHandler<MessageListener>().WaitForNextMessage(e.CreateSession()); * * if (msg == null) * { * return; * } * * if (int.TryParse(msg.Content, out int r)) * { * if (r >= 0) * { * newRole.Price = r; * break; * } * else * { * await sourceMessage.EditAsync(new EditMessageArgs * { * embed = e.ErrorEmbed($"Please pick a number above 0. Try again").ToEmbed() * }); * } * } * else * { * await sourceMessage.EditAsync(new EditMessageArgs * { * embed = e.ErrorEmbed($"Not quite sure if this is a number π€").ToEmbed() * }); * } * } * } * * await context.SaveChangesAsync(); * Utils.Embed.SetTitle("β Role Config") * .SetColor(102, 117, 127) * .SetDescription($"Updated {role.Name}!") * .ToEmbed().QueueToChannel(e.Channel); * } * }*/ public async Task ConfigRoleQuickAsync(EventContext e) { using (var context = new MikiContext()) { string roleName = e.Arguments.ToString().Split('"')[1]; IDiscordRole role = null; if (ulong.TryParse(roleName, out ulong s)) { role = await e.Guild.GetRoleAsync(s); } else { role = (await GetRolesByName(e.Guild, roleName)).FirstOrDefault(); } LevelRole newRole = await context.LevelRoles.FindAsync(e.Guild.Id.ToDbLong(), role.Id.ToDbLong()); MSLResponse arguments = new MMLParser(e.Arguments.ToString().Substring(roleName.Length + 3)) .Parse(); if (role.Name.Length > 20) { await e.ErrorEmbed("Please keep role names below 20 letters.") .ToEmbed().SendToChannel(e.Channel); return; } if (newRole == null) { newRole = context.LevelRoles.Add(new LevelRole() { GuildId = (e.Guild.Id.ToDbLong()), RoleId = (role.Id.ToDbLong()), }).Entity; } if (arguments.HasKey("automatic")) { newRole.Automatic = arguments.GetBool("automatic"); } if (arguments.HasKey("optable")) { newRole.Optable = arguments.GetBool("optable"); } if (arguments.HasKey("level-required")) { newRole.RequiredLevel = arguments.GetInt("level-required"); } if (arguments.HasKey("price")) { newRole.Price = arguments.GetInt("price"); } if (arguments.HasKey("role-required")) { long id = 0; if (arguments.TryGet("role-required", out long l)) { id = l; } else { var r = (await e.Guild.GetRolesAsync()) .Where(x => x.Name.ToLower() == arguments.GetString("role-required").ToLower()) .FirstOrDefault(); if (r != null) { id = r.Id.ToDbLong(); } } if (id != 0) { newRole.RequiredRole = id; } } await context.SaveChangesAsync(); new EmbedBuilder() .SetTitle("β Role Config") .SetColor(102, 117, 127) .SetDescription($"Updated {role.Name}!") .ToEmbed().QueueToChannel(e.Channel); } }
public async Task GuildWeekly(EventContext e) { using (MikiContext database = new MikiContext()) { LocalExperience thisUser = await database.LocalExperience.FindAsync(e.Guild.Id.ToDbLong(), e.Author.Id.ToDbLong()); GuildUser thisGuild = await database.GuildUsers.FindAsync(e.Guild.Id.ToDbLong()); Timer timer = await database.Timers.FindAsync(e.Guild.Id.ToDbLong(), e.Author.Id.ToDbLong()); if (thisUser == null) { return; } if (thisGuild == null) { return; } if (thisUser.Experience >= thisGuild.MinimalExperienceToGetRewards) { if (timer == null) { timer = (await database.Timers.AddAsync(new Timer() { GuildId = e.Guild.Id.ToDbLong(), UserId = e.Author.Id.ToDbLong(), Value = DateTime.Now.AddDays(-30) })).Entity; await database.SaveChangesAsync(); } if (timer.Value.AddDays(7) <= DateTime.Now) { //IDiscordGuild guild = Bot.Instance.Client.GetGuild(thisGuild.Id.FromDbLong()); GuildUser rival = await thisGuild.GetRival(); if (rival == null) { Utils.Embed .SetTitle(e.GetResource("miki_terms_weekly")) .SetDescription(e.GetResource("guildweekly_error_no_rival")) .ToEmbed().QueueToChannel(e.Channel); return; } if (rival.Experience > thisGuild.Experience) { Utils.Embed .SetTitle(e.GetResource("miki_terms_weekly")) .SetDescription(e.GetResource("guildweekly_error_low_level")) .ToEmbed().QueueToChannel(e.Channel); return; } int mekosGained = (int)Math.Round((((MikiRandom.NextDouble() + 1.25) * 0.5) * 10) * thisGuild.CalculateLevel(thisGuild.Experience)); User user = await database.Users.FindAsync(e.Author.Id.ToDbLong()); if (user == null) { // TODO: Add response return; } await user.AddCurrencyAsync(mekosGained, e.Channel); Utils.Embed .SetTitle(e.GetResource("miki_terms_weekly")) .AddInlineField("Mekos", mekosGained.ToString()) .ToEmbed().QueueToChannel(e.Channel); timer.Value = DateTime.Now; await database.SaveChangesAsync(); } else { Utils.Embed .SetTitle(e.GetResource("miki_terms_weekly")) .SetDescription(e.GetResource("guildweekly_error_timer_running", (timer.Value.AddDays(7) - DateTime.Now).ToTimeString(e.Channel.Id))) .ToEmbed().QueueToChannel(e.Channel); } } else { Utils.Embed .SetTitle(e.GetResource("miki_terms_weekly")) .SetDescription(e.GetResource("miki_guildweekly_insufficient_exp", thisGuild.MinimalExperienceToGetRewards)) .ToEmbed().QueueToChannel(e.Channel); } } }
public async Task GuildWeekly(EventContext context) { using (MikiContext database = new MikiContext()) { Locale locale = Locale.GetEntity(context.Channel.Id); LocalExperience thisUser = await database.Experience.FindAsync(context.Guild.Id.ToDbLong(), context.Author.Id.ToDbLong()); GuildUser thisGuild = await database.GuildUsers.FindAsync(context.Guild.Id.ToDbLong()); Timer timer = await database.Timers.FindAsync(context.Guild.Id.ToDbLong(), context.Author.Id.ToDbLong()); if (thisUser == null) { Log.ErrorAt("Guildweekly", "User is null"); return; } if (thisGuild == null) { Log.ErrorAt("Guildweekly", "Guild is null"); return; } if (thisUser.Experience > thisGuild.MinimalExperienceToGetRewards) { if (timer == null) { timer = database.Timers.Add(new Timer() { GuildId = context.Guild.Id.ToDbLong(), UserId = context.Author.Id.ToDbLong(), Value = DateTime.Now.AddDays(-30) }); await database.SaveChangesAsync(); } if (timer.Value.AddDays(7) <= DateTime.Now) { SocketGuild guild = Bot.instance.Client.GetGuild(thisGuild.Id.FromDbLong()); GuildUser rival = await thisGuild.GetRival(); if (rival == null) { await Utils.Embed .SetTitle(locale.GetString("miki_terms_weekly")) .SetDescription(context.GetResource("guildweekly_error_no_rival")) .SendToChannel(context.Channel); return; } if (rival.Experience > thisGuild.Experience) { await Utils.Embed .SetTitle(locale.GetString("miki_terms_weekly")) .SetDescription(context.GetResource("guildweekly_error_low_level")) .SendToChannel(context.Channel); return; } int mekosGained = (int)Math.Round((((Global.random.NextDouble() + 1.25) * 0.5) * 10) * thisGuild.CalculateLevel(thisGuild.Experience)); User user = await database.Users.FindAsync(context.Author.Id.ToDbLong()); await user.AddCurrencyAsync(context.Channel, null, mekosGained); await Utils.Embed .SetTitle(locale.GetString("miki_terms_weekly")) .AddInlineField("Mekos", mekosGained.ToString()) .SendToChannel(context.Channel); timer.Value = DateTime.Now; await database.SaveChangesAsync(); } else { await Utils.Embed .SetTitle(locale.GetString("miki_terms_weekly")) .SetDescription(context.GetResource("guildweekly_error_timer_running", (timer.Value.AddDays(7) - DateTime.Now).ToTimeString(locale))) .SendToChannel(context.Channel); } } else { await Utils.Embed .SetTitle(locale.GetString("miki_terms_weekly")) .SetDescription(locale.GetString("miki_guildweekly_insufficient_exp", thisGuild.MinimalExperienceToGetRewards)) .SendToChannel(context.Channel); } } }
public async Task GiveMekosAsync(EventContext e) { Locale locale = Locale.GetEntity(e.Guild.Id); string[] arguments = e.arguments.Split(' '); if (arguments.Length < 2) { await Utils.ErrorEmbed(locale, "give_error_no_arg").SendToChannel(e.Channel); return; } if (e.message.MentionedUserIds.Count <= 0) { await Utils.ErrorEmbed(locale, e.GetResource("give_error_no_mention")).SendToChannel(e.Channel); return; } if (!int.TryParse(arguments[1], out int goldSent)) { await Utils.ErrorEmbed(locale, e.GetResource("give_error_amount_unparsable")).SendToChannel(e.Channel); return; } if (goldSent > 999999) { await Utils.ErrorEmbed(locale, e.GetResource("give_error_max_mekos")).SendToChannel(e.Channel); return; } if (goldSent <= 0) { await Utils.ErrorEmbed(locale, e.GetResource("give_error_min_mekos")).SendToChannel(e.Channel); return; } using (MikiContext context = new MikiContext()) { User sender = await context.Users.FindAsync(e.Author.Id.ToDbLong()); if (sender == null) { // HOW THE F**K?! return; } User receiver = await context.Users.FindAsync(e.message.MentionedUserIds.First().ToDbLong()); if (receiver == null) { await Utils.ErrorEmbed(locale, e.GetResource("user_error_no_account")) .SendToChannel(e.Channel); return; } if (goldSent <= sender.Currency) { await receiver.AddCurrencyAsync(goldSent, e.Channel, sender); await sender.AddCurrencyAsync(-goldSent, e.Channel, sender); IDiscordEmbed em = Utils.Embed; em.Title = "Γ°ΕΈβΒΈ transaction"; em.Description = e.GetResource("give_description", sender.Name, receiver.Name, goldSent); em.Color = new IA.SDK.Color(255, 140, 0); await context.SaveChangesAsync(); await em.SendToChannel(e.Channel); } else { await Utils.ErrorEmbed(locale, e.GetResource("user_error_insufficient_mekos")) .SendToChannel(e.Channel); } } }
public async Task SlotsAsync(EventContext e) { int moneyBet = 0; using (var context = new MikiContext()) { User u = await context.Users.FindAsync(e.Author.Id.ToDbLong()); Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong()); if (!string.IsNullOrWhiteSpace(e.arguments)) { moneyBet = int.Parse(e.arguments); if (moneyBet > u.Currency) { await e.Channel.SendMessage(locale.GetString(Locale.InsufficientMekos)); return; } } int moneyReturned = 0; if (moneyBet <= 0) { return; } string[] objects = { "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "β", "β", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", "π", }; IDiscordEmbed embed = Utils.Embed; embed.Title = locale.GetString(Locale.SlotsHeader); string[] objectsChosen = { objects[MikiRandom.Next(objects.Length)], objects[MikiRandom.Next(objects.Length)], objects[MikiRandom.Next(objects.Length)] }; Dictionary <string, int> score = new Dictionary <string, int>(); foreach (string o in objectsChosen) { if (score.ContainsKey(o)) { score[o]++; continue; } score.Add(o, 1); } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(moneyBet * 0.5f); } else if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(moneyBet * 1f); } } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(moneyBet * 0.8f); } else if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(moneyBet * 1.5f); } } if (score.ContainsKey("π")) { if (score["π"] == 2) { moneyReturned = (int)Math.Ceiling(moneyBet * 1f); } else if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(moneyBet * 2f); } } if (score.ContainsKey("π")) { if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(moneyBet * 4f); } } if (score.ContainsKey("π")) { if (score["π"] == 3) { moneyReturned = (int)Math.Ceiling(moneyBet * 6f); } } if (score.ContainsKey("β")) { if (score["β"] == 3) { moneyReturned = (int)Math.Ceiling(moneyBet * 12f); } } if (moneyReturned == 0) { moneyReturned = -moneyBet; embed.AddField(locale.GetString("miki_module_fun_slots_lose_header"), locale.GetString("miki_module_fun_slots_lose_amount", moneyBet, u.Currency - moneyBet)); } else { embed.AddField(locale.GetString(Locale.SlotsWinHeader), locale.GetString(Locale.SlotsWinMessage, moneyReturned, u.Currency + moneyReturned)); } embed.Description = string.Join(" ", objectsChosen); await u.AddCurrencyAsync(e.Channel, null, moneyReturned); await context.SaveChangesAsync(); await embed.SendToChannel(e.Channel); } }