Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/poetry migration #81

Merged
merged 7 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ coverage.xml
.vscode
.gitignore
secrets.json
.secrets.toml
.secrets.toml
2 changes: 0 additions & 2 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ labels: ''
assignees: ''

---


2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
python -m pytest -v
python -m pytest -v
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ guilds.json
answers.txt
*.pem
.python-version
*.db
*.db

# Pytest
.coverage
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ WORKDIR /app/harambot
ADD ./Makefile /app/harambot
ADD ./requirements.txt /app/harambot/
ADD ./harambot /app/harambot/harambot
ADD ./config /app/harambot/config

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get upgrade -y
RUN apt-get install -y gcc libc-dev make git libffi-dev python3-dev libxml2-dev libxslt-dev

RUN apt-get install -y default-libmysqlclient-dev
Expand All @@ -19,6 +18,4 @@ RUN pip install -U pip

RUN pip install -r requirements.txt

RUN ls -ltr /app/harambot

CMD ["python", "./harambot/bot.py"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ run-docker:
@echo "${BLUE}Running docker image.."
@echo "name: ${MODULE}"
@echo "tag: ${MODULE}:${TAG}${NC}\n"
@docker run --name ${MODULE} -d ${MODULE}:${TAG}
@docker run --name ${MODULE} -d ${MODULE}:${TAG}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ In order to properly configure your bot you will need the following:
2. Fill out the form as shown below, you can provide your own values for Application Name, Description, and Homepage URL. Once complete click the "Create App" button
![yahoo-app-details](/assests/yahoo-app-details.png)
3. Copy the Client ID and Client Secret values
![yahoo-app-secrets](/assests/yahoo-app-secrets.png)
![yahoo-app-secrets](/assests/yahoo-app-secrets.png)

### Yahoo League ID

Expand All @@ -54,7 +54,7 @@ You can find your league's ID under the settings page of your league

Harambot now supports heroku deployments!

Click the button at the top and fill out the form with your discord token and yahoo api client key and and secret.
Click the button at the top and fill out the form with your discord token and yahoo api client key and and secret.

![heroku-deployment](/assests/heroku-deployment.png)

Expand All @@ -63,12 +63,12 @@ Once the deployment is complete enable the dyno
![heroku-dyno](/assests/heroku-dyno.png)

### Local deployment
1. Clone this repository
1. Clone this repository

git clone [email protected]:DMcP89/harambot.git
cd harambot

2. Run the bot.
2. Run the bot.

### On local machine
make run
Expand Down Expand Up @@ -146,4 +146,4 @@ In order for the bot to work properly it requires the following intents:

### $RIP "My Season"

![rip](/assests/rip.PNG)
![rip](/assests/rip.PNG)
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"description": "Yahoo Consumer Key",
"value": "",
"required": "true"
},
},
"YAHOO_SECRET" : {
"description": "Yahoo Consumer Secret",
"value": "",
Expand Down
7 changes: 1 addition & 6 deletions config/example.secrets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@
DISCORD_TOKEN = 'Discord API Token'
YAHOO_KEY = 'Yahoo Client ID'
YAHOO_SECRET = 'Yahoo Client Secret'
GUILD_DB = 'harambot'
GUILD_DB_USER = 'harambot'
GUILD_DB_PASS = 'harambe'
GUILD_DB_HOST = 'localhost'
GUILD_DB_PORT = 3308
DATABASE_URL = 'sqlite:///harambot.db'
DATABASE_URL = 'sqlite:///harambot.db'
4 changes: 0 additions & 4 deletions config/settings.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
[default]
LOGLEVEL = "DEBUG"
# Supported databases are sqlite, mysql, and postgres
GUILDS_DATASTORE_TYPE = "sqlite"
# if using a sqlite database specify the path to the db file
GUILDS_DATASTORE_LOC = "harambot.db"
46 changes: 26 additions & 20 deletions harambot/bot.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
import os

import logging
import discord
from yahoo_fantasy_api import game
from yahoo_oauth import OAuth2


from discord.ext import commands
from cogs.meta import Meta
from cogs.misc import Misc
from cogs.yahoo import Yahoo
from config import settings
from database.models import Guild
from utils import configure_guild

#logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('harambot.py')
logger.setLevel(settings.loglevel)
from harambot.cogs.meta import Meta
from harambot.cogs.misc import Misc
from harambot.cogs.yahoo import YahooCog
from harambot.config import settings
from harambot.database.models import Guild
from harambot.utils import configure_guild

# logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("harambot.py")
if "LOGLEVEL" in settings:
logger.setLevel(settings.loglevel)
else:
logger.setLevel("INFO")

intents = discord.Intents.default()
intents.members = True
intents.messages = True
intents.message_content = True

bot = commands.Bot(command_prefix="$", description="", intents=intents)
bot.remove_command('help')

bot.remove_command("help")


@bot.event
async def on_ready():
await bot.add_cog(Meta(bot))
await bot.add_cog(Yahoo(bot, settings.yahoo_key, settings.yahoo_secret))
await bot.add_cog(YahooCog(bot, settings.yahoo_key, settings.yahoo_secret))
await bot.add_cog(Misc(bot))
if not Guild.table_exists():
Guild.create_table()
Expand All @@ -40,11 +38,19 @@ async def on_ready():
await bot.tree.sync(guild=guild)
logger.info("Everything's all ready to go~")


@bot.event
async def on_guild_join(guild):
logger.info("Joined {}".format(guild.name))
if not Guild.select().where(Guild.guild_id == str(guild.id)).exists():
await configure_guild(bot,guild.owner, guild.id)
await configure_guild(bot, guild.owner, guild.id)
logger.info("Guild not configured!")

bot.run(settings.discord_token, reconnect=True) # Where 'TOKEN' is your bot token


def run():
bot.run(
settings.discord_token, reconnect=True
) # Where 'TOKEN' is your bot token


run()
51 changes: 39 additions & 12 deletions harambot/cogs/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,54 @@
import discord
import logging

from utils import configure_guild
from harambot.utils import configure_guild

logger = logging.getLogger(__file__)
logger.setLevel(logging.INFO)


class Meta(commands.Cog):

def __init__(self, bot):
self.bot = bot

@commands.command("help")
async def help(self, ctx):
embed = discord.Embed(title="Harambot", description="Yahoo Fantasy Sports Bot for Discord", color=0xeee657)
embed.add_field(name="$ping", value="Gives the latency of harambot", inline=False)
embed.add_field(name="$RIP", value="Pay respects to Harambe", inline=False)
embed.add_field(name="$standings", value="Returns the current standings of your league", inline=False)
embed.add_field(name="$roster team_name", value="Returns the roster of the given team", inline=False)
embed.add_field(name="$stats player_name", value="Returns the details of the given player", inline=False)
embed.add_field(name="$trade", value="Create poll for latest trade for league approval", inline=False)
embed.add_field(name="$matchups", value="Returns the current weeks matchups", inline=False)
embed = discord.Embed(
title="Harambot",
description="Yahoo Fantasy Sports Bot for Discord",
color=0xEEE657,
)
embed.add_field(
name="$ping", value="Gives the latency of harambot", inline=False
)
embed.add_field(
name="$RIP", value="Pay respects to Harambe", inline=False
)
embed.add_field(
name="$standings",
value="Returns the current standings of your league",
inline=False,
)
embed.add_field(
name="$roster team_name",
value="Returns the roster of the given team",
inline=False,
)
embed.add_field(
name="$stats player_name",
value="Returns the details of the given player",
inline=False,
)
embed.add_field(
name="$trade",
value="Create poll for latest trade for league approval",
inline=False,
)
embed.add_field(
name="$matchups",
value="Returns the current weeks matchups",
inline=False,
)
await ctx.send(embed=embed)

@commands.command("ping")
Expand All @@ -32,8 +60,7 @@ async def ping(self, ctx):
await ctx.send(latency)

@commands.hybrid_command()

async def configure(self, ctx):
await ctx.send("Configuring guild...")
await configure_guild(self.bot, ctx.guild.owner, ctx.guild.id)
await ctx.send("Guild configured successfully")
await ctx.send("Guild configured successfully")
12 changes: 6 additions & 6 deletions harambot/cogs/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import discord
import logging

from database.models import Guild
from harambot.database.models import Guild

logger = logging.getLogger(__file__)
logger.setLevel(logging.INFO)


class Misc(commands.Cog):

def __init__(self, bot):
self.bot = bot

Expand All @@ -19,8 +19,8 @@ async def RIP(self, ctx, *args):
logger.info("RIP called")
guild = Guild.get(Guild.guild_id == str(ctx.guild.id))
respected = args[0] if args else "Harambe"
message = guild.RIP_text +" "+ respected
embed = discord.Embed(title="", description='', color=0xeee657)
message = guild.RIP_text + " " + respected
embed = discord.Embed(title="", description="", color=0xEEE657)
embed.set_image(url=guild.RIP_image_url)
await ctx.send(content=message,embed=embed)

await ctx.send(content=message, embed=embed)
Loading