def process_queue(self): """ Procesando el queue de salida. """ plaintext = core.obtconfig('plaintext', cache=True) mps = core.obtconfig('mps', cache=True) while self._stop is False: out = buffer_output.get() if out == 0: # Saliendo! D: break # According to the RFC http://tools.ietf.org/html/rfc2812#page-6, # clients should not transmit more than 512 bytes. if len(out['msg']) > 507: out.update({'msg': textwrap.wrap(out['msg'], 507)[0] + '...'}) try: msg = out['msg'] if isinstance(msg, unicode): msg = msg.encode('utf-8') out['socket'].send(msg + '\r\n') except socket.error: # Ouch! out['disconnect']("Connection reset by peer.") else: if plaintext: log.info('SEND TO %s: %s' % (out['servername'], out['msg'])) # Messages per seconds time.sleep(mps) log.warning('¡Se detuvo la salida de datos!')
def addoper(irc, result, group, other): lc = base[irc.base.name][1][other['rpl_whois']['is logged']]['lang'] opers = core.obtconfig('opers') level, name, password = result('level', 'name', 'sha_passwd') if '/' in level: level, server = level.split('/') if level == 'global': server = None else: server = None if server and not server in base: irc.err(other['target'], _('servidor "%s" invalido', lc) % server) return if not level in ('noob', 'local', 'global'): irc.err(other['target'], _('nivel "%s" invalido', lc) % level) return if not len(password) == 64 or not password.isalnum(): irc.err(other['target'], _('la contraseña debe estar en sha256', lc)) return opers.append({ 'passwd': password, 'user': name, 'level': level if not server else (level, server)}) core.upconfig('opers', opers) irc.notice(other['target'], _('operador %s "%s" agregado', lc) % (level, name))
def connect(self): """ Conecta o reconecta a un servidor. """ while 1: if not self._connect(): time.sleep(self.sleep) else: break # Procesando la entrada de datos. if self.connected is False: self.connected = True self.thd_input_code = self.input() # Logeandonos al servidor (si tiene contraseña claro) if self.base.passwd[0]: self.pass_(self.base.passwd[1]) time.sleep(4) # SASL Mechanisms # http://ircv3.net/docs/sasl-mechs.html if self.base.sasl[0]: log.info('Usando SASL...') self.cap('REQ', 'sasl') self.send_raw('AUTHENTICATE PLAIN') self.send_raw('AUTHENTICATE ' + self.base.sasl[1]) self.cap('END') self.user(config.obtconfig('VERSION', cache=True)[0], self.base.user) self.nick(self.base.nick)
def version(self, name, group): if group('message').upper().endswith("\001VERSION\001") and \ group('message').upper().startswith("\001VERSION\001"): vrn = config.obtconfig('VERSION', cache=True) vrn = (vrn[0] + ' ' + '.'.join(str(num) for num in vrn[1:])) self.ctcp_reply(group('nick'), vrn) return True raise UnboundLocalError("it is not the required event")
def deloper(irc, result, group, other): lc = base[irc.base.name][1][other['rpl_whois']['is logged']]['lang'] name = result('name') opers = core.obtconfig('opers') for oper in opers: if oper['user'] == name: opers.remove(oper) break core.upconfig('opers', opers) irc.notice(other['target'], _('operador "%s" eliminado', lc) % name)
def load_connections(): ircbase = core.obtconfig('ircbase') if ircbase is None: return out = output.output() out.start() __output__.append(out) for base in ircbase: servers[base.name] = [client.ServerConnection(base)] servers[base.name].append( katheryn.users(servers[base.name][0], 'usr', {'post': {}})) servers[base.name].append( katheryn.channels(servers[base.name][0], 'chn')) if base.connect_to_beginning: servers[base.name][0].connect()
def input(self): "read and process input from self.socket" plaintext = config.obtconfig('plaintext', cache=True) log.debug('La entrada de datos de %s se ha iniciado.' % self.base.name) while self.connected is True: try: for line in self.socket.recvfrom(4028)[0].splitlines(): # Registrando cada linea if plaintext: log.info('RECV FROM %s: %s' % (self.base.name, line)) try: self._process_line(line) except AttributeError: for err in traceback.format_exc().splitlines(): log.error(err) except socket.error: # The server hung up. self.connected = False break log.warning('¡Se detuvo la entrada de datos de %s!' % self.base.name)
# -*- coding: utf-8 -*- """ UserBot module Copyright 2015, Ismael R. Lugo G. """ from sysb.config import core from sysb import i18n import random import json locale = i18n.turn( 'es', core.obtconfig('package_translate', cache=True), 'games') _ = locale.turn_tr_str lang = core.obtconfig('lang', cache=True) conf = json.load(file('mods/games/conf/{}/eightball.json'.format(lang))) def eightball(irc, result, group, other): category = random.choice(['positive', 'negative', 'unknown']) irc.notice(other['target'], random.choice(conf[category]))
Copyright 2015, Ismael R. Lugo G. """ from irc.request import whois from sysb.config import core from sysb import i18n from irc.connection import servers as base import httplib import socket import urllib import json import re re_ip = re.compile("(?i)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}") locale = i18n.turn("es", core.obtconfig("package_translate", cache=True), "channels") _ = locale.turn_tr_str lang = core.obtconfig("lang", cache=True) def ip(irc, result, group, other): rpl = whois(irc, group("nick")) lc = other["global_lang"] user = None target = other["target"] if rpl["is logged"] and base[irc.base.name][1][rpl["is logged"]]: user = base[irc.base.name][1][rpl["is logged"]] if user: lc = user["lang"]
def help(irc, result, group, other): rpl = whois(irc, group('nick')) lc = other['global_lang'] user = None command = result('command') target = other['target'] if rpl['is logged'] and base[irc.base.name][1][rpl['is logged']]: user = base[irc.base.name][1][rpl['is logged']] if user: lc = user['lang'] vrn = core.obtconfig('VERSION', cache=True) vrn = (vrn[0] + ' ' + '.'.join(str(num) for num in vrn[1:])) irc.notice(target, vrn + ' - ' + _('codigo fuente: ', lc) + 'https://goo.gl/vVSG8i') if command: res = search(command.lower().split()) if len(res) == 1: res = res[0] if len(res) == 0: pass else: mod = res['module'] else: mod = res[1] res = res[0] if res: irc.notice(target, _('ayuda para: ', lc) + command) if isinstance(res['desc'], tuple) or isinstance(res['desc'], list): irc.notice(target, _('descripcion: ', lc)) for line in res['desc']: irc.notice(target, ' ' + _(line, lc, mod=mod, err=False)) else: irc.notice(target, _('descripcion: ', lc) + _(res['desc'], lc, mod=mod, err=False)) if 'alias' in res: irc.notice(target, 'alias: ' + ', '.join(res['alias'])) irc.notice(target, _('sintaxis: ', lc) + res['sintax']) irc.notice(target, _('ejemplo: ', lc) + res['example']) irc.notice(target, _('?: parametro opcional, |: opciones varias', lc)) else: irc.notice(target, _('el comando no existe', lc)) else: post = {} first = [] for dic in cmls.items(): if 'sub' in dic[1]: if not dic[0] in post: post[dic[0]] = [] for sub in dic[1]['sub']: post[dic[0]].append(sub) else: first.append(dic[0]) irc.notice(target, _('prefijo %s, comandos disponibles: ', lc) % other['global_prefix']) msg = textwrap.wrap(', '.join(first), 400) for o in msg: irc.notice(target, o) for pr, sub in post.items(): if pr == 'admin': if user and user['status'] in ('noob', 'local', 'global'): for o in textwrap.wrap(', '.join(sub), 400): irc.notice(target, '%s: %s' % (pr, o)) else: irc.notice(target, 'admin: id') else: for o in textwrap.wrap(', '.join(sub), 400): irc.notice(target, '%s: %s' % (pr, o)) irc.notice(target, _('envie: help <comando> <subcomando>?', lc)) irc.notice(target, _('?: parametro opcional, |: opciones varias', lc))