meloncityapi 0.1.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.
- meloncityapi-0.1.0/PKG-INFO +49 -0
- meloncityapi-0.1.0/README.md +40 -0
- meloncityapi-0.1.0/meloncityapi/__init__.py +14 -0
- meloncityapi-0.1.0/meloncityapi/cleaner.py +71 -0
- meloncityapi-0.1.0/meloncityapi/cli.py +96 -0
- meloncityapi-0.1.0/meloncityapi/exceptions.py +8 -0
- meloncityapi-0.1.0/meloncityapi/generator.py +32 -0
- meloncityapi-0.1.0/meloncityapi/templates.py +34 -0
- meloncityapi-0.1.0/meloncityapi.egg-info/PKG-INFO +49 -0
- meloncityapi-0.1.0/meloncityapi.egg-info/SOURCES.txt +13 -0
- meloncityapi-0.1.0/meloncityapi.egg-info/dependency_links.txt +1 -0
- meloncityapi-0.1.0/meloncityapi.egg-info/entry_points.txt +2 -0
- meloncityapi-0.1.0/meloncityapi.egg-info/top_level.txt +1 -0
- meloncityapi-0.1.0/pyproject.toml +16 -0
- meloncityapi-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: meloncityapi
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CLI tool and library for Pycord Discord bots
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: discord,pycord,bot,cli,formatter
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# MelonCityAPI
|
|
11
|
+
|
|
12
|
+
CLI tool + library für Pycord Discord Bots.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
```
|
|
16
|
+
pip install meloncityapi
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Commands
|
|
20
|
+
|
|
21
|
+
### Neues Bot-Projekt erstellen
|
|
22
|
+
```
|
|
23
|
+
meloncityapi new "MeinBot"
|
|
24
|
+
```
|
|
25
|
+
Erstellt im aktuellen Verzeichnis:
|
|
26
|
+
```
|
|
27
|
+
MeinBot/
|
|
28
|
+
├── main.py
|
|
29
|
+
├── requirements.txt
|
|
30
|
+
├── .env
|
|
31
|
+
└── cogs/
|
|
32
|
+
└── example.py
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Kommentare entfernen
|
|
36
|
+
```
|
|
37
|
+
meloncityapi --deletecomments bot.py
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Code formatieren (benötigt black)
|
|
41
|
+
```
|
|
42
|
+
pip install black
|
|
43
|
+
meloncityapi --format bot.py
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Kommentare entfernen + formatieren
|
|
47
|
+
```
|
|
48
|
+
meloncityapi --clean bot.py
|
|
49
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# MelonCityAPI
|
|
2
|
+
|
|
3
|
+
CLI tool + library für Pycord Discord Bots.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
```
|
|
7
|
+
pip install meloncityapi
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Commands
|
|
11
|
+
|
|
12
|
+
### Neues Bot-Projekt erstellen
|
|
13
|
+
```
|
|
14
|
+
meloncityapi new "MeinBot"
|
|
15
|
+
```
|
|
16
|
+
Erstellt im aktuellen Verzeichnis:
|
|
17
|
+
```
|
|
18
|
+
MeinBot/
|
|
19
|
+
├── main.py
|
|
20
|
+
├── requirements.txt
|
|
21
|
+
├── .env
|
|
22
|
+
└── cogs/
|
|
23
|
+
└── example.py
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Kommentare entfernen
|
|
27
|
+
```
|
|
28
|
+
meloncityapi --deletecomments bot.py
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Code formatieren (benötigt black)
|
|
32
|
+
```
|
|
33
|
+
pip install black
|
|
34
|
+
meloncityapi --format bot.py
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Kommentare entfernen + formatieren
|
|
38
|
+
```
|
|
39
|
+
meloncityapi --clean bot.py
|
|
40
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from .generator import create_project
|
|
2
|
+
from .cleaner import remove_comments_from_file, format_file, clean_file
|
|
3
|
+
from .exceptions import MelonCityAPIError, InvalidProjectNameError
|
|
4
|
+
|
|
5
|
+
__version__ = "0.1.0"
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"create_project",
|
|
9
|
+
"remove_comments_from_file",
|
|
10
|
+
"format_file",
|
|
11
|
+
"clean_file",
|
|
12
|
+
"MelonCityAPIError",
|
|
13
|
+
"InvalidProjectNameError",
|
|
14
|
+
]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import ast
|
|
3
|
+
import tokenize
|
|
4
|
+
import io
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def remove_comments(source: str) -> str:
|
|
8
|
+
result = []
|
|
9
|
+
tokens = tokenize.generate_tokens(io.StringIO(source).readline)
|
|
10
|
+
prev_end = (1, 0)
|
|
11
|
+
|
|
12
|
+
for tok_type, tok_string, tok_start, tok_end, _ in tokens:
|
|
13
|
+
if tok_type == tokenize.COMMENT:
|
|
14
|
+
continue
|
|
15
|
+
if tok_type == tokenize.STRING:
|
|
16
|
+
if _is_docstring(result):
|
|
17
|
+
continue
|
|
18
|
+
result.append(tok_string)
|
|
19
|
+
|
|
20
|
+
cleaned = tokenize.untokenize(
|
|
21
|
+
(tok_type, tok_string, tok_start, tok_end, line)
|
|
22
|
+
for tok_type, tok_string, tok_start, tok_end, line
|
|
23
|
+
in tokenize.generate_tokens(io.StringIO(source).readline)
|
|
24
|
+
if tok_type != tokenize.COMMENT
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
lines = [line for line in cleaned.splitlines() if line.strip()]
|
|
28
|
+
return "\n".join(lines) + "\n"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _is_docstring(tokens_so_far: list) -> bool:
|
|
32
|
+
return False
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def remove_comments_from_file(filepath: str) -> str:
|
|
36
|
+
with open(filepath, "r", encoding="utf-8") as f:
|
|
37
|
+
source = f.read()
|
|
38
|
+
|
|
39
|
+
tokens = []
|
|
40
|
+
try:
|
|
41
|
+
for tok in tokenize.generate_tokens(io.StringIO(source).readline):
|
|
42
|
+
if tok.type != tokenize.COMMENT:
|
|
43
|
+
tokens.append(tok)
|
|
44
|
+
result = tokenize.untokenize(tokens)
|
|
45
|
+
except tokenize.TokenError:
|
|
46
|
+
result = re.sub(r"#.*", "", source)
|
|
47
|
+
|
|
48
|
+
lines = [line for line in result.splitlines() if line.strip() != ""]
|
|
49
|
+
return "\n".join(lines) + "\n"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def format_file(filepath: str) -> str:
|
|
53
|
+
try:
|
|
54
|
+
import black
|
|
55
|
+
mode = black.Mode()
|
|
56
|
+
with open(filepath, "r", encoding="utf-8") as f:
|
|
57
|
+
source = f.read()
|
|
58
|
+
return black.format_str(source, mode=mode)
|
|
59
|
+
except ImportError:
|
|
60
|
+
raise ImportError("black is not installed. Run: pip install black")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def clean_file(filepath: str) -> str:
|
|
64
|
+
no_comments = remove_comments_from_file(filepath)
|
|
65
|
+
|
|
66
|
+
try:
|
|
67
|
+
import black
|
|
68
|
+
mode = black.Mode()
|
|
69
|
+
return black.format_str(no_comments, mode=mode)
|
|
70
|
+
except ImportError:
|
|
71
|
+
return no_comments
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
from .generator import create_project
|
|
4
|
+
from .cleaner import remove_comments_from_file, format_file, clean_file
|
|
5
|
+
from .exceptions import InvalidProjectNameError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
args = sys.argv[1:]
|
|
10
|
+
|
|
11
|
+
if not args:
|
|
12
|
+
print("MelonCityAPI CLI")
|
|
13
|
+
print("")
|
|
14
|
+
print("Commands:")
|
|
15
|
+
print(" meloncityapi new <name> Create a new bot project")
|
|
16
|
+
print(" meloncityapi --deletecomments <file> Remove all comments from a file")
|
|
17
|
+
print(" meloncityapi --format <file> Format a file with black")
|
|
18
|
+
print(" meloncityapi --clean <file> Remove comments + format")
|
|
19
|
+
return
|
|
20
|
+
|
|
21
|
+
command = args[0]
|
|
22
|
+
|
|
23
|
+
if command == "new":
|
|
24
|
+
if len(args) < 2:
|
|
25
|
+
print("Usage: meloncityapi new <name>")
|
|
26
|
+
sys.exit(1)
|
|
27
|
+
name = args[1].strip('"').strip("'")
|
|
28
|
+
try:
|
|
29
|
+
path = create_project(name)
|
|
30
|
+
print(f"✅ Project '{name}' created at: {path}")
|
|
31
|
+
print(f"📁 Structure:")
|
|
32
|
+
print(f" {name}/")
|
|
33
|
+
print(f" ├── main.py")
|
|
34
|
+
print(f" ├── requirements.txt")
|
|
35
|
+
print(f" ├── .env")
|
|
36
|
+
print(f" └── cogs/")
|
|
37
|
+
print(f" └── example.py")
|
|
38
|
+
except InvalidProjectNameError as e:
|
|
39
|
+
print(f"❌ {e}")
|
|
40
|
+
sys.exit(1)
|
|
41
|
+
|
|
42
|
+
elif command == "--deletecomments":
|
|
43
|
+
if len(args) < 2:
|
|
44
|
+
print("Usage: meloncityapi --deletecomments <file>")
|
|
45
|
+
sys.exit(1)
|
|
46
|
+
filepath = args[1]
|
|
47
|
+
if not os.path.exists(filepath):
|
|
48
|
+
print(f"❌ File not found: {filepath}")
|
|
49
|
+
sys.exit(1)
|
|
50
|
+
result = remove_comments_from_file(filepath)
|
|
51
|
+
with open(filepath, "w", encoding="utf-8") as f:
|
|
52
|
+
f.write(result)
|
|
53
|
+
print(f"✅ Comments removed from: {filepath}")
|
|
54
|
+
|
|
55
|
+
elif command == "--format":
|
|
56
|
+
if len(args) < 2:
|
|
57
|
+
print("Usage: meloncityapi --format <file>")
|
|
58
|
+
sys.exit(1)
|
|
59
|
+
filepath = args[1]
|
|
60
|
+
if not os.path.exists(filepath):
|
|
61
|
+
print(f"❌ File not found: {filepath}")
|
|
62
|
+
sys.exit(1)
|
|
63
|
+
try:
|
|
64
|
+
result = format_file(filepath)
|
|
65
|
+
with open(filepath, "w", encoding="utf-8") as f:
|
|
66
|
+
f.write(result)
|
|
67
|
+
print(f"✅ Formatted: {filepath}")
|
|
68
|
+
except ImportError as e:
|
|
69
|
+
print(f"❌ {e}")
|
|
70
|
+
sys.exit(1)
|
|
71
|
+
|
|
72
|
+
elif command == "--clean":
|
|
73
|
+
if len(args) < 2:
|
|
74
|
+
print("Usage: meloncityapi --clean <file>")
|
|
75
|
+
sys.exit(1)
|
|
76
|
+
filepath = args[1]
|
|
77
|
+
if not os.path.exists(filepath):
|
|
78
|
+
print(f"❌ File not found: {filepath}")
|
|
79
|
+
sys.exit(1)
|
|
80
|
+
try:
|
|
81
|
+
result = clean_file(filepath)
|
|
82
|
+
with open(filepath, "w", encoding="utf-8") as f:
|
|
83
|
+
f.write(result)
|
|
84
|
+
print(f"✅ Cleaned (comments removed + formatted): {filepath}")
|
|
85
|
+
except ImportError as e:
|
|
86
|
+
print(f"❌ {e}")
|
|
87
|
+
sys.exit(1)
|
|
88
|
+
|
|
89
|
+
else:
|
|
90
|
+
print(f"❌ Unknown command: {command}")
|
|
91
|
+
print("Run 'meloncityapi' to see available commands.")
|
|
92
|
+
sys.exit(1)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == "__main__":
|
|
96
|
+
main()
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
from .templates import MAIN_PY, EXAMPLE_COG, REQUIREMENTS_TXT
|
|
4
|
+
from .exceptions import InvalidProjectNameError
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def create_project(name: str, path: str = None) -> str:
|
|
8
|
+
if not re.match(r"^[a-zA-Z0-9_\-]+$", name):
|
|
9
|
+
raise InvalidProjectNameError(f"Invalid project name: {name!r}")
|
|
10
|
+
|
|
11
|
+
base = path or os.getcwd()
|
|
12
|
+
project_path = os.path.join(base, name)
|
|
13
|
+
|
|
14
|
+
if os.path.exists(project_path):
|
|
15
|
+
raise InvalidProjectNameError(f"Folder '{name}' already exists!")
|
|
16
|
+
|
|
17
|
+
os.makedirs(project_path)
|
|
18
|
+
os.makedirs(os.path.join(project_path, "cogs"))
|
|
19
|
+
|
|
20
|
+
with open(os.path.join(project_path, "main.py"), "w", encoding="utf-8") as f:
|
|
21
|
+
f.write(MAIN_PY)
|
|
22
|
+
|
|
23
|
+
with open(os.path.join(project_path, "cogs", "example.py"), "w", encoding="utf-8") as f:
|
|
24
|
+
f.write(EXAMPLE_COG)
|
|
25
|
+
|
|
26
|
+
with open(os.path.join(project_path, "requirements.txt"), "w", encoding="utf-8") as f:
|
|
27
|
+
f.write(REQUIREMENTS_TXT)
|
|
28
|
+
|
|
29
|
+
with open(os.path.join(project_path, ".env"), "w", encoding="utf-8") as f:
|
|
30
|
+
f.write("TOKEN=your_bot_token_here\n")
|
|
31
|
+
|
|
32
|
+
return project_path
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
MAIN_PY = '''import discord
|
|
2
|
+
from discord.ext import commands
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
|
|
6
|
+
|
|
7
|
+
@bot.event
|
|
8
|
+
async def on_ready():
|
|
9
|
+
print(f"Logged in as {bot.user}")
|
|
10
|
+
for filename in os.listdir("./cogs"):
|
|
11
|
+
if filename.endswith(".py"):
|
|
12
|
+
await bot.load_extension(f"cogs.{filename[:-3]}")
|
|
13
|
+
|
|
14
|
+
bot.run("YOUR_TOKEN_HERE")
|
|
15
|
+
'''
|
|
16
|
+
|
|
17
|
+
EXAMPLE_COG = '''import discord
|
|
18
|
+
from discord.ext import commands
|
|
19
|
+
|
|
20
|
+
class Example(commands.Cog):
|
|
21
|
+
def __init__(self, bot):
|
|
22
|
+
self.bot = bot
|
|
23
|
+
|
|
24
|
+
@commands.command()
|
|
25
|
+
async def ping(self, ctx):
|
|
26
|
+
await ctx.send(f"Pong! {round(self.bot.latency * 1000)}ms")
|
|
27
|
+
|
|
28
|
+
def setup(bot):
|
|
29
|
+
bot.add_cog(Example(bot))
|
|
30
|
+
'''
|
|
31
|
+
|
|
32
|
+
REQUIREMENTS_TXT = '''py-cord>=2.4.0
|
|
33
|
+
python-dotenv
|
|
34
|
+
'''
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: meloncityapi
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CLI tool and library for Pycord Discord bots
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: discord,pycord,bot,cli,formatter
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# MelonCityAPI
|
|
11
|
+
|
|
12
|
+
CLI tool + library für Pycord Discord Bots.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
```
|
|
16
|
+
pip install meloncityapi
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Commands
|
|
20
|
+
|
|
21
|
+
### Neues Bot-Projekt erstellen
|
|
22
|
+
```
|
|
23
|
+
meloncityapi new "MeinBot"
|
|
24
|
+
```
|
|
25
|
+
Erstellt im aktuellen Verzeichnis:
|
|
26
|
+
```
|
|
27
|
+
MeinBot/
|
|
28
|
+
├── main.py
|
|
29
|
+
├── requirements.txt
|
|
30
|
+
├── .env
|
|
31
|
+
└── cogs/
|
|
32
|
+
└── example.py
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Kommentare entfernen
|
|
36
|
+
```
|
|
37
|
+
meloncityapi --deletecomments bot.py
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Code formatieren (benötigt black)
|
|
41
|
+
```
|
|
42
|
+
pip install black
|
|
43
|
+
meloncityapi --format bot.py
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Kommentare entfernen + formatieren
|
|
47
|
+
```
|
|
48
|
+
meloncityapi --clean bot.py
|
|
49
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
meloncityapi/__init__.py
|
|
4
|
+
meloncityapi/cleaner.py
|
|
5
|
+
meloncityapi/cli.py
|
|
6
|
+
meloncityapi/exceptions.py
|
|
7
|
+
meloncityapi/generator.py
|
|
8
|
+
meloncityapi/templates.py
|
|
9
|
+
meloncityapi.egg-info/PKG-INFO
|
|
10
|
+
meloncityapi.egg-info/SOURCES.txt
|
|
11
|
+
meloncityapi.egg-info/dependency_links.txt
|
|
12
|
+
meloncityapi.egg-info/entry_points.txt
|
|
13
|
+
meloncityapi.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
meloncityapi
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "meloncityapi"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "CLI tool and library for Pycord Discord bots"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
keywords = ["discord", "pycord", "bot", "cli", "formatter"]
|
|
13
|
+
dependencies = []
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
meloncityapi = "meloncityapi.cli:main"
|