Merge pull request #1 from alexberryman/master

Add custom cards to global files
This commit is contained in:
Gordon Shumway 2019-12-07 03:48:05 -05:00 committed by GitHub
commit 9f2cb8bef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

5
cah.py
View File

@ -5,8 +5,9 @@ import test
# Settings you change # Settings you change
card_folder = 'cards' card_folder = 'cards'
answer_cards_file_names = ['answer_cards', 'custom_anwser_cards'] answer_cards_file_names = ['answer_cards', 'custom_answer_cards']
question_cards_file_name = ['question_cards', 'question_cards1', 'question_cards2', 'custom_question_cards'] question_cards_file_name = ['question_cards', 'question_cards1', 'question_cards2', 'custom_question_cards']
blank_format = '__________'
# Settings that are used # Settings that are used
#this is one level hire then it should be #this is one level hire then it should be
@ -47,7 +48,7 @@ class Deck(object):
card_object_list.append(Card(index, card_type, card)) card_object_list.append(Card(index, card_type, card))
return card_object_list return card_object_list
def count_answers(self, text, blank_format = '__________'): def count_answers(self, text):
blanks = text.count(blank_format) blanks = text.count(blank_format)
if blanks is 0: if blanks is 0:
return 1 return 1

View File

@ -39,9 +39,11 @@ from random import randint
import operator import operator
from cah import Game from cah import Game, base_directory, card_folder, blank_format
import time import time
import os
import re
class Cah(callbacks.Plugin): class Cah(callbacks.Plugin):
"""Add the help for "@plugin help Cah" here """Add the help for "@plugin help Cah" here
@ -321,7 +323,25 @@ class Cah(callbacks.Plugin):
self.games[channel] = self.CahGame(irc, channel, numrounds) self.games[channel] = self.CahGame(irc, channel, numrounds)
self.games[channel].initGame() self.games[channel].initGame()
def addcard(self, irc, msg, args):
"""Add a question or answer card to the deck,
take required argument of [question, answer], and the string.
For questions cards any number of continuous underscores will be treated as a fill-in-the-blank.
"""
channel = ircutils.toLower(msg.args[0])
#TODO: assumes msg[index] is a string
text = args[1].capitalize().strip()
if args[0] == "question":
card_file = "custom_question_cards"
text = re.sub(r'_+', blank_format, text)
elif args[0] == "answer":
card_file = "custom_answer_cards"
else:
irc.reply("Specify type of card as either question or answer.")
return
path = os.path.abspath(os.path.join(base_directory, card_folder, card_file))
with open(path, 'w') as file_handle:
file_handle.writelines([text])
def scah(self, irc, msg, args): def scah(self, irc, msg, args):
channel = ircutils.toLower(msg.args[0]) channel = ircutils.toLower(msg.args[0])