Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pitte
bits-companion
Commits
f889c5fc
Verified
Commit
f889c5fc
authored
Oct 25, 2021
by
Mroik
Browse files
Temporary changes
parent
0bfe9f0f
Changes
3
Hide whitespace changes
Inline
Side-by-side
main.py
View file @
f889c5fc
...
...
@@ -13,7 +13,7 @@ LOGGER = logging.getLogger(__name__)
def
main
():
#
logging.basicConfig(level=logging.DEBUG) # Uncomment for DUBUG
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
# Uncomment for DUBUG
mt
.
bot
=
Bot
(
SERVER
,
PORT
)
mt
.
bot
.
start
(
USERNAME
,
PASSWORD
)
...
...
mt/handlers.py
View file @
f889c5fc
...
...
@@ -25,6 +25,7 @@ def on_message(client, userdata, msg):
payload
=
json
.
loads
(
msg
.
payload
.
decode
(
"utf-8"
))
if
msg
.
topic
!=
"sede/status"
:
return
return
if
payload
[
"status"
]
==
OPEN
:
for
id_
in
where_am_i
:
updater
.
bot
.
send_message
(
id_
,
"🟢🟢 Il POuL è aperto! 🟢🟢"
)
...
...
tgbot/handlers.py
View file @
f889c5fc
...
...
@@ -42,28 +42,26 @@ def check_debounce():
last_change
=
datetime
.
now
()
return
True
else
:
if
datetime
.
now
()
-
timedelta
(
seconds
=
2
0
)
<
last_change
:
if
datetime
.
now
()
-
timedelta
(
seconds
=
2
)
<
last_change
:
return
True
return
False
def
set_open
(
update
:
Update
,
context
:
CallbackContext
):
LOGGER
.
debug
(
"Trying to open"
)
if
check_debounce
():
return
if
not
check_admin
(
update
,
context
):
raise
DispatcherHandlerStop
resp
=
mt
.
bot
.
mqtt
.
publish
(
"sede/status"
,
payload
=
json
.
dumps
({
"id"
:
"Set from telegram"
,
"status"
:
OPEN
}))
LOGGER
.
info
(
resp
.
mid
)
set_status
(
True
,
update
,
context
)
def
set_closed
(
update
:
Update
,
context
:
CallbackContext
):
LOGGER
.
debug
(
"Trying to close"
)
set_status
(
False
,
update
,
context
)
def
set_status
(
status
:
bool
,
update
:
Update
,
context
:
CallbackContext
):
LOGGER
.
debug
(
f
"Trying to set status to
{
status
}
"
)
if
check_debounce
():
LOGGER
.
debug
(
"Debounce triggered"
)
return
if
not
check_admin
(
update
,
context
):
LOGGER
.
debug
(
"Not an admin"
)
raise
DispatcherHandlerStop
resp
=
mt
.
bot
.
mqtt
.
publish
(
"sede/status"
,
payload
=
json
.
dumps
({
"id"
:
"Set from telegram"
,
"status"
:
CLOSED
}))
resp
=
mt
.
bot
.
mqtt
.
publish
(
"sede/status"
,
payload
=
json
.
dumps
({
"id"
:
"Set from telegram"
,
"status"
:
OPEN
if
status
else
CLOSED
}))
LOGGER
.
info
(
resp
.
mid
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment