示例#1
0
文件: ircbot.py 项目: UrLab/lechbot
    def _connect(self, host, port, **kwargs):
        self.last_say = time()

        self.conn = irc.connect(host, port, use_ssl=True)
        sleep(4)

        @self.conn.on("nickserv-auth-success")
        def auth_success(message_text):
            self.log.info("Auth success (%s)", message_text)

        @self.conn.on("nickserv-auth-fail")
        def auth_fail(message_text):
            self.log.info("Auth failed (%s)", message_text)

        if hasattr(config, "IRC_PASSWORD") and config.IRC_PASSWORD:
            @self.conn.on("sasl-auth-complete")
            def sasl_auth_complete(message):
                self.log.info("Logged with SASL (%s)", message)

            self.log.info("Logging with SASL and username {}".format(self.nickname))
            sasl.auth(self.conn, self.nickname, config.IRC_PASSWORD)
            self.conn = self.conn.register(self.nickname, "ident", "LechBot", config.IRC_PASSWORD)
        else:
            self.conn = self.conn.register(self.nickname, "ident", "LechBot")

        self.conn = self.conn.join(self.chanlist)
        self.conn.queue_timer = self.TIMER
        self.conn.on('message')(self._on_irc_message)
        self.conn.on('join')(self._on_irc_join)
        self.log.info("Connected to {}".format(host))
示例#2
0
def main():
    logging.basicConfig(level=logging.DEBUG)
    global cache
    if os.path.isfile(cache_fname):
        with open(cache_fname, 'rb') as fd:
            cache = pickle.load(fd)
    bot = irc.connect(HOST, PORT, use_ssl=USE_SSL)
    bot.register(NICKNAME, "antissh", "antissh proxy checking bot", password=SERVER_PASSWORD)

    @bot.on('irc-001')
    def handle_connection_start(message):
        bot.writeln("OPER {}\r\n".format(OPER))
        if MODES:
            bot.writeln("MODE {0} {1}\r\n".format(NICKNAME, MODES))
        log_chan(bot, 'antissh has started!')

    @bot.on('notice')
    def handle_connection_notice(message, user, target, text):
        if 'connecting' not in text:
            return

        match = IP_REGEX.search(text)
        if match:
            ip = match.group(1)

            if ip in ('0', '255.255.255.255', '127.0.0.1', '::1'):
                return

            asyncio.ensure_future(check_connecting_client(bot, ip))

    asyncio.get_event_loop().run_forever()
示例#3
0
def main():
    logging.basicConfig(level=logging.DEBUG)
    bot = irc.connect(HOST, PORT, use_ssl=USE_SSL)
    bot.register(NICKNAME, "antissh", "antissh proxy checking bot")

    @bot.on('irc-001')
    def handle_connection_start(message):
        bot.writeln("OPER {}\r\n".format(OPER))
        bot.writeln("JOIN {}\r\n".format(LOGCHAN))
        if MODES:
            bot.writeln("MODE {0} {1}\r\n".format(NICKNAME, MODES))

    @bot.on('notice')
    def handle_connection_notice(message, user, target, text):
        if 'connecting' not in text:
            return

        match = IP_REGEX.search(text)
        if match:
            ip = match.group(1)

            if ip in ('0', '255.255.255.255', '127.0.0.1', '::1'):
                return

            asyncio.ensure_future(check_connecting_client(bot, ip))

    asyncio.get_event_loop().run_forever()
示例#4
0
文件: bot.py 项目: bibor/v4runa
 def __new__(cls, *args, **kwargs):
     if not cls.bot:
         password = None
         if 'PASSWORD' in dir(config):
             password = config.PASSWORD
         cls.bot = irc.connect("chat.freenode.net", 6667, use_ssl=False)\
             .register(config.NICKNAME, config.NICKNAME, '{} (bot)'.format(config.NICKNAME), password=password)\
             .join(config.CHANNELS)
     return cls.bot
示例#5
0
文件: ircbot.py 项目: t00n/lechbot
 def _connect(self, host, port, **kwargs):
     self.last_say = time()
     self.conn = irc.connect(host, port, use_ssl=True)\
                    .register(self.nickname, "ident", "LechBot")\
                    .join(self.chanlist)
     self.conn.queue_timer = self.TIMER
     self.conn.on('message')(self._on_irc_message)
     self.conn.on('join')(self._on_irc_join)
     self.log.info("Connected to {}".format(host))
示例#6
0
def main():
    """CLI entry point for antissh."""
    logging.basicConfig(level=logging.DEBUG)
    if os.path.isfile(cache_fname):
        with open(cache_fname, 'rb') as fd:
            cache.update(pickle.load(fd))
    bot = irc.connect(HOST, PORT, use_ssl=USE_SSL)
    bot.register(NICKNAME,
                 "antissh",
                 "antissh proxy checking bot",
                 password=SERVER_PASSWORD)

    @bot.on('irc-001')
    def handle_connection_start(_):
        bot.writeln("OPER {}\r\n".format(OPER))
        if MODES:
            bot.writeln("MODE {0} {1}\r\n".format(NICKNAME, MODES))
        if LOG_CHAN:
            bot.writeln("JOIN {0} {1}\r\n".format(LOG_CHAN, LOG_CHAN_KEY))
        log_chan(bot, 'antissh has started!')

    @bot.on('notice')
    def handle_connection_notice(message, user, target, text):
        if 'connecting' not in text:
            return

        match = IP_REGEX.search(text)
        if match:
            ip = match.group(1)

            if ip in ('0', '255.255.255.255', '127.0.0.1', '::1'):
                return

            cc = get_country_code(ip)
            if cc and cc in GEOIP_COUNTRY_WHITELIST:
                print("{ip} is whitelisted based on country {cc}".format(
                    ip=ip, cc=cc))
                return

            asyncio.ensure_future(check_connecting_client(bot, ip))

    asyncio.get_event_loop().run_forever()
示例#7
0
文件: bot.py 项目: jwoglom/bot-regime
from asyncirc import irc
import asyncirc.plugins.addressed

import config
import hashlib
import logging
import string
import random
logger = logging.getLogger("czarbot")
logging.basicConfig(level=logging.INFO)

bot = irc.connect(config.host)
nickname = config.prefix + str(random.randint(10**6, 10**7 - 1))
print("My nickname is:", nickname)
bot.register(nickname, "regime", "bot regime")


@bot.on("irc-001")
def join_stuff(message):
    logger.info("autojoining channels")
    bot.join(config.channels)


def generate_challenge(nick):
    challenge = "".join(
        [random.choice(string.ascii_lowercase) for i in range(40)])
    response = hashlib.sha1("{}{}{}".format(challenge, config.key,
                                            nick).encode()).hexdigest()
    return challenge, response

示例#8
0
from asyncirc import irc
import asyncirc.plugins.sasl
import asyncio, configparser, time, sys

config = configparser.ConfigParser(interpolation=None)
config.read('config.ini')

network = config["DEFAULT"]["network"]
server = config[network]["server"]
port = config[network]["port"]
nick = config[network]['nick']
password = config[network]['password']


conn = irc.connect(server, port, use_ssl=True)
conn.register(nick, nick, nick)
asyncirc.plugins.sasl.auth(bot_nick, bot_password)

nicks_to_renew = []
nick_to_try = ""

@conn.on("irc-001")
def query_for_nicks(message):
    print("Querying NickServ for list of nicks")
    conn.say("NickServ", "info")

@conn.on("private-notice")
def extract_nicks(message, user, target, text):
    if message.source != "NickServ!NickServ@services.":
        print("Notice from user {}: {}".format(user.user, text))
        return
示例#9
0
from asyncirc import irc
import blinker
import config

connected_signals = []
def connect_signal(signal_name, func):
    connected_signals.append((signal_name, func))
    blinker.signal(signal_name).connect(func)

def clear_signals():
    while connected_signals:
        k = connected_signals.pop()
        blinker.signal(k[0]).disconnect(k[1])

bot = irc.connect("chat.freenode.net")
bot.register(config.nickname, config.ident, config.realname)
示例#10
0

def git():
    cached = os.stat(__file__).st_mtime
    while True:
        os.system("git pull")
        stamp = os.stat(__file__).st_mtime
        if stamp != cached:
            cached = stamp
            print("Restarting")
            os._exit(0)
        time.sleep(300)


asyncirc.plugins.addressed.register_command_character("!")
bot = irc.connect("irc.euirc.net", 6667, use_ssl=False)
bot.register("RT-Quizzer", "RT-Quizzer", "RT-Quizzer",
             password="******").join([Quizbot.channel, "#radio-thirty"])


@bot.on("irc-001")
def connected(par=None):
    global quiz
    quiz = Quizbot(bot)
    threading.Thread(target=git, args=(), daemon=True).start()
    bot.writeln(f"MODE {bot.nick} +B")


@bot.on("addressed")
def on_addressed(message, user, target, text):
    global quiz
示例#11
0
from asyncirc import irc
import asyncirc.plugins.sasl
import asyncio, configparser, time, sys

config = configparser.ConfigParser(interpolation=None)
config.read('config.ini')

network = config["DEFAULT"]["network"]
server = config[network]["server"]
port = config[network]["port"]
nick = config[network]['nick']
password = config[network]['password']

conn = irc.connect(server, port, use_ssl=True)
conn.register(nick, nick, nick)
asyncirc.plugins.sasl.auth(bot_nick, bot_password)

nicks_to_renew = []
nick_to_try = ""


@conn.on("irc-001")
def query_for_nicks(message):
    print("Querying NickServ for list of nicks")
    conn.say("NickServ", "info")


@conn.on("private-notice")
def extract_nicks(message, user, target, text):
    if message.source != "NickServ!NickServ@services.":
        print("Notice from user {}: {}".format(user.user, text))
示例#12
0
CC_CHANNEL = config['CONTROL']['Channel']  # C&C Channel name.
CC_OWNER = config['CONTROL']['Owner']  # Accept commands only from this User.
# ////////END OF C&C CONFIG ////////

# **** Target Configuration ****
TRGT_HOST = config['TARGET']['Host']  # IP or HOSTNAME of Target Server.
TRGT_PORT = int(config['TARGET']['Port'])  # Target server port.
TRGT_CHAN = config['TARGET']['Channel']  # List of Channels to join on target.
TRGT_NICK = config['TARGET']['Nick']  # Nickname of bot in Target server.
# ////////END OF TARGET CONFIG ////////

# DO NOT MODIFY BELOW THIS!

WHOIS_B = None
IsRealUser = False
bot = irc.connect(CC_HOST, CC_PORT, use_ssl=False)
bot.register(CC_NICK, CC_NICK, CC_NICK)

stalker = irc.connect(TRGT_HOST, TRGT_PORT, use_ssl=False)
stalker.register(TRGT_NICK, TRGT_NICK, TRGT_NICK)

print("C&C SERVER: " + CC_HOST + ":" + str(CC_PORT))
print("C&C CHANNEL: " + CC_CHANNEL)
print("ACCEPTING COMMNDS FROM: " + CC_OWNER)


class User:
    """Class for storing results of WHOIS."""
    def __init__(self):
        """Class Variables."""
        self.Name = ""
示例#13
0
import itertools
import asyncio
from asyncirc import irc
from blinker import signal
import asyncirc.plugins.sasl

from redditbot import config

if hasattr(irc.asyncio, 'async') and hasattr(asyncio, 'ensure_future'):
    # remove deprecation warnings
    irc.asyncio.async = asyncio.ensure_future

conn = irc.connect(config['server'], 6697, use_ssl=True)
conn.register(config['botnick'], config['botnick'], config['botnick'])
if config.get('sasl', False) is True:
    asyncirc.plugins.sasl.auth(conn, config['username'], config['password'])
command_character_registry = []


def register_command_character(c):
    command_character_registry.append(c)


def handle_send_messages(channel, message):
    conn.say(
        channel, '{0} https://redd.it/{1}'.format(str(message), message.id)
    )

signal("send-message").connect(handle_send_messages)
signal("plugin-registered").send("asyncirc.plugins.custom")