Skip to content

Commit

Permalink
Made setuptools friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
Amdrel committed Dec 1, 2019
1 parent 4d363bb commit f6d39e5
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
env.sh
__pycache__/
*.pyc
*.egg-info
dist/
build/
log/
2 changes: 1 addition & 1 deletion lorewalker-cho.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ cd "${BASH_SOURCE%/*}" || exit
source ./venv/bin/activate
source ./env.sh

exec ./main.py "$@"
exec ./lorewalker_cho/__main__.py "$@"
File renamed without changes.
13 changes: 10 additions & 3 deletions main.py → lorewalker_cho/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,25 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# pylint: disable=wrong-import-position

"""Command-line interface to start cho."""

import argparse
import logging
import os
import sys

import redis
import sqlalchemy as sa

import config
PARENT_PATH = os.path.dirname((os.path.dirname(os.path.realpath(__file__))))
sys.path.append(PARENT_PATH)

import lorewalker_cho.config as config

from lorewalker_cho import LorewalkerCho
from lorewalker_cho.bot import LorewalkerCho

DISCORD_TOKEN = os.environ["CHO_DISCORD_TOKEN"]
SQLALCHEMY_POOL_SIZE = int(os.environ.get("SQLALCHEMY_POOL_SIZE", 6))
Expand All @@ -39,7 +45,8 @@
def main():
"""Entrypoint for Cho on the CLI."""

parser = argparse.ArgumentParser(description="Start a Cho Trivia worker.")
parser = argparse.ArgumentParser(
description="Start a Lorewalker Cho worker.")
parser.add_argument("--debug", action='store_true', default=False,
help="Enable debug logging.")
parser.add_argument("--log", help="Specify a log file path to log to.")
Expand Down
17 changes: 8 additions & 9 deletions lorewalker_cho.py → lorewalker_cho/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@
import shlex
import traceback

from commands import CommandsMixin

import discord
import redis

from discord.message import Message
from redis import Redis
from sqlalchemy.engine import Engine

import utils
import sql.guild
import lorewalker_cho.utils as utils
import lorewalker_cho.sql.guild as sql_guild

from game import GameMixin
from lorewalker_cho.commands import CommandsMixin
from lorewalker_cho.game import GameMixin

LOGGER = logging.getLogger("cho")

Expand Down Expand Up @@ -99,7 +98,7 @@ async def on_message(self, message: Message):

# Gets the configured prefix if there is one. If there isn't one a
# default that's hardcoded is used instead.
results = sql.guild.get_guild(self.engine, guild_id)
results = sql_guild.get_guild(self.engine, guild_id)
if results:
_, config = results
prefix = utils.get_prefix(config)
Expand Down Expand Up @@ -128,10 +127,10 @@ async def handle_command(self, message):

# This is a good opportunity to make sure the guild we're getting a
# command from is setup properly in the database.
guild_query_results = sql.guild.get_guild(self.engine, guild_id)
guild_query_results = sql_guild.get_guild(self.engine, guild_id)
if not guild_query_results:
LOGGER.info("Got command from new guild: %s", guild_id)
sql.guild.create_guild(self.engine, guild_id)
sql_guild.create_guild(self.engine, guild_id)
config = {}
else:
_, config = guild_query_results
Expand Down Expand Up @@ -185,7 +184,7 @@ async def handle_message_response(self, message: Message):

guild_id = guild_id = message.guild.id

guild_query_results = sql.guild.get_guild(self.engine, guild_id)
guild_query_results = sql_guild.get_guild(self.engine, guild_id)
if guild_query_results:
_, config = guild_query_results
else:
Expand Down
12 changes: 7 additions & 5 deletions commands.py → lorewalker_cho/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

import discord
import redis
import sql.guild

from utils import cho_command
import lorewalker_cho.sql.guild as sql_guild
import lorewalker_cho.sql.scoreboard as sql_scoreboard

from lorewalker_cho.utils import cho_command

CMD_HELP = "help"
CMD_SCOREBOARD = "scoreboard"
Expand Down Expand Up @@ -162,7 +164,7 @@ async def handle_scoreboard_command(self, message, args, config):
guild_id = message.guild.id
guild = self.get_guild(guild_id)

guild_scoreboard = sql.scoreboard.get_scoreboard(self.engine, guild_id)
guild_scoreboard = sql_scoreboard.get_scoreboard(self.engine, guild_id)
if not guild_scoreboard:
guild_scoreboard = {}
else:
Expand Down Expand Up @@ -221,7 +223,7 @@ async def handle_set_channel(self, message, args, config):
return

config["trivia_channel"] = int(trivia_channel_re_match.group(1))
sql.guild.update_guild_config(self.engine, guild_id, config)
sql_guild.update_guild_config(self.engine, guild_id, config)

await message.channel.send(
"The trivia channel is now in {}.".format(trivia_channel_id)
Expand Down Expand Up @@ -254,7 +256,7 @@ async def handle_set_prefix(self, message, args, config):
return

config["prefix"] = new_prefix
sql.guild.update_guild_config(self.engine, guild_id, config)
sql_guild.update_guild_config(self.engine, guild_id, config)

await message.channel.send(f"My prefix is now \"{new_prefix}\".")

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions game.py → lorewalker_cho/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
from discord.channel import TextChannel
from discord.guild import Guild

import sql.guild
import sql.scoreboard
import lorewalker_cho.sql.active_game as sql_active_game
import lorewalker_cho.sql.scoreboard as sql_scoreboard

from game_state import GameState
from lorewalker_cho.game_state import GameState

SHORT_WAIT_SECS = 5
LONG_WAIT_SECS = 30
Expand All @@ -47,7 +47,7 @@ def __cleanup_game(self, guild_id: int):
async def resume_incomplete_games(self):
"""Resumes all inactive games, usually caused by the bot going down."""

incomplete_games = sql.active_game.get_incomplete_games(self.engine)
incomplete_games = sql_active_game.get_incomplete_games(self.engine)

LOGGER.info(
"Found %d incomplete games that need to be resumed",
Expand Down Expand Up @@ -214,7 +214,7 @@ async def complete_game(self, channel, game_state):
ties = 0
scoreboard = ""

guild_scoreboard = sql.scoreboard.get_scoreboard(self.engine, guild_id)
guild_scoreboard = sql_scoreboard.get_scoreboard(self.engine, guild_id)
if not guild_scoreboard:
guild_scoreboard = {}
else:
Expand All @@ -238,7 +238,7 @@ async def complete_game(self, channel, game_state):
guild_member_score += score
guild_scoreboard[str(user_id)] = guild_member_score

sql.scoreboard.save_scoreboard(self.engine, guild_id, guild_scoreboard)
sql_scoreboard.save_scoreboard(self.engine, guild_id, guild_scoreboard)

if ties == 0:
await channel.send(
Expand Down
12 changes: 6 additions & 6 deletions game_state.py → lorewalker_cho/game_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

from sqlalchemy.engine import Engine

import utils
import sql.active_game
import lorewalker_cho.utils as utils
import lorewalker_cho.sql.active_game as sql_active_game

from data.questions import DEFAULT_QUESTIONS
from lorewalker_cho.data.questions import DEFAULT_QUESTIONS

CURRENT_REVISION = 0

Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(
self.waiting = False

if self.save_to_db:
sql.active_game.save_game_state(self.engine, self)
sql_active_game.save_game_state(self.engine, self)

@staticmethod
def __select_questions(questions: list, count=10) -> list:
Expand Down Expand Up @@ -123,7 +123,7 @@ def stop_game(self):
self.__complete_game()

if self.save_to_db:
sql.active_game.save_game_state(self.engine, self)
sql_active_game.save_game_state(self.engine, self)

def step(self):
"""Advances the game forward to the next question.
Expand All @@ -139,7 +139,7 @@ def step(self):
self.__complete_game()

if self.save_to_db:
sql.active_game.save_game_state(self.engine, self)
sql_active_game.save_game_state(self.engine, self)

def bump_score(self, user_id: int, amount=1):
"""Increases the score of a player by an amount.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion sql/active_game.py → lorewalker_cho/sql/active_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from sqlalchemy.engine.interfaces import Connectable
from sqlalchemy.engine.result import ResultProxy

from sql.schema import GUILDS, ACTIVE_GAMES
from lorewalker_cho.sql.schema import GUILDS, ACTIVE_GAMES

LOGGER = logging.getLogger("cho")

Expand Down
3 changes: 2 additions & 1 deletion sql/guild.py → lorewalker_cho/sql/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

from sqlalchemy.engine.interfaces import Connectable
from sqlalchemy.engine.result import ResultProxy
from sql.schema import GUILDS

from lorewalker_cho.sql.schema import GUILDS


def get_guild(conn: Connectable, guild_id: int) -> tuple:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion sql/scoreboard.py → lorewalker_cho/sql/scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from sqlalchemy.engine.interfaces import Connectable
from sqlalchemy.engine.result import ResultProxy

from sql.schema import GUILDS, SCOREBOARDS
from lorewalker_cho.sql.schema import GUILDS, SCOREBOARDS

LOGGER = logging.getLogger("cho")

Expand Down
File renamed without changes.
32 changes: 32 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Lorewalker Cho is a Discord bot that plays WoW-inspired trivia games.
# Copyright (C) 2019 Walter Kuppens
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""setup.py for lorewalker_cho."""

from setuptools import setup, find_packages

setup(
name="lorewalker_cho",
packages=find_packages(),
entry_points={
"console_scripts": ["lorewalker_cho = lorewalker_cho.__main__:main"]
},
version="0.99.4",
description="Lorewalker Cho is a Discord bot that plays WoW-inspired "
"trivia games.",
author="Walter Kuppens",
author_email="reshurum@gmail.com",
)

0 comments on commit f6d39e5

Please sign in to comment.