Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stateless-matrix-bot-framework
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
Service Desk
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
Janne Mareike Koschinski
stateless-matrix-bot-framework
Commits
21ceb91d
Verified
Commit
21ceb91d
authored
1 month ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
feat: improve customizability
parent
1553ab52
Branches
main
Tags
v0.1.4
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api_setpusher.go
+2
-14
2 additions, 14 deletions
api_setpusher.go
matrixbot.go
+29
-14
29 additions, 14 deletions
matrixbot.go
with
31 additions
and
28 deletions
api_setpusher.go
+
2
−
14
View file @
21ceb91d
...
...
@@ -26,20 +26,8 @@ type PusherData struct {
Url
string
`json:"url"`
}
func
SetPusher
(
token
MatrixToken
,
url
string
)
error
{
body
,
err
:=
json
.
Marshal
(
PusherRequest
{
AppDisplayName
:
"webhook"
,
AppId
:
"de.justjanne.webhook"
,
Append
:
false
,
Data
:
PusherData
{
Url
:
url
,
},
DeviceDisplayName
:
"webhook"
,
Kind
:
"http"
,
Lang
:
"en"
,
ProfileTag
:
"abcdef"
,
PushKey
:
"webhook"
,
})
func
SetPusher
(
token
MatrixToken
,
pusher
PusherRequest
)
error
{
body
,
err
:=
json
.
Marshal
(
pusher
)
if
err
!=
nil
{
return
err
}
...
...
This diff is collapsed.
Click to expand it.
matrixbot.go
+
29
−
14
View file @
21ceb91d
...
...
@@ -11,17 +11,13 @@ import (
)
type
MatrixBot
struct
{
Token
*
MatrixToken
PushUrl
*
url
.
URL
handlers
map
[
string
]
func
(
bot
*
MatrixBot
,
notification
Notification
)
error
}
func
NewMatrixBot
(
pushUrl
*
url
.
URL
)
*
MatrixBot
{
return
&
MatrixBot
{
Token
:
nil
,
PushUrl
:
pushUrl
,
handlers
:
make
(
map
[
string
]
func
(
bot
*
MatrixBot
,
notification
Notification
)
error
),
}
AppName
string
AppId
string
ProfileTag
string
PushKey
string
PushUrl
*
url
.
URL
Token
*
MatrixToken
handlers
map
[
string
]
func
(
bot
*
MatrixBot
,
notification
Notification
)
error
}
func
(
bot
*
MatrixBot
)
RefreshToken
()
error
{
...
...
@@ -65,11 +61,30 @@ func (bot *MatrixBot) RefreshTask() {
}
func
(
bot
*
MatrixBot
)
RegisterPusher
()
error
{
return
SetPusher
(
*
bot
.
Token
,
bot
.
PushUrl
.
String
())
return
SetPusher
(
*
bot
.
Token
,
PusherRequest
{
AppDisplayName
:
bot
.
AppName
,
AppId
:
bot
.
AppId
,
Append
:
false
,
Data
:
PusherData
{
Url
:
bot
.
PushUrl
.
String
(),
},
DeviceDisplayName
:
bot
.
AppName
,
Kind
:
"http"
,
Lang
:
"en"
,
ProfileTag
:
bot
.
ProfileTag
,
PushKey
:
bot
.
AppId
,
})
}
func
(
bot
*
MatrixBot
)
ensureHandlers
()
map
[
string
]
func
(
bot
*
MatrixBot
,
notification
Notification
)
error
{
if
bot
.
handlers
==
nil
{
bot
.
handlers
=
make
(
map
[
string
]
func
(
bot
*
MatrixBot
,
notification
Notification
)
error
)
}
return
bot
.
handlers
}
func
(
bot
*
MatrixBot
)
HandleFunc
(
command
string
,
handler
func
(
bot
*
MatrixBot
,
notification
Notification
)
error
)
{
bot
.
h
andlers
[
command
]
=
handler
bot
.
ensureH
andlers
()
[
command
]
=
handler
}
func
(
bot
*
MatrixBot
)
Serve
(
endpoint
string
)
{
...
...
@@ -93,7 +108,7 @@ func (bot *MatrixBot) Serve(endpoint string) {
return
}
command
:=
strings
.
SplitN
(
notification
.
Content
.
Body
,
" "
,
2
)[
0
]
handler
,
ok
:=
bot
.
h
andlers
[
command
]
handler
,
ok
:=
bot
.
ensureH
andlers
()
[
command
]
if
!
ok
{
log
.
Printf
(
"could not find handler for '%s'
\n
"
,
command
)
return
...
...
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