crxsnake 0.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
crxsnake/__init__.py ADDED
@@ -0,0 +1,19 @@
1
+ from .logger import logger
2
+ from .cogs import load_cogs
3
+ from .files import read_json, write_json
4
+ from .tortoise import Database
5
+ from .misc import *
6
+
7
+ from ...issues.hotline import IssueHotline
8
+ from ...issues.crx import IssueCRX
9
+
10
+
11
+ __all__ = [
12
+ IssueHotline,
13
+ IssueCRX,
14
+ logger,
15
+ Database,
16
+ read_json,
17
+ write_json,
18
+ load_cogs,
19
+ ]
crxsnake/cogs.py ADDED
@@ -0,0 +1,16 @@
1
+ from sys import path
2
+ from pathlib import Path
3
+ from rich.console import Console
4
+
5
+
6
+ async def load_cogs(bot, directory="src"):
7
+ directory_path = Path(directory)
8
+ path.append(str(directory_path))
9
+
10
+ for entry in directory_path.iterdir():
11
+ for filename in entry.iterdir():
12
+ if filename.suffix == ".py" and entry.name != "utils":
13
+ try:
14
+ bot.load_extension(f"{entry.name}.{filename.stem}")
15
+ except Exception:
16
+ Console().print_exception(show_locals=True)
crxsnake/files.py ADDED
@@ -0,0 +1,37 @@
1
+ from typing import Optional, Any
2
+ from json import loads, dumps
3
+
4
+ from aiofiles import open
5
+ from rich.console import Console
6
+
7
+
8
+ async def read_json(path: str, *keys: str) -> Optional[Any]:
9
+ """
10
+ Read data from json file.
11
+ """
12
+ try:
13
+ async with open(path, "r", encoding="utf-8") as file:
14
+ file_content = await file.read()
15
+ file_data = loads(file_content)
16
+
17
+ for key in keys:
18
+ if key not in file_data:
19
+ return None
20
+
21
+ file_data = file_data[key]
22
+ return file_data
23
+
24
+ except Exception:
25
+ Console().print_exception(show_locals=True)
26
+
27
+
28
+ async def write_json(path: str, data: Any) -> None:
29
+ """
30
+ Write data to json file.
31
+ """
32
+ try:
33
+ async with open(path, "w", encoding="utf-8") as file:
34
+ await file.write(dumps(data, ensure_ascii=False, indent=2))
35
+
36
+ except Exception:
37
+ Console().print_exception(show_locals=True)
File without changes
crxsnake/issues/crx.py ADDED
@@ -0,0 +1,14 @@
1
+ from typing import List, Dict, Any
2
+
3
+
4
+ class IssueCRX:
5
+ async def create_items(
6
+ self, issue_type: str, items_list: List[Dict[str, Any]]
7
+ ) -> Dict[str, List[Dict[str, Any]]]:
8
+ """
9
+ Create a dictionary with generated codes and processed items.
10
+ """
11
+
12
+ issue_dict = {"items": [], "cars": [], "sets": []}
13
+ issue_dict[issue_type].extend(items_list)
14
+ return issue_dict
@@ -0,0 +1,77 @@
1
+ from random import choices
2
+ from string import ascii_uppercase, ascii_letters, digits
3
+ from typing import List, Dict, Any, AsyncGenerator
4
+
5
+
6
+ class IssueHotline:
7
+ MAX_STACK = 100
8
+
9
+ async def __generate_code(self) -> str:
10
+ part1 = "".join(choices(ascii_uppercase, k=2))
11
+ part2 = "".join(choices(ascii_letters + digits, k=4))
12
+ part3 = "".join(choices(ascii_letters + digits, k=4))
13
+ return f"{part1}-{part2}-{part3}"
14
+
15
+ async def __generate_count(
16
+ self, items_list: List[Dict[str, Any]]
17
+ ) -> AsyncGenerator[Dict[str, Any], None]:
18
+ """
19
+ Generate item counts based on the MAX_STACK value.
20
+ Splits items into full stacks and the remainder.
21
+ """
22
+
23
+ for item in items_list:
24
+ item_count = item.get("m_count", 0)
25
+ item_name = item.get("m_item", "")
26
+ full_stacks, remainder = divmod(item_count, self.MAX_STACK)
27
+
28
+ for _ in range(full_stacks):
29
+ yield {"m_item": item_name, "m_count": self.MAX_STACK}
30
+
31
+ if remainder > 0:
32
+ yield {"m_item": item_name, "m_count": remainder}
33
+
34
+ async def create_items(
35
+ self, issue_name: str, items_list: List[Dict[str, Any]]
36
+ ) -> Dict[str, Any]:
37
+ """
38
+ Create a dictionary with generated codes and processed items.
39
+ """
40
+
41
+ processed_items = [item async for item in self.__generate_count(items_list)]
42
+ return {
43
+ "m_CodeArray": [
44
+ {
45
+ "m_code": await self.__generate_code(),
46
+ "m_name": issue_name,
47
+ "m_type": "item",
48
+ "m_itemsArray": processed_items,
49
+ "m_vehicles": {},
50
+ "m_teleport_position": "",
51
+ "m_give_zone_positions": [],
52
+ "m_give_zone_positions_forbidden": [],
53
+ }
54
+ ]
55
+ }
56
+
57
+ async def create_vehicle(
58
+ self, issue_name: str, items_dict: Dict[str, Any]
59
+ ) -> Dict[str, Any]:
60
+ """
61
+ Create a dictionary with generated code and vehicle data.
62
+ """
63
+
64
+ return {
65
+ "m_CodeArray": [
66
+ {
67
+ "m_code": await self.__generate_code(),
68
+ "m_name": issue_name,
69
+ "m_type": "vehicle",
70
+ "m_itemsArray": [],
71
+ "m_vehicles": items_dict,
72
+ "m_teleport_position": "",
73
+ "m_give_zone_positions": [],
74
+ "m_give_zone_positions_forbidden": [],
75
+ }
76
+ ]
77
+ }
crxsnake/logger.py ADDED
@@ -0,0 +1,28 @@
1
+ import sys
2
+ from loguru import logger
3
+
4
+
5
+ logger.remove(0)
6
+ logger.add(
7
+ sys.stderr,
8
+ format="<blue>[{time:HH:mm:ss}]</blue> <yellow>({level})</yellow> <red>|→</red> <green>{message}</green>",
9
+ colorize=True,
10
+ level="INFO",
11
+ filter=lambda record: record["level"].name == "INFO",
12
+ )
13
+
14
+ logger.add(
15
+ sys.stderr,
16
+ format="<blue>[{time:HH:mm:ss}]</blue> <yellow>({level})</yellow> |> <yellow>{message}</yellow>",
17
+ colorize=True,
18
+ level="WARNING",
19
+ filter=lambda record: record["level"].name == "WARNING",
20
+ )
21
+
22
+ logger.add(
23
+ sys.stderr,
24
+ format="<blue>[{time:HH:mm:ss}]</blue> <red>({level})|→ {message}</red>",
25
+ colorize=True,
26
+ level="ERROR",
27
+ filter=lambda record: record["level"].name == "ERROR",
28
+ )
crxsnake/misc.py ADDED
@@ -0,0 +1,16 @@
1
+ from datetime import datetime
2
+
3
+ red = 16711680
4
+ green = 65280
5
+ blue = 255
6
+ yellow = 16776960
7
+ purple = 9109759
8
+ trans = 2829617
9
+
10
+ timestamp = int(datetime.now().timestamp())
11
+ time_short = f"<t:{timestamp}:d>"
12
+ time_long_date = f"<t:{timestamp}:D>"
13
+ time_short_time = f"<t:{timestamp}:t>"
14
+ time_long_time = f"<t:{timestamp}:T>"
15
+ time_full = f"<t:{timestamp}:f>"
16
+ time_relative = f"<t:{timestamp}:R>"
crxsnake/tortoise.py ADDED
@@ -0,0 +1,28 @@
1
+ from tortoise import Tortoise
2
+ from rich.console import Console
3
+
4
+
5
+ class Database:
6
+ DB_URL = "sqlite://settings/database/database.db"
7
+ DB_MODEL = {"models": ["src.utils"]}
8
+
9
+ async def db_connect(self) -> None:
10
+ """
11
+ Connect to the database.
12
+ """
13
+ try:
14
+ await Tortoise.init(db_url=self.DB_URL, modules=self.DB_MODEL)
15
+ await Tortoise.generate_schemas()
16
+
17
+ except Exception:
18
+ Console().print_exception(show_locals=True)
19
+
20
+ async def db_disconnect(self) -> None:
21
+ """
22
+ Disconnect from the database.
23
+ """
24
+ try:
25
+ await Tortoise.close_connections()
26
+
27
+ except Exception:
28
+ Console().print_exception(show_locals=True)
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 CRX-DEV
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.1
2
+ Name: crxsnake
3
+ Version: 0.0.0
4
+ License-File: LICENSE
5
+
@@ -0,0 +1,14 @@
1
+ crxsnake/__init__.py,sha256=F8W6qG38P8nF8nfCCPfEdPpzJdFX2VyQdzVUvAsPXaM,365
2
+ crxsnake/cogs.py,sha256=gXC81xWcpUZ-YOpI8BqiUoy7s8AInLr0M1asrSFAxEg,557
3
+ crxsnake/files.py,sha256=M6uCktEFaDUuVH3CHUcr9bITZa_ruEsAjIRqf_5gM3o,997
4
+ crxsnake/logger.py,sha256=-TXqHfagCV-TrnwJrucKEa61BRePW34sep0K9RCbHn8,764
5
+ crxsnake/misc.py,sha256=VAv6FTQ-Ekwudtm8iLKjSu3WFSJuTw8Nrs_Gclo1W_c,402
6
+ crxsnake/tortoise.py,sha256=R0IwdfvsS5FGUXlGVIdI1I48_Xde_qz_Rd8E2e_NNHY,768
7
+ crxsnake/issues/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ crxsnake/issues/crx.py,sha256=mhYX4iWmyPw5rV60rb0m18HAy7s72aTFwA-MIsdXV1E,431
9
+ crxsnake/issues/hotline.py,sha256=tLUVp59O8YesXxlmVxOeLcIjDN7RiwWTZGCVKIxXR-Q,2683
10
+ crxsnake-0.0.0.dist-info/LICENSE,sha256=xt4Ru6tOCU8e2wVlx_lgx7wh-sNLKbiCbmANzr2e3cc,1085
11
+ crxsnake-0.0.0.dist-info/METADATA,sha256=dyV-kv1iq56dUJAdhzbldudAZP3ajj8n9IIte7eHKf4,80
12
+ crxsnake-0.0.0.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
13
+ crxsnake-0.0.0.dist-info/top_level.txt,sha256=GOgG6tMH05czsfM6y-Tvm9LUSd-0PPuuuYkkkbWHZjQ,9
14
+ crxsnake-0.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (72.2.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ crxsnake