Skip to content

Commit 57e5865

Browse files
committed
Add a /tell plugin
1 parent 372b032 commit 57e5865

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

plugins/tell.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from plugin import BasePlugin
2+
import tabs
3+
import common
4+
5+
class Plugin(BasePlugin):
6+
def init(self):
7+
self.add_tab_command(tabs.MucTab, 'tell', self.command_tell,
8+
'/tell <nick> <message>\nTell: will tell <nick> of <message> when he next joins.')
9+
self.add_tab_command(tabs.MucTab, 'untell', self.command_untell,
10+
'/untell <nick>\nUntell: will remove the saved messages from /tell.',
11+
self.completion_untell)
12+
self.add_event_handler('muc_join', self.on_join)
13+
# {tab -> {nick -> [messages]}
14+
self.tabs = {}
15+
16+
def on_join(self, presence, tab):
17+
if not tab in self.tabs:
18+
return
19+
nick = presence['from'].resource
20+
if not nick in self.tabs[tab]:
21+
return
22+
for i in self.tabs[tab][nick]:
23+
tab.command_say("%s: %s" % (nick, i))
24+
del self.tabs[tab][nick]
25+
26+
def command_tell(self, args):
27+
"""/tell <nick> <message>"""
28+
arg = common.shell_split(args)
29+
if len(arg) != 2:
30+
self.core.command_help('tell')
31+
return
32+
nick, msg = arg
33+
tab = self.core.current_tab()
34+
if not tab in self.tabs:
35+
self.tabs[tab] = {}
36+
if not nick in self.tabs[tab]:
37+
self.tabs[tab][nick] = []
38+
self.tabs[tab][nick].append(msg)
39+
self.core.information('Will tell %s' % nick, 'Info')
40+
41+
def command_untell(self, args):
42+
"""/untell <nick>"""
43+
tab = self.core.current_tab()
44+
if not tab in self.tabs:
45+
return
46+
nick = args
47+
if not nick in self.tabs[tab]:
48+
return
49+
del self.tabs[tab][nick]
50+
51+
def completion_untell(self, the_input):
52+
tab = self.core.current_tab()
53+
if not tab in self.tabs:
54+
return the_input.auto_completion([], '')
55+
return the_input.auto_completion(list(self.tabs[tab]), '')
56+

0 commit comments

Comments
 (0)