Hardware Reference
In-Depth Information
he irst 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 . hese 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 signiicantly more diicult to
read. he dict begins with the opening curly brace, and ends with the closing curly brace on
the inal line.
he host variable should be set to the fully-qualiied 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 diferent 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-speciic 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. he 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 -bot to the end of your name to make it
clear that the user is a program rather than a real person. Do the same with username , and
ill in the realname variable with a descriptive message about whom the bot belongs to. he
hostname and servername variables can be left set to localhost , or altered to match
your Internet address.
he socket module requires the user to create a socket object . his object provides network
connectivity to the rest of the program. Create the socket object by typing in the following
line:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Search WWH ::




Custom Search