5
""" link <item> to <otheritem> """
7
__copyright__ = 'this file is in the public domain'
9
from gozerbot.commands import cmnds
10
from gozerbot.redispatcher import rebefore
11
from gozerbot.plughelp import plughelp
12
from gozerbot.examples import examples
13
from gozerbot.persist.pdol import Pdol
14
from gozerbot.datadir import datadir
17
plughelp.add('links', 'alias items to other items .. this is only used in \
20
links = Pdol(datadir + os.sep + 'links')
22
def handle_linksadd(bot, ievent):
23
""" links-add <item> = <otheritem> """
25
(item, otheritem) = ievent.groups
27
ievent.missing('<item> = <otheritem>')
29
links.add(item, otheritem)
31
ievent.reply('%s link added' % otheritem)
33
rebefore.add(5, 'links-add (.*?) = (.*)', handle_linksadd, 'USER')
34
examples.add('links-add', 'links-add <from> = <to> .. add a link', \
35
'links-add mekker = miep bla')
37
def handle_linksdel(bot, ievent):
38
""" links-del <item> = <otheritem> """
40
(item, linkto) = ievent.groups
42
ievent.missing('<item> = <link>')
44
itemlist = links[item]
46
ievent.reply('no links available for %s' % item)
48
for i in range(len(itemlist)-1, -1, -1):
49
if itemlist[i] == linkto:
52
ievent.reply('%s deleted' % linkto)
55
rebefore.add(5, 'links-del (.*?) = (.*)', handle_linksdel, ['LINKS', 'OPER'])
56
examples.add('links-del', 'links-del <from> = <to> .. delete a link', \
57
'links-del mekker = miep bla')
59
def handle_linkslist(bot, ievent):
60
""" links-list <item> .. show link of <item> """
62
ievent.missing('<item>')
64
result = links[ievent.rest]
66
ievent.reply("links for %s: " % ievent.rest, result)
68
ievent.reply('no links found for %s' % ievent.rest)
70
cmnds.add('links-list', handle_linkslist, 'USER')
71
examples.add('links-list', 'links-list <item> .. show link of <item>', \