Example #1
0
def irc_to_telegram():
    irc_message_data = ''
    irc.connect(sv_address, sv_port, us_pass, us_nick)

    while 1:
        irc_message_data = irc.listen(irc_message_data)
        gen_msg = GENERAL_MSG_REGEX.search(str(irc_message_data))

        if gen_msg:
            msg_user, msg_source, msg_text = gen_msg.group(1), gen_msg.group(2), gen_msg.group(3)

            if msg_source == (f'#{irc_channel}'):
                telegram.send_message(telegram_group_id, f'[{msg_user}]: {msg_text}')
Example #2
0
def makeConnection():
    tries = 0
    while True:
        try:
            log.notice("Connecting to server %s:%i..." % (SERVER, PORT))
            irc.connect(SERVER, PORT)
            break
        except:
            if tries == 12:
                log.critical("Failed to establish a connection, giving up")
                return False
            timeout = pow(2, tries)
            log.notice("Connection failed, trying again in %i seconds" % timeout)
            time.sleep(timeout)
            tries += 1
    log.notice("Success!")
    return True
Example #3
0
def main():  
    print '[+] Loading configuration file "bot.conf"'

    conf = BotConf("bot.conf")
    
    print "[+] Connecting Bot."
    print "[+] Server: %s" % conf.server
    print "[+] Port  : %d" % conf.port

    s = irc.connect(conf.server,conf.port)

    if s == None:
        print "[-] ERROR: Unable to connect to server."
        sys.exit(0)

    if irc.handshake(s,conf.nick,conf.user,conf.name) == False:
        print "[-] ERROR: Unable to perform handshake."
        sys.exit(0)
    
    print "[+] Waiting for connection to get stable..."

    time.sleep(10)

    print "[+] Bot Connected."

    irc.join_channels(s,conf.get_channel_list())

    print "[+] Joined channels in access list."

    print "[+] Deception locked and loaded!"

    try:
        msg = s.recv(512)
        while len(msg) != 0:
            msglist = msg.split('\n')            

            for line in msglist:
                if len(line) == 0: continue

                #print "[*] " + line

                cmd = irc.parse_irc(s,line.strip())                
                if cmd == None: continue

                if cmd.server_cmd:
                    process_server_cmd(s,conf,cmd)
                else:
                    process_user_cmd(s,conf,cmd)

            msg = s.recv(512)
    except:
        pass

    print "[-] ERROR: Lost connection to the server."

    if s != None: s.close()
Example #4
0
def twitchbot():
	irc.connect()

	while 1:
		text = irc.get_text()
		username = text[1:text.find('!')]
		if "PRIVMSG" in text and "callisterbot" in text and "hello" in text:
			irc.sendmsg("Hello " + text[1:text.find('!')])

		url = 'https://www.strawpoll.me/'
		if username == 'nightbot' and text.find(url) != -1:#Strawpoll manager, looks up poll, waits then moves winner to /OBS
			urlstart = text.find(url)
			idstart = urlstart + len(url)
			pollid = text[urlstart:text.find(' ',urlstart)]
			print('Starting Poll for Callisterbot at https://www.strawpoll.me/' + pollid)
			print('waiting for poll to finish')
			for x in range(200,0):
				time.sleep(1)
				print ('countdown:' + str(x))
			url = ('https://strawpoll.me/api/v2/polls/' + pollid)
			r = requests.get(url)
			polljson = json.loads(r.content.decode('utf-8'))
			zpj = zip(polljson['votes'],polljson['options'])
			winner = max(zpj)[1]
			r = open('gamemodetext.txt', 'w')
			r.write(winner)
			print('Wrote: ' + winner + " to callistergaming.com/obs")
		print(text)

		#Runza Temp Tuesday easteregg
		if  "PRIVMSG" in text and "runza" in text and datetime.datetime.now().weekday() == 1:
			url = 'http://api.openweathermap.org/data/2.5/weather?zip=68106,us&appid=' + settings.WEATHER_API
			r = requests.get(url)
			weatherjson = json.loads(r.content.decode('utf-8'))
			temperature = str(int(weatherjson['main']['temp']*9/5 - 459.67))
			irc.sendmsg("Runza TEMP TUESDAYS DEAL IS ACTIVE TODAY! Head into your local Runza and you will pay " + temperature + " cents for a Runza with the purchase of a medium fry and drink! ")

		#Lets twitch users see the password
		if  "PRIVMSG" in text and "-pass" in text:
			with db.getCur() as cur:
				cur.execute("SELECT * FROM PUBGPasswords")
				print("The password is: " + str(cur.fetchone()[0]))
				irc.sendmsg("The password is: " + str(cur.fetchone()[0]))
Example #5
0
def main_loop(cmd):
    # connect to irc channel
    IRC = irc.connect(cmd)

    LOG = plugin(cmd.plugin, os.path.dirname(cmd.path))
    DB_path = os.path.join(os.path.dirname(cmd.path), "db." + cmd.plugin)

    LOG.connect_DB(DB_path)

    irc.loop(IRC, LOG, DB_path, cmd)
Example #6
0
def connect ():
    try:
        irc.connect(irc.server, irc.port)
    except socket_error:
        # If the bot can't connect to the server, we get a socket error.
        print("WARNING: Couldn't connect to {}... (Retrying in 15 seconds.)".format(irc.server))
        
        # Make irc.ircsock an object with recv and send methods.
        irc.ircsock = type("socket", (object,), {
            "recv": lambda *_: "",
            "send": lambda *_: ""
        })()
        
        # Wait for 15 seconds before attempting to reconnect.
        time.sleep(15)
        return
    
    # In case the connection to the server is successful...
    
    irc.display_info()
    irc.init()
    irc.ircsock.settimeout(irc.timeout)
    initial_nick = irc.botnick
    
    # In case the nickname throws errors.
    while tools.nick_check() and len(irc.botnick) < 20:
        # Append _ to botnick and try to reconnect.
        irc.botnick += "_"
        irc.nick(irc.botnick)
            
    # Check one last time for nick errors.
    if tools.nick_check():
        print("ERROR: deskbot tried her best, but couldn't get in with any nicknames.")
        raise SystemExit
    elif irc.botnick != initial_nick:
        print("WARNING: Using nickname: {}".format(irc.botnick))
    
    print("Joining channels: {}".format(" ".join(var.channels)))
    
    for channel in var.channels:
        irc.join(channel)
Example #7
0
def main():
    irc.connect(HOST, PORT)
    irc.send_pass(PASS)
    irc.send_nick(NICK)
    irc.join_channel(CHAN)

    # irc.send_message(CHAN, ".me A WILD BOT JOINED THE CHAT!")
    print("SYS: A WILD BOT JOINED THE CHAT!")

    while True:
        try:
            data = irc.receive()
            data = re.split(r"[~\r\n]+", data)
            # data.pop()

            for line in data:
                line = str.rstrip(line)
                line = str.split(line)

                if len(line) >= 1:
                    if line[0] == "PING":
                        irc.send_pong(line[1])
                    if line[1] == "PRIVMSG":
                        parse_message(line)
            sleep(1 / (20 / 30))

        except socket.error:
            print("Socket died")
            break
        except socket.timeout:
            print("Socket timeout")
            break
        except (KeyboardInterrupt, SystemExit):
            break

    irc.disconnect()

    # irc.send_message(CHAN, ".me A WILD BOT LEFT THE CHAT!")
    print("SYS: A WILD BOT LEFT THE CHAT!")
Example #8
0
import socket

import encrypt
import irc
import router

settings_server = "pi.jpdias.me"
settings_port = 1723
settings_botnick = "bot-" + socket.gethostname()
settings_botpass = "******"
settings_owner = "root"
settings_commandprefix = "!"

ircSession = irc.connect(settings_server, settings_port, settings_botnick,
                         settings_botpass, "#botnet", settings_owner)

while True:
    recvText = ircSession.recv(2048)  # Text read from the server
    recvText = recvText.split("\r\n")[
        0]  # immediately take away the "\r\n" from the end of the string
    print "<-- " + recvText  # Print the text to terminal for debugging
    parseText = recvText.split(" ")

    try:
        if parseText[1] == "PRIVMSG":
            # Handle PRIVMSGs here
            privmsgText = recvText.split(" ", 3)
            messageSender = privmsgText[0].lstrip(":").split("!")[0]
            messageChannel = privmsgText[2]
            messageSent = privmsgText[3].lstrip(":")
            # print "messageSender:", messageSender, "messageChannel:", messageChannel, "messageSent:", messageSent
Example #9
0
File: iot.py Project: adamgreig/iot
import message_queue

import time

username = "******"
password = raw_input("the password, please: ")

def process_message(data):
    if data['username'] == 'wdw':
        twitter.post_tweet(username, password, data['message'])

irc = irc.IRC("IoTbot", "IRC over Twitter python bot")
commands = {}
channels = {}
queue = message_queue.MessageQueue(irc, 2)

irc.register_callback('channel_message', process_message)
irc.connect('irc.freenode.net', 6667)

irc.join('#slicehost')

last_time = time.time()

while True:
    irc.read()
    if time.time() - last_time > 20:
        last_time = time.time()
        twitter.check_twitter('udev_random', password, queue)
        queue.process_message_queue()
    time.sleep(2)
Example #10
0
#!/usr/bin/env python
import irc
import config
import subprocess
import dcpu
import random

irc.connect(config.host, config.port, config.nick, config.password)
irc.join(config.chan)

def onAssemble(nick, user, host, chan, matches):
    print "Assembling"
    print matches.group()
    print matches.group(1)
    binary, errors = dcpu.assemble(matches.group(1))

    if binary:
        irc.privmsg(nick, chan, ', '.join(binary))
    if errors:
        irc.privmsg(nick, chan, errors)

irc.onPrivmsg(">>>(.+)", onAssemble)

def onDisassemble(nick, user, host, chan, matches):
    print "Disassembling"
    print matches.group()
    print matches.group(1)
    code = dcpu.disassemble(matches.group(1))

    if code:
        irc.privmsg(nick, chan, code)
Example #11
0
def main():

    irc.connect(server, chan, nick, passw)
    signal.signal(signal.SIGINT, closing)
    executions()
Example #12
0
import re

import irc
import telegram
from botconfig import sv_address, sv_port, us_pass, us_nick, irc_channel

message_data = ''
GENERAL_MSG_REGEX = re.compile(r':(.*)!.*@.* .* (.*) :(.*)')

irc.connect(sv_address, sv_port, us_pass, us_nick)

while 1:
    message_data = irc.listen(message_data)
    gen_msg = GENERAL_MSG_REGEX.search(str(message_data))

    if gen_msg:
        print("MAIN:")
        print(gen_msg.groups())
        msg_source = gen_msg.group(2)
        msg_text = gen_msg.group(3)

        if msg_source == irc_channel:
            print(msg_text)

# telegram.get_updates()
# telegram.send_message('', '')
Example #13
0
host = "irc.tripsit.me"
port = 6697
bot_nick = "blackjackbot"
password = ""
bot_channel = "##blackjack"
user_tracker = usertracker.UserTracker()
with open("savefile", "r") as savefile:
    user_tracker.load_state(savefile)

delay = .35
antiflood_timer = 0
antiflood_cooldown = 5

while True:
    irc = irc.Irc()
    irc.connect(host, port, True)
    irc.nick(bot_nick)
    irc.user(bot_nick)

    blackjack = None
    timer = 0

    bantracker = ban.BanTracker()

    dd = False

    while True:
        irc.update_message_queue()

        if irc.message_queue == []:
            break
Example #14
0
    def start(self):
        while True:
            events = self.poller.poll(250)
            for event in events:
                for net in self.networks:
                    if net.fileno() == event[0]:
                        net.receive()
            else:
                self.fireEvent("timeTickEvent")

    def fireEvent(self, event, *args):
        for mod in self.modules:
            func = mod.__dict__[event]
            if func:
                func(*args)


if __name__ == "__main__":
    k = Kompiter()

    k.load_modules()

    irc = irc.Irc(k)
    irc.connect("chat.freenode.net", "kompiter", "lala")
    irc.join("#pardus-devel")
    k.networks.append(irc)
    k.poller.register(irc.fileno(), select.POLLIN)

    k.start()
Example #15
0
import sys
import socket
import jabber
import xmlstream
import time
import random
import traceback
import urllib
import os.path
import i18n
import locale
import threading

#Code to connect with IRC
import irc
irc.connect()

revision = '$Revision: 31 $'
version = '1.' + revision.split(" ")[1]
commandchrs = '/)'

from dict4ini import DictIni


def getlocale():
    if len(sys.argv) > 1:
        conf = DictIni(sys.argv[1])
    else:
        conf = DictIni("confbot.ini")
    try:
        loc = conf.general['language']
Example #16
0
import util
import structures
import config_loader

# Load IRC parameters from a file
irc_params = config_loader.load()

# Check our command line arguments for debug level, default to 0 (don't print)
if len(sys.argv) > 1:
	if sys.argv[1].isdigit() == True:
		debug = int(sys.argv[1])
		print("Debug level: " + str(debug))
else:
	debug = 0

# initialize IRC client
irc = irc.IRC(irc_params, debug)

# do some setup with the utility module
irc.util.auto_join(irc_params.channels)
irc.util.set_connect_command(irc_params.connect_command)
irc.util.set_password(irc_params.password)
irc.util.set_version(irc_params.version)

# connect to the IRC server
irc.connect()

while 1:
	irc.dispatch_message()
	time.sleep(1)
				
Example #17
0
import socket

import encrypt
import irc
import router

settings_server = "jpdias.noip.me"
settings_port = 1723
settings_botnick = "bot-" + socket.gethostname()
settings_botpass = "******"
settings_owner = "root"
settings_commandprefix = "!"


ircSession = irc.connect(settings_server, settings_port, settings_botnick, settings_botpass, "#botnet", settings_owner)

while True:
    recvText = ircSession.recv(2048)  # Text read from the server
    recvText = recvText.split("\r\n")[0]  # immediately take away the "\r\n" from the end of the string
    print "<-- " + recvText  # Print the text to terminal for debugging
    parseText = recvText.split(" ")

    try:
        if parseText[1] == "PRIVMSG":
            # Handle PRIVMSGs here
            privmsgText = recvText.split(" ", 3)
            messageSender = privmsgText[0].lstrip(":").split("!")[0]
            messageChannel = privmsgText[2]
            messageSent = privmsgText[3].lstrip(":")
            # print "messageSender:", messageSender, "messageChannel:", messageChannel, "messageSent:", messageSent
            if not messageSender.startswith( 'bot' ):