fix rules

This commit is contained in:
Mylloon 2022-08-08 09:58:23 +02:00
parent 30615db063
commit d23b9b57c3
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

13
main.py
View file

@ -288,7 +288,7 @@ def create_rules(tracked_users: list[str]) -> list[str]:
rules = [] rules = []
# Repeating rules # Repeating rules
repeat = "-is:retweet" repeat = "-is:retweet ("
# Buffer # Buffer
buffer = repeat buffer = repeat
@ -297,13 +297,14 @@ def create_rules(tracked_users: list[str]) -> list[str]:
for user in tracked_users: for user in tracked_users:
# Check if the rule don't exceeds the maximum length of a rule (512) # Check if the rule don't exceeds the maximum length of a rule (512)
# 5 is len of "from:" # 5 is len of "from:"
if len(buffer) + len(user) + 5 > 512: # 1 is len for closing parenthesis
rules.append(buffer) if len(buffer) + len(user) + 5 + 1 > 512:
rules.append(buffer[:-4] + ")")
buffer = repeat buffer = repeat
buffer += f' OR from:{user}' buffer += f"from:{user} OR "
if len(buffer) > 0: if len(buffer) > 0:
rules.append(buffer) rules.append(buffer[:-4] + ")")
if len(rules) > 25: if len(rules) > 25:
raise BufferError("Too much rules.") raise BufferError("Too much rules.")
@ -333,7 +334,7 @@ def start():
# Clean rules # Clean rules
old_rules = stream.get_rules() old_rules = stream.get_rules()
if (old_rules.data): if (old_rules.data):
stream.delete_rules([rule for rule in old_rules.data]) stream.delete_rules([rule.id for rule in old_rules.data])
# Add new rules # Add new rules
stream.add_rules([StreamRule(rule) stream.add_rules([StreamRule(rule)