Skip to content

Commit

Permalink
Added dragons and improved searching
Browse files Browse the repository at this point in the history
There be dragons now added to the database and model
Improved search capabilities using LIKE instead of an exact name
Updated the readme with images and notice about discord.py
  • Loading branch information
eesandoval committed Apr 11, 2019
1 parent 63aeb3c commit 60942b3
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 29 deletions.
54 changes: 42 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,51 @@
A Dragalia Lost bot that gives information on Adventurers and Wyrmprints (Dragons coming soon)
A Dragalia Lost bot that gives information on Adventurers, Dragons, and Wyrmprints

## Requirements
- [Python 3.6 or higher](https://www.python.org/)
- [discord.py 0.16.12](https://github.com/Rapptz/discord.py). You can install this by opening a command prompt or terminal window and typing the following:
```
python -m pip install discord.py==0.16.12
```

## Installation
1. Go to the [DiscordApp developers application site](https://discordapp.com/developers/applications) and create a New Application, naming it whatever you wish, noting down the client ID
2. Select Bot on the left hand side, and create a new bot
3. Copy the token of this bot and paste it into the config_example.py for the TOKEN string
4. Visit the URL https://discordapp.com/oauth2/authorize?client_id=CLIENT_IDscope=bot, replacing the CLIENT_ID in the URL to what you noted down in step 1
5. Choose the server you want to add the bot to and select authorize
6. Set the TOKEN in the config_example.py file that you copied from step 3 in the file
7. Optional: Set the other items in the configuration file (such as the current event, a stream, the help text, picture server, etc)
8. Change the name of the config_example.py -> config.py
9. Run the bot in Python3 through the main.py
```
python3 main.py
1. Go to the [DiscordApp developers application site](https://discordapp.com/developers/applications) and create a New Application
![Creating the application](https://i.imgur.com/fqe68Zn.gif)
2. Name the application anything you'd like
![Naming the application](https://i.imgur.com/lV71FFb.gif)
3. Note down the Client ID, you can copy this and save it for now
![Saving the client id](https://i.imgur.com/vyebJAi.gif)
4. Select Bot on the left hand side, and create a new bot
![Creating a new bot for the application](https://i.imgur.com/lSAMUAo.gif)
5. Visit the following URL, replacing the CLIENT_ID in it with the client id you copied down in step 3: https://discordapp.com/oauth2/authorize?client_id=CLIENT_IDscope=bot
6. Select the server you want the bot to appear in
![Selecting the server for the bot to appear in](https://i.imgur.com/9zE2CtP.gif)
7. Copy the token from the bot page
![Copying the bot token](https://i.imgur.com/KxaJykR.gif)
8. Set the TOKEN parameter in the config_example.py file that you copied from step 7 in the file
![Setting the bot token](https://imgur.com/M3hS1k5.gif)
9. Change the name of the config_example.py -> config.py
10. Install d
10. Run the bot using the following command in the command prompt or terminal
```
python main.py
```

## Features
Searching for adventurers, dragons, and wyrmprints with the following command:
```
^(adv|wyr|dra) [name] [level]
```
Names are not case sensitive. Additionally, if multiple results would be found, they are sorted by release date in descending order. Level is an optional attribute that will list the abilities/skills of the search result. If level=1, then this gives a 0 unbind wyrmprint or dragon. If level=2, then this gives a max unbound wyrmprint or dragon. This only works with wyrmprints and dragons currently. By default the level is set to 2.

There exists additionally a query function to find adventurers, dragons, or wyrmprints with specific skills, abilities, rarities, element, weapon, etc.
```
^query type=(adv|wyr|dra) key=value
```
Key is defined as an attribute (such as element or weapon) where value is the value of the key. Multiple key value pairs can be given. If the value has spaces, surround it with quotes. Below is an example searching for water axe adventurers with the Freeze Res ability.
```
^query type=adv element=Water ability="Freeze Res" weapon=Axe
```
Be warned this will return ALL results, and may spam the chat log. Use at your own discretion.

## LICENSE
This project is licensed under the [MIT License](https://github.com/eesandoval/NefBot/blob/master/LICENSE).
Binary file modified master.db
Binary file not shown.
6 changes: 4 additions & 2 deletions models/adventurer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, name):

def _getAdventurer(self, db):
result = db.query(Adventurer.adventurerQueryText, (self.name,))
if result == None:
if result == None or result == []:
return False
result = result[0]
self.adventurerid = result[0]
Expand Down Expand Up @@ -113,7 +113,9 @@ def _getAbilities(self, db):
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
WHERE A.Name = ? COLLATE NOCASE
WHERE A.Name LIKE '%' || ? || '%' COLLATE NOCASE
ORDER BY A.ReleaseDate DESC
LIMIT 1
'''
skillsQueryText = '''
SELECT S.Name
Expand Down
26 changes: 15 additions & 11 deletions models/dragon.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def findDragons(element=None, skill=None, ability=None, rarity=None, level=2):
fullQuery += "AND D.rarity >= ? "
params += (rarity,)
if level != None:
fullQuery += "AND DS.level = ? AND DA.level = ? "
params += (level,)
fullQuery += "AND DA.level = ? "
params += (level,)
if len(params) == 0:
return dragons
Expand All @@ -65,10 +64,11 @@ def __init__(self, name, level):
else:
self._getSkills(db, level)
self._getAbilities(db, level)
self.level = level

def _getDragon(self, db):
result = db.query(Dragon.dragonQueryText, (self.name,))
if result == None:
if result == None or result == []:
return False
result = result[0]
self.dragonid = result[0]
Expand All @@ -82,27 +82,29 @@ def _getDragon(self, db):

def _getSkills(self, db, level):
self.skills = []
result = db.query(Dragon.skillsQueryText, (self.dragonid,level))
result = db.query(Dragon.skillsQueryText, (self.dragonid,))
for skill in map(Skill._make, result):
self.skills.append(skill)

def _getAbilities(self, db, level):
self.abilities = []
result = db.query(Dragon.abilitiesQueryText, (self.dragonid,level))
result = db.query(Dragon.abilitiesQueryText, (self.dragonid,level,))
for ability in map(Ability._make, result):
self.abilities.append(ability)

dragonQueryText = '''
SELECT D.DragonID
, ET.Name AS "ElementTypeName"
, D.Rarity
, D.MaxHP
, D.MaxSTR
, D.HP
, D.STR
, D.ReleaseDate
, D.Name
FROM Dragons D
INNER JOIN ElementTypes ET ON ET.ElementTypeID = D.ElementTypeID
WHERE D.Name = ? COLLATE NOCASE
WHERE D.Name LIKE '%' || ? || '%' COLLATE NOCASE
ORDER BY D.ReleaseDate DESC
LIMIT 1
'''

abilitiesQueryText = '''
Expand All @@ -118,12 +120,14 @@ def _getAbilities(self, db, level):

skillsQueryText = '''
SELECT S.Name
, S.Description
, S.SPCost
, S.FrameTime
, S.DescriptionLevel1
, S.DescriptionLevel2
, S.DescriptionLevel3
FROM DragonSkills DS
INNER JOIN Skills S ON S.SkillID = DS.SkillID
WHERE DS.DragonID = ?
AND DS.Level = ?
ORDER BY DS.Slot ASC, DS.Level ASC
'''

dragonSearchQueryText = '''
Expand Down
6 changes: 4 additions & 2 deletions models/wyrmprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, name, level=2):

def _getWyrmprint(self, db):
result = db.query(Wyrmprint.wyrmprintQueryText, (self.name,))
if result == None:
if result == None or result == []:
return False
result = result[0]
self.wyrmprintid = result[0]
Expand All @@ -84,7 +84,9 @@ def _getAbilities(self, db, level):
, W.ReleaseDate
, W.Name
FROM Wyrmprints W
WHERE W.Name = ? COLLATE NOCASE
WHERE W.Name LIKE '%' || ? || '%' COLLATE NOCASE
ORDER BY W.ReleaseDate DESC
LIMIT 1
'''
abilitiesQueryText = '''
SELECT A.Name
Expand Down
7 changes: 5 additions & 2 deletions view.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ async def showDragon(dragon):
e = discord.Embed(title=dragon.name, desc=dragon.name)
portraitURL = PICTURE_SERVER + "dragons/portraits/{0}.png".format("%20".join(dragon.name))
e.set_thumbnail(url=portraitURL)
e.add_field(name="Element", value=getEmojiElement(dragon.element), inline=True)
e.add_field(name="Element", value=getEmojiElement(dragon.elementtype), inline=True)
e.add_field(name="Rarity", value=getEmojiRarity(dragon.rarity), inline=True)
e.add_field(name="Max HP/Max STR", value="{0}/{1}".format(dragon.maxhp, dragon.maxstr), inline=True)
e.add_field(name="Release Date", value=getHumanStringDate(dragon.releasedate), inline=True)
for skill in dragon.skills:
e.add_field(name="Skill: " + skill.name, value=skill.description, inline=False)
if dragon.level == 1:
e.add_field(name="Skill: " + skill.name, value=skill.descriptionlevel1, inline=False)
else:
e.add_field(name="Skill: " + skill.name, value=skill.descriptionlevel2, inline=False)
for ability in dragon.abilities:
e.add_field(name="Ability: " + ability.name, value=ability.description, inline=False)
await client.send_message(channel, embed=e)
Expand Down

0 comments on commit 60942b3

Please sign in to comment.