-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistChannels
65 lines (58 loc) · 2.54 KB
/
listChannels
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
{{$globalSdict:= sdict }}
{{- define "standardize"}}
{{- $value:= .Get "val"}}{{$t:= printf "%T" $value}}{{$recursiveSdict:= sdict}}{{$rangeVal:= ""}}
{{- if (eq $t `map[string]interface {}`)}}{{$rangeVal = sdict $value}}
{{- else if (eq $t `[]interface {}`)}}{{$rangeVal = cslice.AppendSlice $value}}
{{- else if (in (cslice `templates.SDict` `templates.Slice`) $t)}}{{$rangeVal = $value}}
{{- end}}
{{- if (print $rangeVal)}}
{{- range $k,$v:= $rangeVal}}
{{- if in (cslice `map[string]interface {}` `[]interface {}` `templates.SDict` `templates.Slice`) (printf "%T" $v)}}
{{- $recursiveSdict.Set "val" $v}}{{template "standardize" $recursiveSdict}}{{$rangeVal.Set $k ($recursiveSdict.Get "res")}}
{{- end}}
{{- end}}
{{- else}}
{{- $rangeVal = $value}}
{{- end}}
{{- .Set "res" $rangeVal}}
{{- end}}
{{ $rpChannels := ( dbGet 0 "channels" ).Value }}{{$globalSdict.Set "val" $rpChannels}}{{template "standardize" $globalSdict}}{{$rpChannels = $globalSdict.Get "res"}}
{{ $arg_1 := index .CmdArgs 0 }}
{{ $arg_2 := "" }}
{{ if eq $arg_1 "show" }}
{{- range $k, $v := $rpChannels }}
{{- sendMessage nil ( print $k " - " "<#" $v ">" ) -}}
{{- end }}
{{ else }}
{{ if gt ( len .CmdArgs ) 1 }}
{{ $arg_2 = index .CmdArgs 1 }}
{{ end }}
{{ $arg_1 = index .CmdArgs 0 | getChannel }}
{{ with index .CmdArgs 0 | reFind `\d+` | toInt | getChannel }}
{{ $arg_1 =. }}
{{ end }}
{{ if $arg_1 }}
{{ if ( $rpChannels.Get $arg_1.Name ) }}
{{ if eq $arg_2 "delete" "del" "remove" }}
{{ $rpChannels.Del $arg_1.Name }}
{{ sendMessage nil ( print "I have removed <#" $arg_1.ID "> from the list" ) }}
{{ else }}
{{ sendMessage nil ( print "<#" $arg_1.ID "> already exists in my list. Try another?" ) }}
{{ end }}
{{ else }}
{{ $rpChannels.Set $arg_1.Name $arg_1.ID }}
{{ sendMessage nil ( print "I have added <#" $arg_1.ID "> to the list!")}}
{{ end }}
{{ else }}
{{ $arg_1 = index .CmdArgs 0 }}
{{- range $k,$v := $rpChannels }}
{{- if ( eq $k $arg_1 ) }}
{{- if eq $arg_2 "delete" "del" "remove" }}
{{- $rpChannels.Del $arg_1 }}
{{ sendMessage nil ( print "I have removed <#" $arg_1 "> from the list" ) }}
{{- end }}
{{- end }}
{{- end }}
{{ end }}
{{ dbSet 0 "channels" $rpChannels }}
{{ end }}