<commit_before># gozerlib/plugs/nickserv.py
#
# 

""" authenticate to NickServ. """

__author__ = "Wijnand 'tehmaze' Modderman - http://tehmaze.com"
__license__ ='BSD'

## gozerlib imports

from gozerlib.examples import examples
from gozerlib.callbacks import callbacks
from gozerlib.commands import cmnds
from gozerlib.datadir import datadir
from gozerlib.fleet import fleet
from gozerlib.utils.pdod import Pdod
from gozerlib.config import cfg as config

## basic imports

import os
import time
import logging

## NSAuth class

class NSAuth(Pdod):

    """ nickserve auth. """

    def __init__(self):
        self.registered = False
        Pdod.__init__(self, datadir + os.sep + 'plugs' + os.sep + 'gozerlib.plugs.nickserv' + os.sep + 'nickserv')

    def add(self, bot, **kwargs):
        """ add a nickserv entry. """
        options = {
            'nickserv': 'NickServ',
            'identify': 'IDENTIFY',
        }
        options.update(kwargs)
        assert options.has_key('password'), 'A password must be set'
        for key in options.keys(): Pdod.set(self, bot.name, key, options[key])
        self.save()

    def remove(self, bot):
        """ remove a nickserv entry. """
        if self.has_key(bot.name):
            del self[bot.name]
            self.save()

    def has(self, bot):
        """ check if a bot is in the nickserv list. """
        return self.has_key(bot.name)

    def register(self, bot, passwd):
        """ register a bot to nickserv. """
        if self.has_key(bot.name) and self.has_key2(bot.name, 'nickserv'):
            bot.sendraw('PRIVMSG %s :%s %s' % (self.get(bot.name, 'nickserv'),  'REGISTER', passwd))
            logging.debug('nickserv - register sent on %s' % bot.server)

    def identify(self, bot):
        """ identify a bot to nickserv. """
        if self.has_key(bot.name) and self.has_key2(bot.name, 'nickserv'):
            bot.outnocb(self.get(bot.name, 'nickserv', ), '%s %s' % (self.get(bot.name, 'identify'), self.get(bot.name, 'password')), how="notice")
            logging.warn('nickserv - identify sent on %s' % bot.server)

    def listbots(self):
        """ list all bots know. """
        all = []
        for bot in self.data.keys(): all.append((bot, self.data[bot]['nickserv']))
        return all

    def sendstring(self, bot, txt):
        """ send string to nickserver. """
        nickservnick = self.get(bot.name, 'nickserv')
        bot.outnocb(nickservnick, txt, how="msg")

    def handle_001(self, bot, ievent):
        self.identify(bot)
        try:
            for i in self.data[bot.name]['nickservtxt']:
                self.sendstring(bot, i)<commit_msg>remove notices from nickserv plugin<commit_after># gozerlib/plugs/nickserv.py
#
# 

""" authenticate to NickServ. """

__author__ = "Wijnand 'tehmaze' Modderman - http://tehmaze.com"
__license__ ='BSD'

## gozerlib imports

from gozerlib.examples import examples
from gozerlib.callbacks import callbacks
from gozerlib.commands import cmnds
from gozerlib.datadir import datadir
from gozerlib.fleet import fleet
from gozerlib.utils.pdod import Pdod
from gozerlib.config import cfg as config

## basic imports

import os
import time
import logging

## NSAuth class

class NSAuth(Pdod):

    """ nickserve auth. """

    def __init__(self):
        self.registered = False
        Pdod.__init__(self, datadir + os.sep + 'plugs' + os.sep + 'gozerlib.plugs.nickserv' + os.sep + 'nickserv')

    def add(self, bot, **kwargs):
        """ add a nickserv entry. """
        options = {
            'nickserv': 'NickServ',
            'identify': 'IDENTIFY',
        }
        options.update(kwargs)
        assert options.has_key('password'), 'A password must be set'
        for key in options.keys(): Pdod.set(self, bot.name, key, options[key])
        self.save()

    def remove(self, bot):
        """ remove a nickserv entry. """
        if self.has_key(bot.name):
            del self[bot.name]
            self.save()

    def has(self, bot):
        """ check if a bot is in the nickserv list. """
        return self.has_key(bot.name)

    def register(self, bot, passwd):
        """ register a bot to nickserv. """
        if self.has_key(bot.name) and self.has_key2(bot.name, 'nickserv'):
            bot.sendraw('PRIVMSG %s :%s %s' % (self.get(bot.name, 'nickserv'),  'REGISTER', passwd))
            logging.debug('nickserv - register sent on %s' % bot.server)

    def identify(self, bot):
        """ identify a bot to nickserv. """
        if self.has_key(bot.name) and self.has_key2(bot.name, 'nickserv'):
            bot.outnocb(self.get(bot.name, 'nickserv', ), '%s %s' % (self.get(bot.name, 'identify'), self.get(bot.name, 'password')), how="msg")
            logging.warn('nickserv - identify sent on %s' % bot.server)

    def listbots(self):
        """ list all bots know. """
        all = []
        for bot in self.data.keys(): all.append((bot, self.data[bot]['nickserv']))
        return all

    def sendstring(self, bot, txt):
        """ send string to nickserver. """
        nickservnick = self.get(bot.name, 'nickserv')
        bot.outnocb(nickservnick, txt, how="msg")

    def handle_001(self, bot, ievent):
        self.identify(bot)
        try:
            for i in self.data[bot.name]['nickservtxt']:
                self.sendstring(bot, i)
{'fraction_non_alphanumeric': 0.1422939740942369, 'fraction_numerical': 0.0018772292096865028, 'mean_word_length': 2.6024340770791077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '743010', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1759, 'n_words': 449}