Merge branch 'master' into improvements-analytics
This commit is contained in:
4
.github/workflows/code-checker.yml
vendored
4
.github/workflows/code-checker.yml
vendored
@@ -14,10 +14,10 @@ jobs:
|
||||
python-version: [3.6, 3.7, 3.8]
|
||||
steps:
|
||||
- name: Clone Repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v2
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
|
||||
4
.github/workflows/deploy-docker.yml
vendored
4
.github/workflows/deploy-docker.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout source
|
||||
uses: actions/checkout@v2.4.0
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1.2.0
|
||||
@@ -20,7 +20,7 @@ jobs:
|
||||
uses: docker/setup-buildx-action@v1.6.0
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1.13.0
|
||||
uses: docker/login-action@v1.14.1
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_TOKEN }}
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -149,4 +149,4 @@ cookies/*
|
||||
logs/*
|
||||
screenshots/*
|
||||
htmls/*
|
||||
analytics/*
|
||||
analytics/*
|
||||
|
||||
32
README.md
32
README.md
@@ -188,6 +188,7 @@ import logging
|
||||
from colorama import Fore
|
||||
from TwitchChannelPointsMiner import TwitchChannelPointsMiner
|
||||
from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette
|
||||
from TwitchChannelPointsMiner.classes.Discord import Discord
|
||||
from TwitchChannelPointsMiner.classes.Telegram import Telegram
|
||||
from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder
|
||||
from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode
|
||||
@@ -219,6 +220,10 @@ twitch_miner = TwitchChannelPointsMiner(
|
||||
token="123456789:shfuihreuifheuifhiu34578347", # Telegram API token @BotFather
|
||||
events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, "BET_LOSE"], # Only these events will be sent to the chat
|
||||
disable_notification=True, # Revoke the notification (sound/vibration)
|
||||
),
|
||||
discord=Discord(
|
||||
webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", # Discord Webhook URL
|
||||
events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat
|
||||
)
|
||||
),
|
||||
streamer_settings=StreamerSettings(
|
||||
@@ -390,6 +395,7 @@ You can combine all priority but keep in mind that use `ORDER` and `POINTS_ASCEN
|
||||
| `auto_clear` | bool | True | Create a file rotation handler with interval = 1D and backupCount = 7 [#215](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/215) |
|
||||
| `color_palette` | ColorPalette | All messages are Fore.RESET except WIN and LOSE bet (GREEN and RED) | Create your custom color palette. Read more above. |
|
||||
| `telegram` | Telegram | None | (Optional) Receive Telegram updates for multiple events list [#233](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/233) |
|
||||
| `discord` | Discord | None | (Optional) Receive Discord updates for multiple events list [#320](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/320) |
|
||||
|
||||
#### Color Palette
|
||||
Now you can customize the color of the terminal message. We have created a default ColorPalette that provide all the message with `DEFAULT (RESET)` color and the `BET_WIN` and `BET_LOSE` message `GREEN` and `RED` respectively. You can change the colors of all `Events` enum class. The colors allowed are all the Fore color from Colorama: `BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.`
|
||||
@@ -420,7 +426,7 @@ If you want to receive logs update on Telegram initiate a new Telegram class, el
|
||||
| Key | Type | Default | Description |
|
||||
|----------------------- |----------------- |--------- |------------------------------------------------------------------- |
|
||||
| `chat_id` | int | | Chat ID to send messages @GiveChatId |
|
||||
| `token` | string | | Telegram API token @BotFather |
|
||||
| `token` | string | | Telegram API token @BotFather |
|
||||
| `events` | list | | Only these events will be sent to the chat. Array of Event. or str |
|
||||
| `disable_notification` | bool | false | Revoke the notification (sound/vibration) |
|
||||
|
||||
@@ -434,6 +440,30 @@ Telegram(
|
||||
)
|
||||
```
|
||||
|
||||
#### Discord
|
||||
If you want to receive log updates on Discord initialize a new Discord class, else leave omit this parameter or set it as None [YT Video](https://www.youtube.com/watch?v=fKksxz2Gdnc)
|
||||
1. Go to the Server you want to receive updates
|
||||
2. Click "Edit Channel"
|
||||
3. Click "Integrations"
|
||||
4. Click "Webhooks"
|
||||
5. Click "New Webhook"
|
||||
6. Name it if you want
|
||||
7. Click on "Copy Webhook URL"
|
||||
|
||||
|
||||
| Key | Type | Default | Description |
|
||||
|----------------------- |--------------------- |-------------- |------------------------------------------------------------------- |
|
||||
| `webhook_api` | string | | Discord webhook URL |
|
||||
| `events` | list | | Only these events will be sent to the chat. Array of Event. or str |
|
||||
|
||||
```python
|
||||
Discord(
|
||||
webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J",
|
||||
events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE],
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
#### Events
|
||||
- `STREAMER_ONLINE`
|
||||
- `STREAMER_OFFLINE`
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
__version__ = "2.0.7"
|
||||
__version__ = "2.0.8"
|
||||
from .TwitchChannelPointsMiner import TwitchChannelPointsMiner
|
||||
|
||||
__all__ = [
|
||||
|
||||
24
TwitchChannelPointsMiner/classes/Discord.py
Normal file
24
TwitchChannelPointsMiner/classes/Discord.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from textwrap import dedent
|
||||
|
||||
import requests
|
||||
|
||||
from TwitchChannelPointsMiner.classes.Settings import Events
|
||||
|
||||
|
||||
class Discord(object):
|
||||
__slots__ = ["webhook_api", "events"]
|
||||
|
||||
def __init__(self, webhook_api: str, events: list):
|
||||
self.webhook_api = webhook_api
|
||||
self.events = [str(e) for e in events]
|
||||
|
||||
def send(self, message: str, event: Events) -> None:
|
||||
if str(event) in self.events:
|
||||
requests.post(
|
||||
url=self.webhook_api,
|
||||
data={
|
||||
"content": dedent(message),
|
||||
"username": "Twitch Channel Points Miner",
|
||||
"avatar_url": "https://i.imgur.com/X9fEkhT.png",
|
||||
},
|
||||
)
|
||||
@@ -378,6 +378,7 @@ class Twitch(object):
|
||||
extra={
|
||||
"event": Events.DROP_STATUS,
|
||||
"skip_telegram": True,
|
||||
"skip_discord": True,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -387,6 +388,12 @@ class Twitch(object):
|
||||
Events.DROP_STATUS,
|
||||
)
|
||||
|
||||
if Settings.logger.discord is not None:
|
||||
Settings.logger.discord.send(
|
||||
"\n".join(drop_messages),
|
||||
Events.DROP_STATUS,
|
||||
)
|
||||
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
logger.error(f"Error while trying to send minute watched: {e}")
|
||||
self.__check_connection_handler(chunk_size)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from pathlib import Path
|
||||
import emoji
|
||||
from colorama import Fore, init
|
||||
|
||||
from TwitchChannelPointsMiner.classes.Discord import Discord
|
||||
from TwitchChannelPointsMiner.classes.Settings import Events
|
||||
from TwitchChannelPointsMiner.classes.Telegram import Telegram
|
||||
from TwitchChannelPointsMiner.utils import remove_emoji
|
||||
@@ -66,6 +67,7 @@ class LoggerSettings:
|
||||
"color_palette",
|
||||
"auto_clear",
|
||||
"telegram",
|
||||
"discord",
|
||||
]
|
||||
|
||||
def __init__(
|
||||
@@ -79,6 +81,7 @@ class LoggerSettings:
|
||||
color_palette: ColorPalette = ColorPalette(),
|
||||
auto_clear: bool = True,
|
||||
telegram: Telegram or None = None,
|
||||
discord: Discord or None = None,
|
||||
):
|
||||
self.save = save
|
||||
self.less = less
|
||||
@@ -89,6 +92,7 @@ class LoggerSettings:
|
||||
self.color_palette = color_palette
|
||||
self.auto_clear = auto_clear
|
||||
self.telegram = telegram
|
||||
self.discord = discord
|
||||
|
||||
|
||||
class GlobalFormatter(logging.Formatter):
|
||||
@@ -119,13 +123,13 @@ class GlobalFormatter(logging.Formatter):
|
||||
record.msg = remove_emoji(record.msg)
|
||||
|
||||
if hasattr(record, "event"):
|
||||
skip_telegram = (
|
||||
False
|
||||
if hasattr(record, "skip_telegram") is False
|
||||
or hasattr(record, "skip_telegram") is False
|
||||
else True
|
||||
)
|
||||
if self.settings.telegram is not None and skip_telegram is False:
|
||||
skip_telegram = False if hasattr(record, "skip_telegram") is False else True
|
||||
|
||||
if (
|
||||
self.settings.telegram is not None
|
||||
and skip_telegram is False
|
||||
and self.settings.telegram.chat_id != 123456789
|
||||
):
|
||||
self.settings.telegram.send(record.msg, record.event)
|
||||
|
||||
if self.settings.colored is True:
|
||||
@@ -133,6 +137,21 @@ class GlobalFormatter(logging.Formatter):
|
||||
f"{self.settings.color_palette.get(record.event)}{record.msg}"
|
||||
)
|
||||
|
||||
skip_discord = False if hasattr(record, "skip_discord") is False else True
|
||||
|
||||
if (
|
||||
self.settings.discord is not None
|
||||
and skip_discord is False
|
||||
and self.settings.discord.webhook_api
|
||||
!= "https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J"
|
||||
):
|
||||
self.settings.discord.send(record.msg, record.event)
|
||||
|
||||
if self.settings.colored is True:
|
||||
record.msg = (
|
||||
f"{self.settings.color_palette.get(record.event)}{record.msg}"
|
||||
)
|
||||
|
||||
return super().format(record)
|
||||
|
||||
|
||||
|
||||
@@ -190,7 +190,12 @@ def check_versions():
|
||||
current_version = "0.0.0"
|
||||
try:
|
||||
r = requests.get(
|
||||
path.join(GITHUB_url, "TwitchChannelPointsMiner", "__init__.py")
|
||||
"/".join(
|
||||
[
|
||||
s.strip("/")
|
||||
for s in [GITHUB_url, "TwitchChannelPointsMiner", "__init__.py"]
|
||||
]
|
||||
)
|
||||
)
|
||||
github_version = init2dict(r.text)
|
||||
github_version = (
|
||||
|
||||
@@ -4,6 +4,7 @@ import logging
|
||||
from colorama import Fore
|
||||
from TwitchChannelPointsMiner import TwitchChannelPointsMiner
|
||||
from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette
|
||||
from TwitchChannelPointsMiner.classes.Discord import Discord
|
||||
from TwitchChannelPointsMiner.classes.Telegram import Telegram
|
||||
from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder
|
||||
from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode
|
||||
@@ -35,6 +36,10 @@ twitch_miner = TwitchChannelPointsMiner(
|
||||
token="123456789:shfuihreuifheuifhiu34578347", # Telegram API token @BotFather
|
||||
events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, "BET_LOSE"], # Only these events will be sent to the chat
|
||||
disable_notification=True, # Revoke the notification (sound/vibration)
|
||||
),
|
||||
discord=Discord(
|
||||
webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", # Discord Webhook URL
|
||||
events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat
|
||||
)
|
||||
),
|
||||
streamer_settings=StreamerSettings(
|
||||
|
||||
@@ -9,4 +9,4 @@ pre-commit==2.13.0
|
||||
colorama==0.4.4
|
||||
flask==2.0.1
|
||||
irc==19.0.1
|
||||
pandas==1.3.4
|
||||
pandas==1.3.4
|
||||
Reference in New Issue
Block a user