~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to build/lib/gplugs/ops.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Malcolm
  • Date: 2012-04-03 21:58:28 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120403215828-6mik0tzug5na93la
Tags: 0.99.1-2
* Removes logfiles on purge (Closes: #668767)
* Reverted location of installed files back to /usr/lib/gozerbot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# plugs/op.py
 
2
#
 
3
#
 
4
 
 
5
""" for op to work for a user the user must have the channel name in his/hers
 
6
 status .. use !user-addstatus <username> #channel
 
7
 normally the bot doesnt op nicks that join after a split to prevent floods, 
 
8
 this can be disabled by using ops-cfg oponsplit 1
 
9
"""
 
10
 
 
11
__copyright__ = 'this file is in the public domain'
 
12
 
 
13
from gozerbot.generic import getwho, rlog
 
14
from gozerbot.commands import cmnds
 
15
from gozerbot.examples import examples
 
16
from gozerbot.callbacks import callbacks
 
17
from gozerbot.users import users
 
18
from gozerbot.plughelp import plughelp
 
19
from gozerbot.persist.persistconfig import PersistConfig
 
20
from gozerbot.tests import tests
 
21
 
 
22
import time
 
23
 
 
24
plughelp.add('ops', 'op with command or op on join')
 
25
 
 
26
cfg = PersistConfig()
 
27
cfg.define('oponsplit', 0)
 
28
 
 
29
def opjoincb(bot, ievent):
 
30
    """ see if we should op a user on join """
 
31
    # don't try to op the bot
 
32
    if ievent.nick == bot.nick:
 
33
        return
 
34
    chan = ievent.channel.lower()
 
35
    if chan in bot.state['no-op']:
 
36
        return
 
37
    time.sleep(1)
 
38
    if cfg.get('oponsplit') or ievent.nick.lower() not in bot.splitted:
 
39
        if users.status(ievent.userhost, ievent.channel.upper()):
 
40
            if chan not in bot.state['opchan']:
 
41
                return
 
42
            bot.doop(chan, ievent.nick)
 
43
    else:
 
44
        bot.splitted.remove(ievent.nick.lower())
 
45
 
 
46
callbacks.add('JOIN', opjoincb, threaded=True)
 
47
 
 
48
def handle_op1(bot, ievent):
 
49
    """ op [<nick>] .. op an user """
 
50
    chan = ievent.channel.lower()
 
51
    if chan in bot.state['no-op']:
 
52
        ievent.reply('opping is disabled in %s' % ievent.channel)
 
53
        return
 
54
    try:
 
55
        nick = ievent.args[0]
 
56
    except IndexError:
 
57
        nick = ievent.nick
 
58
    userhost = getwho(bot, nick)
 
59
    if not userhost:
 
60
        userhost = ievent.userhost
 
61
    if users.status(userhost, ievent.channel.upper()):
 
62
        bot.doop(chan, nick)
 
63
    else:
 
64
        ievent.reply("%s doesn't have %s status" % (nick, \
 
65
ievent.channel.upper()))
 
66
 
 
67
cmnds.add('op', handle_op1, 'USER', threaded=True, speed=9)
 
68
examples.add('op', 'op [<nick>] .. give ops to <nick> or op the person \
 
69
giving the command', '1) op 2) op dunker')
 
70
tests.add('op').add('op exec')
 
71
 
 
72
def handle_splitted(bot, ievent):
 
73
    """ splitted .. show splitted list """
 
74
    ievent.reply(str(bot.splitted))
 
75
 
 
76
cmnds.add('splitted', handle_splitted, 'OPER')
 
77
examples.add('splitted', 'show whos on the splitted list', 'splitted')
 
78
tests.add('splitted')
 
79
 
 
80
def handle_splittedclear(bot, ievent):
 
81
    """ splitted-clear .. clear splitted list """
 
82
    bot.splitted = []
 
83
    ievent.reply('done')
 
84
 
 
85
cmnds.add('splitted-clear', handle_splittedclear, 'OPER')
 
86
examples.add('splitted-clear', 'clear the splitted list', 'splitted-clear')
 
87
tests.add('splitted-clear', 'done')
 
88
 
 
89
def handle_opsdisable(bot, ievent):
 
90
    """ disable opping in channel """
 
91
    try:
 
92
        chan = ievent.args[0].lower()
 
93
    except:
 
94
        chan = ievent.channel.lower()
 
95
    oplist = bot.state['no-op']
 
96
    if chan not in oplist:
 
97
        bot.state['no-op'].append(chan)
 
98
        bot.state.save()
 
99
        ievent.reply('opping in %s disabled' % chan)
 
100
        if chan in bot.state['opchan']:
 
101
            bot.delop(chan, bot.nick)
 
102
    else:
 
103
        ievent.reply('opping %s is already disabled' % chan)
 
104
 
 
105
cmnds.add('ops-disable', handle_opsdisable, 'OPER')
 
106
examples.add('ops-disable', 'ops-disable [<channel>] .. disable opping in \
 
107
provided channel or the channel command was given in', '1) ops-disable 2) \
 
108
ops-disable #dunkbots')
 
109
tests.add('ops-disable').add('ops-disable #dunkbots')
 
110
 
 
111
def handle_opsenable(bot, ievent):
 
112
    """ enable opping in channel """
 
113
    try:
 
114
        chan = ievent.args[0].lower()
 
115
    except:
 
116
        chan = ievent.channel.lower()
 
117
    oplist = bot.state['no-op']
 
118
    if chan in oplist:
 
119
        bot.state['no-op'].remove(chan)
 
120
        bot.state.save()
 
121
        ievent.reply('opping in %s is enabled' % chan)
 
122
    else:
 
123
        ievent.reply('opping in %s is already enabled' % chan)
 
124
 
 
125
cmnds.add('ops-enable', handle_opsenable, 'OPER')
 
126
examples.add('ops-enable', 'ops-enable [<channel>] .. enable opping in \
 
127
provided channel or the channel command was given in', '1) ops-enable 2) \
 
128
ops-enable #dunkbots')
 
129
tests.add('ops-enable').add('ops-enable #dunkbots')
 
130
 
 
131
def handle_opsnoop(bot, ievent):
 
132
    """ show in which channels opping is disabled """
 
133
    ievent.reply('opping is disabled in %s' % bot.state['no-op'])
 
134
    
 
135
cmnds.add('ops-list', handle_opsnoop, 'OPER')
 
136
examples.add('ops-list', 'list in which channels opping is disabled', \
 
137
'ops-list')
 
138
tests.add('ops-list')
 
139
 
 
140
def checkmode(bot, ievent):
 
141
    """ check mode string """
 
142
    plus = 0
 
143
    teller = 0
 
144
    try:
 
145
        args = ievent.arguments
 
146
        chan = args[0].lower()
 
147
        modestr = args[1]
 
148
        who = args[2:]
 
149
    except:
 
150
        rlog(10, 'op', 'unknow mode string format: %s' % str(ievent))
 
151
        return
 
152
    for i in modestr:
 
153
        if i == '+':
 
154
            plus = 1
 
155
            continue
 
156
        if i == '-':
 
157
            plus = 0
 
158
            continue
 
159
        if i == 'o' and plus:
 
160
            if who[teller].lower() == bot.nick.lower():
 
161
                if ievent.channel in bot.state['no-op']:
 
162
                    bot.delop(ievent.channel.lower(), bot.nick)
 
163
                else:
 
164
                    rlog(1, 'irc', 'opped on %s' % chan)
 
165
                    bot.state['opchan'].append(chan)
 
166
        if i == 'o' and not plus:
 
167
            if who[teller].lower() == bot.nick.lower():
 
168
                rlog(1, 'irc', 'deopped on %s' % chan)
 
169
                try:
 
170
                    bot.state['opchan'].remove(chan)
 
171
                except ValueError:
 
172
                    pass
 
173
        teller += 1
 
174
 
 
175
callbacks.add('MODE', checkmode)