SomeoneElse37 / BattleBot

A Discord bot that rolls dice and stuff.
MIT License
0 stars 1 forks source link

broken .pickle #11

Closed lenscas closed 7 years ago

lenscas commented 7 years ago

for some reason the changes caused by 70fd2c3 break old .pickle files. (old files being generated by a bot that was on the lenscas-fixes branch)

When booting the bot with an old .pickle file results in the following stacktrace Traceback (most recent call last): File "battlebot.py", line 1084, in <module> database = pickle.load(f) ModuleNotFoundError: No module named 'battles' This is possible caused by the fact that the battles class gets imported as classes.battles rather then just battles though I do find it weird that the .pickle file didn't break when splitting battlebot.py into separate files. Maybe that means that .pickle files that are generated from the master branch remain unaffected?

SomeoneElse37 commented 7 years ago

Hmm. Yeah, that one's a problem.

The best solution would probably be to use an actual database to store all the data, but that's likely not going to happen anytime in the near future.

It might be possible to use the "import whatever as name" syntax to make pickle think the classes are located in the same places as they were in earlier versions (see https://docs.python.org/3.6/reference/simple_stmts.html#import for details)... but that may not be the case.

Failing that, the easiest way to update the .pickle file to the new module structure might be to upgrade the Excel code to be able to save and load battles, characters, and abilities. That way, you could run /excel to store the characters currently known to your instance of the bot in a spreadsheet, update the bot on your server, let it create a new .pickle file, and load the spreadsheet back into the bot.

On the other hand, there are only, what, three characters currently known to your instance of the bot (in the AoD guild, at least)? Not a big loss, even if all of their data does get deleted. Just make sure you type /list and /abilities on each of them before the update, so it'd be easy to recreate them.

lenscas commented 7 years ago

so....you are suggesting to make /excel log more (I agree with that) and make code to parse excel files to recover any broken .pickle files?

I don't think that that is worth it, especially considering that unless we do another overhaul of how our code is stored the .pickle files shouldn't break anymore.

It also started to become a problem after I moved lets say battles.py to the class folder. Moving the Battle class to battles.py in itself did not seem to break the .pickle file, its only after I moved that file that it broke stuff.

SomeoneElse37 commented 7 years ago

That was my suggestion, yes (my second suggestion, specifically). I had thought that one of the purposes of the excel command was to allow GMs to edit all the various properties of the characters, for which there may or may not be commands in the Discord interface. Or were you going to let the actual database fill that role, when that eventually comes to exist?

At any rate, you're probably right in that it's not worthwhile to make the bot able to load Excel files as well as save them, if you weren't already planning to do that. Just /list and /abilities each of the characters and roll out with the update.

lenscas commented 7 years ago

Maybe if Excel and programs like it can generate easier to parse data then I guess I could do something like it. user runs /excel does the changes in the excel file runs whatever inside excel to generate a json file user uploads json to discord (in a way that the bot can see it) if user is gm ->bot updates its database accordingly

The reason I rather have the bot deal with json is because that is already an easy to use function for python and all I need to do then is loop over the object rather then read the excel file directly using odfpy.

However, as I only have libreoffice testing the generating of the json in excel (if that is even possible) becomes a bit problematic.......

SomeoneElse37 commented 7 years ago

This is sounding more and more like "not worthwhile" to me...

SomeoneElse37 commented 7 years ago

Also, on this topic, I just pushed commit d19ebcd. I pulled out most of the code in pickleDB.py that is responsible for updating the database format after an updates to the bot, since the bot can't load old database versions now anyway.

lenscas commented 7 years ago

I just updated the bot on my discord server to track lenscas-fixes rather then master.

The .pickle file did not break, as this bot was never on lenscas-fixes thus never saw the files getting moved.