61924

OP command for Phenny

— Frank — ? Comments

I needed something that could make me and others operators in an IRC channel, but there weren't any services running on the IRC server. So I made a simple command for Phenny (IRC bot).

The idea is that the bot is always online and the user is able to "login" and become an operator by sending ".op $channelname userpassword" in a private message to the bot. All the users and password are stored in a file in the Phenny congiguration directory.

It's a pretty simple module at the moment, but it works. If you got suggestions just post them. :)

Configuration

Here's an example of the configuration file:

[Users]
User1=password
RandomUser=p455w0rd
AnotherUser=zxcvbnm

User1, RandomUser and AnotherUser are the users that are allowed to be an operator and on the other side of the = (equal to) sign are the passwords of the users. This file can be saved as oplist.cfg in ~/.phenny.

The code

Save the following code in /path/to/phenny/modules/mode.py. /path/to/phenny/ is the location to the Phenny direcory. I have it in my home directory, ~/phenny.

#!/usr/bin/env python
"""
mode.py - Phenny Mode Module
Copyright 2009, Frank Smit, 61924.nl
Licensed under the Eiffel Forum License 2.

http://inamidst.com/phenny/
"""

import ConfigParser, os

# Load oplist
OPLIST = os.path.expanduser("~/.phenny/oplist.cfg")
config = ConfigParser.SafeConfigParser()
config.read([OPLIST,])

def op(phenny, input):
    # Can only be done in privmsg
    if input.sender.startswith('#'):
        return

    target = input.nick.lower()

    # Check username and password
    if target in config.options('Users'):
        if input.group(2) == config.get('Users', target):
            phenny.write(['MODE', input.group(1), '+o', target])
            phenny.say('You are an OP now.')
        else:
            phenny.say('Your password does not match.')
    else:
        phenny.say('You are not in the OP list.')

op.rule = r'\.op (#?\S+) (.*)'
op.priority = 'low'
op.example = '.op #channel your_password'

Installation

First download, install and run Phenny so it makes a default configuration file and edit it. Then save oplist.cfg (don't forget to add the right users) and mode.py to the correct locations (see the above text) and run Phenny again. It will now connect to the IRC server.

Once the bot is visible in the userlist give it operator status and test the .op command (.op #channel password) with a user that is not an operator. It should work after that.

Share

Comments