Twitch Chat Interface¶
-
class
TwitchChatInterface.
TCI
(settings: dict)¶ Bulids connection, receives chat messages from server and emits corrisponding events!
This library closely follows twitch docs https://dev.twitch.tv/docs/irc
All functions or methods used as event callbacks need to have 2 input varibles
Example of how to use this
import TwitchChatInterface settings = {"server": "irc.chat.twitch.tv", # the server address "port" : 6667, #server port as interger "user" : "mybotsname", # you bots username "password" : "oauth: ", # password as twitch oauth "channels" : ["channel1","channel2"], # replace with any channels yopu want the bot join "caprequest" : "twitch.tv/tags twitch.tv/commands twitch.tv/membership" } # All functions or methods used as event callbacks need to have 2 input varibles # sender: is what triggered event # message: is the message def handleMessage(sender, message): print(f"[{message.channel}] {message.username}: {message.text}") def handleConnect(sender, message): print ("connected!", message) def main(): # setup server instance with settings as dict twitchChat = TwitchChatInterface.TCI(settings) # add function or method for a message event twitchChat.onMessage(handleMessage) # add function or method for a server connected event twitchChat.onConnected(handleConnect) # this starts the server and logins twitchChat.start() # send a messaage to a channel twitchChat.sendMessage("channel1","Hello World!") if __name__ == "__main__": main()
This is the message object that is sent with event 1
class Message: raw: str # the raw unparsed message string from server channel: str # the channel the message is from id: str # id of message prefix: str # there is 3 types of prfixes command: str # the is the command which is also the event name text: str # the context of the message username: str # the person who has sent the message params: List[str] # this is a break down of the end of message tags: Dict # these are twitch tags look
-
join
(channels: list) → None¶ join [summary]
- Parameters
channels (list) – [description]
-
onConnected
(func)¶ onConnected[summary]
- Parameters
func ([type]) – [description]
-
onEmotesOnlyOff
(func)¶ [summary]
- Parameters
func ([type]) – [description]
-
onEmotesOnlyOn
(func)¶ [summary]
- Parameters
func ([type]) – [description]
-
onFollersOnlyOff
(func)¶ [summary]
- Parameters
func ([type]) – [description]
-
onFollersOnlyOn
(func)¶ [summary]
- Parameters
func ([type]) – [description]
-
onGlobalUserState
(func)¶ onGlobalUserState [summary]
- Parameters
func ([type]) – [description]
-
onLoginError
(func)¶ onLoginError [summary]
- Parameters
func ([type]) – [description]
-
onMessage
(func) → None¶ onMessage [summary]
- Parameters
func – [description]
-
onMsgId
(msgid, func)¶ onMsgId [summary]
- Parameters
msgid ([type]) – [description]
func ([type]) – [description]
-
onNotice
(func)¶ onNotice [summary]
- Parameters
func ([type]) – [description]
-
onReceived
(func)¶ onReceived [summary]
- Parameters
func ([type]) – [description]
-
onRoomState
(func)¶ onRoomState [summary]
- Parameters
func ([type]) – [description]
-
onSlowModeOff
(func)¶ [summary]
- Parameters
func ([type]) – [description]
-
onSlowModeOn
(func)¶ [summary]
- Parameters
func ([type]) – [description]
-
onSubsOnlyOff
(func)¶ [summary]
- Parameters
func ([type]) – [description]
-
onSubsOnlyOn
(func)¶ [summary]
- Parameters
func ([type]) – [description]
-
onUserNotice
(func)¶ onUserNotice [summary]
- Parameters
func ([type]) – [description]
-
onUserState
(func)¶ onUserState [summary]
- Parameters
func ([type]) – [description]
-
onWhisper
(func)¶ onWhisper [summary]
- Parameters
func ([type]) – [description]
-
part
(channels: list)¶ [summary]
- Parameters
channels (list) – [description]
-
sendMessage
(channel: str, message: str) → None¶ sendMessage [summary]
- Parameters
channel (str) – [description]
message (str) – [description]
-
sendWhisper
(channel: str, username: str, message: str) → None¶ sendWhisper [summary]
- Parameters
channel (str) – [description]
username (str) – [description]
message (str) – [description]
-
start
() → None¶ TwitchChatInterface.start - connects to server, logins in and starts send and recieve threads
-
timeoutUser
(channel: str, username: str, duration: int) → None¶ timeoutUser [summary]
- Parameters
channel (str) – [description]
username (str) – [description]
duration (int) – [description]
-