Tkd-Alex / Twitch-Channel-Points-Miner-v2

A simple script that will watch a stream for you and earn the channel points.
GNU General Public License v3.0
1.21k stars 671 forks source link

Feature Request: Telegram Bot for Points/Drop Updates #233

Closed ColinShark closed 2 years ago

ColinShark commented 3 years ago

I don't know how easy it would be to implement, but can we have a Telegram Bot Feature? :D

I thought maybe a Class for a Telegram Bot, so we can receive updates on Points, Drops and/or Bets from our own Bot in Telegram. Perhaps a Class to handle everything.

Users could be told in the Readme to create a bot with BotFather and add the Token and their own User ID to the run.py. All api request would need to go to https://api.telegram.org/bot<token>/METHOD_NAME, where Method_Name could just be sendMessage with appropriate information filled in.

As an additional bonus, maybe even commands to restart the points miner? 👀

I know, I've kinda skipped the issue template 🙈


Edit: I've made a (rough) proof-of-concept in WebSocketsPool.on_message:

 message.type == "points-earned":
    earned = message.data["point_gain"]["total_points"]
    reason_code = message.data["point_gain"]["reason_code"]

    token = "123456789:bottokenhere123abc456def789ghi"
    api = f"https://api.telegram.org/bot{token}/sendMessage"
    r = requests.post(
        api,
        data={
            "chat_id": 289579584,
            "text": f"+{earned} → {ws.streamers[streamer_index]} - Reason: {reason_code}."
        }
    )
    if r.raise_for_status():
        # https://docs.python-requests.org/en/master/user/quickstart/#response-status-codes
        pass

    logger.info(
        f"+{earned} → {ws.streamers[streamer_index]} - Reason: {reason_code}.",
        extra={...}
    )

What it could look like:

Proof of Concept

Tkd-Alex commented 3 years ago

I'm really in love with this feature :heart: I've developed in the past many Telegram Bots, and they were my first projects

I'll see what can I do

ColinShark commented 3 years ago

I'll see what can I do

I've already hacked together a method post_telegram() into the utils.py to simply import that lul I could make a fork and push my changes (sans api key) so you can see how it could work ^^

Rakambda commented 3 years ago

@ColinShark Be careful when referencing things from a private repo. We can see the 2 commits that includes your telegram key.

ColinShark commented 3 years ago

@ColinShark Be careful when referencing things from a private repo. We can see the 2 commits that includes your telegram key.

If you read closely, the __TOKEN variable is just ascending numbers and letters. Nothing to worry about ^^

Tkd-Alex commented 3 years ago

I've thought a lot on this issue, we should track all events? Or create a list of event like: track_only=[ STREAMER_ONLINE, STREAMER_OFFLINE, GAIN_FOR_RAID, GAIN_FOR_CLAIM, GAIN_FOR_WATCH, GAIN_FOR_WATCH_STREAK, BET_WIN, BET_LOSE, BET_REFUND], inside TelegramSettings

Something like that?

ColinShark commented 3 years ago

I think choosing which ones to track is a good idea. Probably default to everything so you can just do something like this:

miner = TwitchChannelPointsMiner(
    username="username",
    telegram_settings=TelegramSettings(token="123456:abc123def456")
)

Then you could disable what you don't need/want with something like this? No idea how easy that'd be to implement.

TelegramSettings(
    token="123456:abc123def456",
    streamer_online=True,
    gain_for_raid=False,
    ...
)

As you can see from my fork, I literally just put a POST request to Telegrams API in utils, and track what I get updates on anyway

(Points for watch and claim, drop progress and claim, as well as prediction gains)

Tkd-Alex commented 3 years ago

Are you able to clear the code and submit a PR? I'll work on it, but in this way we will have a commit signed by you - the idea it's yours ;) and we had a contribution by you

ColinShark commented 3 years ago

I can do that, but Imma re-do my fork and branch for that because VSCode commited that as Gitea first 🙄 😅

Tkd-Alex commented 3 years ago

As you wish 😂