Skip to content

Commit

Permalink
feat: setup.py
Browse files Browse the repository at this point in the history
- Added setup.py
- Adjusted internal structure and launcher to work with it
- Reworked --show-logs flag. Now if not enabled, it will still print
critical errors. May be confusing, but program ending without output
would be also confusing.
- Updated readme to highlight installation with setup.py
- Set bot's version to 1.0.0
  • Loading branch information
moonburnt committed Aug 19, 2021
1 parent 54498d1 commit 59e0c87
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 50 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ improvements, but for the most - bot is already done and ready for daily usage.

## Installation:

## From source:

- `git clone https://github.com/moonburnt/notashark.git`
- `cd notashark`
- `pip install -r requirements.txt`
- `python setup.py install`

## Usage:

Expand All @@ -41,16 +43,16 @@ cronjob and forget about. Below are examples of how to run bot without it.

### Basic:

- Run `python ./notashark --show-logs --token=YOUR_TOKEN` (where YOUR_TOKEN is
- Run `python -m notashark --show-logs --token=YOUR_TOKEN` (where YOUR_TOKEN is
your discord bot's token)
This will run bot in its default configuration, suitable for most needs.

### Recommended:

- Set 'NOTASHARK_DISCORD_KEY' environment variable to your bot's discord token
- `python ./notashark -h` to get list of all available launch flags
- Run `python ./notashark` with whatever flags you like (there is no need to pass
token as launch argument again - it will be fetched from envars).
- `python -m notashark -h` to get list of all available launch flags
- Run `python -m notashark` with whatever flags you like (there is no need to
pass token as launch argument again - it will be fetched from envars).
This is a bit more secure thus recommended way to use this bot.

## LICENSE:
Expand Down
5 changes: 4 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
black>=21.7b0
black==21.7b0
setuptools>=57.4.0
wheel>=0.36.2
twine>=3.4.1
5 changes: 1 addition & 4 deletions launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
NOTASHARK_DISCORD_KEY=""

# Dont touch anything below, unless you know what you are doing
botname="notashark"
botpath="."
scriptname=$(basename "$0")

if [ -z "$NOTASHARK_DISCORD_KEY" ]; then
Expand All @@ -16,5 +14,4 @@ if [ -z "$NOTASHARK_DISCORD_KEY" ]; then
fi
export NOTASHARK_DISCORD_KEY

chmod +x "$botpath/$botname"
exec python "$botpath/$botname" --show-logs
exec python -m "notashark" --show-logs
7 changes: 6 additions & 1 deletion notashark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
## You should have received a copy of the GNU General Public License
## along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.txt

from .src import *
from .parts import *
from .settings import *
from .fetcher import *
from .embeds import *
from .discord_bot import *
from .cli import *
import logging

logging.getLogger(__name__).addHandler(logging.NullHandler())
6 changes: 3 additions & 3 deletions notashark/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
## You should have received a copy of the GNU General Public License
## along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.txt

if __name__ == "__main__":
import cli
from notashark.cli import main

cli.main()
if __name__ == "__main__":
main()
20 changes: 13 additions & 7 deletions notashark/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
## You should have received a copy of the GNU General Public License
## along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.txt

from src import fetcher, settings, discord_bot
from notashark import fetcher, settings, discord_bot
import argparse
from os import environ
from sys import exit
Expand Down Expand Up @@ -52,6 +52,12 @@ def main():
file_handler.setFormatter(formatter)
log.addHandler(file_handler)

# doing it these, because seeing critical errors still may be important
terminal_handler = logging.StreamHandler()
terminal_handler.setFormatter(formatter)
# terminal_handler.setLevel(logging.ERROR)
log.addHandler(terminal_handler)

ap = argparse.ArgumentParser()
ap.add_argument(
"--token",
Expand Down Expand Up @@ -82,7 +88,10 @@ def main():
ap.add_argument(
"--show-logs",
action="store_true",
help="Enable showcase of logs in terminal",
help=(
"Enable showcase of logs in terminal. "
"Else only critical errors will be shown"
),
)
# TODO: maybe add arg to override log file location/name?
ap.add_argument(
Expand All @@ -94,11 +103,8 @@ def main():
if args.debug:
log.setLevel(logging.DEBUG)

if args.show_logs:
terminal_handler = logging.StreamHandler()
terminal_handler.setFormatter(formatter)
# terminal_handler.setLevel(logging.ERROR)
log.addHandler(terminal_handler)
if not args.show_logs:
terminal_handler.setLevel(logging.CRITICAL)

bot_token = args.token or environ.get("NOTASHARK_DISCORD_KEY", None)
if not bot_token:
Expand Down
2 changes: 1 addition & 1 deletion notashark/src/discord_bot.py → notashark/discord_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

# This module contains discord bot itaswell as directly related functionality

from notashark import fetcher, settings, embeds
import discord
from . import fetcher, settings, embeds
from asyncio import sleep
import logging
import threading
Expand Down
6 changes: 4 additions & 2 deletions notashark/src/embeds.py → notashark/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

# This module contains functions related to processing embeds

from notashark import parts
import logging
from discord import utils, Embed, File
from . import parts
from datetime import datetime

log = logging.getLogger(__name__)
Expand All @@ -30,7 +30,9 @@ def sanitize(data: str) -> str:
return str(utils.escape_mentions(utils.escape_markdown(data)))


def make_server_embed(data: parts.KagServerInfo) -> parts.EmbedStorage:
def make_server_embed(
data: parts.KagServerInfo,
) -> parts.EmbedStorage:
"""Build single server embed out of provided data"""

# This is a nasty workaround to fix the discord's "clever" caching issue
Expand Down
4 changes: 2 additions & 2 deletions notashark/src/fetcher.py → notashark/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

# This module contains everything related to fetching and processing data from api

from notashark import parts
from notashark.embeds import sanitize
import requests
import json
from pykagapi import kag, kagstats
from threading import Lock
from re import sub
from time import sleep
from io import BytesIO
from . import parts
from .embeds import sanitize
import logging

log = logging.getLogger(__name__)
Expand Down
File renamed without changes.
File renamed without changes.
24 changes: 0 additions & 24 deletions notashark/src/__init__.py

This file was deleted.

30 changes: 30 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from setuptools import find_packages, setup

with open("README.md") as f:
long_description = f.read()

setup(
name="notashark",
version="1.0.0",
description="notashark - discord bot for King Arthur's Gold",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/moonburnt/notashark",
author="moonburnt",
author_email="moonburnt@disroot.org",
license="GPLv3",
classifiers=[
"Programming Language :: Python :: 3",
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
],
packages=find_packages(),
install_requires=[
"pykagapi==0.2.1",
"discord.py==1.7.3",
"requests>=2.25.1",
],
entry_points={
"console_scripts": ["notashark = notashark:cli.main"],
},
)

0 comments on commit 59e0c87

Please sign in to comment.