This file is indexed.

/usr/share/pyshared/gplugs/topic.py is in gozerbot 0.99.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# plugs/topic.py
#
#

__copyright__ = 'this file is in the public domain'
__gendocfirst__ = ['topic-set', ]

from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
from gozerbot.tests import tests

import time

plughelp.add('topic', 'manage the topic of a channel')

def checktopicmode(bot, ievent):
    """ callback for change in channel topic mode """
    chan = ievent.channel
    mode = bot.channels.get(chan, 'mode')
    if mode and 't' in mode:
        if chan not in bot.state['opchan']:
            ievent.reply("i'm not op on %s" % chan)
            return 0
    return 1

def handle_gettopic(bot, ievent):
    """ topic [<channel>] .. get topic """
    try:
        channel = ievent.args[0]
    except IndexError:
        channel = ievent.channel
    result = bot.gettopic(channel)
    if not result:
        ievent.reply("can't get topic data of channel %s" % channel)
    else:
        (what, who, when) = result
        ievent.reply('topic on %s is %s made by %s on %s' % \
(channel, what, who, time.ctime(when)))

cmnds.add('topic', handle_gettopic, 'USER', threaded=True)
examples.add('topic', 'topic [<channel>] .. get topic', '1) topic 2) topic \
#dunkbots')
tests.add('topic')

def handle_topicset(bot, ievent):
    """ topic-set .. set the topic """
    if not bot.jabber and not checktopicmode(bot, ievent):
        return
    if not ievent.rest:
        ievent.missing('<what>')
        return
    bot.settopic(ievent.channel, ievent.rest)

cmnds.add('topic-set', handle_topicset, 'USER', allowqueue=False)
examples.add('topic-set', 'set channel topic', 'topic-set Yooo')
tests.add('topic-set boooo')

def handle_topicadd(bot, ievent):
    """ topic-add <txt> .. add topic item """
    if not bot.jabber and not checktopicmode(bot, ievent):
        return
    if not ievent.rest:
        ievent.missing("<what>")
        return
    result = bot.gettopic(ievent.channel)
    if not result:
        ievent.reply("can't get topic data")
        return
    what = result[0]
    what += " | %s" % ievent.rest
    bot.settopic(ievent.channel, what)

cmnds.add('topic-add', handle_topicadd, 'USER', threaded=True)
examples.add('topic-add', 'topic-add <txt> .. add a topic item', \
'topic-add mekker')
tests.add('topic-add booooo')

def handle_topicdel(bot, ievent):
    """ topic-del <topicnr> .. delete topic item """
    if not bot.jabber and not checktopicmode(bot, ievent):
        return
    try:
        topicnr = int(ievent.args[0])
    except (IndexError, ValueError):
        ievent.reply('i need a integer as argument')
        return
    if topicnr < 1:
        ievent.reply('topic items start at 1')
        return
    result = bot.gettopic(ievent.channel)
    if not result:
        ievent.reply("can't get topic data")
        return
    what = result[0].split(' | ')
    if topicnr > len(what):
        ievent.reply('there are only %s topic items' % len(what))
        return
    del what[topicnr-1]
    newtopic = ' | '.join(what)
    bot.settopic(ievent.channel, newtopic)

cmnds.add('topic-del', handle_topicdel, 'USER', threaded=True)
examples.add('topic-del', 'topic-del <topicnr> .. delete topic item', \
'topic-del 1')
tests.add('topic-del 1')

def handle_topicmove(bot, ievent):
    """ topic-move <nrfrom> <nrto> .. move topic item """
    if not bot.jabber and not checktopicmode(bot, ievent):
        return
    try:
        (topicfrom, topicto) = ievent.args
    except ValueError:
        ievent.missing('<from> <to>')
        return
    try:
        topicfrom = int(topicfrom)
        topicto = int(topicto)
    except ValueError:
        ievent.reply('i need two integers as arguments')
        return
    if topicfrom < 1 or topicto < 1:
        ievent.reply('topic items start at 1')
        return
    topicdata = bot.gettopic(ievent.channel)
    if not topicdata:
        ievent.reply("can't get topic data")
        return
    splitted = topicdata[0].split(' | ')
    if topicfrom > len(splitted) or topicto > len(splitted):
        ievent.reply('max item is %s' % len(splitted))
        return
    tmp = splitted[topicfrom-1]
    del splitted[topicfrom-1]
    splitted.insert(topicto-1, tmp)
    newtopic = ' | '.join(splitted)
    bot.settopic(ievent.channel, newtopic)

cmnds.add('topic-move', handle_topicmove, 'USER', threaded=True)
examples.add('topic-move', 'topic-move <nrfrom> <nrto> .. move topic \
items', 'topic-move 3 1')
tests.add('topic-move 2 1')

def handle_topiclistadd(bot, ievent):
    """ topic-listadd <topicnr> <person> .. add a person to a topic list """
    if not bot.jabber and not checktopicmode(bot, ievent):
        return
    try:
        (topicnr, person) = ievent.args
    except ValueError:
        ievent.missing('<topicnr> <person>')
        return
    try:
        topicnr = int(topicnr)
    except ValueError:
        ievent.reply('i need an integer as topicnr')
        return
    if topicnr < 1:
        ievent.reply('topic items start at 1')
        return
    topicdata = bot.gettopic(ievent.channel)
    if not topicdata:
        ievent.reply("can't get topic data")
        return
    splitted = topicdata[0].split(' | ')
    if topicnr > len(splitted):
        ievent.reply('max item is %s' % len(splitted))
        return
    try:
        topic = splitted[topicnr-1]
    except IndexError:
        ievent.reply('no %s topic found' % str(topicnr))
        return
    if topic.strip().endswith(':'):
        topic += " %s" % person
    else:
        topic += ",%s" % person
    splitted[topicnr-1] = topic
    newtopic = ' | '.join(splitted)
    bot.settopic(ievent.channel, newtopic)

cmnds.add('topic-listadd', handle_topiclistadd, 'USER', threaded=True)
examples.add('topic-listadd', 'topic-listadd <toicnr> <person> .. add user to \
topiclist', 'topic-listadd 1 bart')
tests.add('topic-listadd 1 dunker')

def handle_topiclistdel(bot, ievent):
    """ topic-listdel <topicnr> <person> .. remove person from topic list """
    if not bot.jabber and not checktopicmode(bot, ievent):
        return
    try:
        (topicnr, person) = ievent.args
    except ValueError:
        ievent.missing('<topicnr> <person>')
        return
    try:
        topicnr = int(topicnr)
    except ValueError:
        ievent.reply('i need an integer as topicnr')
        return
    if topicnr < 1:
        ievent.reply('topic items start at 1')
        return
    topicdata = bot.gettopic(ievent.channel)
    if not topicdata:
        ievent.reply("can't get topic data")
        return
    splitted = topicdata[0].split(' | ')
    if topicnr > len(splitted):
        ievent.reply('max item is %s' % len(splitted))
        return
    try:
        topic = splitted[topicnr-1]
    except IndexError:
        ievent.reply('no %s topic found' % str(topicnr))
        return
    if not person in topic:
        ievent.reply('%s is not on the list' % person)
        return
    l = topic.rsplit(':', 1)
    try:
        persons = l[-1].split(',')
        persons = [i.strip() for i in persons]
        persons.remove(person)
    except ValueError:
        ievent.reply('no %s in list' % person)
        return
    except IndexError:
        ievent.reply('i need a : in the topic to work properly')
        return
    splitted[topicnr-1] = "%s: %s" % (l[0], ','.join(persons))
    newtopic = ' | '.join(splitted)
    bot.settopic(ievent.channel, newtopic)

cmnds.add('topic-listdel', handle_topiclistdel, 'USER', threaded=True)
examples.add('topic-listdel', 'topic-listdel <topicnr> <person> .. delete \
 user from topiclist', 'topic-listdel 1 bart')
tests.add('topic-listdel 1 dunker')