Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

IRC hook logic

John Iannandrea edited this page Mar 3, 2016 · 2 revisions

Pybot irc object

The irc object receives the twitch chat information via sockets and api calls. Any time a message is received the irc object sends it through each filter then through each hook so all features can view it.

Irc flow chart

flow

Example use

The hook gets sent 3 paramaters: The irc object itself, the raw message coming in, and the type of "event" it is

from pybotextra import *

class myFeature:
	def __init__(self, con):
		self.someList = []
		
		# add your features hook to the irc object
		con.addHook(self.hook)
	
	# because you added this member function to the list of hooks 
	# it gets called any time someone sends a message in chat
	def hook(self, con, msg, event):
		 if event == "user_privmsg":
            name = msg.replace(':', '').split('!')[0].replace('\n\r', '')
            text = msg.split("PRIVMSG")[1].replace('%s :' % con.channel, '')
			
			# when someone says !addmytext
            if checkIfCommand(text, "!addmytext"):
				self.someList.append(text)
				
			# when someone says !addmytext print
			if checkIfCommand(text, "!addmytext", "print"):
				self.someList.append(text)
				
				# print all saved messaged because why not
				for msg in someList:
					con.msg(msg)
Clone this wiki locally