Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F41921553
Notifications.tcl
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
Notifications.tcl
View Options
package
require
json
namespace
eval
notifications
{
proc
init
{}
{
::
broker
::
bind
[
registry
get
broker.queue.notifications
]
::
notifications::on_broker_message
bind
*
*
*
*
::
notifications::channel_notify
}
proc
bind
{
service
project
group
type
callback
}
{
global
notificationsbinds
set
entry
[
list
$service
$project
$group
$type
$callback
]
if
{[
info
exists
notificationsbinds
]}
{
foreach
bind
$notificationsbinds
{
if
{
$bind
==
$entry
}
{
# Bind is already here
return
}
}
}
lappend
notificationsbinds
$entry
}
proc
binds
{}
{
global
notificationsbinds
if
{[
info
exists
notificationsbinds
]}
{
return
$notificationsbinds
}
return
""
}
proc
is_matching_notification_bind
{
bind
notification
}
{
set
bindFields
"service project group type callback"
# We want to ensure the first four bind fields match the values of the notification dictionary
foreach
$bindFields
$bind
{}
set
fields
[
lrange
$bindFields
0
end-1
]
foreach
field
$fields
{
if
{
!
[
string
match
[set
$field
]
[
dict
get
$notification
$field
]]}
{
return
0
}
}
return
1
}
proc
on_broker_message
{
queue
message
}
{
set
notification
[
json
::
json2dict
$message
]
set
message
[
dict
get
$notification
text
]
foreach
field
"service project group rawContent type text link"
{
lappend
params
[
dict
get
$notification
$field
]
}
foreach
bind
[
binds
]
{
if
{[
is_matching_notification_bind
$bind
$notification
]}
{
set
callback
[
lindex
$bind
4
]
$callback
{
*
}
$params
}
}
}
proc
get_notification_channel
{
project
group
}
{
if
{
$project
==
"Wolfplex"
}
{
return
"#wolfplex"
}
if
{
$project
==
"Nasqueron"
}
{
switch
$group
{
tasacora
{
return
"#tasacora"
}
docker
{
return
"#nasqueron-ops"
}
ops
{
return
"#nasqueron-ops"
}
orgz
{
return
"#nasqueron-ops"
}
default
{
putdebug
"Message for unknown group: $project $group"
return
"#nasqueron-logs"
}
}
}
return
""
}
proc
channel_notify
{
service
project
group
rawContent
type
text
link
}
{
set
channel
[
get_notification_channel
$project
$group
]
if
{
$channel
==
""
}
{
return
}
set
message
$text
if
{
$link
!=
""
}
{
append
message
" — $link"
}
if
{
$type
==
"push"
||
$type
==
"ping"
||
$type
==
"repository"
||
$type
==
"create"
}
{
putquick
"PRIVMSG $channel :$message"
}
{
# These probably need some love on the notifications center
putdebug
"Message for $channel: $message"
}
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Aug 8, 02:52 (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3962639
Default Alt Text
Notifications.tcl (2 KB)
Attached To
Mode
rVIPER ViperServ scripts
Attached
Detach File
Event Timeline
Log In to Comment