Hardware Reference
In-Depth Information
hese are IRC status codes , provided by the server to indicate when particular operations have
completed. These are used by the program to know when it has received the required list of
names from the IRC server. Next, set up the variables for the server connection by entering
the following lines:
irc = {
'host' : 'chat.freenode.net',
'port' : 6667,
'channel' : '#raspiuserguide',
'namesinterval' : 5
}
The first line tells Python to create a dict data type. Short for dictionary, this allows multiple
variables to be stored in a single master variable—in this case, irc . These individual vari-
ables can then be recalled later in the program. Although you could write this program with-
out using dicts to store variables, it would make the program significantly more difficult to
read. The dict begins with the opening curly brace, and ends with the closing curly brace on
the final line.
he host variable should be set to the fully qualified domain name (FQDN) of the IRC server
to which the program will connect. In this example, chat.freenode.net is used, but if
you want to customise the program to use a different server, change the domain name here.
he port variable tells the program which network port IRC is running on, which will usually
be 6667. he channel variable tells Python which channel to join in order to monitor the
users, while namesinterval controls how long the program waits to refresh the list of
users, measured in seconds.
Set up a second dict to store the user-specific variables by typing in the following lines:
user = {
'nick' : 'botnick',
'username' : 'botuser',
'hostname' : 'localhost',
'servername' : 'localhost',
'realname' : 'Raspberry Pi Names Bot'
}
As with irc , all these variables are stored within a dict called user to make it clear which
variables pertain to which section. The nick variable should be set to the IRC nickname the
program will use. Don't use your usual nickname if you're planning to connect to the IRC
server at the same time; instead, try appending -bo it to the end of your name to make it
Search WWH ::




Custom Search