mirror of
https://github.com/hemna/aprsd-telegram-plugin.git
synced 2024-11-25 09:28:40 -05:00
Compare commits
2 Commits
fa8ae88c35
...
108ea07f60
Author | SHA1 | Date | |
---|---|---|---|
108ea07f60 | |||
547c326a09 |
@ -1,6 +1,13 @@
|
|||||||
CHANGES
|
CHANGES
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
v0.1.2
|
||||||
|
------
|
||||||
|
|
||||||
|
* for v0.1.2
|
||||||
|
* for v0.1.1
|
||||||
|
* Use the pbr version of the package as plugin version
|
||||||
|
|
||||||
v0.1.1
|
v0.1.1
|
||||||
------
|
------
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import logging
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from aprsd import messaging, objectstore, plugin, threads, trace
|
from aprsd import messaging, objectstore, plugin, threads
|
||||||
from telegram.ext import Filters, MessageHandler, Updater
|
from telegram.ext import Filters, MessageHandler, Updater
|
||||||
|
|
||||||
import aprsd_telegram_plugin
|
import aprsd_telegram_plugin
|
||||||
@ -101,11 +101,19 @@ class TelegramChatPlugin(plugin.APRSDRegexCommandPluginBase):
|
|||||||
|
|
||||||
# self.bot = telegram.Bot(token=token)
|
# self.bot = telegram.Bot(token=token)
|
||||||
# LOG.info(self.bot.get_me())
|
# LOG.info(self.bot.get_me())
|
||||||
|
LOG.info("Starting up Updater")
|
||||||
|
try:
|
||||||
self.updater = Updater(
|
self.updater = Updater(
|
||||||
token=token,
|
token=token,
|
||||||
use_context=True,
|
use_context=True,
|
||||||
persistence=False,
|
persistence=False,
|
||||||
)
|
)
|
||||||
|
except Exception as ex:
|
||||||
|
self.enabled = False
|
||||||
|
LOG.exception(ex)
|
||||||
|
LOG.info("Starting up Dispatcher")
|
||||||
|
|
||||||
|
try:
|
||||||
self.dispatcher = self.updater.dispatcher
|
self.dispatcher = self.updater.dispatcher
|
||||||
self.dispatcher.add_handler(
|
self.dispatcher.add_handler(
|
||||||
MessageHandler(
|
MessageHandler(
|
||||||
@ -113,6 +121,9 @@ class TelegramChatPlugin(plugin.APRSDRegexCommandPluginBase):
|
|||||||
self.message_handler,
|
self.message_handler,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
except Exception as ex:
|
||||||
|
self.enabled = False
|
||||||
|
LOG.exception(ex)
|
||||||
|
|
||||||
def message_handler(self, update, context):
|
def message_handler(self, update, context):
|
||||||
"""This is called when a telegram users texts the bot."""
|
"""This is called when a telegram users texts the bot."""
|
||||||
@ -145,9 +156,9 @@ class TelegramChatPlugin(plugin.APRSDRegexCommandPluginBase):
|
|||||||
|
|
||||||
def create_threads(self):
|
def create_threads(self):
|
||||||
if self.enabled:
|
if self.enabled:
|
||||||
|
LOG.info("Starting TelegramThread")
|
||||||
return TelegramThread(self.config, self.updater)
|
return TelegramThread(self.config, self.updater)
|
||||||
|
|
||||||
@trace.trace
|
|
||||||
def process(self, packet):
|
def process(self, packet):
|
||||||
"""This is called when a received packet matches self.command_regex."""
|
"""This is called when a received packet matches self.command_regex."""
|
||||||
LOG.info("TelegramChatPlugin Plugin")
|
LOG.info("TelegramChatPlugin Plugin")
|
||||||
@ -205,10 +216,14 @@ class TelegramThread(threads.APRSDThread):
|
|||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
"""We have to loop, so we can stop the thread upon CTRL-C"""
|
"""We have to loop, so we can stop the thread upon CTRL-C"""
|
||||||
|
try:
|
||||||
self.updater.start_polling(
|
self.updater.start_polling(
|
||||||
timeout=2,
|
timeout=2,
|
||||||
drop_pending_updates=True,
|
drop_pending_updates=True,
|
||||||
)
|
)
|
||||||
|
except Exception as ex:
|
||||||
|
LOG.exception(ex)
|
||||||
|
return False
|
||||||
# So we don't eat 100% CPU
|
# So we don't eat 100% CPU
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
# so we can continue looping
|
# so we can continue looping
|
||||||
|
Loading…
Reference in New Issue
Block a user