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
60ff0bf5
Verified
Commit
60ff0bf5
authored
Oct 08, 2021
by
Mroik
Browse files
First working verison
parent
e494707b
Changes
10
Hide whitespace changes
Inline
Side-by-side
.gitignore
0 → 100644
View file @
60ff0bf5
**/__pycache__
__pycache__
mt/__pycache__/__init__.cpython-39.pyc
deleted
100644 → 0
View file @
e494707b
File deleted
mt/__pycache__/bot.cpython-39.pyc
deleted
100644 → 0
View file @
e494707b
File deleted
mt/__pycache__/handlers.cpython-39.pyc
deleted
100644 → 0
View file @
e494707b
File deleted
mt/bot.py
View file @
60ff0bf5
...
...
@@ -9,16 +9,16 @@ class Bot:
self
.
server
=
server
self
.
port
=
port
self
.
updater
=
updater
self
.
mqtt
=
Client
()
def
start
(
self
):
self
.
mqtt
=
Client
(
client_id
=
"Telegram_notifier"
)
self
.
mqtt
.
on_connect
=
on_connect
self
.
mqtt
.
on_message
=
on_message
def
start
(
self
):
self
.
mqtt
.
connect
(
self
.
server
,
self
.
port
)
self
.
updater
.
start_polling
()
print
(
"test"
)
try
:
self
.
mqtt
.
loop_forever
()
except
KeyboardInterrupt
:
pass
self
.
updater
.
stop
()
print
(
"Stopping bot..."
)
self
.
updater
.
stop
()
return
mt/handlers.py
View file @
60ff0bf5
...
...
@@ -3,16 +3,17 @@ from tgbot import updater, where_am_i
def
on_connect
(
client
,
userdata
,
flags
,
rc
):
print
(
"Connected with rc:"
,
rc
)
client
.
subscribe
(
"sede/status"
)
# Maybe should make it into a constant set'd from config file
def
on_message
(
client
,
userdata
,
msg
):
print
(
"Received:"
,
msg
.
topic
,
"
\
n
With:"
,
msg
.
payload
.
decode
(
"utf-8"
))
if
msg
.
topic
is
not
"sede/status"
:
print
(
"Received:"
,
msg
.
topic
,
"
\
t
With:"
,
msg
.
payload
.
decode
(
"utf-8"
))
if
msg
.
topic
!=
"sede/status"
:
return
if
msg
.
payload
.
decode
(
"utf-8"
)
==
0
:
if
msg
.
payload
.
decode
(
"utf-8"
)
==
"1"
:
for
id_
in
where_am_i
:
updater
.
bot
.
send_message
(
id_
,
"Il POuL è aperto!"
)
elif
msg
.
payload
.
decode
(
"utf-8"
)
==
1
:
elif
msg
.
payload
.
decode
(
"utf-8"
)
==
"0"
:
for
id_
in
where_am_i
:
updater
.
bot
.
send_message
(
id_
,
"Il POuL è chiuso!"
)
...
...
tgbot/__pycache__/__init__.cpython-39.pyc
deleted
100644 → 0
View file @
e494707b
File deleted
tgbot/__pycache__/dispatcher.cpython-39.pyc
deleted
100644 → 0
View file @
e494707b
File deleted
tgbot/__pycache__/handlers.cpython-39.pyc
deleted
100644 → 0
View file @
e494707b
File deleted
tgbot/handlers.py
View file @
60ff0bf5
...
...
@@ -4,6 +4,7 @@ from telegram import Update
def
on_message
(
update
:
Update
,
context
:
CallbackContext
):
from
.
import
where_am_i
# Because circular imports
print
(
"Message received"
)
if
update
.
message
.
chat
.
id
not
in
where_am_i
:
where_am_i
.
append
(
update
.
message
.
chat
.
id
)
...
...
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