forked from LukeusMaximus/Python-IRC-Bot-Framework
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamplebot.py
More file actions
Latest commit
88 lines (73 loc) · 3.37 KB
/
Copy pathexamplebot.py
File metadata and controls
88 lines (73 loc) · 3.37 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
fromircbotframeimportircBot
importsys
# Bot specific function definitions
defauthFailure(recipient, name):
bot.say(recipient, "You could not be identified")
defquitSuccess(quitMessage):
bot.disconnect(quitMessage)
bot.stop()
defjoinSuccess(channel):
bot.joinchan(channel)
defsaySuccess(channel, message):
bot.say(channel, message)
defkickSuccess(nick, channel, reason):
bot.kick(nick, channel, reason)
defidentPass():
pass
defidentFail():
pass
defprivmsg(sender, headers, message):
ifmessage.startswith("!say "):
firstSpace=message[5:].find(" ") +5
ifsender==owner:
bot.identify(sender, saySuccess, (message[5:firstSpace], message[firstSpace+1:]), authFailure, (headers[0], sender))
elifmessage.startswith("!quit"):
ifsender==owner:
iflen(message) >6:
bot.identify(sender, quitSuccess, (message[6:],), authFailure, (headers[0], sender))
else:
bot.identify(sender, quitSuccess, ("",), authFailure, (headers[0], sender))
elifmessage.startswith("!join "):
ifsender==owner:
bot.identify(sender, joinSuccess, (message[6:],), authFailure, (headers[0], sender))
elifmessage.startswith("!kick "):
firstSpace=message[6:].find(" ") +6
secondSpace=message[firstSpace+1:].find(" ") + (firstSpace+1)
ifsender==owner:
bot.identify(sender, kickSuccess, (message[6:firstSpace], message[firstSpace+1:secondSpace], message[secondSpace+1:]), authFailure, (headers[0], sender))
else:
print"PRIVMSG: \""+message+"\""
defactionmsg(sender, headers, message):
print"An ACTION message was sent by "+sender+" with the headers "+str(headers) +". It says: \""+sender+" "+message+"\""
defendMOTD(sender, headers, message):
bot.joinchan(chanName)
bot.say(chanName, "I am an example bot.")
bot.say(chanName, "I have 4 functions, they are Join, Kick, Quit and Say.")
bot.say(chanName, "Join (joins a channel); Usage: \"!join #<channel>\"")
bot.say(chanName, "Kick (kicks a user); Usage: \"!kick <nick> #<channel> <reason>\"")
bot.say(chanName, "Quit (disconnects from the IRC server); Usage: \"!quit [<quit message>]\"")
bot.say(chanName, "Say (makes the bot say something); Usage: \"!say <channel/user> <message>\"")
bot.say(chanName, "The underlying framework is in no way limited to the above functions.")
bot.say(chanName, "This is merely an example of the framework's usage")
defuseSSL(argv):
returnlen (argv) ==6andargv[5] =="ssl"
# Main program begins here
if__name__=="__main__":
iflen(sys.argv) ==5oruseSSL(sys.argv):
server=sys.argv[1]
port=int(sys.argv[2])
owner=sys.argv[3]
chanName="#"+sys.argv[4]
bot=ircBot(server, port, "ExampleBot", "An example bot written with the new IRC bot framework", ssl=useSSL(sys.argv))
bot.bind("PRIVMSG", privmsg)
bot.bind("ACTION", actionmsg)
bot.bind("376", endMOTD)
bot.debugging(True)
bot.start()
inputStr=""
whileinputStr!="stop":
inputStr=raw_input()
bot.stop()
bot.join()
else:
print"Usage: python examplebot.py <server> <port> <your IRC nick> <irc channel (no '#' character please)> <ssl (optional)>"