├── .dockerignore
├── .gitignore
├── Dockerfile
├── LICENSE
├── README.md
├── commands
├── addDevice.js
├── devices.js
├── getCameraFrame.js
├── getEntityInfo.js
├── getInfo.js
├── getMap.js
├── getMapMarkers.js
├── getSettings.js
├── getTeamInfo.js
├── getTime.js
├── help.js
├── market.js
├── removeAllDevices.js
├── removeDevice.js
├── sendTeamMessage.js
├── setAlarmNotifications.js
├── setCargoShipNotifications.js
├── setChinook47Notifications.js
├── setCrateNotifications.js
├── setEntityValue.js
├── setExplosionNotifications.js
├── setInGameAlarmNotifications.js
├── setInGameCommands.js
├── setInGameNotifications.js
├── setInGamePairingNotifications.js
├── setNotifications.js
├── setPairingNotifications.js
├── setPrefix.js
├── setStorageMonitorNotifications.js
├── turnOff.js
├── turnOn.js
└── ver.js
├── config.json
├── devices.json
├── docs
└── documentation.md
├── fonts
├── PermanentMarker.fnt
└── PermanentMarker.png
├── images
├── cargoShip.png
├── cargo_ship_body.png
├── chinook47.png
├── chinook_map_blades.png
├── chinook_map_body.png
├── crate.png
├── explosion_marker.png
├── player.png
├── rust_logo.png
├── shop_green.png
├── smart_alarm.png
├── smart_switch.png
├── storage_monitor.png
├── train_tunnels.png
└── vending_machine.png
├── notifications
├── cargoShip.js
├── chinook47.js
├── crate.js
└── explosion.js
├── package-lock.json
├── package.json
├── rustplusDiscordBot.js
├── rustplusDiscordBot.png
├── screenshots
├── cargoShip.png
├── explosion.png
├── getMap.png
├── help.png
├── market.png
├── pairing.gif
└── turnOn.gif
├── tools
├── external
│ ├── copy_server_details_to_config.js
│ └── process_items.js
├── fcmListener.js
├── items.json
└── tools.js
└── version.json
/.dockerignore:
--------------------------------------------------------------------------------
1 |
2 | node_modules/
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | devices.json
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:14
2 |
3 | WORKDIR /app
4 |
5 | COPY package*.json ./
6 |
7 | RUN npm install
8 |
9 | COPY . .
10 |
11 | CMD [ "node", "rustplusDiscordBot.js" ]
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
RustPlus-Discord-Bot
11 |
12 |
13 | **NOTE** This is the old project, the newer and more advanced can be found [here](https://github.com/alexemanuelol/rustPlusPlus).
14 |
15 | A NodeJS Discord Bot that uses the rustplus.js library to interact with Smart Devices, search for items for sale in vending machines, notify about in-game events such as Cargo Ship spawning or trigger of oilrig and other methods that is available through the [Rust](https://store.steampowered.com/app/252490/Rust/)+ companion app.
16 |
17 | # How-To Setup
18 |
19 | ## Setup Video
20 |
21 | [How to setup the RustPlus-Discord-Bot](https://youtu.be/7cdn1dPMEKU)
22 | ## Required Software
23 |
24 | Follow the instructions for your operating system.
25 |
26 | ### Windows
27 | Download the following:
28 |
29 | - NodeJS - [Link to download page.](https://nodejs.org/en/download/)
30 | - Git - [Link to download page.](https://git-scm.com/downloads)
31 |
32 | ### Ubuntu
33 | Run the following commands:
34 |
35 | $ sudo apt update
36 | $ sudo apt install nodejs=14.17.3 npm=6.14.13 git
37 |
38 | ### Arch Linux
39 | Run the following command:
40 |
41 | $ sudo pacman -S nodejs=14.17.3 npm=6.14.13 git
42 |
43 | ## Setup the BOT
44 |
45 | Open a terminal and run the following commands to clone the repository and install the required packages:
46 |
47 | $ git clone https://github.com/alexemanuelol/RustPlus-Discord-Bot.git
48 | $ cd RustPlus-Discord-Bot
49 | $ npm install
50 |
51 | Run the following command to register with FCM, Expo and link your Steam Account with Rust+.
52 |
53 | $ npx @liamcottle/rustplus.js fcm-register
54 |
55 | **NOTE:** Chrome/ Chromium is required for this step to work. It will open up an instance of the browser where you will have to sign in with your Steam Account and link with Rust+:
56 |
57 | This will generate the configuration file *rustplus.config.json* which should remain in the same folder as the *rustplusDiscordBot.js* script.
58 |
59 | Before we can start the BOT, we need to sort out the config.json file. There are some properties that needs to be filled out, these are:
60 | - **steamId**
61 | - **serverIp**
62 | - **appPort**
63 | - **playerToken**
64 | - **token**
65 | - **botSpamChannel**
66 |
67 | The first 4 properties can easily be accessed by running the script:
68 |
69 | $ cd tools/external
70 | $ node copy_server_details_to_config.js
71 |
72 | While this script is running, you simply join the rust server you want to play on, enter the menu and click on 'Rust+' and then press either 'PAIR WITH SERVER' or 'RESEND'. This will trigger a FCM notification that includes **steamId**, **serverIp**, **appPort**, **playerToken** and will automatically be copied into your config.json file.
73 |
74 | **token** property can be gained by creating a [Discord BOT](https://discordpy.readthedocs.io/en/stable/discord.html) for your Discord Server and copying the bot token into the config.json file.
75 |
76 | **botSpamChannel** property can be gained by choosing one of the text channels in your Discord Server and simply copy the channel ID into the config.json file.
77 |
78 | # How to update the repository
79 |
80 | Run the following commands:
81 |
82 | $ git stash
83 | $ git pull --rebase
84 | $ git stash pop
85 |
86 |
87 | # Documentation
88 |
89 | *docs/documentation.md* includes a detailed guide to all available commands and all the configuration settings.
90 |
91 | [Documentation](docs/documentation.md)
92 |
93 |
94 | # Screenshots and GIFs
95 |
96 | ## TurnOn Smart Switches
97 | 
98 |
99 | ## Pairing with Smart Devices
100 | 
101 |
102 | ## Running the help command
103 | 
104 |
105 | ## Running the getMap command
106 | 
107 |
108 | ## Running the market command with assault as keyword
109 | 
110 |
111 | ## CargoShip active notification
112 | 
113 |
114 | ## Explosion detected notification
115 | 
116 |
117 | # Thanks to
118 |
119 | **liamcottle**@GitHub - for the [rustplus.js](https://github.com/liamcottle/rustplus.js) library
120 |
--------------------------------------------------------------------------------
/commands/addDevice.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const switchAttachment = new Discord.MessageAttachment("./images/smart_switch.png", "smart_switch.png");
6 | const alarmAttachment = new Discord.MessageAttachment("./images/smart_alarm.png", "smart_alarm.png");
7 | const storageAttachment = new Discord.MessageAttachment("./images/storage_monitor.png", "storage_monitor.png");
8 |
9 | const prefix = Tools.readJSON("./config.json").general.prefix;
10 | const help = `\
11 | This command lets you add different devices to the devices.json located on the bot server.
12 |
13 | **To add a Smart Switch**:
14 | ${prefix}addDevice nameOfSwitch entityId
15 | Example:
16 | ${prefix}addDevice switch1 1234567
17 |
18 | **To add a Smart Alarm**:
19 | ${prefix}addDevice nameOfAlarm entityId
20 | Example:
21 | ${prefix}addDevice oilrig 1234567
22 |
23 | **To add a Storage Monitor**:
24 | ${prefix}addDevice nameOfSM entityId
25 | Example:
26 | ${prefix}addDevice toolcupboard 1234567`
27 |
28 | module.exports = {
29 | name: "addDevice",
30 | description: "Add a new device to devices.json file.",
31 | help: help,
32 | execute(author, message, channel, args, discordBot, rustplus) {
33 | /* Read the config.json file. */
34 | let config = Tools.readJSON("./config.json");
35 |
36 | /* Verify that the number of arguments is 2. */
37 | if (args.length !== 2) {
38 | Tools.print("ERROR", "2 arguments required. Example: " + config.general.prefix
39 | + "addDevice @name @id.", channel);
40 | return false;
41 | }
42 |
43 | /* Extract device name and id from args. */
44 | var name = args[0];
45 | var id = parseInt(args[1]);
46 |
47 | /* Check if the ID is of integer type. */
48 | if (isNaN(id)) {
49 | Tools.print("ERROR", "Could not convert **" + args[1] + "** to integer", channel);
50 | return false;
51 | }
52 |
53 | /* Send the rustplus.js request: getEntityInfo */
54 | rustplus.getEntityInfo(id, (msg) => {
55 | Tools.print("REQUEST", "getEntityInfo");
56 |
57 | /* Validate that the response message does not include any errors. */
58 | if (!Tools.validateResponse(msg, channel)) {
59 | Tools.print("RESPONSE", "getEntityInfo\n" + JSON.stringify(msg));
60 | return false;
61 | }
62 |
63 | /* Smart Switch */
64 | if (msg.response.entityInfo.type === 1) {
65 | let device = { id: id, type: msg.response.entityInfo.type };
66 | Tools.writeJSON("./devices.json", name, device);
67 | Tools.print("Successfully Added", "Smart Switch **" + name + " : " + id + "** was added to devices.",
68 | channel, null, switchAttachment, "smart_switch.png");
69 | }
70 | /* Smart Alarm */
71 | else if (msg.response.entityInfo.type === 2) {
72 | let device = { id: id, type: msg.response.entityInfo.type };
73 | Tools.writeJSON("./devices.json", name, device);
74 | Tools.print("Successfully Added", "Smart Alarm **" + name + " : " + id +
75 | "** was added to devices.", channel, null, alarmAttachment, "smart_alarm.png");
76 | }
77 | /* Storage Monitor */
78 | else if (msg.response.entityInfo.type === 3) {
79 | let device = { id: id, type: msg.response.entityInfo.type };
80 | Tools.writeJSON("./devices.json", name, device);
81 | Tools.print("Successfully Added", "Storage Monitor **" + name + " : " + id +
82 | "** was added to devices.", channel, null, storageAttachment, "storage_monitor.png");
83 | }
84 | else {
85 | Tools.print("ERROR", "Invalid type.");
86 | }
87 | });
88 |
89 | return true;
90 | },
91 | };
92 |
--------------------------------------------------------------------------------
/commands/devices.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Main = require("./../rustplusDiscordBot.js");
4 | const Tools = require("./../tools/tools.js");
5 |
6 | const help = `\
7 | This command prints all the registered devices in the devices.json located on the bot server.`
8 |
9 | module.exports = {
10 | name: "devices",
11 | description: "Prints all the devices located in the devices.json file.",
12 | help: help,
13 | execute(author, message, channel, args, discordBot, rustplus) {
14 | /* Verify that there are no arguments. */
15 | if (args.length != 0) {
16 | Tools.print("ERROR", "No arguments required.", channel);
17 | return false;
18 | }
19 |
20 | /* Read the devices.json file. */
21 | let devices = Tools.readJSON("./devices.json");
22 |
23 | const embed = new Discord.MessageEmbed()
24 | .setColor("#ce412b")
25 | .attachFiles(Main.THUMBNAIL_DEFAULT)
26 | .setThumbnail("attachment://rust_logo.png")
27 | .setURL(Main.GITHUB_URL)
28 | .setTitle("Registered Devices");
29 |
30 | let switchStr, alarmStr, storageStr;
31 | switchStr = alarmStr = storageStr = "";
32 |
33 | for (let device in devices) {
34 | if (devices[device].type === 1) {
35 | switchStr += "**-** " + device + " : " + devices[device].id + "\n";
36 | }
37 | else if (devices[device].type === 2) {
38 | alarmStr += "**-** " + device + " : " + devices[device].id + "\n";
39 | }
40 | else if (devices[device].type === 3) {
41 | storageStr += "**-** " + device + " : " + devices[device].id + "\n";
42 | }
43 | }
44 |
45 | if (switchStr !== "") {
46 | embed.addField("**Smart Switches**", switchStr);
47 | }
48 | if (alarmStr !== "") {
49 | embed.addField("**Smart Alarms**", alarmStr);
50 | }
51 | if (storageStr !== "") {
52 | embed.addField("**Storage Containers**", storageStr);
53 | }
54 |
55 | if (switchStr === "" && alarmStr === "" && storageStr === "") {
56 | embed.setDescription("No registered devices.");
57 | }
58 |
59 | Tools.print("Registered Devices",);
60 | channel.send(embed);
61 |
62 | return true;
63 | },
64 | };
65 |
--------------------------------------------------------------------------------
/commands/getCameraFrame.js:
--------------------------------------------------------------------------------
1 | const Tools = require("./../tools/tools.js");
2 |
3 | const prefix = Tools.readJSON("./config.json").general.prefix;
4 | const help = `\
5 | This command gathers a jpeg frame from a camera in-game and sends it to discord.
6 | (**NOTE**: Feature not currently supported).
7 |
8 | **Get a frame from 'CASINO' camera at Bandit Camp**:
9 | ${prefix}getCameraFrame CASINO 0`
10 |
11 | module.exports = {
12 | name: "getCameraFrame",
13 | description: "Get a jpeg image from a CCTV Camera.",
14 | help: help,
15 | execute(author, message, channel, args, discordBot, rustplus) {
16 | /* Read the config.json file. */
17 | let config = Tools.readJSON("./config.json");
18 |
19 | /* Verify that the number of arguments is 2. */
20 | if (args.length != 2) {
21 | Tools.print("ERROR", "2 arguments required. Example: " + config.general.prefix +
22 | "getCameraFrame @name @frame.", channel);
23 | return false;
24 | }
25 |
26 | /* Extract camera name and frame from args. */
27 | var camera = args[0];
28 | var frame = parseInt(args[1]);
29 |
30 | /* Send the rustplus.js request: getCameraFrame */
31 | rustplus.getCameraFrame(camera, frame, (msg => {
32 | Tools.print("REQUEST", "getCameraFrame");
33 |
34 | /* Validate that the response message does not include any errors. */
35 | if (msg.response.hasOwnProperty("error")) {
36 | Tools.print("RESPONSE", "getCameraFrame\n" + JSON.stringify(msg));
37 |
38 | let description = "Feature not currently implemented. Might get a successful response if server \
39 | admin run the following command in F1 console: **cctvrender.enabled true**";
40 | Tools.print("ERROR", description, channel);
41 | }
42 | else {
43 | /* TBD */
44 | }
45 | }));
46 |
47 | return true;
48 | },
49 | };
50 |
--------------------------------------------------------------------------------
/commands/getEntityInfo.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const switchAttach = new Discord.MessageAttachment("./images/smart_switch.png", "smart_switch.png");
6 | const alarmAttach = new Discord.MessageAttachment("./images/smart_alarm.png", "smart_alarm.png");
7 | const storageAttach = new Discord.MessageAttachment("./images/storage_monitor.png", "storage_monitor.png");
8 |
9 | const prefix = Tools.readJSON("./config.json").general.prefix;
10 | const help = `\
11 | This command gathers information about a smart device and prints it to discord.
12 |
13 | **To get the entity information from Smart Switch 1234567 (Made up)**:
14 | ${prefix}getEntityInfo 1234567
15 |
16 | **To get the entity information from Smart Alarm 'oilrig' defined in devices.json**:
17 | ${prefix}getEntityInfo oilrig`
18 |
19 | module.exports = {
20 | name: "getEntityInfo",
21 | description: "Get current state of a Smart Device.",
22 | help: help,
23 | execute(author, message, channel, args, discordBot, rustplus) {
24 | /* Read the config.json file. */
25 | let config = Tools.readJSON("./config.json");
26 |
27 | /* Verify that the number of arguments is 1. */
28 | if (args.length != 1) {
29 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
30 | "getEntityInfo @name/id.", channel);
31 | return false;
32 | }
33 |
34 | /* Read the devices.json file. */
35 | let devices = Tools.readJSON("./devices.json");
36 | let id;
37 |
38 | /* Translate input arg to id. */
39 | if (devices.hasOwnProperty(args[0])) {
40 | id = parseInt(devices[args[0]].id);
41 | }
42 | else {
43 | id = parseInt(args[0]);
44 | }
45 |
46 | /* Send the rustplus.js request: getEntityInfo */
47 | rustplus.getEntityInfo(id, (msg) => {
48 | Tools.print("REQUEST", "getEntityInfo");
49 |
50 | /* Validate that the response message does not include any errors. */
51 | if (!Tools.validateResponse(msg, channel)) {
52 | Tools.print("RESPONSE", "getEntityInfo\n" + JSON.stringify(msg));
53 | return false;
54 | }
55 |
56 | let title = "Entity Information";
57 | let description = "**Name:** " + args[0] + "\n" +
58 | "**Id:** " + id + "\n" +
59 | "**Type:** " + Tools.EntityType[msg.response.entityInfo.type] + "\n" +
60 | "**Value:** " + msg.response.entityInfo.payload.value + "\n" +
61 | "**Capacity:** " + msg.response.entityInfo.payload.capacity + "\n" +
62 | "**HasProtection:** " + msg.response.entityInfo.payload.hasProtection + "\n" +
63 | "**ProtectionExpiry:** " + msg.response.entityInfo.payload.protectionExpiry;
64 |
65 | if (msg.response.entityInfo.type === 1) {
66 | Tools.print(title, description, channel, null, switchAttach, "smart_switch.png");
67 | }
68 | else if (msg.response.entityInfo.type === 2) {
69 | Tools.print(title, description, channel, null, alarmAttach, "smart_alarm.png");
70 | }
71 | else if (msg.response.entityInfo.type === 3) {
72 | Tools.print(title, description, channel, null, storageAttach, "storage_monitor.png");
73 | }
74 | });
75 |
76 | return true;
77 | },
78 | };
79 |
--------------------------------------------------------------------------------
/commands/getInfo.js:
--------------------------------------------------------------------------------
1 | const Tools = require("./../tools/tools.js");
2 |
3 | const help = `\
4 | This command prints information about the server.`
5 |
6 | module.exports = {
7 | name: "getInfo",
8 | description: "Get info about the Rust Server.",
9 | help: help,
10 | execute(author, message, channel, args, discordBot, rustplus) {
11 | /* Verify that there are no arguments. */
12 | if (args.length != 0) {
13 | Tools.print("ERROR", "No arguments required.", channel);
14 | return false;
15 | }
16 |
17 | /* Send the rustplus.js request: getInfo */
18 | rustplus.getInfo((msg) => {
19 | Tools.print("REQUEST", "getInfo");
20 |
21 | /* Validate that the response message does not include any errors. */
22 | if (!Tools.validateResponse(msg, channel)) {
23 | Tools.print("RESPONSE", "getInfo\n" + JSON.stringify(msg));
24 | return false;
25 | }
26 |
27 | let info = msg.response.info;
28 | let title = "Server Information";
29 | let description = "**Name:** " + info.name + "\n" +
30 | "**URL:** " + info.url + "\n" +
31 | "**Map:** " + info.map + "\n" +
32 | "**Map Size:** " + info.mapSize + "\n" +
33 | "**Wipe Time:** " + Tools.convertToStringDate(Tools.convertUnixTimestampToDate(info.wipeTime)) + "\n" +
34 | "**Online Players:** (" + info.players + "/" + info.maxPlayers + ")\n" +
35 | "**Queued Players:** " + info.queuedPlayers + "\n" +
36 | "**Seed:** " + info.seed + "\n" +
37 | "**Salt:** " + info.salt;
38 | Tools.print(title, description, channel);
39 | });
40 |
41 | return true;
42 | },
43 | };
44 |
--------------------------------------------------------------------------------
/commands/getMap.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 | const Jimp = require("jimp");
3 | const fs = require("fs");
4 |
5 | const Main = require("./../rustplusDiscordBot.js");
6 | const Tools = require("./../tools/tools.js");
7 |
8 | const mapName = "temp_map_image.jpg";
9 |
10 | const MarkerImagePath = [
11 | mapName,
12 | "./images/player.png",
13 | "./images/explosion_marker.png",
14 | "./images/shop_green.png",
15 | "./images/chinook_map_body.png",
16 | "./images/cargo_ship_body.png",
17 | "./images/crate.png",
18 | "./images/chinook_map_blades.png",
19 | "./images/train_tunnels.png"
20 | ]
21 |
22 | const MarkerImageSize = [
23 | null,
24 | 20,
25 | 30,
26 | 20,
27 | 50,
28 | 100,
29 | 25,
30 | 25,
31 | 35
32 | ]
33 |
34 | const Monument = {
35 | "airfield_display_name": "AIRFIELD",
36 | "bandit_camp": "BANDIT CAMP",
37 | "dome_monument_name": "THE DOME",
38 | "excavator": "GIANT EXCAVATOR PIT",
39 | "fishing_village_display_name": "FISHING VILLAGE",
40 | "gas_station": "OXUM'S GAS STATION",
41 | "harbor_2_display_name": "HARBOR",
42 | "harbor_display_name": "HARBOR",
43 | "junkyard_display_name": "JUNKYARD",
44 | "large_fishing_village_display_name": "LARGE FISHING VILLAGE",
45 | "large_oil_rig": "LARGE OIL RIG",
46 | "launchsite": "LAUNCH SITE",
47 | "lighthouse_display_name": "LIGHTHOUSE",
48 | "military_tunnels_display_name": "MILITARY TUNNEL",
49 | "mining_outpost_display_name": "MINING OUTPOST",
50 | "mining_quarry_hqm_display_name": "HQM QUARRY",
51 | "mining_quarry_stone_display_name": "STONE QUARRY",
52 | "mining_quarry_sulfur_display_name": "SULFUR QUARRY",
53 | "oil_rig_small": "OIL RIG",
54 | "outpost": "OUTPOST",
55 | "power_plant_display_name": "POWER PLANT",
56 | "satellite_dish_display_name": "SATELLITE DISH",
57 | "sewer_display_name": "SEWER BRANCH",
58 | "stables_a": "RANCH",
59 | "stables_b": "LARGE BARN",
60 | "supermarket": "ABANDONED SUPERMARKET",
61 | "swamp_c": "ABANDONED CABINS",
62 | "train_tunnel_display_name": "",
63 | "train_yard_display_name": "TRAIN YARD",
64 | "underwater_lab": "UNDERWATER LAB",
65 | "water_treatment_plant_display_name": "WATER TREATMENT PLANT"
66 | }
67 |
68 | const help = `\
69 | This command gathers a jpeg image of the server map and all it's monuments and sends it to discord.`
70 |
71 | module.exports = {
72 | name: "getMap",
73 | description: "Fetch map info, which includes a jpeg image.",
74 | help: help,
75 | execute(author, message, channel, args, discordBot, rustplus) {
76 | /* Verify that there are no arguments. */
77 | if (args.length != 0) {
78 | Tools.print("ERROR", "No arguments required.", channel);
79 | return false;
80 | }
81 |
82 | /* Send the rustplus.js request: getMap */
83 | rustplus.getMap((msg) => {
84 | Tools.print("REQUEST", "getMap");
85 |
86 | /* Validate that the response message does not include any errors. */
87 | if (!Tools.validateResponse(msg, channel)) {
88 | Tools.print("RESPONSE", "getMap\n" + JSON.stringify(msg));
89 | return false;
90 | }
91 |
92 | /* Write the received image bytes to a file. */
93 | fs.writeFileSync(MarkerImagePath[Tools.MarkerType.Source], msg.response.map.jpgImage);
94 |
95 | /* Read all the marker images via Jimp. */
96 | var jimps = [];
97 | for (var i = 0; i < MarkerImagePath.length; i++) {
98 | jimps.push(Jimp.read(MarkerImagePath[i]));
99 | }
100 |
101 | /* Wait for all Jimp images to load. */
102 | Promise.all(jimps).then(function (markerImage) {
103 | return Promise.all(jimps);
104 | }).then(function (markerImage) {
105 | /* Resize the Jimp images. */
106 | for (var i = 1; i < markerImage.length; i++) {
107 | var size = MarkerImageSize[i];
108 | markerImage[i].resize(size, size);
109 | }
110 |
111 | /* Send the rustplus.js request: getInfo */
112 | rustplus.getInfo((info) => {
113 | Tools.print("REQUEST", "getInfo");
114 |
115 | /* Validate that the response message does not include any errors. */
116 | if (!Tools.validateResponse(info, channel)) {
117 | Tools.print("RESPONSE", "getMap => getInfo\n" + JSON.stringify(info));
118 | return false;
119 | }
120 |
121 | /* Send the rustplus.js request: getMapMarkers */
122 | rustplus.getMapMarkers((mapMarkers) => {
123 | Tools.print("REQUEST", "getMapMarkers");
124 |
125 | /* Validate that the response message does not include any errors. */
126 | if (!Tools.validateResponse(mapMarkers, channel)) {
127 | Tools.print("RESPONSE", "getMap => getMapMarkers\n" + JSON.stringify(mapMarkers));
128 | return false;
129 | }
130 |
131 | let mapSize = info.response.info.mapSize;
132 | let width = msg.response.map.width;
133 | let height = msg.response.map.height;
134 | let oceanMargin = msg.response.map.oceanMargin;
135 |
136 | /* For all map markers, append them to original map image. */
137 | for (let marker of mapMarkers.response.mapMarkers.markers) {
138 | var x = marker.x * ((width - 2 * oceanMargin) / mapSize) + oceanMargin;
139 | var n = height - 2 * oceanMargin;
140 | var y = height - (marker.y * (n / mapSize) + oceanMargin);
141 |
142 | /* Compensate rotations */
143 | if (marker.type === Tools.MarkerType.CargoShip) {
144 | x -= 20;
145 | y -= 20;
146 | }
147 |
148 | try {
149 | var size = MarkerImageSize[marker.type];
150 |
151 | /* Rotate */
152 | markerImage[marker.type].rotate(marker.rotation);
153 |
154 | markerImage[Tools.MarkerType.Source].composite(markerImage[marker.type], x -
155 | (size / 2), y - (size / 2));
156 | }
157 | catch (err) {
158 | /* Ignore */
159 | }
160 | }
161 |
162 | /* Load Permanent Marker font. */
163 | Jimp.loadFont("./fonts/PermanentMarker.fnt").then(function (font) {
164 | /* Append names for all the monuments to original map image. */
165 | for (let monument of msg.response.map.monuments) {
166 | var x = monument.x * ((width - 2 * oceanMargin) / mapSize) + oceanMargin;
167 | var n = height - 2 * oceanMargin;
168 | var y = height - (monument.y * (n / mapSize) + oceanMargin);
169 |
170 | try {
171 | if (monument.token === "train_tunnel_display_name") {
172 | var size = MarkerImageSize[Tools.MarkerType.TrainTunnels];
173 | markerImage[Tools.MarkerType.Source].composite(markerImage[
174 | Tools.MarkerType.TrainTunnels], x - (size / 2), y - (size / 2));
175 | }
176 | else {
177 | /* Compensate for the text placement */
178 | var posCompensation = Monument[monument.token].length * 5;
179 | markerImage[Tools.MarkerType.Source].print(font, x - posCompensation, y - 10,
180 | Monument[monument.token]);
181 | }
182 | }
183 | catch (err) {
184 | /* Ignore */
185 | }
186 | }
187 |
188 | /* Write the original map image with all the added content. */
189 | markerImage[Tools.MarkerType.Source].write(MarkerImagePath[Tools.MarkerType.Source],
190 | (err) => {
191 | const image = fs.readFileSync(MarkerImagePath[Tools.MarkerType.Source]);
192 | const attachment = new Discord.MessageAttachment(image, mapName);
193 | const embed = new Discord.MessageEmbed()
194 | .setColor("#ce412b")
195 | .attachFiles(Main.THUMBNAIL_DEFAULT)
196 | .setThumbnail("attachment://rust_logo.png")
197 | .setURL(Main.GITHUB_URL)
198 | .setTitle("Server Map")
199 | .setDescription("The map of the server '**" + info.response.info.name + "**'.")
200 | .attachFiles(attachment)
201 | .setImage("attachment://" + mapName);
202 |
203 | channel.send(embed);
204 |
205 | /* Remove temp image file. */
206 | try {
207 | fs.unlinkSync(MarkerImagePath[Tools.MarkerType.Source]);
208 | }
209 | catch (err) {
210 | console.error(err);
211 | }
212 | });
213 | }).catch(function (err) {
214 | Tools.print("ERROR", err);
215 | });
216 | });
217 | });
218 | });
219 | });
220 |
221 | return true;
222 | },
223 | };
224 |
--------------------------------------------------------------------------------
/commands/getMapMarkers.js:
--------------------------------------------------------------------------------
1 | const Tools = require("./../tools/tools.js");
2 |
3 | const help = `\
4 | This command gathers all the map markers of the server map.
5 | (**NOTE**: Currently not useful for anything by itself).`
6 |
7 | module.exports = {
8 | name: "getMapMarkers",
9 | description: "Get map markers, such as vending machines and cargo/heli.",
10 | help: help,
11 | execute(author, message, channel, args, discordBot, rustplus) {
12 | /* Verify that there are no arguments. */
13 | if (args.length != 0) {
14 | Tools.print("ERROR", "No arguments required.", channel);
15 | return false;
16 | }
17 |
18 | /* Send the rustplus.js request: getMapMarkers */
19 | rustplus.getMapMarkers((msg) => {
20 | Tools.print("REQUEST", "getMapMarkers");
21 |
22 | /* Validate that the response message does not include any errors. */
23 | if (!Tools.validateResponse(msg, channel)) {
24 | Tools.print("RESPONSE", "getMapMarkers\n" + JSON.stringify(msg));
25 | return false;
26 | }
27 |
28 | /* TODO: Find a convenient way to display the information. */
29 | });
30 |
31 | return true;
32 | },
33 | };
34 |
--------------------------------------------------------------------------------
/commands/getSettings.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Main = require("./../rustplusDiscordBot.js");
4 | const Tools = require("./../tools/tools.js");
5 |
6 | const help = `\
7 | This command gathers all the public settings from the config.json file and prints it to discord.`
8 |
9 | module.exports = {
10 | name: "getSettings",
11 | description: "Get the current config settings.",
12 | help: help,
13 | execute(author, message, channel, args, discordBot, rustplus) {
14 | /* Read the config.json file. */
15 | let config = Tools.readJSON("./config.json");
16 |
17 | /* Verify that there are no arguments. */
18 | if (args.length != 0) {
19 | Tools.print("ERROR", "No arguments required.", channel);
20 | return false;
21 | }
22 |
23 | let title = "Bot Settings";
24 | let description = "";
25 |
26 | description += "Prefix: **" + config.general.prefix + "**\n\n";
27 | description += "Notifications: **" + config.notifications.enabled + "**\n";
28 | description += "In-Game Notifications: **" + config.notifications.inGame + "**\n";
29 | description += "Cargo Ship Notifications: **" + config.notifications.cargoShip + "**\n";
30 | description += "Chinook 47 Notifications: **" + config.notifications.chinook47 + "**\n";
31 | description += "Crate Notifications: **" + config.notifications.crate + "**\n";
32 | description += "Explosion Notifications: **" + config.notifications.explosion + "**\n\n";
33 | description += "Alarm Notifications: **" + config.alarms.enabled + "**\n";
34 | description += "In-Game Alarm Notifications : **" + config.alarms.inGame + "**\n\n";
35 | description += "Storage Monitor Notifications: **" + config.storageMonitors.enabled + "**\n\n";
36 | description += "pairingNotifications: **" + config.rustplus.pairingNotifications + "**\n";
37 | description += "inGamePairingNotifications: **" + config.rustplus.inGamePairingNotifications + "**";
38 |
39 | Tools.print(title, description, channel);
40 |
41 | return true;
42 | },
43 | };
44 |
--------------------------------------------------------------------------------
/commands/getTeamInfo.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Main = require("./../rustplusDiscordBot.js");
4 | const Tools = require("./../tools/tools.js");
5 |
6 | const help = `\
7 | This command gathers information about the team and prints it to discord.`
8 |
9 | module.exports = {
10 | name: "getTeamInfo",
11 | description: "Get list of team members and positions on map.",
12 | help: help,
13 | execute(author, message, channel, args, discordBot, rustplus) {
14 | /* Verify that there are no arguments. */
15 | if (args.length != 0) {
16 | Tools.print("ERROR", "No arguments required.", channel);
17 | return false;
18 | }
19 |
20 | /* Send the rustplus.js request: getTeamInfo */
21 | rustplus.getTeamInfo((msg) => {
22 | Tools.print("REQUEST", "getTeamInfo");
23 |
24 | /* Validate that the response message does not include any errors. */
25 | if (!Tools.validateResponse(msg, channel)) {
26 | Tools.print("RESPONSE", "getTeamInfo\n" + JSON.stringify(msg));
27 | return false;
28 | }
29 |
30 | let title = "Team Information";
31 | let description = "\n";
32 |
33 | const embed = new Discord.MessageEmbed()
34 | .setColor("#ce412b")
35 | .attachFiles(Main.THUMBNAIL_DEFAULT)
36 | .setThumbnail("attachment://rust_logo.png")
37 | .setURL(Main.GITHUB_URL)
38 | .setTitle(title);
39 |
40 | /* Fill description with member information. */
41 | for (let member of msg.response.teamInfo.members) {
42 | let field = "**" + member.name + "** (" + member.steamId + ")";
43 | let str = "**IsOnline:** " + member.isOnline + "\n" +
44 | "**IsAlive:** " + member.isAlive + "\n" +
45 | "**SpawnTime:** " + Tools.convertToStringDate(Tools.convertUnixTimestampToDate(member.spawnTime)) + "\n" +
46 | "**DeathTime:** " + Tools.convertToStringDate(Tools.convertUnixTimestampToDate(member.deathTime)) + "\n" +
47 | "**X-cord:** " + member.x + "\n" +
48 | "**Y-cord:** " + member.y;
49 |
50 | description += field + "\n" + str + "\n";
51 | embed.addField(field, str);
52 | }
53 |
54 | Tools.print(title, description);
55 | channel.send(embed);
56 | });
57 |
58 | return true;
59 | },
60 | };
61 |
--------------------------------------------------------------------------------
/commands/getTime.js:
--------------------------------------------------------------------------------
1 | const Tools = require("./../tools/tools.js");
2 |
3 | const help = `\
4 | This command gathers the in-game time of the server and prints it to discord.`
5 |
6 | module.exports = {
7 | name: "getTime",
8 | description: "Get the current in game time.",
9 | help: help,
10 | execute(author, message, channel, args, discordBot, rustplus) {
11 | /* Verify that there are no arguments. */
12 | if (args.length != 0) {
13 | Tools.print("ERROR", "No arguments required.", channel);
14 | return false;
15 | }
16 |
17 | /* Send the rustplus.js request: getTime */
18 | rustplus.getTime((msg) => {
19 | Tools.print("REQUEST", "getTime");
20 |
21 | /* Validate that the response message does not include any errors. */
22 | if (!Tools.validateResponse(msg, channel)) {
23 | Tools.print("RESPONSE", "getTime\n" + JSON.stringify(msg));
24 | return false;
25 | }
26 |
27 | let title = "Time Information";
28 | let description = "\n**Current time:** " + Tools.convertToHoursMinutes(msg.response.time.time) + "\n" +
29 | "**Total daylight (minutes):** " + msg.response.time.dayLengthMinutes + "\n" +
30 | "**Sunrise:** " + Tools.convertToHoursMinutes(msg.response.time.sunrise) + "\n" +
31 | "**Sunset:** " + Tools.convertToHoursMinutes(msg.response.time.sunset);
32 | Tools.print(title, description, channel);
33 | });
34 |
35 | return true;
36 | },
37 | };
38 |
--------------------------------------------------------------------------------
/commands/help.js:
--------------------------------------------------------------------------------
1 | const Tools = require("./../tools/tools.js");
2 |
3 | const prefix = Tools.readJSON("./config.json").general.prefix;
4 | const help = `\
5 | This command prints a help message.
6 |
7 | **For help of a specific command type**:
8 | ${prefix}help theCommand
9 | Example:
10 | ${prefix}help addDevice`
11 |
12 | module.exports = {
13 | name: "help",
14 | description: "Displays a help message.",
15 | help: help,
16 | execute(author, message, channel, args, discordBot, rustplus) {
17 | /* Read the config.json file. */
18 | let config = Tools.readJSON("./config.json");
19 |
20 | let commands = "";
21 | for (let command of discordBot.commands.keys()) {
22 | commands += command + "\n";
23 | }
24 |
25 | let title = "Help Information";
26 | let description = "Command prefix: **" + config.general.prefix + "**\n\n";
27 | description += "To get help for a specific command, write:\n" +
28 | "*" + config.general.prefix + "help command*";
29 |
30 | Tools.print(title, description + "\n**Available Commands:**\n" + commands);
31 | Tools.sendEmbed(channel, title, description, ["**Available Commands:**", commands]);
32 |
33 | return true;
34 | },
35 | };
36 |
--------------------------------------------------------------------------------
/commands/market.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Main = require("./../rustplusDiscordBot.js");
4 | const Tools = require("./../tools/tools.js");
5 |
6 | const thumbnailName = "vending_machine.png";
7 | const attachment = new Discord.MessageAttachment("./images/" + thumbnailName, thumbnailName);
8 |
9 | const prefix = Tools.readJSON("./config.json").general.prefix;
10 | const help = `\
11 | This command goes through all vending machines on the server and look for the specified item.
12 |
13 | **To look through all items on the market, type**:
14 | ${prefix}market
15 |
16 | **To look for a specific item, type**:
17 | ${prefix}market Assault Rifle
18 |
19 | **Or if you dont know the full name, part of the name will be fine**:
20 | ${prefix}market assa`
21 |
22 | module.exports = {
23 | name: "market",
24 | description: "Search for items for sale in vending machines all over the server.",
25 | help: help,
26 | execute(author, message, channel, args, discordBot, rustplus) {
27 | /* Read the config.json file. */
28 | let config = Tools.readJSON("./config.json");
29 |
30 | /* Send the rustplus.js request: getMapMarkers */
31 | rustplus.getMapMarkers((msg) => {
32 | Tools.print("REQUEST", "getMapMarkers");
33 |
34 | /* Validate that the response message does not include any errors. */
35 | if (!Tools.validateResponse(msg, channel)) {
36 | Tools.print("RESPONSE", "getMapMarkers\n" + JSON.stringify(msg));
37 | return false;
38 | }
39 |
40 | let items = Tools.readJSON("./tools/items.json");
41 |
42 | /* If args is not empty, that means the user is looking for something. */
43 | let originalSearchItemName = "";
44 | let searchItem = "";
45 | if (args.length !== 0) {
46 | originalSearchItemName = message.replace(config.general.prefix + "market ", "");
47 | searchItem = originalSearchItemName.toLowerCase();
48 | }
49 |
50 | let title = "Market Search";
51 | let description = "";
52 | if (searchItem !== "") {
53 | description = "The result of a market search for the item **" + originalSearchItemName + "**.";
54 | }
55 | else {
56 | description = "The result of a market search.";
57 | }
58 |
59 | let maxLength = 4000;
60 | let currentLength = title.length + description.length;
61 |
62 | let embed = new Discord.MessageEmbed()
63 | .setColor("#ce412b")
64 | .attachFiles(attachment)
65 | .setThumbnail("attachment://" + thumbnailName)
66 | .setURL(Main.GITHUB_URL)
67 | .setTitle(title)
68 | .setDescription(description);
69 |
70 |
71 | let resultsFound = false;
72 | for (let marker of msg.response.mapMarkers.markers) {
73 | if (marker.type === Tools.MarkerType.VendingMachine) {
74 | if (marker.hasOwnProperty("sellOrders")) {
75 | let field = marker.name;
76 | if (marker.name === "") {
77 | field = "A Shop";
78 | }
79 | let str = "";
80 |
81 | for (let order of marker.sellOrders) {
82 | if (order.amountInStock === 0) {
83 | continue;
84 | }
85 |
86 | let selling = (order.itemId in items) ? items[order.itemId].name : "Unknown";
87 | let quantity = order.quantity;
88 | let currency = (order.currencyId in items) ? items[order.currencyId].name : "Unknown";
89 | let costPerItem = order.costPerItem;
90 |
91 | /* If no specific item was provided. */
92 | if (searchItem === "") {
93 | resultsFound = true;
94 |
95 | str += quantity + "x **" + selling + "** for " + costPerItem + "x **" + currency
96 | + "**.\n";
97 | }
98 | else {
99 | /* Does the order contain the specified item in question? */
100 | if ((selling.toLowerCase()).includes(searchItem) ||
101 | (currency.toLowerCase()).includes(searchItem) ||
102 | Tools.similarity(searchItem, selling) >= 0.9 ||
103 | Tools.similarity(searchItem, currency) >= 0.9) {
104 | resultsFound = true;
105 | str += quantity + "x **" + selling + "** for " + costPerItem + "x **" + currency
106 | + "**.\n";
107 | }
108 | }
109 | }
110 |
111 | /* If no specified item was found in the shop. */
112 | if (str === "") {
113 | continue;
114 | }
115 | else {
116 | if ((currentLength + field.length + str.length) < maxLength) {
117 | currentLength += field.length + str.length;
118 | embed.addField(field, str);
119 | }
120 | else {
121 | /* Max size of embed have been reached, empty buffer and create new embed. */
122 | Tools.print(title.description);
123 | channel.send(embed);
124 |
125 | /* Clear the embed variable and replace with a fresh. */
126 | embed = new Discord.MessageEmbed()
127 | .setColor("#ce412b")
128 | .attachFiles(attachment)
129 | .setThumbnail("attachment://" + thumbnailName)
130 | .setURL(Main.GITHUB_URL)
131 | .setTitle(title)
132 | .setDescription(description);
133 |
134 | currentLength = title.length + description.length + field.length + str.length;
135 | embed.addField(field, str);
136 | }
137 | }
138 | }
139 | }
140 | }
141 |
142 | if (!resultsFound) {
143 | description = "No market items found named **" + originalSearchItemName + "**.\nTry to run the " +
144 | "command *" + config.general.prefix + "market* without any arguments to get all market items.";
145 | embed.setDescription(description);
146 | }
147 |
148 | Tools.print(title, description);
149 | channel.send(embed);
150 | });
151 |
152 | return true;
153 | },
154 | };
155 |
--------------------------------------------------------------------------------
/commands/removeAllDevices.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const help = `\
6 | This command will remove all registered devices in the devices.json located on the bot server.`
7 |
8 | module.exports = {
9 | name: "removeAllDevices",
10 | description: "Removes all devices from the devices.json file.",
11 | help: help,
12 | execute(author, message, channel, args, discordBot, rustplus) {
13 | /* Verify that there are no arguments. */
14 | if (args.length != 0) {
15 | Tools.print("ERROR", "No arguments required.", channel);
16 | return false;
17 | }
18 |
19 | /* Clear the devices.json from content. */
20 | fs.writeFile("./devices.json", JSON.stringify({}, null, 2), (err) => {
21 | if (err) throw err;
22 |
23 | Tools.print("Successfully Removed", "All devices were removed.", channel);
24 | });
25 |
26 | return true;
27 | },
28 | };
29 |
--------------------------------------------------------------------------------
/commands/removeDevice.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const Tools = require("./../tools/tools.js");
3 |
4 | const prefix = Tools.readJSON("./config.json").general.prefix;
5 | const help = `\
6 | This command will remove the specified device from devices.json located on the bot server.
7 |
8 | **To remove Smart Switch 'Switch1'**:
9 | ${prefix}removeDevice Switch1`
10 |
11 | module.exports = {
12 | name: "removeDevice",
13 | description: "Removes a device from the devices.json file.",
14 | help: help,
15 | execute(author, message, channel, args, discordBot, rustplus) {
16 | /* Read the config.json file. */
17 | let config = Tools.readJSON("./config.json");
18 |
19 | /* Verify that the number of arguments is 1. */
20 | if (args.length != 1) {
21 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
22 | "removeDevice @name.", channel);
23 | return false;
24 | }
25 |
26 | /* Read the devices.json file. */
27 | let devices = Tools.readJSON("./devices.json");
28 |
29 | if (devices.hasOwnProperty(args[0])) {
30 | delete devices[args[0]];
31 |
32 | /* Write the updated version of devices to devices.json. */
33 | fs.writeFile("./devices.json", JSON.stringify(devices, null, 2), (err) => {
34 | if (err) throw err;
35 |
36 | Tools.print("Successfully Removed", "**" + args[0] + "** was removed from devices.", channel);
37 | });
38 | }
39 | else {
40 | Tools.print("ERROR", "**" + args[0] + "** does not exist in devices.", channel);
41 | return false;
42 | }
43 |
44 | return true;
45 | },
46 | };
47 |
--------------------------------------------------------------------------------
/commands/sendTeamMessage.js:
--------------------------------------------------------------------------------
1 | const Tools = require("./../tools/tools.js");
2 |
3 | const prefix = Tools.readJSON("./config.json").general.prefix;
4 | const help = `\
5 | This command sends a team message in-game.
6 |
7 | **To send a team message In-Game**:
8 | ${prefix}sendTeamMessage theMessage
9 | Example:
10 | ${prefix}sendTeamMessage Hello there!`
11 |
12 | module.exports = {
13 | name: "sendTeamMessage",
14 | description: "Sends a message to the team in-game.",
15 | help: help,
16 | execute(author, message, channel, args, discordBot, rustplus) {
17 | /* Read the config.json file. */
18 | let config = Tools.readJSON("./config.json");
19 |
20 | /* Verify that the number of arguments is not 0, i.e. the message is empty. */
21 | if (args.length === 0) {
22 | Tools.print("ERROR", "Empty message.", channel);
23 | return false;
24 | }
25 |
26 | msg = message.replace(config.general.prefix + "sendTeamMessage ", "");
27 |
28 | let title = "Successfully Sent";
29 | let description = "[" + author + "] sent the message: **" + msg + "**.";
30 | rustplus.sendTeamMessage("[" + author + "] " + msg);
31 | Tools.print(title, description, channel);
32 | return true;
33 | },
34 | };
35 |
--------------------------------------------------------------------------------
/commands/setAlarmNotifications.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const prefix = Tools.readJSON("./config.json").general.prefix;
6 | const help = `\
7 | This command lets you set the Alarm Notifications to enable/disable.
8 |
9 | **To turn off Alarm Notifications**:
10 | ${prefix}setAlarmNotifications false
11 |
12 | **To turn on Alarm Notifications**:
13 | ${prefix}setAlarmNotifications true`
14 |
15 | module.exports = {
16 | name: "setAlarmNotifications",
17 | description: "Set Alarm Notifications enable/disable.",
18 | help: help,
19 | execute(author, message, channel, args, discordBot, rustplus) {
20 | /* Read the config.json file. */
21 | let config = Tools.readJSON("./config.json");
22 |
23 | /* Verify that the number of arguments is 1. */
24 | if (args.length != 1) {
25 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
26 | "setAlarmNotifications true.", channel);
27 | return false;
28 | }
29 |
30 | if (!Tools.isStringBool(args[0])) {
31 | Tools.print("ERROR", "Argument is not of boolean type.", channel);
32 | return false;
33 | }
34 |
35 | config.alarms.enabled = args[0];
36 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
37 |
38 | Tools.print("Successfully Set", "Alarm Notifications was set to **" + args[0] + "**.", channel);
39 |
40 | return true;
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/commands/setCargoShipNotifications.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const prefix = Tools.readJSON("./config.json").general.prefix;
6 | const help = `\
7 | This command lets you set the Cargo Ship Notifications to enable/disable.
8 |
9 | **To turn off Cargo Ship Notifications**:
10 | ${prefix}setCargoShipNotifications false
11 |
12 | **To turn on Cargo Ship Notifications**:
13 | ${prefix}setCargoShipNotifications true`
14 |
15 | module.exports = {
16 | name: "setCargoShipNotifications",
17 | description: "Set Cargo Ship Notifications enable/disable.",
18 | help: help,
19 | execute(author, message, channel, args, discordBot, rustplus) {
20 | /* Read the config.json file. */
21 | let config = Tools.readJSON("./config.json");
22 |
23 | /* Verify that the number of arguments is 1. */
24 | if (args.length != 1) {
25 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
26 | "setCargoShipNotifications true.", channel);
27 | return false;
28 | }
29 |
30 | if (!Tools.isStringBool(args[0])) {
31 | Tools.print("ERROR", "Argument is not of boolean type.", channel);
32 | return false;
33 | }
34 |
35 | config.notifications.cargoShip = args[0];
36 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
37 |
38 | Tools.print("Successfully Set", "Cargo Ship Notifications was set to **" + args[0] + "**.", channel);
39 |
40 | return true;
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/commands/setChinook47Notifications.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const prefix = Tools.readJSON("./config.json").general.prefix;
6 | const help = `\
7 | This command lets you set the Chinook 47 Notifications to enable/disable.
8 |
9 | **To turn off Chinook 47 Notifications**:
10 | ${prefix}setChinook47Notifications false
11 |
12 | **To turn on Chinook 47 Notifications**:
13 | ${prefix}setChinook47Notifications true`
14 |
15 | module.exports = {
16 | name: "setChinook47Notifications",
17 | description: "Set Chinook 47 Notifications enable/disable.",
18 | help: help,
19 | execute(author, message, channel, args, discordBot, rustplus) {
20 | /* Read the config.json file. */
21 | let config = Tools.readJSON("./config.json");
22 |
23 | /* Verify that the number of arguments is 1. */
24 | if (args.length != 1) {
25 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
26 | "setChinook47Notifications true.", channel);
27 | return false;
28 | }
29 |
30 | if (!Tools.isStringBool(args[0])) {
31 | Tools.print("ERROR", "Argument is not of boolean type.", channel);
32 | return false;
33 | }
34 |
35 | config.notifications.chinook47 = args[0];
36 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
37 |
38 | Tools.print("Successfully Set", "Chinook 47 Notifications was set to **" + args[0] + "**.", channel);
39 |
40 | return true;
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/commands/setCrateNotifications.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const prefix = Tools.readJSON("./config.json").general.prefix;
6 | const help = `\
7 | This command lets you set the Crate Notifications to enable/disable.
8 |
9 | **To turn off Crate Notifications**:
10 | ${prefix}setCrateNotifications false
11 |
12 | **To turn on Crate Notifications**:
13 | ${prefix}setCrateNotifications true`
14 |
15 | module.exports = {
16 | name: "setCrateNotifications",
17 | description: "Set Crate Spawn Notifications enable/disable.",
18 | help: help,
19 | execute(author, message, channel, args, discordBot, rustplus) {
20 | /* Read the config.json file. */
21 | let config = Tools.readJSON("./config.json");
22 |
23 | /* Verify that the number of arguments is 1. */
24 | if (args.length != 1) {
25 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
26 | "setCrateNotifications true.", channel);
27 | return false;
28 | }
29 |
30 | if (!Tools.isStringBool(args[0])) {
31 | Tools.print("ERROR", "Argument is not of boolean type.", channel);
32 | return false;
33 | }
34 |
35 | config.notifications.crate = args[0];
36 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
37 |
38 | Tools.print("Successfully Set", "Crate Spawn Notifications was set to **" + args[0] + "**.", channel);
39 |
40 | return true;
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/commands/setEntityValue.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const thumbnailName = "smart_switch.png";
6 | const attachment = new Discord.MessageAttachment("./images/" + thumbnailName, thumbnailName);
7 |
8 | const prefix = Tools.readJSON("./config.json").general.prefix;
9 | const help = `\
10 | This command lets you change the entity value of a Smart Switch.
11 |
12 | **To set the entity value of Smart Switch 'light' to false**:
13 | ${prefix}setEntityValue light false
14 |
15 | **To set the entity value of Smart Switch 'light' to true**:
16 | ${prefix}setEntityValue light true`
17 |
18 | module.exports = {
19 | name: "setEntityValue",
20 | description: "Set the value of a Smart Device.",
21 | help: help,
22 | execute(author, message, channel, args, discordBot, rustplus) {
23 | /* Read the config.json file. */
24 | let config = Tools.readJSON("./config.json");
25 |
26 | /* Verify that the number of arguments is 2. */
27 | if (args.length != 2) {
28 | Tools.print("ERROR", "2 arguments required. Example: " + config.general.prefix +
29 | "setEntityValue @name @value.", channel);
30 | return false;
31 | }
32 |
33 | /* Read the devices.json file. */
34 | let devices = Tools.readJSON("./devices.json");
35 |
36 | let value = false;
37 | if (args[1].toLowerCase() === "false") {
38 | value = false;
39 | }
40 | else {
41 | value = true;
42 | }
43 |
44 | let id;
45 | if (devices.hasOwnProperty(args[0])) {
46 | id = parseInt(devices[args[0]].id);
47 | }
48 | else {
49 | id = parseInt(args[0]);
50 | }
51 |
52 | /* Send the rustplus.js request: setEntityValue */
53 | rustplus.setEntityValue(id, value, (msg) => {
54 | Tools.print("REQUEST", "setEntityValue");
55 |
56 | /* Validate that the response message does not include any errors. */
57 | if (!Tools.validateResponse(msg, channel)) {
58 | Tools.print("RESPONSE", "setEntityValue\n" + JSON.stringify(msg));
59 | return false;
60 | }
61 |
62 | Tools.print("Successfully Set", "**" + args[0] + "** entity value set to: **" + value + "**",
63 | channel, null, attachment, thumbnailName);
64 | });
65 |
66 | return true;
67 | },
68 | };
69 |
--------------------------------------------------------------------------------
/commands/setExplosionNotifications.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const prefix = Tools.readJSON("./config.json").general.prefix;
6 | const help = `\
7 | This command lets you set the Explosion Notifications to enable/disable.
8 |
9 | **To turn off Explosion Notifications**:
10 | ${prefix}setExplosionNotifications false
11 |
12 | **To turn on Explosion Notifications**:
13 | ${prefix}setExplosionNotifications true`
14 |
15 | module.exports = {
16 | name: "setExplosionNotifications",
17 | description: "Set Explosion Notifications enable/disable.",
18 | help: help,
19 | execute(author, message, channel, args, discordBot, rustplus) {
20 | /* Read the config.json file. */
21 | let config = Tools.readJSON("./config.json");
22 |
23 | /* Verify that the number of arguments is 1. */
24 | if (args.length != 1) {
25 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
26 | "setExplosionNotifications true.", channel);
27 | return false;
28 | }
29 |
30 | if (!Tools.isStringBool(args[0])) {
31 | Tools.print("ERROR", "Argument is not of boolean type.", channel);
32 | return false;
33 | }
34 |
35 | config.notifications.explosion = args[0];
36 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
37 |
38 | Tools.print("Successfully Set", "Explosion Notifications was set to **" + args[0] + "**.", channel);
39 |
40 | return true;
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/commands/setInGameAlarmNotifications.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const prefix = Tools.readJSON("./config.json").general.prefix;
6 | const help = `\
7 | This command lets you set the In-Game Alarm Notifications to enable/disable.
8 |
9 | **To turn off In-Game Alarm Notifications**:
10 | ${prefix}setInGameAlarmNotifications false
11 |
12 | **To turn on In-Game Alarm Notifications**:
13 | ${prefix}setInGameAlarmNotifications true`
14 |
15 | module.exports = {
16 | name: "setInGameAlarmNotifications",
17 | description: "Set In-Game Alarm Notifications enable/disable.",
18 | help: help,
19 | execute(author, message, channel, args, discordBot, rustplus) {
20 | /* Read the config.json file. */
21 | let config = Tools.readJSON("./config.json");
22 |
23 | /* Verify that the number of arguments is 1. */
24 | if (args.length != 1) {
25 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
26 | "setInGameAlarmNotifications true.", channel);
27 | return false;
28 | }
29 |
30 | if (!Tools.isStringBool(args[0])) {
31 | Tools.print("ERROR", "Argument is not of boolean type.", channel);
32 | return false;
33 | }
34 |
35 | config.alarms.inGame = args[0];
36 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
37 |
38 | Tools.print("Successfully Set", "In-Game Alarm Notifications was set to **" + args[0] + "**.", channel);
39 |
40 | return true;
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/commands/setInGameCommands.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const prefix = Tools.readJSON("./config.json").general.prefix;
6 | const help = `\
7 | This command lets you set the In-Game commands ability to enable/disable.
8 |
9 | **To turn off In-Game commands**:
10 | ${prefix}setInGameCommands false
11 |
12 | **To turn on In-Game commands**:
13 | ${prefix}setInGameCommands true`
14 |
15 | module.exports = {
16 | name: "setInGameCommands",
17 | description: "Set In-Game commands enable/disable.",
18 | help: help,
19 | execute(author, message, channel, args, discordBot, rustplus) {
20 | /* Read the config.json file. */
21 | let config = Tools.readJSON("./config.json");
22 |
23 | /* Verify that the number of arguments is 1. */
24 | if (args.length != 1) {
25 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
26 | "setInGameCommands true.", channel);
27 | return false;
28 | }
29 |
30 | if (!Tools.isStringBool(args[0])) {
31 | Tools.print("ERROR", "Argument is not of boolean type.", channel);
32 | return false;
33 | }
34 |
35 | config.general.inGameCommands = args[0];
36 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
37 |
38 | Tools.print("Successfully Set", "In-Game commands was set to **" + args[0] + "**.", channel);
39 |
40 | return true;
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/commands/setInGameNotifications.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const prefix = Tools.readJSON("./config.json").general.prefix;
6 | const help = `\
7 | This command lets you set the In-Game Notifications to enable/disable.
8 |
9 | **To turn off In-Game Notifications**:
10 | ${prefix}setInGameNotifications false
11 |
12 | **To turn on In-Game Notifications**:
13 | ${prefix}setInGameNotifications true`
14 |
15 | module.exports = {
16 | name: "setInGameNotifications",
17 | description: "Set In-Game Notifications enable/disable.",
18 | help: help,
19 | execute(author, message, channel, args, discordBot, rustplus) {
20 | /* Read the config.json file. */
21 | let config = Tools.readJSON("./config.json");
22 |
23 | /* Verify that the number of arguments is 1. */
24 | if (args.length != 1) {
25 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
26 | "setInGameNotifications true.", channel);
27 | return false;
28 | }
29 |
30 | if (!Tools.isStringBool(args[0])) {
31 | Tools.print("ERROR", "Argument is not of boolean type.", channel);
32 | return false;
33 | }
34 |
35 | config.notifications.inGame = args[0];
36 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
37 |
38 | Tools.print("Successfully Set", "In-Game Notifications was set to **" + args[0] + "**.", channel);
39 |
40 | return true;
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/commands/setInGamePairingNotifications.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const prefix = Tools.readJSON("./config.json").general.prefix;
6 | const help = `\
7 | This command lets you set the In-Game Pairing Notifications to enable/disable.
8 |
9 | **To turn off In-Game Pairing Notifications**:
10 | ${prefix}setInGamePairingNotifications false
11 |
12 | **To turn on In-Game Pairing Notifications**:
13 | ${prefix}setInGamePairingNotifications true`
14 |
15 | module.exports = {
16 | name: "setInGamePairingNotifications",
17 | description: "Set In-Game Pairing Notifications enable/disable.",
18 | help: help,
19 | execute(author, message, channel, args, discordBot, rustplus) {
20 | /* Read the config.json file. */
21 | let config = Tools.readJSON("./config.json");
22 |
23 | /* Verify that the number of arguments is 1. */
24 | if (args.length != 1) {
25 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
26 | "setInGamePairingNotifications true.", channel);
27 | return false;
28 | }
29 |
30 | if (!Tools.isStringBool(args[0])) {
31 | Tools.print("ERROR", "Argument is not of boolean type.", channel);
32 | return false;
33 | }
34 |
35 | config.rustplus.inGamePairingNotifications = args[0];
36 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
37 |
38 | Tools.print("Successfully Set", "In-Game Pairing Notifications was set to **" + args[0] + "**.", channel);
39 |
40 | return true;
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/commands/setNotifications.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const prefix = Tools.readJSON("./config.json").general.prefix;
6 | const help = `\
7 | This command lets you set the Notifications to enable/disable.
8 |
9 | **To turn off Notifications**:
10 | ${prefix}setNotifications false
11 |
12 | **To turn on Notifications**:
13 | ${prefix}setNotifications true`
14 |
15 | module.exports = {
16 | name: "setNotifications",
17 | description: "Set Notifications enable/disable.",
18 | help: help,
19 | execute(author, message, channel, args, discordBot, rustplus) {
20 | /* Read the config.json file. */
21 | let config = Tools.readJSON("./config.json");
22 |
23 | /* Verify that the number of arguments is 1. */
24 | if (args.length != 1) {
25 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
26 | "setNotifications true.", channel);
27 | return false;
28 | }
29 |
30 | if (!Tools.isStringBool(args[0])) {
31 | Tools.print("ERROR", "Argument is not of boolean type.", channel);
32 | return false;
33 | }
34 |
35 | config.notifications.enabled = args[0];
36 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
37 |
38 | Tools.print("Successfully Set", "Notifications was set to **" + args[0] + "**.", channel);
39 |
40 | return true;
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/commands/setPairingNotifications.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const prefix = Tools.readJSON("./config.json").general.prefix;
6 | const help = `\
7 | This command lets you set the Pairing Notifications to enable/disable.
8 |
9 | **To turn off Pairing Notifications**:
10 | ${prefix}setPairingNotifications false
11 |
12 | **To turn on Pairing Notifications**:
13 | ${prefix}setPairingNotifications true`
14 |
15 | module.exports = {
16 | name: "setPairingNotifications",
17 | description: "Set Pairing Notifications enable/disable.",
18 | help: help,
19 | execute(author, message, channel, args, discordBot, rustplus) {
20 | /* Read the config.json file. */
21 | let config = Tools.readJSON("./config.json");
22 |
23 | /* Verify that the number of arguments is 1. */
24 | if (args.length != 1) {
25 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
26 | "setPairingNotifications true.", channel);
27 | return false;
28 | }
29 |
30 | if (!Tools.isStringBool(args[0])) {
31 | Tools.print("ERROR", "Argument is not of boolean type.", channel);
32 | return false;
33 | }
34 |
35 | config.rustplus.pairingNotifications = args[0];
36 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
37 |
38 | Tools.print("Successfully Set", "Pairing Notifications was set to **" + args[0] + "**.", channel);
39 |
40 | return true;
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/commands/setPrefix.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const help = `\
6 | This command lets you change the command prefix for the bot.
7 |
8 | **To change the prefix to / from !**:
9 | !setPrefix /`
10 |
11 | module.exports = {
12 | name: "setPrefix",
13 | description: "Set the command prefix.",
14 | help: help,
15 | execute(author, message, channel, args, discordBot, rustplus) {
16 | /* Read the config.json file. */
17 | let config = Tools.readJSON("./config.json");
18 |
19 | /* Verify that the number of arguments is 1. */
20 | if (args.length != 1) {
21 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix + "setPrefix !", channel);
22 | return false;
23 | }
24 |
25 | if (args[0].length !== 1) {
26 | Tools.print("ERROR", "A prefix has to be of length 1.", channel);
27 | return false;
28 | }
29 |
30 | config.general.prefix = args[0];
31 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
32 |
33 | Tools.print("Successfully Set", "New prefix was set: **" + args[0] + "**", channel);
34 |
35 | /* Set the BOT activity text. */
36 | discordBot.user.setActivity(args[0] + "help", { type: "LISTENING" });
37 |
38 | return true;
39 | },
40 | };
41 |
--------------------------------------------------------------------------------
/commands/setStorageMonitorNotifications.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const prefix = Tools.readJSON("./config.json").general.prefix;
6 | const help = `\
7 | This command lets you set the Storage Monitor Notifications to enable/disable.
8 |
9 | **To turn off Storage Monitor Notifications**:
10 | ${prefix}setStorageMonitorNotifications false
11 |
12 | **To turn on Storage Monitor Notifications**:
13 | ${prefix}setStorageMonitorNotifications true`
14 |
15 | module.exports = {
16 | name: "setStorageMonitorNotifications",
17 | description: "Set Storage Monitor Notifications enable/disable.",
18 | help: help,
19 | execute(author, message, channel, args, discordBot, rustplus) {
20 | /* Read the config.json file. */
21 | let config = Tools.readJSON("./config.json");
22 |
23 | /* Verify that the number of arguments is 1. */
24 | if (args.length != 1) {
25 | Tools.print("ERROR", "1 argument required. Example: " + config.general.prefix +
26 | "setStorageMonitorNotifications true.", channel);
27 | return false;
28 | }
29 |
30 | if (!Tools.isStringBool(args[0])) {
31 | Tools.print("ERROR", "Argument is not of boolean type.", channel);
32 | return false;
33 | }
34 |
35 | config.storageMonitors.enabled = args[0];
36 | fs.writeFileSync("./config.json", JSON.stringify(config, null, 2));
37 |
38 | Tools.print("Successfully Set", "Storage Monitor Notifications was set to **" + args[0] + "**.", channel);
39 |
40 | return true;
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/commands/turnOff.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const thumbnailName = "smart_switch.png";
6 | const attachment = new Discord.MessageAttachment("./images/" + thumbnailName, thumbnailName);
7 |
8 | const prefix = Tools.readJSON("./config.json").general.prefix;
9 | const help = `\
10 | This command lets you turn off Smart Switches.
11 |
12 | **To turn off Smart Switch 'turret'**:
13 | ${prefix}turnOff turret
14 |
15 | **To turn off Smart Switches 'turret1', 'turret2' and 'turret3'**:
16 | ${prefix}turnOff turret*
17 | or
18 | ${prefix}turnOff turret1 turret2 turret3
19 |
20 | **To turn off Smart Switch with entityId 1234567**:
21 | ${prefix}turnOff 1234567`
22 |
23 | module.exports = {
24 | name: "turnOff",
25 | description: "Turn off a Smart Switch.",
26 | help: help,
27 | execute(author, message, channel, args, discordBot, rustplus) {
28 | /* Read the config.json file. */
29 | let config = Tools.readJSON("./config.json");
30 |
31 | /* Verify that the number of arguments is at least 1. */
32 | if (args.length === 0) {
33 | Tools.print("ERROR", "At least 1 arguments required. Example: " + config.general.prefix +
34 | "turnOff @name/id.", channel);
35 | return false;
36 | }
37 |
38 | /* Read the devices.json file. */
39 | let devices = Tools.readJSON("./devices.json");
40 |
41 | let identifiedDevices = [];
42 | /* Parse arguments and find all matching devices. */
43 | for (let arg of args) {
44 | if (devices.hasOwnProperty(arg)) {
45 | identifiedDevices.push([arg, parseInt(devices[arg].id)]);
46 | }
47 | else if (arg.includes("*")) {
48 | for (let device in devices) {
49 | if (Tools.wildcardMatch(device, arg)) {
50 | identifiedDevices.push([device, parseInt(devices[device].id)]);
51 | }
52 | }
53 | }
54 | else {
55 | identifiedDevices.push([arg, parseInt(arg)]);
56 | }
57 | }
58 |
59 | let covered = [];
60 | let finalDevices = [];
61 | /* Remove duplicates from indentifiedDevices and place them in finalDevices. */
62 | for (let dev of identifiedDevices) {
63 | if (!covered.includes(dev[0])) {
64 | finalDevices.push(dev);
65 | covered.push(dev[0]);
66 | }
67 | }
68 |
69 | /* Call turnSmartSwitchOff on all devices in finalDevices. */
70 | for (let device of finalDevices) {
71 | /* Send the rustplus.js request: turnSmartSwitchOff */
72 | rustplus.turnSmartSwitchOff(device[1], (msg) => {
73 | Tools.print("REQUEST", "turnSmartSwitchOff");
74 |
75 | /* Validate that the response message does not include any errors. */
76 | if (!Tools.validateResponse(msg, channel)) {
77 | Tools.print("RESPONSE", "turnSmartSwitchOff\n" + JSON.stringify(msg));
78 | return false;
79 | }
80 |
81 | Tools.print("Successfully Turned Off", "**" + device[0] + " : " + device[1] +
82 | "** was turned off.", channel, null, attachment, thumbnailName);
83 | });
84 | }
85 |
86 | return true;
87 | },
88 | };
89 |
--------------------------------------------------------------------------------
/commands/turnOn.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const thumbnailName = "smart_switch.png";
6 | const attachment = new Discord.MessageAttachment("./images/" + thumbnailName, thumbnailName);
7 |
8 | const prefix = Tools.readJSON("./config.json").general.prefix;
9 | const help = `\
10 | This command lets you turn on Smart Switches.
11 |
12 | **To turn on Smart Switch 'turret'**:
13 | ${prefix}turnOn turret
14 |
15 | **To turn on Smart Switches 'turret1', 'turret2' and 'turret3'**:
16 | ${prefix}turnOn turret*
17 | or
18 | ${prefix}turnOn turret1 turret2 turret3
19 |
20 | **To turn on Smart Switch with entityId 1234567**:
21 | ${prefix}turnOn 1234567`
22 |
23 | module.exports = {
24 | name: "turnOn",
25 | description: "Turn on a Smart Switch.",
26 | help: help,
27 | execute(author, message, channel, args, discordBot, rustplus) {
28 | /* Read the config.json file. */
29 | let config = Tools.readJSON("./config.json");
30 |
31 | /* Verify that the number of arguments is at least 1. */
32 | if (args.length === 0) {
33 | Tools.print("ERROR", "At least 1 arguments required. Example: " + config.general.prefix +
34 | "turnOn @name/id.", channel);
35 | return false;
36 | }
37 |
38 | /* Read the devices.json file. */
39 | let devices = Tools.readJSON("./devices.json");
40 |
41 | let identifiedDevices = [];
42 | /* Parse arguments and find all matching devices. */
43 | for (let arg of args) {
44 | if (devices.hasOwnProperty(arg)) {
45 | identifiedDevices.push([arg, parseInt(devices[arg].id)]);
46 | }
47 | else if (arg.includes("*")) {
48 | for (let device in devices) {
49 | if (Tools.wildcardMatch(device, arg)) {
50 | identifiedDevices.push([device, parseInt(devices[device].id)]);
51 | }
52 | }
53 | }
54 | else {
55 | identifiedDevices.push([arg, parseInt(arg)]);
56 | }
57 | }
58 |
59 | let covered = [];
60 | let finalDevices = [];
61 | /* Remove duplicates from indentifiedDevices and place them in finalDevices. */
62 | for (let dev of identifiedDevices) {
63 | if (!covered.includes(dev[0])) {
64 | finalDevices.push(dev);
65 | covered.push(dev[0]);
66 | }
67 | }
68 |
69 | /* Call turnSmartSwitchOn on all devices in finalDevices. */
70 | for (let device of finalDevices) {
71 | /* Send the rustplus.js request: turnSmartSwitchOn */
72 | rustplus.turnSmartSwitchOn(device[1], (msg) => {
73 | Tools.print("REQUEST", "turnSmartSwitchOn");
74 |
75 | /* Validate that the response message does not include any errors. */
76 | if (!Tools.validateResponse(msg, channel)) {
77 | Tools.print("RESPONSE", "turnSmartSwitchOn\n" + JSON.stringify(msg));
78 | return false;
79 | }
80 |
81 | Tools.print("Successfully Turned On", "**" + device[0] + " : " + device[1] +
82 | "** was turned on.", channel, null, attachment, thumbnailName);
83 | });
84 | }
85 |
86 | return true;
87 | },
88 | };
89 |
--------------------------------------------------------------------------------
/commands/ver.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Main = require("./../rustplusDiscordBot.js");
4 | const Tools = require("./../tools/tools.js");
5 | const { version } = require("./../version.json");
6 |
7 | const help = `\
8 | This command prints this bots current version.`
9 |
10 | module.exports = {
11 | name: "ver",
12 | description: "Obtain the bot version.",
13 | help: help,
14 | execute(author, message, channel, args, discordBot, rustplus) {
15 | Tools.print("VERSION", version);
16 |
17 | const embed = new Discord.MessageEmbed()
18 | .setColor("#ce412b")
19 | .attachFiles(Main.THUMBNAIL_DEFAULT)
20 | .setThumbnail("attachment://rust_logo.png")
21 | .setURL(Main.GITHUB_URL + "/releases/tag/v" + version)
22 | .setTitle("RustPlus-Discord-Bot Version")
23 | .setDescription("**" + version + "**")
24 | .setFooter("By Alexemanuelol");
25 |
26 | channel.send(embed);
27 | },
28 | };
29 |
--------------------------------------------------------------------------------
/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "general": {
3 | "prefix": "!",
4 | "steamId": "",
5 | "reconnectAttempts": "30",
6 | "inGameCommands": "true"
7 | },
8 | "notifications": {
9 | "enabled": "true",
10 | "inGame": "true",
11 | "cargoShip": "true",
12 | "chinook47": "true",
13 | "crate": "false",
14 | "explosion": "true"
15 | },
16 | "alarms": {
17 | "enabled": "true",
18 | "inGame": "true"
19 | },
20 | "storageMonitors": {
21 | "enabled": "true"
22 | },
23 | "discord": {
24 | "token": "",
25 | "botSpamChannel": ""
26 | },
27 | "rustplus": {
28 | "fcmListener": "true",
29 | "pairingNotifications": "true",
30 | "inGamePairingNotifications": "true"
31 | },
32 | "rust": {
33 | "serverIp": "",
34 | "appPort": "",
35 | "playerToken": ""
36 | }
37 | }
--------------------------------------------------------------------------------
/devices.json:
--------------------------------------------------------------------------------
1 | {
2 | }
--------------------------------------------------------------------------------
/docs/documentation.md:
--------------------------------------------------------------------------------
1 | # **Documentation**
2 |
3 | ## **Commands**
4 |
5 | ### **addDevice**
6 | This command lets you add different devices to the devices.json located on the bot server.
7 |
8 | To add a Smart Switch:
9 |
10 | !addDevice nameOfSwitch entityId
11 | # Example:
12 | !addDevice switch1 1234567
13 |
14 | To add a Smart Alarm:
15 |
16 | !addDevice nameOfAlarm entityId
17 | # Example:
18 | !addDevice oilrig 1234567
19 |
20 | To add a Storage Monitor:
21 |
22 | !addDevice nameOfSM entityId
23 | # Example:
24 | !addDevice toolcupboard 1234567
25 |
26 | ### **devices**
27 | This command prints all the registered devices in the devices.json located on the bot server.
28 |
29 | ### **getCameraFrame**
30 | This command gathers a jpeg frame from a camera in-game and sends it to discord (**NOTE**: Feature not currently supported).
31 |
32 | Get a frame from 'CASINO' camera at Bandit Camp:
33 |
34 | !getCameraFrame CASINO 0
35 |
36 | ### **getEntityInfo**
37 | This command gathers information about a smart device and prints it to discord.
38 |
39 | To get the entity information from Smart Switch 1234567 (Made up):
40 |
41 | !getEntityInfo 1234567
42 |
43 | To get the entity information from Smart Alarm 'oilrig' defined in devices.json:
44 |
45 | !getEntityInfo oilrig
46 |
47 | ### **getInfo**
48 | This command prints information about the server.
49 |
50 | ### **getMap**
51 | This command gathers a jpeg image of the server map and all it's monuments and sends it to discord.
52 |
53 | ### **getMapMarkers**
54 | This command gathers all the map markers of the server map (**NOTE**: Currently not useful for anything by itself).
55 |
56 | ### **getSettings**
57 | This command gathers all the public settings from the config.json file and prints it to discord.
58 |
59 | ### **getTeamInfo**
60 | This command gathers information about the team and prints it to discord.
61 |
62 | ### **getTime**
63 | This command gathers the in-game time of the server and prints it to discord.
64 |
65 | ### **help**
66 | This command prints a help message.
67 |
68 | For help of a specific command type:
69 |
70 | !help theCommand
71 | # Example:
72 | !help addDevice
73 |
74 | ### **market**
75 | This command goes through all vending machines on the server and look for the specified item.
76 |
77 | To look through all items on the market, type:
78 |
79 | !market
80 |
81 | To look for a specific item, type:
82 |
83 | !market Assault Rifle
84 |
85 | Or if you dont know the full name, part of the name will be fine:
86 |
87 | !market assa
88 |
89 | ### **removeAllDevices**
90 | This command will remove all registered devices in the devices.json located on the bot server.
91 |
92 | ### **removeDevice**
93 | This command will remove the specified device from devices.json located on the bot server.
94 |
95 | To remove Smart Switch 'Switch1':
96 |
97 | !removeDevice Switch1
98 |
99 | ### **sendTeamMessage**
100 | This command sends a team message in-game.
101 |
102 | To send a team message In-Game:
103 |
104 | !sendTeamMessage theMessage
105 | # Example:
106 | !sendTeamMessage Hello there!
107 |
108 | ### **setAlarmNotifications**
109 | This command lets you set the Alarm Notifications to enable/disable.
110 |
111 | To turn off Alarm Notifications:
112 |
113 | !setAlarmNotifications false
114 |
115 | To turn on Alarm Notifications:
116 |
117 | !setAlarmNotifications true
118 |
119 | ### **setCargoShipNotifications**
120 | This command lets you set the Cargo Ship Notifications to enable/disable.
121 |
122 | To turn off Cargo Ship Notifications:
123 |
124 | !setCargoShipNotifications false
125 |
126 | To turn on Cargo Ship Notifications:
127 |
128 | !setCargoShipNotifications true
129 |
130 | ### **setChinook47Notifications**
131 | This command lets you set the Chinook 47 Notifications to enable/disable.
132 |
133 | To turn off Chinook 47 Notifications:
134 |
135 | !setChinook47Notifications false
136 |
137 | To turn on Chinook 47 Notifications:
138 |
139 | !setChinook47Notifications true
140 |
141 | ### **setCrateNotifications**
142 | This command lets you set the Crate Notifications to enable/disable.
143 |
144 | To turn off Crate Notifications:
145 |
146 | !setCrateNotifications false
147 |
148 | To turn on Crate Notifications:
149 |
150 | !setCrateNotifications true
151 |
152 | ### **setEntityValue**
153 | This command lets you change the entity value of a Smart Switch.
154 |
155 | To set the entity value of Smart Switch 'light' to false:
156 |
157 | !setEntityValue light false
158 |
159 | To set the entity value of Smart Switch 'light' to true:
160 |
161 | !setEntityValue light true
162 |
163 | ### **setExplosionNotifications**
164 | This command lets you set the Explosion Notifications to enable/disable.
165 |
166 | To turn off Explosion Notifications:
167 |
168 | !setExplosionNotifications false
169 |
170 | To turn on Explosion Notifications:
171 |
172 | !setExplosionNotifications true
173 |
174 | ### **setInGameAlarmNotifications**
175 | This command lets you set the In-Game Alarm Notifications to enable/disable.
176 |
177 | To turn off In-Game Alarm Notifications:
178 |
179 | !setInGameAlarmNotifications false
180 |
181 | To turn on In-Game Alarm Notifications:
182 |
183 | !setInGameAlarmNotifications true
184 |
185 | ### **setInGameCommands**
186 | This command lets you set the In-Game commands ability to enable/disable.
187 |
188 | To turn off In-Game commands:
189 |
190 | !setInGameCommands false
191 |
192 | To turn on In-Game commands:
193 |
194 | !setInGameCommands true
195 |
196 | ### **setInGameNotifications**
197 | This command lets you set the In-Game Notifications to enable/disable.
198 |
199 | To turn off In-Game Notifications:
200 |
201 | !setInGameNotifications false
202 |
203 | To turn on In-Game Notifications:
204 |
205 | !setInGameNotifications true
206 |
207 | ### **setInGamePairingNotifications**
208 | This command lets you set the In-Game Pairing Notifications to enable/disable.
209 |
210 | To turn off In-Game Pairing Notifications:
211 |
212 | !setInGamePairingNotifications false
213 |
214 | To turn on In-Game Pairing Notifications:
215 |
216 | !setInGamePairingNotifications true
217 |
218 | ### **setNotifications**
219 | This command lets you set the Notifications to enable/disable.
220 |
221 | To turn off Notifications:
222 |
223 | !setNotifications false
224 |
225 | To turn on Notifications:
226 |
227 | !setNotifications true
228 |
229 | ### **setPairingNotifications**
230 | This command lets you set the Pairing Notifications to enable/disable.
231 |
232 | To turn off Pairing Notifications:
233 |
234 | !setPairingNotifications false
235 |
236 | To turn on Pairing Notifications:
237 |
238 | !setPairingNotifications true
239 |
240 | ### **setPrefix**
241 | This command lets you change the command prefix for the bot.
242 |
243 | To change the prefix to / from !:
244 |
245 | !setPrefix /
246 |
247 | ### **setStorageMonitorNotifications**
248 | This command lets you set the Storage Monitor Notifications to enable/disable.
249 |
250 | To turn off Storage Monitor Notifications:
251 |
252 | !setStorageMonitorNotifications false
253 |
254 | To turn on Storage Monitor Notifications:
255 |
256 | !setStorageMonitorNotifications true
257 |
258 | ### **turnOff**
259 | This command lets you turn off Smart Switches.
260 |
261 | To turn off Smart Switch 'turret':
262 |
263 | !turnOff turret
264 |
265 | To turn off Smart Switches 'turret1', 'turret2' and 'turret3':
266 |
267 | !turnOff turret*
268 | # or
269 | !turnOff turret1 turret2 turret3
270 |
271 | To turn off Smart Switch with entityId 1234567:
272 |
273 | !turnOff 1234567
274 |
275 | ### **turnOn**
276 | This command lets you turn on Smart Switches.
277 |
278 | To turn on Smart Switch 'turret':
279 |
280 | !turnOn turret
281 |
282 | To turn on Smart Switches 'turret1', 'turret2' and 'turret3':
283 |
284 | !turnOn turret*
285 | # or
286 | !turnOn turret1 turret2 turret3
287 |
288 | To turn on Smart Switch with entityId 1234567:
289 |
290 | !turnOn 1234567
291 |
292 | ### **ver**
293 | This command prints this bots current version.
294 |
295 |
296 | ## **config.json**
297 |
298 | {
299 | "general": {
300 | "prefix": "!",
301 | "steamId": "1234567890",
302 | "reconnectAttempts": "30",
303 | "inGameCommands": "true"
304 | },
305 | "notifications": {
306 | "enabled": "true",
307 | "inGame": "true",
308 | "cargoShip": "true",
309 | "chinook47": "true",
310 | "crate": "false",
311 | "explosion": "true"
312 | },
313 | "alarms": {
314 | "enabled": "true",
315 | "inGame": "true"
316 | },
317 | "storageMonitors": {
318 | "enabled": "true"
319 | },
320 | "discord": {
321 | "token": "abcdefghijklmnopqrstuvwxyz",
322 | "botSpamChannel": "1234567890"
323 | },
324 | "rustplus": {
325 | "fcmListener": "true",
326 | "pairingNotifications": "true",
327 | "inGamePairingNotifications": "true"
328 | },
329 | "rust": {
330 | "serverIp": "111.222.333.444",
331 | "appPort": "12345",
332 | "playerToken": "1234567890"
333 | }
334 | }
335 |
336 | ### **general.prefix**
337 | This decides which prefix symbol should be used for the bot, length of the symbol has to be 1.
338 |
339 | ### **general.steamId**
340 | The Steam Id of the player that sets the bot up/ owns the rustplus.config.json file.
341 |
342 | ### **general.reconnectAttempts**
343 | The amount of reconnection attempts if the rust server were to go down. Default is 30, set it to 0 to have endless reconnection attempts.
344 |
345 | ### **general.inGameCommands**
346 | Having this set to true makes it possible to run bot commands from in-game team chat. If in the same team as the one who set up the bot.
347 |
348 | ### **notifications.enabled**
349 | Having this set to true allows notifications in discord. Notifications is either Cargo Ship spawn, Chinook 47 spawn, Crate detection or Explosion detection.
350 |
351 | ### **notifications.inGame**
352 | Having this set to true allows notifications to be forwarded to in-game team chat.
353 |
354 | ### **notifications.cargoShip**
355 | Having this set to true allows Cargo Ship spawn notifications.
356 |
357 | ### **notifications.chinook47**
358 | Having this set to true allows Chinook 47 spawn notifications.
359 |
360 | ### **notifications.crate**
361 | Having this set to true allows Crate detection notifications.
362 |
363 | ### **notifications.explosion**
364 | Having this set to true allows Explosion detection notifications.
365 |
366 | ### **alarms.enabled**
367 | Having this set to true allows alarms in discord. Alarms are triggered via in-game Smart Alarms.
368 |
369 | ### **alarms.inGame**
370 | Having this set to true allows alarms to be forwarded to in-game team chat.
371 |
372 | ### **storageMonitor.enabled**
373 | Having this set to true allows Storage Monitors to notify whenever it changes it's content and prints the content to discord. It also give you an approximation of time left before decaying if the storage monitor is set on a Tool Cupboard. NOTE: The time left before decaying seem to be one step behind so whenever something gets added or removed from it shows the time left before the content was moved.
374 |
375 | ### **discord.token**
376 | This is the Discord Bot Token.
377 |
378 | ### **discord.botSpamChannel**
379 | This is the Discord Text Channel that is used for notifications and alarms.
380 |
381 | ### **rustplus.fcmListener**
382 | Having this set to true allows pairing notifications as well as Smart Alarm functionality.
383 |
384 | ### **rustplus.pairingNotifications**
385 | Having this set to true allows pairing notifications in discord. Pairing notification messages include a entityId that needs to be registered via addDevice for Smart Switches and Storage Monitors. Smart Alarms automatically gets paired when pairing in-game.
386 |
387 | ### **rustplus.inGamePairingNotifications**
388 | Having this set to true allows pairing notifications to be forwarded to in-game team chat.
389 |
390 | ### **rust.serverIp**
391 | This is the Rust Server ip address.
392 |
393 | ### **rust.appPort**
394 | This is the Rust Server app port. Not the port used to connect to the server, this is the Rust+ port used for the Rust Server.
395 |
396 | ### **rust.playerToken**
397 | This is a Rust Server Player Token that is specific for every Rust Server you use the bot on. When you decide you want to use the bot on another server, you will need to run the *tools/external/copy_server_details_to_config.js* script again to update **serverIp**, **appPort** and **playerToken**.
398 |
--------------------------------------------------------------------------------
/fonts/PermanentMarker.fnt:
--------------------------------------------------------------------------------
1 | info face="Permanent Marker" size=16 bold=0 italic=0 charset="" unicode=1 stretchH=0 smooth=0 aa=1 padding=0,0,0,0 spacing=0,0 outline=0
2 | common lineHeight=24 base=18 scaleW=256 scaleH=256 pages=1 packed=0 alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0
3 | page id=0 file="PermanentMarker.png"
4 | chars count=95
5 | char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=6 page=0 chnl=15
6 | char id=33 x=24 y=80 width=5 height=13 xoffset=0 yoffset=6 xadvance=4 page=0 chnl=15
7 | char id=34 x=10 y=247 width=8 height=8 xoffset=1 yoffset=6 xadvance=8 page=0 chnl=15
8 | char id=35 x=30 y=66 width=12 height=13 xoffset=0 yoffset=6 xadvance=11 page=0 chnl=15
9 | char id=36 x=41 y=92 width=9 height=13 xoffset=0 yoffset=6 xadvance=8 page=0 chnl=15
10 | char id=37 x=0 y=178 width=11 height=12 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15
11 | char id=38 x=34 y=44 width=10 height=9 xoffset=0 yoffset=9 xadvance=10 page=0 chnl=15
12 | char id=39 x=24 y=224 width=4 height=8 xoffset=1 yoffset=6 xadvance=4 page=0 chnl=15
13 | char id=40 x=0 y=144 width=8 height=17 xoffset=0 yoffset=4 xadvance=6 page=0 chnl=15
14 | char id=41 x=0 y=161 width=8 height=17 xoffset=-2 yoffset=4 xadvance=6 page=0 chnl=15
15 | char id=42 x=23 y=44 width=11 height=9 xoffset=1 yoffset=6 xadvance=11 page=0 chnl=15
16 | char id=43 x=30 y=167 width=9 height=9 xoffset=0 yoffset=9 xadvance=9 page=0 chnl=15
17 | char id=44 x=27 y=198 width=4 height=6 xoffset=-2 yoffset=15 xadvance=3 page=0 chnl=15
18 | char id=45 x=39 y=13 width=9 height=4 xoffset=0 yoffset=12 xadvance=10 page=0 chnl=15
19 | char id=46 x=51 y=88 width=4 height=4 xoffset=-1 yoffset=15 xadvance=4 page=0 chnl=15
20 | char id=47 x=42 y=66 width=9 height=13 xoffset=-1 yoffset=6 xadvance=6 page=0 chnl=15
21 | char id=48 x=12 y=104 width=11 height=14 xoffset=0 yoffset=5 xadvance=11 page=0 chnl=15
22 | char id=49 x=23 y=104 width=5 height=13 xoffset=0 yoffset=6 xadvance=5 page=0 chnl=15
23 | char id=50 x=0 y=67 width=12 height=13 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15
24 | char id=51 x=34 y=116 width=10 height=12 xoffset=-1 yoffset=6 xadvance=9 page=0 chnl=15
25 | char id=52 x=11 y=131 width=10 height=14 xoffset=0 yoffset=5 xadvance=9 page=0 chnl=15
26 | char id=53 x=8 y=145 width=11 height=12 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
27 | char id=54 x=43 y=53 width=9 height=13 xoffset=-1 yoffset=6 xadvance=8 page=0 chnl=15
28 | char id=55 x=23 y=117 width=11 height=13 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
29 | char id=56 x=0 y=190 width=10 height=13 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
30 | char id=57 x=42 y=79 width=9 height=13 xoffset=0 yoffset=6 xadvance=8 page=0 chnl=15
31 | char id=58 x=19 y=227 width=5 height=8 xoffset=-1 yoffset=11 xadvance=4 page=0 chnl=15
32 | char id=59 x=21 y=203 width=6 height=10 xoffset=-2 yoffset=11 xadvance=4 page=0 chnl=15
33 | char id=60 x=8 y=168 width=11 height=8 xoffset=-1 yoffset=10 xadvance=10 page=0 chnl=15
34 | char id=61 x=18 y=247 width=9 height=7 xoffset=0 yoffset=10 xadvance=9 page=0 chnl=15
35 | char id=62 x=19 y=168 width=11 height=8 xoffset=-1 yoffset=10 xadvance=10 page=0 chnl=15
36 | char id=63 x=0 y=203 width=10 height=13 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
37 | char id=64 x=13 y=31 width=13 height=13 xoffset=-1 yoffset=6 xadvance=12 page=0 chnl=15
38 | char id=65 x=17 y=54 width=13 height=13 xoffset=-1 yoffset=6 xadvance=11 page=0 chnl=15
39 | char id=66 x=12 y=67 width=12 height=13 xoffset=-1 yoffset=6 xadvance=11 page=0 chnl=15
40 | char id=67 x=0 y=118 width=11 height=13 xoffset=-1 yoffset=6 xadvance=10 page=0 chnl=15
41 | char id=68 x=0 y=216 width=10 height=13 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
42 | char id=69 x=11 y=118 width=11 height=13 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15
43 | char id=70 x=26 y=31 width=13 height=13 xoffset=-1 yoffset=6 xadvance=9 page=0 chnl=15
44 | char id=71 x=38 y=0 width=14 height=13 xoffset=0 yoffset=6 xadvance=13 page=0 chnl=15
45 | char id=72 x=30 y=79 width=12 height=13 xoffset=-1 yoffset=6 xadvance=11 page=0 chnl=15
46 | char id=73 x=0 y=80 width=12 height=13 xoffset=-1 yoffset=6 xadvance=8 page=0 chnl=15
47 | char id=74 x=52 y=0 width=14 height=12 xoffset=-1 yoffset=6 xadvance=11 page=0 chnl=15
48 | char id=75 x=29 y=17 width=13 height=13 xoffset=0 yoffset=6 xadvance=12 page=0 chnl=15
49 | char id=76 x=0 y=229 width=10 height=13 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15
50 | char id=77 x=13 y=18 width=16 height=13 xoffset=0 yoffset=6 xadvance=16 page=0 chnl=15
51 | char id=78 x=30 y=53 width=13 height=13 xoffset=-1 yoffset=6 xadvance=11 page=0 chnl=15
52 | char id=79 x=12 y=80 width=12 height=13 xoffset=0 yoffset=6 xadvance=12 page=0 chnl=15
53 | char id=80 x=22 y=130 width=11 height=13 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15
54 | char id=81 x=25 y=0 width=13 height=14 xoffset=-1 yoffset=6 xadvance=12 page=0 chnl=15
55 | char id=82 x=0 y=131 width=11 height=13 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15
56 | char id=83 x=29 y=92 width=12 height=13 xoffset=0 yoffset=6 xadvance=9 page=0 chnl=15
57 | char id=84 x=39 y=30 width=13 height=13 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15
58 | char id=85 x=0 y=106 width=12 height=12 xoffset=0 yoffset=6 xadvance=11 page=0 chnl=15
59 | char id=86 x=0 y=242 width=10 height=13 xoffset=1 yoffset=6 xadvance=9 page=0 chnl=15
60 | char id=87 x=0 y=54 width=17 height=13 xoffset=0 yoffset=6 xadvance=16 page=0 chnl=15
61 | char id=88 x=0 y=93 width=12 height=13 xoffset=-1 yoffset=6 xadvance=10 page=0 chnl=15
62 | char id=89 x=10 y=190 width=10 height=13 xoffset=0 yoffset=6 xadvance=8 page=0 chnl=15
63 | char id=90 x=42 y=17 width=13 height=13 xoffset=-1 yoffset=6 xadvance=11 page=0 chnl=15
64 | char id=91 x=0 y=0 width=13 height=18 xoffset=-1 yoffset=3 xadvance=6 page=0 chnl=15
65 | char id=92 x=19 y=214 width=5 height=13 xoffset=0 yoffset=6 xadvance=6 page=0 chnl=15
66 | char id=93 x=13 y=0 width=12 height=18 xoffset=-5 yoffset=3 xadvance=6 page=0 chnl=15
67 | char id=94 x=44 y=43 width=8 height=10 xoffset=0 yoffset=6 xadvance=8 page=0 chnl=15
68 | char id=95 x=25 y=14 width=14 height=3 xoffset=-2 yoffset=16 xadvance=11 page=0 chnl=15
69 | char id=96 x=20 y=198 width=6 height=5 xoffset=4 yoffset=6 xadvance=12 page=0 chnl=15
70 | char id=97 x=11 y=176 width=11 height=11 xoffset=-1 yoffset=8 xadvance=9 page=0 chnl=15
71 | char id=98 x=41 y=105 width=10 height=11 xoffset=-1 yoffset=8 xadvance=9 page=0 chnl=15
72 | char id=99 x=52 y=30 width=9 height=11 xoffset=-1 yoffset=8 xadvance=8 page=0 chnl=15
73 | char id=100 x=10 y=236 width=8 height=11 xoffset=0 yoffset=8 xadvance=8 page=0 chnl=15
74 | char id=101 x=55 y=17 width=9 height=11 xoffset=0 yoffset=8 xadvance=8 page=0 chnl=15
75 | char id=102 x=20 y=156 width=11 height=11 xoffset=-1 yoffset=8 xadvance=7 page=0 chnl=15
76 | char id=103 x=8 y=157 width=12 height=11 xoffset=0 yoffset=8 xadvance=10 page=0 chnl=15
77 | char id=104 x=50 y=92 width=10 height=11 xoffset=-1 yoffset=8 xadvance=9 page=0 chnl=15
78 | char id=105 x=24 y=213 width=5 height=11 xoffset=0 yoffset=8 xadvance=5 page=0 chnl=15
79 | char id=106 x=19 y=145 width=12 height=11 xoffset=-1 yoffset=8 xadvance=9 page=0 chnl=15
80 | char id=107 x=10 y=203 width=11 height=11 xoffset=0 yoffset=8 xadvance=10 page=0 chnl=15
81 | char id=108 x=52 y=41 width=9 height=11 xoffset=0 yoffset=8 xadvance=9 page=0 chnl=15
82 | char id=109 x=28 y=105 width=13 height=11 xoffset=0 yoffset=8 xadvance=13 page=0 chnl=15
83 | char id=110 x=20 y=187 width=11 height=11 xoffset=-1 yoffset=8 xadvance=9 page=0 chnl=15
84 | char id=111 x=51 y=66 width=10 height=11 xoffset=0 yoffset=8 xadvance=10 page=0 chnl=15
85 | char id=112 x=52 y=52 width=9 height=11 xoffset=0 yoffset=8 xadvance=8 page=0 chnl=15
86 | char id=113 x=22 y=176 width=11 height=11 xoffset=-1 yoffset=8 xadvance=10 page=0 chnl=15
87 | char id=114 x=10 y=214 width=9 height=11 xoffset=0 yoffset=8 xadvance=9 page=0 chnl=15
88 | char id=115 x=51 y=77 width=10 height=11 xoffset=0 yoffset=8 xadvance=7 page=0 chnl=15
89 | char id=116 x=31 y=143 width=11 height=11 xoffset=0 yoffset=8 xadvance=8 page=0 chnl=15
90 | char id=117 x=13 y=44 width=10 height=10 xoffset=0 yoffset=8 xadvance=9 page=0 chnl=15
91 | char id=118 x=18 y=236 width=8 height=11 xoffset=1 yoffset=8 xadvance=8 page=0 chnl=15
92 | char id=119 x=12 y=93 width=14 height=11 xoffset=0 yoffset=8 xadvance=13 page=0 chnl=15
93 | char id=120 x=33 y=130 width=11 height=11 xoffset=-1 yoffset=8 xadvance=8 page=0 chnl=15
94 | char id=121 x=10 y=225 width=9 height=11 xoffset=0 yoffset=8 xadvance=6 page=0 chnl=15
95 | char id=122 x=31 y=154 width=11 height=11 xoffset=-1 yoffset=8 xadvance=9 page=0 chnl=15
96 | char id=123 x=0 y=18 width=13 height=18 xoffset=0 yoffset=3 xadvance=7 page=0 chnl=15
97 | char id=124 x=24 y=67 width=6 height=13 xoffset=0 yoffset=6 xadvance=5 page=0 chnl=15
98 | char id=125 x=0 y=36 width=13 height=18 xoffset=-5 yoffset=3 xadvance=8 page=0 chnl=15
99 | char id=126 x=48 y=13 width=9 height=4 xoffset=0 yoffset=11 xadvance=9 page=0 chnl=15
100 | kernings count=0
101 |
--------------------------------------------------------------------------------
/fonts/PermanentMarker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/fonts/PermanentMarker.png
--------------------------------------------------------------------------------
/images/cargoShip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/cargoShip.png
--------------------------------------------------------------------------------
/images/cargo_ship_body.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/cargo_ship_body.png
--------------------------------------------------------------------------------
/images/chinook47.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/chinook47.png
--------------------------------------------------------------------------------
/images/chinook_map_blades.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/chinook_map_blades.png
--------------------------------------------------------------------------------
/images/chinook_map_body.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/chinook_map_body.png
--------------------------------------------------------------------------------
/images/crate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/crate.png
--------------------------------------------------------------------------------
/images/explosion_marker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/explosion_marker.png
--------------------------------------------------------------------------------
/images/player.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/player.png
--------------------------------------------------------------------------------
/images/rust_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/rust_logo.png
--------------------------------------------------------------------------------
/images/shop_green.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/shop_green.png
--------------------------------------------------------------------------------
/images/smart_alarm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/smart_alarm.png
--------------------------------------------------------------------------------
/images/smart_switch.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/smart_switch.png
--------------------------------------------------------------------------------
/images/storage_monitor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/storage_monitor.png
--------------------------------------------------------------------------------
/images/train_tunnels.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/train_tunnels.png
--------------------------------------------------------------------------------
/images/vending_machine.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/images/vending_machine.png
--------------------------------------------------------------------------------
/notifications/cargoShip.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const thumbnailName = "cargoShip.png";
6 | const attachment = new Discord.MessageAttachment("./images/" + thumbnailName, thumbnailName);
7 |
8 | var cargoActive = false;
9 |
10 | module.exports = {
11 | name: "cargoShip",
12 | description: "Notification function for cargoShip active/inactive.",
13 | execute(message, channel, discordBot, rustplus) {
14 | /* Read the config.json file. */
15 | let config = Tools.readJSON("./config.json");
16 |
17 | if (config.notifications.cargoShip !== "true") return;
18 |
19 | if (cargoActive === false) {
20 | for (let marker of message.response.mapMarkers.markers) {
21 | if (marker.type === Tools.MarkerType.CargoShip) {
22 | cargoActive = true;
23 | break;
24 | }
25 | }
26 |
27 | if (cargoActive) {
28 | if (config.notifications.inGame === "true") {
29 | Tools.print("NOTIFICATION", "Cargo Ship is active.", channel, rustplus, attachment, thumbnailName);
30 | }
31 | else {
32 | Tools.print("NOTIFICATION", "Cargo Ship is active.", channel, null, attachment, thumbnailName);
33 | }
34 | }
35 | }
36 | else {
37 | let cargoLeft = true;
38 | for (let marker of message.response.mapMarkers.markers) {
39 | if (marker.type === Tools.MarkerType.CargoShip) {
40 | cargoLeft = false;
41 | break;
42 | }
43 | }
44 |
45 | if (cargoLeft) {
46 | cargoActive = false;
47 | if (config.notifications.inGame === "true") {
48 | Tools.print("NOTIFICATION", "Cargo Ship just despawned.", channel, rustplus, attachment, thumbnailName);
49 | }
50 | else {
51 | Tools.print("NOTIFICATION", "Cargo Ship just despawned.", channel, null, attachment, thumbnailName);
52 | }
53 | }
54 | }
55 |
56 | return true;
57 | },
58 | };
59 |
--------------------------------------------------------------------------------
/notifications/chinook47.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const thumbnailName = "chinook47.png";
6 | const attachment = new Discord.MessageAttachment("./images/" + thumbnailName, thumbnailName);
7 |
8 | var numberOfActiveChinook = 0;
9 |
10 | module.exports = {
11 | name: "chinook47",
12 | description: "Notification function for chinook 47 active/inactive.",
13 | execute(message, channel, discordBot, rustplus) {
14 | /* Read the config.json file. */
15 | let config = Tools.readJSON("./config.json");
16 |
17 | if (config.notifications.chinook47 !== "true") return;
18 |
19 | let chinookCounter = 0;
20 |
21 | for (let marker of message.response.mapMarkers.markers) {
22 | if (marker.type === Tools.MarkerType.CH47) {
23 | chinookCounter++;
24 | }
25 | }
26 |
27 | if (chinookCounter > numberOfActiveChinook) {
28 | let title = "NOTIFICATION";
29 | let description = "Chinook 47 is active. Oilrig might've been triggered or CH47 is ready to drop off a crate at a monument.";
30 | if (config.notifications.inGame === "true") {
31 | Tools.print(title, description, channel, rustplus, attachment, thumbnailName);
32 | }
33 | else {
34 | Tools.print(title, description, channel, null, attachment, thumbnailName);
35 | }
36 | }
37 |
38 | numberOfActiveChinook = chinookCounter;
39 |
40 | return true;
41 | },
42 | };
--------------------------------------------------------------------------------
/notifications/crate.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const thumbnailName = "crate.png";
6 | const attachment = new Discord.MessageAttachment("./images/" + thumbnailName, thumbnailName);
7 |
8 | var numberOfCurrentCrates = 0;
9 |
10 | module.exports = {
11 | name: "crate",
12 | description: "Notification function for crate spawn.",
13 | execute(message, channel, discordBot, rustplus) {
14 | /* Read the config.json file. */
15 | let config = Tools.readJSON("./config.json");
16 |
17 | if (config.notifications.crate !== "true") return;
18 |
19 | let crateCounter = 0;
20 |
21 | for (let marker of message.response.mapMarkers.markers) {
22 | if (marker.type === Tools.MarkerType.Crate) {
23 | crateCounter++;
24 | }
25 | }
26 |
27 | if (crateCounter > numberOfCurrentCrates) {
28 | let title = "NOTIFICATION";
29 | let description = "A Crate just spawned somewhere on the map.";
30 | if (config.notifications.inGame === "true") {
31 | Tools.print(title, description, channel, rustplus, attachment, thumbnailName);
32 | }
33 | else {
34 | Tools.print(title, description, channel, null, attachment, thumbnailName);
35 | }
36 | }
37 |
38 | numberOfCurrentCrates = crateCounter;
39 |
40 | return true;
41 | },
42 | };
--------------------------------------------------------------------------------
/notifications/explosion.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 |
3 | const Tools = require("./../tools/tools.js");
4 |
5 | const thumbnailName = "explosion_marker.png";
6 | const attachment = new Discord.MessageAttachment("./images/" + thumbnailName, thumbnailName);
7 |
8 | var numberOfExplosions = 0;
9 |
10 | module.exports = {
11 | name: "explosion",
12 | description: "Notification function for explosion detected.",
13 | execute(message, channel, discordBot, rustplus) {
14 | /* Read the config.json file. */
15 | let config = Tools.readJSON("./config.json");
16 |
17 | if (config.notifications.explosion !== "true") return;
18 |
19 | let explosionCounter = 0;
20 |
21 | for (let marker of message.response.mapMarkers.markers) {
22 | if (marker.type === Tools.MarkerType.Explosion) {
23 | explosionCounter++;
24 | }
25 | }
26 |
27 | if (explosionCounter > numberOfExplosions) {
28 | let title = "NOTIFICATION";
29 | let description = "Explosion detected. Patrol Helicopter or Bradley APC have been taken down.";
30 | if (config.notifications.inGame === "true") {
31 | Tools.print(title, description, channel, rustplus, attachment, thumbnailName);
32 | }
33 | else {
34 | Tools.print(title, description, channel, null, attachment, thumbnailName);
35 | }
36 | }
37 |
38 | numberOfExplosions = explosionCounter;
39 |
40 | return true;
41 | },
42 | };
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rustplus-discord-bot",
3 | "version": "1.0.0",
4 | "description": "TBD",
5 | "main": "bot.js",
6 | "scripts": {
7 | "test": "TBD"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/alexemanuelol/RustPlus-Discord-Bot.git"
12 | },
13 | "author": "Alexemanuelol",
14 | "license": "SEE LICENSE IN LICENSE",
15 | "bugs": {
16 | "url": "https://github.com/alexemanuelol/RustPlus-Discord-Bot/issues"
17 | },
18 | "homepage": "https://github.com/alexemanuelol/RustPlus-Discord-Bot#readme",
19 | "dependencies": {
20 | "discord.js": "^12.5.3",
21 | "rustplus.js": "github:liamcottle/rustplus.js",
22 | "jimp": "^0.16.1",
23 | "push-receiver": "^2.1.0"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/rustplusDiscordBot.js:
--------------------------------------------------------------------------------
1 | const Discord = require("discord.js");
2 | const RustPlus = require("rustplus.js");
3 | const fs = require("fs");
4 |
5 | const Tools = require("./tools/tools.js");
6 | const FcmListener = require("./tools/fcmListener.js");
7 |
8 | exports.THUMBNAIL_DEFAULT = new Discord.MessageAttachment("./images/rust_logo.png", "rust_logo.png");
9 | exports.GITHUB_URL = "https://github.com/alexemanuelol/RustPlus-Discord-Bot";
10 | const storageAttachment = new Discord.MessageAttachment("./images/storage_monitor.png", "storage_monitor.png");
11 |
12 | var connected = false;
13 |
14 | function mapMarkerPolling() {
15 | if (!connected) {
16 | /* The connection must be closed. Continue polling till connected again. */
17 | setTimeout(mapMarkerPolling, 10000);
18 | return;
19 | }
20 |
21 | /* Send the rustplus.js request: getMapMarkers */
22 | rustplus.getMapMarkers((msg) => {
23 | Tools.print("mapMarkerPolling", "Poll");
24 |
25 | /* Validate that the response message does not include any errors. */
26 | if (!Tools.validateResponse(msg, null)) {
27 | Tools.print("RESPONSE", "getMapMarkers\n" + JSON.stringify(msg));
28 | return false;
29 | }
30 |
31 | /* Read the config.json file. */
32 | config = Tools.readJSON("./config.json");
33 |
34 | if (config.notifications.enabled === "true") {
35 | let channel = discordBot.channels.cache.get(config.discord.botSpamChannel);
36 | if (typeof (channel) === "undefined") {
37 | Tools.print("ERROR", "botSpamChannel is invalid in config.json.");
38 | }
39 | else {
40 | /* Update notifications */
41 | for (const notification of notifications) {
42 | notification.execute(msg, channel, discordBot, rustplus);
43 | }
44 | }
45 | }
46 | });
47 |
48 | setTimeout(mapMarkerPolling, 10000);
49 | }
50 |
51 | function reconnectRustplus() {
52 | Tools.print("RECONNECTING", "Reconnecting Attempt " + (reconnectAttempts + 1) + "...");
53 | reconnectAttempts += 1;
54 | reconnection = true;
55 | rustplus.disconnect();
56 | rustplus.connect();
57 | }
58 |
59 | function destroyBot() {
60 | rustplus.disconnect();
61 | discordBot.destroy();
62 | process.exit(1);
63 | }
64 |
65 | function setFcmReady() {
66 | Tools.print("ATTENTION", "Listening for FCM Notifications.");
67 | FcmListener.fcmReady = true;
68 | }
69 |
70 | function parseCommand(author, message, channel, inGameCall = false) {
71 | /* The connection must be closed. Do nothing. */
72 | if (!connected) {
73 | return;
74 | }
75 |
76 | /* Read the config.json file. */
77 | config = Tools.readJSON("./config.json");
78 |
79 | if (inGameCall === true && config.general.inGameCommands === "false") {
80 | /* In-Game commands is not possible. */
81 | return;
82 | }
83 |
84 | /* If it does not start with the command prefix or if message comes from another bot, ignore. */
85 | if (!message.startsWith(config.general.prefix)) return;
86 |
87 | /* Obtain additional arguments from the command. */
88 | const args = message.slice(config.general.prefix.length).trim().split(/ +/);
89 |
90 | /* Obtain the actual command name. */
91 | const command = args.shift();
92 |
93 | /* If the command does not exist, ignore. */
94 | if (!discordBot.commands.has(command)) return;
95 |
96 | /* Check if it is a help command with arguments. */
97 | if (command === "help" && args.length === 1 && discordBot.commands.has(args[0])) {
98 | Tools.print("Help " + args[0], discordBot.commands.get(args[0]).help, channel);
99 | return;
100 | }
101 |
102 | if (inGameCall) {
103 | channel.send("**" + author + "** just called command from in-game: **" + message + "**");
104 | }
105 |
106 | try {
107 | /* Execute the command. */
108 | discordBot.commands.get(command).execute(author, message, channel, args, discordBot, rustplus);
109 | }
110 | catch (error) {
111 | Tools.print("ERROR", error, channel);
112 | }
113 | }
114 |
115 | /* Read the config.json file. */
116 | var config = Tools.readJSON("./config.json");
117 |
118 | /* Check if fcmListener is enabled in config and if the rustplus.config.json file exist. */
119 | if (config.rustplus.fcmListener === "true") {
120 | if (fs.existsSync("./rustplus.config.json")) {
121 | Tools.print("SUCCESS", "rustplus.config.json file was found!");
122 | }
123 | else {
124 | Tools.print("ERROR", "rustplus.config.json file does not exist inside root folder.\n" +
125 | "Try running the command: 'npx @liamcottle/rustplus.js fcm-register' and then place the output " +
126 | "'rustplus.config.json' file in the root folder of the RustPlus-Discord-Bot.");
127 | process.exit(1);
128 | }
129 | }
130 |
131 |
132 | /*
133 | * DISCORD
134 | */
135 |
136 | /* Create an instance of a discord client. */
137 | const discordBot = new Discord.Client();
138 | discordBot.commands = new Discord.Collection();
139 | var notifications = [];
140 |
141 | /* Extract all the command files from the commands directory. */
142 | const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
143 | /* Add a new item to the Collection. Key = command name, Value = the exported module. */
144 | for (const file of commandFiles) {
145 | const command = require("./commands/" + file);
146 | discordBot.commands.set(command.name, command);
147 | }
148 |
149 | /* Extract all the notification files from the notifications directory. */
150 | const notificationFiles = fs.readdirSync("./notifications").filter(file => file.endsWith(".js"));
151 | /* Add the file to notifications list. */
152 | for (const file of notificationFiles) {
153 | const notification = require("./notifications/" + file);
154 | notifications.push(notification);
155 | }
156 |
157 | discordBot.on("ready", () => {
158 | Tools.print("DISCORD", "Logged in as " + discordBot.user.tag + "!");
159 |
160 | /* Read the config.json file. */
161 | config = Tools.readJSON("./config.json");
162 |
163 | /* Set the BOT activity text. */
164 | discordBot.user.setActivity(config.general.prefix + "help", { type: "LISTENING" });
165 |
166 | /* Start pairing listener. */
167 | if (config.rustplus.fcmListener === "true") {
168 | FcmListener.fcmListener(discordBot, rustplus);
169 | setTimeout(setFcmReady, 3000);
170 | }
171 | });
172 |
173 | /* Called whenever a new message is sent in the guild. */
174 | discordBot.on("message", message => {
175 | /* If messages comes from another bot, ignore */
176 | if (message.author.bot) return;
177 |
178 | parseCommand(message.author.username, message.content, message.channel);
179 | });
180 |
181 | /* Login to the discord bot. */
182 | discordBot.login(config.discord.token);
183 |
184 |
185 | /*
186 | * RUSTPLUS
187 | */
188 |
189 | /* Create an instance of RustPlus */
190 | var rustplus = new RustPlus(config.rust.serverIp, config.rust.appPort, config.general.steamId,
191 | config.rust.playerToken);
192 |
193 | var reconnectAttempts = 0;
194 | var reconnection = false;
195 |
196 | /* Wait until connected before sending commands. */
197 | rustplus.on('connected', () => {
198 | /* RustPlus-Discord-Bot now enabled! */
199 | connected = true;
200 | reconnectAttempts = 0;
201 |
202 | if (reconnection) {
203 | reconnection = false;
204 | let channel = discordBot.channels.cache.get(config.discord.botSpamChannel);
205 |
206 | if (typeof (channel) === "undefined") {
207 | Tools.print("ERROR", "discordBotSpamChannel is invalid in config.json.");
208 | return;
209 | }
210 |
211 | Tools.print("Reconnection Successful", "Reconnection to the rust server was successful!", channel);
212 | }
213 | else {
214 | /* Go through all devices in devices.json to enable broadcast. */
215 | Tools.print("DEVICES", "Go through devices.json and validate.");
216 | let devices = Tools.readJSON("./devices.json");
217 | for (let device in devices) {
218 | rustplus.getEntityInfo(parseInt(devices[device].id), (msg) => {
219 | if (msg.response.hasOwnProperty("error")) {
220 | Tools.print("DEVICES", device + " : " + parseInt(devices[device].id) + " is INVALID.");
221 | }
222 | else {
223 | Tools.print("DEVICES", device + " : " + parseInt(devices[device].id) + " is VALID.");
224 | }
225 | });
226 | }
227 | }
228 | });
229 |
230 | /* Whenever the rust server disconnects. */
231 | rustplus.on("disconnected", () => {
232 | let channel = discordBot.channels.cache.get(config.discord.botSpamChannel);
233 |
234 | if (connected) {
235 | connected = false;
236 |
237 | if (typeof (channel) === "undefined") {
238 | Tools.print("ERROR", "discordBotSpamChannel is invalid in config.json.");
239 | return;
240 | }
241 |
242 | Tools.print("ATTENTION", "RustPlus-Discord-Bot lost connection to the rust server... " +
243 | "Will attempt to reconnect...", channel);
244 | }
245 |
246 | if ((reconnectAttempts === parseInt(config.general.reconnectAttempts)) &&
247 | (parseInt(config.general.reconnectAttempts) !== 0)) {
248 | Tools.print("Reconnection Failed", "RustPlus-Discord-Bot failed to reconnect to the rust server, exiting...", channel);
249 | setTimeout(destroyBot, 3000);
250 | return;
251 | }
252 |
253 | reconnectRustplus();
254 | });
255 |
256 | /* Whenever an error occurs. */
257 | rustplus.on("error", (err) => {
258 | Tools.print("ERROR", err);
259 | });
260 |
261 | rustplus.on("message", (msg) => {
262 | if (msg.hasOwnProperty("broadcast")) {
263 | config = Tools.readJSON("./config.json");
264 |
265 | if (msg.broadcast.hasOwnProperty("teamMessage")) {
266 | Tools.print("BROADCAST", "teamMessage received.");
267 |
268 | let message = msg.broadcast.teamMessage.message.message;
269 | let author = msg.broadcast.teamMessage.message.name;
270 | let channel = discordBot.channels.cache.get(config.discord.botSpamChannel);
271 |
272 | if (typeof (channel) === "undefined") {
273 | Tools.print("ERROR", "discordBotSpamChannel is invalid in config.json.");
274 | return;
275 | }
276 |
277 | parseCommand(author, message, channel, true);
278 | }
279 | else if (msg.broadcast.hasOwnProperty("entityChanged")) {
280 | Tools.print("BROADCAST", "entityChanged triggered.");
281 |
282 | let devices = Tools.readJSON("./devices.json");
283 | let channel = discordBot.channels.cache.get(config.discord.botSpamChannel);
284 |
285 | if (typeof (channel) === "undefined") {
286 | Tools.print("ERROR", "discordBotSpamChannel is invalid in config.json.");
287 | return;
288 | }
289 |
290 | for (let device in devices) {
291 | if (devices[device].id === msg.broadcast.entityChanged.entityId) {
292 | if (devices[device].type === 1) { /* Smart Switch */
293 | break;
294 | }
295 | else if (devices[device].type === 2) { /* Smart Alarm */
296 | break;
297 | }
298 | else if (devices[device].type === 3) { /* Storage Monitor */
299 | if (config.storageMonitors.enabled === "false") break;
300 |
301 | /* Make sure that we only trigger on one of the two, either true or false. */
302 | if (msg.broadcast.entityChanged.payload.value === false) {
303 | let items = Tools.readJSON("./tools/items.json");
304 | let summed = {};
305 |
306 | if (msg.broadcast.entityChanged.payload.hasOwnProperty("items")) {
307 | for (let item of msg.broadcast.entityChanged.payload.items) {
308 | if (item.itemId in summed) {
309 | summed[item.itemId] += item.quantity;
310 | }
311 | else {
312 | summed[item.itemId] = item.quantity;
313 | }
314 | }
315 | }
316 |
317 | let title = "Storage Monitor";
318 | let description = "";
319 | const embed = new Discord.MessageEmbed()
320 | .setColor("#ce412b")
321 | .attachFiles(storageAttachment)
322 | .setThumbnail("attachment://storage_monitor.png")
323 | .setURL(this.GITHUB_URL)
324 | .setTitle(title);
325 |
326 | /* If a 'Tool Cupboard'. */
327 | if (msg.broadcast.entityChanged.payload.capacity === 24) {
328 | description = "Content of the Tool Cupboard **" + device + "** have changed.\n";
329 | timeLeft = msg.broadcast.entityChanged.payload.protectionExpiry;
330 | description += "Time left before decay: ";
331 |
332 | if (timeLeft === 0) {
333 | description += "**DECAYING**";
334 | }
335 | else {
336 | let day = 86400;
337 | let hour = 3600;
338 | let minute = 60;
339 |
340 | let totSeconds = Math.floor((Tools.convertUnixTimestampToDate(timeLeft) - Date.now()) / 1000);
341 | let days = Math.floor(totSeconds / day);
342 | let hours = Math.floor((totSeconds - days * day) / hour);
343 | let minutes = Math.floor((totSeconds - days * day - hours * hour) / minute);
344 | let seconds = totSeconds - days * day - hours * hour - minutes * minute;
345 |
346 | description += "**" + days + "d " + hours + "h " + minutes + "m " + seconds + "s**";
347 | }
348 | }
349 | /* If a 'Large Wood Box' or a 'Vending Machine'. */
350 | else if (msg.broadcast.entityChanged.payload.capacity === 30) {
351 | description = "Content of the Large Wood Box/ Vending Machine **" + device +
352 | "** have changed.";
353 | }
354 |
355 | embed.setDescription(description)
356 |
357 | let field = "**Items in '" + device + "':**";
358 | let str = "";
359 | for (let item in summed) {
360 | if (item in items) {
361 | str += summed[item] + "x of **" + items[item].name + "**\n";
362 | }
363 | else {
364 | str += summed[item] + "x of **Unknown Item**\n";
365 | }
366 | }
367 |
368 | if (str === "") {
369 | str = "No items.";
370 | }
371 |
372 | description += "\n" + field + "\n" + str;
373 | embed.addField(field, str);
374 |
375 | Tools.print(title, description);
376 | channel.send(embed);
377 | }
378 | break;
379 | }
380 |
381 | }
382 | }
383 | }
384 | }
385 | });
386 |
387 | /* Connect to the rust server */
388 | rustplus.connect();
389 |
390 | /* Start the map marker polling */
391 | setTimeout(mapMarkerPolling, 10000);
392 |
--------------------------------------------------------------------------------
/rustplusDiscordBot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/rustplusDiscordBot.png
--------------------------------------------------------------------------------
/screenshots/cargoShip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/screenshots/cargoShip.png
--------------------------------------------------------------------------------
/screenshots/explosion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/screenshots/explosion.png
--------------------------------------------------------------------------------
/screenshots/getMap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/screenshots/getMap.png
--------------------------------------------------------------------------------
/screenshots/help.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/screenshots/help.png
--------------------------------------------------------------------------------
/screenshots/market.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/screenshots/market.png
--------------------------------------------------------------------------------
/screenshots/pairing.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/screenshots/pairing.gif
--------------------------------------------------------------------------------
/screenshots/turnOn.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexemanuelol/RustPlus-Discord-Bot/6404446da1c1e243db11630557c840206891c81e/screenshots/turnOn.gif
--------------------------------------------------------------------------------
/tools/external/copy_server_details_to_config.js:
--------------------------------------------------------------------------------
1 | /*
2 | * This script is used to automatically update the config.json with rust server details when you click
3 | * 'PAIR WITH SERVER' or 'RESEND'. By clicking a notification message gets triggered that includes
4 | * steamId, serverIp, appPort, playerToken.
5 | */
6 |
7 | const { register, listen } = require('push-receiver');
8 | const fs = require("fs");
9 |
10 | var fcmClient;
11 | var fcmReady = false;
12 |
13 | function setFcmReady() {
14 | console.log("[INFO] Enter the Rust Server and go into Rust+ and press 'PAIR WITH SERVER' or 'RESEND'. " +
15 | "This will trigger a notification message that includes steamId, serverIp, appPort and playerToken. " +
16 | "These parameters will automatically be updated in the config.json file.");
17 | fcmReady = true;
18 | }
19 |
20 | async function listenRustplusDetails() {
21 | if (fs.existsSync("./../../rustplus.config.json")) {
22 | console.log("[SUCCESS] rustplus.config.json file was found!");
23 | }
24 | else {
25 | console.log("[ERROR] rustplus.config.json file does not exist inside root folder.\n Try running the command" +
26 | ": 'npx @liamcottle/rustplus.js fcm-register' and then place the output 'rustplus.config.json' file in " +
27 | "the root folder of the RustPlus-Discord-Bot.");
28 | process.exit(1);
29 | }
30 |
31 | const rustPlusConfig = JSON.parse(fs.readFileSync("./../../rustplus.config.json", "utf8"));
32 | const config = JSON.parse(fs.readFileSync("./../../config.json", "utf8"));
33 |
34 | /* Make sure that fcm credentials are in config. */
35 | if (!rustPlusConfig.fcm_credentials) {
36 | console.log("[ERROR] FCM Credentials missing. Please run: 'npx @liamcottle/rustplus.js fcm-register' and " +
37 | "then place the output 'rustplus.config.json' file in the root folder of the RustPlus-Discord-Bot.");
38 | process.exit(1);
39 | }
40 |
41 | fcmClient = await listen(rustPlusConfig.fcm_credentials, ({ notification, persistentId }) => {
42 | /* Create a delay so that buffered notifications are ignored. */
43 | if (!fcmReady) return;
44 |
45 | /* Parse the notification body. */
46 | const data = notification.data;
47 | const body = JSON.parse(notification.data.body);
48 |
49 | if (data.channelId !== "pairing") return;
50 |
51 | let steamId = body.playerId;
52 | let serverIp = body.ip;
53 | let appPort = body.port;
54 | let playerToken = body.playerToken;
55 |
56 | config.general.steamId = steamId;
57 | config.rust.serverIp = serverIp;
58 | config.rust.appPort = appPort;
59 | config.rust.playerToken = playerToken;
60 |
61 | fs.writeFileSync("./../../config.json", JSON.stringify(config, null, 2));
62 |
63 | console.log("[UPDATE] Following have been written to config.json");
64 | console.log(" steamId: " + steamId);
65 | console.log(" serverIp: " + serverIp);
66 | console.log(" appPort: " + appPort);
67 | console.log(" playerToken: " + playerToken + "\n");
68 | });
69 | }
70 |
71 | listenRustplusDetails();
72 | setTimeout(setFcmReady, 3000);
--------------------------------------------------------------------------------
/tools/external/process_items.js:
--------------------------------------------------------------------------------
1 | /*
2 | * This script is used to combine all of the item meta .json files from
3 | * the Rust game directory ":\SteamLibrary\steamapps\common\Rust\Bundles\items"
4 | * into a single items.json file to be used in this project.
5 | */
6 |
7 | const fs = require('fs');
8 |
9 | var items = {};
10 |
11 | /* Iterate each file in current directory. */
12 | fs.readdirSync('.').forEach(file => {
13 | /* Check if file is item meta file. */
14 | if (file.endsWith('.json')) {
15 |
16 | /* Read item meta. */
17 | var item = JSON.parse(fs.readFileSync(file));
18 |
19 | /* Push item meta we want to keep. */
20 | items[item.itemid] = {
21 | shortname: item.shortname,
22 | name: item.Name,
23 | description: item.Description
24 | };
25 | }
26 | });
27 |
28 | /* Write formatted json to items.json. */
29 | fs.writeFileSync('items.json', JSON.stringify(items, null, 4));
--------------------------------------------------------------------------------
/tools/fcmListener.js:
--------------------------------------------------------------------------------
1 | const { register, listen } = require('push-receiver');
2 | const Discord = require("discord.js");
3 |
4 | const Tools = require("./tools.js");
5 |
6 | const switchAttachment = new Discord.MessageAttachment("./images/smart_switch.png", "smart_switch.png");
7 | const alarmAttachment = new Discord.MessageAttachment("./images/smart_alarm.png", "smart_alarm.png");
8 | const storageAttachment = new Discord.MessageAttachment("./images/storage_monitor.png", "storage_monitor.png");
9 |
10 | var fcmClient;
11 |
12 | module.exports = {
13 | fcmReady: false,
14 | fcmListener: async function (discordBot, rustplus) {
15 | const rustPlusConfig = Tools.readJSON("./rustplus.config.json");
16 | const config = Tools.readJSON("./config.json");
17 | const devices = Tools.readJSON("./devices.json");
18 |
19 | /* Make sure that fcm credentials are in config. */
20 | if (!rustPlusConfig.fcm_credentials) {
21 | Tools.print("ERROR", "FCM Credentials missing. Please run: 'npx @liamcottle/rustplus.js fcm-register' " +
22 | "and then place the output 'rustplus.config.json' file in the root folder of the " +
23 | "RustPlus-Discord-Bot.");
24 | discordBot.destroy();
25 | process.exit(1);
26 | }
27 |
28 | fcmClient = await listen(rustPlusConfig.fcm_credentials, ({ notification, persistentId }) => {
29 | /* Create a delay so that buffered notifications are ignored. */
30 | if (!this.fcmReady) return;
31 |
32 | /* Parse the notification body. */
33 | const data = notification.data;
34 | const body = JSON.parse(notification.data.body);
35 |
36 | if (data.channelId === "pairing") {
37 | if (config.rustplus.pairingNotifications === "true") {
38 | if (body.hasOwnProperty("entityType")) {
39 | let channel = discordBot.channels.cache.get(config.discord.botSpamChannel);
40 |
41 | if (typeof (channel) === "undefined") {
42 | Tools.print("ERROR", "discordBotSpamChannel is invalid in config.json.");
43 | return;
44 | }
45 |
46 | let type = Tools.EntityType[body.entityType];
47 | let id = parseInt(body.entityId);
48 |
49 | /* If it is a Smart Alarm, we do not need to add it to devices.json. */
50 | if (body.entityType === "2") {
51 | Tools.print("PAIRING", "Smart Alarm with entityId **'" + id + "'** have been paired. " +
52 | "No need to add to devices.", channel, null, alarmAttachment, "smart_alarm.png");
53 | if (config.rustplus.inGamePairingNotifications === "true") {
54 | rustplus.sendTeamMessage("[PAIRING] Smart Alarm with entityId '" + id + "' have been paired. No need to " +
55 | "add to devices.");
56 | }
57 | return;
58 | }
59 |
60 | for (let device in devices) {
61 | if (devices[device].id === id) {
62 | /* Already exist in devices.json */
63 | Tools.print("ATTENTION", "Device with entityId '" + id + "' already exist in " +
64 | "devices.json");
65 | return;
66 | }
67 | }
68 | let att;
69 | let name;
70 | if (body.entityType === "1") {
71 | att = switchAttachment;
72 | name = "smart_switch.png";
73 | }
74 | else if (body.entityType === "3") {
75 | att = storageAttachment;
76 | name = "storage_monitor.png";
77 | }
78 |
79 | Tools.print("PAIRING", "A **" + type + "** with the entityId **'" + id + "'** was paired" +
80 | ", add to devices?", channel, null, att, name);
81 | if (config.rustplus.inGamePairingNotifications === "true") {
82 | rustplus.sendTeamMessage("[PAIRING] A " + type + " with entityId '" + id +
83 | "' was paired, add to devices?");
84 | }
85 | }
86 | }
87 | }
88 | else if (data.channelId === "alarm") {
89 | if (config.alarms.enabled === "true") {
90 | let channel = discordBot.channels.cache.get(config.discord.botSpamChannel);
91 | let title = data.title;
92 | let message = data.message;
93 |
94 | Tools.print("ALARM '" + title + "'", message, channel, null, alarmAttachment, "smart_alarm.png");
95 | if (config.alarms.inGame === "true") {
96 | rustplus.sendTeamMessage("[ALARM '" + title + "'] " + message);
97 | }
98 | }
99 | }
100 | });
101 | },
102 | };
--------------------------------------------------------------------------------
/tools/tools.js:
--------------------------------------------------------------------------------
1 | const Main = require("./../rustplusDiscordBot.js");
2 | const fs = require("fs");
3 | const Discord = require("discord.js");
4 |
5 | module.exports = {
6 | readJSON: function (path) {
7 | let data = fs.readFileSync(path, "utf8");
8 | return JSON.parse(data);
9 | },
10 |
11 | writeJSON: function (path, property, value) {
12 | let jsonObj = module.exports.readJSON(path);
13 | jsonObj[property] = value;
14 | fs.writeFileSync(path, JSON.stringify(jsonObj, null, 2));
15 | },
16 |
17 | sendEmbed: function (discordChannel, title, description, field = null, attachment = Main.THUMBNAIL_DEFAULT, thumbnailName = "rust_logo.png") {
18 | const embed = new Discord.MessageEmbed()
19 | .setColor("#ce412b")
20 | .attachFiles(attachment)
21 | .setThumbnail("attachment://" + thumbnailName)
22 | .setURL(Main.GITHUB_URL)
23 | .setTitle(title)
24 | .setDescription(description);
25 |
26 | if (field !== null) {
27 | embed.addField(field[0], field[1]);
28 | }
29 |
30 | discordChannel.send(embed);
31 | },
32 |
33 | wildcardMatch: function (str, rule) {
34 | var escapeRegex = (str) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
35 | return new RegExp("^" + rule.split("*").map(escapeRegex).join(".*") + "$").test(str);
36 | },
37 |
38 | print: function (title, description, channel = null, rustplus = null, attachment = Main.THUMBNAIL_DEFAULT, thumbnailName = "rust_logo.png") {
39 | let date = new Date();
40 | let hours = date.getHours() < 10 ? ("0" + date.getHours()) : date.getHours();
41 | let minutes = date.getMinutes() < 10 ? ("0" + date.getMinutes()) : date.getMinutes();
42 | let seconds = date.getSeconds() < 10 ? ("0" + date.getSeconds()) : date.getSeconds();
43 |
44 | let time = "(" + hours + ":" + minutes + ":" + seconds + ") ";
45 |
46 | /* Print to console. */
47 | console.log(time + "[" + title + "] " + description);
48 |
49 | /* If team message enabled. */
50 | if (rustplus !== null) {
51 | rustplus.sendTeamMessage("[" + title + "] " + description);
52 | }
53 |
54 | /* If discord message enabled. */
55 | if (channel !== null) {
56 | module.exports.sendEmbed(channel, title, description, null, attachment, thumbnailName);
57 | }
58 | },
59 |
60 | validateResponse: function (response, channel) {
61 | if (response.response.hasOwnProperty("error")) {
62 | module.exports.print("ERROR", "The response message include errors, Make sure that command inputs are valid.", channel);
63 | return false;
64 | }
65 | else {
66 | return true;
67 | }
68 | },
69 |
70 | convertToHoursMinutes: function (value) {
71 | let hours = Math.floor(value);
72 | let minutes = Math.floor((value - hours) * 60);
73 |
74 | hours = (hours < 10) ? ("0" + hours).toString() : hours.toString();
75 | minutes = (minutes < 10) ? ("0" + minutes).toString() : minutes.toString();
76 |
77 | return hours + ":" + minutes;
78 | },
79 |
80 | convertUnixTimestampToDate: function (value) {
81 | let date = new Date(value * 1000);
82 |
83 | return date;
84 | },
85 |
86 | convertToStringDate: function (date) {
87 | return module.exports.Day[date.getDay()] + " " +
88 | module.exports.Month[date.getMonth()] + " " +
89 | date.getDate() + " " +
90 | date.getFullYear() + " " +
91 | date.getHours() + ":" +
92 | date.getMinutes() + ":" +
93 | date.getSeconds() + " " +
94 | "GMT" + ((date.getTimezoneOffset() <= 0) ? "+" : "-") + Math.abs(date.getTimezoneOffset() / 60);
95 | },
96 |
97 | similarity: function (s1, s2) {
98 | var longer = s1;
99 | var shorter = s2;
100 | if (s1.length < s2.length) {
101 | longer = s2;
102 | shorter = s1;
103 | }
104 |
105 | var longerLength = longer.length;
106 | if (longerLength == 0) {
107 | return 1.0;
108 | }
109 |
110 | return (longerLength - module.exports.editDistance(longer, shorter)) / parseFloat(longerLength);
111 | },
112 |
113 | editDistance: function (s1, s2) {
114 | s1 = s1.toLowerCase();
115 | s2 = s2.toLowerCase();
116 |
117 | var costs = new Array();
118 | for (var i = 0; i <= s1.length; i++) {
119 | var lastValue = i;
120 | for (var j = 0; j <= s2.length; j++) {
121 | if (i == 0)
122 | costs[j] = j;
123 | else {
124 | if (j > 0) {
125 | var newValue = costs[j - 1];
126 | if (s1.charAt(i - 1) != s2.charAt(j - 1))
127 | newValue = Math.min(Math.min(newValue, lastValue),
128 | costs[j]) + 1;
129 | costs[j - 1] = lastValue;
130 | lastValue = newValue;
131 | }
132 | }
133 | }
134 | if (i > 0)
135 | costs[s2.length] = lastValue;
136 | }
137 | return costs[s2.length];
138 | },
139 |
140 | isStringBool: function (arg) {
141 | if (arg === "true" || arg === "false") return true;
142 |
143 | return false;
144 | },
145 |
146 | MarkerType: {
147 | Source: 0,
148 | Player: 1,
149 | Explosion: 2,
150 | VendingMachine: 3,
151 | CH47: 4,
152 | CargoShip: 5,
153 | Crate: 6,
154 | GenericRadius: 7,
155 | TrainTunnels: 8,
156 | },
157 |
158 | EntityType: {
159 | 1: "Smart Switch",
160 | 2: "Smart Alarm",
161 | 3: "Storage Monitor"
162 | },
163 |
164 | Month: {
165 | 0: "Jan",
166 | 1: "Feb",
167 | 2: "Mar",
168 | 3: "Apr",
169 | 4: "May",
170 | 5: "Jun",
171 | 6: "Jul",
172 | 7: "Aug",
173 | 8: "Sep",
174 | 9: "Oct",
175 | 10: "Nov",
176 | 11: "Dec",
177 | },
178 |
179 | Day: {
180 | 0: "Sun",
181 | 1: "Mon",
182 | 2: "Tue",
183 | 3: "Wed",
184 | 4: "Thu",
185 | 5: "Fri",
186 | 6: "Sat",
187 | },
188 | }
189 |
--------------------------------------------------------------------------------
/version.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "1.3.7"
3 | }
4 |
--------------------------------------------------------------------------------