# todo by smong and chambahs
# add cmd_tshow, cmd_tadd and cmd_tdel to conf/groupdef.dir/mod
# inital version feb 7 2005

from asss import *

chat = get_interface(I_CHAT)

# global variable storing all the todo's
todo_list = []

def c_tshow(cmd, params, p, targ):
    """\
Module: <py> todo
Use this command to show all todo items.
"""
    i = 0
    for t in todo_list:
    	chat.SendMessage(p, "%d : %s" % (i, t))
	i += 1

    if i == 0:
    	chat.SendMessage(p, "There are no todo items to show.")

cmd1 = add_command("tshow", c_tshow)


def c_tadd(cmd, params, p, targ):
    """\
Module: <py> todo
Args: <some text>
Use this command to add a todo item.
"""
    if len(params) > 0:
    	todo_list.append(params)
	chat.SendMessage(p, "Added todo item.")
    else:
    	chat.SendMessage(p, "Correct usage is: ?tadd <some text>.")

cmd2 = add_command("tadd", c_tadd)


def c_tdel(cmd, params, p, targ):
    """\
Module: <py> todo
Args: <ID number>
Use this command to delete a todo item.
The ID is the same as that shown with ?tshow.
"""
    try:
    	tid = int(params)
    except ValueError:
        chat.SendMessage(p, "Please use the ID# as shown in ?tshow.")
    	return

    i = 0
    for t in todo_list:
    	if i == tid:
	    todo_list.remove(t)
	    chat.SendMessage(p, "Deleted todo item.")
	    break
	i += 1
    else:
    	chat.SendMessage(p, "No such todo for ID #%d." % tid)

cmd3 = add_command("tdel", c_tdel)

