@@ -1085,29 +1085,34 @@ def load_config(self):
10851085 self ._proxy ["password" ] = parser .get ("proxy" , "password" , fallback = None ) or None
10861086
10871087 if self .plugins :
1088- self .plugins ["enabled" ] = bool (self .plugins .get ("enabled" , True ))
1089- self .plugins ["include" ] = "\n " .join (self .plugins .get ("include" , [])) or None
1090- self .plugins ["exclude" ] = "\n " .join (self .plugins .get ("exclude" , [])) or None
1088+ self .plugins = {
1089+ "enabled" : bool (self .plugins .get ("enabled" , True )),
1090+ "root" : self .plugins .get ("root" , None ),
1091+ "include" : self .plugins .get ("include" , []),
1092+ "exclude" : self .plugins .get ("exclude" , [])
1093+ }
10911094 else :
10921095 try :
10931096 section = parser ["plugins" ]
10941097
10951098 self .plugins = {
10961099 "enabled" : section .getboolean ("enabled" , True ),
1097- "root" : section .get ("root" ),
1098- "include" : section .get ("include" ) or None ,
1099- "exclude" : section .get ("exclude" ) or None
1100+ "root" : section .get ("root" , None ),
1101+ "include" : section .get ("include" , []) ,
1102+ "exclude" : section .get ("exclude" , [])
11001103 }
1101- except KeyError :
1102- self .plugins = {}
11031104
1104- if self .plugins :
1105- for option in ["include" , "exclude" ]:
1106- if self .plugins [option ] is not None :
1107- self .plugins [option ] = [
1108- (i .split ()[0 ], i .split ()[1 :] or None )
1109- for i in self .plugins [option ].strip ().split ("\n " )
1110- ]
1105+ include = self .plugins ["include" ]
1106+ exclude = self .plugins ["exclude" ]
1107+
1108+ if include :
1109+ self .plugins ["include" ] = include .strip ().split ("\n " )
1110+
1111+ if exclude :
1112+ self .plugins ["exclude" ] = exclude .strip ().split ("\n " )
1113+
1114+ except KeyError :
1115+ self .plugins = None
11111116
11121117 def load_session (self ):
11131118 try :
@@ -1142,14 +1147,26 @@ def load_session(self):
11421147 self .peers_by_phone [k ] = peer
11431148
11441149 def load_plugins (self ):
1145- if self .plugins .get ("enabled" , False ):
1146- root = self .plugins ["root" ]
1147- include = self .plugins ["include" ]
1148- exclude = self .plugins ["exclude" ]
1150+ if self .plugins :
1151+ plugins = self .plugins .copy ()
1152+
1153+ for option in ["include" , "exclude" ]:
1154+ if plugins [option ]:
1155+ plugins [option ] = [
1156+ (i .split ()[0 ], i .split ()[1 :] or None )
1157+ for i in self .plugins [option ]
1158+ ]
1159+ else :
1160+ return
1161+
1162+ if plugins .get ("enabled" , False ):
1163+ root = plugins ["root" ]
1164+ include = plugins ["include" ]
1165+ exclude = plugins ["exclude" ]
11491166
11501167 count = 0
11511168
1152- if include is None :
1169+ if not include :
11531170 for path in sorted (Path (root ).rglob ("*.py" )):
11541171 module_path = '.' .join (path .parent .parts + (path .stem ,))
11551172 module = import_module (module_path )
@@ -1206,7 +1223,7 @@ def load_plugins(self):
12061223 log .warning ('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"' .format (
12071224 self .session_name , name , module_path ))
12081225
1209- if exclude is not None :
1226+ if exclude :
12101227 for path , handlers in exclude :
12111228 module_path = root + "." + path
12121229 warn_non_existent_functions = True
0 commit comments