Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fernuni-bot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dnns01
fernuni-bot
Commits
5642f503
Commit
5642f503
authored
11 months ago
by
dnns01
Browse files
Options
Downloads
Patches
Plain Diff
Add modal to command add and capability to update description
parent
a9bd4cfb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
extensions/text_commands.py
+15
-30
15 additions, 30 deletions
extensions/text_commands.py
fernuni_bot.py
+1
-0
1 addition, 0 deletions
fernuni_bot.py
modals/text_command_modal.py
+52
-0
52 additions, 0 deletions
modals/text_command_modal.py
models.py
+1
-0
1 addition, 0 deletions
models.py
with
69 additions
and
30 deletions
extensions/text_commands.py
+
15
−
30
View file @
5642f503
...
...
@@ -6,6 +6,7 @@ from discord import app_commands, Interaction
from
discord.ext
import
commands
import
utils
from
modals.text_command_modal
import
TextCommandModal
from
models
import
Command
,
CommandText
from
views.text_command_view
import
TextCommandView
...
...
@@ -52,24 +53,17 @@ class TextCommands(commands.GroupCog, name="commands", description="Text Command
@app_commands.command
(
name
=
"
add
"
,
description
=
"
Ein neues Text Command hinzufügen, oder zu einem bestehenden einen weiteren Text hinzufügen
"
)
@app_commands.describe
(
cmd
=
"
Command. Bsp:
\"
link
\"
für das Command
\"
/link
\"
.
"
,
text
=
"
Text, der bei Benutzung des Commands ausgegeben werden soll.
"
,
description
=
"
Beschreibung des Commands, die bei Benutzung angezeigt wird. Wird nur übernommen, bei neuen Commands.
"
)
async
def
cmd_add
(
self
,
interaction
:
Interaction
,
cmd
:
str
,
text
:
str
,
description
:
str
):
await
interaction
.
response
.
defer
(
ephemeral
=
True
)
text
=
"
Text, der bei Benutzung des Commands ausgegeben werden soll.
"
)
async
def
cmd_add
(
self
,
interaction
:
Interaction
,
cmd
:
str
,
text
:
str
):
if
not
re
.
match
(
r
"
^[a-z0-9]+(-[a-z0-9]+)*$
"
,
cmd
):
await
interaction
.
edit_original_response
(
content
=
"
Ein Command darf nur aus Kleinbuchstaben und Zahlen bestehen, die durch Bindestriche getrennt werden können.
"
)
return
if
utils
.
is_mod
(
interaction
.
user
,
self
.
bot
):
if
await
self
.
add_command
(
cmd
,
text
,
description
,
interaction
.
guild_id
):
await
interaction
.
edit_original_response
(
content
=
"
Dein Command wurde erfolgreich hinzugefügt!
"
)
else
:
await
interaction
.
edit_original_response
(
content
=
"
Das Command, dass du hinzufügen möchtest existiert bereits.
"
)
else
:
await
self
.
suggest_command
(
cmd
,
text
,
description
,
interaction
.
guild_id
)
await
interaction
.
edit_original_response
(
content
=
"
Dein Vorschlag wurde den Mods zur Genehmigung vorgelegt.
"
)
command
=
Command
.
get_or_none
(
Command
.
command
==
cmd
)
description
=
command
.
description
if
command
else
""
await
interaction
.
response
.
send_modal
(
TextCommandModal
(
text_commands
=
self
,
cmd
=
cmd
,
text
=
text
,
description
=
description
))
@app_commands.command
(
name
=
"
edit
"
,
description
=
"
Bearbeite bestehende Text Commands
"
)
@app_commands.describe
(
cmd
=
"
Command, dass du bearbeiten möchtest
"
,
id
=
"
ID des zu bearbeitenden Texts
"
,
...
...
@@ -125,6 +119,11 @@ class TextCommands(commands.GroupCog, name="commands", description="Text Command
mod_channel
=
await
self
.
bot
.
fetch_channel
(
mod_channel_id
)
if
command
:
=
Command
.
get_or_none
(
Command
.
command
==
cmd
):
CommandText
.
create
(
text
=
text
,
command
=
command
.
id
)
if
command
.
description
!=
description
:
Command
.
update
(
description
=
description
).
where
(
Command
.
id
==
command
.
id
).
execute
()
self
.
bot
.
tree
.
get_command
(
command
.
command
).
description
=
description
await
self
.
bot
.
sync_slash_commands_for_guild
(
command
.
guild_id
)
await
mod_channel
.
send
(
f
"
Beschreibung von Command `
{
cmd
}
` geändert zu `
{
description
}
`
"
)
else
:
if
self
.
exists
(
cmd
):
return
False
...
...
@@ -135,27 +134,13 @@ class TextCommands(commands.GroupCog, name="commands", description="Text Command
await
mod_channel
.
send
(
f
"
[
{
cmd
}
] => [
{
text
}
] erfolgreich hinzugefügt.
"
)
return
True
async
def
suggest_command
(
self
,
cmd
:
str
,
text
:
str
,
description
:
str
,
guild_id
:
int
):
mod_channel_id
=
self
.
bot
.
get_settings
(
guild_id
).
modmail_channel_id
mod_channel
=
await
self
.
bot
.
fetch_channel
(
mod_channel_id
)
command
=
Command
.
get_or_none
(
Command
.
command
==
cmd
)
title
=
"
Vorschlag für neuen Command Text
"
if
command
else
"
Vorschlag für neues Command
"
embed
=
discord
.
Embed
(
title
=
title
)
embed
.
add_field
(
name
=
"
Command
"
,
value
=
cmd
,
inline
=
False
)
embed
.
add_field
(
name
=
"
Text
"
,
value
=
text
,
inline
=
False
)
if
not
command
:
embed
.
add_field
(
name
=
"
Beschreibung
"
,
value
=
description
,
inline
=
False
)
await
mod_channel
.
send
(
embed
=
embed
,
view
=
TextCommandView
(
self
))
async
def
remove_text
(
self
,
command
,
command_texts
,
id
):
command_text
=
list
(
command_texts
)[
id
]
command_text
.
delete_instance
(
recursive
=
True
)
if
command
.
texts
.
count
()
==
0
:
await
self
.
remove_command
(
command
)
async
def
remove_command
(
self
,
command
):
async
def
remove_command
(
self
,
command
:
Command
):
await
self
.
unregister_command
(
command
)
command
.
delete_instance
(
recursive
=
True
)
...
...
@@ -187,11 +172,11 @@ class TextCommands(commands.GroupCog, name="commands", description="Text Command
self
.
bot
.
tree
.
add_command
(
process_command
)
if
sync
:
await
self
.
bot
.
tree
.
sync
(
)
await
self
.
bot
.
sync_slash_commands_for_guild
(
command
.
guild_id
)
async
def
unregister_command
(
self
,
command
:
Command
):
self
.
bot
.
tree
.
remove_command
(
command
.
command
)
await
self
.
bot
.
tree
.
sync
(
)
await
self
.
bot
.
sync_slash_commands_for_guild
(
command
.
guild_id
)
async
def
setup
(
bot
:
commands
.
Bot
)
->
None
:
...
...
This diff is collapsed.
Click to expand it.
fernuni_bot.py
+
1
−
0
View file @
5642f503
...
...
@@ -32,6 +32,7 @@ class Boty(commands.Bot):
self
.
view_manager
:
ViewManager
=
ViewManager
(
self
)
async
def
setup_hook
(
self
)
->
None
:
await
self
.
tree
.
sync
()
for
extension
in
self
.
initial_extensions
:
await
self
.
load_extension
(
f
"
extensions.
{
extension
}
"
)
print
(
f
"
➕ Module
{
extension
}
"
)
...
...
This diff is collapsed.
Click to expand it.
modals/text_command_modal.py
0 → 100644
+
52
−
0
View file @
5642f503
import
re
import
traceback
from
typing
import
Optional
import
discord
as
discord
from
discord
import
ui
,
TextStyle
from
discord.utils
import
MISSING
import
models
import
utils
class
InvalidLinkError
(
Exception
):
pass
class
LinkDoesNotExistError
(
Exception
):
pass
class
TextCommandModal
(
ui
.
Modal
,
title
=
'
Neues Text Command hinzufügen
'
):
def
__init__
(
self
,
*
,
text_commands
=
None
,
cmd
:
str
=
""
,
text
:
str
=
""
,
description
:
str
=
""
,
title
:
str
=
MISSING
,
timeout
:
Optional
[
float
]
=
None
,
custom_id
:
str
=
MISSING
)
->
None
:
super
().
__init__
(
title
=
title
,
timeout
=
timeout
,
custom_id
=
custom_id
)
self
.
text_commands
=
text_commands
self
.
cmd
=
cmd
self
.
text
.
default
=
text
self
.
description
.
default
=
description
text
=
ui
.
TextInput
(
label
=
'
Text
'
,
style
=
TextStyle
.
long
)
description
=
ui
.
TextInput
(
label
=
'
Beschreibung
'
,
max_length
=
100
,
placeholder
=
"
Beschreibung des Commands.
"
)
async
def
on_submit
(
self
,
interaction
:
discord
.
Interaction
):
await
interaction
.
response
.
send_message
(
"
Verarbeite Command...
"
,
ephemeral
=
True
)
if
utils
.
is_mod
(
interaction
.
user
,
self
.
text_commands
.
bot
):
if
await
self
.
text_commands
.
add_command
(
self
.
cmd
,
self
.
text
.
value
,
self
.
description
.
value
,
interaction
.
guild_id
):
await
interaction
.
edit_original_response
(
content
=
"
Dein Command wurde erfolgreich hinzugefügt!
"
)
else
:
await
interaction
.
edit_original_response
(
content
=
"
Das Command, dass du hinzufügen möchtest existiert bereits.
"
)
else
:
await
self
.
text_commands
.
suggest_command
(
self
.
cmd
,
self
.
text
.
value
,
self
.
description
.
value
,
interaction
.
guild_id
)
await
interaction
.
edit_original_response
(
content
=
"
Dein Vorschlag wurde den Mods zur Genehmigung vorgelegt.
"
)
async
def
on_error
(
self
,
interaction
:
discord
.
Interaction
,
error
:
Exception
)
->
None
:
if
type
(
error
)
in
[
InvalidLinkError
,
LinkDoesNotExistError
]:
await
interaction
.
response
.
send_message
(
content
=
error
,
ephemeral
=
True
)
else
:
await
interaction
.
response
.
send_message
(
content
=
"
Fehler beim Hinzufügen eines Commands/Texts.
"
,
ephemeral
=
True
)
traceback
.
print_exception
(
type
(
error
),
error
,
error
.
__traceback__
)
This diff is collapsed.
Click to expand it.
models.py
+
1
−
0
View file @
5642f503
...
...
@@ -95,6 +95,7 @@ class PollParticipant(BaseModel):
class
Command
(
BaseModel
):
guild_id
=
IntegerField
()
command
=
CharField
(
unique
=
True
)
description
=
CharField
()
...
...
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