tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.55k stars 214 forks source link

How can i change !game and !title #307

Closed selimyalinkilic closed 6 years ago

selimyalinkilic commented 6 years ago

Hi,

I'm using tmi js and making my own bot for my channel. I was looking at events and commands. I just want to change stream title and stream game names. But i couldn't see anything. Can you please help me.

And one more things. Can i add shortcut to !game. For example: When i write !game pubg, then set the game playerunknown's battlegrounds. Something like that.

Thanks.

Actual behaviour:

Expected behaviour:

Error log:

Insert your error log here

Server configuration

AlcaDesign commented 6 years ago

You may be better off asking at the official Twitch third-party forum as this isn't an issue with tmi.js. You can also find all of the information you want by looking at the official Twitch docs.

The "Update Channel" endpoint will let you update a channel's title and game. Requires the channel_editor scope.

You could keep a list of "shortcut" names like this:

const gameAliases = [
        {
            name: 'PLAYERUNKNOWN\'S BATTLEGROUNDS',
            aliases: [
                'playerunknowns battlegrounds',
                'pubg'
            ]
        }, {
            name: 'Fortnite',
            aliases: [
                'fn',
                'fort'
            ]
        }, {
            name: 'Call of Duty: Black Ops 4',
            aliases: [
                'bo4',
                'black ops 4',
                'blackops 4',
                'call of duty black ops 4'
            ]
        }
    ];

function findGameName(input_) {
    let input = input_.toLowerCase();
    let game = gameAliases.find(n =>
            input === n.name.toLowerCase() || n.aliases.find(a => a === input)
        );
    return game ? game.name : input_;
}

All "aliases" values should be lower cased already. Could also use a fuzzy string matching package in this case. Usage:

findGameName('fortnite'); // Fortnite
findGameName('fn'); // Fortnite
findGameName('playerunknown\'s battlegrounds'); // PLAYERUNKNOWN'S BATTLEGROUNDS
findGameName('pubg'); // PLAYERUNKNOWN'S BATTLEGROUNDS

You could also use the "Search Games" endpoint.