Skip to content

Commit

Permalink
Merge pull request #59 from DMcP89/dev
Browse files Browse the repository at this point in the history
0.2.0 Beta Release
  • Loading branch information
DMcP89 authored Sep 30, 2022
2 parents 8c4fb71 + 659b743 commit 1483d8d
Show file tree
Hide file tree
Showing 32 changed files with 309 additions and 257 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ coverage.xml
.venv
.vscode
.gitignore
secrets.json
.secrets.toml
4 changes: 2 additions & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
github: [DMcP89]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
ko_fi: davemcpherson
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
custom: [https://www.buymeacoffee.com/wochstudios]
4 changes: 2 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python package
name: Pytest

on: [push, pull_request]

Expand All @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ guilds.json
# Ignore dynaconf secret files
.secrets.*
answers.txt
*.pem
*.pem
.python-version
*.db
21 changes: 15 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
FROM python:3.7.4-slim
FROM python:3.10.7-slim

WORKDIR /app/harambot

ADD . /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 && \
apt-get upgrade -y && \
apt-get install -y gcc libc-dev make git libffi-dev python3-dev libxml2-dev libxslt-dev
RUN apt-get update
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

RUN apt-get install -y libpq-dev

RUN pip install -U pip

RUN pip install -r requirements.txt

CMD ["make", "run"]
RUN ls -ltr /app/harambot

CMD ["python", "./harambot/bot.py"]
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@ MODULE := harambot
BLUE='\033[0;34m'
NC='\033[0m' # No color

TAG := $(shell git describe --tags --always)
TAG := $(shell git describe --tags --always --abbrev=0)

showenv:
@echo 'Environment:'
@echo '-----------------------'
@echo 'Module: '${MODULE}
@echo 'Tag: '${TAG}

configure:
@pip install -r requirements.txt
@./scripts/configure.sh

test:
@python -m pytest -v

run:
@python ${MODULE}/${MODULE}.py
@pip install -r requirements.txt
@python ${MODULE}/bot.py

build-docker:
build-image:
@echo "${BLUE}Building docker image.."
@echo "name: ${MODULE}"
@echo "tag: ${MODULE}:${TAG}${NC}\n"
Expand All @@ -32,4 +29,4 @@ run-docker:
@echo "${BLUE}Running docker image.."
@echo "name: ${MODULE}"
@echo "tag: ${MODULE}:${TAG}${NC}\n"
@docker run ${MODULE}:${TAG}
@docker run --name ${MODULE} -d ${MODULE}:${TAG}
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worker: make run
89 changes: 51 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Harambot
[![Python 3.7](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/downloads/release/python-360/)
![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)

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


A Yahoo Fantasy sports bot for Discord.

Expand All @@ -8,7 +11,7 @@ A Yahoo Fantasy sports bot for Discord.
$RIP - Pay respects
$standings - Returns the current standings of the current league
$roster "Team name" - Returns the roster of the given team
$player_details "Player Name" - Returns the details of the given player
$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

Expand All @@ -17,7 +20,6 @@ A Yahoo Fantasy sports bot for Discord.
In order to properly configure your bot you will need the following:

* Discord API Token
* Discord Guild ID
* Yahoo API Client Id & Secret
* Yahoo League ID

Expand All @@ -31,13 +33,6 @@ In order to properly configure your bot you will need the following:
4. Click the "Copy" button under token to copy your bots API token to your clipboard
![discord-copy-token](/assests/discord-copy-token.png)

### Discord Guild ID
1. Open the discord web app - https://discord.com/app
2. Navigate to your guild
3. Copy the guild ID from the url
```
https://discord.com/channels/[guild-id-is-here]/12345678910
```

### Yahoo API Client ID & Secret

Expand All @@ -53,44 +48,65 @@ In order to properly configure your bot you will need the following:
You can find your league's ID under the settings page of your league
![yahoo-league-id](/assests/yahoo-league-id.png)

## Install
## Deployment

### Heroku

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.

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

### Local deployment
1. Clone this repository

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

2. Configure the bot

* Create a copy of example.secrets.toml named .secrets.toml
```
cd config
cp example.secrets.toml .secrets.toml
```
* Update .secrets.toml with the values from the prerequisites section
```
[default]
DISCORD_TOKEN = 'Discord API Token'
YAHOO_KEY = 'Yahoo Client ID'
YAHOO_SECRET = 'Yahoo Client Secret'
```
* Run make configure from the root directory
```
cd ..
make configure
```
3. Run the bot.
2. Run the bot.

### On local machine
make run
### With Docker
make build-docker
make build-image
make run-docker

## Setup

### Add the bot to your guild
1. Generate a OAuth url from the discord developer portal using the bot scope and the following permissions:

* Send Messages
* Send Messages in Threads
* Embed Links
* Attach Files
* Read Message History
* Add Reactions
* Use Slash Commands

The permission value should be 277025507392

![discord-oauth](/assests/discord-oauth-generator.png)

2. Navigate to the generated url in a web browser and authorize the bot for your guild

![discord-oauth-url-1](/assests/discord-oauth-url-authorize-1.png)
![discord-oauth-url-2](/assests/discord-oauth-url-authorize-2.png)

### Configure your guild

1. From your guild run the configure slash command

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

2. The bot will DM you to complete the guild setup

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

## Command Examples

### $player_details Rashaad Penny
### $stats Rashaad Penny

![player-details](/assests/player_details.PNG)

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

### $RIP "My Season"

![rip](/assests/rip.PNG)
## Support Harambot!
<a href="https://www.buymeacoffee.com/wochstudios" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
![rip](/assests/rip.PNG)
36 changes: 36 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "Harambot",
"description": "A Yahoo Fantasy sports bot for Discord.",
"keywords": [
"fantasy football",
"discord",
"yahoo",
"chat bot",
"ff",
"harambe"
],
"website" : "https://github.com/DMcP89/harambot",
"repository": "https://github.com/DMcP89/harambot",
"env": {
"YAHOO_KEY" : {
"description": "Yahoo Consumer Key",
"value": "",
"required": "true"
},
"YAHOO_SECRET" : {
"description": "Yahoo Consumer Secret",
"value": "",
"required": "true"
},
"DISCORD_TOKEN" : {
"description": "Discord bot token",
"value": "",
"required": "true"
}
},
"addons": [
"heroku-postgresql"
]


}
Binary file added assests/discord-config-command.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/discord-config-dm.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/discord-oauth-generator.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/discord-oauth-url-authorize-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/discord-oauth-url-authorize-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/heroku-deployment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion config/example.secrets.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
[default]
DISCORD_TOKEN = 'Discord API Token'
YAHOO_KEY = 'Yahoo Client ID'
YAHOO_SECRET = 'Yahoo Client Secret'
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'
5 changes: 4 additions & 1 deletion config/settings.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[default]
LOGLEVEL = "DEBUG"
GUILDS_DATASTORE_LOC = "config/guilds.json"
# 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"
53 changes: 53 additions & 0 deletions harambot/bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os

import logging
import discord
import requests
import base64
import time
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)

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.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(Misc(bot))
if not Guild.table_exists():
Guild.create_table()
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
Loading

0 comments on commit 1483d8d

Please sign in to comment.