January 2002
Beginner
480 pages
13h 15m
English
To maintain this dictionary, we will use two subroutines to add words to
and remove words from a user’s word list. These subroutines
are called when a command such as watch
or ignore is recognized in the callback
subroutine that handles
incoming <message/> elements:
def addword(jid, word):
if not keywords.has_key(jid):
keywords[jid] = {}
keywords[jid][word] = 1
def delword(jid, word):
if keywords.has_key(jid):
if keywords[jid].has_key(word):
del keywords[jid][word]
A string representation of the JID (in jid) of the correspondent giving the command is passed to the subroutines along with the word or phrase specified (in word) by the user.
The dictionary has two levels: the first level is keyed by the JID, and the second
by word or phrase. We use a dictionary, rather than an array, at the second
level simply to make removal of words and phrases easier.
Read now
Unlock full access