~ubuntu-branches/ubuntu/precise/gozerbot/precise

« back to all changes in this revision

Viewing changes to build/lib/gozerplugs/plugs/ops.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2008-06-02 19:26:39 UTC
  • mfrom: (1.1.3 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080602192639-3rn65nx4q1sgd6sy
Tags: 0.8.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

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