carrots084

Server [Creative Chat Recorder]

Feb 7th, 2018
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.59 KB | None | 0 0
  1. -- TODO add prefix modification via command
  2.  
  3.  
  4. -- Written by: Sara Mae (bellezacelestial)
  5. -- Discord: @1000#0001
  6. -- If The username has not been found, you can reach her in the MMD Public Server at https://discord.gg/BurN6C3
  7.  
  8.  
  9. -- FUNCTIONS
  10. for a, b in pairs(rs.getSides()) do
  11.     if peripheral.getType(b) == "manipulator" then
  12.         chat = peripheral.wrap(b)
  13.         break
  14.     end
  15. end
  16.  
  17. for a, b in pairs(rs.getSides()) do
  18.     if peripheral.getType(b) == "modem" then
  19.         rednet.open(b)
  20.         break
  21.     end
  22. end
  23.  
  24. function _help()
  25.     _say("The list of prefixes is wrapped in square brackets: "..prefix)
  26.     _say("The commands are: day, night, clear, rain, storm, update, and printsides")
  27. end
  28.  
  29.  
  30. function send(command)
  31.     rednet.send(client, command)
  32.     return "Command Sent: \""..command.."\""
  33. end
  34.  
  35. -- VARIABLES
  36. version = "0.2.7"
  37. saraIsOnline = false
  38. prefix = "[?!`~]"
  39. client = 75
  40. day = "SET_TO_DAY"
  41. night = "SET_TO_NIGHT"
  42. clear = "SET_TO_CLEAR"
  43. rain = "SET_TO_RAIN"
  44. storm = "SET_TO_STORM"
  45. hasSaid = false
  46. sara = "bellezacelestial"
  47.  
  48.  
  49. print("Version: "..version)
  50. while true do
  51.    
  52.     function _say(command)
  53.        -- if saraIsOnline then
  54.             chat.say("[Sara's Weather & Time Bot]: "..command)
  55.        -- end
  56.        -- This is just out of laziness, from when I had to check if I was online
  57.     end
  58.  
  59.     local _, player, message, uuid = os.pullEvent("chat_message") -- Waits for a message
  60.  
  61.     -- Checking what commands are available
  62.     if rs.getAnalogInput("left") >= 3 then
  63.         canMakeDay = true
  64.         canMakeNight = false
  65.     else
  66.         canMakeNight = true
  67.         canMakeDay = false
  68.     end
  69.  
  70.     if rs.getInput("back") then
  71.         canClear = true
  72.         canRain = false
  73.         canStorm = false
  74.     else
  75.         canClear = false
  76.         canRain = true
  77.         canStorm = true
  78.     end
  79.  
  80.  
  81.     -- Seeing if Sara is online
  82.     if message:find(prefix.."[Oo]nline") and player == sara then
  83.         chat.say("Sara is now marked online! Chat printing is enabled!")
  84.         saraIsOnline = true
  85.  
  86.     elseif message:find(prefix.."[Oo]ffline") then
  87.         saraIsOnline = false
  88.  
  89.     -- Checking for commands
  90.     elseif message:find(prefix.."[Dd]ay") and canMakeDay then
  91.         print(send(day))
  92.         _say("Setting time to day...")
  93.  
  94.     elseif message:find(prefix.."[Nn]ight") and canMakeNight then
  95.         print(send(night))
  96.         _say("Setting time to night...")
  97.  
  98.     elseif message:find(prefix.."[Cc]lear") and canClear then
  99.         print(send(clear))
  100.         _say("Clearing the weather...")
  101.  
  102.     elseif message:find(prefix.."[Rr]ain") and canRain then
  103.         print(send(rain))
  104.         _say("Makin' it rain ;)")
  105.  
  106.     elseif message:find(prefix.."[Rr]ain") and canRain == false then
  107.         _say("If it is currently storming and you want it to rain without lightning, please set it to clear, and then try again.")
  108.  
  109.     elseif message:find(prefix.."[Ss]torm") and canStorm then
  110.         print(send(storm))
  111.         _say("Creating a storm...")
  112.  
  113.     elseif message:find(prefix.."[Ss]torm") and canStorm == false then
  114.         _say("If it is currently raining and you want a storm, please set it to clear, and then run the command.")
  115.  
  116.     elseif message:find(prefix.."[Pp]rint_sides") and player == sara then
  117.         print(send("PRINT_SIDES"))
  118.         -- TODO add the printing
  119.  
  120.     elseif message:find(prefix.."[Ss]ource") then
  121.         _say("You can find the source for the server program here: https://pastebin.com/edit/e3YpAR0j")
  122.         _say("You can find the source for the client program here: https://pastebin.com/V3dNaWvw")
  123.         --chat.say("You can find the instructions here: ")
  124.  
  125.     elseif message:find(prefix.."[Uu]pdate") and player == sara then
  126.         _say("Rebooting now!")
  127.         os.reboot()
  128.  
  129.     elseif message:find(prefix.."[Pp]layer[Ii]nfo") then
  130.         print("Username: "..player)
  131.         _say("Username: "..player)
  132.  
  133.     elseif message:find(prefix.."[Hh]elp") then
  134.         _help()
  135.  
  136.     elseif message:find(prefix.."[Uu]pdate") and player == not sara then
  137.         _say("You do not have permissions. Please contact Sara (bellezacelestial) for permissions.")
  138.  
  139.     elseif message:find(prefix.."[Pp]rintsides") and player == not sara then
  140.         _say("You do not have permissions. Please contact Sara (bellezacelestial) for permissions.")
  141.  
  142.     elseif message:find(prefix.."[Ii]s[Oo]nline") then
  143.         _say("saraIsOnline = "..tostring(saraIsOnline))
  144.  
  145.     --AUTOMATIC COMMANDS
  146.     elseif message:find(prefix.."[Aa]uto[Dd]ay") then
  147.         _say("Will automatically set to day, at nightfall.")
  148.         repeat
  149.             os.pullEvent("redstone")
  150.             if rs.getAnalogInput("left") >= 3 and hasSaid == false then
  151.                 rednet.send(client, "SET_TO_DAY")
  152.                 _say("Automatically setting to day. Type the commmand \"autoStop\" with your preferred prefix to stop.")
  153.                 hasSaid = true
  154.             end
  155.             if rs.getInput("right") then
  156.                 _say("Stopping the automatic time change!")
  157.             end
  158.         until rs.getInput("right")
  159.  
  160.     elseif message:find(prefix.."[Aa]uto[Nn]ight") then
  161.         _say("Will automatically set to night, at sunrise.")
  162.         repeat
  163.             os.pullEvent("redstone")
  164.             if rs.getAnalogInput("left") <= 3  and hasSaid == false then
  165.                 rednet.send(client, "SET_TO_DAY")
  166.                 _say("Automatically setting to night. Type the commmand \"autoStop\" with your preferred prefix to stop.")
  167.                 hasSaid = true
  168.             end
  169.             if rs.getInput("right") then
  170.                 _say("Stopping the automatic time change!")
  171.             end
  172.         until rs.getInput("right")
  173.     end
  174. end
Advertisement
Add Comment
Please, Sign In to add comment