forked from kenkeiras/PyIC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
executable file
·59 lines (36 loc) · 1.3 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# PyIC example
from pyic import *
botName = "HelloBot" # NickName
server = "irc.freenode.net" # IRC server
channel = "#bot_testing" # IRC channel
greet = "Hello"
topic = "PyIC testing"
print "Connecting..."
irc = irc_client( botName, server ) # Connect
print "Message of the day:"
print irc.get_motd( )
print "Reading channel list"
print len( irc.get_channels( ) ), "channels"
print "Joining", channel
irc.join( channel ) # Joins the channel
irc.notice( channel, greet + " " + channel ) # talks to the channel
# use notice in order to avoid automatic responses
# Reads the user list
for usr in irc.get_users( channel ):
print '"' + usr + '" data'
print irc.whois( clean_usr( usr ) ) # Shows the user data
irc.notice( channel, greet + " " + usr ) # talks to the user
print "Setting channel topic"
irc.set_topic( channel, topic )
print "Topic:", irc.get_topic( channel )
print "Waiting for users..."
# Greets who enters the channel
while ( True ):
msg = irc.getmsg( )
if ( msg.type.upper( ) == "JOIN" ): # Someone entered the channel
if ( msg.by != botName ):
print "'" + msg.by + "'", "has arrived"
irc.notice( channel, greet + " " + msg.by )
print irc.whois( msg.by )