From 1e1a3ab43ee42283fbf477351ee87b310d5fd24f Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Thu, 4 May 2017 03:22:27 +0000 Subject: [PATCH] Partial discordbot work --- discordbot/requirements.txt | 2 ++ discordbot/run.py | 4 ++++ discordbot/titanembeds/__init__.py | 0 discordbot/titanembeds/bot.py | 17 +++++++++++++++++ discordbot/titanembeds/database/__init__.py | 17 +++++++++++++++++ discordbot/titanembeds/database/guilds.py | 14 ++++++++++++++ 6 files changed, 54 insertions(+) create mode 100644 discordbot/requirements.txt create mode 100644 discordbot/run.py create mode 100644 discordbot/titanembeds/__init__.py create mode 100644 discordbot/titanembeds/bot.py create mode 100644 discordbot/titanembeds/database/__init__.py create mode 100644 discordbot/titanembeds/database/guilds.py diff --git a/discordbot/requirements.txt b/discordbot/requirements.txt new file mode 100644 index 0000000..ee91f00 --- /dev/null +++ b/discordbot/requirements.txt @@ -0,0 +1,2 @@ +discord.py +sqlalchemy-aio \ No newline at end of file diff --git a/discordbot/run.py b/discordbot/run.py new file mode 100644 index 0000000..1ec70b8 --- /dev/null +++ b/discordbot/run.py @@ -0,0 +1,4 @@ +from titanembeds.bot import client +from config import config + +client.run(config["bot-token"]) diff --git a/discordbot/titanembeds/__init__.py b/discordbot/titanembeds/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/discordbot/titanembeds/bot.py b/discordbot/titanembeds/bot.py new file mode 100644 index 0000000..55457f9 --- /dev/null +++ b/discordbot/titanembeds/bot.py @@ -0,0 +1,17 @@ +from config import config +import discord + +client = discord.Client() + +@client.event +async def on_ready(): + print('Titan -- DiscordBot') + print('Logged in as the following user:') + print(client.user.name) + print(client.user.id) + print('------') + await test() + +async def test(): + from titanembeds.database import db, Guilds, session + session.query(Guilds).all() \ No newline at end of file diff --git a/discordbot/titanembeds/database/__init__.py b/discordbot/titanembeds/database/__init__.py new file mode 100644 index 0000000..0c8a8db --- /dev/null +++ b/discordbot/titanembeds/database/__init__.py @@ -0,0 +1,17 @@ +from config import config +from sqlalchemy_aio import ASYNCIO_STRATEGY +import sqlalchemy as db +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() + +from .guilds import Guilds + +engine = db.create_engine(config["database-uri"]) + +Base.metadata.create_all(engine) + +from sqlalchemy.orm import sessionmaker +DBSession = sessionmaker() +DBSession.bind = engine +session = DBSession() \ No newline at end of file diff --git a/discordbot/titanembeds/database/guilds.py b/discordbot/titanembeds/database/guilds.py new file mode 100644 index 0000000..d80e9f2 --- /dev/null +++ b/discordbot/titanembeds/database/guilds.py @@ -0,0 +1,14 @@ +from titanembeds.database import db, Base + +class Guilds(Base): + __tablename__ = "guilds" + id = db.Column(db.Integer, primary_key=True) # Auto incremented id + guild_id = db.Column(db.String(255)) # Discord guild id + unauth_users = db.Column(db.Boolean()) # If allowed unauth users + + def __init__(self, guild_id): + self.guild_id = guild_id + self.unauth_users = True # defaults to true + + def __repr__(self): + return ''.format(self.id, self.guild_id) \ No newline at end of file