Advertisement
Imgoodisher

randphrase

Jun 18th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. require "luacom"
  2.  
  3. local skype = assert(luacom.CreateObject("Skype4COM.Skype"), "Failed to create skype object")
  4. local chats = {}
  5.  
  6. for i,v in luacom.pairs(skype.ActiveChats) do
  7.     table.insert(chats, skype:Chat(v.Name))
  8. end
  9.  
  10. table.insert(chats, {FriendlyName="Testing", SendMessage=function(self, msg) print(msg) end})
  11.  
  12. print("Chats:")
  13.  
  14. for i,v in pairs(chats) do
  15.     print(i..": "..v.FriendlyName)
  16. end
  17.  
  18. io.write("chat #> ")
  19. local chat = chats[tonumber(io.read())]
  20. print("Chose "..chat.FriendlyName)
  21.  
  22.  
  23.  
  24. local syntax = {
  25.     ["start"] = {
  26.         "have you ever !v",
  27.         "have you ever been arrested for !ving"
  28.     },
  29.     ["v"] = {
  30.         "decided to !vpres",
  31.         "met !name",
  32.         "went though !con",
  33.         "found !n !con",
  34.         "lost !n !con",
  35.         "buffaloed !n !con",
  36.         "ate !n !con",
  37.     },
  38.     ["vpres"] = {
  39.         "open !n !con",
  40.         "explode !con",
  41.         "buffalo !n !con",
  42.         "eat !n !con",
  43.     },
  44.     ["ving"] = {
  45.         "running !con",
  46.         "flying !con",
  47.         "stealing !n !con",
  48.         "buffaloing !n !con"
  49.     },
  50.     ["n"] = {
  51.         "a key to !n",
  52.         "a different universe",
  53.         "a door",
  54.         "some monster",
  55.         "balloons",
  56.         "buffalos",
  57.         "buffalo buffalos",
  58.         "elephants",
  59.         "flamingos",
  60.         "crackers",
  61.         "computers",
  62.     },
  63.     ["con"] = {
  64.         "while !n !v",
  65.         "then !n !v",
  66.         "but then !n !v",
  67.         "and then !n !v",
  68.         "until !n !v",
  69.         "so !n !v",
  70.     },
  71.     ["name"] = {
  72.         "a guy named bob",
  73.         "jesus",
  74.         "jegus",
  75.     }
  76. }
  77.  
  78. function randphrase()
  79.     local function rbuild(str)
  80.         if math.random(1, 10) == 1 and str:find("!con$") then
  81.             return str:gsub("!([^%s]+)", "")
  82.         else
  83.             return str:gsub("!([^%s]+)",
  84.                 function(m)
  85.                     return rbuild(syntax[m][math.random(#syntax[m])]) .. " "
  86.                 end
  87.             )
  88.         end
  89.     end
  90.     return rbuild("!start"):gsub("%s+", " ")
  91. end
  92.  
  93. math.randomseed(os.time())
  94. while true do
  95.     io.read()
  96.     local phrase = randphrase()
  97.     print(phrase)
  98.     chat:SendMessage(phrase)
  99. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement