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
bc9a8f51
Commit
bc9a8f51
authored
6 years ago
by
wactbprot
Browse files
Options
Downloads
Patches
Plain Diff
cmd struct and output
parent
744a430e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bot.py
+27
-13
27 additions, 13 deletions
bot.py
with
27 additions
and
13 deletions
bot.py
+
27
−
13
View file @
bc9a8f51
...
@@ -51,27 +51,41 @@ class Bot(System):
...
@@ -51,27 +51,41 @@ class Bot(System):
def
handle_command
(
self
,
command
,
channel
):
def
handle_command
(
self
,
command
,
channel
):
default_response
=
"
Not sure what you mean.
\n
Try *gas?* or *calids?*.
"
ok
=
False
response
=
None
if
command
==
'
gas?
'
:
if
command
.
startswith
(
'
ga
'
):
response
=
"
calibration gas is {}
"
.
format
(
self
.
aget
(
'
gas
'
,
0
))
ok
=
True
self
.
post
(
channel
,
"
calibration gas is {}
"
.
format
(
self
.
aget
(
'
gas
'
,
0
)))
if
command
==
"
calids?
"
:
if
command
.
startswith
(
'
id
'
):
ids
=
""
ok
=
True
self
.
post
(
channel
,
"
doc ids are:
"
)
lines
=
self
.
get_lines
(
"
cal_id
"
)
lines
=
self
.
get_lines
(
"
cal_id
"
)
for
line
in
lines
:
for
line
in
lines
:
ids
+=
self
.
aget
(
"
cal_id
"
,
line
)
self
.
post
(
channel
,
self
.
aget
(
"
cal_id
"
,
line
))
if
command
.
startswith
(
'
fu
'
):
ok
=
True
self
.
post
(
channel
,
"
fullscale of the devices are:
"
)
lines
=
self
.
get_lines
(
"
fullscale_value
"
)
for
line
in
lines
:
self
.
post
(
channel
,
"
{} {}
"
.
format
(
self
.
aget
(
"
fullscale_value
"
,
line
),
self
.
aget
(
"
fullscale_unit
"
,
line
)))
if
command
.
startswith
(
'
he
'
):
ok
=
True
self
.
post
(
channel
,
"
Available command are *he[lp]* *ga[s]*, *fu[llscales]* or *id[s]*.
"
)
response
=
"
documet ids are {}
"
.
format
(
ids
)
if
not
ok
:
self
.
post
(
channel
,
"
Not sure what you mean. Try *help* command.
"
)
def
post
(
self
,
channel
,
msg
):
self
.
slack_client
.
api_call
(
self
.
slack_client
.
api_call
(
"
chat.postMessage
"
,
"
chat.postMessage
"
,
channel
=
self
.
info_
channel
_id
,
channel
=
channel
,
text
=
response
or
default_response
text
=
msg
)
)
def
msg_in
(
self
):
def
msg_in
(
self
):
self
.
log
.
debug
(
"
message in
"
)
self
.
log
.
debug
(
"
message in
"
)
...
@@ -93,7 +107,7 @@ class Bot(System):
...
@@ -93,7 +107,7 @@ class Bot(System):
"
chat.postMessage
"
,
"
chat.postMessage
"
,
channel
=
self
.
info_channel_id
,
channel
=
self
.
info_channel_id
,
text
=
item
.
get
(
'
data
'
)
text
=
item
.
get
(
'
data
'
)
)
)
else
:
else
:
self
.
log
.
error
(
"
got no info channel id
"
)
self
.
log
.
error
(
"
got no info channel id
"
)
...
...
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