Skip to content

Commit 7ab3162

Browse files
committed
Manual merge, fix conflicts - Sync with master
2 parents 385361f + a37d1b9 commit 7ab3162

File tree

11 files changed

+108
-16
lines changed

11 files changed

+108
-16
lines changed

.github/workflows/code-checker.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
python-version: [3.6, 3.7, 3.8]
1515
steps:
1616
- name: Clone Repository
17-
uses: actions/checkout@v2
17+
uses: actions/checkout@v3
1818

1919
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v2
20+
uses: actions/setup-python@v3
2121
with:
2222
python-version: ${{ matrix.python-version }}
2323

.github/workflows/deploy-docker.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout source
14-
uses: actions/checkout@v2.4.0
14+
uses: actions/checkout@v3
1515

1616
- name: Set up QEMU
1717
uses: docker/[email protected]
@@ -20,7 +20,7 @@ jobs:
2020
uses: docker/[email protected]
2121

2222
- name: Login to DockerHub
23-
uses: docker/login-action@v1.13.0
23+
uses: docker/login-action@v1.14.1
2424
with:
2525
username: ${{ secrets.DOCKER_USERNAME }}
2626
password: ${{ secrets.DOCKER_TOKEN }}

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,4 @@ cookies/*
149149
logs/*
150150
screenshots/*
151151
htmls/*
152-
analytics/*
152+
analytics/*

README.md

+34-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ import logging
187187
from colorama import Fore
188188
from TwitchChannelPointsMiner import TwitchChannelPointsMiner
189189
from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette
190+
<<<<<<< HEAD
190191
from TwitchChannelPointsMiner.classes.Chat import ChatPresence
192+
=======
193+
from TwitchChannelPointsMiner.classes.Discord import Discord
194+
>>>>>>> master
191195
from TwitchChannelPointsMiner.classes.Telegram import Telegram
192196
from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder
193197
from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode
@@ -219,6 +223,10 @@ twitch_miner = TwitchChannelPointsMiner(
219223
token="123456789:shfuihreuifheuifhiu34578347", # Telegram API token @BotFather
220224
events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, "BET_LOSE"], # Only these events will be sent to the chat
221225
disable_notification=True, # Revoke the notification (sound/vibration)
226+
),
227+
discord=Discord(
228+
webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", # Discord Webhook URL
229+
events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat
222230
)
223231
),
224232
streamer_settings=StreamerSettings(
@@ -390,6 +398,7 @@ You can combine all priority but keep in mind that use `ORDER` and `POINTS_ASCEN
390398
| `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) |
391399
| `color_palette` | ColorPalette | All messages are Fore.RESET except WIN and LOSE bet (GREEN and RED) | Create your custom color palette. Read more above. |
392400
| `telegram` | Telegram | None | (Optional) Receive Telegram updates for multiple events list [#233](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/233) |
401+
| `discord` | Discord | None | (Optional) Receive Discord updates for multiple events list [#320](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/320) |
393402

394403
#### Color Palette
395404
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 +429,7 @@ If you want to receive logs update on Telegram initiate a new Telegram class, el
420429
| Key | Type | Default | Description |
421430
|----------------------- |----------------- |--------- |------------------------------------------------------------------- |
422431
| `chat_id` | int | | Chat ID to send messages @GiveChatId |
423-
| `token` | string | | Telegram API token @BotFather |
432+
| `token` | string | | Telegram API token @BotFather |
424433
| `events` | list | | Only these events will be sent to the chat. Array of Event. or str |
425434
| `disable_notification` | bool | false | Revoke the notification (sound/vibration) |
426435

@@ -434,6 +443,30 @@ Telegram(
434443
)
435444
```
436445

446+
#### Discord
447+
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)
448+
1. Go to the Server you want to receive updates
449+
2. Click "Edit Channel"
450+
3. Click "Integrations"
451+
4. Click "Webhooks"
452+
5. Click "New Webhook"
453+
6. Name it if you want
454+
7. Click on "Copy Webhook URL"
455+
456+
457+
| Key | Type | Default | Description |
458+
|----------------------- |--------------------- |-------------- |------------------------------------------------------------------- |
459+
| `webhook_api` | string | | Discord webhook URL |
460+
| `events` | list | | Only these events will be sent to the chat. Array of Event. or str |
461+
462+
```python
463+
Discord(
464+
webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J",
465+
events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE],
466+
)
467+
```
468+
469+
437470
#### Events
438471
- `STREAMER_ONLINE`
439472
- `STREAMER_OFFLINE`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from textwrap import dedent
2+
3+
import requests
4+
5+
from TwitchChannelPointsMiner.classes.Settings import Events
6+
7+
8+
class Discord(object):
9+
__slots__ = ["webhook_api", "events"]
10+
11+
def __init__(self, webhook_api: str, events: list):
12+
self.webhook_api = webhook_api
13+
self.events = [str(e) for e in events]
14+
15+
def send(self, message: str, event: Events) -> None:
16+
if str(event) in self.events:
17+
requests.post(
18+
url=self.webhook_api,
19+
data={
20+
"content": dedent(message),
21+
"username": "Twitch Channel Points Miner",
22+
"avatar_url": "https://i.imgur.com/X9fEkhT.png",
23+
},
24+
)

TwitchChannelPointsMiner/classes/Twitch.py

+7
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ def send_minute_watched_events(self, streamers, priority, chunk_size=3):
378378
extra={
379379
"event": Events.DROP_STATUS,
380380
"skip_telegram": True,
381+
"skip_discord": True,
381382
},
382383
)
383384

@@ -387,6 +388,12 @@ def send_minute_watched_events(self, streamers, priority, chunk_size=3):
387388
Events.DROP_STATUS,
388389
)
389390

391+
if Settings.logger.discord is not None:
392+
Settings.logger.discord.send(
393+
"\n".join(drop_messages),
394+
Events.DROP_STATUS,
395+
)
396+
390397
except requests.exceptions.ConnectionError as e:
391398
logger.error(f"Error while trying to send minute watched: {e}")
392399
self.__check_connection_handler(chunk_size)
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

TwitchChannelPointsMiner/logger.py

+26-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import emoji
99
from colorama import Fore, init
1010

11+
from TwitchChannelPointsMiner.classes.Discord import Discord
1112
from TwitchChannelPointsMiner.classes.Settings import Events
1213
from TwitchChannelPointsMiner.classes.Telegram import Telegram
1314
from TwitchChannelPointsMiner.utils import remove_emoji
@@ -66,6 +67,7 @@ class LoggerSettings:
6667
"color_palette",
6768
"auto_clear",
6869
"telegram",
70+
"discord",
6971
]
7072

7173
def __init__(
@@ -79,6 +81,7 @@ def __init__(
7981
color_palette: ColorPalette = ColorPalette(),
8082
auto_clear: bool = True,
8183
telegram: Telegram or None = None,
84+
discord: Discord or None = None,
8285
):
8386
self.save = save
8487
self.less = less
@@ -89,6 +92,7 @@ def __init__(
8992
self.color_palette = color_palette
9093
self.auto_clear = auto_clear
9194
self.telegram = telegram
95+
self.discord = discord
9296

9397

9498
class GlobalFormatter(logging.Formatter):
@@ -119,20 +123,35 @@ def format(self, record):
119123
record.msg = remove_emoji(record.msg)
120124

121125
if hasattr(record, "event"):
122-
skip_telegram = (
123-
False
124-
if hasattr(record, "skip_telegram") is False
125-
or hasattr(record, "skip_telegram") is False
126-
else True
127-
)
128-
if self.settings.telegram is not None and skip_telegram is False:
126+
skip_telegram = False if hasattr(record, "skip_telegram") is False else True
127+
128+
if (
129+
self.settings.telegram is not None
130+
and skip_telegram is False
131+
and self.settings.telegram.chat_id != 123456789
132+
):
129133
self.settings.telegram.send(record.msg, record.event)
130134

131135
if self.settings.colored is True:
132136
record.msg = (
133137
f"{self.settings.color_palette.get(record.event)}{record.msg}"
134138
)
135139

140+
skip_discord = False if hasattr(record, "skip_discord") is False else True
141+
142+
if (
143+
self.settings.discord is not None
144+
and skip_discord is False
145+
and self.settings.discord.webhook_api
146+
!= "https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J"
147+
):
148+
self.settings.discord.send(record.msg, record.event)
149+
150+
if self.settings.colored is True:
151+
record.msg = (
152+
f"{self.settings.color_palette.get(record.event)}{record.msg}"
153+
)
154+
136155
return super().format(record)
137156

138157

TwitchChannelPointsMiner/utils.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,12 @@ def check_versions():
190190
current_version = "0.0.0"
191191
try:
192192
r = requests.get(
193-
path.join(GITHUB_url, "TwitchChannelPointsMiner", "__init__.py")
193+
"/".join(
194+
[
195+
s.strip("/")
196+
for s in [GITHUB_url, "TwitchChannelPointsMiner", "__init__.py"]
197+
]
198+
)
194199
)
195200
github_version = init2dict(r.text)
196201
github_version = (

example.py

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from TwitchChannelPointsMiner import TwitchChannelPointsMiner
66
from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette
77
from TwitchChannelPointsMiner.classes.Chat import ChatPresence
8+
from TwitchChannelPointsMiner.classes.Discord import Discord
89
from TwitchChannelPointsMiner.classes.Telegram import Telegram
910
from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder
1011
from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode
@@ -36,6 +37,10 @@
3637
token="123456789:shfuihreuifheuifhiu34578347", # Telegram API token @BotFather
3738
events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, "BET_LOSE"], # Only these events will be sent to the chat
3839
disable_notification=True, # Revoke the notification (sound/vibration)
40+
),
41+
discord=Discord(
42+
webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", # Discord Webhook URL
43+
events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat
3944
)
4045
),
4146
streamer_settings=StreamerSettings(

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ millify==0.1.1
88
pre-commit==2.13.0
99
colorama==0.4.4
1010
flask==2.0.1
11-
irc==19.0.1
11+
irc==19.0.1

0 commit comments

Comments
 (0)