Exemplo n.º 1
0
	def on_privmsg(self, bot, source, target, message):
		m = re.search('((https?:\/\/|www\.)\S+)', message, re.IGNORECASE)

		if m:
			url = m.group(1)
			self.urls[target] = URL()
			self.urls[target].url = m.group(1)
			self.urls[target].nick = source
			self.urls[target].timestamp = 'test'
			tweetbool = tweet.match_tweet_url(url)
			try:
				title = utility.timeout(get_title, 10, (url,))
				self.urls[target].title = title
				self.save_last_url(target)
				if not tweetbool and target in ['#c++.se', '#d1d', '#lithen', "#d2006","#testchannel"]:
					# don't announce title if we've been asked to be quiet
					spoiler_averted = False
					if target in self.no_spoil_dict:
						ts = self.no_spoil_dict[target]
						del self.no_spoil_dict[target]
						now = datetime.datetime.now()
						diff_secs = (now - ts).total_seconds()
						if diff_secs < 60:
							spoiler_averted = True
					if not spoiler_averted:
						bot.tell(target, self.clean(url, title))
			except utility.TimeoutException:
				pass
Exemplo n.º 2
0
    def on_command(self, bot, source, target, trigger, arguments):
        if source == "buffi":
            return

        meth_name = "trig_" + trigger.lower()

        pairs = []

        for command_class in commands.Command.__subclasses__():
            import __builtin__

            meth = None
            try:
                meth = command_class.instance.__getattribute__(meth_name)
                pairs.append([command_class.instance, meth])
            except:
                pass

        for command in commands.get_commands_by_trigger(trigger):
            pairs.append([command, command.on_trigger])

        for pair in pairs:
            command, method = pair

            if command.can_trigger(source, trigger):
                m = re.search("^(.+)!", source)
                if m:
                    if target == source:
                        target = m.group(1)
                    source = m.group(1)

                try:
                    return utility.timeout(method, 10, (bot, source, target, trigger, arguments))
                except utility.TimeoutException:
                    return "Command '%s' took too long to execute." % trigger
                except:
                    boll = list(traceback.extract_tb(sys.exc_info()[2]))
                    bolliStr = ", ".join(map(lambda x: str(x), boll))
                    bot.tell(
                        "#botnik",
                        "%s triggered an error by typing '%s %s': %s. %s"
                        % (source, trigger, arguments, sys.exc_info(), bolliStr),
                    )

                    error_handler.output_message(str(sys.exc_info()))
                    error_handler.output_message(
                        "Error when executing command '" + trigger + "':" + str(traceback.extract_tb(sys.exc_info()[2]))
                    )

                    return "Oops. Error logged."
            else:
                return "Bwaha. You can't trigger that!"

        if not len(pairs):
            if trigger in favorites.FavoriteCommands.instance.favorites.keys():
                return favorites.FavoriteCommands.instance.trig_fav(
                    bot, source, target, "fav", trigger + " " + arguments
                )
Exemplo n.º 3
0
    def on_command(self, bot, source, target, trigger, arguments):
        if source == "buffi":
            return

        meth_name = 'trig_' + trigger.lower()

        pairs = []

        for command_class in commands.Command.__subclasses__():
            import __builtin__
            meth = None
            try:
                meth = command_class.instance.__getattribute__(meth_name)
                pairs.append([command_class.instance, meth])
            except:
                pass

        for command in commands.get_commands_by_trigger(trigger):
            pairs.append([command, command.on_trigger])

        for pair in pairs:
            command, method = pair

            if command.can_trigger(source, trigger):
                m = re.search('^(.+)!', source)
                if m:
                    if target == source:
                        target = m.group(1)
                    source = m.group(1)

                try:
                    return utility.timeout(
                        method, 10, (bot, source, target, trigger, arguments))
                except utility.TimeoutException:
                    return "Command '%s' took too long to execute." % trigger
                except:
                    boll = list(traceback.extract_tb(sys.exc_info()[2]))
                    bolliStr = ", ".join(map(lambda x: str(x), boll))
                    bot.tell(
                        '#botnik',
                        "%s triggered an error by typing \'%s %s\': %s. %s" %
                        (source, trigger, arguments, sys.exc_info(), bolliStr))

                    print sys.exc_info()
                    print 'Error when executing command \'', trigger, '\':', traceback.extract_tb(
                        sys.exc_info()[2])

                    return "Oops. Error logged."
            else:
                return "Bwaha. You can't trigger that!"

        if not len(pairs):
            if trigger in favorites.FavoriteCommands.instance.favorites.keys():
                return favorites.FavoriteCommands.instance.trig_fav(
                    bot, source, target, 'fav', trigger + ' ' + arguments)
Exemplo n.º 4
0
def bot_loop():
	while connected:
		response = s.recv(1024).decode("utf-8")
		if response == "PING :tmi.twitch.tv\r\n":
			s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
			print("Pong")
		else:
			username = re.search(r"\w+", response).group(0) 
			message = CHAT_MSG.sub("", response)
			print(username + ": " + message)
			# Ban pattern check
			for pat in pattern.BAN_PAT:
				if re.match(pat, message):
					utility.ban(s, username)					
					utility.chat(s,"Tap, tap, tap. Nevermore. " + username + " banned")
					break
			# Time out pattern check
			for pat in pattern.TO_PAT:
				if re.match(pat, message):
					utility.timeout(s, username)
					utility.chat(s,"Caw caw! " + username + " silence! You know what you've done...")
					break
			# Command check
			if re.match(r'^(![A-Z,a-z])\w', message):
				# Check if command exists
				if message.strip() in command_list:
					utility.runCommand(s, message.strip(), command_list[message.strip()])
				else:					
					# New command check
					if re.match(r'^(![A-Z,a-z])\w+\s([A-Z,a-z])', message):
						command = message.split(" ", 1)[0]
						action = message.split(" ", 1)[1]
						utility.newCommand(s, command, action, command_list.keys())
						command_list[command] = action
						print("A new command: " + command + " action: " + action)					
					else:
						utility.chat(s, "Command doesn't exists")

		time.sleep(1 / config.RATE)
Exemplo n.º 5
0
    def on_privmsg(self, bot, source, target, message, network):
        m = re.search('((https?:\/\/|www\.)\S+)', message, re.IGNORECASE)

        if m:
            url = m.group(1)
            self.urls[target] = URL()
            self.urls[target].url = m.group(1)
            self.urls[target].nick = source
            self.urls[target].timestamp = 'test'
            try:
                title = utility.timeout(get_title, 10, (url, ))
                self.urls[target].title = title
                self.save_last_url(target)
                if target in ['#c++.se', '#d1d', '#lithen', "#d2006"]:  #FIXME!
                    bot.tell(network, target, self.clean(url, title))
            except utility.TimeoutException:
                pass
Exemplo n.º 6
0
	def on_privmsg(self, bot, source, target, message, network):
		m = re.search('((https?:\/\/|www\.)\S+)', message, re.IGNORECASE)

		if m:
			url = m.group(1)
			self.urls[target] = URL()
			self.urls[target].url = m.group(1)
			self.urls[target].nick = source
			self.urls[target].timestamp = 'test'
			try:
				title = utility.timeout(get_title, 10, (url,))
				self.urls[target].title = title
				self.save_last_url(target)
				if target in ['#c++.se', '#d1d', '#lithen', "#d2006"]: #FIXME!
					bot.tell(network, target, self.clean(url, title))
			except utility.TimeoutException:
				pass
Exemplo n.º 7
0
	def on_command(self, bot, source, target, trigger, arguments):
		if source == "buffi":
			return

		meth_name = 'trig_' + trigger.lower()

		pairs = []

		for command_class in commands.Command.__subclasses__():
			import __builtin__
			meth = None
			try:
				meth = command_class.instance.__getattribute__(meth_name)
				pairs.append([command_class.instance, meth])
			except:
				pass

		for command in commands.get_commands_by_trigger(trigger):
			pairs.append([command, command.on_trigger])

		for pair in pairs:
			command, method = pair

			if command.can_trigger(source, trigger):
				m = re.search('^(.+)!', source)
				if m:
					if target == source:
						target = m.group(1)
					source = m.group(1)

				try:
					return utility.timeout(method, 10, (bot, source, target, trigger, arguments))
				except utility.TimeoutException:
					return "Command '%s' took too long to execute." % trigger
				except:
					print sys.exc_info()
					print 'Error when executing command \'', trigger, '\':', traceback.extract_tb(sys.exc_info()[2])

					return "Oops. Error logged."
			else:
				return "Bwaha. You can't trigger that!"

		if not len(pairs):
			if trigger in favorites.FavoriteCommands.instance.favorites.keys():
				return favorites.FavoriteCommands.instance.trig_fav(bot, source, target, 'fav', trigger + ' ' + arguments)
Exemplo n.º 8
0
    def on_privmsg(self, bot, source, target, message):
        m = re.search('((https?:\/\/|www\.)\S+)', message, re.IGNORECASE)

        if m:
            url = m.group(1)
            self.urls[target] = URL()
            self.urls[target].url = m.group(1)
            self.urls[target].nick = source
            self.urls[target].timestamp = 'test'
            tweetbool = tweet.match_tweet_url(url)
            try:
                title = utility.timeout(get_title, 10, (url, ))
                self.urls[target].title = title
                self.save_last_url(target)
                if not tweetbool and target in settings.title_channels:
                    bot.tell(target, self.clean(url, title))
            except utility.TimeoutException:
                pass
Exemplo n.º 9
0
	def on_privmsg(self, bot, source, target, message):
		m = re.search('((https?:\/\/|www\.)\S+)', message, re.IGNORECASE)

		if m:
			url = m.group(1)
			self.urls[target] = URL()
			self.urls[target].url = m.group(1)
			self.urls[target].nick = source
			self.urls[target].timestamp = 'test'
			tweetbool = tweet.match_tweet_url(url)
			try:
				title = utility.timeout(get_title, 10, (url,))
				self.urls[target].title = title
				self.save_last_url(target)
				if not tweetbool and target in settings.title_channels:
					bot.tell(target, self.clean(url, title))
			except utility.TimeoutException:
				pass
Exemplo n.º 10
0
	def on_privmsg(self, bot, source, target, message):
		m = re.search('((https?:\/\/|www\.)\S+)', message, re.IGNORECASE)

		if m:
			url = m.group(1)
			self.urls[target] = URL()
			self.urls[target].url = m.group(1)
			self.urls[target].nick = source
			self.urls[target].timestamp = 'test'
			tweetbool = tweet.match_tweet_url(url)
			try:
				title = utility.timeout(get_title, 10, (url,))
				self.urls[target].title = title
				self.save_last_url(target)
				if not tweetbool and target in ['#c++.se', '#d1d', '#lithen', "#d2006", "#d2005a", "#uppetid", "#starkast", "#testchannel"]:
					bot.tell(target, self.clean(url, title))
			except utility.TimeoutException:
				pass
Exemplo n.º 11
0
    def timer_beat(self, bot, now, network):
        if not self.next_beat or self.next_beat < now:
            self.next_beat = now + datetime.timedelta(0, 0, 0, 0, 30)

            save_needed = False

            for t in self.watch_list:
                nick, url, newest = t

                try:
                    response = utility.timeout(utility.read_url, 10, [url])
                    if not response:
                        continue

                    data = response["data"]

                    self.reader.parse(data)

                    articles = self.reader.get_articles()

                    if articles:
                        articles = sorted(
                            filter(lambda x: not newest or x[0] > newest,
                                   articles))

                        if articles:
                            articles.reverse()
                            if not newest or articles[0][0] > newest:
                                t[2] = newest = articles[0][0]
                                save_needed = True

                            bot.tell(
                                network, nick, 'New: ' + ' | '.join(
                                    map(lambda x: "%s - %s" %
                                        (x[1], x[2]), articles[0:3])))
                    #else:
                    #	bot.tell(nick, 'I couldn\'t find any articles there. :-(')
                except utility.TimeoutException:
                    pass
                except:
                    raise

            if save_needed:
                self.save()
Exemplo n.º 12
0
	def on_privmsg(self, bot, source, target, message):
		m = re.search('((https?:\/\/|www\.)\S+)', message, re.IGNORECASE)

		if m:
			url = m.group(1)
			
			url_obj = URL()
			url_obj.url = m.group(1)
			url_obj.nick = source
			url_obj.timestamp = datetime.now()
			
			try:
				url_obj.title = utility.timeout(get_title, 10, (url,))
			except utility.TimeoutException:
				return
			
			# Anti-old filter?
			if target in ['#d1d']:
				duplicates = self.search_url_list(target, [url_obj.url], False)
				
				if len(duplicates) > 0:
					whine_string = utility.extract_nick(source) + ': OOOLD!!! Already posted '
					whine_string += str(len(duplicates)) + ' time'
					
					if len(duplicates) > 1:
						whine_string += 's'
					
					whine_string += ', most recently by ' + utility.extract_nick(duplicates[-1].nick)
					
					if (datetime.now() - duplicates[-1].timestamp).days > 0:
						whine_string += " (although it was a while ago)"
					else:
						whine_string += duplicates[-1].timestamp.strftime(' at %H:%M:%S >:(')
					
					bot.tell(target, whine_string)
			
			# Save URL
			self.last_urls[target] = url_obj
			self.save_last_url(target)
			
			# Auto-title?
			if target in ['#c++.se', '#d1d', '#lithen', "#d2006"]:
				bot.tell(target, self.clean(url_obj.url, url_obj.title))
Exemplo n.º 13
0
Arquivo: rss.py Projeto: dentarg/pynik
	def timer_beat(self, bot, now):
		if not self.next_beat or self.next_beat < now:
			self.next_beat = now + datetime.timedelta(0, 0, 0, 0, 2)

			save_needed = False

			for t in self.watch_list:
				nick, url, newest = t

				try:
					response = utility.timeout(utility.read_url, 10, [url])
					if not response:
						continue

					data = response["data"]

					self.reader.parse(data)

					articles = self.reader.get_articles()

					if articles:
						articles = sorted(filter(lambda x: not newest or x[0] > newest, articles))

						if articles:
							articles.reverse()
							if not newest or articles[0][0] > newest:
								t[2] = newest = articles[0][0]
								save_needed = True

							bot.tell(nick, 'New: ' + ' | '.join(map(lambda x: "%s - %s" % (x[1], x[2]), articles[0:3])))
					#else:
					#	bot.tell(nick, 'I couldn\'t find any articles there. :-(')
				except utility.TimeoutException:
					pass
				except:
					raise

			if save_needed:
				self.save()
Exemplo n.º 14
0
	def on_privmsg(self, bot, source, target, message):
		link = None
		haz_url = re.search('https?:\/\/', message, re.IGNORECASE)

		if haz_url:
			link = BeautifulSoup(bleach.linkify(message), 'html5lib').find('a')

		if link:
			url = link.attrs['href']
			self.urls[target] = URL()
			self.urls[target].url = url
			self.urls[target].nick = source
			self.urls[target].timestamp = 'test'
			tweetbool = tweet.match_tweet_url(url)
			try:
				title = utility.timeout(get_title, 10, (url,))
				self.urls[target].title = title
				self.save_last_url(target)
				if not tweetbool and target in settings.title_channels:
					bot.tell(target, self.clean(url, title))
			except utility.TimeoutException:
				print "TitleReaderPlugin utility.TimeoutException for %s" % (url)
				pass
Exemplo n.º 15
0
	def on_command(self, bot, source, target, trigger, arguments, network):
		meth_name = 'trig_' + trigger.lower()
		pairs = []
		
		for command_class in commands.Command.__subclasses__():
			import __builtin__
			meth = None
			try:
				meth = command_class.instance.__getattribute__(meth_name)
				pairs.append([command_class.instance, meth])
			except:
				pass
				
		for command in commands.get_commands_by_trigger(trigger):
			pairs.append([command, command.on_trigger])

		for pair in pairs:
			command, method = pair

			if command.can_trigger(source, trigger):
				m = re.search('^(.+)!', source)
				if m:
					if target == source:
						target = m.group(1)
					source = m.group(1)

				try:
					# FIXME this is rather ugly, for compatiblity with pynik
					if method.im_func.func_code.co_argcount == 7:
						ret = utility.timeout(method, 10, (bot, source, target, trigger, arguments), {'network': network})
					elif method.im_func.func_code.co_argcount == 6:
						ret = utility.timeout(method, 10, (bot, source, target, trigger, arguments))
					else:
						raise NotImplementedError("Trigger '%s' argument count missmatch, was %s." % (
								trigger, method.im_func.func_code.co_argcount))
					return ret
				except utility.TimeoutException:
					return "Command '%s' took too long to execute." % trigger
				except MemoryError:
					return "Command '%s' used to much memory." % trigger
				except:
					error_handler.output_message("Error triggered by '%s' with command '%s', exinfo: '%s', traceback: '%s'" % (
							source, trigger, sys.exc_info(), traceback.extract_tb(sys.exc_info()[2])))

					try:
						bot.tell(bot.settings.admin_network, bot.settings.admin_channel, 
							 "%s triggered an error by typing '%s %s': %s, tb: %s." % (
								source, trigger, arguments, 
								sys.exc_info(), traceback.extract_tb(sys.exc_info()[2])[::-1]))
					except:
						error_handler.output_message("%s %s Unable to send exception to admin channel, exinfo: '%s', traceback: '%s'" % (
							datetime.datetime.now().strftime("[%H:%M:%S]"), network,
							sys.exc_info(), traceback.extract_tb(sys.exc_info()[2])))

					return "Oops. Error logged."
			else:
				return "Bwaha. You can't trigger that!"

		if not len(pairs):
			if trigger in favorites.FavoriteCommands.instance.favorites.keys():
				return favorites.FavoriteCommands.instance.trig_fav(bot, source, target, 'fav', trigger + ' ' + arguments)