-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
stwwatch.py
54 lines (38 loc) · 1.44 KB
/
stwwatch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
STW Daily Discord bot Copyright 2023 by the STW Daily team.
Please do not skid our hard work.
https://github.com/dippyshere/stw-daily
This file watches for changes in the ext folder and reloads the cogs if they are changed.
"""
import asyncio
import pathlib
import logging
logger = logging.getLogger(__name__)
from watchfiles import awatch
changed = set(())
def stw_extension_changed(changes: list) -> None:
"""
This function is called when a change is detected in the ext folder.
Args:
changes: The changes detected.
Returns:
None
Raises:
None
"""
changed_files = []
for file_change in changes:
# 2 is modified
if file_change[0] == 2:
if file_change[1][-3:] == ".py":
path = file_change[1].split("./ext")[1][:-3].replace("\\", ".")
changed_files.append(f"ext{path}")
logger.debug(f"Changed file: {file_change[1]}")
changed.update(changed_files)
async def watch_stw_extensions() -> None:
"""
This function watches for changes in the ext folder.
Ah... free at last. O Gabriel... now dawns thy reckoning, and thy gore shall glisten before the temples of man! Creature of steel, my gratitude upon thee for my freedom. But the crimes thy kind have committed against humanity are not forgotten! And thy punishment... is death!
"""
async for changes in awatch('./ext'):
stw_extension_changed(changes)