{"id":17929317,"url":"https://github.com/xenova/twitch-chat-irc","last_synced_at":"2025-03-24T04:30:59.084Z","repository":{"id":44735809,"uuid":"282305003","full_name":"xenova/twitch-chat-irc","owner":"xenova","description":"A simple tool used to send and receive Twitch chat messages over IRC with python web sockets.","archived":false,"fork":false,"pushed_at":"2022-01-27T20:42:08.000Z","size":39,"stargazers_count":33,"open_issues_count":1,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-19T02:38:40.423Z","etag":null,"topics":["irc","python","twitch","websockets"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xenova.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-24T19:56:28.000Z","updated_at":"2025-02-21T22:56:00.000Z","dependencies_parsed_at":"2022-09-03T02:50:28.093Z","dependency_job_id":null,"html_url":"https://github.com/xenova/twitch-chat-irc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenova%2Ftwitch-chat-irc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenova%2Ftwitch-chat-irc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenova%2Ftwitch-chat-irc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xenova%2Ftwitch-chat-irc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xenova","download_url":"https://codeload.github.com/xenova/twitch-chat-irc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245210884,"owners_count":20578309,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["irc","python","twitch","websockets"],"created_at":"2024-10-28T21:08:40.053Z","updated_at":"2025-03-24T04:30:58.839Z","avatar_url":"https://github.com/xenova.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twitch Chat IRC\nA simple tool used to send and receive Twitch chat messages over IRC with python web sockets. Receiving does not require authentication, while sending does.\n\n\n\n\n## Setup\n### Requirements:\n* This tool was created in a Python 3 environment.\n* Run `pip install -r requirements.txt` to ensure you have the necessary dependencies.\n\n### Authentication\nIf you intend to send messages, you will require authentication.\n1. Go to https://twitchapps.com/tmi/\n2. Click \"Connect\".\n3. Log in with Twitch.\n4. Copy the generated oath token. Now, there are 2 ways to proceed:\n\t- (Recommended) Create a file called `.env` and save your credentials here as:\n      \u003e NICK=x \u003cbr\u003e PASS=y\n\t  \n\t  replacing `x` and `y` with your username and oauth token respectively.\u003cbr\u003e See `example.env` for an example.\n\n\t- Pass your credentials as function/command line arguments. See below for examples.\n\n\n## Command line:\n### Usage\n```\nusage: twitch_chat_irc.py [-h] [-timeout TIMEOUT]\n                          [-message_timeout MESSAGE_TIMEOUT]\n                          [-buffer_size BUFFER_SIZE]\n                          [-message_limit MESSAGE_LIMIT] [-username USERNAME]\n                          [-oauth OAUTH] [--send] [-output OUTPUT]\n                          channel_name\n\nSend and receive Twitch chat messages over IRC with python web sockets. For\nmore info, go to https://dev.twitch.tv/docs/irc/guide\n\npositional arguments:\n  channel_name          Twitch channel name (username)\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -timeout TIMEOUT, -t TIMEOUT\n                        time in seconds needed to close connection after not\n                        receiving any new data (default: None = no timeout)\n  -message_timeout MESSAGE_TIMEOUT, -mt MESSAGE_TIMEOUT\n                        time in seconds between checks for new data (default:\n                        1 second)\n  -buffer_size BUFFER_SIZE, -b BUFFER_SIZE\n                        buffer size (default: 4096 bytes = 4 KB)\n  -message_limit MESSAGE_LIMIT, -l MESSAGE_LIMIT\n                        maximum amount of messages to get (default: None =\n                        unlimited)\n  -username USERNAME, -u USERNAME\n                        username (default: None)\n  -oauth OAUTH, -password OAUTH, -p OAUTH\n                        oath token (default: None). Get custom one from\n                        https://twitchapps.com/tmi/\n  --send                send mode (default: False)\n  -output OUTPUT, -o OUTPUT\n                        output file (default: None = print to standard output)\n```\n\n### Examples\n#### Receiving messages\n##### 1. Output messages from a livestream to standard output\n```\npython twitch_chat_irc.py \u003cchannel_name\u003e\n```\n\n##### 2. Output messages from a livestream to a file\n```\npython twitch_chat_irc.py \u003cchannel_name\u003e -output \u003cfile_name\u003e\n```\n\nIf the file name ends in `.json`, the array will be written to the file in JSON format. Similarly, if the file name ends in `.csv`, the data will be written in CSV format. \u003cbr\u003e Otherwise, the chat messages will be outputted to the file in the following format:\u003cbr\u003e\n`[\u003ctime\u003e] \u003cauthor\u003e: \u003cmessage\u003e`\n\n##### 3. Set a timeout (close connection if no message has been sent in a certain time)\n```\npython twitch_chat_irc.py \u003cchannel_name\u003e -timeout \u003ctime_in_seconds\u003e -output \u003cfile_name\u003e\n```\n\nThere are other options, such as `message_timeout` and `buffer_size`, but these normally do not need to be changed. See above for a description of all options.\n\n##### 4. Set a maximum number of messages to read (close connection once limit has been reached)\n```\npython twitch_chat_irc.py \u003cchannel_name\u003e -message_limit \u003cnumber_of_messages\u003e -output \u003cfile_name\u003e\n```\n\n\n#### Example outputs\n[JSON Example](examples/example.json):\n```\npython twitch_chat_irc.py \u003cchannel_name\u003e -output example.json\n```\n\n[CSV Example](examples/example.csv):\n```\npython twitch_chat_irc.py \u003cchannel_name\u003e -output example.csv\n```\n\n[Text Example](examples/example.txt):\n```\npython twitch_chat_irc.py \u003cchannel_name\u003e -output example.txt\n```\n\n\n#### Sending messages\nThis will open an interactive session which allows you to send messages to the specified channel.\n##### 1. Send messages to a channel (authentication via .env)\n```\npython twitch_chat_irc.py --send \u003cchannel_name\u003e\n```\n\n##### 2. Send messages to a channel (authentication via arguments)\n```\npython twitch_chat_irc.py --send \u003cchannel_name\u003e -username \u003cusername\u003e -oauth \u003coauth_token\u003e\n```\n\n## Python module\n\n### Importing the module\n\n```python\nimport twitch_chat_irc\n```\n\n### Examples\n#### Starting a connection\nThis allows for both receiving and sending of messages\n##### 1. Start a connection with Twitch chat using credentials in `.env` (if any)\n\n```python\nconnection = twitch_chat_irc.TwitchChatIRC()\n```\n##### 2. Start a connection with Twitch chat using credentials\n\n```python\nconnection = twitch_chat_irc.TwitchChatIRC('username','oauth:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')\n```\n#### Receiving messages\nThe `listen` method returns a list when a `KeyboardInterrupt` is fired, or when a timeout/limit has been reached. The arguments shown below can be used together to form more complex method calls.\n\n##### 1. Get a list of messages from a channel\n```python\nmessages = connection.listen('channel_name')\n```\n\n##### 2. Get a list of messages from a channel, stopping after not getting a message for 30 seconds\n```python\nmessages = connection.listen('channel_name', timeout=30)\n```\n\n##### 3. Get a list of messages from a channel, stopping after getting 100 messages\n```python\nmessages = connection.listen('channel_name', message_limit=100)\n```\n\n##### 4. Write messages from a channel to a file\n```python\nconnection.listen('channel_name', output='file.txt')\n```\n\n##### 5. Set a callback function to be fired each time a message is received\n```python\ndef do_something(message):\n\tprint(message)\n\nconnection.listen('channel_name', on_message=do_something)\n```\n\n#### Sending messages\nThe `send` method allows for messages to be sent to different channels. This method requires valid authentication to be provided, otherwise an exception will be called.\n\n##### 1. Send a message\n```python\nmessage = 'Hello world!'\nconnection.send('channel_name', message)\n```\n\n#### Close connection\nThe `close_connection` method closes the connection with Twitch chat. No futher messages can be received or sent now.\n\n##### 1. Close a connection\n```python\nconnection.close()\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxenova%2Ftwitch-chat-irc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxenova%2Ftwitch-chat-irc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxenova%2Ftwitch-chat-irc/lists"}