-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
40 lines (30 loc) · 1.07 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
""" An example bot using the StatefulIRC framework. This is a simple bot with
two states: noisy and quiet. In the nosy state, it will say to the current
channel anything it receives in PM. In the quiet state, it will not. """
import main
class NoisyState(main.State):
@property
def name(self):
return 'Noisy'
def OnPrivateMessage(self, user, message):
if message == 'be quiet':
self._bot.go_to_state('Quiet')
elif user.nickname != self._bot.nickname:
self._bot.send_message_all_channels(message)
class QuietState(main.State):
@property
def name(self):
return 'Quiet'
def OnPrivateMessage(self, user, message):
if message == 'be noisy':
self._bot.go_to_state('Noisy')
class MasterState(main.State):
@property
def name(self):
return 'Master'
def OnPrivateMessage(self, user, message):
print user.nickname + "!" + user.ident + "@" + user.hostname + ": " + message
quietstate = QuietState()
noisystate = NoisyState()
masterstate = MasterState()
noisybot = main.StateBot('NoisyBot', 'irc.efnet.nl', ['#NoisyBotTest'], masterstate, [noisystate, quietstate])