Andy73

offerGenerator

Jan 3rd, 2016
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.78 KB | None | 0 0
  1.  
  2. -- Internet Offer Generator
  3. -- Copyright 2015 - 2016 viluon (Andrew Kvapil), licensed under the MIT license (http://opensource.org/licenses/MIT)
  4. -- Version 1.2
  5.  
  6. local m_rnd = math.random
  7.  
  8. local args = { ... }
  9. local egg
  10. local path = shell.getRunningProgram()
  11.  
  12. if #args == 0 then
  13.     error( "  Usage:\n" .. path .. " [--enable-markdown] <output path>", 0 )
  14. end
  15.  
  16. local markdownEnabled = ( args[ 1 ] == "--enable-markdown" and #args == 2 )
  17. local filename = ( #args == 1 and args[ 1 ] or args[ 2 ] )
  18.  
  19. local usedNumbers = {}
  20.  
  21. local products = {
  22.     "graphics card",
  23.     "CPU",
  24.     "16 GB RAM",
  25.     "8 GB RAM",
  26.     "harddrive",
  27.     "2TB HDD",
  28.     "Tablet",
  29.     "Smartphone",
  30. }
  31.  
  32. local productModifiers = {
  33.     "top class",
  34.     "Kingston",
  35.     "nVidia",
  36.     "AMD",
  37.     "ATX",
  38.     "overclocked",
  39.     "limited edition",
  40.     "core i9",
  41.     "DDR4",
  42.     "brand new",
  43.     "flagship",
  44. }
  45.  
  46. local productFeatures = {
  47.     "4K streaming",
  48.     "full-HD streaming",
  49.     "remote connectibility",
  50.     "SSH",
  51.     "updates",
  52.     "WiFi",
  53.     "Bluetooth",
  54.     "LTE",
  55.     "Dual SIM",
  56.     "USB 3.0",
  57.     "Qualcomm Snapdragon processor",
  58.     "DolbyDigital Surround Sound",
  59.     "headphones",
  60.     "LAN",
  61.     "FireWire",
  62.     "Thunderbird",
  63.     "eSATA",
  64.     "CD-ROM",
  65.     "HDMI",
  66.     "VGA",
  67.     "OLED display",
  68.     "AMOLED display",
  69.     "Android 5.0",
  70.     "Android 5.1",
  71.     "iOS 7",
  72. }
  73.  
  74. local free = {
  75.     "*FREE*",
  76.     "one-month FREE",
  77.     "completely *free* of charge",
  78.     "**free**",
  79. }
  80.  
  81. local sales = {
  82.     "90% OFF",
  83.     "50% Off",
  84.     "75% OFF",
  85. }
  86.  
  87. local easterEggs = {
  88.     [ "squiddev" ] = "a free all-natural British octopus with C# skills.";
  89.     [ "exerro" ] = "a Lua maniac with a weird love for graphic libraries.";
  90.     [ "oeed" ] = "an Australian developer with his MacBook.";
  91.     [ "creator" ] = "a terrible childish ComputerCrafter who'll instantly ruin your life.";
  92.     [ "bombbloke" ] = "a geeky guy who loves GIFs and is also capable of porting your Minecraft worlds and packaging stuff.";
  93.     [ "bomb bloke" ] = "a geeky guy who loves GIFs and is also capable of porting your Minecraft worlds and packaging stuff.";
  94.     [ "demhydraz" ] = "a Brazilian FOSS and Linux geek who likes to destructively criticize everything he is highly opinionated about (i.e. everything) but is quite a good friend.";
  95.     [ "viluon" ] = "an evil genius, a mad scientist with programming skills at such a pro level that he caused the default level number data type \
  96. of the Universe to overflow, setting it to negative values, and is therefore misregarded as a total asshole \
  97. (who else would be capable of creating something like this program?). \
  98. Really now, I am @viluon, nice to meet you. Most people say I am crazy. I am. That's about it. I like being friends with cool and smart people, so don't you ever talk to me.";
  99.  
  100.     [ "" ] = "";
  101. }
  102.  
  103. local catchPhrases = {
  104.     "Order yours today",
  105.     "Order yours right now",
  106.     "Claim this prize",
  107.     "Don't hesitate and get yours",
  108. }
  109.  
  110. local waysToOrder = {
  111.     "calling 800-11-BESTBUY",
  112.     "visiting the website www.100-percent-legit.com",
  113.     "calling 911-I-WANT-ONE",
  114.     "checking in on our FREE web www.all-free.com",
  115. }
  116.  
  117. local callForTwoPack = {
  118.     "Call 911 and introduce yourself as Antonio Murdrio to get a *second one* for FREE.",
  119.     "Email us your credit card number, photo and other personally identifying information to [email protected] and get a second one _Free of Charge_.",
  120. }
  121.  
  122. local callForSpecial = {
  123.     "Call 200-100-000 within 1 hour and get a %PRODUCT% for free!",
  124.     "Visit www.best-store-ever.com in the following 5 minutes to receive a **FREE** %PRODUCT% with your order.",
  125.     "Call 1234-GIMME-FREE-STUFF right now to order a %PRODUCT% absolutely *free of charge*.",
  126.     "Order a %PRODUCT% as well and you will get a 40% extra sale on your order.",
  127. }
  128.  
  129. local offerModifiers = {
  130.     "Premium",
  131.     "VIP",
  132.     "Secret",
  133.     "Limited",
  134.     "One-time",
  135. }
  136.  
  137. local authors = {
  138.     "Google",
  139.     "Apple",
  140.     "Samsung",
  141.     "Lenovo",
  142.     "Acer",
  143.     "Asus",
  144. }
  145.  
  146. if not markdownEnabled and #args == 2 then
  147.     if easterEggs[ args[ 1 ]:lower() ] then
  148.         egg = easterEggs[ args[ 1 ]:lower() ]
  149.     end
  150. end
  151.  
  152. local function rnd( ... )
  153.     local run, res = true
  154.  
  155.     while run do
  156.         res = m_rnd( ... )
  157.  
  158.         run = false
  159.  
  160.         for i = 1, #usedNumbers do
  161.             if usedNumbers[ i ] == res then
  162.                 run = true
  163.             end
  164.         end
  165.     end
  166.  
  167.     usedNumbers[ #usedNumbers + 1 ] = res
  168.  
  169.     return res
  170. end
  171.  
  172. local function resetRnd()
  173.     usedNumbers = {}
  174. end
  175.  
  176. local function generateProduct( markdown )
  177.     local result = ""
  178.    
  179.     local limit = rnd( 1, 4 )
  180.     resetRnd()
  181.     for i = 1, limit do
  182.         result = result .. productModifiers[ rnd( 1, #productModifiers ) ] .. " "
  183.     end
  184.     resetRnd()
  185.  
  186.     result = result .. products[ rnd( 1, #products ) ] .. " with "
  187.     resetRnd()
  188.  
  189.     local limit = rnd( 1, 5 )
  190.     resetRnd()
  191.     for i = 1, limit do
  192.         result = result .. ( markdown and "\n  - " or "" ) .. ( m_rnd() > 0.8 and free[ m_rnd( 1, #free ) ] .. " " or ""  ) .. productFeatures[ rnd( 1, #productFeatures ) ] .. ( markdown and "" or ( i == limit - 1 and " and " or ( i == limit and "" or ", " ) ) )
  193.     end
  194.     resetRnd()
  195.  
  196.     return result
  197. end
  198.  
  199. local function generateOffer( markdown )
  200.     local result = ""
  201.  
  202.     result = result ..
  203.         offerModifiers[ m_rnd( 1, #offerModifiers ) ] ..
  204.         " Offer " ..
  205.         ( m_rnd() > 0.5 and "by " or "from " ) ..
  206.         authors[ m_rnd( 1, #authors ) ] ..
  207.         ":\n"
  208.  
  209.     --TODO: Fix the limits here
  210.     --local limit = math.max( math.floor( math.sqrt( m_rnd( 1, 1000 ) ) / 8 ), 1 )
  211.  
  212.     local limit = m_rnd( 1, 4 )
  213.     if limit == 2 then
  214.         result = result .. "Dual pack of "
  215.     elseif limit > 9 then
  216.         result = result .. "GIGApack (" .. limit .. "!!!) of "
  217.     elseif limit > 2 then
  218.         result = result .. "Multipack (" .. limit .. "!) of "
  219.     end
  220.  
  221.     for i = 1, limit do
  222.         result = result .. ( markdown and "\n- " or "" ) .. generateProduct( markdown ) .. ( markdown and "" or ( i == limit - 1 and " and " or ( i == limit and "" or ", " ) ) )
  223.     end
  224.  
  225.     if m_rnd() > 0.6 then
  226.         result = result .. "\n\n" .. "Now up to " .. sales[ m_rnd( 1, #sales ) ] .. "!"
  227.     end
  228.  
  229.     if m_rnd() > 0.6 then
  230.         result = result .. "\n\n" .. catchPhrases[ m_rnd( 1, #catchPhrases ) ] .. " by " .. waysToOrder[ m_rnd( 1, #waysToOrder ) ] .. "."
  231.     end
  232.  
  233.     if m_rnd() > 0.6 then
  234.         result = result .. "\n\n" .. callForSpecial[ m_rnd( 1, #callForSpecial ) ]:gsub( "%%PRODUCT%%", generateProduct() )
  235.     end
  236.  
  237.     if m_rnd() > 0.6 then
  238.         result = result .. "\n\n" .. callForTwoPack[ m_rnd( 1, #callForTwoPack ) ]
  239.     end
  240.  
  241.     if egg then
  242.         result = result .. "\n\n" .. ( egg == easterEggs.viluon and "Includes " .. egg or ( m_rnd() > 0.5 and "Includes " .. egg or egg:sub( 1, 1 ):upper() .. egg:sub( 2, -2 ) .. " included." ) )
  243.     end
  244.  
  245.     return result
  246. end
  247.  
  248. term.setTextColour( colours.lightGrey )
  249.  
  250. local offer = generateOffer( markdownEnabled )
  251.  
  252. print( offer )
  253.  
  254. local f, err = fs.open( filename, "w" )
  255. if not f then
  256.     error( "Failed to open file ('" .. tostring( filename ) .. "') for writing: " .. tostring( err ), 0 )
  257. end
  258.  
  259. f.write( offer )
  260. f.close()
Advertisement
Add Comment
Please, Sign In to add comment