示例#1
0
文件: feed.py 项目: mikotohe2/deskbot
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)
示例#2
0
文件: app.py 项目: welshypie/ircbot
def irc_handshake(sock, nick, chan):
	# Stage 0: define what we're looking for in the transactions
	ident_trigger = "Checking Ident"
	join_trigger = "MODE"
	# Stage 1: send our ident once the server requests it
	while True:
		msg = receive(sock)
		if ident_trigger in msg:
			user_cmd = irc.user()		# Formulate USER command
			transmit(sock, user_cmd)	# Send USER command
			nick_cmd = irc.nick(nick)	# Formulate NICK command
			transmit(sock, nick_cmd)	# Send NICK command
			break
	# Stage 2: join channel once the server sets our mode
	while True:
		msg = receive(sock)
		# Check if the server has set a mode for us
		if join_trigger in msg:
			join_cmd = irc.join(chan)	# Formulate JOIN command
			transmit(sock, join_cmd)	# Send JOIN command
			break
示例#3
0
def invite (user, channel):
    irc.join(channel)
    irc.msg(channel, "{} invited me here.".format(user))
示例#4
0
 def connect_handler(self, event, args):
     if self.conf.get_value("bot.channel"):
         channel = self.conf.get_value("bot.channel")
         self.bot.send_message(irc.join(channel))
         self.channels[channel] = []
示例#5
0
文件: core.py 项目: tomlawn/IRC-Bot
                pass
            else:
                data = split.irc_data_split(section)
                print data
                logdata(str(data) + "\n")
                irc_type = data[0]
                if irc_type == 'ping':
                    network.send(irc.ping(data[1]))
                elif irc_type == '376':
                    #End of MOTD
                    connecting = False
    except:
        pass

for channel in irc_channels:
    network.send(irc.join(channel))

running = True
while running == True:
    #Listen for data sent to the client from the IRC server, split it up, and then assign it to nice varables.
    try:
        line = network.recv()
        data = split.irc_data_split(line)
        irc_type = data[0].lower()
        irc_data = data[1]
        logdata(str(data) + "\n")
    except:
        pass
    if irc_type == 'ping':
        network.send(irc.ping(data[1]))
    #---
示例#6
0
文件: iot.py 项目: 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)
示例#7
0
def after_connect_join(request):
    channels = request.source_settings.get('channels')
    return irc.join(channels)
示例#8
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)
示例#9
0
def onConnect():
  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)

  irc.onPrivmsg("<<<(.+)", onDisassemble)

  def onExecute(nick, user, host, chan, matches):
      executed, errors = dcpu.execute(matches.group(1))

      if executed:
          irc.privmsg(nick, chan, executed)
      if errors:
          irc.privmsg(nick, chan, errors)

  irc.onPrivmsg(">>([^>].+)", onExecute)

  def onHex(nick, user, host, chan, matches):
      converted = 0
      
      if matches.group(1) == "0b":
          converted = hex(int(matches.group(2), 2))
      else:
          converted = hex(int(matches.group(2)))

      irc.privmsg(nick, chan, converted)

  irc.onPrivmsg(r"^hex\((0b)?(\d+)\)", onHex)

  def onDec(nick, user, host, chan, matches):
      converted = 0
      
      if matches.group(1) == "0b":
          converted = str(int(matches.group(2), 2))
      elif matches.group(1) == "0x":
          converted = str(int(matches.group(2), 16))
      else:
          converted = str(int(matches.group(2)))

      irc.privmsg(nick, chan, converted)

  irc.onPrivmsg(r"^dec\((0b|0x)?([0-9a-fA-F]+)\)", onDec)

  def onBin(nick, user, host, chan, matches):
      converted = 0

      if matches.group(1) == "0x":
          converted = bin(int(matches.group(2), 16))
      else:
          converted = bin(int(matches.group(2), 16))

      irc.privmsg(nick, chan, converted)

  irc.onPrivmsg(r"^bin\((0x)?([0-9a-fA-F]+)\)", onBin)

  def onStinks(nick, user, host, chan, matches):
      messages = ["So do you!!!", "Shut up.", "You smell even worse.", "You really shouldn't be talking."]
      irc.privmsg(nick, chan, choice(messages))

  irc.onPrivmsg(".*" + config.nick + r":?( ?is| you)? stink(ing|s)?.*", onStinks)

  def onReload(nick, user, host, chan, matches):
      if(host == "unaffiliated/thatotherpersony"):
          subprocess.call(["git", "pull", "origin", "master"]);
          irc.privmsg(nick, chan, "Pulled latest changes from GitHub. Attempting to reload.")
          irc.reload()
      elif(host == "unaffiliated/quu"):
          irc.privmsg(nick, chan, "wat. Quu. derp.\nReally?\nInitializing spambot mode. >:D")
      else:
          irc.privmsg(nick, chan, "No. I don't wanna!")

  irc.onMsgToMe(".*reload.*", onReload)

  def onRudeness(nick, user, host, chan, matches):
      irc.privmsg(nick, chan, "Why don't you?")

  irc.onMsgToMe(".*stfu.*", onRudeness)

  def onHello(nick, user, host, chan, matches):
      irc.privmsg(nick, chan, "Howdy!")

  irc.onMsgToMe(".*hello.*", onHello)

  def onSup(nick, user, host, chan, matches):
      irc.privmsg(nick, chan, "I'm fine. How about you?")

  irc.onMsgToMe(".*(how.*you|sup|what.*up).*", onSup)
示例#10
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()
示例#11
0
def notice (user, channel, content):
    if user == "NickServ" and "This nickname is registered" in content:
        irc.identify()
        
        for channel in var.channels:
            irc.join(channel)
示例#12
0
			self.parse(self.read())
	#end run
#end linkFromIRC

# IRC parameters
server = "irc.freenode.net"
port = 6667
nick = "Linker"
channel = "#wwu-dcpp"
IRCSock = socket.socket()
irc.s = IRCSock

def IRCconnect(server, port, nick):
	ident = nick
	host = nick
	realname = nick
	IRCSock.connect((server, port))
	irc.serverMessage("NICK %s" % nick)
	irc.serverMessage("USER %s %s bla :%s" % (ident, host, realname))
	return True
#end connect

#main
if __name__ == "__main__":
	IRCconnect(server, port, nick)
	irc.join(channel)
	server_to_irc = linkToIRC(IRCSock)
	irc_to_server = linkFromIRC(IRCSock)
	server_to_irc.start()
	irc_to_server.start()
#end main
示例#13
0
	def run(self):
		self.IRCconnect(self.server, self.port, self.nick)
		self.UDPSock.connect(self.address)
		irc.join(self.channel)
		while True:
			self.parse(self.read())