Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
anselm
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
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
vaclab
anselm
Commits
7f80fec1
Commit
7f80fec1
authored
6 years ago
by
wactbprot
Browse files
Options
Downloads
Patches
Plain Diff
anselm can be asked over slack
parent
b9da6dc3
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
anselm.png
+0
-0
0 additions, 0 deletions
anselm.png
anselm.py
+1
-11
1 addition, 11 deletions
anselm.py
bot.py
+86
-36
86 additions, 36 deletions
bot.py
srv.py
+39
-7
39 additions, 7 deletions
srv.py
with
126 additions
and
54 deletions
anselm.png
0 → 100644
+
0
−
0
View file @
7f80fec1
910 KiB
This diff is collapsed.
Click to expand it.
anselm.py
+
1
−
11
View file @
7f80fec1
...
@@ -7,7 +7,7 @@ from anselm.worker import Worker # pylint: disable=E0611
...
@@ -7,7 +7,7 @@ from anselm.worker import Worker # pylint: disable=E0611
from
PyQt5.QtWidgets
import
QWidget
,
QDesktopWidget
,
QApplication
,
QPushButton
from
PyQt5.QtWidgets
import
QWidget
,
QDesktopWidget
,
QApplication
,
QPushButton
from
PyQt5.QtWidgets
import
QComboBox
,
QGridLayout
,
QPlainTextEdit
,
QLabel
,
QLineEdit
from
PyQt5.QtWidgets
import
QComboBox
,
QGridLayout
,
QPlainTextEdit
,
QLabel
,
QLineEdit
from
PyQt5.QtCore
import
QThread
,
pyqtSignal
,
Qt
from
PyQt5.QtCore
import
QThread
,
pyqtSignal
,
Qt
from
slackclient
import
SlackClient
class
Observe
(
QThread
,
System
):
class
Observe
(
QThread
,
System
):
signal
=
pyqtSignal
(
'
PyQt_PyObject
'
)
signal
=
pyqtSignal
(
'
PyQt_PyObject
'
)
...
@@ -25,16 +25,6 @@ class Observe(QThread, System):
...
@@ -25,16 +25,6 @@ class Observe(QThread, System):
class
Anselm
(
System
):
class
Anselm
(
System
):
# instantiate Slack client
slack_client
=
SlackClient
(
os
.
environ
.
get
(
'
SLACK_BOT_TOKEN
'
))
# starterbot's user ID in Slack: value is assigned after the bot starts up
starterbot_id
=
None
# constants
RTM_READ_DELAY
=
1
# 1 second delay between reading from RTM
EXAMPLE_COMMAND
=
"
do
"
MENTION_REGEX
=
"
^<@(|[WU].+?)>(.*)
"
std_select
=
[
"
SE3
"
,
"
CE3
"
,
"
FRS5
"
,
"
DKM_PPC4
"
]
std_select
=
[
"
SE3
"
,
"
CE3
"
,
"
FRS5
"
,
"
DKM_PPC4
"
]
year_select
=
[
"
2019
"
,
"
2018
"
,
"
2017
"
]
year_select
=
[
"
2019
"
,
"
2018
"
,
"
2017
"
]
...
...
This diff is collapsed.
Click to expand it.
bot.py
+
86
−
36
View file @
7f80fec1
...
@@ -2,55 +2,105 @@
...
@@ -2,55 +2,105 @@
import
os
import
os
import
time
import
time
import
re
import
re
from
anselm.system
import
System
from
slackclient
import
SlackClient
from
slackclient
import
SlackClient
# instantiate Slack client
# instantiate Slack client
slack_client
=
SlackClient
(
os
.
environ
.
get
(
'
SLACK_BOT_TOKEN
'
))
from
_thread
import
start_new_thread
starterbot_id
=
None
RTM_READ_DELAY
=
1
class
Bot
(
System
):
EXAMPLE_COMMAND
=
"
do
"
MENTION_REGEX
=
"
^<@(|[WU].+?)>(.*)
"
MENTION_REGEX
=
"
^<@(|[WU].+?)>(.*)
"
RTM_READ_DELAY
=
1
def
parse_bot_commands
(
slack_events
):
def
__init__
(
self
):
super
().
__init__
()
channel_list
=
None
self
.
info_channel_id
=
None
for
event
in
slack_events
:
self
.
p
.
subscribe
(
"
info
"
)
if
event
[
"
type
"
]
==
"
message
"
and
not
"
subtype
"
in
event
:
self
.
log
.
info
(
'
start listening redis
'
)
user_id
,
message
=
parse_direct_mention
(
event
[
"
text
"
])
if
user_id
==
starterbot_id
:
self
.
slack_client
=
SlackClient
(
os
.
environ
.
get
(
'
SLACK_BOT_TOKEN
'
))
return
message
,
event
[
"
channel
"
]
return
None
,
None
if
self
.
slack_client
.
rtm_connect
(
with_team_state
=
False
):
anselm_id
=
self
.
slack_client
.
api_call
(
"
auth.test
"
)[
"
user_id
"
]
self
.
log
.
info
(
'
start listening redis
'
)
channel_list
=
self
.
slack_client
.
api_call
(
"
channels.list
"
)
if
channel_list
and
'
channels
'
in
channel_list
:
for
channel
in
channel_list
.
get
(
'
channels
'
):
if
channel
.
get
(
'
name
'
)
==
'
allgemein
'
:
self
.
log
.
info
(
"
git info channel id
"
)
self
.
info_channel_id
=
channel
.
get
(
'
id
'
)
break
def
parse_bot_commands
(
self
,
slack_events
):
def
parse_direct_mention
(
message_text
):
for
event
in
slack_events
:
if
event
[
"
type
"
]
==
"
message
"
and
not
"
subtype
"
in
event
:
user_id
,
message
=
self
.
parse_direct_mention
(
event
[
"
text
"
])
if
user_id
==
self
.
anselm_id
:
return
message
,
event
[
"
channel
"
]
return
None
,
None
def
parse_direct_mention
(
self
,
message_text
):
matches
=
re
.
search
(
MENTION_REGEX
,
message_text
)
matches
=
re
.
search
(
self
.
MENTION_REGEX
,
message_text
)
return
(
matches
.
group
(
1
),
matches
.
group
(
2
).
strip
())
if
matches
else
(
None
,
None
)
return
(
matches
.
group
(
1
),
matches
.
group
(
2
).
strip
())
if
matches
else
(
None
,
None
)
def
handle_command
(
self
,
command
,
channel
):
def
handle_command
(
command
,
channel
):
default_response
=
"
Not sure what you mean.
\n
Try *gas?* or *calids?*.
"
response
=
None
default_response
=
"
Not sure what you mean. Try *{}*.
"
.
format
(
EXAMPLE_COMMAND
)
if
command
==
'
gas?
'
:
response
=
None
response
=
"
calibration gas is {}
"
.
format
(
self
.
aget
(
'
gas
'
,
0
))
if
command
.
startswith
(
EXAMPLE_COMMAND
):
if
command
==
"
calids?
"
:
response
=
"
Sure...write some more code then I can do that!
"
ids
=
""
lines
=
self
.
get_lines
(
"
cal_id
"
)
for
line
in
lines
:
ids
+=
self
.
aget
(
"
cal_id
"
,
line
)
slack_client
.
api_call
(
response
=
"
documet ids are {}
"
.
format
(
ids
)
"
chat.postMessage
"
,
channel
=
channel
,
self
.
slack_client
.
api_call
(
text
=
response
or
default_response
"
chat.postMessage
"
,
)
channel
=
self
.
info_channel_id
,
text
=
response
or
default_response
)
if
__name__
==
"
__main__
"
:
if
slack_client
.
rtm_connect
(
with_team_state
=
False
):
def
msg_in
(
self
):
print
(
"
Starter Bot connected and running!
"
)
self
.
log
.
debug
(
"
message in
"
)
starterbot_id
=
slack_client
.
api_call
(
"
auth.test
"
)[
"
user_id
"
]
self
.
anselm_id
=
self
.
slack_client
.
api_call
(
"
auth.test
"
)[
"
user_id
"
]
while
True
:
while
True
:
command
,
channel
=
parse_bot_commands
(
slack_client
.
rtm_read
())
command
,
channel
=
self
.
parse_bot_commands
(
self
.
slack_client
.
rtm_read
())
print
(
command
)
print
(
channel
)
if
command
:
if
command
:
handle_command
(
command
,
channel
)
self
.
handle_command
(
command
,
channel
)
time
.
sleep
(
RTM_READ_DELAY
)
time
.
sleep
(
self
.
RTM_READ_DELAY
)
else
:
print
(
"
Connection failed. Exception traceback printed above.
"
)
def
msg_out
(
self
):
if
self
.
info_channel_id
:
for
item
in
self
.
p
.
listen
():
self
.
log
.
debug
(
"
received item: {}
"
.
format
(
item
))
if
item
[
'
type
'
]
==
'
message
'
:
self
.
slack_client
.
api_call
(
"
chat.postMessage
"
,
channel
=
self
.
info_channel_id
,
text
=
item
.
get
(
'
data
'
)
)
else
:
self
.
log
.
error
(
"
got no info channel id
"
)
if
__name__
==
"
__main__
"
:
bot
=
Bot
()
#bot.msg_in()
start_new_thread
(
bot
.
msg_out
,
())
bot
.
msg_in
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
srv.py
+
39
−
7
View file @
7f80fec1
...
@@ -26,6 +26,10 @@ def home():
...
@@ -26,6 +26,10 @@ def home():
@app.route
(
'
/cal_ids
'
,
methods
=
[
'
GET
'
])
@app.route
(
'
/cal_ids
'
,
methods
=
[
'
GET
'
])
def
calids
():
def
calids
():
msg
=
"
http request to endpoint /cal_ids
"
s
.
log
.
info
(
msg
)
s
.
r
.
publish
(
'
info
'
,
msg
)
keys
=
s
.
get_keys
(
'
cal_id
'
)
keys
=
s
.
get_keys
(
'
cal_id
'
)
cal_ids
=
[]
cal_ids
=
[]
for
key
in
keys
:
for
key
in
keys
:
...
@@ -37,6 +41,10 @@ def calids():
...
@@ -37,6 +41,10 @@ def calids():
@app.route
(
'
/target_pressure
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@app.route
(
'
/target_pressure
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
target_pressure
():
def
target_pressure
():
msg
=
"
http request to /target_pressure endpoint
"
s
.
log
.
info
(
msg
)
s
.
r
.
publish
(
'
info
'
,
msg
)
if
request
.
method
==
'
POST
'
:
if
request
.
method
==
'
POST
'
:
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
...
@@ -76,6 +84,10 @@ def target_pressure():
...
@@ -76,6 +84,10 @@ def target_pressure():
@app.route
(
'
/save_dut_branch
'
,
methods
=
[
'
POST
'
])
@app.route
(
'
/save_dut_branch
'
,
methods
=
[
'
POST
'
])
def
save_dut_branch
():
def
save_dut_branch
():
msg
=
"
http request to endpoint /save_dut_branch
"
s
.
log
.
info
(
msg
)
s
.
r
.
publish
(
'
info
'
,
msg
)
if
request
.
method
==
'
POST
'
:
if
request
.
method
==
'
POST
'
:
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
...
@@ -100,10 +112,13 @@ def save_dut_branch():
...
@@ -100,10 +112,13 @@ def save_dut_branch():
@app.route
(
'
/save_maintainer
'
,
methods
=
[
'
POST
'
])
@app.route
(
'
/save_maintainer
'
,
methods
=
[
'
POST
'
])
def
save_maintainer
():
def
save_maintainer
():
msg
=
"
http request to endpoint /save_maintainer
"
s
.
log
.
info
(
msg
)
s
.
r
.
publish
(
'
info
'
,
msg
)
if
request
.
method
==
'
POST
'
:
if
request
.
method
==
'
POST
'
:
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
s
.
log
.
info
(
"
request and save maintainer
"
)
res
=
{
"
ok
"
:
True
}
res
=
{
"
ok
"
:
True
}
req
=
request
.
get_json
()
req
=
request
.
get_json
()
...
@@ -127,10 +142,13 @@ def save_maintainer():
...
@@ -127,10 +142,13 @@ def save_maintainer():
@app.route
(
'
/save_gas
'
,
methods
=
[
'
POST
'
])
@app.route
(
'
/save_gas
'
,
methods
=
[
'
POST
'
])
def
save_gas
():
def
save_gas
():
msg
=
"
request to endpoint /save_gas
"
s
.
log
.
info
(
msg
)
s
.
r
.
publish
(
'
info
'
,
msg
)
if
request
.
method
==
'
POST
'
:
if
request
.
method
==
'
POST
'
:
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
s
.
log
.
info
(
"
request and save gas
"
)
res
=
{
"
ok
"
:
True
}
res
=
{
"
ok
"
:
True
}
req
=
request
.
get_json
()
req
=
request
.
get_json
()
...
@@ -155,7 +173,10 @@ def save_gas():
...
@@ -155,7 +173,10 @@ def save_gas():
@app.route
(
'
/dut_max
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@app.route
(
'
/dut_max
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
dut_max
():
def
dut_max
():
s
.
log
.
info
(
"
request max values for dut branch
"
)
msg
=
"
http request to endpoint /dut_max
"
s
.
log
.
info
(
msg
)
s
.
r
.
publish
(
'
info
'
,
msg
)
if
request
.
method
==
'
POST
'
:
if
request
.
method
==
'
POST
'
:
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
req
=
request
.
get_json
()
req
=
request
.
get_json
()
...
@@ -249,8 +270,10 @@ def dut_max():
...
@@ -249,8 +270,10 @@ def dut_max():
@app.route
(
'
/target_pressures
'
,
methods
=
[
'
GET
'
])
@app.route
(
'
/target_pressures
'
,
methods
=
[
'
GET
'
])
def
target_pressures
():
def
target_pressures
():
s
.
log
.
info
(
"
request to target pressures
"
)
msg
=
"
http request to endpoint /target_pressures
"
s
.
log
.
info
(
msg
)
s
.
r
.
publish
(
'
info
'
,
msg
)
res
=
{
res
=
{
"
Target_pressure
"
:
{
"
Target_pressure
"
:
{
"
Caption
"
:
"
target pressure
"
,
"
Caption
"
:
"
target pressure
"
,
...
@@ -286,6 +309,10 @@ def target_pressures():
...
@@ -286,6 +309,10 @@ def target_pressures():
@app.route
(
'
/offset_sequences
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@app.route
(
'
/offset_sequences
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
offset_sequences
():
def
offset_sequences
():
msg
=
"
request to endpoint /offset_sequences
"
s
.
log
.
info
(
msg
)
s
.
r
.
publish
(
'
info
'
,
msg
)
if
request
.
method
==
'
POST
'
:
if
request
.
method
==
'
POST
'
:
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
...
@@ -307,7 +334,10 @@ def offset_sequences():
...
@@ -307,7 +334,10 @@ def offset_sequences():
@app.route
(
'
/offset
'
,
methods
=
[
'
POST
'
])
@app.route
(
'
/offset
'
,
methods
=
[
'
POST
'
])
def
offset
():
def
offset
():
s
.
log
.
info
(
"
request to endpoint /offset
"
)
msg
=
"
request to endpoint /offset
"
s
.
log
.
info
(
msg
)
s
.
r
.
publish
(
'
info
'
,
msg
)
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
res
=
{
"
ok
"
:
True
}
res
=
{
"
ok
"
:
True
}
req
=
request
.
get_json
()
req
=
request
.
get_json
()
...
@@ -361,7 +391,9 @@ def offset():
...
@@ -361,7 +391,9 @@ def offset():
@app.route
(
'
/ind
'
,
methods
=
[
'
POST
'
])
@app.route
(
'
/ind
'
,
methods
=
[
'
POST
'
])
def
ind
():
def
ind
():
s
.
log
.
info
(
"
request to endpoint /ind
"
)
msg
=
"
request to endpoint /ind
"
s
.
log
.
info
(
msg
)
s
.
r
.
publish
(
'
info
'
,
msg
)
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
s
.
aset
(
'
save
'
,
0
,
"
yes
"
)
res
=
{
"
ok
"
:
True
}
res
=
{
"
ok
"
:
True
}
req
=
request
.
get_json
()
req
=
request
.
get_json
()
...
...
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