Merge pull request #1 from alexberryman/master
Add custom cards to global files
This commit is contained in:
commit
9f2cb8bef5
5
cah.py
5
cah.py
|
@ -5,8 +5,9 @@ import test
|
|||
|
||||
# Settings you change
|
||||
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']
|
||||
blank_format = '__________'
|
||||
|
||||
# Settings that are used
|
||||
#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))
|
||||
return card_object_list
|
||||
|
||||
def count_answers(self, text, blank_format = '__________'):
|
||||
def count_answers(self, text):
|
||||
blanks = text.count(blank_format)
|
||||
if blanks is 0:
|
||||
return 1
|
||||
|
|
24
plugin.py
24
plugin.py
|
@ -39,9 +39,11 @@ from random import randint
|
|||
|
||||
import operator
|
||||
|
||||
from cah import Game
|
||||
from cah import Game, base_directory, card_folder, blank_format
|
||||
|
||||
import time
|
||||
import os
|
||||
import re
|
||||
|
||||
class Cah(callbacks.Plugin):
|
||||
"""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].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):
|
||||
channel = ircutils.toLower(msg.args[0])
|
||||
|
|
Loading…
Reference in New Issue