forked from BlackWolfWoof/yagpdb-cc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutechecker.yag
141 lines (122 loc) · 7.1 KB
/
mutechecker.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
{{/*
You don't know if you set up your channel permissions right and if a muted user can keep sending messages? Well with this code you can test it out!
Trigger Type: Command
Trigger: mutechecker
Usage:
on $yagmute false: mutechecker @user @mutedrole
on $yagmute false: mutechecker userid roleid
on $yagmute true: mutechecker userid
Copyright (c): Black Wolf, 2021
License: MIT
Repository: https://github.com/BlackWolfWoof/yagpdb-cc/
*/}}
{{/*If YAGPDB removes roles on mute set this to true.
NOTE: This might dm the user and lets them know they have been muted*/}}
{{$yagmute := true}}
{{$args := parseArgs 1 (print .Cmd " <UserID/UserMention> <RoleID/RoleMention (optional)>") (carg "userid" "") (carg "role" "")}}
{{define "perms"}}{{.TemplateArgs.Set "Out" (exec "viewperms" .TemplateArgs.userid)}}{{end}}
{{$mutedrole := .ExecData.mutedrole}}{{$beforeslice := .ExecData.beforeslice}}{{$maxspace := .ExecData.maxspace}}{{$lenallchannels := .ExecData.lenallchannels}}{{$channels := .ExecData.channels}}{{$msgid := .ExecData.msgid}}{{$desc := .ExecData.desc}}{{$userid := .ExecData.userid}}{{$nil := .ExecData.nil}}{{$role := .ExecData.role}}{{$ttc := .ExecData.ttc}}{{$starttime := .ExecData.starttime}}{{$mode := .ExecData.mode}}
{{if not .ExecData}}
{{with getMember ($args.Get 0)}}{{$userid = .User.ID}}{{$beforeslice = .Roles}}{{end}}
{{$starttime = currentTime}}
{{$channels = sdict}}{{$desc = sdict}}{{$maxspace = 0}}
{{range .Guild.Channels}}
{{- if eq .Type 0}}
{{- $channels.Set (str .ID) .Name}}
{{- if gt (toRune .Name|len) $maxspace}}
{{- $maxspace = toRune .Name|len}}
{{- end}}
{{- end}}
{{end}}
{{$nil = .Channel.ID}}
{{$lenallchannels = len $channels}}
{{$msgid = sendMessageRetID $nil (cembed "description" (print "Loading permissions..."))}}
{{$role = ($args.Get 1).ID}}
{{$time := fdiv $lenallchannels 3|mult 8|roundCeil|add 18|mult 1000000000|toDuration}}
{{$ttc = currentTime.Add $time}}
{{if (in (split (index (split (exec "viewperms" $userid) "\n") 2) ", ") "Administrator")}}
{{$_ := parseArgs 10 "**__Code Stopped! The user has Administrator permissions and it makes no sense to test the role on them. Select another user.__**" (carg "duration" "")}}
{{end}}
{{if $yagmute}}
{{$_ := exec "mute" (str $userid) (str $time) "Please ignore this mute. An admin is testing out the server's mute role on you."}}
{{$mode = "YAGPDB Mute"}}
{{/*Some hacky shit to find out the muted role... this was a fucking pain to code and test*/}}
{{$after := sdict}}{{range (getMember $userid).Roles}}{{$after.Set (str .) 0}}{{end}}
{{range $ID, $_ := $after}}{{if in $beforeslice (toInt $ID)}}{{$after.Del $ID}}{{end}}{{end}}
{{range $ID, $_ := $after}}{{$mutedrole = toInt $ID}}{{end}}
{{if not $mutedrole}}
{{$_ := parseArgs 10 "**__Code Stopped!\n- The user was already muted\nOR\n- If you set $yagmute to true you will have to select a mute role on the control panel under \"Tools & Utilities > Moderation > Mute > Mute role\"__**" (carg "duration" "")}}
{{end}}
{{else}}
{{if ($args.Get 1)}}
{{giveRoleID $userid $role}}
{{takeRoleID $userid $role (fdiv $lenallchannels 3|mult 8|roundCeil|add 10)}}
{{$mode = "role input"}}
{{$mutedrole = $role}}
{{else}}
{{$_ := parseArgs 10 "**__Code Stopped! If $yagmute is set to false you need to input the muted role.__**" (carg "duration" "")}}
{{end}}
{{end}}
{{else}}
{{$c := 1}}{{$permlist := sdict "userid" $userid}}
{{range $id, $_ := $channels}}
{{- if le $c 3}}
{{- $v0 := sendTemplate $id "perms" $permlist}}
{{- if (in (split (index (split $permlist.Out "\n" ) 2) ", ") "ReadMessages")}}
{{- if (in (split (index (split $permlist.Out "\n" ) 2) ", ") "SendMessages")}}
{{- $roles := ""}}{{- $muted := true}}
{{- range (getChannel $id).PermissionOverwrites}}
{{- $roleid := .ID}}
{{- $pbit := .Allow}}
{{- $type := .Type}}
{{- $permissions := cslice "CREATE_INSTANT_INVITE" "KICK_MEMBERS" "BAN_MEMBERS" "ADMINISTRATOR" "MANAGE_CHANNELS" "MANAGE_GUILD" "ADD_REACTIONS" "VIEW_AUDIT_LOG" "PRIORITY_SPEAKER" "STREAM" "VIEW_CHANNEL" "SEND_MESSAGES" "SEND_TTS_MESSAGES" "MANAGE_MESSAGES" "EMBED_LINKS" "ATTACH_FILES" "READ_MESSAGE_HISTORY" "MENTION_EVERYONE" "USE_EXTERNAL_EMOJIS" "VIEW_GUILD_INSIGHTS" "CONNECT" "SPEAK" "MUTE_MEMBERS" "DEAFEN_MEMBERS" "MOVE_MEMBERS" "USE_VAD" "CHANGE_NICKNAME" "MANAGE_NICKNAMES" "MANAGE_ROLES" "MANAGE_WEBHOOKS" "MANAGE_EMOJIS" "USE_SLASH_COMMANDS" "REQUEST_TO_SPEAK" "MANAGE_THREADS" "USE_PUBLIC_THREADS" "USE_PRIVATE_THREADS"}}
{{- range seq 0 (len $permissions)}}
{{- if (mod $pbit 2)}}
{{- if eq (index $permissions . ) "SEND_MESSAGES"}}
{{- if eq 0 $type}}
{{- $roles = joinStr ", " $roles ($.Guild.GetRole $roleid).Name}}
{{- else}}
{{- $roles = joinStr ", " $roles (getMember $roleid).User.String}}
{{- end}}
{{- end}}
{{- end}}
{{- $pbit = div $pbit 2}}
{{- end}}
{{- if eq .ID $mutedrole}}
{{- $pbit := .Deny}}
{{- range seq 0 (len $permissions)}}
{{- if (mod $pbit 2)}}
{{- if eq (index $permissions . ) "SEND_MESSAGES"}}
{{- if eq 0 $type}}
{{- $muted = false}}
{{- end}}
{{- end}}
{{- end}}
{{- $pbit = div $pbit 2}}
{{- end}}
{{- end}}
{{- end}}
{{- if $muted}}
{{- $roles = "❗Mute role doesn't deny SendMessages permissions❗"}}
{{- end}}
{{- $space := " "}}
{{- range (toRune $_|len|sub $maxspace|add 1|seq 0)}}{{$space = print $space " "}}{{end}}
{{- $desc.Set $id (print "#" $_ $space $roles)}}
{{- end}}
{{- end}}
{{- $channels.Del $id}}
{{- $c = add 1 $c}}
{{end}}
{{end}}
{{end}}
{{if eq (len $channels) 0}}
{{$message := "Please take a look at the permissions in the following channels:"}}
{{range $print, $_ := $desc}}
{{- $message = print $message "\n" $_}}
{{end}}
{{deleteMessage $nil $msgid 0}}
{{sendMessage $nil (complexMessage "content" (print .User.Mention " I am done scanning! The scan took **" (sub currentTime.UnixNano $starttime.UnixNano|toDuration|humanizeDurationSeconds) "** and was on mute mode **" $mode "** for role **<@&" $mutedrole ">**.\nIn the following channels **" (getMember $userid).User.String "** can still speak when they are muted:") "file" (or $message "No channels are setup wrong, congrats 🐺"))}}
{{else}}
{{editMessage $nil $msgid (cembed "color" 0xffff00 "title" "Permission checker - Mute" "description" (print .User.Mention " will be pinged if the scan is done.\n<:stopwatch1:650328464825516062>Time left: `" ($ttc.Sub currentTime|humanizeDurationSeconds) "~`\n<a:discord_loading:714051544265392229>Scanned: " (sub $lenallchannels (len $channels)) "/" $lenallchannels "\n🔇Mute Mode: **" $mode "** - **<@&" $mutedrole ">**\n<:Member:708268764495609856>Tested on: <@" $userid "> **do not unmute them!**"))}}
{{execCC .CCID nil 8 (sdict "mutedrole" $mutedrole "beforeslice" $beforeslice "maxspace" $maxspace "msgid" $msgid "channels" $channels "lenallchannels" $lenallchannels "desc" $desc "userid" $userid "nil" $nil "role" $role "ttc" $ttc "starttime" $starttime "mode" $mode)}}
{{end}}