-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshop.lua
2369 lines (2219 loc) · 74.1 KB
/
shop.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
31
Fix shop crashing when there is none of a specified item and it is selected.
SIMPLIFY Shop
made by fatmanchummy
----https://github.com/Fatboychummy-CC/Simplify-Shop/blob/master/LICENSE
]]
local version = 31
local tArgs = {...}
local params = {
"setupText",
"setupVisuals",
}
shell.setCompletionFunction(shell.getRunningProgram(),
function(shell,par,cur)
if par == 1 then
local res = {}
for i = 1,#params do
if params[i]:sub(1,#cur) == cur then
res[#res+1] = params[i]:sub(#cur+1)
end
end
return res
end
return {}
end
)
if not fs.exists("w.lua") then
shell.run("wget","https://raw.githubusercontent.com/justync7/w.lua/master/w.lua")
end
if not fs.exists("r.lua") then
shell.run("wget","https://raw.githubusercontent.com/justync7/r.lua/master/r.lua")
end
if not fs.exists("k.lua") then
shell.run("wget","https://raw.githubusercontent.com/justync7/k.lua/master/k.lua")
end
if not fs.exists("json.lua") then
shell.run("pastebin","get","4nRg9CHU","json.lua")
end
if not fs.exists("jua.lua") then
shell.run("wget","https://raw.githubusercontent.com/justync7/Jua/master/jua.lua")
end
if not fs.exists("Logger.lua") then
shell.run("wget https://raw.githubusercontent.com/Fatboychummy-CC/Simplify-Shop/master/Logger.lua Logger.lua")
end
os.unloadAPI("Logger.lua")
os.loadAPI("Logger.lua")
local logger = Logger
local w = require("w")
local r = require("r")
local k = require("k")
os.loadAPI("json.lua")
local json = _G.json
local jua = require("jua")
w.init(jua)
r.init(jua)
k.init(jua,json,w,r)
---------------------------------------------------
if logger.canLogBeOpened then
logger.openLog()
end
if logger.canPurchaseLogBeOpened then
logger.openPurchaseLog()
end
local function checkKristAddress(a)
return k.makev2address(k.toKristWalletFormat(a))
end
----------
local fatData = "fatItemData"
local fatCustomization = "fatShopCustomization"
local mon = nil
local mName = nil
local tName = nil
local items = nil
local privKey = nil
local pubKey = nil
local custom = {}
local chests = {}
local sIL = {}
local selection = false
local recentPressCount = 0
local oldY = 0
local oldNotice = "no"
local page = 1
local mxPages = 1
local mX = 0
local mY = 0
local ws
local buttons = {}
local recentPress = false
local recentNotice = false
local purchaseTimer = "nothing to see yet"
local cobCount = 0
local function chatFunc(event, ...)
if event == "chat_message" then
local player, message, uuid = ...
local tbl = {n = 0}
for word in string.gmatch(message, "%w+") do
tbl.n = tbl.n + 1
tbl[tbl.n] = word
end
return tbl
elseif event == "command" then
local user, command, args = ...
table.insert(args, 1, command)
return args
end
end
local function getFile(url, file)
local handle = http.get(url)
if handle then
local file = fs.open(file, 'w')
if file then
file.write(handle.readAll())
file.close()
else
error(string.format("Failed to open file '%s' for writing.", file))
end
else
error(string.format("Failed to connect to %s", url))
end
end
local function checkUpdates()
local didUpdate = false
local handle = http.get("https://raw.githubusercontent.com/Fatboychummy-CC/Simplify-Shop/master/shop.lua")
handle.readLine()
local v = tonumber(handle.readLine())
local notes = handle.readLine()
if v < version then
print(v,"<",version)
elseif v == version then
print(v,"=",version)
else
print(v,">",version)
end
handle.close()
if v > version then
mon.setTextScale(2)
mon.setBackgroundColor(colors.black)
mon.clear()
mon.setCursorPos(1, 1)
mon.write("Update available...")
mon.setCursorPos(1, 2)
mon.write("Waiting...")
print("There is an update available.")
print("Update notes: ")
print("--------------------------------")
print(notes)
print("--------------------------------")
print("Would you like to do the update now? (Y/N)")
local utm = os.startTimer(30)
while true do
local a = {os.pullEvent()}
if a[1] == "char" then
if a[2] == "y" then
fs.delete(shell.getRunningProgram())
getFile("https://raw.githubusercontent.com/Fatboychummy-CC/Simplify-Shop/master/shop.lua", shell.getRunningProgram())
print("Update complete.")
didUpdate = true
break
elseif a[2] == "n" then
break
end
elseif a[1] == "timer" and a[2] == utm then
break
end
end
if not didUpdate then
print("Timed out or skipping update.")
end
else
print("Up to date.")
end
if logger.isUpdate(version) then
if logger.update() then
didUpdate = true
end
else
logger.info("Logger is up to date.")
end
if didUpdate then
print("Rebooting.")
mon.setCursorPos(1, 3)
mon.write("Rebooting...")
os.sleep(2)
os.reboot()
end
mon.setTextScale(0.5)
mX,mY = mon.getSize()
mon.clear()
return v > version
end
local function fixCustomization(key)
logger.info("Attempting to fix customization file.")
local hand = "h"
local function ao(a)
hand.writeLine(a)
hand.flush()
end
local function chk(a)
return type(a) == "table"
end
local clr = {
[1] = "colors.white",
[2] = "colors.orange",
[4] = "colors.magenta",
[8] = "colors.lightBlue",
[16] = "colors.yellow",
[32] = "colors.lime",
[64] = "colors.pink",
[128] = "colors.gray",
[256] = "colors.lightGray",
[512] = "colors.cyan",
[1024] = "colors.purple",
[2048] = "colors.blue",
[4096] = "colors.brown",
[8192] = "colors.green",
[16384] = "colors.red",
[32768] = "colors.black",
}
hand = fs.open(fatCustomization,"w")
if chk(custom) then
ao("data = {")
ao(custom.owner and " owner = \""..custom.owner.."\"," or " owner = \"Nobody\",")
ao(custom.shopName and " shopName = \""..custom.shopName.."\"," or " shopName = \"Unnamed Shop\",")
ao(type(custom.drawBottomInfoBar) == "boolean" and " drawBottomInfoBar = "..tostring(custom.drawBottomInfoBar).."," or " drawBottomInfoBar = true,")
ao(type(custom.showCustomInfo) == "boolean" and " showCustomInfo = "..tostring(custom.showCustomInfo).."," or " showCustomInfo = true,")
ao(" customInfo = {")
if chk(custom.customInfo) then
ao((custom.customInfo and custom.customInfo[1]) and " [ 1 ] = \"" .. custom.customInfo[1] .. "\"," or " [ 1 ] = \"Edit customInfo variable to change me\",")
ao((custom.customInfo and custom.customInfo[2]) and " [ 2 ] = \"" .. custom.customInfo[2] .. "\"," or " [ 2 ] = \"Up to two lines are permitted\",")
else
ao(" [ 1 ] = \"Edit customInfo variable to change me\",")
ao(" [ 2 ] = \"Up to two lines are permitted\",")
end
ao(" },")
ao(type(custom.showCustomBigInfo) == "boolean" and " showCustomBigInfo = "..tostring(custom.showCustomBigInfo).."," or " showCustomBigInfo = false,")
ao(" customBigInfo = {")
if chk(custom.customBigInfo) then
ao((custom.customBigInfo and custom.customBigInfo[1]) and " [ 1 ] = \""..custom.customBigInfo[1].."\"," or " [ 1 ] = \"Edit customBigInfo variable to change me\",")
ao((custom.customBigInfo and custom.customBigInfo[2]) and " [ 2 ] = \""..custom.customBigInfo[2].."\"," or " [ 2 ] = \"the word PUBKEY will be translated\",")
ao((custom.customBigInfo and custom.customBigInfo[3]) and " [ 3 ] = \""..custom.customBigInfo[3].."\"," or " [ 3 ] = \"to your public krist address.\",")
ao((custom.customBigInfo and custom.customBigInfo[4]) and " [ 4 ] = \""..custom.customBigInfo[4].."\"," or " [ 4 ] = \"Up to four lines are permitted\",")
else
ao(" [ 1 ] = \"Edit customBigInfo variable to change me\",")
ao(" [ 2 ] = \"the word PUBKEY will be translated\",")
ao(" [ 3 ] = \"to your public krist address.\",")
ao(" [ 4 ] = \"Up to four lines are permitted\",")
end
ao(" },")
ao(type(custom.touchHereForCobbleButton) == "boolean" and " touchHereForCobbleButton = "..tostring(custom.touchHereForCobbleButton).."," or " touchHereForCobbleButton = true,")
ao(custom.dropSide and " dropSide = \""..custom.dropSide.."\", -- the side the turtle will drop from, accepts 'top', 'bottom', and 'front'" or " dropSide = \"unset\", -- the side the turtle will drop from, accepts 'top', 'bottom', and 'front'")
ao(custom.itemsDrawnAtOnce and " itemsDrawnAtOnce = "..tostring(custom.itemsDrawnAtOnce).."," or " itemsDrawnAtOnce = 7,")
ao(type(custom.useBothChestTypes) == "boolean" and " useBothChestTypes = "..tostring(custom.useBothChestTypes).."," or " useBothChestTypes = false,")
ao(type(custom.useSingleChest) == "boolean" and " useSingleChest = "..tostring(custom.useSingleChest)..", --if useBothChestTypes is true, this value does not matter. If useBothChestTypes is false, and there is a network attached, the turtle will ignore everything except the single chest." or " useSingleChest = false, --if useBothChestTypes is true, this value does not matter. If useBothChestTypes is false, and there is a network attached, the turtle will ignore everything except the single chest.")
ao(custom.chestSide and " chestSide = \""..custom.chestSide.."\",--You can use a single chest attached to a network by typing it's network name here (eg: \"minecraft:chest_666\")" or " chestSide = \"bottom\",--You can use a single chest attached to a network by typing it's network name here (eg: \"minecraft:chest_666\")")
ao(type(custom.doPurchaseForwarding) == "boolean" and " doPurchaseForwarding = "..tostring(custom.doPurchaseForwarding).."," or " doPurchaseForwarding = false," )
ao(custom.purchaseForwardingAddress and " purchaseForwardingAddress = \""..custom.purchaseForwardingAddress.."\"," or " purchaseForwardingAddress = \"fakeAddress\"," )
ao(type(custom.compactMode) == "boolean" and " compactMode = "..tostring(custom.compactMode).."," or " compactMode = false,")
ao(" farthestBackground = {")
if chk(custom.farthestBackground) then
ao(custom.farthestBackground.bg and " bg = "..clr[custom.farthestBackground.bg].."," or " bg = colors.black,")
else
ao(" bg = colors.black,")
end
ao(" },")
ao(" background = {")
if chk(custom.background) then
ao(custom.background.bg and " bg = "..clr[custom.background.bg].."," or " bg = colors.gray,")
ao(custom.background.fg and " fg = "..clr[custom.background.fg].."," or " fg = colors.white,")
else
ao(" bg = colors.gray,")
ao(" fg = colors.white,")
end
ao(" },")
ao(" nameBar = {")
if chk(custom.nameBar) then
ao(custom.nameBar.bg and " bg = "..clr[custom.nameBar.bg].."," or " bg = colors.purple,")
ao(custom.nameBar.fg and " fg = "..clr[custom.nameBar.fg].."," or " fg = colors.white,")
else
ao(" bg = colors.purple,")
ao(" fg = colors.white,")
end
ao(" },")
ao(" itemInfoBar = {")
if chk(custom.itemInfoBar) then
ao(custom.itemInfoBar.bg and " bg = "..clr[custom.itemInfoBar.bg].."," or " bg = colors.blue,")
ao(custom.itemInfoBar.fg and " fg = "..clr[custom.itemInfoBar.fg].."," or " fg = colors.white,")
else
ao(" bg = colors.blue,")
ao(" fg = colors.white,")
end
ao(" },")
ao(" infoBar = {")
if chk(custom.infoBar) then
ao(custom.infoBar.bg and " bg = "..clr[custom.infoBar.bg].."," or " bg = colors.purple,")
ao(custom.infoBar.fg and " fg = "..clr[custom.infoBar.fg].."," or " fg = colors.white,")
else
ao(" bg = colors.purple,")
ao(" fg = colors.white,")
end
ao(" },")
ao(" buttons = {")
if chk(custom.buttons) then
ao(custom.buttons.bg and " bg = "..clr[custom.buttons.bg].."," or " bg = colors.blue,")
ao(custom.buttons.fg and " fg = "..clr[custom.buttons.fg].."," or " fg = colors.white,")
else
ao(" bg = colors.blue,")
ao(" fg = colors.white,")
end
ao(" },")
ao(" disabledButtons = {")
if chk(custom.disabledButtons) then
ao(custom.disabledButtons.bg and " bg = "..clr[custom.disabledButtons.bg].."," or " bg = colors.lightGray,")
ao(custom.disabledButtons.fg and " fg = "..clr[custom.disabledButtons.fg].."," or " fg = colors.white,")
else
ao(" bg = colors.lightGray,")
ao(" fg = colors.white,")
end
ao(" },")
ao(" selection = {")
if chk(custom.selection) then
ao(custom.selection.bg and " bg = "..clr[custom.selection.bg].."," or " bg = colors.white,")
ao(custom.selection.fg and " fg = "..clr[custom.selection.fg].."," or " fg = colors.black,")
else
ao(" bg = colors.white,")
ao(" fg = colors.black,")
end
ao(" },")
ao(" bigSelection = {")
if chk(custom.bigSelection) then
ao(custom.bigSelection.bg and " bg = "..clr[custom.bigSelection.bg].."," or " bg = colors.black,")
ao(custom.bigSelection.bg and " fg = "..clr[custom.bigSelection.fg].."," or " fg = colors.white,")
else
ao(" bg = colors.black,")
ao(" fg = colors.white,")
end
ao(" },")
ao(" selectedEmptyStock = {")
if chk(custom.selectedEmptyStock) then
ao(custom.selectedEmptyStock.bg and " bg = "..clr[custom.selectedEmptyStock.bg].."," or " bg = colors.red,")
ao(custom.selectedEmptyStock.fg and " fg = "..clr[custom.selectedEmptyStock.fg].."," or " fg = colors.white,")
else
ao(" bg = colors.red,")
ao(" fg = colors.white,")
end
ao(" },")
ao(" bigSelectionEmptyStock = {")
if chk(custom.bigSelectionEmptyStock) then
ao(custom.bigSelectionEmptyStock.bg and " bg = "..clr[custom.bigSelectionEmptyStock.bg].."," or " bg = colors.red,")
ao(custom.bigSelectionEmptyStock.fg and " fg = "..clr[custom.bigSelectionEmptyStock.fg].."," or " fg = colors.white,")
else
ao(" bg = colors.red,")
ao(" fg = colors.white,")
end
ao(" },")
ao(" bigInfo = {")
if chk(custom.bigInfo) then
ao(custom.bigInfo.bg and " bg = "..clr[custom.bigInfo.bg].."," or " bg = colors.black,")
ao(custom.bigInfo.fg and " fg = "..clr[custom.bigInfo.fg].."," or " fg = colors.white,")
else
ao(" bg = colors.black,")
ao(" fg = colors.white,")
end
ao(" },")
ao(" itemTableColor1 = {")
if chk(custom.itemTableColor1) then
ao(custom.itemTableColor1.bg and " bg = "..clr[custom.itemTableColor1.bg].."," or " bg = colors.black,")
ao(custom.itemTableColor1.bg and " fg = "..clr[custom.itemTableColor1.fg].."," or " fg = colors.white,")
else
ao(" bg = colors.black,")
ao(" fg = colors.white,")
end
ao(" },")
ao(" itemTableColor2 = {")
if chk(custom.itemTableColor2) then
ao(custom.itemTableColor2.bg and " bg = "..clr[custom.itemTableColor2.bg].."," or " bg = colors.black,")
ao(custom.itemTableColor2.fg and " fg = "..clr[custom.itemTableColor2.fg].."," or " fg = colors.white,")
else
ao(" bg = colors.black,")
ao(" fg = colors.white,")
end
ao(" },")
ao(" itemTableEmptyStock1 = {")
if chk(custom.itemTableEmptyStock1) then
ao(custom.itemTableEmptyStock1.bg and " bg = "..clr[custom.itemTableEmptyStock1.bg].."," or " bg = colors.black,")
ao(custom.itemTableEmptyStock1.fg and " fg = "..clr[custom.itemTableEmptyStock1.fg].."," or " fg = colors.red,")
else
ao(" bg = colors.black,")
ao(" fg = colors.red,")
end
ao(" },")
ao(" itemTableEmptyStock2 = {")
if chk(custom.itemTableEmptyStock2) then
ao(custom.itemTableEmptyStock2.bg and " bg = "..clr[custom.itemTableEmptyStock2.bg].."," or " bg = colors.black,")
ao(custom.itemTableEmptyStock2.fg and " fg = "..clr[custom.itemTableEmptyStock2.fg].."," or " fg = colors.red,")
else
ao(" bg = colors.black,")
ao(" fg = colors.red,")
end
ao(" },")
ao(" chatty = {")
if chk(custom.chatty) then
ao(type(custom.chatty.enabled) == "boolean" and custom.chatty.enabled and " enabled = true," or " enabled = false,")
ao(custom.chatty.prefix and " prefix = \"" .. custom.chatty.prefix .. "\"," or " prefix = \"shop" .. math.random(100000, 999999) .. "\",")
ao(type(custom.chatty.showNotice) == "boolean" and custom.chatty.showNotice and " showNotice = true," or type(custom.chatty.showNotice) == "boolean" and " showNotice = false," or " showNotice = true,")
ao(" -- change the above value if you state that chatty is enabled elsewhere (like in big info or bottom info bar)")
ao(custom.chatty.noticeFG and " noticeFG = " .. custom.chatty.noticeFG .. "," or " noticeFG = colors.white,")
ao(custom.chatty.noticeFG and " noticeBG = " .. custom.chatty.noticeBG .. "," or " noticeBG = colors.black,")
ao(" -- the above are the colors of the notice that displays just above the bottom info bar.")
ao(custom.chatty.infoFG and " infoFG = " .. custom.chatty.infoFG .. "," or " infoFG = colors.white,")
ao(custom.chatty.infoBG and " infoBG = " .. custom.chatty.infoBG .. "," or " infoBG = colors.red,")
ao(" -- the above are the colors of the popup when someone chats something and chatty reacts.")
ao(custom.chatty.event and " event = \"" .. custom.chatty.event .. "\"," or " event = \"chat_message\",")
ao(" -- If on switchcraft, change the above to 'command'")
else
ao(" enabled = false,")
ao(" prefix = \"shop" .. math.random(100000, 999999) .. "\",")
ao(" showNotice = true,")
ao(" -- change the above value if you state that chatty is enabled elsewhere (like in big info or bottom info bar)")
ao(" noticeFG = colors.white,")
ao(" noticeBG = colors.black,")
ao(" -- the above are the colors of the notice that displays just above the bottom info bar.")
ao(" infoFG = colors.white,")
ao(" infoBG = colors.red,")
ao(" -- the above are the colors of the popup when someone chats something and chatty reacts.")
ao(" event = \"chat_message\",")
ao(" -- If on switchcraft, change the above to 'command'")
end
ao(" },")
ao(" REFUNDS = {")
if chk(custom.REFUNDS) then
ao(custom.REFUNDS.noItemSelected and " noItemSelected = \""..custom.REFUNDS.noItemSelected.."\"," or " noItemSelected = \"There is no item selected!\",")
ao(custom.REFUNDS.underpay and " underpay = \""..custom.REFUNDS.underpay .."\"," or " underpay = \"You seem to have underpaid.\",")
ao(custom.REFUNDS.change and " change = \""..custom.REFUNDS.change .."\"," or " change = \"You overpaid by a small amount, here's your change!\",")
ao(custom.REFUNDS.outOfStock and " outOfStock = \""..custom.REFUNDS.outOfStock .."\"," or " outOfStock = \"We do not have any stock of that item!\",")
ao(custom.REFUNDS.UPDATE and " UPDATE = \""..custom.REFUNDS.UPDATE.."\"," or " UPDATE = \"The shop is updating it's stocks and an error occured!\",")
else
ao(" noItemSelected = \"There is no item selected!\",")
ao(" underpay = \"You seem to have underpaid.\",")
ao(" change = \"You overpaid by a small amount, here's your change.\",")
ao(" outOfStock = \"We do not have any stock of that item!\",")
ao(" UPDATE = \"The shop is updating it's stocks and an error occured!\",")
end
ao(" },")
ao(" LOGGER = {")
if chk(custom.LOGGER) then
ao(type(custom.LOGGER.doNormalLogging) == "boolean" and " doNormalLogging = "..tostring(custom.LOGGER.doNormalLogging)..", --If you are getting errors, set this to true. It tends to spam files." or " doNormalLogging = false, --If you are getting errors, set this to true. It tends to spam files.")
ao(type(custom.LOGGER.doPurchaseLogging) == "boolean" and " doPurchaseLogging = "..tostring(custom.LOGGER.doPurchaseLogging).."," or " doPurchaseLogging = true,")
ao(type(custom.LOGGER.doInfoLogging) == "boolean" and " doInfoLogging = "..tostring(custom.LOGGER.doInfoLogging)..", --HIGHLY recommended to not enable this. Every time the screen redraws an info event is created." or " doInfoLogging = false, --HIGHLY recommended to not enable this. Every time the screen redraws an info event is created.")
ao(type(custom.LOGGER.doWarnLogging) == "boolean" and " doWarnLogging = "..tostring(custom.LOGGER.doWarnLogging).."," or " doWarnLogging = true,")
ao(custom.LOGGER.LOG_LOCATION and " LOG_LOCATION = \""..custom.LOGGER.LOG_LOCATION.."\"," or "\"logs/\",")
ao(custom.LOGGER.LOG_NAME and " LOG_NAME = \""..custom.LOGGER.LOG_NAME.."\"," or " LOG_NAME = \"Log\",")
ao(custom.LOGGER.PURCHASE_LOG_LOCATION and " PURCHASE_LOG_LOCATION = \""..custom.LOGGER.PURCHASE_LOG_LOCATION.."\"," or " PURCHASE_LOG_LOCATION = \"purchases/\",")
ao(custom.LOGGER.PURCHASE_LOG_NAME and " PURCHASE_LOG_NAME = \""..custom.LOGGER.PURCHASE_LOG_NAME.."\"," or " PURCHASE_LOG_NAME = \"PurchaseLog\",")
else
ao(" doNormalLogging = false, --If you are getting errors, set this to true. It tends to spam files.")
ao(" doPurchaseLogging = true,")
ao(" doInfoLogging = false, --HIGHLY recommended to not enable this. Every time the screen redraws an info event is created.")
ao(" doWarnLogging = true,")
ao(" LOG_LOCATION = \"logs/\",")
ao(" LOG_NAME = \"Log\",")
ao(" PURCHASE_LOG_LOCATION = \"purchases/\",")
ao(" PURCHASE_LOG_NAME = \"PurchaseLog\",")
end
ao(" },")
ao("}")
ao("return data")
else
fs.move(fatShopCustomization,"BadShopCustomization")
writeCustomization(fatShopCustomization)
logger.severe("The fatShopCustomization file should return a table. The old file has been moved to BadShopCustomization, and a new one has been written in it's place.")
logger.info("Rebooting in 10 seconds.")
os.sleep(10)
os.reboot()
end
logger.info("Potential fix for customization file. Rebooting.")
os.sleep(4)
os.reboot()
end
if tArgs[1] == "setupText" then
logger.info("Entering setup.")
sleep(3)
term.clear()
term.setCursorPos(1,1)
print("Before continuing, be sure you are alone and nobody else is on/able to access this computer.")
print("Nothing will be hidden, and everything written to the screen during the setup will be in plaintext.")
print()
print("Press any key to continue")
os.pullEvent("key")
sleep()
local qa = {
kristAddress = {
t = "boolean",
},
kristPword = {
q = "Please enter the private-key for your krist address.",
},
confirmPword = {
q = "Please confirm the key by typing it again.",
},
customInfo1 = {
t = "string",
q = "Enter line 1, leave blank for nothing.",
},
customInfo2 = {
t = "string",
q = "Enter line 2, leave blank for nothing.",
},
useSingleChest = {
t = "boolean",
q = "Will you be using a chest directly beside the turtle?",
},
chestSide = {
q = "What side of the turtle is the chest on?",
},
useModemChest = {
t = "boolean",
q = "Will you be using a storage network attached to a modem?",
},
}
local q = {
owner = {
t = "string",
q = "Who owns this shop?",
},
shopName = {
t = "string",
q = "What would you like this shop to be called?",
},
showCustomInfo = {
t = "boolean",
q = "Would you like to use a custom information bar?",
},
touchHereForCobbleButton = {
t = "boolean",
q = "Would you like to display a \"Free Cobble\" button?",
},
itemsDrawnAtOnce = {
t = "number",
q = "How many items should be drawn per page?",
},
dropSide = {
t = "string",
q = "What side of the turtle would you like to drop items? (front, top, or bottom)",
list = {
"front",
"top",
"bottom",
},
},
}
local function resolveAnswer(q,a)
if q.list and (q.t == "string" or q.t == "number") then
local inList = false
for i = 1,#q.list do
if a == q.list[i] then
inList = true
end
end
return a,inList;
else
if q.t == "string" then
return a,true;
elseif q.t == "boolean" then
a = string.lower(a)
if a == "yes" or a == "true" or a == "1" or a == "y" then
return true,true;
elseif a == "no" or a == "false" or a == "0" or a == "n" then
return false,true;
else
return nil,false;
end
elseif q.t == "number" then
a = tonumber(a)
return a,type(a) == "number"
end
end
return "Something failed.",false;
end
local function c()
term.clear()
term.setCursorPos(1,1)
end
local function pq(q)
print(q.q,"(" .. q.t .. ")")
term.write("->")
end
local tries = 0
repeat
local complete = false
tries = 0
repeat
c()
if tries > 0 then
print("Those are not the same!")
end
print(qa.kristPword.q)
term.write("->")
qa.kristPword.a = io.read()
print()
print(qa.confirmPword.q)
term.write("->")
qa.confirmPword.a = io.read()
print()
tries = 1
qa.kristAddress.a = checkKristAddress(qa.kristPword.a)
until qa.kristPword.a == qa.confirmPword.a
tries = 0
repeat
if tries > 0 then
print("That is not a valid answer!")
end
print("Is",checkKristAddress(qa.kristPword.a),"your krist address? (boolean)")
term.write("->")
local tmp = io.read()
local a,b = resolveAnswer(qa.kristAddress,tmp)
print(a,b)
if a and b then complete = true end
tries = 1
until b
until complete
tries = 0
repeat
c()
if tries > 0 then
print("That is not a valid answer!")
end
print(qa.useSingleChest.q)
term.write("->")
local tmp = "empty"
local a,b = resolveAnswer(qa.useSingleChest,io.read())
if a and b then
print(qa.chestSide.q)
term.write("->")
tmp = io.read()
end
qa.chestSide.a = tmp
qa.useSingleChest.a = a
tries = 1
until b
tries = 0
repeat
c()
if tries > 0 then
print("That is not a valid answer!")
end
print(qa.useModemChest.q)
term.write("->")
local a,b = resolveAnswer(qa.useModemChest,io.read())
qa.useModemChest.a = a
tries = 1
until b
local function customInfoRead()
c()
pq(qa.customInfo1)
qa.customInfo1.a = io.read()
print()
c()
pq(qa.customInfo2)
qa.customInfo2.a = io.read()
end
for k,v in pairs(q) do
tries = 0
repeat
local tmp = nil
c()
if tries > 0 then
print("That is not a valid answer!")
end
pq(v)
local a,b = resolveAnswer(v,io.read())
q[k].a = a
if k == "showCustomInfo" and a and b then
customInfoRead()
end
tries = tries + 1
until b
end
custom = {}
for k,v in pairs(q) do
if v.a ~= nil then
custom[k] = v.a
end
end
custom.customInfo = {
[ 1 ] = qa.customInfo1.a,
[ 2 ] = qa.customInfo2.a,
}
custom.useSingleChest = qa.useSingleChest.a
custom.chestSide = qa.chestSide.a
custom.useBothChestTypes = qa.useModemChest.a and qa.useSingleChest.a
local hand = fs.open(".privKey","w")
hand.writeLine("return \""..qa.kristPword.a.."\",\""..qa.kristAddress.a.."\"")
hand.close()
fixCustomization()
end
if fs.exists(".turtle") then
local hd = fs.open(".turtle","r")
tName = hd.readLine()
hd.close()
else
local juan = nil
for k,v in pairs(peripheral.getNames()) do
if peripheral.getType(v):find("chest") then juan = v break end
end
if not juan then
error("No chests connected to the network")
end
juan = peripheral.wrap(juan)
local tmp = juan.getTransferLocations()
for i = 1,#tmp do
if tmp[i]:find("turtle") then
tName = tmp[i]
logger.info("Connected to turtle "..tName)
break
end
end
end
if fs.exists(".monitor") then
local hd = fs.open(".monitor","r")
mName = hd.readLine()
if peripheral.find(mName) then
mon = peripheral.wrap(mName)
end
hd.close()
end
if not mon then
local pers = peripheral.getNames()
for i = 1,#pers do
if peripheral.getType(pers[i]) == "monitor" then
mName = pers[i]
mon = peripheral.wrap(pers[i])
end
end
if not mon then
error("Could not find monitor")
end
end
logger.info("Connected to monitor "..mName)
mon.setTextScale(0.5)
mX,mY = mon.getSize()
local function writeBlankPrivKey()
local hd = fs.open(".privKey","w")
hd.writeLine("--by default, so long as this returns your privateKey and public Krist Address, it will work.")
hd.writeLine("-- You may use whatever encryption methods.")
hd.writeLine("--It is recommended to use a different kristWallet than your main, as it may cause problems.")
hd.writeLine("return false,false")
hd.close()
logger.severe("Private key not valid. Edit .privKey to change it. Purchases will likely not work.")
end
if not fs.exists(".privKey") then
writeBlankPrivKey()
else
privKey,pubKey = dofile(".privKey")
if type(privKey) ~= "string" or type(pubKey) ~= "string" then
fs.move(".privKey","badPrivateKey")
logger.severe("Your private key is messed up. Your old private key has been moved to \"badPrivateKey\"")
logger.warn("Purchases will not work currently. Without the private key the shop will crash!")
writeBlankPrivKey()
end
if privKey then
privKey = k.toKristWalletFormat(privKey)
end
end
local function writeData()
local hd = fs.open(fatData,"w")
local function ao(a)
hd.writeLine(a)
end
ao("local items = {")
ao(" {")
ao(" display = \"Iron Ingot\",")
ao(" price = 1,")
ao(" find = \"minecraft:iron_ingot\",")
ao(" damage = 0,")
ao(" },")
ao(" {")
ao(" display = \"Coal\",")
ao(" price = 0.2,")
ao(" find = \"minecraft:coal\",")
ao(" damage = 0,")
ao(" },")
ao(" {")
ao(" display = \"Charcoal\",")
ao(" price = 0.1,")
ao(" find = \"minecraft:coal\",")
ao(" damage = 1,")
ao(" },")
ao("}")
ao("return items")
hd.close()
end
if not fs.exists(fatData) then
writeData()
logger.warn("file "..fatData.." does not exist, wrote default item data.")
items = dofile(fatData)
else
items = dofile(fatData)
if type(items) ~= "table" then
logger.severe(fatData.." should return a table!")
else
logger.info("Items found in data: "..#items)
end
end
local function refund(to,amt,rsn,gbad)
local success,err = await(k.makeTransaction,privKey,to,amt,( rsn and gbad and "message="..rsn ) or ( rsn and not gbad and "error="..rsn ) or ( "error=Unknown error occured, take your money back" ) )
if not success then
logger.severe("Failed to send refund")
print(textutils.serialise(err))
error("Failed to refund money due to "..err.error)
else
logger.info("Sent refund")
end
end
--get user preferences
local function writeCustomization(name)
local hd = fs.open(name,"w")
local function ao(txt)
hd.writeLine(txt)
end
ao("data = {")
ao(" owner = \"nobody\",")
ao(" shopName = \"Unnamed Shop\",")
ao(" drawBottomInfoBar = true,")
ao(" showCustomInfo = true,")
ao(" customInfo = {")
ao(" [ 1 ] = \"Edit customInfo variable to change me\",")
ao(" [ 2 ] = \"Up to two lines are permitted\",")
ao(" },")
ao(" showCustomBigInfo = false,")
ao(" customBigInfo = {")
ao(" [ 1 ] = \"Edit customBigInfo variable to change me\",")
ao(" [ 2 ] = \"the word PUBKEY will be translated\",")
ao(" [ 3 ] = \"to your public krist address.\",")
ao(" [ 4 ] = \"Up to four lines are permitted\",")
ao(" },")
ao(" touchHereForCobbleButton = true,")
ao(" dropSide = \"top\", -- the side the turtle will drop from, accepts 'top', 'bottom', and 'front'")
ao(" itemsDrawnAtOnce = 7,")
ao(" useBothChestTypes = false,")
ao(" useSingleChest = false, --if useBothChestTypes is true, this value does not matter. If useBothChestTypes is false, and there is a network attached, the turtle will ignore everything except the single chest.")
ao(" chestSide = \"bottom\",--You can use a single chest attached to a network by typing it's network name here (eg: \"minecraft:chest_666\")")
ao(" doPurchaseForwarding = false,")
ao(" purchaseForwardingAddress = \"fakeAddress\",")
ao(" compactMode = false,")
ao(" farthestBackground = {")
ao(" bg = colors.black,")
ao(" },")
ao(" background = {")
ao(" bg = colors.gray,")
ao(" fg = colors.white,")
ao(" },")
ao(" nameBar = {")
ao(" bg = colors.purple,")
ao(" fg = colors.white,")
ao(" },")
ao(" itemInfoBar = {")
ao(" bg = colors.blue,")
ao(" fg = colors.white,")
ao(" },")
ao(" infoBar = {")
ao(" bg = colors.purple,")
ao(" fg = colors.white,")
ao(" },")
ao(" buttons = {")
ao(" bg = colors.blue,")
ao(" fg = colors.white,")
ao(" },")
ao(" disabledButtons = {")
ao(" bg = colors.lightGray,")
ao(" fg = colors.white,")
ao(" },")
ao(" selection = {")
ao(" bg = colors.white,")
ao(" fg = colors.black,")
ao(" },")
ao(" bigSelection = {")
ao(" bg = colors.black,")
ao(" fg = colors.white,")
ao(" },")
ao(" selectedEmptyStock = {")
ao(" bg = colors.red,")
ao(" fg = colors.white,")
ao(" },")
ao(" bigSelectionEmptyStock = {")
ao(" bg = colors.red,")
ao(" fg = colors.white,")
ao(" },")
ao(" bigInfo = {")
ao(" bg = colors.black,")
ao(" fg = colors.white,")
ao(" },")
ao(" itemTableColor1 = {")
ao(" bg = colors.black,")
ao(" fg = colors.white,")
ao(" },")
ao(" itemTableColor2 = {")
ao(" bg = colors.black,")
ao(" fg = colors.white,")
ao(" },")
ao(" itemTableEmptyStock1 = {")
ao(" bg = colors.black,")
ao(" fg = colors.red,")
ao(" },")
ao(" itemTableEmptyStock2 = {")
ao(" bg = colors.black,")
ao(" fg = colors.red,")
ao(" },")
ao(" chatty = {")
ao(" enabled = false,")
ao(" prefix = \"shop" .. math.random(100000, 999999) .. "\",")
ao(" showNotice = true,")
ao(" -- change the above value if you state that chatty is enabled elsewhere (like in big info or bottom info bar)")
ao(" noticeFG = colors.white,")
ao(" noticeBG = colors.black,")
ao(" -- the above are the colors of the notice that displays just above the bottom info bar.")
ao(" infoFG = colors.white,")
ao(" infoBG = colors.red,")
ao(" -- the above are the colors of the popup when someone chats something and chatty reacts.")
ao(" event = \"chat_message\",")
ao(" -- If on switchcraft, change the above to 'command'")
ao(" },")
ao(" REFUNDS = {")
ao(" noItemSelected = \"There is no item selected!\",")
ao(" underpay = \"You seem to have underpaid.\",")
ao(" change = \"You overpaid by a small amount, here's your change!\",")
ao(" outOfStock = \"We do not have any stock of that item!\",")
ao(" UPDATE = \"The shop is updating it's stocks and an error occured!\",")
ao(" },")
ao(" LOGGER = {")
ao(" doNormalLogging = false, --If you are getting errors, set this to true. It tends to spam files.")
ao(" doPurchaseLogging = true,")
ao(" doInfoLogging = false, --HIGHLY recommended to not enable this. Every time the screen redraws an info event is created.")
ao(" doWarnLogging = true,")
ao(" LOG_LOCATION = \"logs/\",")
ao(" LOG_NAME = \"Log\",")
ao(" PURCHASE_LOG_LOCATION = \"purchases/\",")