Skip to content

Commit

Permalink
Manual merge, fix conflicts - Sync with master
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkd-Alex committed Mar 5, 2022
2 parents 385361f + a37d1b9 commit 7ab3162
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/code-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand All @@ -20,7 +20,7 @@ jobs:
uses: docker/[email protected]

- 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 }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ cookies/*
logs/*
screenshots/*
htmls/*
analytics/*
analytics/*
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ import logging
from colorama import Fore
from TwitchChannelPointsMiner import TwitchChannelPointsMiner
from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette
<<<<<<< HEAD
from TwitchChannelPointsMiner.classes.Chat import ChatPresence
=======
from TwitchChannelPointsMiner.classes.Discord import Discord
>>>>>>> master
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
Expand Down Expand Up @@ -219,6 +223,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(
Expand Down Expand Up @@ -390,6 +398,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.`
Expand Down Expand Up @@ -420,7 +429,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) |

Expand All @@ -434,6 +443,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`
Expand Down
24 changes: 24 additions & 0 deletions TwitchChannelPointsMiner/classes/Discord.py
Original file line number Diff line number Diff line change
@@ -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",
},
)
7 changes: 7 additions & 0 deletions TwitchChannelPointsMiner/classes/Twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def send_minute_watched_events(self, streamers, priority, chunk_size=3):
extra={
"event": Events.DROP_STATUS,
"skip_telegram": True,
"skip_discord": True,
},
)

Expand All @@ -387,6 +388,12 @@ def send_minute_watched_events(self, streamers, priority, chunk_size=3):
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)
Expand Down
1 change: 0 additions & 1 deletion TwitchChannelPointsMiner/classes/entities/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

33 changes: 26 additions & 7 deletions TwitchChannelPointsMiner/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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
Expand Down Expand Up @@ -66,6 +67,7 @@ class LoggerSettings:
"color_palette",
"auto_clear",
"telegram",
"discord",
]

def __init__(
Expand All @@ -79,6 +81,7 @@ def __init__(
color_palette: ColorPalette = ColorPalette(),
auto_clear: bool = True,
telegram: Telegram or None = None,
discord: Discord or None = None,
):
self.save = save
self.less = less
Expand All @@ -89,6 +92,7 @@ def __init__(
self.color_palette = color_palette
self.auto_clear = auto_clear
self.telegram = telegram
self.discord = discord


class GlobalFormatter(logging.Formatter):
Expand Down Expand Up @@ -119,20 +123,35 @@ def format(self, record):
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:
record.msg = (
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)


Expand Down
7 changes: 6 additions & 1 deletion TwitchChannelPointsMiner/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
5 changes: 5 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from TwitchChannelPointsMiner import TwitchChannelPointsMiner
from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette
from TwitchChannelPointsMiner.classes.Chat import ChatPresence
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
Expand Down Expand Up @@ -36,6 +37,10 @@
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(
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ millify==0.1.1
pre-commit==2.13.0
colorama==0.4.4
flask==2.0.1
irc==19.0.1
irc==19.0.1

0 comments on commit 7ab3162

Please sign in to comment.