7
7
from aprs_backend .version import __version__ as ERR_APRS_VERSION
8
8
from errbot .backends .base import Message
9
9
from errbot .backends .base import ONLINE
10
+ from errbot .plugin_manager import BotPluginManager
10
11
from errbot .core import ErrBot
11
12
from aprs_backend .exceptions import ProcessorError , PacketParseError , APRSISConnnectError
12
13
from aprs_backend .packets .parser import parse , hash_packet
16
17
from aprs_backend .utils .counter import MessageCounter
17
18
from random import randint
18
19
from datetime import datetime
20
+
19
21
from better_profanity import profanity
20
22
from aprs_backend .clients .aprs_registry import APRSRegistryClient , RegistryAppConfig
21
23
import logging
22
24
import asyncio
23
25
from errbot .version import VERSION as ERR_VERSION
24
26
from aprs_backend .clients .beacon import BeaconConfig , BeaconClient
27
+ from aprs_backend .utils .plugins import _load_plugins_generic , activate_non_started_plugins
28
+ from types import MethodType
29
+
25
30
26
31
log = logging .getLogger (__name__ )
27
32
33
38
34
39
class APRSBackend (ErrBot ):
35
40
def __init__ (self , config ):
36
- log .debug ("Initied" )
41
+ super ().__init__ (config )
42
+ log .debug ("Init called" )
37
43
38
- self ._errbot_config = config
39
44
self ._multiline = False
40
45
41
46
aprs_config = {"host" : "rotate.aprs.net" , "port" : 14580 }
@@ -64,9 +69,6 @@ def __init__(self, config):
64
69
self ._send_queue : asyncio .Queue [MessagePacket ] = asyncio .Queue (
65
70
maxsize = int (self ._get_from_config ("APRS_SEND_MAX_QUEUE" , "2048" ))
66
71
)
67
- self .help_text = self ._get_from_config (
68
- "APRS_HELP_TEXT" , f"Errbot { ERR_VERSION } & err-aprs-backend { ERR_APRS_VERSION } by { aprs_config ['callsign' ]} "
69
- )
70
72
71
73
self ._message_counter = MessageCounter (initial_value = randint (1 , 20 )) # nosec not used cryptographically
72
74
self ._max_dropped_packets = int (self ._get_from_config ("APRS_MAX_DROPPED_PACKETS" , "25" ))
@@ -125,10 +127,23 @@ def __init__(self, config):
125
127
)
126
128
else :
127
129
self .beacon_client = None
128
- super ().__init__ (config )
130
+
131
+ def attach_plugin_manager (self , plugin_manager : BotPluginManager | None ) -> None :
132
+ """Modified attach_plugin_manager that patches the plugin manager
133
+
134
+ _log_plugins_generic is modified to remove a check on multiple plugin classes in
135
+ a single module
136
+ """
137
+ log .debug ("In aprs-backend attach_plugin_manager" )
138
+ if plugin_manager is not None :
139
+ log .debug ("Patching plugin manager with custom _load_plugins_generic" )
140
+ funcType = MethodType
141
+ plugin_manager ._load_plugins_generic = funcType (_load_plugins_generic , plugin_manager )
142
+ plugin_manager .activate_non_started_plugins = funcType (activate_non_started_plugins , plugin_manager )
143
+ self .plugin_manager = plugin_manager
129
144
130
145
def _get_from_config (self , key : str , default : any = None ) -> any :
131
- return getattr (self ._errbot_config , key , default )
146
+ return getattr (self .bot_config , key , default )
132
147
133
148
def _get_beacon_config (self ) -> BeaconConfig | None :
134
149
if self ._get_from_config ("APRS_BEACON_ENABLE" , "false" ) == "true" :
@@ -317,6 +332,13 @@ async def receive_worker(self) -> bool:
317
332
return False
318
333
319
334
async def async_serve_once (self ) -> bool :
335
+ """The async portion of serve once
336
+
337
+ Starts the bot tasks for receiving aprs messages, sending messages, and retrying
338
+ """
339
+ log .debug (
340
+ "Bot plugins: %s" , [plugin .__class__ .__name__ for plugin in self .plugin_manager .get_all_active_plugins ()]
341
+ )
320
342
receive_task = asyncio .create_task (self .receive_worker ())
321
343
322
344
worker_tasks = [asyncio .create_task (self .send_worker ()), asyncio .create_task (self .retry_worker ())]
@@ -426,13 +448,6 @@ async def __drop_message_from_waiting(self, message_hash: str) -> None:
426
448
else :
427
449
log .debug ("Dropped Packet from waiting_ack: %s" , packet )
428
450
429
- def handle_help (self , msg : APRSMessage ) -> None :
430
- """Returns simplified help text for the APRS backend"""
431
- help_msg = APRSMessage (body = self .help_text , extras = msg .extras )
432
- help_msg .to = msg .frm
433
- help_msg .frm = self .bot_identifier
434
- self .send_message (help_msg )
435
-
436
451
async def _process_message (self , packet : MessagePacket ) -> None :
437
452
"""
438
453
Check if this message is a dupe of one the bot is already processing
@@ -449,8 +464,6 @@ async def _process_message(self, packet: MessagePacket) -> None:
449
464
self ._packet_cache [this_packet_hash ] = packet
450
465
msg = APRSMessage .from_message_packet (packet )
451
466
msg .body = msg .body .strip ("\n " ).strip ("\r " )
452
- if msg .body .lower ().strip (" " ) == "help" :
453
- return self .handle_help (msg )
454
467
return self .callback_message (msg )
455
468
456
469
async def _ack_message (self , packet : MessagePacket ) -> None :
0 commit comments