View difference between Paste ID: 47FtCuzr and yEThuM1N
SHOW: | | - or go back to the newest paste.
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-
    local _, player, message, uuid = os.pullEvent("chat_message")
29+
function _say(command)
30-
    if rs.getAnalogInput("left") >= 4 then
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-
    
46+
47-
    
47+
48-
    
48+
49-
    if message:find("[?!`~][Dd]ay") and canMakeDay then
49+
50
hasSaid = false
51-
        chat.say("Setting time to day...")
51+
sara = "bellezacelestial"
52-
    elseif message:find("[?!`~][Nn]ight") and canMakeNight then
52+
53
54-
        chat.say("Setting time to night...")
54+
print("Version: "..version)
55-
    elseif message:find("[?!`~][Cc]lear") and canClear then
55+
56
57-
        chat.say("Clearing the weather...")
57+
58-
    elseif message:find("[?!`~][Rr]ain") and canRain then
58+
    local _, player, message, uuid = os.pullEvent("chat_message") -- Waits for a message
59
60-
        chat.say("Makin' it rain ;)")
60+
    -- Checking what commands are available
61-
    elseif message:find("[?!`~][Rr]ain") and canRain == false then
61+
    if rs.getAnalogInput("left") >= 3 then
62-
        chat.say("If it is currently storming and you want it to rain without lightning, please set it to clear, and then try again.")
62+
63-
    elseif message:find("[?!`~][Ss]torm") and canStorm then
63+
64
    else
65-
        chat.say("Creating a storm...")
65+
66-
    elseif message:find("[?!`~][Ss]torm") and canStorm == false then
66+
67-
        chat.say("If it is currently raining and you want a storm, please set it to clear, and then run the command.")
67+
68-
    elseif message:find("[?!`~][Pp]rint_sides") then
68+
69
    if rs.getInput("back") then
70-
        id, message = rednet.receive()
70+
71-
        chat.say(message)
71+
72-
        rednet.send(id, "")
72+
73-
        id, message = rednet.receive()
73+
74-
        chat.say(message)
74+
75-
        rednet.send(id, "")
75+
76-
        id, message = rednet.receive()
76+
77-
        chat.say(message)
77+
78-
        rednet.send(id, "")
78+
79-
        id, message = rednet.receive()
79+
80-
        chat.say(message)
80+
    -- Seeing if Sara is online
81-
        rednet.send(id, "")
81+
    if message:find(prefix.."[Oo]nline") and player == sara then
82-
        id, message = rednet.receive()
82+
        chat.say("Sara is now marked online! Chat printing is enabled!")
83-
        chat.say(message)
83+
        saraIsOnline = true
84-
    elseif message:find("[?!`~][Ss]ource") then
84+
85-
        
85+
    elseif message:find(prefix.."[Oo]ffline") then
86
        saraIsOnline = false
87-
        
87+
88-
    --id, message = rednet.receive()
88+
    -- Checking for commands
89-
    --print(message)
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