Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LUH-Informatik-Bot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maurice Höppner
LUH-Informatik-Bot
Commits
c2454fa5
Commit
c2454fa5
authored
3 years ago
by
Patric Plattner
Browse files
Options
Downloads
Patches
Plain Diff
Adding the ability to unselect a role.
parent
27943b3a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/roles.js
+17
-17
17 additions, 17 deletions
components/roles.js
util/perm.js
+4
-4
4 additions, 4 deletions
util/perm.js
with
21 additions
and
21 deletions
components/roles.js
+
17
−
17
View file @
c2454fa5
...
...
@@ -4,7 +4,6 @@ const checkPerm = require('../util/perm');
// slashcommand handler
async
function
addRoleMenu
(
interaction
)
{
console
.
log
(
'
test
'
);
if
(
!
(
await
checkPerm
(
interaction
.
member
,
'
role_menu
'
)))
{
await
interaction
.
reply
({
content
:
'
You are not authorized to do this.
'
,
ephemeral
:
true
})
return
;
...
...
@@ -20,8 +19,8 @@ async function addRoleMenu(interaction) {
.
setPlaceholder
(
"
Select a role.
"
)
.
addOptions
([
{
label
:
'
Placeholder
'
,
value
:
'
placeholder
'
label
:
'
Reset Selection
'
,
value
:
'
select_reset
'
}
])
);
...
...
@@ -92,9 +91,6 @@ async function addRoleToMenu(interaction) {
});
if
(
menu
!=
null
)
{
let
components
=
message
.
components
;
if
(
components
[
0
].
components
[
0
].
options
[
0
].
value
===
'
placeholder
'
)
{
components
[
0
].
components
[
0
].
options
=
[];
}
if
(
!
menu
.
roles
.
map
((
role
)
=>
role
.
roleID
).
includes
(
role
.
id
.
toString
()))
{
components
[
0
].
components
[
0
].
addOptions
({
label
:
role
.
name
,
...
...
@@ -164,12 +160,6 @@ async function deleteRoleFromMenu(interaction) {
const
value
=
menu
.
roles
[
menu
.
roles
.
map
(
role
=>
role
.
roleID
).
indexOf
(
role
.
id
.
toString
())].
value
;
const
index1
=
menu
.
roles
.
map
(
role
=>
role
.
value
).
indexOf
(
value
);
menu
.
roles
.
splice
(
index1
,
1
);
if
(
message
.
components
[
0
].
components
[
0
].
options
.
length
===
1
)
{
message
.
components
[
0
].
components
[
0
].
addOptions
({
label
:
"
Placeholder
"
,
value
:
"
placeholder
"
});
}
const
index2
=
message
.
components
[
0
].
components
[
0
].
options
.
map
(
option
=>
option
.
value
).
indexOf
(
value
);
message
.
components
[
0
].
components
[
0
].
options
...
...
@@ -255,7 +245,6 @@ async function editRoleMenu(interaction) {
}
const
slashCommandHandler
=
async
(
interaction
)
=>
{
console
.
log
(
'
slashCommandHandler
'
);
if
(
interaction
.
commandName
===
'
add_role_menu
'
)
{
await
addRoleMenu
(
interaction
);
}
else
if
(
interaction
.
commandName
===
'
delete_role_menu
'
)
{
...
...
@@ -283,12 +272,23 @@ const selectMenuHandler = async (interaction) => {
channelID
:
channel
.
id
,
messageID
:
message
.
id
});
console
.
log
(
"
1
"
);
if
(
interaction
.
values
[
0
]
!=
'
placeholder
'
)
{
console
.
log
(
"
2
"
);
if
(
menu
!=
null
)
{
const
roleIDs
=
menu
.
roles
.
map
(
role
=>
role
.
roleID
);
roleIDs
.
forEach
(
roleID
=>
interaction
.
member
.
roles
.
remove
(
roleID
));
interaction
.
member
.
roles
.
add
(
roleIDs
[
menu
.
roles
.
map
(
role
=>
role
.
value
).
indexOf
(
interaction
.
values
[
0
])]);
await
interaction
.
reply
({
content
:
'
You have received your role.
'
,
ephemeral
:
true
});
console
.
log
(
"
3
"
);
if
(
interaction
.
values
[
0
]
===
'
select_reset
'
)
{
console
.
log
(
"
4
"
);
const
roleIDs
=
menu
.
roles
.
map
(
role
=>
role
.
roleID
);
roleIDs
.
forEach
(
roleID
=>
interaction
.
member
.
roles
.
remove
(
roleID
));
await
interaction
.
reply
({
content
:
'
Your role has been removed.
'
,
ephemeral
:
true
});
}
else
{
console
.
log
(
"
5
"
);
const
roleIDs
=
menu
.
roles
.
map
(
role
=>
role
.
roleID
);
roleIDs
.
forEach
(
roleID
=>
interaction
.
member
.
roles
.
remove
(
roleID
));
interaction
.
member
.
roles
.
add
(
roleIDs
[
menu
.
roles
.
map
(
role
=>
role
.
value
).
indexOf
(
interaction
.
values
[
0
])]);
await
interaction
.
reply
({
content
:
'
You have received your role.
'
,
ephemeral
:
true
});
}
}
else
{
await
interaction
.
reply
({
content
:
'
Internal Error. Please contact admins.
'
,
ephemeral
:
true
});
}
...
...
This diff is collapsed.
Click to expand it.
util/perm.js
+
4
−
4
View file @
c2454fa5
...
...
@@ -8,10 +8,10 @@ module.exports = async (member, permission) => {
return
false
;
}
if
(
permission
===
'
role_menu
'
)
{
console
.
log
(
member
.
roles
.
cache
);
console
.
log
(
config
.
permissions
.
roleMenu
);
return
member
.
roles
.
cache
.
some
((
role
)
=>
config
.
permissions
.
roleMenu
.
some
((
prole
)
=>
prole
==
role
.
id
.
toString
()))
||
member
.
permissions
.
has
(
Permissions
.
FLAGS
.
ADMINISTRATOR
);
//
console.log(member.roles.cache);
//
console.log(config.permissions.roleMenu);
console
.
log
(
"
ASD
"
);
return
member
.
roles
.
cache
.
some
((
role
)
=>
config
.
permissions
.
roleMenu
.
some
((
prole
)
=>
prole
==
role
.
id
.
toString
()))
||
member
.
permissions
.
has
(
Permissions
.
FLAGS
.
ADMINISTRATOR
);
}
return
false
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment