Skip to content

Commit

Permalink
Merge pull request #93 from DMcP89/dev
Browse files Browse the repository at this point in the history
Merging changes for 0.3.0-Beta Release
  • Loading branch information
DMcP89 authored Apr 23, 2023
2 parents 3956b7f + 0dd5f02 commit 4a4b48b
Show file tree
Hide file tree
Showing 41 changed files with 5,212 additions and 437 deletions.
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: ''

---


27 changes: 27 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Description

<!--- Describe your changes in detail here. -->

## Types of Changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply. -->
- [ ] Core
- [ ] Bugfix
- [ ] New feature
- [ ] Enhancement/optimization

## Issues Fixed or Closed by This PR

*

## Checklist

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] My code follows the code style of this project: [**Python**]()
- [ ] I have read the [**PR Checklist** document]() and have made the appropriate changes.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have read the [**CONTRIBUTING** document]().
- [ ] I have added tests to cover my changes.
- [ ] I have tested the changes and verified that they work and don't break anything (as well as I can manage).
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ guilds.json
answers.txt
*.pem
.python-version
*.db
*.db

# Pytest
.coverage

dist/
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
15 changes: 3 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
FROM python:3.10.7-slim

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 @@ -17,8 +10,6 @@ RUN apt-get install -y libpq-dev

RUN pip install -U pip

RUN pip install -r requirements.txt

RUN ls -ltr /app/harambot
RUN pip install harambot

CMD ["python", "./harambot/bot.py"]
CMD ["harambot"]
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ 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}\
-e DISCORD_TOKEN=${DISCORD_TOKEN}\
-e YAHOO_KEY=${YAHOO_KEY}\
-e YAHOO_SECRET=${YAHOO_SECRET}\
-e DATABASE_URL=${DATABASE_URL}\
-e RUN_MIGRATIONS=${RUN_MIGRATIONS}\
--rm ${MODULE}:${TAG}
80 changes: 62 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# Harambot
![Python](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-blue) ![License](https://img.shields.io/badge/License-MIT-green) ![Build](https://img.shields.io/github/workflow/status/DMcP89/harambot/Pytest) ![Version](https://img.shields.io/badge/version-0.2.1--Beta-red)
![Python](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-blue) ![License](https://img.shields.io/badge/License-MIT-green) ![Build](https://img.shields.io/github/actions/workflow/status/DMcP89/harambot/pytest.yml?branch=main) ![Version](https://img.shields.io/badge/version-0.3.0--Beta-red)

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)


A Yahoo Fantasy sports bot for Discord.

## Commands
$ping - Gives the latency of harambot
$RIP - Pay respects
$standings - Returns the current standings of the current league
$roster "Team name" - Returns the roster of the given team
$stats "Player Name" - Returns the details of the given player
$trade - Create poll for latest trade for league approval
$matchups - Returns the current weeks matchups
/ping - Gives the latency of harambot
/RIP - Pay respects
/standings - Returns the current standings of the current league
/roster "Team name" - Returns the roster of the given team
/stats "Player Name" - Returns the details of the given player
/trade - Create poll for latest trade for league approval
/matchups - Returns the current weeks matchups
/waiver - Returns the waiver wire tranasactions from the previous 24 hours
/configure - Configure the bot for your guild

## Prerequisites

Expand Down Expand Up @@ -41,7 +43,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,21 +56,49 @@ 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)

Once the deployment is complete enable the dyno

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

### Local deployment
1. Clone this repository
### Install package from PIP

1. Install the harambot package using pip

pip install harambot

2. Export the following environment variables

```
export DISCORD_TOKEN='[YOUR DISCORD TOKEN]'
export YAHOO_KEY='[YOUR YAHOO API CLIENT ID]'
export YAHOO_SECRET='[YOUR YAHOO API CLIENT SECRET]'
export DATABASE_URL='[YOUR DATABASE URL]'
```

3. Run the bot

harambot

### Run from source
1. Clone this repository

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

2. Run the bot.
2. Export the following environment variables

```
export DISCORD_TOKEN='[YOUR DISCORD TOKEN]'
export YAHOO_KEY='[YOUR YAHOO API CLIENT ID]'
export YAHOO_SECRET='[YOUR YAHOO API CLIENT SECRET]'
export DATABASE_URL='[YOUR DATABASE URL]'
```

3. Run the bot.

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

### Configure your guild

* When the bot joins your guild for the first time it will DM you to complete the guild setup
* Once your bot is added to your guild you can configure it by sending a direct message to the bot with the following command:


![discord-config-commnd](/assests/harambot_configure_1.png)

* Use the Login with Yahoo button to authenticate with Yahoo and get your Yahoo token


![discord-config-yahoo](/assests/harambot_configure_4.png)

* Use the Configure Guild button to configure your guild for the bot


![discord-config-guild](/assests/harambot_configure_2.png)


* You can reconfigure your guild by running the configure command and clicking the Configure Guild button.

![discord-config-dm](/assests/discord-config-dm.png)

* You can reconfigure your guild by running the configure slash command from your guild
![discord-config-guild](/assests/harambot_configure_3.png)

![discord-config-command](/assests/discord-config-command.png)

## Command Examples

Expand Down Expand Up @@ -146,4 +190,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
Binary file added assests/harambot_configure_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assests/harambot_configure_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assests/harambot_configure_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assests/harambot_configure_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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'
6 changes: 2 additions & 4 deletions config/settings.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
[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"
VERSION = "0.0.3-Beta"
RUN_MIGRATIONS = false
49 changes: 29 additions & 20 deletions harambot/bot.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,59 @@
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.database.migrations import migrations

# 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()
if "RUN_MIGRATIONS" in settings and settings.run_migrations:
migrations[settings.version]()
for guild in bot.guilds:
bot.tree.copy_global_to(guild=guild)
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)
logger.info("Guild not configured!")

bot.run(settings.discord_token, reconnect=True) # Where 'TOKEN' is your bot token
await guild.owner.send(
"""Thank you for adding Harambot to your server!
Please complete your setup by running the /configure command!"""
)


def run():
bot.run(settings.discord_token, reconnect=True)


run()
Loading

0 comments on commit 4a4b48b

Please sign in to comment.