-
Notifications
You must be signed in to change notification settings - Fork 66
/
Join_Message.yag
42 lines (33 loc) · 1.75 KB
/
Join_Message.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
{{/*
Trigger type: Join Message Server
(Can be found in 'Notifications & Feeds' > 'General' > 'Join message in server channel')
Description: Part of the code for the stickyrole system that gives back roles on re-join
Copyright (c): Black Wolf, 2021
License: MIT
Repository: https://github.com/BlackWolfWoof/yagpdb-cc/
*/}}
{{$mode := false}}
{{/*true = WHITELIST; A $list of roles that WILL be given back on join*/}}
{{/*false = BLACKLIST; A $list of roles that WON'T be given back on join*/}}
{{$list := cslice 861997703759134770 861997702396772373 861997701096538112}}
{{/*A list of the roles. When using $mode false you can keep this empty if you want to give back all roles*/}}
{{/*Correct db if expiring*/}}
{{$db := dbGet .User.ID "stickyroles"}}{{if $db.ExpiresAt}}{{dbSet .User.ID "stickyroles" $db.Value}}{{end}}
{{/*Yag's highest role position*/}}
{{$yagpos := 0}}{{range (getMember $.BotUser.ID).Roles}}{{if gt ($_ := ($.Guild.GetRole .).Position) $yagpos}}{{$yagpos = $_}}{{end}}{{end}}
{{/*If another bot already gave roles they are included in setRoles*/}}
{{$roles := cslice}}{{range .Member.Roles}}{{if gt $yagpos ($.Guild.GetRole .).Position}}{{$roles = $roles.Append .}}{{end}}{{end}}
{{/*Putting together cslice of roles that the user should have*/}}
{{range $id, $name := $db.Value}}{{/*Extracting role id's*/}}
{{- $id := toInt $id -}}
{{- if $mode -}}{{/*Whitelist*/}}
{{- if and (in $list $id) (gt $yagpos ($.Guild.GetRole $id).Position) (in $roles $id|not) -}}
{{- $roles = $roles.Append $id -}}
{{- end -}}
{{- else -}}{{/*Blacklist*/}}
{{- if and (in $list $id|not) (gt $yagpos ($.Guild.GetRole $id).Position) (in $roles $id|not) -}}
{{$roles = $roles.Append $id -}}
{{- end -}}
{{- end -}}
{{end}}
{{setRoles .User.ID $roles}}