crxsnake 0.0.0__tar.gz
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-0.0.0/LICENSE +21 -0
- crxsnake-0.0.0/MANIFEST.in +4 -0
- crxsnake-0.0.0/PKG-INFO +4 -0
- crxsnake-0.0.0/README.md +12 -0
- crxsnake-0.0.0/crxsnake/__init__.py +19 -0
- crxsnake-0.0.0/crxsnake/cogs.py +16 -0
- crxsnake-0.0.0/crxsnake/files.py +37 -0
- crxsnake-0.0.0/crxsnake/issues/__init__.py +0 -0
- crxsnake-0.0.0/crxsnake/issues/crx.py +14 -0
- crxsnake-0.0.0/crxsnake/issues/hotline.py +77 -0
- crxsnake-0.0.0/crxsnake/logger.py +28 -0
- crxsnake-0.0.0/crxsnake/misc.py +16 -0
- crxsnake-0.0.0/crxsnake/tortoise.py +28 -0
- crxsnake-0.0.0/crxsnake.egg-info/PKG-INFO +4 -0
- crxsnake-0.0.0/crxsnake.egg-info/SOURCES.txt +17 -0
- crxsnake-0.0.0/crxsnake.egg-info/dependency_links.txt +1 -0
- crxsnake-0.0.0/crxsnake.egg-info/top_level.txt +1 -0
- crxsnake-0.0.0/pyproject.toml +6 -0
- crxsnake-0.0.0/setup.cfg +4 -0
crxsnake-0.0.0/LICENSE
ADDED
@@ -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.
|
crxsnake-0.0.0/PKG-INFO
ADDED
crxsnake-0.0.0/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# CRX-Snake
|
2
|
+
|
3
|
+
**CRX-Snake** is a set of utilities designed to simplify the development of projects, including the creation of Discord bots. This library contains a number of features and tools to help you quickly develop and customize bots and other components of your projects.
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
CRX-Snake was developed specifically for internal use and is now available to other developers. It provides user-friendly features and solutions for common tasks in bot development and project management. It includes:
|
8
|
+
|
9
|
+
- **Features for working with Discord**: Tools for creating and managing Discord bots using the Disnake library.
|
10
|
+
- **File Utilities**: Functions for reading and writing JSON files, making it easy to work with configurations and data.
|
11
|
+
- **Database Tools**: Interfaces with Tortoise ORM for data management and query execution.
|
12
|
+
- **Logging and debugging**: Includes functions for error logging and debugging.
|
@@ -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
|
+
]
|
@@ -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)
|
@@ -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
|
@@ -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
|
+
}
|
@@ -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
|
+
)
|
@@ -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>"
|
@@ -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,17 @@
|
|
1
|
+
LICENSE
|
2
|
+
MANIFEST.in
|
3
|
+
README.md
|
4
|
+
pyproject.toml
|
5
|
+
crxsnake/__init__.py
|
6
|
+
crxsnake/cogs.py
|
7
|
+
crxsnake/files.py
|
8
|
+
crxsnake/logger.py
|
9
|
+
crxsnake/misc.py
|
10
|
+
crxsnake/tortoise.py
|
11
|
+
crxsnake.egg-info/PKG-INFO
|
12
|
+
crxsnake.egg-info/SOURCES.txt
|
13
|
+
crxsnake.egg-info/dependency_links.txt
|
14
|
+
crxsnake.egg-info/top_level.txt
|
15
|
+
crxsnake/issues/__init__.py
|
16
|
+
crxsnake/issues/crx.py
|
17
|
+
crxsnake/issues/hotline.py
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
crxsnake
|
crxsnake-0.0.0/setup.cfg
ADDED