Refactored flag system

This commit is contained in:
aewens 2019-12-01 20:27:48 -05:00
parent 770365f7e2
commit bafc495f0f
3 changed files with 6 additions and 4 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
NOTES
test.py
settings.json
plugins/private_*.py
*.vim
*.swp
*.swo

View File

@ -12,7 +12,7 @@ def callback(state, sock, message):
irc_settings = settings.get("irc", dict())
bot_name = irc_settings.get("name", "ircbot")
flags = dict()
flags = state.get("_flags")
send = lambda msg: sock.send(f"{msg}\r\n".encode())
if command == "ERROR":
@ -77,7 +77,4 @@ def callback(state, sock, message):
print(privmsg(message))
#NotImplemented
for key, value in flags.items():
state[key] = value
return state

View File

@ -138,6 +138,7 @@ def irc(host, port, plugins, secure=True):
settings_path = Path(__file__).resolve().parent / "settings.json"
settings_text = settings_path.read_text()
settings = json_loads(settings_text)
state["_flags"] = dict()
state["settings"] = settings
while not state.get("stop"):
@ -181,6 +182,9 @@ def irc(host, port, plugins, secure=True):
for plugin_name, plugin_callbacks in plugins.items():
for callback in plugin_callbacks:
state = callback(state, sock, parsed)
flags = state.get("_flags")
for key, value in flags.items():
state[key] = value
print("CLOSED")