Skip to content

Adding alerts over a certain amount causes error and loss of settings #5

Open

Description

@Peliia

I wanted to create a multitude of alerts with different notifications but receive an error:
alerts version 0.6.20161201.002 loaded. Type /alerts help for usage instructions Failed to load alerts: Unterminated string starting at: line 1 column 437 (char 436) 0 alert(s) loaded

None of the alerts function, and after exiting HexChat, the addon_python.conf file containing the set alerts is cut, looking as such:
python_alerts_saved = [] \"}, {\"n\": \"crdeclare\", \"f\": \"efgw,,68\", \"r\": \"blabla\", \"s\": \"cr.wav\"}]

It's been found that shortening the list of alarms below the character count shown in the error works, and switching around the order of alarms showed all of them are of valid syntax and function proper. However, this makes adding additional alerts not possible. While adding these alerts through commands in HexChat works, upon exiting and launching HexChat again, this error occurs and a part of the file is lost again.

Activity

  1. Peliia commented on Mar 2, 2019

    @Peliia
    Author

    I should add that I am using Python for Windows 3.6.0 on Win 7 x64. I could not use any other version of Python as otherwise HexChat would not install properly with its interface.

  2. spboxer3 commented on Mar 10, 2021

    @spboxer3

    my solution:
    replace original def save(self) and def load(self) function
    here's my code:

    def save(self):
            """Save alerts data"""
            data = list(alert.export_dict() for alert in self.alerts.values())
            file = open(os.environ['appdata']+r"\hexchat\alerts.conf","wt")
            file.write(json.dumps(data)) 
            file.close()
    

    and

    def load(self):
            """Load alerts data"""
            try:
                file = open(os.environ['appdata']+r"\hexchat\alerts.conf","r")
                print("alerts config file is exist, loading config")
            except:
                file = open(os.environ['appdata']+r"\hexchat\alerts.conf","wt")
                file.write("[]")
                file.close()
                file = open(os.environ['appdata']+r"\hexchat\alerts.conf","r")
                print("alerts config file is not exist, create config")
            data = file.read()
            if data is None:
                return
            try:
                result = json.loads(data)
            except Exception as ex:
                print("Failed to load alerts:", str(ex))
                return False
    
            if not isinstance(result, list):
                result = [result]
    
            self.alerts.clear()
    
            for ix, data in enumerate(result):
                try:
                    alert = Alert.import_dict(data)
                except Exception as ex:
                    print("Failed to load entry {}:".format(ix), str(ex))
                    ok = False
                    continue
                if alert.name in plugin.alerts:
                    print("Failed to load entry {}: Alert '{}' duplicated in save data.".format(ix, alert.name))
                    ok = False
                    continue
                plugin.alerts.append(alert)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions