mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 05:33:00 +00:00 
			
		
		
		
	Add date-specific MOTDs (like Minecraft) (#533)
This commit is contained in:
		| @@ -1,15 +1,24 @@ | |||||||
| local tMotd = {} | local date = os.date("*t") | ||||||
|  | if date.month == 1 and date.day == 1 then | ||||||
|  |     print("Happy new year!") | ||||||
|  | elseif date.month == 12 and date.day == 24 then | ||||||
|  |     print("Merry X-mas!") | ||||||
|  | elseif date.month == 10 and date.day == 31 then | ||||||
|  |     print("OOoooOOOoooo! Spooky!") | ||||||
|  | else | ||||||
|  |     local tMotd = {} | ||||||
|  |  | ||||||
| for sPath in string.gmatch(settings.get("motd.path"), "[^:]+") do |     for sPath in string.gmatch(settings.get("motd.path"), "[^:]+") do | ||||||
|     if fs.exists(sPath) then |         if fs.exists(sPath) then | ||||||
|         for sLine in io.lines(sPath) do |             for sLine in io.lines(sPath) do | ||||||
|             table.insert(tMotd, sLine) |                 table.insert(tMotd, sLine) | ||||||
|  |             end | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| end |  | ||||||
|  |  | ||||||
| if #tMotd == 0 then |     if #tMotd == 0 then | ||||||
|     print("missingno") |         print("missingno") | ||||||
| else |     else | ||||||
|     print(tMotd[math.random(1, #tMotd)]) |         print(tMotd[math.random(1, #tMotd)]) | ||||||
|  |     end | ||||||
| end | end | ||||||
|   | |||||||
| @@ -1,14 +1,36 @@ | |||||||
| local capture = require "test_helpers".capture_program | local capture = require "test_helpers".capture_program | ||||||
|  |  | ||||||
| describe("The motd program", function() | describe("The motd program", function() | ||||||
|  |     local function setup_date(month, day) | ||||||
|  |         stub(os, "date", function() return { month = month, day = day } end) | ||||||
|  |     end | ||||||
|  |  | ||||||
|     it("displays MODT", function() |     it("displays MOTD", function() | ||||||
|         local file = fs.open("/modt_check.txt", "w") |         setup_date(0, 0) | ||||||
|  |         local file = fs.open("/motd_check.txt", "w") | ||||||
|         file.write("Hello World!") |         file.write("Hello World!") | ||||||
|         file.close() |         file.close() | ||||||
|         settings.set("motd.path", "/modt_check.txt") |         settings.set("motd.path", "/motd_check.txt") | ||||||
|  |  | ||||||
|         expect(capture(stub, "motd")) |         expect(capture(stub, "motd")) | ||||||
|             :matches { ok = true, output = "Hello World!\n", error = "" } |             :matches { ok = true, output = "Hello World!\n", error = "" } | ||||||
|     end) |     end) | ||||||
|  |  | ||||||
|  |     it("displays date-specific MOTD (1/1)", function() | ||||||
|  |         setup_date(1, 1) | ||||||
|  |         expect(capture(stub, "motd")) | ||||||
|  |             :matches { ok = true, output = "Happy new year!\n", error = "" } | ||||||
|  |     end) | ||||||
|  |  | ||||||
|  |     it("displays date-specific MOTD (10/31)", function() | ||||||
|  |         setup_date(10, 31) | ||||||
|  |         expect(capture(stub, "motd")) | ||||||
|  |             :matches { ok = true, output = "OOoooOOOoooo! Spooky!\n", error = "" } | ||||||
|  |     end) | ||||||
|  |  | ||||||
|  |     it("displays date-specific MOTD (12/24)", function() | ||||||
|  |         setup_date(12, 24) | ||||||
|  |         expect(capture(stub, "motd")) | ||||||
|  |             :matches { ok = true, output = "Merry X-mas!\n", error = "" } | ||||||
|  |     end) | ||||||
| end) | end) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 JackMacWindows
					JackMacWindows