mirror of
https://github.com/markqvist/LXMF-Tools.git
synced 2024-10-01 03:15:38 -04:00
Message fields improved
This commit is contained in:
parent
2ce31fcee2
commit
16887b5dd1
@ -838,9 +838,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
title = message.title.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "lxmf_to_matrix_deny_title")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "lxmf_to_matrix_deny_title")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -848,9 +847,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
content = message.content.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "lxmf_to_matrix_deny_content")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "lxmf_to_matrix_deny_content")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -858,9 +856,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
if message.fields:
|
||||
denys = config_get(CONFIG, "message", "lxmf_to_matrix_deny_fields")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "lxmf_to_matrix_deny_fields")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -881,9 +878,9 @@ def lxmf_message_received_callback(message):
|
||||
source_name = ""
|
||||
|
||||
if message.fields:
|
||||
if "src" in message.fields:
|
||||
source_address = RNS.hexrep(message.fields["src"]["h"], False)
|
||||
source_name = message.fields["src"]["n"]
|
||||
if 0xAF in message.fields:
|
||||
source_address = RNS.hexrep(message.fields[0xAF]["h"], False)
|
||||
source_name = message.fields[0xAF]["n"]
|
||||
|
||||
routing_destination = ROUTING_TABLE[destination_address][0]
|
||||
routing_table = ROUTING_TABLE[destination_address][1]
|
||||
@ -903,16 +900,16 @@ def lxmf_message_received_callback(message):
|
||||
|
||||
content = content_prefix + content + content_suffix
|
||||
|
||||
if message.fields and "hash" in message.fields:
|
||||
hash = message.fields["hash"]
|
||||
if message.fields and 0xA7 in message.fields:
|
||||
hash = message.fields[0xA7]
|
||||
else:
|
||||
hash = message.hash
|
||||
|
||||
if message.fields and "edit" in message.fields and "hash" in message.fields and message.fields["hash"] in DATA:
|
||||
content = {"msgtype": "m.text", "body": "", "m.new_content": {"body": content, "msgtype": "m.text"}, "m.relates_to": {"event_id": DATA[message.fields["hash"]][0], "rel_type": "m.replace"}}
|
||||
elif message.fields and "delete" in message.fields and "hash" in message.fields and message.fields["hash"] in DATA:
|
||||
content = {"msgtype": "m.text", "body": "", "m.new_content": {"body": config_get(CONFIG, "message", "lxmf_to_matrix_deleted", "-"), "msgtype": "m.text"}, "m.relates_to": {"event_id": DATA[message.fields["hash"]][0], "rel_type": "m.replace"}}
|
||||
elif message.fields and "answer" in message.fields and message.fields["answer"] in DATA:
|
||||
if message.fields and 0xA5 in message.fields and 0xA7 in message.fields and message.fields[0xA7] in DATA:
|
||||
content = {"msgtype": "m.text", "body": "", "m.new_content": {"body": content, "msgtype": "m.text"}, "m.relates_to": {"event_id": DATA[message.fields[0xA7]][0], "rel_type": "m.replace"}}
|
||||
elif message.fields and 0xA4 in message.fields and 0xA7 in message.fields and message.fields[0xA7] in DATA:
|
||||
content = {"msgtype": "m.text", "body": "", "m.new_content": {"body": config_get(CONFIG, "message", "lxmf_to_matrix_deleted", "-"), "msgtype": "m.text"}, "m.relates_to": {"event_id": DATA[message.fields[0xA7]][0], "rel_type": "m.replace"}}
|
||||
elif message.fields and 0xA0 in message.fields and message.fields[0xA0] in DATA:
|
||||
content = {"msgtype": "m.text", "body": content, "m.relates_to": {"m.in_reply_to": {"event_id": DATA[message.fields["answer"]][0]}}}
|
||||
else:
|
||||
content = {"msgtype": "m.text", "body": content}
|
||||
@ -920,8 +917,8 @@ def lxmf_message_received_callback(message):
|
||||
MATRIX_CONNECTION.send(routing_destination, content, hash)
|
||||
|
||||
# TODO
|
||||
#if message.fields and "attachment" in message.fields:
|
||||
# for attachment in message.fields["attachment"]:
|
||||
#if message.fields and 0xA1 in message.fields:
|
||||
# for attachment in message.fields[0xA1]:
|
||||
# MATRIX_CONNECTION.send_file(routing_destination, attachment["name"], attachment["size"], attachment["data"])
|
||||
else:
|
||||
log("LXMF - Source " + RNS.prettyhexrep(message.source_hash) + " not allowed", LOG_DEBUG)
|
||||
@ -959,16 +956,16 @@ def matrix_message_received_callback(room: MatrixRoom, event: RoomMessage):
|
||||
content = content_dict["m.new_content"]["body"]
|
||||
event_id = content_dict["m.relates_to"]["event_id"]
|
||||
if event_id in DATA:
|
||||
fields["hash"] = DATA[event_id][0]
|
||||
fields[0xA7] = DATA[event_id][0]
|
||||
if DATA[event_id][1]:
|
||||
fields["answer"] = DATA[event_id][1]
|
||||
fields["edit"] = time.time()
|
||||
fields[0xA0] = DATA[event_id][1]
|
||||
fields[0xA5] = time.time()
|
||||
elif "m.relates_to" in content_dict and "m.in_reply_to" in content_dict["m.relates_to"]:
|
||||
content = content_dict["formatted_body"]
|
||||
content = re.sub(r'<mx-reply>.*<\/mx-reply>', '', content)
|
||||
event_id = content_dict["m.relates_to"]["m.in_reply_to"]["event_id"]
|
||||
if event_id in DATA:
|
||||
fields["answer"] = DATA[event_id][0]
|
||||
fields[0xA0] = DATA[event_id][0]
|
||||
else:
|
||||
content = event.body
|
||||
except:
|
||||
@ -1004,15 +1001,15 @@ def matrix_message_received_callback(room: MatrixRoom, event: RoomMessage):
|
||||
|
||||
content = content_prefix + content + content_suffix
|
||||
|
||||
fields["src"] = {}
|
||||
fields["src"]["h"] = b''
|
||||
fields["src"]["n"] = replace(config_get(CONFIG, "message", "matrix_to_lxmf"), source_address=event.sender, source_name=user_name, destination_address=room.room_id, destination_name=room.display_name, routing_table=routing_table)
|
||||
fields[0xAF] = {}
|
||||
fields[0xAF]["h"] = b''
|
||||
fields[0xAF]["n"] = replace(config_get(CONFIG, "message", "matrix_to_lxmf"), source_address=event.sender, source_name=user_name, destination_address=room.room_id, destination_name=room.display_name, routing_table=routing_table)
|
||||
|
||||
result = LXMF_CONNECTION.send(routing_destination, content, "", fields=fields)
|
||||
|
||||
if result:
|
||||
if "answer" in fields:
|
||||
answer = fields["answer"]
|
||||
if 0xA0 in fields:
|
||||
answer = fields[0xA0]
|
||||
else:
|
||||
answer = None
|
||||
DATA[result] = [event.event_id, answer]
|
||||
@ -1071,6 +1068,23 @@ def config_get(config, section, key, default="", lng_key=""):
|
||||
return default
|
||||
|
||||
|
||||
def config_getarray(config, section, key, default=[], lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
value = ""
|
||||
if config.has_option(section, key+lng_key):
|
||||
value = config[section][key+lng_key]
|
||||
elif config.has_option(section, key):
|
||||
value = config[section][key]
|
||||
if value != "":
|
||||
values_return = []
|
||||
values = value.split(",")
|
||||
for value in values:
|
||||
values_return.append(val_to_val(value.strip()))
|
||||
return values_return
|
||||
return default
|
||||
|
||||
|
||||
def config_getint(config, section, key, default=0, lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
@ -1309,8 +1323,13 @@ def val_to_val(val):
|
||||
return True
|
||||
elif val.lower() == "false":
|
||||
return False
|
||||
else:
|
||||
return val
|
||||
elif val.startswith("0x") or val.startswith("0X"):
|
||||
try:
|
||||
val_int = int(val, 16)
|
||||
return val_int
|
||||
except:
|
||||
pass
|
||||
return val
|
||||
|
||||
|
||||
##############################################################################################################
|
||||
|
@ -681,9 +681,8 @@ def lxmf_message_received_callback(message):
|
||||
if CONFIG.has_option("allowed", "any") or CONFIG.has_option("allowed", "all") or CONFIG.has_option("allowed", "anybody") or CONFIG.has_option("allowed", RNS.hexrep(message.source_hash, False)) or CONFIG.has_option("allowed", RNS.prettyhexrep(message.source_hash)):
|
||||
|
||||
title = message.title.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "lxmf_to_mqtt_deny_title")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "lxmf_to_mqtt_deny_title")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -691,9 +690,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
content = message.content.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "lxmf_to_mqtt_deny_content")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "lxmf_to_mqtt_deny_content")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -701,9 +699,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
if message.fields:
|
||||
denys = config_get(CONFIG, "message", "lxmf_to_mqtt_deny_fields")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "lxmf_to_mqtt_deny_fields")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -927,6 +924,23 @@ def config_get(config, section, key, default="", lng_key=""):
|
||||
return default
|
||||
|
||||
|
||||
def config_getarray(config, section, key, default=[], lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
value = ""
|
||||
if config.has_option(section, key+lng_key):
|
||||
value = config[section][key+lng_key]
|
||||
elif config.has_option(section, key):
|
||||
value = config[section][key]
|
||||
if value != "":
|
||||
values_return = []
|
||||
values = value.split(",")
|
||||
for value in values:
|
||||
values_return.append(val_to_val(value.strip()))
|
||||
return values_return
|
||||
return default
|
||||
|
||||
|
||||
def config_getint(config, section, key, default=0, lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
@ -1104,8 +1118,13 @@ def val_to_val(val):
|
||||
return True
|
||||
elif val.lower() == "false":
|
||||
return False
|
||||
else:
|
||||
return val
|
||||
elif val.startswith("0x") or val.startswith("0X"):
|
||||
try:
|
||||
val_int = int(val, 16)
|
||||
return val_int
|
||||
except:
|
||||
pass
|
||||
return val
|
||||
|
||||
|
||||
##############################################################################################################
|
||||
|
@ -653,9 +653,8 @@ def lxmf_message_received_callback(message):
|
||||
if CONFIG.has_option("allowed", "any") or CONFIG.has_option("allowed", "all") or CONFIG.has_option("allowed", "anybody") or CONFIG.has_option("allowed", RNS.hexrep(message.source_hash, False)) or CONFIG.has_option("allowed", RNS.prettyhexrep(message.source_hash)):
|
||||
|
||||
title = message.title.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "deny_title")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_title")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -663,9 +662,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
content = message.content.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "deny_content")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_content")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -673,9 +671,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
if message.fields:
|
||||
denys = config_get(CONFIG, "message", "deny_fields")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_fields")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -751,6 +748,23 @@ def config_get(config, section, key, default="", lng_key=""):
|
||||
return default
|
||||
|
||||
|
||||
def config_getarray(config, section, key, default=[], lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
value = ""
|
||||
if config.has_option(section, key+lng_key):
|
||||
value = config[section][key+lng_key]
|
||||
elif config.has_option(section, key):
|
||||
value = config[section][key]
|
||||
if value != "":
|
||||
values_return = []
|
||||
values = value.split(",")
|
||||
for value in values:
|
||||
values_return.append(val_to_val(value.strip()))
|
||||
return values_return
|
||||
return default
|
||||
|
||||
|
||||
def config_getint(config, section, key, default=0, lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
@ -930,8 +944,13 @@ def val_to_val(val):
|
||||
return True
|
||||
elif val.lower() == "false":
|
||||
return False
|
||||
else:
|
||||
return val
|
||||
elif val.startswith("0x") or val.startswith("0X"):
|
||||
try:
|
||||
val_int = int(val, 16)
|
||||
return val_int
|
||||
except:
|
||||
pass
|
||||
return val
|
||||
|
||||
|
||||
##############################################################################################################
|
||||
|
@ -651,9 +651,8 @@ def lxmf_message_received_callback(message):
|
||||
if CONFIG.has_option("allowed", "any") or CONFIG.has_option("allowed", "all") or CONFIG.has_option("allowed", "anybody") or CONFIG.has_option("allowed", RNS.hexrep(message.source_hash, False)) or CONFIG.has_option("allowed", RNS.prettyhexrep(message.source_hash)):
|
||||
|
||||
title = message.title.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "deny_title")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_title")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -661,9 +660,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
content = message.content.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "deny_content")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_content")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -671,9 +669,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
if message.fields:
|
||||
denys = config_get(CONFIG, "message", "deny_fields")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_fields")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -785,6 +782,23 @@ def config_get(config, section, key, default="", lng_key=""):
|
||||
return default
|
||||
|
||||
|
||||
def config_getarray(config, section, key, default=[], lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
value = ""
|
||||
if config.has_option(section, key+lng_key):
|
||||
value = config[section][key+lng_key]
|
||||
elif config.has_option(section, key):
|
||||
value = config[section][key]
|
||||
if value != "":
|
||||
values_return = []
|
||||
values = value.split(",")
|
||||
for value in values:
|
||||
values_return.append(val_to_val(value.strip()))
|
||||
return values_return
|
||||
return default
|
||||
|
||||
|
||||
def config_getint(config, section, key, default=0, lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
@ -962,8 +976,13 @@ def val_to_val(val):
|
||||
return True
|
||||
elif val.lower() == "false":
|
||||
return False
|
||||
else:
|
||||
return val
|
||||
elif val.startswith("0x") or val.startswith("0X"):
|
||||
try:
|
||||
val_int = int(val, 16)
|
||||
return val_int
|
||||
except:
|
||||
pass
|
||||
return val
|
||||
|
||||
|
||||
##############################################################################################################
|
||||
|
@ -43,7 +43,7 @@ enabled = False
|
||||
|
||||
#### Message settings ####
|
||||
[message]
|
||||
deny_fields = ts
|
||||
deny_fields = 0x09,0xAD
|
||||
|
||||
send_title_prefix =
|
||||
send_prefix =
|
||||
@ -54,8 +54,8 @@ cluster_receive_prefix = @!cluster_source!->
|
||||
cluster_send_title_prefix = !source_name! <!source_address!>
|
||||
cluster_send_prefix = @!cluster_destination!!n!
|
||||
|
||||
fields_remove = gps
|
||||
fields_remove_anonymous = src,gps
|
||||
fields_remove = 0x02,0x03,0x04,0xA6
|
||||
fields_remove_anonymous = 0x02,0x03,0x04,0xAF,0xA6
|
||||
|
||||
|
||||
#### Statistic/Counter settings ####
|
||||
|
@ -43,7 +43,7 @@ enabled = False
|
||||
|
||||
#### Message settings ####
|
||||
[message]
|
||||
deny_fields = ts
|
||||
deny_fields = 0x09,0xAD
|
||||
|
||||
send_title_prefix = !source_name! <!source_address!>
|
||||
send_prefix =
|
||||
@ -55,7 +55,7 @@ cluster_send_title_prefix = !source_name! <!source_address!>
|
||||
cluster_send_prefix = @!cluster_destination!!n!
|
||||
|
||||
fields_remove =
|
||||
fields_remove_anonymous = src,gps
|
||||
fields_remove_anonymous = 0x02,0x03,0x04,0xAF,0xA6
|
||||
|
||||
|
||||
#### Statistic/Counter settings ####
|
||||
|
@ -870,9 +870,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
title = message.title.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "deny_title")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_title")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -880,9 +879,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
content = message.content.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "deny_content")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_content")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -890,9 +888,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
if message.fields:
|
||||
denys = config_get(CONFIG, "message", "deny_fields")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_fields")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -1263,12 +1260,12 @@ def lxmf_message_received_callback(message):
|
||||
else:
|
||||
fields = {}
|
||||
if CONFIG["main"].getboolean("fields_message"):
|
||||
if not "hash" in fields:
|
||||
fields["hash"] = message.hash
|
||||
if not "anonymous" in source_rights and "src" not in fields:
|
||||
fields["src"] = {}
|
||||
fields["src"]["h"] = message.source_hash
|
||||
fields["src"]["n"] = source_name
|
||||
if not 0xA7 in fields:
|
||||
fields[0xA7] = message.hash
|
||||
if not "anonymous" in source_rights and 0xAF not in fields:
|
||||
fields[0xAF] = {}
|
||||
fields[0xAF]["h"] = message.source_hash
|
||||
fields[0xAF]["n"] = source_name
|
||||
fields["c_n"] = CONFIG["cluster"]["name"]
|
||||
fields["c_t"] = CONFIG["cluster"]["type"]
|
||||
|
||||
@ -1313,13 +1310,13 @@ def lxmf_message_received_callback(message):
|
||||
|
||||
if CONFIG["main"].getboolean("fields_message"):
|
||||
if CONFIG["lxmf"]["destination_type_conv"] != "":
|
||||
fields["type"] = CONFIG["lxmf"].getint("destination_type_conv")
|
||||
if not "hash" in fields:
|
||||
fields["hash"] = message.hash
|
||||
if not "anonymous" in source_rights and "src" not in fields:
|
||||
fields["src"] = {}
|
||||
fields["src"]["h"] = message.source_hash
|
||||
fields["src"]["n"] = source_name
|
||||
fields[0xB3] = CONFIG["lxmf"].getint("destination_type_conv")
|
||||
if not 0xA7 in fields:
|
||||
fields[0xA7] = message.hash
|
||||
if not "anonymous" in source_rights and 0xAF not in fields:
|
||||
fields[0xAF] = {}
|
||||
fields[0xAF]["h"] = message.source_hash
|
||||
fields[0xAF]["n"] = source_name
|
||||
|
||||
for section in sections:
|
||||
if "receive_cluster_send" in config_get(CONFIG, "rights", section).split(",") or (cluster_loop and "receive_cluster_loop" in config_get(CONFIG, "rights", section).split(",")):
|
||||
@ -1388,13 +1385,13 @@ def lxmf_message_received_callback(message):
|
||||
|
||||
if CONFIG["main"].getboolean("fields_message"):
|
||||
if CONFIG["lxmf"]["destination_type_conv"] != "":
|
||||
fields["type"] = CONFIG["lxmf"].getint("destination_type_conv")
|
||||
if not "hash" in fields:
|
||||
fields["hash"] = message.hash
|
||||
if not "anonymous" in source_rights and "src" not in fields:
|
||||
fields["src"] = {}
|
||||
fields["src"]["h"] = message.source_hash
|
||||
fields["src"]["n"] = source_name
|
||||
fields[0xB3] = CONFIG["lxmf"].getint("destination_type_conv")
|
||||
if not 0xA7 in fields:
|
||||
fields[0xA7] = message.hash
|
||||
if not "anonymous" in source_rights and 0xAF not in fields:
|
||||
fields[0xAF] = {}
|
||||
fields[0xAF]["h"] = message.source_hash
|
||||
fields[0xAF]["n"] = source_name
|
||||
|
||||
if config_get(CONFIG, "message", "timestamp", "", lng_key) == "client":
|
||||
timestamp = message.timestamp
|
||||
@ -1608,7 +1605,7 @@ def interface(cmd, source_hash, source_name, source_right, source_rights, lng_ke
|
||||
content = config_get(CONFIG, "interface_menu", "leave_ok", "", lng_key)
|
||||
content = replace(content, source_hash, source_name, source_right, lng_key)
|
||||
if content != "":
|
||||
LXMF_CONNECTION.send(source_hash, content, "", {"data": None, "tpl": "info"}, None, "interface_send")
|
||||
LXMF_CONNECTION.send(source_hash, content, "", {0xA3: None, 0xB1: "info"}, None, "interface_send")
|
||||
content = ""
|
||||
|
||||
if CONFIG["main"].getboolean("auto_save_data"):
|
||||
@ -2905,7 +2902,7 @@ def interface(cmd, source_hash, source_name, source_right, source_rights, lng_ke
|
||||
|
||||
#### Fields #####
|
||||
def fields_remove(fields=None, key="fields_remove"):
|
||||
search = config_get(CONFIG, "message", key).split(",")
|
||||
search = config_getarray(CONFIG, "message", key)
|
||||
|
||||
delete = []
|
||||
for field in fields:
|
||||
@ -2927,64 +2924,64 @@ def fields_generate(lng_key, fields=None, h=None, n=None, m=False, d=False, r=Fa
|
||||
fields = {}
|
||||
|
||||
if CONFIG["lxmf"]["destination_type_conv"] != "":
|
||||
fields["type"] = CONFIG["lxmf"].getint("destination_type_conv")
|
||||
fields[0xB3] = CONFIG["lxmf"].getint("destination_type_conv")
|
||||
|
||||
if h:
|
||||
fields["src"] = {}
|
||||
fields["src"]["h"] = h
|
||||
fields[0xAF] = {}
|
||||
fields[0xAF]["h"] = h
|
||||
if n:
|
||||
fields["src"]["n"] = n
|
||||
fields[0xAF]["n"] = n
|
||||
else:
|
||||
fields["src"]["n"] = ""
|
||||
fields[0xAF]["n"] = ""
|
||||
|
||||
if m or d or r or cmd or config:
|
||||
fields["data"] = {}
|
||||
fields[0xA3] = {}
|
||||
|
||||
if m:
|
||||
fields["data"]["m"] = {}
|
||||
fields[0xA3]["m"] = {}
|
||||
for (key, val) in CONFIG.items("rights"):
|
||||
if DATA.has_section(key):
|
||||
fields["data"]["m"][key] = {}
|
||||
fields[0xA3]["m"][key] = {}
|
||||
for (section_key, section_val) in DATA.items(key):
|
||||
try:
|
||||
h = bytes.fromhex(LXMF_CONNECTION.destination_correct(section_key))
|
||||
fields["data"]["m"][key][h] = section_val
|
||||
fields[0xA3]["m"][key][h] = section_val
|
||||
except:
|
||||
pass
|
||||
|
||||
if d:
|
||||
fields["data"]["d"] = config_get(DATA, "main", "description", "", lng_key).replace(CONFIG["interface"]["delimiter_output"]+"n"+CONFIG["interface"]["delimiter_output"], "\n")
|
||||
fields[0xA3]["d"] = config_get(DATA, "main", "description", "", lng_key).replace(CONFIG["interface"]["delimiter_output"]+"n"+CONFIG["interface"]["delimiter_output"], "\n")
|
||||
|
||||
if r:
|
||||
fields["data"]["r"] = config_get(DATA, "main", "rules", "", lng_key).replace(CONFIG["interface"]["delimiter_output"]+"n"+CONFIG["interface"]["delimiter_output"], "\n")
|
||||
fields[0xA3]["r"] = config_get(DATA, "main", "rules", "", lng_key).replace(CONFIG["interface"]["delimiter_output"]+"n"+CONFIG["interface"]["delimiter_output"], "\n")
|
||||
|
||||
if cmd:
|
||||
fields["data"]["cmd"] = []
|
||||
fields[0xA3]["cmd"] = []
|
||||
if CONFIG.has_option("cmds", cmd):
|
||||
cmds = config_get(CONFIG, "cmds", cmd).split(",")
|
||||
for cmd in cmds:
|
||||
fields["data"]["cmd"].append({"c": "/"+cmd})
|
||||
fields[0xA3]["cmd"].append({"c": "/"+cmd})
|
||||
|
||||
if config:
|
||||
fields["data"]["config"] = {}
|
||||
fields[0xA3]["config"] = {}
|
||||
if CONFIG.has_option("configs", config):
|
||||
configs = config_get(CONFIG, "configs", config).split(",")
|
||||
for config in configs:
|
||||
if config != "":
|
||||
key, value = config.split("=", 1)
|
||||
fields["data"]["config"][key] = val_to_val(value)
|
||||
fields[0xA3]["config"][key] = val_to_val(value)
|
||||
|
||||
if cmd or config:
|
||||
if DATA.has_section("topics"):
|
||||
fields["data"]["topics"] = {}
|
||||
fields[0xA3]["topics"] = {}
|
||||
for (key, val) in DATA.items("topics"):
|
||||
try:
|
||||
fields["data"]["topics"][int(key)] = val
|
||||
fields[0xA3]["topics"][int(key)] = val
|
||||
except:
|
||||
pass
|
||||
|
||||
if tpl:
|
||||
fields["tpl"] = tpl
|
||||
fields[0xB1] = tpl
|
||||
|
||||
return fields
|
||||
|
||||
@ -3040,6 +3037,23 @@ def config_get(config, section, key, default="", lng_key=""):
|
||||
return default
|
||||
|
||||
|
||||
def config_getarray(config, section, key, default=[], lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
value = ""
|
||||
if config.has_option(section, key+lng_key):
|
||||
value = config[section][key+lng_key]
|
||||
elif config.has_option(section, key):
|
||||
value = config[section][key]
|
||||
if value != "":
|
||||
values_return = []
|
||||
values = value.split(",")
|
||||
for value in values:
|
||||
values_return.append(val_to_val(value.strip()))
|
||||
return values_return
|
||||
return default
|
||||
|
||||
|
||||
def config_getint(config, section, key, default=0, lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
@ -3578,8 +3592,13 @@ def val_to_val(val):
|
||||
return True
|
||||
elif val.lower() == "false":
|
||||
return False
|
||||
else:
|
||||
return val
|
||||
elif val.startswith("0x") or val.startswith("0X"):
|
||||
try:
|
||||
val_int = int(val, 16)
|
||||
return val_int
|
||||
except:
|
||||
pass
|
||||
return val
|
||||
|
||||
|
||||
##############################################################################################################
|
||||
@ -3771,7 +3790,7 @@ def setup(path=None, path_rns=None, path_log=None, loglevel=None, service=False)
|
||||
if CONFIG["lxmf"]["destination_type_conv"] != "":
|
||||
try:
|
||||
if CONFIG["main"].getboolean("fields_announce"):
|
||||
announce_data = umsgpack.packb({"c": CONFIG["lxmf"]["display_name"].encode("utf-8"), "t": None, "f": {"type": CONFIG["lxmf"].getint("destination_type_conv")}})
|
||||
announce_data = umsgpack.packb({"c": CONFIG["lxmf"]["display_name"].encode("utf-8"), "t": None, "f": {0xB3: CONFIG["lxmf"].getint("destination_type_conv")}})
|
||||
else:
|
||||
display_name += chr(CONFIG["lxmf"].getint("destination_type_conv"))
|
||||
except:
|
||||
|
@ -654,9 +654,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
title = message.title.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "deny_title")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_title")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -664,9 +663,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
content = message.content.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "deny_content")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_content")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -674,9 +672,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
if message.fields:
|
||||
denys = config_get(CONFIG, "message", "deny_fields")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_fields")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -792,6 +789,23 @@ def config_get(config, section, key, default="", lng_key=""):
|
||||
return default
|
||||
|
||||
|
||||
def config_getarray(config, section, key, default=[], lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
value = ""
|
||||
if config.has_option(section, key+lng_key):
|
||||
value = config[section][key+lng_key]
|
||||
elif config.has_option(section, key):
|
||||
value = config[section][key]
|
||||
if value != "":
|
||||
values_return = []
|
||||
values = value.split(",")
|
||||
for value in values:
|
||||
values_return.append(val_to_val(value.strip()))
|
||||
return values_return
|
||||
return default
|
||||
|
||||
|
||||
def config_getint(config, section, key, default=0, lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
@ -1053,8 +1067,13 @@ def val_to_val(val):
|
||||
return True
|
||||
elif val.lower() == "false":
|
||||
return False
|
||||
else:
|
||||
return val
|
||||
elif val.startswith("0x") or val.startswith("0X"):
|
||||
try:
|
||||
val_int = int(val, 16)
|
||||
return val_int
|
||||
except:
|
||||
pass
|
||||
return val
|
||||
|
||||
|
||||
##############################################################################################################
|
||||
|
13
lxmf_echo/Examples/Communicator_Software/config.cfg.owr
Normal file
13
lxmf_echo/Examples/Communicator_Software/config.cfg.owr
Normal file
@ -0,0 +1,13 @@
|
||||
# This is the user configuration file to override the default configuration file.
|
||||
# All settings made here have precedence.
|
||||
# This file can be used to clearly summarize all settings that deviate from the default.
|
||||
# This also has the advantage that all changed settings can be kept when updating the program.
|
||||
[lxmf]
|
||||
display_name = Echo Test
|
||||
announce_startup = Yes
|
||||
announce_periodic = Yes
|
||||
announce_periodic_interval = 30 #Minutes
|
||||
|
||||
[message]
|
||||
deny_fields = 0x09,0xB2,0xA4,0xA5,0xAD
|
||||
fields_remove = 0x02,0x03,0x04,0xA6,0xAB
|
@ -647,9 +647,8 @@ def lxmf_message_received_callback(message):
|
||||
if CONFIG.has_option("allowed", "any") or CONFIG.has_option("allowed", "all") or CONFIG.has_option("allowed", "anybody") or CONFIG.has_option("allowed", RNS.hexrep(message.source_hash, False)) or CONFIG.has_option("allowed", RNS.prettyhexrep(message.source_hash)):
|
||||
|
||||
title = message.title.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "deny_title")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_title")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -657,9 +656,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
content = message.content.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "deny_content")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_content")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -667,9 +665,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
if message.fields:
|
||||
denys = config_get(CONFIG, "message", "deny_fields")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_fields")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -728,7 +725,7 @@ def lxmf_message_received_callback(message):
|
||||
if CONFIG["message"].getboolean("fields"):
|
||||
fields = message.fields
|
||||
if fields:
|
||||
search = config_get(CONFIG, "message", "fields_remove").split(",")
|
||||
search = config_getarray(CONFIG, "message", "fields_remove")
|
||||
delete = []
|
||||
for field in fields:
|
||||
if field in search:
|
||||
@ -759,6 +756,23 @@ def config_get(config, section, key, default="", lng_key=""):
|
||||
return default
|
||||
|
||||
|
||||
def config_getarray(config, section, key, default=[], lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
value = ""
|
||||
if config.has_option(section, key+lng_key):
|
||||
value = config[section][key+lng_key]
|
||||
elif config.has_option(section, key):
|
||||
value = config[section][key]
|
||||
if value != "":
|
||||
values_return = []
|
||||
values = value.split(",")
|
||||
for value in values:
|
||||
values_return.append(val_to_val(value.strip()))
|
||||
return values_return
|
||||
return default
|
||||
|
||||
|
||||
def config_getint(config, section, key, default=0, lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
@ -936,8 +950,13 @@ def val_to_val(val):
|
||||
return True
|
||||
elif val.lower() == "false":
|
||||
return False
|
||||
else:
|
||||
return val
|
||||
elif val.startswith("0x") or val.startswith("0X"):
|
||||
try:
|
||||
val_int = int(val, 16)
|
||||
return val_int
|
||||
except:
|
||||
pass
|
||||
return val
|
||||
|
||||
|
||||
##############################################################################################################
|
||||
|
@ -753,9 +753,8 @@ def lxmf_message_received_callback(message):
|
||||
SESSION["source"] = message.source_hash
|
||||
|
||||
title = message.title.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "deny_title")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_title")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -763,9 +762,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
content = message.content.decode('utf-8').strip()
|
||||
denys = config_get(CONFIG, "message", "deny_content")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_content")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -773,9 +771,8 @@ def lxmf_message_received_callback(message):
|
||||
return
|
||||
|
||||
if message.fields:
|
||||
denys = config_get(CONFIG, "message", "deny_fields")
|
||||
if denys != "":
|
||||
denys = denys.split(",")
|
||||
denys = config_getarray(CONFIG, "message", "deny_fields")
|
||||
if len(denys) > 0:
|
||||
if "*" in denys:
|
||||
return
|
||||
for deny in denys:
|
||||
@ -920,6 +917,23 @@ def config_get(config, section, key, default="", lng_key=""):
|
||||
return default
|
||||
|
||||
|
||||
def config_getarray(config, section, key, default=[], lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
value = ""
|
||||
if config.has_option(section, key+lng_key):
|
||||
value = config[section][key+lng_key]
|
||||
elif config.has_option(section, key):
|
||||
value = config[section][key]
|
||||
if value != "":
|
||||
values_return = []
|
||||
values = value.split(",")
|
||||
for value in values:
|
||||
values_return.append(val_to_val(value.strip()))
|
||||
return values_return
|
||||
return default
|
||||
|
||||
|
||||
def config_getint(config, section, key, default=0, lng_key=""):
|
||||
if not config or section == "" or key == "": return default
|
||||
if not config.has_section(section): return default
|
||||
@ -1097,8 +1111,13 @@ def val_to_val(val):
|
||||
return True
|
||||
elif val.lower() == "false":
|
||||
return False
|
||||
else:
|
||||
return val
|
||||
elif val.startswith("0x") or val.startswith("0X"):
|
||||
try:
|
||||
val_int = int(val, 16)
|
||||
return val_int
|
||||
except:
|
||||
pass
|
||||
return val
|
||||
|
||||
|
||||
##############################################################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user