public async Task UserBalance(SocketGuildUser user = null) { var handler = new UserAccounts(); if (user is null) { if (handler.GetUserAccount(Context.User.Id) is null) { return; } await Context.Channel.SendMessageAsync("", false, Utilities.SendEmbedMessage($"◆ Your balance is: ${handler.GetUserAccount(Context.User.Id).Balance}", Utilities.Colors.Green)); } else { if (handler.GetUserAccount(user.Id) is null) { return; } await Context.Channel.SendMessageAsync("", false, Utilities.SendEmbedMessage($"◆ **{user.Username}'s** balance: ${handler.GetUserAccount(user.Id).Balance}", Utilities.Colors.Green)); Console.WriteLine(handler.GetUserAccount(user.Id).Balance); } }
public async Task ScratchoffCasino() { var handler = new UserAccounts(); if (handler.GetUserAccount(Context.User.Id).Balance < 100) { await Context.Channel.SendMessageAsync("", false, Utilities.SendEmbedMessage("◆ You can't afford purchasing a scratch off ticket.", Utilities.Colors.Red)); return; } handler.TakeUserAccountBalance(Context.User.Id, 100); var result = GetResult(); var embed = new EmbedBuilder() { Color = new Color(255, 255, 255), Author = new EmbedAuthorBuilder() { IconUrl = Context.User.GetAvatarUrl(), Name = Context.User.ToString() }, Title = result.IsWin ? $"You bought a scratch off ticket and won ${result.Amount}!" : "You bought a scratch off ticket and lost. Better luck next time!", ImageUrl = result.Url, }; if (result.Amount > 0) { handler.AddUserAccountBalance(Context.User.Id, result.Amount); } await Context.Channel.SendMessageAsync("", false, embed.Build()); }
public async Task UsingItem(int index, IGuildUser taggedUser = null, int optional = 0) { if (!GlobalVar.CanUseItem) { return; } if (UserAccounts.CheckHaveThisDebuff(UserAccounts.GetUserAccount(Context.User), "Panic")) { await Context.Channel.SendMessageAsync($"Cant use item in panic {Context.User.Mention}"); return; } if (UserAccounts.IsDead(Context.User)) { return; } if (!IsHavingThisRole((SocketGuildUser)Context.User, "Survivor")) { return; } GlobalVar.GuildSelect = Context.Guild; GlobalVar.ChannelSelect = (SocketTextChannel)Context.Channel; if (taggedUser != null) { var target = UserAccounts.GetUserAccount((SocketUser)taggedUser); await Inventories.UseActiveItem(Context.User, index, target, optional); } else { await Inventories.UseActiveItem(Context.User, index, null, optional); } }
public async Task Answering([Remainder] string answer) { if (!GlobalVar.QuizHasBeenStarted) { return; } if (!IsHavingThisRole((SocketGuildUser)Context.User, "Survivor")) { return; } if (UserAccounts.IsDead(Context.User)) { return; } UserAccount user = UserAccounts.GetUserAccount(Context.User); ulong id = GlobalVar.Selected.ID; int point = Quizzes.CheckAnswer(answer, id); if (point == 0) { return; } await Context.Channel.SendMessageAsync($"{Context.User.Mention} {point} point(s)"); UserAccounts.TempPoints(user, point); }
public async Task PayUser(SocketGuildUser user, double amount) { var handler = new UserAccounts(); if (handler.GetUserAccount(Context.User.Id) is null || handler.GetUserAccount(user.Id) is null || handler.GetUserAccount(Context.User.Id).Balance < amount || amount < 1) { await Context.Channel.SendMessageAsync("", false, Utilities.SendEmbedMessage("◆ Could not pay this user.", Utilities.Colors.Red)); return; } handler.TakeUserAccountBalance(Context.User.Id, amount); handler.AddUserAccountBalance(user.Id, amount); await Context.Channel.SendMessageAsync("", false, Utilities.SendEmbedMessage($"◆ You paid **{user.Username}** ${amount}.", Utilities.Colors.Green)); }
public async Task Stats() { var user = Context.User; var account = UserAccounts.GetUserAccount(user); embed = new EmbedBuilder(); embed.WithTitle(user.Username + "'s Profile"); embed.WithColor(0, 0, 255); embed.WithThumbnailUrl(user.GetAvatarUrl()); embed.AddInlineField("HP : ", account.HP); embed.AddInlineField("Points : ", account.Points); embed.AddInlineField("Kills : ", account.Kills); int lenght = account.Inventory.Items.Count; int temp = 0; embed.AddField("Inventory : ", "Items List(1-3) : "); for (int i = 0; i < lenght; i++) { if (account.Inventory.Items[i].Countdown != -1) { embed.AddInlineField($"Items-{i + 1} : ", account.Inventory.Items[i].Name + $" ({account.Inventory.Items[i].Countdown})"); } else { embed.AddInlineField($"Items-{i+1} : ", account.Inventory.Items[i].Name); } temp++; } for (int i = temp; i < 3; i++) { embed.AddInlineField($"Items-{i+1} : ", "---"); } lenght = account.Buffs.Count; temp = 0; for (int i = 0; i < lenght; i++) { embed.AddInlineField($"Buffs-{i + 1} : ", account.Buffs[i].Name + $" ({account.Buffs[i].Countdown})"); temp++; } for (int i = temp; i < 3; i++) { embed.AddInlineField($"Buffs-{i + 1} : ", "---"); } lenght = account.Debuffs.Count; temp = 0; for (int i = 0; i < lenght; i++) { embed.AddInlineField($"Debuffs-{i + 1} : ", account.Debuffs[i].Name + $" ({account.Debuffs[i].Countdown})"); temp++; } for (int i = temp; i < 3; i++) { embed.AddInlineField($"Debuffs-{i + 1} : ", "---"); } await Context.Channel.SendMessageAsync("", embed : embed); }
public async Task RegisterUser() { var handler = new UserAccounts(); if (handler.GetUserAccount(Context.User.Id) is null) { handler.AddUserAccount(Context.User.Id, 1000); await Context.Channel.SendMessageAsync($"Successfully registered with the ID `{Context.User.Id}`."); } else { await Context.Channel.SendMessageAsync("You are already registered."); } }
public async Task Status(SocketGuildUser user = null) { // check if user was specified if (user == null) { // if not initialize it with command sender user user = Context.User as SocketGuildUser; } // get server and user account informations Guild guild = Guilds.GetGuild(Context.Guild.Id); UserAccount userAccount = UserAccounts.GetUserAccount(user.Id, guild.UserAccounts, guild.Categories); // create embed EmbedBuilder embed = new EmbedBuilder { ThumbnailUrl = user.GetAvatarUrl(), Title = $"{user.Username}'s status:", Color = new Color(255, 255, 0) }; // create embed fields with points List <EmbedFieldBuilder> fields = new List <EmbedFieldBuilder>() { //global points new EmbedFieldBuilder() { IsInline = false, Name = "Points: ", Value = UserAccounts.CalculateTotalPointsOfUser(userAccount) } }; // foreach category for (int i = 0; i < guild.Categories.Count; i++) { // add category points fields.Add(new EmbedFieldBuilder() { IsInline = false, Name = guild.Categories[i].Name, Value = $"{100*(double)userAccount.CategoryComplition[i]/(double)guild.Categories[i].Questions.Count}%" }); } embed.Fields = fields; // send message to user await Context.Channel.SendMessageAsync("", false, embed.Build()); }
public async Task Heal(IGuildUser guildUser = null) { UserAccount me = new UserAccount(); if (guildUser != null) { me = UserAccounts.GetUserAccount((SocketUser)guildUser); } else { me = UserAccounts.GetUserAccount(Context.User); } UserAccounts.IncreasingHealth(me, 15); await Context.Channel.SendMessageAsync("YOU HAVE BEEN HEALED"); }
public async Task GetQuestion(int id = -100) { // question which will be fetch from server database Question question = null; // if question was already seen bool wasSeen = false; // Get server informations Guild guild = Guilds.GetGuild(Context.Guild.Id); // Get user account UserAccount userAccount = UserAccounts.GetUserAccount(Context.User.Id, guild.UserAccounts, guild.Categories); // check if question id is valid if (id >= 0) { // check if user already seen this question if (userAccount.SeenQuestionsIds.Contains(id)) { wasSeen = true; } // get question with id from database question = Questions.GetQuestion(id, guild.Categories); } else { Random random = new Random(DateTime.Now.Millisecond); List <Question> allQuestions = new List <Question>(); // Get maximum question id foreach (Category category in guild.Categories) { allQuestions.AddRange(category.Questions); // and all questions as well } // get all unseen questions IEnumerable <Question> unseenQuestions = from q in allQuestions where !userAccount.SeenQuestionsIds.Contains(q.Id) select q; int unseenQuestionsCount = unseenQuestions.ToList().Count; // if list of unseen questions is empty if (unseenQuestionsCount == 0) { // send random question wasSeen = true; question = allQuestions.ElementAt(random.Next(0, allQuestions.Count)); } else { // send unseen question question = unseenQuestions.ElementAt(random.Next(0, unseenQuestionsCount)); } id = question.Id; } // Create embed for message with question EmbedBuilder embedBuild = new EmbedBuilder { Title = $"Pytanie #{question.Id}", Description = question.Description }; // add possible answers for (int i = 0; i < question.PossibleAnswers.Count; i++) { embedBuild.AddField(Util.AnswersEmojis.ToList()[i].Name, question.PossibleAnswers[i], true); } // add image if (question.ImageURL != null) { embedBuild.ImageUrl = question.ImageURL; } // build embed Embed embed = embedBuild.Build(); // ReactionCallbackData(message content, embed, expires after first use, if command should react to only one answer from 1 user, // command timeout, what to do if command expires) ReactionCallbackData reactionData = new ReactionCallbackData("", embed, true, true, TimeSpan.FromSeconds(120), (c) => Timeout(c.Channel)); // Iterate all possible answers and add answer placeholder for (int i = 0; i < question.PossibleAnswers.Count; i++) { // check if this iteration answer is right if (i == question.RightAnswer) { // Add answer placecholder with information what if user select this answer // reactionData.WithCallback(answer emoji, what to do if user select answer) // CheckScore(if question was seen, is this good answer, question id, question category, user account, source channel) reactionData.WithCallback(Util.AnswersEmojis.ToList()[i], (c, r) => CheckScore(wasSeen, true, id, GetCategoryContainingQuestionId(id, guild.Categories), userAccount, c.Channel)); } else { reactionData.WithCallback(Util.AnswersEmojis.ToList()[i], (c, r) => CheckScore(wasSeen, false, id, GetCategoryContainingQuestionId(id, guild.Categories), userAccount, c.Channel)); } } // Send quiz message and await user selection await InlineReactionReplyAsync(reactionData, true); }
public async Task ShowAllSurvivors() { if (!IsHavingThisRole((SocketGuildUser)Context.User, "Developer") && !IsHavingThisRole((SocketGuildUser)Context.User, "Quiz Manager")) { return; } var users = Context.Guild.Users; EmbedBuilder embed = new EmbedBuilder(); string text = ""; foreach (var u in users) { if (IsHavingThisRole(u, "Survivor")) { var user = UserAccounts.GetUserAccount((SocketUser)u); text += $"{u.Username}\nHP : {user.HP}\n" + $"POINT : {user.Points}\nKILL : {user.Kills}\n"; //item text += "Inventory : \n"; int num = 0; for (int i = 0; i < user.Inventory.Items.Count; i++) { text += $"Item-{i + 1}: {user.Inventory.Items[i].Name}"; if (user.Inventory.Items[i].Countdown != -1) { text += $" ({user.Inventory.Items[i].Countdown})"; } text += "\n"; num++; } for (int i = num; i < 3; i++) { text += $"Item-{i + 1}: ---\n"; } //buff text += "Buffs : \n"; num = 0; for (int i = 0; i < user.Buffs.Count; i++) { text += $"Buff-{i + 1}: {user.Buffs[i].Name} ({user.Buffs[i].Countdown})\n"; num++; } for (int i = num; i < 3; i++) { text += $"Buff-{i + 1}: ---\n"; } //debuff text += "Debuffs : \n"; num = 0; for (int i = 0; i < user.Debuffs.Count; i++) { text += $"Debuff-{i + 1}: {user.Debuffs[i].Name} ({user.Debuffs[i].Countdown})\n"; num++; } for (int i = num; i < 3; i++) { text += $"Debuff-{i + 1}: ---\n"; } text += "\n\n"; } if ((text.Length + 300) > 2048) { embed.WithDescription(text); await Context.Channel.SendMessageAsync("", embed : embed); text = ""; } } embed.WithDescription(text); await Context.Channel.SendMessageAsync("", embed : embed); }
public async Task Balance(SocketGuildUser user = null) { var handler = new UserAccounts(); if (user is null) { await Context.Channel.SendMessageAsync($"Your balance is: ${Convert.ToDecimal(handler.GetUserAccount(Context.User.Id).Balance).ToString("#,##0.00")}"); } else { await Context.Channel.SendMessageAsync($"Balance of **{user.Username}:** ${Convert.ToDecimal(handler.GetUserAccount(user.Id).Balance).ToString("#,##0.00")}"); } }