Skip to content

Script structure (Python)

Yazaar edited this page May 29, 2019 · 8 revisions

All Python scripts should contain one or a few of the following functions. They are called whenever a specific event occurs. All functions are optional! An example script should be installed on a fresh install.

Jump to specific function:

Execute

Execute(data)

This function occurs for each chat message.

This is what data contains:

{
    "raw": "@badge-info=;badges=broadcaster/1,bits-charity/1;color=#9ACD32;display-name=Yazaar;emotes=64138:18-26;flags=;id=528edb99-9b26-4559-be38-5cdfdadfe931;mod=0;room-id=64242999;subscriber=0;tmi-sent-ts=1558820533444;turbo=0;user-id=64242999;user-type= :yazaar!yazaar@yazaar.tmi.twitch.tv PRIVMSG #yazaar :test message here SeemsGood",
    "badges": {
        "broadcaster": "1",
        "bits-charity": "1"
    },
    "message": "test message here SeemsGood",
    "moderator": true,
    "subscriber": false,
    "turbo": true,
    "name": "Yazaar",
    "room": "64242999",
    "id": "528edb99-9b26-4559-be38-5cdfdadfe931",
    "utc-timestamp": "2019-05-25 21:42:13",
    "emotes": {
        "64138": ["18-26"]
    }
}



Tick

Tick()

This function occurs each time that there are no other functions to handle. Nothing fancy, just a function that runs regularly.

Event

Event(data)

This function occurs each time that an StreamElements or twitch event takes place.

This is what data contains (found here):

{
    channel: Number;
    type: String;
    provider: String;
    providerId: String;
    createdAt: Date;
    flagged: Boolean;
    data: {
        username: String;
        tier: String;
        currency: String;
        amount: Number
        message: String;
        avatar: String;
        sender: String;
        gifted: Boolean;
    }
}



TestEvent

TestEvent(data)

This function occurs each time that you generate a test event from StreamElements.

Toggle

Toggle(state)

This function occurs whenever the user toggles the script on the website.

state is True (enabled) or False (disabled)

CrossTalk

CrossTalk(data)

This function occurs whenever you send data between scripts as well as whenever you send data from HTML/JavaScript to python script! What data contains depends on the user who sends the data.

Clone this wiki locally