Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Peliia opened this issue Mar 2, 2019 · 2 comments
Open

Comments

@Peliia
Copy link

Peliia commented Mar 2, 2019

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.

@Peliia
Copy link
Author

Peliia commented Mar 2, 2019

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.

@spboxer3
Copy link

spboxer3 commented Mar 10, 2021

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants