Skip to content
This repository was archived by the owner on Feb 21, 2018. It is now read-only.

Commit 23da576

Browse files
committed
services/replayserv: New service to emulate channel mode +X on inspricd
1 parent 508b19b commit 23da576

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

modules/services/replayserv.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+

src/structures.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,30 @@ def __init__(self, name, ts):
126126
self.clients = {}
127127
self.lists = {'b': [], 'e': [], 'I': [], 'q': [], 'u': []}
128128
self.modes = ""
129+
self.msgbuffer = []
129130

130131
def listAdd(self, chanlist, mask):
131132
self.lists[chanlist].append(mask)
132133

133134
def clientAdd(self, client, prefix = ""):
134135
self.clients[client.uid] = ChanUser(client)
135136

137+
def addMessage(self, line):
138+
if len(self.msgbuffer) == 5:
139+
self.msgbuffer.pop(0)
140+
141+
try:
142+
fakeline = FakeLine(line)
143+
144+
self.msgbuffer.append(fakeline)
145+
except Exception as e:
146+
print type(e), e.message
147+
148+
class FakeLine():
149+
def __init__(self, line):
150+
self.nick = line.source.nick
151+
self.message = line.args[-1]
152+
136153
class ChanUser():
137154
"""
138155
Stub channel user structure for prefix tracking

0 commit comments

Comments
 (0)