Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ColinShark opened this issue Jul 18, 2021 · 9 comments · Fixed by #254
Closed

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

ColinShark opened this issue Jul 18, 2021 · 9 comments · Fixed by #254
Labels
enhancement New feature or request

Comments

@ColinShark
Copy link
Contributor

ColinShark commented Jul 18, 2021

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

@ColinShark ColinShark added the enhancement New feature or request label Jul 18, 2021
@Tkd-Alex
Copy link
Owner

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

I'll see what can I do

@ColinShark
Copy link
Contributor Author

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 ^^

ColinShark pushed a commit to ColinShark/Twitch-Channel-Points-Miner-v2 that referenced this issue Jul 30, 2021
This adds a (bad) Telegram implementation to receive updates via your
own bot. Bot Token via https://t.me/BotFather.

See here for the accompanying issue:
Tkd-Alex#233
ColinShark added a commit to ColinShark/Twitch-Channel-Points-Miner-v2 that referenced this issue Jul 30, 2021
This adds a (bad) Telegram implementation to receive updates via your
own bot. Bot Token via https://t.me/BotFather.

See here for the accompanying issue:
Tkd-Alex#233
@Rakambda
Copy link
Contributor

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

@ColinShark
Copy link
Contributor Author

@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
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Owner

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
Copy link
Contributor Author

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

@Tkd-Alex
Copy link
Owner

As you wish 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants