Partial discordbot work

This commit is contained in:
Jeremy Zhang 2017-05-04 03:22:27 +00:00
parent cef4012738
commit 1e1a3ab43e
6 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,2 @@
discord.py
sqlalchemy-aio

4
discordbot/run.py Normal file
View File

@ -0,0 +1,4 @@
from titanembeds.bot import client
from config import config
client.run(config["bot-token"])

View File

View File

@ -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()

View File

@ -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()

View File

@ -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 '<Guilds {0} {1}>'.format(self.id, self.guild_id)