public async Task UpdateStatus(Giveaway giveaway) { MongoGiveaway mongoGiveaway = GetMongoGiveaway(giveaway.ExternalId); UpdateDefinition <Giveaway> update = Builders <Giveaway> .Update .Set(s => s.Url, giveaway.Url) .Set(s => s.Sent, true); try { await mongoGiveaway.collection.UpdateOneAsync(mongoGiveaway.filter, update); } catch (Exception e) { throw new MongoStoreException($"Fatal error happened when updating data to mongodb {giveaway.ExternalId}", e); } }
public OperationResultVo GenerateNew(Guid currentUserId) { try { Giveaway model = giveawayDomainService.GenerateNewGiveaway(currentUserId); GiveawayViewModel newVm = mapper.Map <GiveawayViewModel>(model); SetImagesToShow(newVm, true); return(new OperationResultVo <GiveawayViewModel>(newVm)); } catch (Exception ex) { return(new OperationResultVo(ex.Message)); } }
///<inheritdoc cref="IDatabaseEngine.UpdateOrCreateGiveaway(Giveaway, ulong)"/> public Giveaway UpdateOrCreateGiveaway(Giveaway giveaway, ulong guildId) { Core.Logger.LogGenericMessage($"[Mongo] UPDATE GIVEAWAY {giveaway.Id} FOR {guildId}"); var _userDb = GetDatabaseFromGuildId(guildId); var _collection = _userDb.GetCollection <Giveaway>("giveaways"); if (_collection.Find(new BsonDocument()).ToList().Any(g => g.Id == giveaway.Id)) { _collection.FindOneAndReplace(g => g.Id == giveaway.Id, giveaway); } else { _collection.InsertOne(giveaway); } return(giveaway); }
internal void StartingGiveaway(Giveaway giveaway) { if (giveaway.Type == 1 || giveaway.Type == 2) { hashtags.Add(giveaway.Hashtag, giveaway); if (giveaway.AnnounceStart) { client.SendMessage(client.JoinedChannels[0].Channel, giveaway.StartMessage); } } else { if (giveaway.AnnounceStart) { client.SendMessage(client.JoinedChannels[0].Channel, giveaway.StartMessage); } } }
public OperationResultVo <Guid> SaveGiveaway(Guid currentUserId, GiveawayViewModel vm) { int pointsEarned = 0; try { Giveaway model; Giveaway existing = giveawayDomainService.GetById(vm.Id); if (existing != null) { model = mapper.Map(vm, existing); } else { model = mapper.Map <Giveaway>(vm); } FormatImagesToSave(model); if (vm.Id == Guid.Empty) { giveawayDomainService.Add(model); vm.Id = model.Id; pointsEarned += gamificationDomainService.ProcessAction(currentUserId, PlatformAction.GiveawayAdd); } else { giveawayDomainService.Update(model); } unitOfWork.Commit(); vm.Id = model.Id; return(new OperationResultVo <Guid>(model.Id, pointsEarned)); } catch (Exception ex) { return(new OperationResultVo <Guid>(ex.Message)); } }
public OperationResultVo GetGiveawayForManagement(Guid currentUserId, Guid giveawayId) { try { Giveaway existing = giveawayDomainService.GetById(giveawayId); GiveawayViewModel vm = mapper.Map <GiveawayViewModel>(existing); SetAuthorDetails(vm); SetViewModelState(currentUserId, vm); SetImagesToShow(vm, false); return(new OperationResultVo <GiveawayViewModel>(vm)); } catch (Exception ex) { return(new OperationResultVo(ex.Message)); } }
public override void Run(CommandContext context) { if (context.ArgumentsAsList.Count > 0 && (context.ChatMessage.IsModerator || context.ChatMessage.IsBroadcaster)) { switch (context.ArgumentsAsList[0]) { case "start": { if (giveaway == null) { giveaway = new ViewerGiveaway(); giveaway.Start(); context.SendMessage("Starting a giveaway! Type \"!giveaway\" to enter!"); } } break; case "end": { context.SendMessage($"Giveaway ended! The lucky winner is... @{giveaway.End()}!"); giveaway = null; } break; default: context.SendMessage($"\"{context.ArgumentsAsString}\" is not a valid argument for the command \"{context.CommandText}\"."); break; } } else { if (giveaway != null) { giveaway.AddName(context.ChatMessage.DisplayName); } } }
public async Task <List <Giveaway> > ParseFeed(string resource) { try { var feedHtml = await _feedProvider.GetFeedHtml(resource); var feedParser = new FeedParser(); var feedItemsHtml = feedParser.GetItems(feedHtml); var feedItemsList = new List <Giveaway>(); foreach (var feedItemHtml in feedItemsHtml) { string feedItemUrl = feedParser.GetItemLink(feedItemHtml); HtmlDocument innerHtml = await _feedProvider.GetFeedHtml(feedItemUrl); //html decode var feedItem = new Giveaway { ExternalId = feedParser.GetItemId(feedItemHtml), Url = feedItemUrl, Sent = false, PhotoUrl = feedParser.GetItemPhotoUrl(feedItemHtml), Store = feedParser.GetItemStore(feedItemHtml), Title = feedParser.GetItemTitle(feedItemHtml), DirectUrl = feedParser.GetItemDirectUrl(innerHtml) }; feedItemsList.Add(feedItem); } return(feedItemsList); } catch (Exception e) { throw new FeedParsingException("failed to parse html", e); } }
private void StartGiveaway(object sender, RoutedEventArgs e) { if (MainWindow.bot != null && MainWindow.bot.isConnected) { if (((Button)sender).Content.Equals("Stop")) { var row = dataGridGiveaways.ItemContainerGenerator.ContainerFromItem(((FrameworkElement)sender).DataContext) as DataGridRow; row.Background = new SolidColorBrush(Colors.Transparent); Giveaway obj = ((FrameworkElement)sender).DataContext as Giveaway; obj.GiveawayStop(); } else { var row = dataGridGiveaways.ItemContainerGenerator.ContainerFromItem(((FrameworkElement)sender).DataContext) as DataGridRow; row.Background = new SolidColorBrush(Colors.Green); Giveaway obj = ((FrameworkElement)sender).DataContext as Giveaway; obj.GiveawayStart(); } } else { MessageBox.Show("Error: Bot is not connected!", "Bot not connected", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Giveaway_OpenButton_Click(object sender, EventArgs e) { Giveaway.Open(); }
private void Giveaway_RerollButton_Click(object sender, EventArgs e) { Giveaway.Roll(false); }
private void Giveaway_Settings_Changed(object sender, EventArgs e) { Control ctrl = (Control)sender; if (ctrl == Giveaway_UnbanButton) { int iOldIndex = Giveaway_BanListListBox.SelectedIndex; Giveaway_BanListListBox.Items.RemoveAt(iOldIndex); Giveaway_UnbanButton.Enabled = false; if (Giveaway_BanListListBox.Items.Count > 0) { Giveaway_BanListListBox.SelectedIndex = iOldIndex > Giveaway_BanListListBox.Items.Count - 1 ? Giveaway_BanListListBox.Items.Count - 1 : iOldIndex; } Giveaway.UserListHandler(null); } else if (ctrl == Giveaway_BanButton) { Giveaway_BanListListBox.Items.Add(Giveaway_AddBanTextBox.Text.ToLower()); Giveaway_AddBanTextBox.Text = ""; Giveaway.UserListHandler(null); } else if (ctrl == Giveaway_MinCurrency) { Giveaway_MinCurrencyBox.Enabled = Giveaway_MinCurrency.Checked; } else if (ctrl == Giveaway_TypeActive) { Giveaway_ActiveUserTime.Enabled = Giveaway_TypeActive.Checked; Giveaway_AnnounceFalseEntries.Enabled = !Giveaway_TypeActive.Checked; Giveaway_WarnFalseEntries.Enabled = (Giveaway_AnnounceFalseEntries.Checked && !Giveaway_TypeActive.Checked && Channel.Moderators.Contains(Channel.Bot.ToLower())); if (Giveaway_TypeActive.Checked) { Giveaway_AnnounceFalseEntries.Checked = false; if (!Channel.Moderators.Contains(Channel.Bot.ToLower())) { Giveaway_WarnFalseEntries.Checked = false; } } } else if (ctrl == Giveaway_TypeKeyword) { Giveaway_CustomKeyword.Enabled = Giveaway_TypeKeyword.Checked; } else if (ctrl == Giveaway_TypeTickets) { if (Giveaway_TypeTickets.Checked) { Giveaway_MinCurrency.Checked = false; } Giveaway_MinCurrency.Enabled = !Giveaway_TypeTickets.Checked; Giveaway_TicketCost.Enabled = Giveaway_MaxTickets.Enabled = Giveaway_TypeTickets.Checked; } else if (ctrl == Giveaway_MustWatch) { Giveaway_MustWatchHours.Enabled = Giveaway_MustWatchMinutes.Enabled = Giveaway_MustWatch.Checked; } else if (ctrl == Giveaway_MustWatchMinutes) { if (Giveaway_MustWatchMinutes.Value == -1) { if (Giveaway_MustWatchHours.Value > 0) { Giveaway_MustWatchMinutes.Value = 59; Giveaway_MustWatchHours.Value--; } else { Giveaway_MustWatchMinutes.Value = 0; } } else if (Giveaway_MustWatchMinutes.Value == 60) { Giveaway_MustWatchMinutes.Value = 0; Giveaway_MustWatchHours.Value++; } } else if (ctrl == Giveaway_AnnounceFalseEntries) { Giveaway_WarnFalseEntries.Enabled = Giveaway_AnnounceFalseEntries.Checked; if (!Giveaway_AnnounceFalseEntries.Checked) { Giveaway_WarnFalseEntries.Checked = false; } } else if (ctrl == Giveaway_WarnFalseEntries) { Giveaway_AnnounceWarnedEntries.Enabled = Giveaway_WarnFalseEntries.Checked; if (!Giveaway_WarnFalseEntries.Checked) { Giveaway_AnnounceWarnedEntries.Checked = false; } } else if (ctrl == Giveaway_SubscribersWinMultiplier) { Giveaway_SubscribersWinMultiplierAmount.Enabled = Giveaway_SubscribersWinMultiplier.Checked; } SaveSettings(); }
public WinnerChosenEventArgs(Viewer viewer, Giveaway giveaway) { winner = viewer; this.giveaway = giveaway; }
public static void DeleteGiveaway(Giveaway giveaway, ulong guildId) => DatabaseEngine.DeleteGiveaway(giveaway, guildId);
public static Giveaway UpdateOrCreateGiveaway(Giveaway giveaway, ulong guildId) => DatabaseEngine.UpdateOrCreateGiveaway(giveaway, guildId);
public List <Command> Load() { List <Command> commands = new List <Command>(); Command giveaway = new Command("giveaway"); giveaway.Usage = "giveaway [create <description>|join <id>|close <id>|roll <id>|list]"; giveaway.ToExecute += async(context) => { if (context.Parameters.Count == 0) { await context.Message.ReplyAsync("Please choose one of the following options: `create`, `join`, `close`, `roll`, or `list`"); } else if (context.Parameters[0].ToLower().Equals("create") || context.Parameters[0].ToLower().Equals("open") || context.Parameters[0].ToLower().Equals("start")) { string desc = context.Parameters.Count > 1 ? context.ParameterString.Substring("create".Length).Trim() : string.Empty; Giveaway newGiveaway = new Giveaway(context, desc); newGiveaway = Core.CreateGiveaway(newGiveaway, context.Guild.Id); await context.Message.ReplyAsync($"New giveaway with id `{newGiveaway.Id}` created!"); } else if (context.Parameters[0].ToLower().Equals("join")) { List <Giveaway> giveaways = Core.GetGiveaways(context.Guild.Id).Where(g => g.IsActive).ToList(); if (giveaways.Count == 0) { await context.Message.ReplyAsync("No giveaways found"); } else if (giveaways.Count == 1) { Giveaway g = giveaways.First(); if (g.EnteredUsers.Contains(context.Author.Id)) { await context.Message.ReplyAsync("You're already in that giveaway"); } else { g.EnteredUsers.Add(context.Author.Id); Core.UpdateOrCreateGiveaway(g, context.Guild.Id); await context.Message.ReplyAsync($"You've joined the giveaway! Good luck!"); } } else { if (context.Parameters.Count < 2) { await context.Message.ReplyAsync("There are multiple giveaways running. Please provide an Id"); } else { Giveaway g = giveaways.Find(x => x.Id.ToLower().Equals(context.Parameters[1])); if (g == null) { await context.Message.ReplyAsync("Invalid Id"); } else if (g.EnteredUsers.Contains(context.Author.Id)) { await context.Message.ReplyAsync("You're already in that giveaway"); } else { g.EnteredUsers.Add(context.Author.Id); Core.UpdateOrCreateGiveaway(g, context.Guild.Id); await context.Message.ReplyAsync($"You've joined the giveaway! Good luck!"); } } } } else if (context.Parameters[0].ToLower().Equals("close")) { List <Giveaway> giveaways = Core.GetGiveaways(context.Guild.Id).Where(g => g.IsActive).ToList(); if (giveaways.Count == 0) { await context.Message.ReplyAsync("No giveaways found"); } else if (giveaways.Count == 1) { Giveaway g = giveaways.First(); if (g.OwnerId != context.Author.Id && giveaway.GetPermissions(context) < Command.PermissionLevels.Moderator) { await context.Message.ReplyAsync("You do not have permissions to do that."); } else { g.IsActive = false; Core.UpdateOrCreateGiveaway(g, context.Guild.Id); await context.Message.ReplyAsync($"Giveaway closed with {g.EnteredUsers.Count} participants!"); } } else { if (context.Parameters.Count < 2) { await context.Message.ReplyAsync("There are multiple giveaways running. Please provide an Id"); } else { Giveaway g = giveaways.Find(x => x.Id.ToLower().Equals(context.Parameters[1])); if (g == null) { await context.Message.ReplyAsync("Invalid Id"); } else if (g.OwnerId != context.Author.Id && giveaway.GetPermissions(context) < Command.PermissionLevels.Moderator) { await context.Message.ReplyAsync("You do not have permissions to do that."); } else { g.IsActive = false; Core.UpdateOrCreateGiveaway(g, context.Guild.Id); await context.Message.ReplyAsync($"Giveaway closed with {g.EnteredUsers.Count} participants!"); } } } } else if (context.Parameters[0].ToLower().Equals("roll")) { List <Giveaway> giveaways = Core.GetGiveaways(context.Guild.Id).Where(g => !g.IsActive).ToList(); if (giveaways.Count == 0) { await context.Message.ReplyAsync("No giveaways found. Make sure the giveaway is closed before rolling."); } else if (giveaways.Count == 1) { Giveaway g = giveaways.First(); if (g.OwnerId != context.Author.Id && giveaway.GetPermissions(context) < Command.PermissionLevels.Moderator) { await context.Message.ReplyAsync("You do not have permissions to do that."); } else { await context.Message.ReplyAsync($"<@{g.EnteredUsers.GetRandomItem()}> has won {g.Description}!"); } } else { if (context.Parameters.Count < 2) { await context.Message.ReplyAsync("There are multiple giveaways running. Please provide an Id"); } else { Giveaway g = giveaways.Find(x => x.Id.ToLower().Equals(context.Parameters[1])); if (g == null) { await context.Message.ReplyAsync("Invalid Id"); } else if (g.OwnerId != context.Author.Id && giveaway.GetPermissions(context) < Command.PermissionLevels.Moderator) { await context.Message.ReplyAsync("You do not have permissions to do that."); } else { await context.Message.ReplyAsync($"<@{g.EnteredUsers.GetRandomItem()}> has won {g.Description}!"); } } } } else if (context.Parameters[0].ToLower().Equals("delete")) { List <Giveaway> giveaways = Core.GetGiveaways(context.Guild.Id); if (giveaways.Count == 0) { await context.Message.ReplyAsync("No giveaways found"); } else { if (context.Parameters.Count < 2) { await context.Message.ReplyAsync("Please provide an Id"); } else { Giveaway g = giveaways.Find(x => x.Id.ToLower().Equals(context.Parameters[1])); if (g == null) { await context.Message.ReplyAsync("Invalid Id"); } else if (g.OwnerId != context.Author.Id && giveaway.GetPermissions(context) < Command.PermissionLevels.Moderator) { await context.Message.ReplyAsync("You do not have permissions to do that."); } else { Core.DeleteGiveaway(g, context.Guild.Id); await context.Message.ReplyAsync($"Deleted giveaway."); } } } } else if (context.Parameters[0].ToLower().Equals("list")) { List <Giveaway> giveaways = Core.GetGiveaways(context.Guild.Id); string resp = ""; if (giveaways.Any(g => g.IsActive)) { resp += "Open Giveaways:"; } foreach (Giveaway _giveaway in giveaways.Where(g => g.IsActive)) { resp += $"\n `{_giveaway.Id}`: {_giveaway.Description} (By {Core.DiscordClient.GetUser(_giveaway.OwnerId)}, {_giveaway.EnteredUsers.Count} entered)"; } if (giveaways.Any(g => !g.IsActive)) { resp += "\nClosed Giveaways:"; } foreach (Giveaway _giveaway in giveaways.Where(g => !g.IsActive)) { resp += $"\n `{_giveaway.Id}`: {_giveaway.Description} (By {Core.DiscordClient.GetUser(_giveaway.OwnerId)}, {_giveaway.EnteredUsers.Count} entered)"; } if (string.IsNullOrEmpty(resp)) { await context.Message.ReplyAsync("No running giveaways found"); } else { await context.Message.ReplyAsync(resp); } } }; commands.Add(giveaway); return(commands); }
internal void StopGiveaway(Giveaway giveaway) { hashtags.Remove(giveaway.Hashtag); }
//------------------------------------------------------------------------ async private Task <bool> EntryInsert(Giveaway giveaway) { CookieContainer cookies = new CookieContainer(); cookies.Add(Program.BaseAddress, new Cookie("PHPSESSID", Program.settings.PHPSESSID)); using (var handler = new HttpClientHandler() { CookieContainer = cookies }) using (var client = new HttpClient(handler) { BaseAddress = Program.BaseAddress }) { HttpResponseMessage result; try { result = await client.GetAsync(giveaway.Link); result.EnsureSuccessStatusCode(); } catch { MainForm.ShowLoadErrorMessage("Failed to get Token"); return(false); } string response_string = await result.Content.ReadAsStringAsync(); Regex regex = new Regex("Not Enough Points"); if (regex.Match(response_string).Success == true) { return(false); } FormUrlEncodedContent content = new FormUrlEncodedContent(new Dictionary <string, string>() { { "xsrf_token", Program.Token }, { "do", "entry_insert" }, { "code", giveaway.ID } }); try { result = await client.PostAsync("ajax.php", content); result.EnsureSuccessStatusCode(); } catch { MainForm.ShowLoadErrorMessage("Failed to entry giveaway"); return(false); } response_string = await result.Content.ReadAsStringAsync(); if (response_string.Length != 0) { JsonValue value = await Task.Run(() => JsonObject.Parse(response_string)); if (value["type"] == "success") { GamesListView.Controls.Remove(giveaways[0].Control); giveaways.RemoveAt(0); PointsLabel.Text = "Points: " + value["points"]; return(true); } } } return(false); }
private void Giveaway_CancelButton_Click(object sender, EventArgs e) { Giveaway.Cancel(); }
private void Giveaway_CloseButton_Click(object sender, EventArgs e) { Giveaway.Close(); }
public void InsertGiveaway(Giveaway giveaway) { context.Giveaways.Add(giveaway); }
private void timerTick(object sender, ElapsedEventArgs e) { Console.WriteLine("Timer tick " + UnixTimeNow()); Thread t = new Thread(() => { Api api = new Api(); // Graph if (nextMin < UnixTimeNow()) { nextMin = UnixTimeNow() + 60; this.Invoke(new Action(() => this.chart1.Series["User(s) in chat"].Points.AddXY(DateTime.Now.ToString("H:mm"), members.Count(user => user.isOnline == true)))); } // bet if (bet != null) { if (bet.nextAnnouncement < UnixTimeNow()) { bet.nextAnnouncement = UnixTimeNow() + bet.betAnnouncementWaiter; // We write an announcement this.Invoke(new Action(() => connection.Sender.PublicMessage("#" + this.channelBox.Text, "Betting is open: " + bet.name + " !bet a: " + bet.optionA + " !bet b: " + bet.optionB + ". Max. betsize is: " + bet.maxBet + ". To bet, type: !bet a <amount> or !bet b <amount>."))); bet.nextAnnouncement = UnixTimeNow() + bet.betAnnouncementWaiter; } // Is finished? if (bet.betEnd < UnixTimeNow()) { bet.acceptBets = false; this.Invoke(new Action(() => { MessageBox.Show("The bet has ended, please select a winning option", "BET ENDED", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); label34.Text = "Status: Not accepting bets."; })); } // we update the stats on the giveaway page this.Invoke(new Action(() => { currentBetLabel1.Text = "Current members in the bet: " + (bet.membersOptionA.Count() + bet.membersOptionB.Count()); currentBetLabel2.Text = "Total points in bet pool: " + (bet.membersOptionA.Sum(temp1 => temp1.Item2) + bet.membersOptionB.Sum(temp2 => temp2.Item2)); currentBetLabel3.Text = "Time left on bet: " + (bet.betEnd - UnixTimeNow()) + " seconds"; })); } // Giveaway if (giveaway != null) { if (giveaway.nextAnnouncement < UnixTimeNow()) { giveaway.nextAnnouncement = UnixTimeNow() + giveaway.timeAnnouncementWaiter; // We write an announcement this.Invoke(new Action(() => connection.Sender.PublicMessage("#" + this.channelBox.Text, "Enter the giveaway for " + giveaway.name + "! Type !" + giveaway.slug + " in chat. Total entries so far: " + giveaway.members.Count() + "."))); giveaway.nextAnnouncement = UnixTimeNow() + giveaway.timeAnnouncementWaiter; } // Is finished? if (giveaway.endTime < UnixTimeNow()) { User winner = giveaway.getWinner(); this.Invoke(new Action(() => { connection.Sender.PublicMessage("#" + winner.channel, "The winner of the giveaway is: " + winner.nick + "!"); currentGiveawayLabel4.Text = "Winner: " + winner.nick; giveawayBox.Enabled = true; currentGiveawayBox.Enabled = false; })); giveaway = null; } // we update the stats on the giveaway page this.Invoke(new Action(() => { currentGiveawayLabel1.Text = "Current members in the giveaway: " + giveaway.members.Count(); currentGiveawayLabel2.Text = "Total points used on giveaway: " + giveaway.members.Count() * giveaway.cost; currentGiveawayLabel3.Text = "Time left on giveaway: " + (giveaway.endTime - UnixTimeNow()) + " seconds"; })); } // Sync if (nextSync < UnixTimeNow()) { nextSync = UnixTimeNow() + (60 * 5); List <User> _syncMembers = api.syncUsers(api.getUsers(channelBox.Text), channelBox.Text); // update followers this.members = api.updatedFollowers(_syncMembers, channelBox.Text, 0); nextSync = UnixTimeNow() + (60 * 5); } }); t.Start(); }
private void giveawayStop_Click(object sender, EventArgs e) { giveaway = null; giveawayBox.Enabled = true; currentGiveawayBox.Enabled = false; }
private void Giveaway_StopButton_Click(object sender, EventArgs e) { Giveaway.End(); }
private static async void OnTimerTicked(object sender, ElapsedEventArgs e) { await Giveaway.Do(guild, channel); await Giveaway.RewardAllActiveUsers(guild); }
public Response Put(Giveaway request) { request.Text = request.Text.Trim(); if (string.IsNullOrWhiteSpace(request.Text)) { throw new ArgumentNullException("request", "Giveaway text is required"); } if (request.UserId != Guid.Empty) { throw new ArgumentException("Giveaway must have gifter", "request"); } Db.Save(Request.ConvertTo<Giveaway>()); if (request.Id != Guid.Empty) { Request.RemoveFromCache(base.Cache, request.Id.ToString()); } return new Response(true); }
public ViewerEnteredEventArgs(string viewer, Giveaway gw) { this.viewer = viewer; giveaway = gw; }