Browse Source

refactored

master
wes 14 years ago
parent
commit
445363f7a3
  1. 7
      irc_speak.py

7
irc_speak.py

@ -58,7 +58,7 @@ aliases = {"rate" : 1,
"pitch" : 3, "pitch" : 3,
"vrange" : 4} "vrange" : 4}
def edit_users(*args, **new_options): def edit_users(**new_options):
"""Edits the options dictionary to add/update a user's settings""" """Edits the options dictionary to add/update a user's settings"""
nick = new_options['name'][0] nick = new_options['name'][0]
if not nick in options: if not nick in options:
@ -83,6 +83,7 @@ def irc_speak(word, word_eol, users):
return xchat.EAT_NONE # return nothing because they weren't in the options dictionary return xchat.EAT_NONE # return nothing because they weren't in the options dictionary
def set_user(arguments): def set_user(arguments):
"""Parses arguments and calls the edit_users function"""
try: try:
arguments = editor.parse_args(arguments) arguments = editor.parse_args(arguments)
return edit_users(**vars(arguments)) return edit_users(**vars(arguments))
@ -91,11 +92,13 @@ def set_user(arguments):
return "Exited with status %s" % (exception) return "Exited with status %s" % (exception)
def save(): def save():
"""Saves a user in the json file"""
with open(options_path, mode='w') as jsonfile: with open(options_path, mode='w') as jsonfile:
json.dump(options, jsonfile) json.dump(options, jsonfile)
return "Saved!" return "Saved!"
def deluser(user): def deluser(user):
"""Deletes a user from the global dictionary"""
if user[0] in options: if user[0] in options:
del options[user[0]] del options[user[0]]
return "Deleted!" return "Deleted!"
@ -112,7 +115,7 @@ def commands(word, word_eol, users):
arguments = word[1:] arguments = word[1:]
try: try:
print commands[arguments[0]](arguments[1:]) print commands[arguments[0]](arguments[1:])
except KeyError as exception: except KeyError:
return xchat.EAT_XCHAT return xchat.EAT_XCHAT
xchat.hook_command("ircspeak", commands, help="/ircspeak set --help") xchat.hook_command("ircspeak", commands, help="/ircspeak set --help")