carrots084

Server Startup

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