dump and init whitelist with a json file.

ADDED DEP: jsonpickle
This commit is contained in:
Skillet 2023-03-04 13:12:17 -05:00
parent 1d0efc3c85
commit 6f05fcb5ee
5 changed files with 31 additions and 2 deletions

1
.gitignore vendored
View File

@ -132,3 +132,4 @@ dmypy.json
.idea/ .idea/
.envrc .envrc
/test.json

View File

@ -1,3 +1,4 @@
import jsonpickle
import discord import discord
import logging import logging
from autowl import config from autowl import config
@ -37,6 +38,9 @@ class Whitelist(commands.Cog):
] = config.WhitelistMember(interaction.user.name, steam64) ] = config.WhitelistMember(interaction.user.name, steam64)
if steam64_updated: if steam64_updated:
outFile = open("test.json", "w")
outFile.write(jsonpickle.encode(self.client.whitelist, unpicklable=False))
outFile.close()
log.info( log.info(
f"Updated {interaction.user.name}'s ({interaction.user.id}) whitelist steam64 to {steam64}" f"Updated {interaction.user.name}'s ({interaction.user.id}) whitelist steam64 to {steam64}"
) )

View File

@ -1,3 +1,4 @@
import jsonpickle
import logging import logging
import discord import discord
from discord.ext import commands from discord.ext import commands
@ -9,6 +10,11 @@ log = logging.getLogger(__name__)
class Bot(commands.Bot): class Bot(commands.Bot):
whitelist = config.Whitelist({}).whitelist whitelist = config.Whitelist({}).whitelist
infile = open("test.json", "r")
if infile:
whitelist = jsonpickle.decode(infile.read())
infile.close()
def __init__(self, config: config.DiscordClientConfig): def __init__(self, config: config.DiscordClientConfig):
self.config = config self.config = config
intents = discord.Intents.default() intents = discord.Intents.default()

21
poetry.lock generated
View File

@ -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]] [[package]]
name = "aiohttp" name = "aiohttp"
@ -287,6 +287,23 @@ files = [
{file = "idna-3.4.tar.gz", hash = "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"}, {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]] [[package]]
name = "multidict" name = "multidict"
version = "6.0.4" version = "6.0.4"
@ -462,4 +479,4 @@ multidict = ">=4.0"
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.10" python-versions = "^3.10"
content-hash = "4150717da98b5eb32609d7670dc1457938d4fff5799126847030c693503f0247" content-hash = "22e27ffb14d002d43920b5647c8fd824ca4487469c5687561af70c02aa8e3cca"

View File

@ -8,6 +8,7 @@ readme = "README.md"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.10" python = "^3.10"
"discord.py" = "^2.1.0" "discord.py" = "^2.1.0"
jsonpickle = "^3.0.1"
[build-system] [build-system]