3 # Copyright (c) Twisted Matrix Laboratories.
4 # See LICENSE for details.
8 A very simple twisted.words.im-based logbot.
14 from twisted.words.im import basechat, baseaccount, ircsupport
17 # A list of account objects. We might as well create them at runtime, this is
18 # supposed to be a Minimalist Implementation, after all.
21 ircsupport.IRCAccount("IRC", 1,
24 "irc.freenode.net", # irc server
26 "#twisted", # comma-seperated list of channels
31 class AccountManager (baseaccount.AccountManager):
33 This class is a minimal implementation of the Acccount Manager.
35 Most implementations will show some screen that lets the user add and
36 remove accounts, but we're not quite that sophisticated.
41 self.chatui = MinChat()
43 if len(accounts) == 0:
44 print "You have defined no accounts."
46 acct.logOn(self.chatui)
49 class MinConversation(basechat.Conversation):
51 This class is a minimal implementation of the abstract Conversation class.
53 This is all you need to override to receive one-on-one messages.
57 If you don't have a GUI, this is a no-op.
63 If you don't have a GUI, this is a no-op.
67 def showMessage(self, text, metadata=None):
68 print "<%s> %s" % (self.person.name, text)
70 def contactChangedNick(self, person, newnick):
71 basechat.Conversation.contactChangedNick(self, person, newnick)
72 print "-!- %s is now known as %s" % (person.name, newnick)
75 class MinGroupConversation(basechat.GroupConversation):
77 This class is a minimal implementation of the abstract GroupConversation class.
79 This is all you need to override to listen in on a group conversaion.
83 If you don't have a GUI, this is a no-op.
89 If you don't have a GUI, this is a no-op.
93 def showGroupMessage(self, sender, text, metadata=None):
94 print "<%s/%s> %s" % (sender, self.group.name, text)
96 def setTopic(self, topic, author):
97 print "-!- %s set the topic of %s to: %s" % (author,
98 self.group.name, topic)
100 def memberJoined(self, member):
101 basechat.GroupConversation.memberJoined(self, member)
102 print "-!- %s joined %s" % (member, self.group.name)
104 def memberChangedNick(self, oldnick, newnick):
105 basechat.GroupConversation.memberChangedNick(self, oldnick, newnick)
106 print "-!- %s is now known as %s in %s" % (oldnick, newnick,
109 def memberLeft(self, member):
110 basechat.GroupConversation.memberLeft(self, member)
111 print "-!- %s left %s" % (member, self.group.name)
114 class MinChat(basechat.ChatUI):
116 This class is a minimal implementation of the abstract ChatUI class.
118 There are only two methods that need overriding - and of those two,
119 the only change that needs to be made is the default value of the Class
123 def getGroupConversation(self, group, Class=MinGroupConversation,
126 return basechat.ChatUI.getGroupConversation(self, group, Class,
129 def getConversation(self, person, Class=MinConversation,
132 return basechat.ChatUI.getConversation(self, person, Class, stayHidden)
135 if __name__ == "__main__":
136 from twisted.internet import reactor