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
Projects
B.I.T.S. 4.0
bits-companion
Commits
9da690a9
Verified
Commit
9da690a9
authored
Oct 19, 2021
by
Mroik
Browse files
More logging
parent
e6cb633a
Changes
3
Hide whitespace changes
Inline
Side-by-side
main.py
View file @
9da690a9
import
logging
from
mt.bot
import
Bot
import
mt
from
config
import
(
...
...
@@ -7,8 +9,11 @@ from config import (
PASSWORD
,
)
LOGGER
=
logging
.
getLogger
(
__name__
)
def
main
():
# logging.basicConfig(level=logging.INFO) # Uncomment for DUBUG
mt
.
bot
=
Bot
(
SERVER
,
PORT
)
mt
.
bot
.
start
(
USERNAME
,
PASSWORD
)
...
...
mt/handlers.py
View file @
9da690a9
...
...
@@ -12,7 +12,7 @@ def on_connect(client, userdata, flags, rc):
LOGGER
.
error
(
RETURN_CODE
[
rc
])
return
res
,
mid
=
client
.
subscribe
(
"sede/status"
)
# Maybe should make it into a constant set'd from config file
LOGGER
.
info
(
res
,
mid
)
LOGGER
.
info
(
f
"
{
res
}
{
mid
}
"
)
def
on_message
(
client
,
userdata
,
msg
):
...
...
tgbot/handlers.py
View file @
9da690a9
import
logging
from
datetime
import
datetime
from
telegram.ext
import
CallbackContext
,
DispatcherHandlerStop
from
telegram
import
Update
,
Message
...
...
@@ -8,6 +9,7 @@ from config import ADMIN_CHANNELS
LOGGER
=
logging
.
getLogger
(
__name__
)
last_change
=
None
def
on_message
(
update
:
Update
,
context
:
CallbackContext
):
...
...
@@ -38,6 +40,15 @@ def set_open(update: Update, context: CallbackContext):
def
set_closed
(
update
:
Update
,
context
:
CallbackContext
):
global
last_change
if
last_change
is
None
:
last_change
=
datetime
.
now
()
else
:
if
datetime
.
now
()
-
10000
<
last_change
:
print
(
datetime
.
now
())
return
if
not
check_admin
(
update
,
context
):
raise
DispatcherHandlerStop
resp
=
mt
.
bot
.
mqtt
.
publish
(
"sede/status"
,
0
)
...
...
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