Add choice of templates when starting a new game

This commit is contained in:
Simone Baracchi 2019-04-08 20:26:38 +02:00
parent 44e04a01bf
commit 6be5bd132a
3 changed files with 21 additions and 6 deletions

View File

@ -4,7 +4,7 @@ RPG helper bot for Telegram. Manages character sheets, dice rolls, and game stat
**Want to try it?** Message @character_sheet_bot on Telegram.
This is a very generic tool for pen-and-paper RPGs, but via Telegram. Character sheets are structured as a "key - value" data store (actually, they can group keys together, more like a "container - key - value" data store) and are fully customizable from the Telegram interface for any purpose. It is up to you what your character sheet is made up of. A "template" sheet (based on Fate Accelerated RPG) is included and is automatically generated for new players (but it can be changed afterwards).
This is a very generic tool for pen-and-paper RPGs, but via Telegram. Character sheets are structured as a "key - value" data store (actually, they can group keys together, more like a "container - key - value" data store) and are fully customizable from the Telegram interface for any purpose. It is up to you what your character sheet is made up of. Some "template" sheets are included and automatically generated for new players (currently limited to FateRPG and D&D, but they can be changed and customized after game creation).
Just tell `/start` to the bot to enter its menu. Optionally, you can issue commands without going through the buttons; see the `Commands` section below.

View File

@ -115,6 +115,18 @@ def choose_item(string, argname):
return wrapper
return decorator
def choose_template(string, argname):
def decorator(func):
@functools.wraps(func)
def wrapper(handler, **kwargs):
options = OrderedDict()
for key, value in db.game_templates.items():
options[value] = key
handler.send(string, options=options, allowedit=True)
handler.read_answer(func, argname, kwargs)
return wrapper
return decorator
def need_group(func):
@functools.wraps(func)
def wrapper(handler):
@ -188,9 +200,9 @@ def delgame(handler):
@add_command('showgame')
@need_gameid(allowexisting=True, errormessage='No game found.')
def showgame(handler):
gamename, groups, players = db.get_game_info(handler.dbc, handler.group.gameid)
gamename, template, groups, players = db.get_game_info(handler.dbc, handler.group.gameid)
players_string = [x + (' (gm)' if (y == db.ROLE_MASTER) else '') for x,y in players.items()]
ret = '{}\nGroups: {}\nPlayers: {}'.format(gamename, ', '.join(groups), ', '.join(players_string))
ret = '{} ({})\nGroups: {}\nPlayers: {}'.format(gamename, db.game_templates[template], ', '.join(groups), ', '.join(players_string))
items = db.get_items(handler.dbc, handler.group.gameid, handler.chat_id)
if db.room_container in items:

9
db.py
View File

@ -1,11 +1,13 @@
import sqlite3
import config
from collections import OrderedDict
db_name = config.db_file
db_version = 1
ROLE_PLAYER = 10
ROLE_MASTER = 20
game_templates = ['fae']
game_templates = OrderedDict([('fae', 'Fate Accelerated RPG'),
('dnd', 'Dungeons & Dragons')])
room_container = 'room'
rolls_container = 'rolls'
@ -217,9 +219,10 @@ def get_game_from_group(db, groupid):
def get_game_info(db, gameid):
c = db.cursor()
query = c.execute('''SELECT gamename FROM Games WHERE gameid=?''', (gameid,))
query = c.execute('''SELECT gamename, template FROM Games WHERE gameid=?''', (gameid,))
result = query.fetchone()
gamename = result[0]
template = result[1]
query = c.execute('''SELECT groupname FROM Groups WHERE gameid=?''', (gameid,))
groups = []
for group in query:
@ -228,7 +231,7 @@ def get_game_info(db, gameid):
players = {}
for player in query:
players[player[0]] = player[1]
return gamename, groups, players
return gamename, template, groups, players
def number_of_items(db, gameid, playerid):
c = db.cursor()