From 508345f15cd414bffd5cf507e5d40cee13982eaf Mon Sep 17 00:00:00 2001 From: ParkerXChen Date: Sat, 13 Mar 2021 11:23:23 -0500 Subject: [PATCH 1/3] Fix Translations --- cmdproc/game24.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmdproc/game24.py b/cmdproc/game24.py index 50beb69..e02235f 100644 --- a/cmdproc/game24.py +++ b/cmdproc/game24.py @@ -8,7 +8,7 @@ LifetimeStats = twconfig.CONFIG['LifetimeStats'] def help(): - return r"""欢迎来到 Noah 的 24 点游戏! + return r"""欢迎来到 Grace 的 24 点游戏! 您的目标是尝试去使用四个数字来算出 24 (四个数字可以在 /gameq 找到)。 每张牌都必须使用一次。 @@ -17,14 +17,14 @@ def help(): 祝你们好运!@作者:Noah、Sicheng -------------------- -Welcome to Aunt Grace's 24 point game! +Welcome to Grace's game of 24! Your goal is to try to use four numbers to calculate 24 (the four numbers can be found in /gameq). Each card must be used once. Remember, you can only use addition, subtraction, multiplication, division, and parentheses (please don't use unnecessary parentheses). You can only use three symbols for addition, subtraction, multiplication, and division. -Wish ya'll good luck! @: Noah, Sicheng""" +Wish you all good luck! @: Noah, Sicheng, Parker""" def correctAnswers(func): return func['correct'] From 43beb1835cff88b37de373dad8d06e46b2d010df Mon Sep 17 00:00:00 2001 From: ParkerXChen Date: Sat, 20 Mar 2021 10:29:43 -0400 Subject: [PATCH 2/3] Make ms.py --- bot.py | 3 +- cmdproc/game24.py | 2 +- cmdproc/makestorygame.py | 97 ++++++++++++++++++++++++++++++++++++++++ cmdproc/ms.json | 1 + cmdproc/msconfig.py | 19 ++++++++ tw.json | 4 +- 6 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 cmdproc/makestorygame.py create mode 100644 cmdproc/ms.json create mode 100644 cmdproc/msconfig.py diff --git a/bot.py b/bot.py index c829747..cd5bc03 100644 --- a/bot.py +++ b/bot.py @@ -44,7 +44,7 @@ def help(): print(f"Starting... ID: {str(CONFIG['ID'])} , Username: {CONFIG['Username']}") # 在这里加入功能 - from cmdproc import startcmd,rewardscmd,admincmd,weathercmd,infocmd,penaltiescmd,guesscmd,capitals,botadmincmd + from cmdproc import startcmd,rewardscmd,admincmd,weathercmd,infocmd,penaltiescmd,guesscmd,capitals,botadmincmd, youtubemusic,game24, makestorygame from cmdproc import youtubemusic,game24 commands = startcmd.add_dispatcher(dispatcher) commands = admincmd.add_dispatcher(dispatcher) @@ -57,6 +57,7 @@ def help(): commands += botadmincmd.add_dispatcher(dispatcher) commands += youtubemusic.add_dispatcher(dispatcher) commands += game24.add_handler(dispatcher) + commands += makestorygame.add_handler(dispatcher) updater.bot.set_my_commands(commands) diff --git a/cmdproc/game24.py b/cmdproc/game24.py index e02235f..2995cbb 100644 --- a/cmdproc/game24.py +++ b/cmdproc/game24.py @@ -351,4 +351,4 @@ def add_handler(dp:Dispatcher): BotCommand('gameend24','结束当前进行的游戏'), BotCommand('gamerules','查询24点的游戏规则'), BotCommand('gamel','查询总排行榜') - ] + ] \ No newline at end of file diff --git a/cmdproc/makestorygame.py b/cmdproc/makestorygame.py new file mode 100644 index 0000000..cf86730 --- /dev/null +++ b/cmdproc/makestorygame.py @@ -0,0 +1,97 @@ +import config +from telegram import Update,BotCommand +from telegram.ext import Dispatcher,CommandHandler,CallbackContext +import random + +games = {} + +def set_game(chatid,uid,fname): + games[chatid] = {'responsestreak':0} + games[chatid]['storysofar'] = '' + games[chatid][uid] = { + 'fname':fname, + 'senctencescontributed':0 + } + + +def startms(update,context): + global lastword + fname = update.effective_user.first_name + uid = str(update.effective_user.id) + chatid = update.effective_chat.id + + if len(context.args) == 0: + update.message.reply_text(""" + Welcome to Parker's Story game! + + How to play: + - 1 Person will the start the game by typing a "/startms (word/sentence)" + - The next person will continue by typing "/ms (sentence)", but the first word of the sentence must be the last word of the last sentence. + Type /startms followed by any sentence to begin a new game. + + Note: This is the english version. You can play the chinese version with @TheRandomDudeHimself's @SichengsGodBot. + """) + else: + try: + game = games[chatid] + print(game) + update.message.reply_text('Sorry, but there is already a game going on in this group. Please try again later.') + except KeyError: + set_game(chatid,uid,fname) + + startingsentence = ' ' + for i in context.args: + startingsentence += i + startingsentence += ' ' + startingsentence = startingsentence[:-1] + startingsentence += f'. ({fname})\n' + + lastword = '' + lastword = context.args[-1] + games[chatid]['storysofar'] = startingsentence + update.message.reply_text(f""" + A game has begun! + + To play, type /ms followed by any sentence. + + Note: This is the english version. You can play the chinese version with @TheRandomDudeHimself's @BotGod. + + The current story: + + {games[chatid]['storysofar']} + + The next message must begin with the word "{lastword}" """) + +def ms(update,context): + global lastword + fname = update.effective_user.first_name + uid = str(update.effective_user.id) + chatid = update.effective_chat.id + + if len(context.args) == 0: + update.message.reply_text('Please type a sentence following /ms.') + else: + if context.args[0].lower() == lastword.lower(): + if games[chatid]['responsestreak'] < 2: + sentence = '' + for i in context.args: + sentence += i + sentence += ' ' + sentence += f'.({fname})\n' + games[chatid]['storysofar'] += f' {sentence}' + lastword = '' + lastword = context.args[-1] + update.message.reply_text(f'You have added the sentence "{sentence}" to the story! The story so far:\n\n {games[chatid]["storysofar"]}\n\nRemember: The first word of the next sentence must be "{lastword}"') + else: + update.message.reply_text(f'Sorry, but the first word in your sentence must be "{lastword}"') + # except KeyError: + # update.message.reply_text('Sorry, but there is no game going on in this group chat. Type /startms to start one!') + + +def add_handler(dp: Dispatcher): + dp.add_handler(CommandHandler(["startms"], startms)) + dp.add_handler(CommandHandler(["ms"], ms)) + return get_command() + +def get_command(): + return [BotCommand('rewards','Reward Spins // 奖励大转盘')] \ No newline at end of file diff --git a/cmdproc/ms.json b/cmdproc/ms.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/cmdproc/ms.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/cmdproc/msconfig.py b/cmdproc/msconfig.py new file mode 100644 index 0000000..3895938 --- /dev/null +++ b/cmdproc/msconfig.py @@ -0,0 +1,19 @@ +import json +import os +import config + +def load_config(): + with open(config_file, 'r') as configfile: + CONFIG = json.load(configfile) + return CONFIG + +def save_config(): + with open(config_file, 'w') as configfile: + json.dump(CONFIG, configfile, indent=4,ensure_ascii=False) + +RUN_PATH = os.getcwd() + +config_file = f'{config.run_path}/ms.json' +CONFIG = load_config() +if not "game" in CONFIG: + CONFIG["game"] = {} \ No newline at end of file diff --git a/tw.json b/tw.json index 9e26dfe..90606bf 100644 --- a/tw.json +++ b/tw.json @@ -1 +1,3 @@ -{} \ No newline at end of file +{ + "LifetimeStats": {} +} \ No newline at end of file From 8964434876e5b73cc6ed28e5b7005c143552c04e Mon Sep 17 00:00:00 2001 From: ParkerXChen Date: Sat, 27 Mar 2021 10:18:27 -0400 Subject: [PATCH 3/3] Make MakeStoryGame.py --- cmdproc/makestorygame.py | 93 +++++++++++++++++++++++++++------------- 1 file changed, 64 insertions(+), 29 deletions(-) diff --git a/cmdproc/makestorygame.py b/cmdproc/makestorygame.py index cf86730..53cf169 100644 --- a/cmdproc/makestorygame.py +++ b/cmdproc/makestorygame.py @@ -1,18 +1,27 @@ import config -from telegram import Update,BotCommand -from telegram.ext import Dispatcher,CommandHandler,CallbackContext +from telegram import InlineKeyboardButton, InlineKeyboardMarkup,BotCommand, Update +from telegram.ext import Dispatcher,CommandHandler,CallbackContext,CallbackQueryHandler import random +from langdetect import detect + games = {} def set_game(chatid,uid,fname): - games[chatid] = {'responsestreak':0} - games[chatid]['storysofar'] = '' + games[chatid] = {'responsestreak':0,'storysofar':'','last2responses':[],'avotes':0,'bvotes':0} games[chatid][uid] = { 'fname':fname, - 'senctencescontributed':0 + 'senctencescontributed':0, + 'voted':True } +def set_user(chatid,uid,fname): + games[chatid][uid] = { + 'fname':fname, + 'senctencescontributed':0, + 'voted':True + } + def startms(update,context): global lastword @@ -37,58 +46,84 @@ def startms(update,context): print(game) update.message.reply_text('Sorry, but there is already a game going on in this group. Please try again later.') except KeyError: - set_game(chatid,uid,fname) - startingsentence = ' ' for i in context.args: startingsentence += i startingsentence += ' ' startingsentence = startingsentence[:-1] startingsentence += f'. ({fname})\n' + + if detect(startingsentence) == 'en': + set_game(chatid,uid,fname) + lastword = '' + lastword = context.args[-1] + games[chatid]['storysofar'] = startingsentence + update.message.reply_text(f""" + A game has begun! - lastword = '' - lastword = context.args[-1] - games[chatid]['storysofar'] = startingsentence - update.message.reply_text(f""" - A game has begun! - - To play, type /ms followed by any sentence. + To play, type /ms followed by any sentence. - Note: This is the english version. You can play the chinese version with @TheRandomDudeHimself's @BotGod. + Note: This is the english version. You can play the chinese version with @TheRandomDudeHimself's @BotGod. - The current story: + The current story: - {games[chatid]['storysofar']} + {games[chatid]['storysofar']} - The next message must begin with the word "{lastword}" """) + The next message must begin with the word "{lastword}" """) + else: + update.message.reply_text('Sorry, but please make sure that:\n\n1. Your sentence is in english\n2. Your sentence is grammatically correct.') def ms(update,context): global lastword fname = update.effective_user.first_name - uid = str(update.effective_user.id) chatid = update.effective_chat.id if len(context.args) == 0: update.message.reply_text('Please type a sentence following /ms.') else: if context.args[0].lower() == lastword.lower(): - if games[chatid]['responsestreak'] < 2: - sentence = '' - for i in context.args: - sentence += i - sentence += ' ' - sentence += f'.({fname})\n' - games[chatid]['storysofar'] += f' {sentence}' + sentence = '' + for i in context.args: + sentence += i + sentence += ' ' + sentence += f'.({fname})\n' + if detect(sentence) == 'en': + games[chatid]['last2responses'].append(f' {sentence}'[:-1]) + games[chatid]['responsestreak'] += 1 lastword = '' lastword = context.args[-1] - update.message.reply_text(f'You have added the sentence "{sentence}" to the story! The story so far:\n\n {games[chatid]["storysofar"]}\n\nRemember: The first word of the next sentence must be "{lastword}"') + update.message.reply_text(f'You have added the sentence "{sentence}" to the story! The story so far:\n\n {games[chatid]["storysofar"]} (Every 2 repsonses, players will vote which sentence they want to add to the story.)\n\nRemember: The first word of the next sentence must be "{lastword}"') + if games[chatid]['responsestreak'] == 2: + votefora = InlineKeyboardButton('Vote for response (a)',callback_data='voteforresponse:a') + voteforb = InlineKeyboardButton('Vote for response (b)',callback_data='voteforresponse:b') + voteforresponsekb = InlineKeyboardMarkup([[votefora],[voteforb]]) + update.message.reply_text(f'To prevent spam, Players will now vote which of the last two responses they want to add to the story.\n\nThe two responses:\n\na.{games[chatid]["last2responses"][0]}\n\nb.{games[chatid]["last2responses"][1]}\n\nClick either the "Vote for response (a)" or the "vote for response (b)" to choose which response you want in your story. ',reply_markup=voteforresponsekb) else: update.message.reply_text(f'Sorry, but the first word in your sentence must be "{lastword}"') - # except KeyError: - # update.message.reply_text('Sorry, but there is no game going on in this group chat. Type /startms to start one!') + +def voteforresponsecallback(update,context): + query = update.callback_query + chatid = update.effective_chat.id + user = update.effective_user + try: + if games[chatid][user.id]['voted']== False: + if query.data =='voteforresponse:a': + voteindex = 0 + games[chatid]['avotes'] += 1 + print(str(games[chatid]['avotes'])) + elif query.data == 'voteforresponse:b': + voteindex = 1 + games[chatid]['bvotes'] += 1 + print(str(games[chatid]['bvotes'])) + else: + query.answer('You have already voted.') + except KeyError: + set_user(chatid,user.id,user.fname) + def add_handler(dp: Dispatcher): + dp.add_handler(CallbackQueryHandler(voteforresponsecallback,pattern="^voteforresponse:[A-Za-z0-9_]*")) dp.add_handler(CommandHandler(["startms"], startms)) dp.add_handler(CommandHandler(["ms"], ms)) return get_command()