Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
maubot-rt
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
Container Registry
Model registry
Operate
Environments
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
isgphys
maubot-rt
Commits
f9d75a1d
Commit
f9d75a1d
authored
5 years ago
by
Sven Mäder
Browse files
Options
Downloads
Patches
Plain Diff
Add !rt resolve command
parent
6190f32c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
base-config.yaml
+6
-0
6 additions, 0 deletions
base-config.yaml
maubot.yaml
+1
-1
1 addition, 1 deletion
maubot.yaml
rtlinks.py
+44
-4
44 additions, 4 deletions
rtlinks.py
with
51 additions
and
5 deletions
base-config.yaml
+
6
−
0
View file @
f9d75a1d
# The prefix for all commands
# It has to be prefixed with ! in matrix to be recognised
prefix
:
'
rt'
# RT base URL
url
:
https://example.com/rt
# RT Username
user
:
rtlinks
# RT Password
pass
:
secret
# The list of user IDs who are allowed to modify stuff.
whitelist
:
-
'
@user:example.com'
This diff is collapsed.
Click to expand it.
maubot.yaml
+
1
−
1
View file @
f9d75a1d
...
...
@@ -5,7 +5,7 @@ maubot: 0.1.0
id
:
isg.rda.rtlinks
# A PEP 440 compliant version string.
version
:
0.2.
4
version
:
0.2.
6
# The SPDX license identifier for the plugin. https://spdx.org/licenses/
# Optional, assumes all rights reserved if omitted.
...
...
This diff is collapsed.
Click to expand it.
rtlinks.py
+
44
−
4
View file @
f9d75a1d
import
re
from
typing
import
List
,
Tuple
,
Type
from
typing
import
List
,
Tuple
,
Type
,
Set
from
mautrix.types
import
UserID
from
mautrix.util.config
import
BaseProxyConfig
,
ConfigUpdateHelper
from
maubot
import
Plugin
,
MessageEvent
from
maubot.handlers
import
command
...
...
@@ -7,22 +8,36 @@ from maubot.handlers import command
class
Config
(
BaseProxyConfig
):
def
do_update
(
self
,
helper
:
ConfigUpdateHelper
)
->
None
:
helper
.
copy
(
"
prefix
"
)
helper
.
copy
(
"
url
"
)
helper
.
copy
(
"
user
"
)
helper
.
copy
(
"
pass
"
)
helper
.
copy
(
"
whitelist
"
)
class
RTLinksPlugin
(
Plugin
):
prefix
:
str
whitelist
:
Set
[
UserID
]
regex
=
re
.
compile
(
r
'
([a-zA-z]+): (.+)
'
)
async
def
start
(
self
)
->
None
:
await
super
().
start
()
#await super().start()
self
.
on_external_config_update
()
def
on_external_config_update
(
self
)
->
None
:
self
.
config
.
load_and_update
()
self
.
prefix
=
self
.
config
[
"
prefix
"
]
self
.
whitelist
=
set
(
self
.
config
[
"
whitelist
"
])
@classmethod
def
get_config_class
(
cls
)
->
Type
[
BaseProxyConfig
]:
return
Config
async
def
can_manage
(
self
,
evt
:
MessageEvent
)
->
bool
:
if
evt
.
sender
in
self
.
whitelist
:
return
True
return
False
@command.passive
(
"
((^| )([rR][tT]#?))([0-9]{6})
"
,
multiple
=
True
)
async
def
handler
(
self
,
evt
:
MessageEvent
,
subs
:
List
[
Tuple
[
str
,
str
]])
->
None
:
await
evt
.
mark_read
()
...
...
@@ -38,9 +53,34 @@ class RTLinksPlugin(Plugin):
content
=
await
response
.
text
()
ticket
=
dict
(
self
.
regex
.
findall
(
content
))
link
=
"
{}/Ticket/Display.html?id={}
"
.
format
(
self
.
config
[
'
url
'
],
number
)
markdown
=
"
[rt#{}]({}) {} {} {}
"
.
format
(
number
,
link
,
ticket
[
'
Queue
'
],
ticket
[
'
Creator
'
],
ticket
[
'
Subject
'
])
markdown
=
"
[rt#{}]({}) ({}) is **{}** in **{}** from {}
"
.
format
(
number
,
link
,
ticket
[
'
Subject
'
],
ticket
[
'
Status
'
],
ticket
[
'
Queue
'
],
ticket
[
'
Creator
'
]
)
msg_lines
.
append
(
markdown
)
if
msg_lines
:
await
evt
.
respond
(
"
\n
"
.
join
(
msg_lines
))
@command.new
(
name
=
lambda
self
:
self
.
prefix
,
help
=
"
Manage RT tickets
"
,
require_subcommand
=
True
)
async
def
rt
(
self
)
->
None
:
pass
@rt.subcommand
(
"
resolve
"
,
help
=
"
Mark the ticket as resolved.
"
)
@command.argument
(
"
number
"
,
"
ticket number
"
,
pass_raw
=
True
)
async
def
resolve
(
self
,
evt
:
MessageEvent
,
number
:
str
)
->
None
:
if
not
await
self
.
can_manage
(
evt
):
return
await
evt
.
mark_read
()
headers
=
{
"
User-agent
"
:
"
rtlinksmaubot
"
}
api
=
'
{}/REST/1.0/
'
.
format
(
self
.
config
[
'
url
'
])
api_edit
=
'
{}ticket/{}/edit
'
.
format
(
api
,
number
)
data
=
{
'
user
'
:
self
.
config
[
'
user
'
],
'
pass
'
:
self
.
config
[
'
pass
'
],
'
content
'
:
'
Status: resolved
'
}
await
self
.
http
.
post
(
api_edit
,
data
=
data
,
headers
=
headers
)
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