From 6f05fcb5ee6b987ea9fc235372b3b4b525433905 Mon Sep 17 00:00:00 2001 From: Skillet Date: Sat, 4 Mar 2023 13:12:17 -0500 Subject: [PATCH] dump and init whitelist with a json file. ADDED DEP: jsonpickle --- .gitignore | 1 + autowl/Cogs/Whitelist.py | 4 ++++ autowl/bot.py | 6 ++++++ poetry.lock | 21 +++++++++++++++++++-- pyproject.toml | 1 + 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 1eeea52..7e6958f 100644 --- a/.gitignore +++ b/.gitignore @@ -132,3 +132,4 @@ dmypy.json .idea/ .envrc +/test.json diff --git a/autowl/Cogs/Whitelist.py b/autowl/Cogs/Whitelist.py index cf8c459..d1e2afa 100644 --- a/autowl/Cogs/Whitelist.py +++ b/autowl/Cogs/Whitelist.py @@ -1,3 +1,4 @@ +import jsonpickle import discord import logging from autowl import config @@ -37,6 +38,9 @@ class Whitelist(commands.Cog): ] = config.WhitelistMember(interaction.user.name, steam64) if steam64_updated: + outFile = open("test.json", "w") + outFile.write(jsonpickle.encode(self.client.whitelist, unpicklable=False)) + outFile.close() log.info( f"Updated {interaction.user.name}'s ({interaction.user.id}) whitelist steam64 to {steam64}" ) diff --git a/autowl/bot.py b/autowl/bot.py index 22f2b9d..a363eee 100644 --- a/autowl/bot.py +++ b/autowl/bot.py @@ -1,3 +1,4 @@ +import jsonpickle import logging import discord from discord.ext import commands @@ -9,6 +10,11 @@ log = logging.getLogger(__name__) class Bot(commands.Bot): whitelist = config.Whitelist({}).whitelist + infile = open("test.json", "r") + if infile: + whitelist = jsonpickle.decode(infile.read()) + infile.close() + def __init__(self, config: config.DiscordClientConfig): self.config = config intents = discord.Intents.default() diff --git a/poetry.lock b/poetry.lock index 7995f71..95536c2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry and should not be changed by hand. +# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand. [[package]] name = "aiohttp" @@ -287,6 +287,23 @@ files = [ {file = "idna-3.4.tar.gz", hash = "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"}, ] +[[package]] +name = "jsonpickle" +version = "3.0.1" +description = "Python library for serializing any arbitrary object graph into JSON" +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "jsonpickle-3.0.1-py2.py3-none-any.whl", hash = "sha256:130d8b293ea0add3845de311aaba55e6d706d0bb17bc123bd2c8baf8a39ac77c"}, + {file = "jsonpickle-3.0.1.tar.gz", hash = "sha256:032538804795e73b94ead410800ac387fdb6de98f8882ac957fcd247e3a85200"}, +] + +[package.extras] +docs = ["jaraco.packaging (>=3.2)", "rst.linker (>=1.9)", "sphinx"] +testing = ["ecdsa", "feedparser", "gmpy2", "numpy", "pandas", "pymongo", "pytest (>=3.5,!=3.7.3)", "pytest-black-multipy", "pytest-checkdocs (>=1.2.3)", "pytest-cov", "pytest-flake8 (>=1.1.1)", "scikit-learn", "sqlalchemy"] +testing-libs = ["simplejson", "ujson"] + [[package]] name = "multidict" version = "6.0.4" @@ -462,4 +479,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "4150717da98b5eb32609d7670dc1457938d4fff5799126847030c693503f0247" +content-hash = "22e27ffb14d002d43920b5647c8fd824ca4487469c5687561af70c02aa8e3cca" diff --git a/pyproject.toml b/pyproject.toml index fd782d6..f288e5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,7 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.10" "discord.py" = "^2.1.0" +jsonpickle = "^3.0.1" [build-system]