|
| 1 | +""" |
| 2 | +Copyright (c) 2014, Sam Dodrill |
| 3 | +All rights reserved. |
| 4 | +
|
| 5 | +This software is provided 'as-is', without any express or implied |
| 6 | +warranty. In no event will the authors be held liable for any damages |
| 7 | +arising from the use of this software. |
| 8 | +
|
| 9 | +Permission is granted to anyone to use this software for any purpose, |
| 10 | +including commercial applications, and to alter it and redistribute it |
| 11 | +freely, subject to the following restrictions: |
| 12 | +
|
| 13 | + 1. The origin of this software must not be misrepresented; you must not |
| 14 | + claim that you wrote the original software. If you use this software |
| 15 | + in a product, an acknowledgment in the product documentation would be |
| 16 | + appreciated but is not required. |
| 17 | +
|
| 18 | + 2. Altered source versions must be plainly marked as such, and must not be |
| 19 | + misrepresented as being the original software. |
| 20 | +
|
| 21 | + 3. This notice may not be removed or altered from any source |
| 22 | + distribution. |
| 23 | +""" |
| 24 | + |
| 25 | +from structures import makeService |
| 26 | + |
| 27 | +global my_client |
| 28 | + |
| 29 | +def initModule(cod): |
| 30 | + global my_client |
| 31 | + |
| 32 | + cod.s2scommands["PRIVMSG"].append(handlePRIVMSG) |
| 33 | + cod.s2scommands["JOIN"].append(handleJOIN) |
| 34 | + |
| 35 | + my_client = makeService(cod.config["replay"]["nick"], |
| 36 | + cod.config["replay"]["user"], |
| 37 | + cod.config["replay"]["host"], |
| 38 | + cod.config["replay"]["gecos"], cod.getUID()) |
| 39 | + |
| 40 | + cod.burstClient(cod, my_client) |
| 41 | + cod.join(cod.config["etc"]["snoopchan"], my_client) |
| 42 | + |
| 43 | +def destroyModule(cod): |
| 44 | + cod.s2scommands["PRIVMSG"].remove(handlePRIVMSG) |
| 45 | + cod.s2scommands["JOIN"].remove(handleJOIN) |
| 46 | + |
| 47 | + cod.sendLine(my_client.quit()) |
| 48 | + cod.clients.pop(my_client.uid) |
| 49 | + |
| 50 | +def rehash(): |
| 51 | + pass |
| 52 | + |
| 53 | +def handlePRIVMSG(cod, line): |
| 54 | + if line.args[0][0] == "#": |
| 55 | + line.source = cod.clients[line.source] |
| 56 | + |
| 57 | + channel = cod.channels[line.args[0]] |
| 58 | + |
| 59 | + channel.addMessage(line) |
| 60 | + |
| 61 | +def handleJOIN(cod, line): |
| 62 | + channame = "" |
| 63 | + |
| 64 | + if line.args[0][0] == "#": |
| 65 | + channame = line.args[0] |
| 66 | + elif line.args[1][0] == "#": |
| 67 | + channame = line.args[1] |
| 68 | + |
| 69 | + doReplay(cod, line.source, cod.channels[channame]) |
| 70 | + |
| 71 | +def doReplay(cod, client, channel): |
| 72 | + global my_client |
| 73 | + |
| 74 | + if len(channel.msgbuffer) == 0: |
| 75 | + return |
| 76 | + |
| 77 | + cod.notice(client, "Now replaying you the last 5 lines of chat in %s" % channel.name, my_client) |
| 78 | + |
| 79 | + for line in channel.msgbuffer: |
| 80 | + cod.notice(client, "<%s> %s" % (line.nick, line.message), my_client) |
| 81 | + |
0 commit comments