1
|
|
|
from base import PsywerxPlugin |
2
|
|
|
from response import REPOSTS, MULTIPLE_REPOST, \ |
3
|
|
|
SELF_REPOSTS, MULTIPLE_SELF_REPOST, random_response |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class PsywerxHistory(PsywerxPlugin): |
7
|
|
|
|
8
|
|
|
def handle_message(self, channel, nick, msg, line=None): |
9
|
|
|
r = self.request(channel, 'irc/add', {'raw': line}) |
10
|
|
|
if not r: |
11
|
|
|
return |
12
|
|
|
if r.startswith('REPOST'): |
13
|
|
|
self._handle_repost(r, channel) |
14
|
|
|
elif r != 'OK': |
15
|
|
|
self.bot.log_error("Response not OK: " + r) |
16
|
|
|
|
17
|
|
|
def handle_say(self, channel, msg, line): |
18
|
|
|
msg = ":" + self.bot.nick + "!~" + self.bot.nick + "@6.6.6.6 " + line |
19
|
|
|
self.request(channel, 'irc/add', {'raw': msg}) |
20
|
|
|
|
21
|
|
|
def _handle_repost(self, r, channel): |
22
|
|
|
_, nick, repost_nick, message_type, num = r.split(' ') |
23
|
|
|
if message_type != 'M': |
24
|
|
|
return |
25
|
|
|
|
26
|
|
|
response = self._pick_response(nick == repost_nick, int(num) > 1) |
27
|
|
|
self.bot.say(response % { |
28
|
|
|
'nick': nick, |
29
|
|
|
'repost_nick': repost_nick, |
30
|
|
|
'num': num, |
31
|
|
|
}, channel) |
32
|
|
|
|
33
|
|
|
@staticmethod |
34
|
|
|
def _pick_response(is_self, is_multiple): |
35
|
|
|
f = [ |
36
|
|
|
[REPOSTS, MULTIPLE_REPOST], |
37
|
|
|
[SELF_REPOSTS, MULTIPLE_SELF_REPOST], |
38
|
|
|
] |
39
|
|
|
return random_response(f[is_self][is_multiple]) |
40
|
|
|
|