forked from BlackWolfWoof/yagpdb-cc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
message_link.yag
115 lines (110 loc) · 4.71 KB
/
message_link.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
{{/*
Trigger: (?:[^<]|\A)https://(?:\w+\.)?discord(?:app)?\.com/channels\/(\d+)\/(\d+)\/(\d+)(?:[^>\d]|\z)
Trigger Type: Regex
Usage:
Right click on a message to copy the message link and send it in chat.
Copyright (c): Black Wolf, 2021
License: MIT
Repository: https://github.com/BlackWolfWoof/yagpdb-cc/
*/}}
{{$m := reFindAllSubmatches `(?i)https://(?:\w+\.)?discord(?:app)?\.com/channels\/(\d+)\/(\d+)\/(\d+)` .Message.Content}}{{$reminder := true}}
{{if not (eq (toInt64 (index $m 0 1)) .Guild.ID)}}
{{sendMessage nil (cembed
"author" (sdict
"name" "Unknown User"
"icon_url" "https://i.imgur.com/jNz2Dwp.png")
"description" (print "\n\n**[Message](" (index $m 0 0) "/) in <#" (index $m 0 2) ">**\n" "<:excl:565142262401728512> Unknown Message")
"color" 0xF04747
"footer" (sdict
"text" (print "Command triggered by " .Message.Author.String ". Message from"))
"timestamp" (div (index $m 0 3) 4194304 | mult 1000000 | toDuration | .DiscordEpoch.Add))}}
{{else}}
{{$msg := getMessage (index $m 0 2) (index $m 0 3)}}
{{if not $msg}}
{{sendMessage nil (cembed "title" "Something broke :(" "color" 0xDD2E44 "description" "<:cross:705738821110595607>OOPS! The message you are trying to quote doesn't exist!\nCheck if the channel and message exists.")}}
{{else}}
{{$content := $msg.Content}}
{{$mc := reReplace `(?:https?://)?(?:www\.)?(discord(?:app)?\.gg(?:/|\\+/+)|discord(?:app)?\.com(?:/|\\+/+)(?:invite/))\w{2,}|(?:https?://)?(?:www\.)?(?:discord(?:app)?\.(?:io|me|li)|invite\.gg|dsc\.gg|top\.gg\/servers|discordservers\.com\/(?:server|bump))(?:/|\\+/+)[A-z+0-9]{2,}` $msg.Content "[Invite Removed](https://example.com/)"}}
{{$e := sdict
"author" (sdict
"name" (print $msg.Author.String " (ID " $msg.Author.ID ")")
"icon_url" ($msg.Author.AvatarURL "1024"))
"color" 0x36393F
"footer" (sdict
"text" (print "Command triggered by " .User.String ". Message from"))
"timestamp" $msg.Timestamp}}
{{/*Anti overflow embed*/}}
{{$fields := cslice}}{{$desc := ""}}
{{if gt (len $mc) 2000}}
{{$cslice := reFindAll `.{1,1000}` $mc}}
{{/*Split into umtiple fields*/}}
{{range $num, $text := $cslice}}{{if eq $num 0 1}}{{$desc = print $desc $text}}{{else}}{{$fields = $fields.Append (sdict "name" "\u200B" "value" $text "inline" false)}}{{end}}{{end}}
{{$fields = $fields.Append (sdict "name" "\u200B" "value" (print "\n\n**[Message](" (index $m 0 0) ") in <#" $msg.ChannelID ">**") "inline" false)}}
{{$e.Set "fields" $fields}}
{{else}}
{{$desc = (print "\n\n**[Message](" (index $m 0 0) ") in <#" $msg.ChannelID ">**\n" $mc)}}
{{end}}
{{if and $msg.Content (not $msg.Embeds)}}
{{$e.Set "description" $desc}}
{{end}}
{{$fo := $e.footer}}
{{$ti := $msg.Timestamp}}
{{if or $msg.Attachments $msg.Embeds}}
{{range $c,$ma := (or $msg.Attachments $msg.Embeds)}}
{{$filename := ""}}{{$count := ""}}
{{if eq (printf "%T" .) "*discordgo.MessageAttachment"}}
{{$filename = .Filename}}{{$count = len $msg.Attachments}}
{{else if eq (printf "%T" .) "*discordgo.MessageEmbed"}}
{{if eq .Type "image"}}
{{$filename = .URL}}{{$count = len $msg.Embeds}}
{{end}}
{{end}}
{{if ne $filename ""}}
{{$e.Del "footer"}}
{{$e.Del "timestamp"}}
{{if eq $c 0}}
{{$e.Set "description" $desc}}
{{end}}
{{if eq $count (add $c 1)}}
{{$e.Set "footer" $fo}}
{{$e.Set "timestamp" $ti}}
{{end}}
{{if (reFind `(?i)\.(jpg|jpeg|png|gif|tif|tiff|webp)` $filename)}}
{{$e.Set "image" (sdict "url" .URL)}}
{{sendMessage nil (cembed $e)}}
{{else}}
{{$fields = $fields.AppendSlice (cslice
(sdict "name" "File Name" "value" (print "`" $filename "`") "inline" true)
(sdict "name" "URL" "value" (print "[File Link](" .URL ")") "inline" true))}}
{{$e.Set "fields" $fields}}
{{sendMessage nil (cembed $e)}}
{{end}}
{{$e.Del "fields"}}
{{$e.Del "image"}}
{{$e.Del "description"}}
{{$e.Del "author"}}
{{$reminder = false}}{{$content = ""}}
{{end}}
{{end}}
{{else}}
{{if and $msg.Content (not $msg.Embeds)}}
{{sendMessage nil (cembed $e)}}
{{end}}
{{end}}
{{if $msg.Embeds}}
{{if $reminder}}{{$embed2 := ""}}
{{if eq (index $msg.Embeds 0).Type "rich"}}
{{$embed2 = index $msg.Embeds 0}}
{{sendMessage nil (complexMessage "embed" $embed2 "content" $content)}}
{{else if ne (index $msg.Embeds 0).Type "image"}}
{{sendMessage nil $mc}}
{{end}}
{{$e.Set "description" (print "**[Embed Link](" (index $m 0 0) ") to <#" $msg.ChannelID ">**")}}
{{sendMessage nil (cembed $e)}}
{{end}}
{{end}}
{{if and (eq (len (index $m 0 0)) (len .Message.Content)) (not .Message.Attachments)}}
{{deleteTrigger 1}}
{{end}}
{{end}}
{{end}}