Skip to content

Commit

Permalink
Added aliases and alias creation
Browse files Browse the repository at this point in the history
Allowed for aliases to specify different names for
wyrmprints, dragons, or adventurers
Built in aliases come by default for event characters
New aliases can be created with the alias command
  • Loading branch information
eesandoval committed May 3, 2019
1 parent bc92016 commit 83e51ba
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 0 deletions.
29 changes: 29 additions & 0 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from models.adventurer import Adventurer
from models.wyrmprint import Wyrmprint
from models.dragon import Dragon
import models.alias

async def query(criteria):
try:
Expand Down Expand Up @@ -198,6 +199,34 @@ async def process_dragon_reaction(emoji, dragon, message):
elif emoji == "\U0001F509": # 2 unbinds
await process_dragon(dragon.name, 2, message)

async def create_alias(message):
print(message)
if ',' not in message or len(message.split(',')) != 2:
await view.show_missing_criteria("Missing alias, name, or format")
return
alias = message.split(',')[0].strip()
name = message.split(',')[1].strip()
alias_type = 0
print(name)
print(alias)
aliased_id = Adventurer.get_adventurer_id(name)
if aliased_id != 0:
models.alias.create_alias(aliased_id, alias, alias_type)
await view.show_completed_alias()
return
alias_type += 1
aliased_id = Wyrmprint.get_wyrmprint_id(name)
if aliased_id != 0:
models.alias.create_alias(aliased_id, alias, alias_type)
await view.show_completed_alias()
return
alias_type += 1
aliased_id = Dragon.get_dragon_id(name)
if aliased_id != 0:
models.alias.create_alias(aliased_id, alias, alias_type)
await view.show_completed_alias()
return


def start():
view.start_discord_bot()
Binary file modified master.db
Binary file not shown.
40 changes: 40 additions & 0 deletions models/adventurer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ def find_adventurers(element=None, weapon=None, skill=None, ability=None,
adventurers.append(Adventurer(adventurer[0]))
return adventurers

@staticmethod
def get_adventurer_id(name):
with Database("master.db") as db:
result = db.query(Adventurer.id_query_text, (name,))
if result is None or result == []:
return 0
return int(result[0][0])

def __init__(self, name, level=None):
self.name = name
with Database("master.db") as db:
Expand All @@ -70,6 +78,8 @@ def __init__(self, name, level=None):

def _get_adventurer(self, db):
result = db.query(Adventurer.adventurer_query_text, (self.name,))
if result is None or result == []:
result = db.query(Adventurer.alias_query_text, (self.name,))
if result is None or result == []:
return False
result = result[0]
Expand Down Expand Up @@ -162,3 +172,33 @@ def _get_abilities(self, db, level=None):
INNER JOIN Abilities Ab ON Ab.AbilityID = AA.AbilityID
WHERE 1=1
'''
alias_query_text = '''
SELECT A.AdventurerID
, A.Title
, A.Rarity
, ET.Name AS "ElementType"
, WT.Name AS "WeaponType"
, A.MaxHP
, A.MaxSTR
, A.MaxCoOp
, A.Defense
, A.ReleaseDate
, UT.Name AS "UnitType"
, A.Name
, A.Limited
FROM Adventurers A
INNER JOIN ElementTypes ET ON ET.ElementTypeID = A.ElementTypeID
INNER JOIN WeaponTypes WT ON WT.WeaponTypeID = A.WeaponTypeID
INNER JOIN UnitTypes UT ON UT.UnitTypeID = A.UnitTypeID
INNER JOIN Aliases AL ON AL.AdventurerID = A.AdventurerID
AND AL.AdventurerID IS NOT NULL
WHERE AL.AliasText LIKE '%' || ? || '%' COLLATE NOCASE
ORDER BY A.ReleaseDate ASC
LIMIT 1
'''
id_query_text = '''
SELECT AdventurerID
FROM Adventurers
WHERE Name LIKE '%' || ? || '%' COLLATE NOCASE
LIMIT 1
'''
47 changes: 47 additions & 0 deletions models/alias.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'''
MIT License
Copyright (c) 2019 Enrique Sandoval
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
'''
from models.database import Database


create_adventurer_alias_text = '''
INSERT INTO Aliases (AdventurerID, AliasText) VALUES (?, ?)
'''

create_wyrmprint_alias_text = '''
INSERT INTO Aliases (WyrmprintID, AliasText) VALUES (?, ?)
'''

create_dragon_alias_text = '''
INSERT INTO Aliases (DragonID, AliasText) VALUES (?, ?)
'''


def create_alias(alias_id, text, alias_type):
with Database("master.db") as db:
if alias_type == 0:
db.execute(create_adventurer_alias_text, (alias_id, text,))
elif alias_type == 1:
db.execute(create_wyrmprint_alias_text, (alias_id, text,))
elif alias_type == 2:
db.execute(create_dragon_alias_text, (alias_id, text,))
33 changes: 33 additions & 0 deletions models/dragon.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ def find_dragons(element=None, skill=None, ability=None, rarity=None,
dragons.append(Dragon(dragon[0], level))
return dragons

@staticmethod
def get_dragon_id(name):
with Database("master.db") as db:
result = db.query(Dragon.id_query_text, (name,))
if result is None or result == []:
return 0
return int(result[0][0])

def __init__(self, name, level):
self.name = name
with Database("master.db") as db:
Expand All @@ -71,6 +79,8 @@ def __init__(self, name, level):

def _get_dragon(self, db):
result = db.query(Dragon.dragon_query_text, (self.name,))
if result is None or result == []:
result = db.query(Dragon.alias_query_text, (self.name,))
if result is None or result == []:
return False
result = result[0]
Expand Down Expand Up @@ -148,3 +158,26 @@ def _get_abilities(self, db, level):
INNER JOIN Abilities A ON A.AbilityID = DA.AbilityID
WHERE 1=1
'''
alias_query_text = '''
SELECT D.DragonID
, ET.Name AS "ElementTypeName"
, D.Rarity
, D.HP
, D.STR
, D.ReleaseDate
, D.Name
, D.Limited
FROM Dragons D
INNER JOIN ElementTypes ET ON ET.ElementTypeID = D.ElementTypeID
INNER JOIN Aliases AL ON AL.DragonID = D.DragonID
AND AL.DragonID IS NOT NULL
WHERE AL.AliasText LIKE '%' || ? || '%' COLLATE NOCASE
ORDER BY D.ReleaseDate ASC
LIMIT 1
'''
id_query_text = '''
SELECT DragonID
FROM Dragons
WHERE Name LIKE '%' || ? || '%' COLLATE NOCASE
LIMIT 1
'''
31 changes: 31 additions & 0 deletions models/wyrmprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def find_wyrmprints(ability=None, rarity=None, level=3):
wyrmprints.append(Wyrmprint(wyrmprint[0], wyrmprint[1]))
return wyrmprints

@staticmethod
def get_wyrmprint_id(name):
with Database("master.db") as db:
result = db.query(Wyrmprint.id_query_text, (name,))
if result is None or result == []:
return 0
return int(result[0][0])

def __init__(self, name, level=3):
self.name = name
with Database("master.db") as db:
Expand All @@ -61,6 +69,8 @@ def __init__(self, name, level=3):

def _get_wyrmprint(self, db):
result = db.query(Wyrmprint.wyrmprint_query_text, (self.name,))
if result is None or result == []:
result = db.query(Wyrmprint.alias_query_text, (self.name,))
if result is None or result == []:
return False
result = result[0]
Expand Down Expand Up @@ -111,3 +121,24 @@ def _get_abilities(self, db, level):
INNER JOIN Abilities A ON A.AbilityID = WA.AbilityID
WHERE 1=1
'''
alias_query_text = '''
SELECT W.WyrmprintID
, W.Rarity
, W.MaxHP
, W.MaxSTR
, W.ReleaseDate
, W.Name
, W.Limited
FROM Wyrmprints W
INNER JOIN Aliases AL ON AL.WyrmprintID = W.WyrmprintID
AND AL.WyrmprintID IS NOT NULL
WHERE AL.AliasText LIKE '%' || ? || '%' COLLATE NOCASE
ORDER BY W.ReleaseDate ASC
LIMIT 1
'''
id_query_text = '''
SELECT WyrmprintID
FROM Wyrmprints
WHERE Name LIKE '%' || ? || '%' COLLATE NOCASE
LIMIT 1
'''
16 changes: 16 additions & 0 deletions view.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ async def update(context):
await show_completed_update()


@client.command(name="alias",
description="Creates a new alias to search by",
brief="Creates a new alias to search by",
aliases=["al", "ali", "alia"],
pass_context=True)
async def alias(context):
message = handle_context(context)
await client.send_typing(channel)
await controller.create_alias(message)


def handle_context(context):
global channel
channel = context.message.channel
Expand Down Expand Up @@ -415,6 +426,11 @@ async def show_completed_update():
await client.send_message(channel, "Update complete")


@client.event
async def show_completed_alias():
await client.send_message(channel, "Alias created")


@client.event
async def clear_active_messages():
global all_active_messages, active_adventurer_messages, \
Expand Down

0 comments on commit 83e51ba

Please sign in to comment.