3
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
4
# See LICENSE for details.
8
A very simple twisted.im-based logbot.
11
from twisted.im import basechat, baseaccount
13
# A list of account objects. We might as well create them at runtime, this is
14
# supposed to be a Minimalist Implementation, after all.
15
from twisted.im import ircsupport
17
ircsupport.IRCAccount("IRC", 1,
20
"irc.freenode.net", # irc server
22
"#twisted", # comma-seperated list of channels
27
class AccountManager (baseaccount.AccountManager):
28
"""This class is a minimal implementation of the Acccount Manager.
30
Most implementations will show some screen that lets the user add and
31
remove accounts, but we're not quite that sophisticated.
36
self.chatui = MinChat()
38
if len(accounts) == 0:
39
print "You have defined no accounts."
41
acct.logOn(self.chatui)
44
class MinConversation(basechat.Conversation):
45
"""This class is a minimal implementation of the abstract Conversation class.
47
This is all you need to override to receive one-on-one messages.
50
"""If you don't have a GUI, this is a no-op.
55
"""If you don't have a GUI, this is a no-op.
59
def showMessage(self, text, metadata=None):
60
print "<%s> %s" % (self.person.name, text)
62
def contactChangedNick(self, person, newnick):
63
basechat.Conversation.contactChangedNick(self, person, newnick)
64
print "-!- %s is now known as %s" % (person.name, newnick)
67
class MinGroupConversation(basechat.GroupConversation):
68
"""This class is a minimal implementation of the abstract GroupConversation class.
70
This is all you need to override to listen in on a group conversaion.
73
"""If you don't have a GUI, this is a no-op.
78
"""If you don't have a GUI, this is a no-op.
82
def showGroupMessage(self, sender, text, metadata=None):
83
print "<%s/%s> %s" % (sender, self.group.name, text)
85
def setTopic(self, topic, author):
86
print "-!- %s set the topic of %s to: %s" % (author,
87
self.group.name, topic)
89
def memberJoined(self, member):
90
basechat.GroupConversation.memberJoined(self, member)
91
print "-!- %s joined %s" % (member, self.group.name)
93
def memberChangedNick(self, oldnick, newnick):
94
basechat.GroupConversation.memberChangedNick(self, oldnick, newnick)
95
print "-!- %s is now known as %s in %s" % (oldnick, newnick,
98
def memberLeft(self, member):
99
basechat.GroupConversation.memberLeft(self, member)
100
print "-!- %s left %s" % (member, self.group.name)
102
class MinChat(basechat.ChatUI):
103
"""This class is a minimal implementation of the abstract ChatUI class.
105
There are only two methods that need overriding - and of those two,
106
the only change that needs to be made is the default value of the Class
110
def getGroupConversation(self, group, Class=MinGroupConversation,
113
return basechat.ChatUI.getGroupConversation(self, group, Class,
116
def getConversation(self, person, Class=MinConversation,
119
return basechat.ChatUI.getConversation(self, person, Class, stayHidden)
121
if __name__ == "__main__":
122
from twisted.internet import reactor