-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from DMcP89/feature/rdb_integration
Feature/rdb integration
- Loading branch information
Showing
17 changed files
with
188 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# These are supported funding model platforms | ||
|
||
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 | ||
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ guilds.json | |
answers.txt | ||
*.pem | ||
.python-version | ||
*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
worker: make run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"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": { | ||
"HARAMBOT_YAHOO_KEY" : { | ||
"description": "Yahoo Consumer Key", | ||
"value": "", | ||
"required": "true" | ||
}, | ||
"HARAMBOT_YAHOO_SECRET" : { | ||
"description": "Yahoo Consumer Secret", | ||
"value": "", | ||
"required": "true" | ||
}, | ||
"HARAMBOT_DISCORD_TOKEN" : { | ||
"description": "Discord bot token", | ||
"value": "", | ||
"required": "true" | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[default] | ||
LOGLEVEL = "DEBUG" | ||
GUILDS_DATASTORE_LOC = "config/guilds.json" | ||
# Supported databases are sqlite, mysql, and postgres | ||
GUILDS_DATASTORE_TYPE = "sqlite" | ||
GUILDS_DATASTORE_LOC = "harambot.db" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
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 | ||
|
||
#logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger('harambot.py') | ||
logger.setLevel(settings.loglevel) | ||
|
||
intents = discord.Intents.default() | ||
intents.members = True | ||
|
||
bot = commands.Bot(command_prefix="$", description="", intents=intents) | ||
bot.remove_command('help') | ||
|
||
|
||
|
||
@bot.event | ||
async def on_ready(): | ||
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(guild.owner, guild.id) | ||
logger.info("Guild not configured!") | ||
|
||
|
||
async def configure_guild(owner, id): | ||
|
||
def check(m): | ||
return m.author == owner | ||
|
||
await owner.send("Thank you for adding Harambot to your server!") | ||
await owner.send("Please open the following link to authorize with Yahoo, respond with the code given after authorization") | ||
await owner.send("https://api.login.yahoo.com/oauth2/request_auth?redirect_uri=oob&response_type=code&client_id={}".format(settings.yahoo_key)) | ||
code = await bot.wait_for('message', timeout=60, check=check) | ||
encoded_creds = base64.b64encode(('{0}:{1}'.format(settings.yahoo_key, settings.yahoo_secret )).encode('utf-8')) | ||
details = requests.post( | ||
url='https://api.login.yahoo.com/oauth2/get_token', | ||
data={"code": code.clean_content, 'redirect_uri': 'oob', 'grant_type': 'authorization_code'}, | ||
headers = { | ||
'Authorization': 'Basic {0}'.format(encoded_creds.decode('utf-8')), | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
).json() | ||
details['token_time'] = time.time() | ||
await owner.send("Enter Yahoo League ID") | ||
leauge_id = await bot.wait_for('message', timeout=60, check=check) | ||
await owner.send("Enter Yahoo League Type(nfl, nhl, nba, mlb)") | ||
leauge_type = await bot.wait_for('message', timeout=60, check=check) | ||
await owner.send("Enter text to use with $RIP command") | ||
RIP_text = await bot.wait_for('message', timeout=60, check=check) | ||
await owner.send("Enter image url to use with $RIP command") | ||
RIP_image_url = await bot.wait_for('message', timeout=60, check=check) | ||
details["league_id"] = leauge_id.clean_content | ||
details["league_type"] = leauge_type.clean_content | ||
details["RIP_text"] = RIP_text.clean_content | ||
details["RIP_image_url"] = RIP_image_url.clean_content | ||
Guild.create(guild_id=id,**details) | ||
return | ||
|
||
bot.add_cog(Meta(bot)) | ||
bot.add_cog(Yahoo(bot, settings.yahoo_key, settings.yahoo_secret)) | ||
bot.add_cog(Misc(bot)) | ||
|
||
bot.run(settings.discord_token, bot=True, reconnect=True) # Where 'TOKEN' is your bot token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from enum import Enum | ||
|
||
class DatabaseType(Enum): | ||
SQLITE = 'sqlite' | ||
MYSQL = 'mysql' | ||
POSTGRES = 'postgres' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from peewee import * | ||
from config import settings | ||
from database.databasetype import DatabaseType | ||
|
||
if settings.guilds_datastore_type == DatabaseType.POSTGRES: | ||
database = PostgresqlDatabase(settings.guild_db,user=settings.guild_db_user, password=settings.guild_db_pass, | ||
host=settings.guild_db_host, port=settings.guild_db_port) | ||
elif settings.guilds_datastore_type == DatabaseType.MYSQL: | ||
database = MySQLDatabase(settings.guild_db,user=settings.guild_db_user, password=settings.guild_db_pass, | ||
host=settings.guild_db_host, port=settings.guild_db_port) | ||
elif settings.guilds_datastore_type == DatabaseType.SQLITE: | ||
database = SqliteDatabase(settings.guilds_datastore_loc) | ||
else: | ||
database = SqliteDatabase(':memory:') | ||
|
||
|
||
class BaseModel(Model): | ||
class Meta: | ||
database = database | ||
|
||
|
||
class Guild(BaseModel): | ||
guild_id = TextField(unique=True) | ||
access_token = TextField() | ||
refresh_token = TextField() | ||
expires_in = IntegerField() | ||
token_type = TextField() | ||
xoauth_yahoo_guid = TextField() | ||
token_time = BigIntegerField() | ||
league_id = TextField() | ||
league_type = TextField() | ||
RIP_text = TextField() | ||
RIP_image_url = TextField() | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ yahoo-fantasy-api==2.4.0 | |
yahoo-oauth==1.1 | ||
yarl==1.3.0 | ||
zipp==3.4.0 | ||
peewee==3.15.1 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.