-
Notifications
You must be signed in to change notification settings - Fork 942
/
Copy pathcustomcommands-editcmd.html
746 lines (684 loc) · 41.4 KB
/
customcommands-editcmd.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
{{define "cp_custom_commands_edit_cmd"}}
{{template "cp_head" .}}
<header class="page-header">
<h2>Custom commands</h2>
</header>
{{template "cp_alerts" .}}
<style>
.cc-editor {
font-family: Consolas, monospace;
}
</style>
<!-- Nav -->
<div class="row">
<div class="col">
<!-- Nav tabs -->
<div class="tabs">
<ul class="nav nav-tabs">
<li class="nav-item {{if and (not .CurrentCommandGroup)}}active{{end}}">
<a data-partial-load="true" class="nav-link show {{if not .CurrentCommandGroup}}active{{end}}"
href="/manage/{{.ActiveGuild.ID}}/customcommands/">Ungrouped</a>
</li>
{{$dot := .}}
{{range .CommandGroups}}
<li
class="nav-item {{if $dot.CurrentCommandGroup}}{{if eq $dot.CurrentCommandGroup.ID .ID}}active{{end}}{{end}}">
<a data-partial-load="true"
class="nav-link show {{if $dot.CurrentCommandGroup}}{{if eq $dot.CurrentCommandGroup.ID .ID}}active{{end}}{{end}}"
href="/manage/{{$dot.ActiveGuild.ID}}/customcommands/groups/{{.ID}}">{{.Name}}</a>
</li>
{{end}}
<li class="nav-item">
<form class="form-horizontal" method="post"
action="/manage/{{.ActiveGuild.ID}}/customcommands/creategroup" data-async-form>
<input type="text" class="hidden" name="Name" value="Unnamed group">
<input clasS="nav-link show" type="submit" value="+"></input>
</form>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active">
<ul id="cc-feedback-top">
<li class="text-danger" hidden id="trigger-warning"></li>
</ul>
{{$guild := .ActiveGuild.ID}}
{{$g := .ActiveGuild}}
{{$dot := .}}
<form class="form-horizontal" method="post"
action="/manage/{{$guild}}/customcommands/commands/{{.CC.LocalID}}/update" data-async-form>
<button type="submit" class="hidden"
formaction="/manage/{{$guild}}/customcommands/commands/{{.CC.LocalID}}/update"
data-async-form-alertsonly></button>
<h2 class="card-title">
#{{.CC.LocalID}} -
{{index .CCTriggerTypes .CC.TriggerType}}{{if and (ne .CC.TriggerType 5) (ne .CC.TriggerType 6)}}:
<span
class="cc-text-trigger-span">{{.CC.TextTrigger}}</span>{{else if ne .CC.TriggerType 6}}:
Every
{{call .GetCCInterval .CC}}
{{if eq (call .GetCCIntervalType .CC) 1}}hour(s){{else}}minute(s){{end}}{{end}}
</h2>
<input type="text" class="hidden form-control" name="id" value="{{.CC.LocalID}}">
<div class="row">
<!-- Trigger -->
<div class="col-lg-4">
<div class="row">
<div class="col">
<div class="form-group">
<label>Trigger type</label>
<select class="form-control" id="trigger-type-dropdown" name="type"
onchange="triggerTypeChanged(this)">
<option value="none" {{if eq .CC.TriggerType 10}}selected{{end}}>None
</option>
<option value="cmd" {{if eq .CC.TriggerType 0}} selected{{end}}>Command
(mention/cmd
prefix)</option>
<option value="prefix" {{if eq .CC.TriggerType 1}} selected{{end}}>
Starts with</option>
<option value="contains" {{if eq .CC.TriggerType 2}} selected{{end}}>
Contains</option>
<option value="regex" {{if eq .CC.TriggerType 3}} selected{{end}}>Regex
</option>
<option value="exact" {{if eq .CC.TriggerType 4}} selected{{end}}>Exact
match</option>
<option value="reaction" {{if eq .CC.TriggerType 6}} selected{{end}}>
Reaction</option>
<option value="interval_hours"
{{if eq (call .GetCCIntervalType .CC) 1}}selected{{end}}>
Hourly interval
</option>
<option value="interval_minutes"
{{if eq (call .GetCCIntervalType .CC) 0}}selected{{end}}>
Minute interval
</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col" id="trigger-help">
<p id="trigger-desc-none" class="text-danger">
No trigger: can only be triggered manually by other custom
commands
</p>
<p id="trigger-desc-cmd">
<b>Command Trigger</b>: Works the same way as normal commands by using the
command
prefix or bot mention followed by the trigger.<br />
</p>
<p id="trigger-desc-prefix">
Any message that starts with the trigger will run the command.
</p>
<p id="trigger-desc-contains">
Any message that contains the trigger will run the command.
</p>
<p id="trigger-desc-regex">
Any message that matches the provided regex will trigger the command.
</p>
<p id="trigger-desc-exact">
Any message that is equal to the trigger will run the command.
</p>
<p id="trigger-desc-reaction">
The command will trigger on the specified reaction events.
</p>
<p id="trigger-desc-interval_hours">
The command will run at a hourly interval, for example every 5 hours.
</p>
<p id="trigger-desc-interval_minutes">
The command will run at a minute interval, for example every 10 minutes.
</p>
</div>
</div>
</div>
<div id="cc-text-trigger-details" class="hidden col-lg-8">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label>Trigger (<span id="trigger-length">{{len .CC.TextTrigger}}</span>/1000)</label>
<div class="input-group mb-2">
<div class="input-group-prepend" id="command-trigger-prepended-prefix">
<div class="input-group-text">{{.CommandPrefix}}</div>
</div>
<input id="trigger" type="text" class="form-control" name="trigger" placeholder="fun"
value="{{.CC.TextTrigger}}">
</div>
<div class="row">
<div class="col-lg-6"> {{checkbox "case_sensitive" "case_sensitive" "Case Sensitive?" .CC.TextTriggerCaseSensitive}}</div>
<div class="col-lg-6">
{{$disabledClass := ""}}
{{if not .IsGuildPremium}}{{$disabledClass = "disabled"}}{{end}}
{{checkbox "trigger_on_edit" "trigger_on_edit" "Trigger on message edits too? (Premium Only!)" .CC.TriggerOnEdit $disabledClass}}
</div>
</div>
</div>
</div>
</div>
</div>
<div id="cc-reaction-trigger-details" class="hidden col-lg-8">
<div class="row">
<div class="col-lg-12">
<div class="form-check">
<input class="form-check-input" type="radio" name="reaction_trigger_mode"
id="reaction-mode-both-{{.CC.LocalID}}" value="0"
{{if eq .CC.ReactionTriggerMode 0}}checked{{end}}>
<label class="form-check-label" for="reaction-mode-both-{{.CC.LocalID}}">
Added + Removed reactions
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="reaction_trigger_mode"
id="reaction-mode-added-{{.CC.LocalID}}" value="1"
{{if eq .CC.ReactionTriggerMode 1}}checked{{end}}>
<label class="form-check-label" for="reaction-mode-added-{{.CC.LocalID}}">
Added reactions only
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="reaction_trigger_mode"
id="reaction-mode-removed-{{.CC.LocalID}}" value="2"
{{if eq .CC.ReactionTriggerMode 2}}checked{{end}}>
<label class="form-check-label" for="reaction-mode-removed-{{.CC.LocalID}}">
Removed reactions only
</label>
</div>
</div>
</div>
</div>
<div id="cc-time-trigger-details" class="hidden col-lg-8">
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label>Interval</label>
<input type="number" min="0" class="form-control" name="time_trigger_interval"
placeholder="" value="{{call $dot.GetCCInterval .CC}}">
</div>
</div>
<div class="col-lg-8">
<div class="form-group">
<label>Channel</label>
<select id="time-trigger-channel" name="context_channel" class="form-control">
{{textChannelOptions $g.Channels .CC.ContextChannel true "None"}}
</select>
</div>
</div>
</div>
<div class="row mt-3">
<div class="form-group col-lg-3">
<label for="trigger">Excluding hours (UTC)</label><br>
<select name="time_trigger_excluding_hours" class="multiselect form-control"
multiple="multiple" data-plugin-multiselect>
{{$selectedExclHours := .CC.TimeTriggerExcludingHours}}
{{range seq 0 24}}<option value="{{.}}"
{{if in $selectedExclHours .}}selected{{end}}>{{.}}</option>
{{end}}
</select>
</div>
<div class="form-group col-lg-3">
<label for="trigger">Excluding weekdays (UTC)</label><br>
<select name="time_trigger_excluding_days" class="multiselect form-control"
multiple="multiple" data-plugin-multiselect>
<option value="1"
{{if in .CC.TimeTriggerExcludingDays 1}}selected{{end}}>
Monday</option>
<option value="2"
{{if in .CC.TimeTriggerExcludingDays 2}}selected{{end}}>
Tuesday</option>
<option value="3"
{{if in .CC.TimeTriggerExcludingDays 3}}selected{{end}}>
Wednesday</option>
<option value="4"
{{if in .CC.TimeTriggerExcludingDays 4}}selected{{end}}>
Thursday</option>
<option value="5"
{{if in .CC.TimeTriggerExcludingDays 5}}selected{{end}}>
Friday</option>
<option value="6"
{{if in .CC.TimeTriggerExcludingDays 6}}selected{{end}}>
Saturday</option>
<option value="0"
{{if in .CC.TimeTriggerExcludingDays 0}}selected{{end}}>
Sunday</option>
</select>
</div>
</div>
</div>
</div>
<div class="row mt-3">
<div class="col-lg-4">
<div class="form-group">
<label>Name (<span id="name-length">{{len .CC.Name.String}}</span>/100) </label>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter a name" value="{{if .CC.Name.Valid}}{{.CC.Name.String}}{{end}}">
<p>An optional name that can be used to identify the command.</p>
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label> Command Enabled?</label>
{{checkbox "is_enabled" "is_enabled" "Enables or Disables the command" (not .CC.Disabled) }}
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label> Allow Public Imports?</label>
{{checkbox "public" "public" "Allow anyone to view and copy this command" .CC.Public}}
</div>
</div>
</div>
<div class="row mb-2">
<div class="col-lg-12">
<div class="form-group">
<label for="responses">Response (<span
class="cc-length-counter">x</span>/{{.MaxCCLength}})</label>
<!-- Use .btn-add for simplicity and let the page loader adjust. -->
{{range .CC.Responses}}
<div id="cc-responses" class="entry input-group input-group-sm">
<textarea class="form-control response-text-area tab-textbox cc-editor" name="responses"
placeholder="Command body here" rows="5"
oninput="onCCChanged(this)">{{.}}</textarea>
<span class="input-group-append">
<button class="btn btn-success btn-add btn-circle" type="button">
<i class="fas fa-plus"></i>
</button>
</span>
</div>
{{else}}
<div id="cc-responses" class="entry input-group input-group-sm">
<textarea class="form-control response-text-area tab-textbox cc-editor" name="responses"
placeholder="Command body here" rows="5"
oninput="onCCChanged(this)"></textarea>
<span class="input-group-append">
<button class="btn btn-success btn-add btn-circle" type="button">
<i class="fas fa-plus"></i>
</button>
</span>
</div>
{{end}}
<a class="mb-1 mt-1 mr-1 modal-basic btn btn-info btn-sm"
href="#cc-help-modal">Info</a>
{{if .CC.Public}}
<a class="mb-1 mt-1 mr-1 modal-basic btn btn-info btn-sm"
href="#cc-share-modal">Share</a>
{{end}}
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label>Custom command group</label>
{{$selectedGroup := .CC.GroupID.Int64}}
<select Name="GroupID" class="form-control">
<option {{if eq $selectedGroup 0}}selected{{end}} value="0">None
</option>
{{range $dot.CommandGroups}}<option value="{{.ID}}"
{{if eq $selectedGroup .ID}}selected{{end}}>{{.Name}}</option>
{{end}}
</select>
</div>
<h4>Last error</h4>
<p>{{if .CC.LastError}}<b>{{formatTime .CC.LastErrorTime.Time.UTC}}</b> - <code>
{{.CC.LastError}}</code>{{else}}None{{end}}</p>
<div class="row">
<div class="col-auto">
<h4>Run count</h4>
<p><code>{{.CC.RunCount}}</code></p>
</div>
<div class="col-auto">
<h4>Last run</h4>
<p>{{if .CC.LastRun.Valid}}{{formatTime .CC.LastRun.Time.UTC}}{{else}}None{{end}}</p>
</div>
{{if (eq .CC.TriggerType 5)}}
<div class="col-auto">
<h4>Next scheduled run</h4>
<p>{{if .CC.NextRun.Valid}}{{formatTime .CC.NextRun.Time.UTC}}{{else}}None{{end}}</p>
</div>
{{end}}
</div>
<h4>Output errors as command response</h4>
{{checkbox "show_errors" "show_errors" "" .CC.ShowErrors}}
</div>
<div id="cc-extra-settings" class="col-lg-6">
<h3>Channel/User role restrictions</h3>
<div class="radio">
<label>
<input id="require-role-mode" type="radio" name="require_roles" value="on"
{{if .CC.RolesWhitelistMode}}checked{{end}}>
Require at least one of the roles in the following lists
</label>
</div>
<div class="radio">
<label>
<input id="ignore-role-mode" type="radio" name="require_roles" value=""
{{if not .CC.RolesWhitelistMode}}checked{{end}}>
Ignore the roles in the following list
</label>
</div>
<select name="roles" class="multiselect form-control" multiple="multiple"
id="command-roles" data-plugin-multiselect>
{{roleOptionsMulti $g.Roles nil .CC.Roles}}
</select>
<hr>
<div class="radio">
<label>
<input id="require-channel-mode" type="radio" name="require_channels" value="on"
{{if .CC.ChannelsWhitelistMode}}checked{{end}}>
Only run in the following channels
</label>
</div>
<div class="radio">
<label>
<input id="ignore-channel-mode" type="radio" name="require_channels" value=""
{{if not .CC.ChannelsWhitelistMode}}checked{{end}}>
Ignore the channels in the following list
</label>
</div>
<select name="channels" class="multiselect form-control" multiple="multiple"
id="command-channels" data-plugin-multiselect>
{{textChannelOptionsMulti $g.Channels .CC.Channels}}
</select>
</div>
</div>
<div class="row mt-4">
<div class="col">
<button type="submit" class="btn btn-success btn-block"
formaction="/manage/{{$guild}}/customcommands/commands/{{.CC.LocalID}}/update"
data-async-form-alertsonly
id = "save-custom-command"
>Save</button>
</div>
<div class="col">
<button type="submit" class="btn btn-danger btn-block"
formaction="/manage/{{$guild}}/customcommands/commands/{{.CC.LocalID}}/delete">Delete</button>
</div>
</div>
<div class="row mt-4" id="interval-cc-run-now">
<div class="col">
<button type="submit" class="btn btn-secondary btn-block" title="This will trigger this custom command immediately"
formaction="/manage/{{$guild}}/customcommands/commands/{{.CC.LocalID}}/update_and_run">Run now</button>
</div>
</div>
<p class="help-block">Tip: Alt + Shift + S also saves the custom command </p>
</form>
</div>
</div>
</div>
</div>
</div>
{{if .CC.Public}}
<div id="cc-share-modal" class="modal-block modal-header-color modal-block-info mfp-hide">
<section class="card">
<header class="card-header">
<h2 class="card-title">Copy Import Link</h2>
</header>
<div class="card-body">
<div class="modal-wrapper">
<div class="modal-text">
<p class="help-block">To share custom command #<code>{{.CC.LocalID}}</code>, and allow users to
import it, copy the link below.
</p>
<div class="row no-gutters">
<div class="col-md-9">
<input type="text" style="border-radius: 0% !important;" id="public-link" class="form-control" name="Public Link" value="{{.PublicLink}}" readonly>
</div>
<div class="col-md-3">
<button id="copy-link-button" style="border-radius: 0% !important;" class="btn btn-quaternary"><i class="fas fa-copy p-1"> </i>Copy</button>
</div>
</div>
<script>
document.getElementById("copy-link-button").addEventListener("click", function() {
let copyText = document.getElementById("public-link");
copyText.select();
copyText.setSelectionRange(0, 99999); // For mobile devices
navigator.clipboard.writeText(copyText.value);
copyText.setSelectionRange(0, 0);
this.textContent = "Copied!";
setTimeout(() => {
this.innerHTML =`<i class="fas fa-copy p-1"> </i>Copy`;
}, 2000);
}, false);
</script>
</div>
</div>
</div>
<footer class="card-footer">
<div class="row">
<div class="col-md-8">
<p>Total Imports: <code>{{.CC.ImportCount}}</code></p>
</div>
<div class="col-md-4 text-right">
<button class="btn btn-info modal-dismiss">Close</button>
</div>
</div>
</footer>
</section>
</div>
{{end}}
<div id="cc-help-modal" class="modal-block modal-header-color modal-block-info mfp-hide">
<section class="card">
<header class="card-header">
<h2 class="card-title">Custom Command Information</h2>
</header>
<div class="card-body">
<div class="modal-wrapper">
<div class="modal-text">
<p class="help-block">Available template data is {{template "template_helper_user"}} (and much
more)
</p>
<p class="help-block">Execute bot commands using
<code>{{`{{exec "command" "arg1" "arg2"}}`}}</code>, Example:
<code>{{"{{exec \"role\" \"yagpdb\"}}"}}</code> will be the same as the user typing
<code>(mention or prefix) role yagpdb</code></p>
<p class="help-block">Arguments are available in a string array: <code>.CmdArgs</code><br>
Access
single arguments by index using <code>{{"{{index .CmdArgs 0}}"}}</code><br>Get the number of
arguments using <code>{{"{{len .CmdArgs}}"}}</code><br>Loop over them with
<br><code>{{"{{range .CmdArgs}}{{.}}"}} <- that dot will be replaced by the current argument we're looping over{{"{{end}}"}}</code><br>"end"
marks the end of the for loop.</p>
<!-- {{/* .IgnoreMe */}} -->
<p>
See the <a href="https://docs.yagpdb.xyz/templates" target="_blank">templating</a> and <a
href="https://docs.yagpdb.xyz/commands/custom-commands" target="_blank">custom
command</a>
docs for more info and join the support server if you have further questions. Custom
commands
for yagpdb are rather complicated for the time being.</p>
<p class="help-block">
YAGPDB will pick one message at random from all configured responses.
</p>
</div>
</div>
</div>
<footer class="card-footer">
<div class="row">
<div class="col-md-12 text-right">
<button class="btn btn-info modal-dismiss">OK</button>
</div>
</div>
</footer>
</section>
</div>
<script src="/static/vendorr/tln/tln.min.js"></script>
<link rel="stylesheet" href="/static/vendorr/tln/tln.min.css">
<style>
html.dark .input-group-prepend > .input-group-text {
background: #191c21;
}
</style>
<script type="text/javascript">
function isTextTrigger(t) {
return t === "cmd" ||
t === "prefix" ||
t === "contains" ||
t === "regex" ||
t === "exact";
}
function triggerTypeChanged() {
var dropdown = $("#trigger-type-dropdown")
if (dropdown.val() === "interval_hours" || dropdown.val() === "interval_minutes") {
// Interval triggers
$("#interval-cc-run-now").removeClass("hidden")
$("#cc-time-trigger-details").removeClass("hidden");
$("#cc-text-trigger-details").addClass("hidden");
$("#cc-extra-settings").addClass("hidden");
$("#cc-reaction-trigger-details").addClass("hidden")
$("#trigger-warning").attr("hidden", true);
handleTimeTriggerChannelChange();
$("#require-no-channels-warning").addClass("hidden");
$("#require-no-roles-warning").addClass("hidden");
$("#time-trigger-no-channel-warning").removeClass("hidden");
} else if (dropdown.val() === "reaction") {
// Reaction triggers
$("#cc-reaction-trigger-details").removeClass("hidden")
$("#cc-extra-settings").removeClass("hidden");
$("#cc-time-trigger-details").addClass("hidden");
$("#cc-text-trigger-details").addClass("hidden");
$("#interval-cc-run-now").addClass("hidden")
$("#trigger-warning").attr("hidden", true);
$("#require-no-channels-warning").removeClass("hidden");
$("#require-no-roles-warning").removeClass("hidden");
$("#time-trigger-no-channel-warning").addClass("hidden");
} else if (isTextTrigger(dropdown.val())) {
// Other message triggers
$("#cc-text-trigger-details").removeClass("hidden");
$("#cc-extra-settings").removeClass("hidden");
$("#cc-reaction-trigger-details").addClass("hidden")
$("#cc-time-trigger-details").addClass("hidden");
$("#interval-cc-run-now").addClass("hidden")
$("#trigger-warning").attr("hidden", true);
$("#require-no-channels-warning").removeClass("hidden");
$("#require-no-roles-warning").removeClass("hidden");
// $("#trigger-warning").text("No trigger set, this command will only be able to be called from other commands")
$("#time-trigger-no-channel-warning").addClass("hidden");
} else {
// No automatic trigger
$("#cc-text-trigger-details").addClass("hidden");
$("#cc-extra-settings").addClass("hidden");
$("#cc-reaction-trigger-details").addClass("hidden")
$("#cc-time-trigger-details").addClass("hidden");
$("#interval-cc-run-now").addClass("hidden")
$("#trigger-warning").removeAttr("hidden");
$("#trigger-warning").text("No trigger set, this command will only be able to be called from other commands")
$("#require-no-channels-warning").addClass("hidden");
$("#require-no-roles-warning").addClass("hidden");
$("#time-trigger-no-channel-warning").addClass("hidden");
};
if (dropdown.val() === "cmd") $("#command-trigger-prepended-prefix").show();
else $("#command-trigger-prepended-prefix").hide();
$("#trigger-help").children().each(function (i, v) {
$(v).attr("hidden", true);
});
$("#trigger-desc-" + dropdown.val()).removeAttr("hidden");
}
$(function () {
handleTimeTriggerChannelChange();
handleRestrictionChange($("#require-role-mode").prop("checked"), $("#command-roles"), "require-no-roles-warning", requireNoRolesWarning);
handleRestrictionChange($("#require-channel-mode").prop("checked"), $("#command-channels"), "require-no-channels-warning", requireNoChannelsWarning);
triggerTypeChanged();
calcCCLength();
calcTriggerLength();
calcNameLength();
})
function calcTriggerLength() {
let triggerLength = $('#trigger-length')
let trigger = $('#trigger')
if (triggerLength && trigger && trigger.val()) {
triggerLength.text(trigger.val().length).toggleClass("text-danger", trigger.val().length > 1000);
}
}
function calcNameLength() {
let nameLength = $('#name-length')
let name = $('#name')
if (nameLength && name && name.val()) {
nameLength.text(name.val().length).toggleClass("text-danger", name.val().length > 100);
}
}
$("#trigger").keyup(function() {
calcTriggerLength();
});
$("#name").keyup(function(){
calcNameLength();
});
function calcCCLength() {
var textAreas = document.querySelectorAll("#cc-responses > textarea")
var combinedLength = 0;
textAreas.forEach(function (elem) {
combinedLength += elem.value.length;
// The data received on the backend contains "\r\n" while it is simply "\n" on the JS side.
// Adjust for this discrepancy by double-counting newline characters.
const newlines = elem.value.match(/\n/g);
if (newlines) combinedLength += newlines.length;
})
var display = document.querySelector(".cc-length-counter")
display.textContent = combinedLength
if (combinedLength > {{.MaxCCLength}}) {
display.classList.add("text-danger");
} else {
display.classList.remove("text-danger");
}
}
function onCCChanged(textArea) {
calcCCLength();
}
var idGen = 0
$("#time-trigger-channel").change(handleTimeTriggerChannelChange);
function handleTimeTriggerChannelChange() {
const triggerType = $("#trigger-type-dropdown").val();
if (triggerType !== "interval_hours" && triggerType !== "interval_minutes") return;
// if no channel is selected for an interval trigger, the command is
// effectively disabled as it has nowhere to run
const isChannelSelected = Boolean($("#time-trigger-channel").val());
const existingWarning = $("#time-trigger-no-channel-warning");
if (existingWarning.length > 0 && isChannelSelected) {
// remove existing warning if a channel is selected
existingWarning.remove();
} else if (existingWarning.length === 0 && !isChannelSelected) {
addAlert("warning", "Selecting no channel for the command to run in effectively disables it, making it never run. If your command does not need to run in any specific channel, select a random one from the list instead.", "time-trigger-no-channel-warning");
}
}
var requireNoRolesWarning = "Requiring no roles effectively disables your command, making it run for no one. If you want no role restrictions, set the mode to 'ignore roles' instead.";
var requireNoChannelsWarning = "Requiring no channels effectively disables your command, making it run for no one. If you want no channel restrictions, set the mode to 'ignore channels' instead.";
$("#require-role-mode").change(function() {
handleRestrictionChange($(this).prop("checked"), $("#command-roles"), "require-no-roles-warning", requireNoRolesWarning);
});
$("#ignore-role-mode").change(function() {
handleRestrictionChange(!$(this).prop("checked"), $("#command-roles"), "require-no-roles-warning", requireNoRolesWarning);
});
$("#command-roles").change(function() {
handleRestrictionChange($("#require-role-mode").prop("checked"), $(this), "require-no-roles-warning", requireNoRolesWarning);
});
$("#require-channel-mode").change(function() {
handleRestrictionChange($(this).prop("checked"), $("#command-channels"), "require-no-channels-warning", requireNoChannelsWarning);
});
$("#ignore-channel-mode").change(function() {
handleRestrictionChange(!$(this).prop("checked"), $("#command-channels"), "require-no-channels-warning", requireNoChannelsWarning);
});
$("#command-channels").change(function() {
handleRestrictionChange($("#require-channel-mode").prop("checked"), $(this), "require-no-channels-warning", requireNoChannelsWarning);
});
function handleRestrictionChange(modeIsRequire, selectMenu, warningID, warningText) {
// requiring no roles/channels results in the command not being able to
// run anywhere, this is typically a mistake
const doWarn = modeIsRequire && selectMenu.val().length === 0;
const existingWarning = $(`#${warningID}`);
if (existingWarning.length > 0 && !doWarn) {
// remove existing warning if there's no need for it anymore
existingWarning.remove();
} else if (existingWarning.length === 0 && doWarn) {
// warning does not exist, so add it
addAlert("warning", warningText, warningID);
}
}
$(document).bind('keydown', (e) => {
let event = e.originalEvent;
if(event.altKey && event.shiftKey && event.code === 'KeyS'){
const saveCCbutton = document.querySelector("#save-custom-command");
if(saveCCbutton){
saveCCbutton.click();
return false;
}
}
});
</script>
{{template "cp_footer" .}}
{{end}}