Skip to content

Commit

Permalink
Merge pull request #3 from awolins/master
Browse files Browse the repository at this point in the history
Class validation on add
  • Loading branch information
pachev authored Jan 1, 2018
2 parents 2759557 + e9a32a9 commit 0042718
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
27 changes: 27 additions & 0 deletions cogs/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,34 @@ async def add(self,
discord id and can only be updated by either that member or an officer.
**Officers can add a user by tagging them at the end. eg @drawven**
Note: Total gear score and rank is auto calculated."""

try:
# if char_class is shorthand for a class name (EX. DK = DARKKNIGHT) then set it to the real name
char_class = CHARACTER_CLASS_SHORT.get(char_class.upper()) if CHARACTER_CLASS_SHORT.get(char_class.upper()) else char_class

# check for invalid class names
if char_class.upper() not in CHARACTER_CLASSES:
# find possible class names that user was trying to match
possible_classes = list(filter(
lambda class_name: char_class.upper() in class_name,
CHARACTER_CLASSES,
))
if len(possible_classes) > 1:
await self.bot.say(codify("Character class not recognized.\n"
"Did you mean {}?".format(", ".join(
possible_classes[:-1]) + " or " + possible_classes[-1])
))
elif len(possible_classes) == 1:
await self.bot.say(codify("Character class not recognized.\n"
"Did you mean {}?".format(possible_classes[0])
))
else:
await self.bot.say(
codify("Character class not recognized, here is a list "
"of recognized classes\n "
+ "\n ".join(CHARACTER_CLASSES)))
return

author = ctx.message.author
roles = [u.name for u in author.roles]

Expand Down
1 change: 1 addition & 0 deletions gsbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# Main connection function offered by mongoengine defaults are localhost:27017
connect(DB_NAME,
host=DB_HOST,
username=DB_USER,
password=DB_PASS,
authentication_source=DB_NAME)
Expand Down
29 changes: 28 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
COLLECTION = CONFIG.get('db', 'collection')
HIST_COLLECTION = CONFIG.get('db', 'historical')
DB_NAME = CONFIG.get('db', 'name')
DB_HOST = CONFIG.get('db', 'host')
DB_USER = CONFIG.get('auth', 'user')
DB_PASS = CONFIG.get('auth', 'pwd')
TOKEN = CONFIG.get('auth', 'dev_token')
Expand All @@ -26,8 +27,34 @@

HEADERS = ['Rank', 'Fam', 'Char', 'Class', 'Lvl', ' % ', 'AP', 'DP', 'GS', 'Updated']

CHARACTER_CLASSES = [
"MUSA",
"DARKKNIGHT",
"BERSERKER",
"KUNOICHI",
"MAEHWA",
"MYSTIC",
"NINJA",
"RANGER",
"SORCERESS",
"STRIKER",
"TAMER",
"VALKYRIE",
"WARRIOR",
"WITCH",
"WIZARD",
]

CHARACTER_CLASS_SHORT = {
"DK": "DARKKNIGHT",
"ZERKER": "BERSERKER",
"KUNO": "KUNOICHI",
"SORC": "SORCERESS",
"VALK": "VALKYRIE",
}

DESCRIPTION = '''
This the official Gear Score bot.
This the official Gear Score bot.
Made by drawven(drawven@gmail.com)
'''

Expand Down

0 comments on commit 0042718

Please sign in to comment.