Skip to content

Commit

Permalink
Updating all handlers except turns.py
Browse files Browse the repository at this point in the history
  • Loading branch information
satanas committed Nov 12, 2019
1 parent b72bbf5 commit 50c1c7e
Show file tree
Hide file tree
Showing 15 changed files with 264 additions and 317 deletions.
283 changes: 0 additions & 283 deletions character.py

This file was deleted.

17 changes: 8 additions & 9 deletions commands.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from roll import handler as roll_handler
from charsheet import handler as charsheet_handler
from character import handler as character_handler
from turns import handler as turn_handler
from dm import handler as dm_handler
from campaign import handler as campaign_handler
from exceptions import CommandNotFound, NotACommand
from handlers.roll import handler as roll_handler
from handlers.charsheet import handler as charsheet_handler
from handlers.character import handler as character_handler
from handlers.turns import handler as turn_handler
from handlers.dm import handler as dm_handler
from handlers.campaign import handler as campaign_handler

# Each command should be defined using the expression below:
#
Expand Down Expand Up @@ -39,11 +39,10 @@
"/link_char": (character_handler, ["<char_id>", "(username)"], "links character to target username or self username"),
"/status": (character_handler, ["<username|character>"], "shows the list of weapons of a character"),
"/weapons": (character_handler, ["<username|character>"], "shows the list of weapons of a character"),
"/attack_roll": (character_handler, ["<character>", "<weapon>", "<melee|range>", "(distance)", "(adv|disadv)"], "performs an attack roll on a character"),
"/attack_roll": (character_handler, ["<weapon>", "<melee|range>", "(distance)", "(adv|disadv)"], "performs an attack roll on a character"),
"/initiative_roll": (character_handler, ["<character>"], "performs an initiative roll for a character"),
"/short_rest_roll": (character_handler, ["<username|character>"], "performs an short rest roll for a character"),
"/talk": (character_handler, ["<message>"], "prints a message using in-game conversation format"),
"/say": (character_handler, ["<message>"], "prints a normal message using in-game conversation format"),
"/say": (character_handler, ["<message>"], "prints a message using in-game conversation format"),
"/whisper": (character_handler, ["<message>"], "prints a whisper message using in-game conversation format"),
"/yell": (character_handler, ["<message>"], "prints a yell message using in-game conversation format"),
}
Expand Down
2 changes: 1 addition & 1 deletion database.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_character_id(self, campaign_id, username):
return None

return result[username]

def get_character(self, character, find_by_id):
if find_by_id:
result = self.firebase_db.get('/', f'/characters/{character}', params={'auth': FIREBASE_API_SECRET})
Expand Down
3 changes: 3 additions & 0 deletions exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ class CommandNotFound(Exception):
class NotACommand(Exception):
"""Raised when the message from the chat is not a command"""
pass

class CharacterNotFound(Exception):
pass
12 changes: 5 additions & 7 deletions campaign.py → handlers/campaign.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
from database import Database

def handler(bot, update):
def handler(bot, update, command, txt_args):
db = Database()
chat_id = update.message.chat.id
text = update.message.text
response = "Invalid command"
if text.startswith('/start_campaign'):
response = start_campaign(chat_id, text, db)
elif text.startswith('/close_campaign'):
if command == '/start_campaign':
response = start_campaign(chat_id, txt_args, db)
elif command == '/close_campaign':
response = close_campaign(chat_id, db)

bot.send_message(chat_id=update.message.chat_id, text=response, parse_mode="Markdown")

def start_campaign(chat_id, text, db):
name = text.replace('/start_campaign', '').strip()
campaign_id, campaign = db.get_campaign(chat_id)
if campaign_id != None or campaign != None:
return 'There is an active campaign for this group. Close the active campaign before creating a new one'

db.create_campaign(chat_id, name)
db.create_campaign(chat_id, text)
return "Campaign created successfully!"

def close_campaign(chat_id, db):
Expand Down
Loading

0 comments on commit 50c1c7e

Please sign in to comment.