Advertisement
osmarks

GChat 5000

Feb 18th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. if not process.info "chatbox" then process.spawn(chatbox.run, "chatbox") end
  2.  
  3. local messages = {
  4.     "Ah, %s. I have been expecting you.",
  5.     "Welcome back!",
  6.     "Hi.",
  7.     "Hello!",
  8.     "Hey %s!",
  9.     "Hi %s.",
  10.     "WELCOME" .. ("!"):rep(10),
  11.     "Good morning!",
  12.     "Good evening, %s.",
  13.     "Beneficent salutations.",
  14.     "Good morrow, good %s."
  15. }
  16.  
  17. local data = persistence "gchat"
  18. data.players = data.players or {}
  19.  
  20. local function set_optin(player, thing, yesno)
  21.     if not data.players[player] then data.players[player] = {} end
  22.     local playerdata = data.players[player]
  23.     if not playerdata.optin then playerdata.optin = {} end
  24.     playerdata.optin[thing] = yesno
  25.     chatbox.tell(player, ("Optin status for %s: %s"):format(thing, tostring(yesno)))
  26.     data:save()
  27. end
  28.  
  29. local function get_optin(player, thing)
  30.     return data.players[player] and data.players[player].optin and data.players[player].optin[thing]
  31. end
  32.  
  33. while true do
  34.     local event, player, command, arguments = os.pullEvent ()
  35.     if event == "join" and get_optin(player, "hi") then
  36.         local x = messages[math.random(1, #messages)]
  37.         if type(x) == "string" then x = x:format(player)
  38.         elseif type(x) == "function" then x = x(player, messages) end
  39.         print(player, x)
  40.         sleep(1)
  41.         chatbox.tell(player, x)
  42.     elseif event == "command" then
  43.         print(player, command, textutils.serialise(arguments))
  44.         if command == "hi" then
  45.             local sub = arguments[1]
  46.             if sub == "optin" then
  47.                 set_optin(player, "hi", true)
  48.             elseif sub == "optout" then
  49.                 set_optin(player, "hi", false)
  50.             else
  51.                 chatbox.tell(player, "Command not found.")
  52.             end
  53.         end
  54.     end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement