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
11
__copyright__ = 'this file is in the public domain'
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
24
plughelp.add('ops', 'op with command or op on join')
27
cfg.define('oponsplit', 0)
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:
34
chan = ievent.channel.lower()
35
if chan in bot.state['no-op']:
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']:
42
bot.doop(chan, ievent.nick)
44
bot.splitted.remove(ievent.nick.lower())
46
callbacks.add('JOIN', opjoincb, threaded=True)
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)
58
userhost = getwho(bot, nick)
60
userhost = ievent.userhost
61
if users.status(userhost, ievent.channel.upper()):
64
ievent.reply("%s doesn't have %s status" % (nick, \
65
ievent.channel.upper()))
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')
72
def handle_splitted(bot, ievent):
73
""" splitted .. show splitted list """
74
ievent.reply(str(bot.splitted))
76
cmnds.add('splitted', handle_splitted, 'OPER')
77
examples.add('splitted', 'show whos on the splitted list', 'splitted')
80
def handle_splittedclear(bot, ievent):
81
""" splitted-clear .. clear splitted list """
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')
89
def handle_opsdisable(bot, ievent):
90
""" disable opping in channel """
92
chan = ievent.args[0].lower()
94
chan = ievent.channel.lower()
95
oplist = bot.state['no-op']
96
if chan not in oplist:
97
bot.state['no-op'].append(chan)
99
ievent.reply('opping in %s disabled' % chan)
100
if chan in bot.state['opchan']:
101
bot.delop(chan, bot.nick)
103
ievent.reply('opping %s is already disabled' % chan)
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')
111
def handle_opsenable(bot, ievent):
112
""" enable opping in channel """
114
chan = ievent.args[0].lower()
116
chan = ievent.channel.lower()
117
oplist = bot.state['no-op']
119
bot.state['no-op'].remove(chan)
121
ievent.reply('opping in %s is enabled' % chan)
123
ievent.reply('opping in %s is already enabled' % chan)
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')
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'])
135
cmnds.add('ops-list', handle_opsnoop, 'OPER')
136
examples.add('ops-list', 'list in which channels opping is disabled', \
138
tests.add('ops-list')
140
def checkmode(bot, ievent):
141
""" check mode string """
145
args = ievent.arguments
146
chan = args[0].lower()
150
rlog(10, 'op', 'unknow mode string format: %s' % str(ievent))
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)
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)
170
bot.state['opchan'].remove(chan)
175
callbacks.add('MODE', checkmode)