public async Task SetModuleAsync(EventContext e) { ArgObject arg = e.Arguments.FirstOrDefault(); if (arg == null) { return; } string moduleName = arg.Argument; Module m = e.EventSystem.GetCommandHandler <SimpleCommandHandler>().Modules.FirstOrDefault(x => x.Name == moduleName); if (m == null) { e.ErrorEmbed($"{arg.Argument} is not a valid module.") .ToEmbed().QueueToChannel(e.Channel); return; } arg = arg?.Next(); bool?setValue = arg.AsBoolean(); if (!setValue.HasValue) { setValue = arg.Argument.ToLower() == "yes" || arg.Argument == "1"; } if (!m.CanBeDisabled && !setValue.Value) { e.ErrorEmbed(e.GetResource("miki_admin_cannot_disable", $"`{moduleName}`")) .ToEmbed().QueueToChannel(e.Channel); return; } arg = arg?.Next(); if (arg != null) { if (arg.Argument == "-s") { // TODO: serverwide disable/enable } } await m.SetEnabled(Global.RedisClient, e.Channel.Id, (setValue ?? false)); Utils.SuccessEmbed(e.Channel.Id, ((setValue ?? false) ? e.GetResource("miki_generic_enabled") : e.GetResource("miki_generic_disabled")) + $" {m.Name}") .QueueToChannel(e.Channel); }
public async Task SetCommandAsync(EventContext e) { ArgObject arg = e.Arguments.FirstOrDefault(); if (arg == null) { return; } string commandId = arg.Argument; Event command = e.EventSystem.GetCommandHandler <SimpleCommandHandler>().Commands.FirstOrDefault(x => x.Name == commandId); if (command == null) { e.ErrorEmbed($"{commandId} is not a valid command") .ToEmbed().QueueToChannel(e.Channel); return; } arg = arg.Next(); bool?setValue = arg.AsBoolean(); if (!setValue.HasValue) { setValue = arg.Argument.ToLower() == "yes" || arg.Argument == "1"; } if (!command.CanBeDisabled) { e.ErrorEmbed(e.Locale.GetString("miki_admin_cannot_disable", $"`{commandId}`")) .ToEmbed().QueueToChannel(e.Channel); return; } arg = arg?.Next(); if (arg != null) { if (arg.Argument == "-s") { // TODO: serverwide disable/enable } } using (var context = new MikiContext()) { await command.SetEnabled(context, Global.RedisClient, e.Channel.Id, setValue ?? false); } e.SuccessEmbed(((setValue ?? false) ? e.Locale.GetString("miki_generic_enabled") : e.Locale.GetString("miki_generic_disabled")) + $" {command.Name}") .QueueToChannel(e.Channel); }
public async Task BlackjackAsync(EventContext e) { ArgObject args = e.Arguments.FirstOrDefault(); string subCommand = args?.Argument.ToLower() ?? ""; args = args?.Next(); switch (subCommand) { case "new": { await OnBlackjackNew(e, args); } break; case "hit": case "draw": { await OnBlackjackHit(e); } break; case "stay": case "stand": { await OnBlackjackHold(e); } break; default: { new EmbedBuilder() .SetTitle("🎲 Blackjack") .SetColor(234, 89, 110) .SetDescription("Play a game of blackjack against miki!\n\n" + "`>blackjack new <bet> [ok]` to start a new game\n" + "`>blackjack hit` to draw a card\n" + "`>blackjack stay` to stand") .ToEmbed() .QueueToChannel(e.Channel); } break; } }
private Task CancelReminderAsync(EventContext e) { ArgObject arg = e.Arguments.FirstOrDefault(); arg = arg?.Next(); if (arg == null) { e.ErrorEmbed(e.Locale.GetString("error_argument_null", "id")) .ToEmbed().QueueToChannel(e.Channel); return(Task.CompletedTask); } if (Utils.IsAll(arg)) { if (reminders.GetAllInstances(e.Author.Id) is List <TaskInstance <string> > instances) { instances.ForEach(i => i.Cancel()); } new EmbedBuilder() .SetTitle($"⏰ {e.Locale.GetString("reminders")}") .SetColor(0.86f, 0.18f, 0.26f) .SetDescription(e.Locale.GetString("reminder_cancelled_all")) .ToEmbed().QueueToChannel(e.Channel); return(Task.CompletedTask); } else if (int.TryParse(arg.Argument, out int id)) { if (reminders.CancelReminder(e.Author.Id, id) is TaskInstance <string> i) { new EmbedBuilder() .SetTitle($"⏰ {e.Locale.GetString("reminders")}") .SetColor(0.86f, 0.18f, 0.26f) .SetDescription(e.Locale.GetString("reminder_cancelled", $"`{i.Context}`")) .ToEmbed().QueueToChannel(e.Channel); return(Task.CompletedTask); } } e.ErrorEmbed(e.Locale.GetString("error_reminder_null")) .ToEmbed().QueueToChannel(e.Channel); return(Task.CompletedTask); }
public async Task LeaderboardsAsync(EventContext e) { LeaderboardsOptions options = new LeaderboardsOptions(); Args args = new Args(e.arguments); ArgObject argument = args.Get(0); switch (argument?.Argument.ToLower() ?? "") { case "commands": case "cmds": { options.type = LeaderboardsType.COMMANDS; argument = argument?.Next(); } break; case "currency": case "mekos": case "money": case "bal": { options.type = LeaderboardsType.CURRENCY; argument = argument?.Next(); } break; case "rep": case "reputation": { options.type = LeaderboardsType.REPUTATION; argument = argument?.Next(); } break; case "pasta": case "pastas": { options.type = LeaderboardsType.PASTA; argument = argument?.Next(); } break; case "experience": case "exp": { options.type = LeaderboardsType.EXPERIENCE; argument = argument?.Next(); } break; default: { options.type = LeaderboardsType.EXPERIENCE; } break; } if (argument?.Argument.ToLower() == "local") { if (options.type != LeaderboardsType.PASTA) { options.guildId = e.Guild.Id; } argument = argument.Next(); } // Null-conditional operators do not apply on async methods. if (argument != null) { IDiscordUser user = (await argument.GetUserAsync(e.Guild)); if (user != null) { options.mentionedUserId = user.Id; argument = argument.Next(); } } if ((argument?.AsInt(0) ?? 0) != 0) { options.pageNumber = argument.AsInt(); argument = argument?.Next(); } await ShowLeaderboardsAsync(e.message, options); }
public async Task GiveReputationAsync(EventContext e) { using (var context = new MikiContext()) { User giver = await context.Users.FindAsync(e.Author.Id.ToDbLong()); var repObject = Global.RedisClient.Get <ReputationObject>($"user:{giver.Id}:rep"); if (repObject == null) { repObject = new ReputationObject() { LastReputationGiven = DateTime.Now, ReputationPointsLeft = 3 }; await Global.RedisClient.AddAsync($"user:{giver.Id}:rep", repObject, new DateTimeOffset(DateTime.UtcNow.AddDays(1).Date)); } ArgObject arg = e.Arguments.FirstOrDefault(); if (arg == null) { TimeSpan pointReset = (DateTime.Now.AddDays(1).Date - DateTime.Now); new EmbedBuilder() { Title = (e.GetResource("miki_module_accounts_rep_header")), Description = (e.GetResource("miki_module_accounts_rep_description")) }.AddInlineField(e.GetResource("miki_module_accounts_rep_total_received"), giver.Reputation.ToString()) .AddInlineField(e.GetResource("miki_module_accounts_rep_reset"), pointReset.ToTimeString(e.Channel.Id)) .AddInlineField(e.GetResource("miki_module_accounts_rep_remaining"), repObject.ReputationPointsLeft) .ToEmbed().QueueToChannel(e.Channel); return; } else { Dictionary <IDiscordUser, int> usersMentioned = new Dictionary <IDiscordUser, int>(); 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); int amount = 1; if (u == null) { break; } arg = arg?.Next(); if ((arg?.AsInt() ?? -1) != -1) { amount = 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.GetResource("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.GetResource("miki_module_accounts_rep_header")); embed.Description = (e.GetResource("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.AddAsync($"user:{giver.Id}:rep", repObject, new DateTimeOffset(DateTime.UtcNow.AddDays(1).Date)); embed.AddInlineField(e.GetResource("miki_module_accounts_rep_points_left"), repObject.ReputationPointsLeft) .ToEmbed().QueueToChannel(e.Channel); await context.SaveChangesAsync(); } } }
public async Task LeaderboardsAsync(EventContext e) { LeaderboardsOptions options = new LeaderboardsOptions(); ArgObject argument = e.Arguments.FirstOrDefault(); switch (argument?.Argument.ToLower() ?? "") { case "commands": case "cmds": { options.type = LeaderboardsType.COMMANDS; argument = argument?.Next(); } break; case "currency": case "mekos": case "money": case "bal": { options.type = LeaderboardsType.CURRENCY; argument = argument?.Next(); } break; case "rep": case "reputation": { options.type = LeaderboardsType.REPUTATION; argument = argument?.Next(); } break; case "pasta": case "pastas": { options.type = LeaderboardsType.PASTA; argument = argument?.Next(); } break; case "experience": case "exp": { options.type = LeaderboardsType.EXPERIENCE; argument = argument?.Next(); } break; case "guild": case "guilds": { options.type = LeaderboardsType.GUILDS; argument = argument?.Next(); } break; default: { options.type = LeaderboardsType.EXPERIENCE; } break; } if (argument?.Argument.ToLower() == "local") { if (options.type != LeaderboardsType.PASTA) { options.guildId = e.Guild.Id; } argument = argument.Next(); } if (argument != null) { IDiscordUser user = await argument.GetUserAsync(e.Guild); if (user != null) { options.mentionedUserId = user.Id; argument = argument.Next(); } } if ((argument?.AsInt() ?? 0) != 0) { options.pageNumber = argument.AsInt().Value - 1; argument = argument?.Next(); } using (var context = new MikiContext()) { int p = Math.Max(options.pageNumber - 1, 0); LeaderboardsObject obj = await Global.MikiApi.GetPagedLeaderboardsAsync(options); Utils.RenderLeaderboards(Utils.Embed, obj.items, obj.currentPage * 10) .SetFooter(Locale.GetString(e.Channel.Id, "page_index", obj.currentPage + 1, Math.Ceiling((double)obj.totalItems / 10)), "") .SetAuthor( "Leaderboards: " + options.type + " (click me!)", null, Global.MikiApi.BuildLeaderboardsUrl(options) ) .ToEmbed().QueueToChannel(e.Channel); } }
public async Task LeaderboardsAsync(EventContext e) { LeaderboardsOptions options = new LeaderboardsOptions(); ArgObject argument = e.Arguments.FirstOrDefault(); switch (argument?.Argument.ToLower() ?? "") { case "commands": case "cmds": { options.Type = LeaderboardsType.COMMANDS; argument = argument?.Next(); } break; case "currency": case "mekos": case "money": case "bal": { options.Type = LeaderboardsType.CURRENCY; argument = argument?.Next(); } break; case "rep": case "reputation": { options.Type = LeaderboardsType.REPUTATION; argument = argument?.Next(); } break; case "pasta": case "pastas": { options.Type = LeaderboardsType.PASTA; argument = argument?.Next(); } break; case "experience": case "exp": { options.Type = LeaderboardsType.EXPERIENCE; argument = argument?.Next(); } break; case "guild": case "guilds": { options.Type = LeaderboardsType.GUILDS; argument = argument?.Next(); } break; default: { options.Type = LeaderboardsType.EXPERIENCE; } break; } if (argument?.Argument.ToLower() == "local") { if (options.Type != LeaderboardsType.PASTA) { options.GuildId = e.Guild.Id; } argument = argument.Next(); } if ((argument?.TakeInt() ?? 0) != 0) { options.Offset = Math.Max(0, argument.TakeInt().Value - 1) * 12; argument = argument?.Next(); } options.Amount = 12; using (var context = new MikiContext()) { int p = Math.Max(options.Offset - 1, 0); using (var api = new MikiApi(Global.Config.MikiApiBaseUrl, Global.Config.MikiApiKey)) { LeaderboardsObject obj = await api.GetPagedLeaderboardsAsync(options); Utils.RenderLeaderboards(new EmbedBuilder(), obj.items, obj.currentPage * 12) .SetFooter( e.Locale.GetString("page_index", obj.currentPage + 1, Math.Ceiling((double)obj.totalPages / 10)), "" ) .SetAuthor( "Leaderboards: " + options.Type + " (click me!)", null, api.BuildLeaderboardsUrl(options) ) .ToEmbed() .QueueToChannel(e.Channel); } } }
public async Task SetCommandAsync(EventContext e) { ArgObject arg = e.Arguments.FirstOrDefault(); if (arg == null) { return; } string commandId = arg.Argument; Event command = e.EventSystem.GetCommandHandler <SimpleCommandHandler>().Commands .FirstOrDefault(x => x.Name == commandId); if (command == null) { e.ErrorEmbed($"{commandId} is not a valid command") .ToEmbed().QueueToChannel(e.Channel); return; } if (!command.CanBeDisabled) { e.ErrorEmbed(e.Locale.GetString("miki_admin_cannot_disable", $"`{commandId}`")) .ToEmbed().QueueToChannel(e.Channel); return; } arg = arg.Next(); if (arg == null) { return; } bool setValue = arg.Argument == "1" || arg.Argument.ToLower().StartsWith("y"); string localeState = (setValue) ? e.Locale.GetString("miki_generic_enabled") : e.Locale.GetString("miki_generic_disabled"); arg = arg?.Next(); bool global = false; using (var context = new MikiContext()) { if (arg?.Argument == "-g") { global = true; var channels = await e.Guild.GetChannelsAsync(); foreach (var c in channels) { await command.SetEnabled(context, Global.RedisClient, c.Id, setValue); } } else { await command.SetEnabled(context, Global.RedisClient, e.Channel.Id, setValue); } await context.SaveChangesAsync(); } string outputDesc = localeState + " " + commandId; if (global) { outputDesc += " in every channel."; } else { outputDesc += "."; } Utils.SuccessEmbed(e, outputDesc) .QueueToChannel(e.Channel); }
public async Task <int?> ValidateBetAsync(EventContext e, ArgObject arg, int maxBet = 1000000) { if (arg != null) { const int noAskLimit = 10000; using (MikiContext context = new MikiContext()) { User user = await context.Users.FindAsync(e.Author.Id.ToDbLong()); if (user == null) { // TODO: add user null error return(null); } string checkArg = arg?.Argument; if (int.TryParse(checkArg, out int bet)) { } else if (checkArg.ToLower() == "all" || checkArg == "*") { bet = user.Currency > maxBet ? maxBet : user.Currency; } else { e.ErrorEmbed(e.GetResource("miki_error_gambling_parse_error")) .ToEmbed().QueueToChannel(e.Channel); return(null); } if (bet < 1) { e.ErrorEmbed(e.GetResource("miki_error_gambling_zero_or_less")) .ToEmbed().QueueToChannel(e.Channel); return(null); } else if (bet > user.Currency) { e.ErrorEmbed(e.GetResource("miki_mekos_insufficient")) .ToEmbed().QueueToChannel(e.Channel); return(null); } else if (bet > maxBet) { e.ErrorEmbed($"you cannot bet more than {maxBet} mekos!") .ToEmbed().QueueToChannel(e.Channel); return(null); } else if (bet > noAskLimit) { arg = arg?.Next(); if (arg?.Argument.ToLower() == "ok") { return(bet); } else { EmbedBuilder embed = Utils.Embed; embed.Description = $"Are you sure you want to bet **{bet}**? You currently have `{user.Currency}` mekos.\n\nAppend your command with `>my_command ... <bet> ok` to confirm."; embed.Color = new Color(0.4f, 0.6f, 1f); embed.ToEmbed().QueueToChannel(e.Channel); return(null); } } else { return(bet); } } } else { e.ErrorEmbed(e.GetResource("miki_error_gambling_no_arg")) .ToEmbed().QueueToChannel(e.Channel); return(null); } }
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) { switch (arg.Argument) { case "expneeded": { arg = arg.Next(); if (arg != null) { if (int.TryParse(arg.Argument, out int value)) { g.MinimalExperienceToGetRewards = value; new EmbedBuilder() .SetTitle(e.Locale.GetString("miki_terms_config")) .SetDescription(e.Locale.GetString("guildconfig_expneeded", value)) .ToEmbed().QueueToChannel(e.Channel); } } } break; case "visible": { arg = arg.Next(); if (arg != null) { bool?result = arg.TakeBoolean(); if (!result.HasValue) { return; } string resourceString = result.Value ? "guildconfig_visibility_true" : "guildconfig_visibility_false"; new EmbedBuilder() .SetTitle(e.Locale.GetString("miki_terms_config")) .SetDescription(resourceString) .ToEmbed().QueueToChannel(e.Channel); } } break; } await context.SaveChangesAsync(); } else { new EmbedBuilder() { Title = e.Locale.GetString("guild_settings"), Description = e.Locale.GetString("miki_command_description_guildconfig") }.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 .WithTitle(e.GetResource("miki_terms_config")) .WithDescription(e.GetResource("guildconfig_expneeded", value)) .Build().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 .WithTitle(e.GetResource("miki_terms_config")) .WithDescription(resourceString) .Build().QueueToChannel(e.Channel); } } break; } await context.SaveChangesAsync(); } }
public async Task DoSafe(EventContext e) { ILinkable s = null; ArgObject arg = e.Arguments.FirstOrDefault(); if (arg != null) { string useArg = arg.Argument; if (useArg.ToLower().StartsWith("use")) { arg = arg.Next(); switch (useArg.Split(':')[1].ToLower()) { case "safebooru": { s = await ImageboardProviderPool.GetProvider <SafebooruPost>().GetPostAsync(arg?.TakeUntilEnd().Argument, ImageboardRating.SAFE); } break; case "gelbooru": { s = await ImageboardProviderPool.GetProvider <GelbooruPost>().GetPostAsync(arg?.TakeUntilEnd().Argument, ImageboardRating.SAFE); } break; case "konachan": { s = await ImageboardProviderPool.GetProvider <KonachanPost>().GetPostAsync(arg?.TakeUntilEnd().Argument, ImageboardRating.SAFE); } break; case "e621": { s = await ImageboardProviderPool.GetProvider <E621Post>().GetPostAsync(arg?.TakeUntilEnd().Argument, ImageboardRating.SAFE); } break; default: { e.Channel.QueueMessageAsync("I do not support this image host :("); } break; } } else { s = await ImageboardProviderPool.GetProvider <SafebooruPost>().GetPostAsync(e.Arguments.Join()?.Argument ?? "", ImageboardRating.SAFE); } } else { s = await ImageboardProviderPool.GetProvider <SafebooruPost>().GetPostAsync(e.Arguments.Join()?.Argument ?? "", ImageboardRating.SAFE); } if (s == null) { e.ErrorEmbed("We couldn't find an image with these tags!").Build().QueueToChannel(e.Channel); return; } e.Channel.QueueMessageAsync(s.Url); }
//[Command(Name = "reportpasta")] //public async Task ReportPastaAsync(EventContext e) //{ // ArgObject arg = e.Arguments.FirstOrDefault(); // if(arg == null) // { // // TODO: error message // return; // } // string pastaId = arg.Argument; // arg = arg.Next(); // string reason = arg?.TakeUntilEnd()?.Argument ?? ""; // if(string.IsNullOrEmpty(reason)) // { // // TODO: reason empty error // return; // } // Utils.SuccessEmbed(e.Channel.Id, "Your report has been received!").QueueToChannel(e.Channel); // Utils.Embed.SetAuthor(e.Author.Username, e.Author.GetAvatarUrl(), "") // .SetDescription($"Reported pasta `{pastaId}`.```{reason}```") // .SetColor(255, 0 , 0) // .SetFooter(DateTime.Now.ToString(), "") // .ToEmbed().QueueToChannel(Bot.Instance.Client.GetChannel(PastaReportsChannelId) as IMessageChannel); //} public async Task FavouritePastaList(EventContext e, bool lovedPastas = true) { IDiscordUser targetUser = e.Author; float totalPerPage = 25f; int page = 0; ArgObject arg = e.Arguments.FirstOrDefault(); if (arg == null) { // TODO: error no user found return; } IDiscordUser user = await arg.GetUserAsync(e.Guild); if (user != null) { arg = arg.Next(); } else { user = e.Author; } page = arg.AsInt() ?? 0; using (MikiContext context = new MikiContext()) { long authorId = targetUser.Id.ToDbLong(); IEnumerable <PastaVote> pastaVotes = context.Votes.Where(x => x.UserId == authorId && x.PositiveVote == lovedPastas); int maxPage = (int)Math.Floor(pastaVotes.Count() / totalPerPage); page = page > maxPage ? maxPage : page; page = page < 0 ? 0 : page; if (pastaVotes.Count() <= 0) { string loveString = (lovedPastas ? e.GetResource("miki_module_pasta_loved") : e.GetResource("miki_module_pasta_hated")); string errorString = e.GetResource("miki_module_pasta_favlist_self_none", loveString); if (e.message.MentionedUserIds.Count() >= 1) { errorString = e.GetResource("miki_module_pasta_favlist_mention_none", loveString); } Utils.ErrorEmbed(e, errorString).ToEmbed().QueueToChannel(e.Channel); return; } EmbedBuilder embed = Utils.Embed; List <PastaVote> neededPastas = pastaVotes.Skip((int)totalPerPage * page).Take((int)totalPerPage).ToList(); string resultString = string.Join(" ", neededPastas.Select(x => $"`{x.Id}`")); string useName = string.IsNullOrEmpty(targetUser.Username) ? targetUser.Username : targetUser.Username; embed.SetTitle($"{(lovedPastas ? e.GetResource("miki_module_pasta_loved_header") : e.GetResource("miki_module_pasta_hated_header"))} - {useName}"); embed.SetDescription(resultString); embed.SetFooter(e.GetResource("page_index", page + 1, Math.Ceiling(pastaVotes.Count() / totalPerPage)), ""); embed.ToEmbed().QueueToChannel(e.Channel); } }
public async Task LotteryAsync(EventContext e) { ArgObject arg = e.Arguments.FirstOrDefault(); if (arg == null) { long totalTickets = await Global.RedisClient.Database.ListLengthAsync(lotteryKey); long yourTickets = 0; string latestWinner = Global.RedisClient.Database.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.Channel.Id, 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) .AddInlineField("Drawing In", timeLeft) .AddInlineField("Total Tickets", totalTickets) .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 User.GetAsync(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.Database.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(); Utils.SuccessEmbed(e.Channel.Id, $"Successfully bought {amount} tickets!") .QueueToChannel(e.Channel); } } break; } }
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.GetResource("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 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(); Utils.SuccessEmbed(e.Channel.Id, "Background purchased!") .QueueToChannel(e.Channel); } else { throw new BackgroundOwnedException(); } } } } else { embed.ToEmbed() .QueueToChannel(e.Channel); } } }
public async Task KickAsync(EventContext e) { IDiscordGuildUser currentUser = await e.Guild.GetSelfAsync(); ArgObject arg = e.Arguments.FirstOrDefault(); if ((await(e.Channel as IDiscordGuildChannel).GetPermissionsAsync(currentUser)).HasFlag(GuildPermission.KickMembers)) { IDiscordGuildUser bannedUser = null; bannedUser = await arg?.GetUserAsync(e.Guild) ?? null; if (bannedUser == null) { e.ErrorEmbed(e.GetResource("ban_error_user_null")) .ToEmbed().QueueToChannel(e.Channel); return; } if ((bannedUser as IDiscordGuildUser).Hierarchy >= (e.Author as IDiscordGuildUser).Hierarchy) { e.ErrorEmbed(e.GetResource("permission_error_low", "kick")).ToEmbed() .QueueToChannel(e.Channel); return; } if ((bannedUser as IDiscordGuildUser).Hierarchy >= (currentUser as IDiscordGuildUser).Hierarchy) { e.ErrorEmbed(e.GetResource("permission_error_low", "kick")).ToEmbed() .QueueToChannel(e.Channel); return; } string reason = ""; if (!arg.IsLast) { arg = arg.Next(); reason = arg.TakeUntilEnd().Argument; } EmbedBuilder embed = new EmbedBuilder(); embed.Title = e.GetResource("miki_module_admin_kick_header"); embed.Description = e.GetResource("miki_module_admin_kick_description", new object[] { e.Guild.Name }); if (!string.IsNullOrWhiteSpace(reason)) { embed.AddField(e.GetResource("miki_module_admin_kick_reason"), reason, true); } embed.AddField(e.GetResource("miki_module_admin_kick_by"), e.Author.Username + "#" + e.Author.Discriminator, true); embed.Color = new Color(1, 1, 0); await embed.ToEmbed().SendToUser(bannedUser); await bannedUser.KickAsync(reason); } else { e.ErrorEmbed(e.GetResource("permission_needed_error", $"`{e.GetResource("permission_kick_members")}`")) .ToEmbed().QueueToChannel(e.Channel); } }