-
Notifications
You must be signed in to change notification settings - Fork 66
/
pagination.yag
161 lines (154 loc) · 8.06 KB
/
pagination.yag
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
{{/*
Trigger type: Reaction
This code is used for the snippet system & the counting system. That means once you added it you do not need to add it again for the other system
Copyright (c): Black Wolf, 2022
License: MIT
Repository: https://github.com/BlackWolfWoof/yagpdb-cc/
*/}}
{{if and .Message.Embeds (eq .Message.Author.ID $.BotUser.ID)}}
{{$msg := index .Message.Embeds 0|structToSdict}}
{{if (reFind `\A(Snippet:|Counter Leaderboard)` $msg.Title)}}
{{range $k, $v := $msg}}
{{if eq (kindOf $v true) "struct"}}{{$msg.Set $k (structToSdict $v)}}{{end}}
{{end}}
{{if $msg.Footer}}
{{if and (eq .Reaction.Emoji.Name "📱") (reFind `React with 📱 to be DMed a mobile version\.` $msg.Footer.Text)}}
{{sendDM (printf "\n**%s**\n%s\n%s\n%s" $msg.Title $msg.Description (or $msg.Image (sdict "URL" "")).URL (reReplace `\)\n.+` $msg.Footer.Text ")"))}}
{{deleteAllMessageReactions nil .Message.ID}}{{addMessageReactions nil .Message.ID "📱"}}
{{else if and (eq .Reaction.Emoji.Name "🗑" "🗑️") (reFind `React with 🗑️ to delete this message\.` $msg.Footer.Text)}}
{{deleteMessage nil .Message.ID 0}}
{{else if eq .Reaction.Emoji.Name "⚙️"}}
{{sendMessage nil (complexMessage "content" (print "Raw snippet **(" (reReplace `Tag: ` $msg.Title "") ")** output triggered by " .User.String) "file" (print ";tag add \"" (reReplace `Snippet: ` $msg.Title "") "\" \"" (or $msg.Image (sdict "URL" "")).URL "\"\n" (reReplace `\\` $msg.Description `\\`)))}}
{{deleteAllMessageReactions nil .Message.ID}}{{addMessageReactions nil .Message.ID "📱"}}
{{end}}
{{end}}
{{end}}
{{with $msg.Author}}
{{if reFind "Snippet Search|Snippet List" .Name}}
{{$r := (reFindAllSubmatches `\?author=(\d+)\?messageid=(\d+)` .IconURL)}}
{{if eq $.Reaction.Emoji.Name "🗑️"}}
{{if or (eq (str $.User.ID) (index $r 0 1)) (in (split (index (split (exec "viewperms") "\n") 2) ", ") "ManageMessages")}}
{{deleteMessage nil $.Message.ID 0}}
{{deleteMessage nil (index $r 0 2) 0}}
{{end}}
{{else if and (eq $.Reaction.Emoji.Name "◀" "▶") (reFind `React with 🗑️ to delete this message\.` $msg.Footer.Text) (eq .Name "Snippet List")}}
{{if eq $.Reaction.Emoji.Name "▶"}}
{{$jump := reFind `\d+` $msg.Footer.Text|toInt|add -1}}{{$send := true}}{{$page := mult 10 (add 1 $jump)}}
{{$grab := "```\n"}}{{$count := $page}}
{{range dbTopEntries `snippet\_%` 10 $page}}
{{$count = add 1 $count}}
{{$grab = print $grab "\n" (printf "#%-4d" $count) (slice .Key 8)}}
{{else}}
{{$send = false}}
{{end}}
{{if $send}}
{{editMessage nil $.Message.ID (cembed
"author" (sdict "name" "Snippet List" "icon_url" $msg.Author.IconURL)
"description" (print $grab "```")
"footer" (sdict "text" (print "React with 🗑️ to delete this message.\nPage: " (add 2 $jump)))
)}}
{{end}}
{{end}}
{{if eq $.Reaction.Emoji.Name "◀"}}
{{$jump := reFind `\d+` $msg.Footer.Text|toInt}}{{$send := true}}{{$page := mult 10 (sub $jump 2)}}
{{$grab := "```\n"}}{{$count := $page}}{{if lt $page 0}}{{$send = false}}{{end}}
{{if $send}}
{{range dbTopEntries `snippet\_%` 10 $page}}
{{$count = add 1 $count}}
{{$grab = print $grab "\n" (printf "#%-4d" $count) (slice .Key 8)}}
{{else}}
{{$send = false}}
{{end}}
{{if $send}}
{{editMessage nil $.Message.ID (cembed
"author" (sdict "name" "Snippet List" "icon_url" $msg.Author.IconURL)
"description" (print $grab "```")
"footer" (sdict "text" (print "React with 🗑️ to delete this message.\nPage: " (sub $jump 1)))
)}}
{{end}}
{{end}}
{{end}}
{{end}}
{{else if (eq "Counting Leaderboard" .Name)}}
{{$r := (reFindAllSubmatches `\?author=(\d+)\?messageid=(\d+)` .IconURL)}}
{{if eq $.Reaction.Emoji.Name "🗑️" "🗑"}}
{{if or (eq (str $.User.ID) (index $r 0 1)) (in (split (index (split (exec "viewperms") "\n") 2) ", ") "ManageMessages")}}
{{deleteMessage nil $.Message.ID 0}}
{{deleteMessage nil (index $r 0 2) 0}}
{{end}}
{{end}}
{{$page := toInt (reFind `\d+` $msg.Footer.Text)}}
{{if eq $.Reaction.Emoji.Name "⬅️"}}
{{$page = sub $page 1}}
{{else if eq $.Reaction.Emoji.Name "➡️"}}
{{$page = add $page 1}}
{{else}}
{{$page = -1}}
{{end}}
{{if gt $page 0}}
{{$num_per_page := 10}}
{{$skip := mult (sub $page 1) $num_per_page}}
{{$text := ""}}{{$count := add $skip 1}}
{{range (dbTopEntries `counting_tracker` 10 $skip)}}
{{$member := getMember .UserID}}
{{if $member}}
{{$text = joinStr "\n" $text (printf "#%-4d %5d - %-20s" $count (toInt .Value) $member.User)}}
{{else}}
{{$text = joinStr "\n" $text (printf "#%-4d %5d - %-20d" $count (toInt .Value) .UserID)}}
{{end}}
{{$count = add $count 1}}
{{end}}
{{if $text}}
{{$embed := cembed "author" (sdict "name" "Counting Leaderboard" "icon_url" (print "https://cdn.discordapp.com/emojis/714491414100181092.png?author=" $.User.ID "?messageid=" $.Message.ID)) "description" (print "```# -- Points -- User\n" $text "```") "footer" (sdict "text" (print "React with 🗑️ to delete this message.\nPage: " $page)) "color" (randInt 0 16777216)}}
{{editMessage nil $.ReactionMessage.ID $embed}}
{{end}}
{{end}}
{{else if ($rf := reFindAllSubmatches `(Mutes|Bans|Kicks|Warnings|Warns|Timeouts) - User : (\d+)` .Name)}}
{{$authorname := .Name}}
{{$r := (reFindAllSubmatches `\?author=(\d+)\?messageid=(\d+)` .IconURL)}}
{{if eq $.Reaction.Emoji.Name "🗑️" "🗑"}}
{{if or (eq (str $.User.ID) (index $r 0 1)) (in (split (index (split (exec "viewperms") "\n") 2) ", ") "ManageMessages")}}
{{deleteMessage nil $.Message.ID 0}}
{{deleteMessage nil (index $r 0 2) 0}}
{{end}}
{{end}}
{{$page := toInt (reFind `\d+` $msg.Footer.Text)}}
{{if eq $.Reaction.Emoji.Name "◀️"}}
{{$page = sub $page 1|add -1}}
{{else if eq $.Reaction.Emoji.Name "▶️"}}
{{$page = add $page 1|add -1}}
{{else}}
{{$page = -1}}
{{end}}
{{$dblogs := sdict}}{{with dbGet (index $rf 0 2|toInt) "logs"}}{{$dblogs = .Value}}{{end}}
{{$type := reFind `warn|mute|kick|ban|timeout` (lower .Name)}}
{{if ne $page -1}}
{{$c := 0}}{{$grab := ""}}
{{range $name, $value := $dblogs}}
{{- if in $name $type}}
{{- $c = add 1 $c}}
{{- if and (gt $c (mult $page 5)) (le $c (add 1 $page|mult 5))}}
{{- with $value}}
{{- if (index .c 0)}}{{.Set "c" (print "\n🔎Where: <#" (index .c 0) "> `" (index .c 1) "`")}}{{else}}{{.Set "c" ""}}{{end}}
{{- if .d}}{{.Set "d" (print "\n<:voice:711600648659140678>Duration: <t:" (.ctime.Add (print .d "s"|toDuration)).Unix ":R>")}}{{else}}{{.Set "d" ""}}{{end}}
{{- if .l}}{{.Set "l" (print "\n<:log:603248981132181504>Logs: [Message Logs](https://yagpdb.xyz/public/" $.Guild.ID "/log/" .l ")")}}{{end}}
{{- $grab = print $grab "**<:cc_ID:780036580592189460>" (title $type) " ID: " (slice $name 4) "**" .c "\n🕐When: <t:" $value.ctime.Unix ":d><t:" $value.ctime.Unix ":t>\n🛡️Author: <@" .aid "> `" .as "`" .d .l "\n<:status:704342789177212979>Reason: " .r "\n\n"}}
{{- end}}
{{- end}}
{{- end}}
{{end}}
{{if not $grab}}{{$grab = "Nobody here but us chickens🐔"}}{{end}}
{{editMessage nil $.Message.ID (cembed
"author" $msg.Author
"description" (print "**Total " (index $rf 0 1) ": " $c "**\n\n" $grab)
"footer" (sdict "text" (print "React with 🗑️ to delete this message.\nPage: " (add 1 $page))))}}
{{$page := add 1 $page}}
{{$max := fdiv $c 5|roundCeil|toInt}}
{{deleteAllMessageReactions nil $.Message.ID}}
{{if and (ne $page $max) (eq $page 1)}}{{addMessageReactions nil $.Message.ID "blank:656125423247425557" "▶️" "🗑️"}}{{end}}
{{if and (ne $page 1) (eq $page $max)}}{{addMessageReactions nil $.Message.ID "◀️" "blank:656125423247425557" "🗑️"}}{{end}}
{{if and (ne $page $max) (ne $page 1)}}{{addMessageReactions nil $.Message.ID "◀️" "▶️" "🗑️"}}{{end}}
{{end}}
{{end}}
{{end}}
{{end}}