-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCloud.java
More file actions
271 lines (220 loc) · 8.32 KB
/
Cloud.java
File metadata and controls
271 lines (220 loc) · 8.32 KB
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
package bot.HT.HT_Backup;
import java.io.File;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;
public class Cloud {
public Cloud() {
//Rename old storage
if(App.cloudExec("ls").contains(Ref.previousStorageName)) {
App.cloudExec("mv " + Ref.previousStorageName + " " + Ref.storageName);
}
}
public String help() {
return
"\n CLOUD FUNCTIONS:"
+ "\n ***>store*** <SLOT_NUMBER>: Stores a file at the specified slot number. Leave empty to fill the next empty slot."
+ "\n ***>retrieve*** <SLOT_NUMBER>: Get the file inside the specified slot."
+ "\n ***>remove*** <SLOT_NUMBER>: Remove the specified slot."
+ "\n ***>show*** <SLOT_NUMBER>: Show the contents of the specified slot."
+ "\n ***>show all***: Show the slots that are created.";
}
public String store(Message objMsg) {
String input = objMsg.getContentRaw();
String storeNum = objMsg.getAuthor().getId();
if(!App.cloudExec("ls").contains(Ref.storageName)) {
App.cloudExec("mkdir " + Ref.storageName);
}
if(!App.cloudExec("ls " + Ref.storageName).contains(storeNum)) {
App.cloudExec("mkdir "+Ref.storageName+"/" + storeNum);
}
if(!App.cloudExec("ls "+Ref.storageName+"/" + storeNum).equals("")) {
App.cloudExec("rm -rf "+Ref.storageName+"/"+storeNum+"/*");
System.out.println("rm -rf "+Ref.storageName+"/"+storeNum+"/*");
}
if(objMsg.getAttachments().size() < 2) {
String fileLink = objMsg.getAttachments().get(0).getUrl();
String output = App.cloudExec("wget -q -P "+Ref.storageName+"/" + storeNum + " " + fileLink);
if(App.cloudExec("ls " + storeNum).equals("")) {
return "File was not stored succesfully.";
}else {
return "File stored succesfully in slot "+ storeNum + ".";
}
}else {
return "No file attached!";
}
}
public String store(Message objMsg,String slot) {
String input = objMsg.getContentRaw();
String storeNum = slot;
if(!App.cloudExec("ls").contains(Ref.storageName)) {
App.cloudExec("mkdir " + Ref.storageName);
}
if(!App.cloudExec("ls " + Ref.storageName).contains(storeNum)) {
App.cloudExec("mkdir "+Ref.storageName+"/" + storeNum);
}
if(!App.cloudExec("ls "+Ref.storageName+"/" + storeNum).equals("")) {
App.cloudExec("rm -rf "+Ref.storageName+"/"+storeNum+"/*");
System.out.println("rm -rf "+Ref.storageName+"/"+storeNum+"/*");
}
if(objMsg.getAttachments().size() < 2) {
String fileLink = objMsg.getAttachments().get(0).getUrl();
String output = App.cloudExec("wget -q -P "+Ref.storageName+"/" + storeNum + " " + fileLink);
if(App.cloudExec("ls " + storeNum).equals("")) {
return "File was not stored succesfully.";
}else {
return "File stored succesfully in slot "+ storeNum + ".";
}
}else {
return "No file attached!";
}
}
public String empty(Message objMsg) {
String input = objMsg.getContentRaw();
String storeNum = input.substring(6,input.length());
storeNum = storeNum.trim();
//Verify that storage is a directory
if(!App.cloudExec("ls").contains(Ref.storageName)) {
App.cloudExec("mkdir " + Ref.storageName);
}
//Verify that storage contains this slot.
if(!App.cloudExec("ls " + Ref.storageName).contains(storeNum)) {
return ("Storage " + storeNum + " does not exist.");
}
//Check if slot is empty or not.
if(App.cloudExec("ls "+Ref.storageName+"/" + storeNum).equals("")) {
return ("Storage " + storeNum + " is already emtpy.");
}else {
if(objMsg.getAttachments().size() < 2) {
String fileInSlot = App.cloudExec("ls "+Ref.storageName+"/" + storeNum);
String output = App.cloudExec("rm -f "+Ref.storageName+"/"+storeNum+"/*");
return ("Storage slot " + storeNum + " succesfully emptied.");
}
}
return "Action empty failed.";
}
public String remove(Message objMsg){
String input = objMsg.getContentRaw();
String storeNum = input.substring(8,input.length());
//Verify that "storage" is a directory
if(!App.cloudExec("ls").contains(Ref.storageName)) {
App.cloudExec("mkdir " + Ref.storageName);
}
//Verify that storage contains this slot.
if(!App.cloudExec("ls " + Ref.storageName).contains(storeNum)) {
return ("Storage " + storeNum + " does not exist.");
}else {
//Verify that slot is empty.
if(!App.cloudExec("ls " + Ref.storageName + "/" + storeNum).equals("")) {
return ("Storage " + storeNum + " is NOT EMPTY! Run >empty " + storeNum + " to empty the slot. After emptying the slot, you can choose to remove the slot.");
}
String output = App.cloudExec("rm -r "+Ref.storageName+"/" + storeNum);
return ("Slot " + storeNum + " succesfully removed.");
}
}
public String show(Message objMsg) {
String input = objMsg.getContentRaw();
String storeNum;
try {
storeNum = input.substring(6,input.length());
}catch(Exception e) {
return "No slot specified. Try >show all.";
}
//Verify that "storage" is a directory
if(!App.cloudExec("ls").contains(Ref.storageName)) {
App.cloudExec("mkdir " + Ref.storageName);
}
if(storeNum.equals("all")) {
String output = App.cloudExec("ls " + Ref.storageName);
String[] snowflakes = output.split("\n");
output = "";
for(int i = 0; i < snowflakes.length; i++) {
output += snowflakes[i].trim() + "/" + App.jda.getUserById(Long.parseLong(snowflakes[i].trim())).getName() + "\n";
}
if(!output.equals("")){
return (output);
}else{
return ("Storage is empty.");
}
}else {
if(!App.cloudExec("ls " + Ref.storageName).contains(storeNum)) {
return ("Storage slot "+storeNum+" does not exist.");
}else {
String output = App.cloudExec("ls "+Ref.storageName+"/" + storeNum);
if(!output.equals("")){
return (output);
}else{
return "Slot "+storeNum+" does not exist or is empty."
+ "\nRun >show all to show slots that exist.";
}
}
}
}
public String showAll() {
//Verify that "storage" is a directory
if(!App.cloudExec("ls").contains(Ref.storageName)) {
App.cloudExec("mkdir " + Ref.storageName);
}
String output = App.cloudExec("ls " + Ref.storageName);
String[] snowflakes = output.split("\n");
output = "";
for(int i = 0; i < snowflakes.length; i++) {
if(!App.cloudExec("ls " + snowflakes[i].trim()).equals("")) {
output += App.jda.getUserById(Long.parseLong(snowflakes[i].trim())).getName() + "\n";
}
}
if(!output.equals("")){
return (output);
}else{
return ("There are no players you can battle against, currently.");
}
}
public String verifyRetrieve(Message objMsg) {
String input = objMsg.getContentRaw();
String storeNum = input.substring(10,input.length());
if(!App.cloudExec("ls").contains(Ref.storageName)) {
App.cloudExec("mkdir " + Ref.storageName);
return ("Storage space empty.");
}
if(!App.cloudExec("ls " + Ref.storageName).contains(storeNum)) {
return ("Storage slot"+storeNum+"does not exist.");
}
return "Verify complete. Retrieiving file...";
}
public String userVerification(Message objMsg) {
String storeNum = objMsg.getAuthor().getId();
if(!App.cloudExec("ls").contains(Ref.storageName)) {
App.cloudExec("mkdir " + Ref.storageName);
return ("Storage space empty.");
}
if(!App.cloudExec("ls " + Ref.storageName).contains(storeNum)) {
return ("Storage slot"+storeNum+"does not exist.");
}
return "Verify complete. Retrieiving file...";
}
public File sendZip() {
String zip = App.cloudExec("zip backup.zip " + Ref.storageName + "/*/*");
String filename = "../backup.zip";
filename = filename.trim();
File file = new File(filename);
return file;
}
public void deleteZip() {
App.cloudExec("rm backup.zip");
}
public File userRetrieve(Message objMsg) {
String input = objMsg.getContentRaw();
String storeNum = objMsg.getAuthor().getId();
String filename = App.cloudExec("ls "+Ref.storageName+"/"+storeNum);
filename = filename.trim();
File file = new File("../" + Ref.storageName + "/" + storeNum + "/" + filename);
return file;
}
public File retrieve(Message objMsg) {
String input = objMsg.getContentRaw();
String storeNum = input.substring(10,input.length());
String filename = App.cloudExec("ls "+Ref.storageName+"/"+storeNum);
filename = filename.trim();
File file = new File("../" + Ref.storageName + "/" + storeNum + "/" + filename);
return file;
}
}