Skip to content

Commit 7ce8b8e

Browse files
authored
Merge pull request #42 from mensch272/bots
Hostable discord bot
2 parents 7ad0cb8 + 47ab523 commit 7ce8b8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1568
-76
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
- Added pre-commit checks for consistent style
1515
- Added pre-commit badge to README.md
1616
- Added change log to database migrations README.md
17+
- Added discord bot with (most functions are only available in private):
18+
- Download novel to multiple formats
19+
- Search for novels using a query
20+
- Added alternative method to acquire package version if importlib fails
1721

1822
### Changed
1923

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bot: python -m novelsave runbot discord

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
![PyPI](https://img.shields.io/pypi/v/novelsave)
44
![Python Version](https://img.shields.io/badge/Python-v3.8-blue)
5-
![Repo Size](https://img.shields.io/github/repo-size/mensch272/novelsave)
6-
[![Contributors](https://img.shields.io/github/contributors/mensch272/novelsave)](https://github.com/mensch272/novelsave/graphs/contributors)
75
![Last Commit](https://img.shields.io/github/last-commit/mensch272/novelsave/main)
86
![Issues](https://img.shields.io/github/issues/mensch272/novelsave)
97
![Pull Requests](https://img.shields.io/github/issues-pr/mensch272/novelsave)
108
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/mensch272/novelsave/main.svg)](https://results.pre-commit.ci/latest/github/mensch272/novelsave/main)
119
[![License](https://img.shields.io/github/license/mensch272/novelsave)](LICENSE)
10+
![Discord](https://img.shields.io/discord/911120379341307904)
1211

1312
This is a tool to download and convert novels from popular sites to e-books.
1413

1514
> **v0.7.+ is not compatible with previous versions**
1615
1716
## Install
1817

18+
### Local
19+
1920
```bash
2021
pip install novelsave
2122
```
@@ -26,6 +27,32 @@ or
2627
pip install git+https://github.com/mensch272/novelsave.git
2728
```
2829

30+
### Chatbots
31+
32+
#### Discord
33+
34+
Join our server: https://discord.gg/eFgtrKTFt3
35+
36+
##### Environmental Variables
37+
38+
The default environmental variables are shown below. Modify them to your liking when deploying.
39+
40+
`DISCORD_TOKEN` is required, others are optional.
41+
42+
```shell
43+
DISCORD_TOKEN= # Required: discord bot token
44+
DISCORD_SESSION_TIMEOUT=10 # Minutes
45+
DISCORD_DOWNLOAD_THREADS=4
46+
DISCORD_SEARCH_LIMIT=20 # Maximum results to show
47+
DISCORD_SEARCH_DISABLED=no # Disable search functionality
48+
```
49+
50+
#### Heroku Deployment
51+
52+
Fill out the following form and set the environmental variables.
53+
54+
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
55+
2956
## Usage
3057

3158
### Basic

novelsave/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
from importlib.metadata import version
1+
from importlib.metadata import version, PackageNotFoundError
2+
3+
try:
4+
__version__ = version("novelsave")
5+
except PackageNotFoundError:
6+
import re
7+
from pathlib import Path
8+
9+
pyproject = Path(__file__).parent.parent / "pyproject.toml"
10+
with pyproject.open("r") as f:
11+
text = f.read()
12+
13+
__version__ = re.search(r'version = "(.+?)"', text).group(1)
214

3-
__version__ = version("novelsave")
415
__source__ = "https://github.com/mHaisham/novelsave"

novelsave/__main__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
from .cli import main
1+
import sys
22

3+
from novelsave.client import cli
34

45
if __name__ == "__main__":
5-
main()
6+
if sys.argv[1:] == ["runbot", "discord"]:
7+
from novelsave.client.bots import discord
8+
9+
discord.main()
10+
else:
11+
cli.main()

novelsave/client/__init__.py

Whitespace-only changes.

novelsave/client/bots/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from . import config
2+
from . import containers
3+
from . import bot
4+
from . import session
5+
from . import endpoints
6+
from .main import main

novelsave/client/bots/discord/bot.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import sys
2+
3+
from loguru import logger
4+
5+
from . import config
6+
7+
logger.configure(**config.logger_config())
8+
9+
try:
10+
from nextcord.ext import commands
11+
except ImportError as e:
12+
logger.exception(e)
13+
sys.exit(1)
14+
15+
16+
bot = commands.Bot("$")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from nextcord.ext import commands
2+
3+
4+
async def direct_only(ctx: commands.Context):
5+
"""Custom direct only check
6+
7+
This check returns true when one of the below checks are true
8+
- The message author is bot owner and is invoked with help
9+
- The message is not from a guild
10+
"""
11+
if await ctx.bot.is_owner(ctx.author) and ctx.invoked_with == "help":
12+
return True
13+
14+
if ctx.guild is not None:
15+
raise commands.CheckFailure(
16+
f"You may not use this command inside a guild. "
17+
f"Use the '{ctx.clean_prefix}dm' to start a private session.",
18+
)
19+
20+
return True

0 commit comments

Comments
 (0)