Exemple #1
0
        private static async void OnMarketingMessage(SteamUser.MarketingMessageCallback callback)
        {
            if (!callback.Messages.Any())
            {
                return;
            }

            using (var db = await Database.GetConnectionAsync())
            {
                var items       = (await db.QueryAsync <RSS.GenericFeedItem>("SELECT `Link` FROM `RSS` WHERE `Link` IN @Ids", new { Ids = callback.Messages.Select(x => x.URL) })).ToDictionary(x => x.Link, x => (byte)1);
                var newMessages = callback.Messages.Where(item => !items.ContainsKey(item.URL));

                foreach (var message in newMessages)
                {
                    Log.WriteInfo("Marketing", $"{message.ID} {message.URL} ({message.Flags})");

                    if (message.Flags == EMarketingMessageFlags.None)
                    {
                        IRC.Instance.SendMain($"New marketing message:{Colors.DARKBLUE} {message.URL}");
                    }
                    else
                    {
                        IRC.Instance.SendMain($"New marketing message:{Colors.DARKBLUE} {message.URL} {Colors.DARKGRAY}({message.Flags.ToString().Replace("Platform", string.Empty)})");
                    }

                    await db.ExecuteAsync("INSERT INTO `RSS` (`Link`, `Title`) VALUES(@URL, @Title)", new { message.URL, Title = $"Marketing #{message.ID}" });
                }
            }
        }
        public static void OnMarketingMessage(SteamUser.MarketingMessageCallback callback)
        {
            foreach (var message in callback.Messages)
            {
                // TODO: Move this query outside this loop
                using (MySqlDataReader Reader = DbWorker.ExecuteReader("SELECT `ID` FROM `MarketingMessages` WHERE `ID` = @ID", new MySqlParameter("ID", message.ID)))
                {
                    if (Reader.Read())
                    {
                        continue;
                    }
                }

                if (message.Flags == EMarketingMessageFlags.None)
                {
                    IRC.SendMain("New marketing message:{0} {1}", Colors.DARK_BLUE, message.URL);
                }
                else
                {
                    IRC.SendMain("New marketing message:{0} {1} {2}({3})", Colors.DARK_BLUE, message.URL, Colors.DARK_GRAY, message.Flags.ToString().Replace("Platform", string.Empty));
                }

                DbWorker.ExecuteNonQuery("INSERT INTO `MarketingMessages` (`ID`, `Flags`) VALUES (@ID, @Flags)",
                                         new MySqlParameter("@ID", message.ID),
                                         new MySqlParameter("@Flags", message.Flags)
                                         );
            }
        }