Awesome IRC bot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.6 KiB

#!/usr/bin/env python
.. module:: Services
:synopsis: Provides the ability to configure a nickname, password, channel auto-join
.. moduleauthor:: Dave Pedu <>
from pyircbot.modulebase import ModuleBase, hook
from time import sleep
class Services(ModuleBase):
def __init__(self, bot, moduleName):
ModuleBase.__init__(self, bot, moduleName)
self.current_preferred_nick = 0
self.current_nick = None
self.current_channels = []
self.do_ghost = False = ["services"]
def _doConnect(self, msg, cmd):
"""Hook for when the IRC conneciton is opened"""
self.current_preferred_nick = 0["user"]["nick"][self.current_preferred_nick])["user"]["username"], self.config["user"]["hostname"],
def _nickTaken(self, msg, cmd):
"""Hook that responds to 433, meaning our nick is taken"""
if self.config["ident"]["ghost"]:
self.do_ghost = True
self.current_preferred_nick += 1
if self.current_preferred_nick >= len(self.config["user"]["nick"]):
self.log.critical("Ran out of usernames while selecting backup username!")
def _initservices(self, msg, cmd):
"""Hook that sets our initial nickname"""
if self.do_ghost:["ident"]["ghost_to"], self.config["ident"]["ghost_cmd"] %
{"nick": self.config["user"]["nick"][0], "password": self.config["user"]["password"]})
self.current_nick = self.config["user"]["nick"][self.current_preferred_nick]
def _invited(self, msg, cmd):
"""Hook responding to INVITE channel invitations"""
if msg.trailing.lower() in self.config["privatechannels"]["list"]:"Invited to %s, joining" % msg.trailing)
def _do_initservices(self):
"""Identify with nickserv and join startup channels"""
" id to nickserv "
if self.config["ident"]["enable"]:["ident"]["to"], self.config["ident"]["command"] %
{"password": self.config["user"]["password"]})
" join plain channels "
for channel in self.config["channels"]:"Joining %s" % channel)
" request invite for private message channels "
for channel in self.config["privatechannels"]["list"]:"Requesting invite to %s" % channel)["privatechannels"]["to"], self.config["privatechannels"]["command"] %
{"channel": channel})
def _changed_nick(self, msg, cmd):
if msg.prefix.nick == self.current_nick:
self.current_nick = msg.trailing
@hook("JOIN", "PART")
def _joinpart(self, msg, cmd):
channel = msg.args[0] if msg.command == "PART" else msg.trailing
(self.current_channels.append if msg.command == "JOIN" else self.current_channels.remove)(channel)
def nick(self):
return self.current_nick
def channels(self):
return self.current_channels