public async Task RaffleAsync([Remainder] string raffleDetails) { var userID = Convert.ToUInt64(raffleDetails.Split(';').FirstOrDefault().Trim(' ', '<', '>', '@')); var raffleName = raffleDetails.Split(';')[1].Trim(' '); var userToAdd = Context.Guild.Users.Where(user => user.Id == userID).FirstOrDefault(); var noofTickets = Int32.Parse(raffleDetails.Split(';').LastOrDefault().Trim(' ')); var raffleFilepath = raffleHelpers.GetRaffleFilepath(raffleName); EmbedBuilder embedBuilder = new EmbedBuilder(); if (!File.Exists(raffleFilepath)) { embedBuilder .WithTitle(Properties.Resources.TitleUhOh) .WithDescription($"{raffleName} does not exist!") .WithColor(Color.Red); await ReplyAsync("", false, embedBuilder); return; } var raffle = raffleHelpers.GetRaffle(raffleName); if (raffle.endDate > DateTime.MinValue) { embedBuilder .WithColor(Color.Red) .WithTitle(Properties.Resources.TitleHmm) .WithDescription($"{raffle.name} has ended on {raffle.endDate} UTC") .AddInlineField("Winner", userHelpers.GetUserName(userHelpers.GetDiscordUser(raffleHelpers.GetRaffleWinner(raffle).discordID, Context))) .AddInlineField("Reward", $"{raffle.reward}"); await ReplyAsync("", false, embedBuilder); return; } if (raffle.participants.Any(participant => participant.discordID == userToAdd.Id)) { embedBuilder .WithTitle(Properties.Resources.TitleHmm) .WithDescription($"{userHelpers.GetUserName(userToAdd)} is already participating!") .WithColor(Color.Red); await ReplyAsync("", false, embedBuilder); return; } var newParticipant = userToAdd.ToRaffleParticipant(); raffle.participants.Add(newParticipant); raffleHelpers.CreateUpdateRaffle(raffle); embedBuilder .WithTitle(Properties.Resources.TitleYay) .WithDescription($"{userHelpers.GetUserName(userToAdd)} has been added to {raffle.name}!") .WithColor(Color.Green); await ReplyAsync("", false, embedBuilder); }
public async Task RaffleAsync([Remainder] string raffleName) { var raffle = raffleHelpers.GetRaffle(raffleName); EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder .WithColor(Color.Gold) .AddField("Name", raffle.name) .AddField("Reward", raffle.reward) .AddField("Creator", userHelpers.GetUserName(userHelpers.GetDiscordUser(raffle.creator.discordID, Context))) .AddField("Participants #", raffle.participants.Count) .AddInlineField("Start", raffle.startDate) .AddInlineField("Planned End", raffle.endDate); if (raffle.endDate > DateTime.MinValue) { embedBuilder .AddField("Winner", userHelpers.GetUserName(userHelpers.GetDiscordUser(raffleHelpers.GetRaffleWinner(raffle).discordID, Context))) .AddField("Ended", raffle.endDate); } await ReplyAsync("", false, embedBuilder); embedBuilder = new EmbedBuilder(); embedBuilder .WithColor(Color.Gold) .WithTitle("Participants"); foreach (var participant in raffle.participants) { embedBuilder .AddField("Name", userHelpers.GetUserName(userHelpers.GetDiscordUser(participant.discordID, Context))) .AddInlineField("Added", participant.dateAdded) .AddInlineField("Tickets #", participant.noofTickets); } await ReplyAsync("", false, embedBuilder); }
public async Task RaffleAsync([Remainder] string raffleName) { var raffle = raffleHelpers.GetRaffle(raffleName); EmbedBuilder embedBuilder = new EmbedBuilder(); if (raffle.endDate > DateTime.MinValue && raffle.endDate < DateTime.UtcNow) { embedBuilder .WithColor(Color.Red) .WithTitle(Properties.Resources.TitleHmm) .WithDescription($"{raffle.name} has ended on {raffle.endDate} UTC") .AddInlineField("Winner", userHelpers.GetUserName(userHelpers.GetDiscordUser(raffleHelpers.GetRaffleWinner(raffle).discordID, Context))) .AddInlineField("Reward", $"{raffle.reward}"); await ReplyAsync("", false, embedBuilder); return; } raffle.endDate = DateTime.UtcNow; double winChance = 0; var winner = raffleHelpers.DetermineWinner(raffle, out winChance); var winnerDiscord = userHelpers.GetDiscordUser(winner.discordID, Context); raffleHelpers.CreateUpdateRaffle(raffle); embedBuilder .WithColor(Color.Green) .WithTitle($"Congratulations {userHelpers.GetUserName(winnerDiscord)}! :tada:") .WithDescription($"{winnerDiscord.Mention} has won the {raffle.name} raffle!") .AddField("Reward", $"{raffle.reward}") .AddField("Win %", winChance); await ReplyAsync("", false, embedBuilder); }