From 2982af5031dd579ca314e67df405519769d17d6e Mon Sep 17 00:00:00 2001 From: fm528 Date: Sat, 27 Aug 2022 18:42:21 +0800 Subject: [PATCH 01/16] Change message editing --- src/bot.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/bot.py b/src/bot.py index a8a69dc..d0d6f46 100644 --- a/src/bot.py +++ b/src/bot.py @@ -70,65 +70,69 @@ def chat_command(update: Update, context: CallbackContext) -> None: ) -def sendNonTextMessage(message, bot, chat_id) -> None: +def sendNonTextMessage(message, bot, chat_id, messageText) -> None: if message.photo: bot.send_photo( photo=message.photo[-1], - caption=message.caption, + caption=messageText, chat_id=chat_id ) elif message.sticker: bot.send_sticker( sticker=message.sticker, + caption=messageText, chat_id=chat_id ) elif message.document: bot.send_document( document=message.document, - caption=message.caption, + caption=messageText, chat_id=chat_id ) elif message.video: bot.send_video( video=message.video, - caption=message.caption, + caption=messageText, chat_id=chat_id ) elif message.video_note: bot.send_video_note( video_note=message.video_note, + caption=messageText, chat_id=chat_id ) elif message.voice: bot.send_voice( voice=message.voice, + caption=messageText, chat_id=chat_id ) elif message.audio: bot.send_audio( audio=message.audio, + caption=messageText, chat_id=chat_id ) elif message.animation: bot.send_animation( animation=message.animation, + caption=messageText, chat_id=chat_id ) def send_msg_command(update: Update, context: CallbackContext) -> None: playerName = update.message.chat.username.lower() - message = angelOrMortal(playerName, message) if players[playerName].chat_id is None or players[playerName].partner.chat_id is None: return - message = angelOrMortal(playerName, update.message) + messageText = angelOrMortal(playerName, update.message) if message.text: context.bot.send_message( - text=message.text, + text=messageText, chat_id=players[playerName].partner.chat_id ) else: - sendNonTextMessage(message, context.bot, players[playerName].partner.chat_id) + sendNonTextMessage(message, context.bot, players[playerName].partner.chat_id, messageText) def admin_command(update: Update, context: CallbackContext) -> None: @@ -159,18 +163,18 @@ def reset_command(update: Update, context: CallbackContext) -> None: logger.info('Players have been reset.') -def angelOrMortal(playerName, message): +def angelOrMortal(playerName, message) -> str: if players[playerName].isAngel: if message.text: - message.text = '\U0001F47C' + message.text + message = '\U0001F47C' + message.text else: - message.caption = '\U0001F47C' + message.caption + message = '\U0001F47C' + message.caption return message else: if message.text: - message.text = '\U0001f476' + message.text + message = '\U0001f476' + message.text else: - message.caption = '\U0001f476' + message.caption + message = '\U0001f476' + message.caption return message From 6afe3e9d1d355d7b9ce45d0c19f3b63d51fa78fb Mon Sep 17 00:00:00 2001 From: fm528 Date: Sat, 27 Aug 2022 18:43:50 +0800 Subject: [PATCH 02/16] Changed pairings --- csv/pairings.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/csv/pairings.csv b/csv/pairings.csv index 146ab92..3204447 100644 --- a/csv/pairings.csv +++ b/csv/pairings.csv @@ -1 +1,2 @@ Angel,Mortal +god,adam From fdbef870b851ae0f6292ba885f9b8fb48a9cfbb0 Mon Sep 17 00:00:00 2001 From: fm528 Date: Sat, 27 Aug 2022 18:50:06 +0800 Subject: [PATCH 03/16] Fixed Bug --- src/bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bot.py b/src/bot.py index d0d6f46..9858f2b 100644 --- a/src/bot.py +++ b/src/bot.py @@ -125,6 +125,7 @@ def send_msg_command(update: Update, context: CallbackContext) -> None: playerName = update.message.chat.username.lower() if players[playerName].chat_id is None or players[playerName].partner.chat_id is None: return + message = update.message messageText = angelOrMortal(playerName, update.message) if message.text: context.bot.send_message( From 47c408fd40c887309ad083689f8068c8ec991ca8 Mon Sep 17 00:00:00 2001 From: fm528 Date: Sat, 27 Aug 2022 19:03:05 +0800 Subject: [PATCH 04/16] First Deployment --- .vs/ProjectSettings.json | 3 +++ .vs/slnx.sqlite | Bin 0 -> 90112 bytes 2 files changed, 3 insertions(+) create mode 100644 .vs/ProjectSettings.json create mode 100644 .vs/slnx.sqlite diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 0000000..f8b4888 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": null +} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..596d48fd6a130aa7be27e23143c4943664618d01 GIT binary patch literal 90112 zcmeI4U2Gdyc7SIz6o;ZjjvPm3vO?+!vVq0gBlG_!X|ScKkEHp2&8yDRG!7k93z7*KLtPAv|4+|71(4uI8eQ94>^r5@h0*fxt7HCnR1=H-+ z!hh!LB7PGvZ}5NG@qXG{mRi60e4b?HeoFGZ!u@pV`O@;@?eJ#{pN4+OGQl0@+jF1K z)#u)yRt2PgX$XXfrpI56va!1YeZ12fDClwH=%6#~Z=h~(&{KQEL0f-2xWC!!ql(h5 z_+{eCb+ObG`ATg={D9v-Q5~&Fn8&ZJ+GPF~zqapgwiQ2KiLkLUR`aI6nl^d=FMyj}VbjSCGcLKk%qyN+kHhD@Ww7l{ zw%&?A-3@CV_pGIPoVS$se$nl5UNLUp^f<4`=`$zrIAcKlbe^yrm&a-C&Ni5rvlr8? zot-l6-KCA0(K22$VZ#6YoxFMU5JyQfQkhMdp4aRhps^|)JZ$kKcr+__a3sa?iddqs zz{ak}=_j0KiDt8;zBaj-3A$ooV_0`gYL^wW1WJ2WfPt9RcmxNXoabXcG%a1PQ5EKj!#OJTh`c9>1fjIw6C zR##6_m<-uFEE^LAbI81g+}@T(XrQ)9*!IdozT@Z3<*dOml-_J)!r=FGzJ?!XnhM?m z#Fme51lia(aO69(BcHN9mFekxQJJDI#tSHGg8jX z()OhOAs$DMb?)M|+J$fgUjxw?#r+far`&h(8+ZW$AOHk_01yBIKmZ5;0U!VbfWR*j zfv1tcJoWA;L$c1V*e7%ieJ6jMMo3QNQnHZD!=Te1SUY3PiUMdKgqMQ?? zqLL6&9n?+dib|o=#hE(YOd*@e3yBWOVV#r|ZW#ANPNtM@I;$X5EDB07l}yQ5MJVR8 z60Qm7l=9iMkm_a&xlXs!P2}@}(v|bsVzMX{6bUQd$;d)S$z+9OE~}(EayQq_B?Y7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W`cubliJP@9+b@|9|G29MB*T00KY&2mk>f00e*l5C8%|00;nqGbaG+|1(Dp4FUlm z00e*l5C8%|00;m9AOHk_01!BH0`U8PXO0{i1Oh++2mk>f00e*l5C8%|00;m9AaLdc k;Qas0kwb$(00;m9AOHk_01yBIKmZ5;0U!Vb&YZyi0+>|)tpET3 literal 0 HcmV?d00001 From 259d177d7c4c8250e18f186487722f86e1fe76f9 Mon Sep 17 00:00:00 2001 From: fm528 Date: Sat, 27 Aug 2022 19:28:57 +0800 Subject: [PATCH 05/16] Fixing Bug --- src/bot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bot.py b/src/bot.py index 9858f2b..a4ddde5 100644 --- a/src/bot.py +++ b/src/bot.py @@ -171,11 +171,11 @@ def angelOrMortal(playerName, message) -> str: else: message = '\U0001F47C' + message.caption return message - else: + if players[playerName].isAngel == False: if message.text: - message = '\U0001f476' + message.text + message = '\U0001F476' + message.text else: - message = '\U0001f476' + message.caption + message = '\U0001F476' + message.caption return message From 43a645852b0b5fb065c0da4e864873b8e6042fd8 Mon Sep 17 00:00:00 2001 From: fm528 Date: Sat, 27 Aug 2022 19:46:41 +0800 Subject: [PATCH 06/16] Bug fixes --- src/bot.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/bot.py b/src/bot.py index a4ddde5..fa04b57 100644 --- a/src/bot.py +++ b/src/bot.py @@ -70,53 +70,53 @@ def chat_command(update: Update, context: CallbackContext) -> None: ) -def sendNonTextMessage(message, bot, chat_id, messageText) -> None: +def sendNonTextMessage(message, bot, chat_id) -> None: if message.photo: bot.send_photo( photo=message.photo[-1], - caption=messageText, + caption=message.caption, chat_id=chat_id ) elif message.sticker: bot.send_sticker( sticker=message.sticker, - caption=messageText, + caption=message.caption, chat_id=chat_id ) elif message.document: bot.send_document( document=message.document, - caption=messageText, + caption=message.caption, chat_id=chat_id ) elif message.video: bot.send_video( video=message.video, - caption=messageText, + caption=message.caption, chat_id=chat_id ) elif message.video_note: bot.send_video_note( video_note=message.video_note, - caption=messageText, + caption=message.caption, chat_id=chat_id ) elif message.voice: bot.send_voice( voice=message.voice, - caption=messageText, + caption=message.caption, chat_id=chat_id ) elif message.audio: bot.send_audio( audio=message.audio, - caption=messageText, + caption=message.caption, chat_id=chat_id ) elif message.animation: bot.send_animation( animation=message.animation, - caption=messageText, + caption=message.caption, chat_id=chat_id ) @@ -126,14 +126,14 @@ def send_msg_command(update: Update, context: CallbackContext) -> None: if players[playerName].chat_id is None or players[playerName].partner.chat_id is None: return message = update.message - messageText = angelOrMortal(playerName, update.message) + #messageText = angelOrMortal(playerName, update.message) if message.text: context.bot.send_message( - text=messageText, + text=message.text, chat_id=players[playerName].partner.chat_id ) else: - sendNonTextMessage(message, context.bot, players[playerName].partner.chat_id, messageText) + sendNonTextMessage(message, context.bot, players[playerName].partner.chat_id) def admin_command(update: Update, context: CallbackContext) -> None: From 192949b58e750b219ba3ae6c6f00ad48bde96581 Mon Sep 17 00:00:00 2001 From: fm528 Date: Sat, 27 Aug 2022 19:58:25 +0800 Subject: [PATCH 07/16] More Bug Fixes --- src/bot.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/bot.py b/src/bot.py index fa04b57..939e537 100644 --- a/src/bot.py +++ b/src/bot.py @@ -70,53 +70,52 @@ def chat_command(update: Update, context: CallbackContext) -> None: ) -def sendNonTextMessage(message, bot, chat_id) -> None: +def sendNonTextMessage(message, bot, chat_id, messageText) -> None: if message.photo: bot.send_photo( photo=message.photo[-1], - caption=message.caption, + caption=messageText, chat_id=chat_id ) elif message.sticker: bot.send_sticker( sticker=message.sticker, - caption=message.caption, chat_id=chat_id ) elif message.document: bot.send_document( document=message.document, - caption=message.caption, + caption=messageText, chat_id=chat_id ) elif message.video: bot.send_video( video=message.video, - caption=message.caption, + caption=messageText, chat_id=chat_id ) elif message.video_note: bot.send_video_note( video_note=message.video_note, - caption=message.caption, + caption=messageText, chat_id=chat_id ) elif message.voice: bot.send_voice( voice=message.voice, - caption=message.caption, + caption=messageText, chat_id=chat_id ) elif message.audio: bot.send_audio( audio=message.audio, - caption=message.caption, + caption=messageText, chat_id=chat_id ) elif message.animation: bot.send_animation( animation=message.animation, - caption=message.caption, + caption=messageText, chat_id=chat_id ) @@ -126,14 +125,14 @@ def send_msg_command(update: Update, context: CallbackContext) -> None: if players[playerName].chat_id is None or players[playerName].partner.chat_id is None: return message = update.message - #messageText = angelOrMortal(playerName, update.message) + messageText = angelOrMortal(playerName, update.message) if message.text: context.bot.send_message( - text=message.text, + text=messageText, chat_id=players[playerName].partner.chat_id ) else: - sendNonTextMessage(message, context.bot, players[playerName].partner.chat_id) + sendNonTextMessage(message, context.bot, players[playerName].partner.chat_id, messageText) def admin_command(update: Update, context: CallbackContext) -> None: @@ -171,7 +170,7 @@ def angelOrMortal(playerName, message) -> str: else: message = '\U0001F47C' + message.caption return message - if players[playerName].isAngel == False: + else: if message.text: message = '\U0001F476' + message.text else: From f6e83772d966fe6a64f1b9a3138d0a848aa6e01c Mon Sep 17 00:00:00 2001 From: fm528 Date: Sat, 27 Aug 2022 20:03:55 +0800 Subject: [PATCH 08/16] Moreeee Bug Fixes --- src/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bot.py b/src/bot.py index 939e537..f6a0e6c 100644 --- a/src/bot.py +++ b/src/bot.py @@ -170,7 +170,7 @@ def angelOrMortal(playerName, message) -> str: else: message = '\U0001F47C' + message.caption return message - else: + elif not players[playerName].isAngel: if message.text: message = '\U0001F476' + message.text else: From 762c7733b5b6297f546f35268a466f07edd2491a Mon Sep 17 00:00:00 2001 From: fm528 Date: Sat, 27 Aug 2022 20:09:35 +0800 Subject: [PATCH 09/16] Bug Fix --- src/bot.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bot.py b/src/bot.py index f6a0e6c..2c4e627 100644 --- a/src/bot.py +++ b/src/bot.py @@ -170,12 +170,12 @@ def angelOrMortal(playerName, message) -> str: else: message = '\U0001F47C' + message.caption return message - elif not players[playerName].isAngel: - if message.text: - message = '\U0001F476' + message.text - else: - message = '\U0001F476' + message.caption - return message + + if message.text: + message = '\U0001F476' + message.text + else: + message = '\U0001F476' + message.caption + return message def main(): From 6ba79226bfda84c425ecc80f2d59f3e3bdbd49d5 Mon Sep 17 00:00:00 2001 From: fm528 Date: Sat, 27 Aug 2022 20:13:38 +0800 Subject: [PATCH 10/16] Final Bug Hopefully --- src/bot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bot.py b/src/bot.py index 2c4e627..56d3ab8 100644 --- a/src/bot.py +++ b/src/bot.py @@ -170,11 +170,11 @@ def angelOrMortal(playerName, message) -> str: else: message = '\U0001F47C' + message.caption return message - - if message.text: - message = '\U0001F476' + message.text else: - message = '\U0001F476' + message.caption + if message.text: + message = '\U0001F476' + message.text + else: + message = '\U0001F476' + message.caption return message From e623560f49549e70ad20ce21bc02be67f39cbde6 Mon Sep 17 00:00:00 2001 From: fm528 Date: Sat, 27 Aug 2022 20:19:25 +0800 Subject: [PATCH 11/16] Final Bug Fix Prt2 --- src/bot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bot.py b/src/bot.py index 56d3ab8..f2c354e 100644 --- a/src/bot.py +++ b/src/bot.py @@ -166,15 +166,15 @@ def reset_command(update: Update, context: CallbackContext) -> None: def angelOrMortal(playerName, message) -> str: if players[playerName].isAngel: if message.text: - message = '\U0001F47C' + message.text + message = '\U0001F47C' + str(message.text or '') else: - message = '\U0001F47C' + message.caption + message = '\U0001F47C' + str(message.text or '') return message else: if message.text: - message = '\U0001F476' + message.text + message = '\U0001F476' + str(message.text or '') else: - message = '\U0001F476' + message.caption + message = '\U0001F476' + str(message.text or '') return message From ff8f006737af8b05ed7a13c2ba6a238864e3a09e Mon Sep 17 00:00:00 2001 From: fm528 Date: Sat, 27 Aug 2022 20:36:33 +0800 Subject: [PATCH 12/16] Added Captions --- src/bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bot.py b/src/bot.py index f2c354e..a61eeb6 100644 --- a/src/bot.py +++ b/src/bot.py @@ -168,13 +168,13 @@ def angelOrMortal(playerName, message) -> str: if message.text: message = '\U0001F47C' + str(message.text or '') else: - message = '\U0001F47C' + str(message.text or '') + message = '\U0001F47C' + str(message.caption or '') return message else: if message.text: message = '\U0001F476' + str(message.text or '') else: - message = '\U0001F476' + str(message.text or '') + message = '\U0001F476' + str(message.caption or '') return message From 2a9f7162ee6b86f73d7b9496e53c6f3f5079b026 Mon Sep 17 00:00:00 2001 From: fm528 Date: Sun, 28 Aug 2022 02:33:25 +0800 Subject: [PATCH 13/16] Updated Messages --- src/messages.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/messages.py b/src/messages.py index 1368216..958b429 100644 --- a/src/messages.py +++ b/src/messages.py @@ -1,6 +1,7 @@ WELCOME_TEXT = 'The conversation will only start when both sides have started the bot.\n\n' HELP_TEXT = ( 'This bot supports only text, photos, stickers, documents, audio, video, and animations.' + '\n\nPlease note that a message from an Angel will be prefaced by an angel and a message from a mortal will be prefaced by a human. DO NOT MIX UP YOUR CHATS!!!' '\n\nThe messages will not be recorded. The conversation will automatically end after the event.' '\n\nUse /help if you want to see this message again.' ) From 3045b0e00aef13134e6f536d3af97db09e3671d5 Mon Sep 17 00:00:00 2001 From: fm528 Date: Sun, 28 Aug 2022 21:21:43 +0800 Subject: [PATCH 14/16] Changed Emoji --- src/bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bot.py b/src/bot.py index a61eeb6..1eaee11 100644 --- a/src/bot.py +++ b/src/bot.py @@ -166,9 +166,9 @@ def reset_command(update: Update, context: CallbackContext) -> None: def angelOrMortal(playerName, message) -> str: if players[playerName].isAngel: if message.text: - message = '\U0001F47C' + str(message.text or '') + message = '\U0001F607' + str(message.text or '') else: - message = '\U0001F47C' + str(message.caption or '') + message = '\U0001F607' + str(message.caption or '') return message else: if message.text: From ab9c8523821ea18f3de804ecce2b7f07056e5396 Mon Sep 17 00:00:00 2001 From: chanjingzhi <36781967+chanjingzhi@users.noreply.github.com> Date: Wed, 31 Aug 2022 02:45:11 +0800 Subject: [PATCH 15/16] Firestore for data permanence --- requirements.txt | 12 ++++++++++++ src/bot.py | 2 +- src/creds.json | 12 ++++++++++++ src/player.py | 26 +++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/creds.json diff --git a/requirements.txt b/requirements.txt index a2bc2c8..d8a8ffd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,13 @@ python-telegram-bot==13.13 +firebase==3.0.1 +firebase-admin==5.2.0 +google-api-core==2.7.3 +google-api-python-client==2.47.0 +google-auth==2.6.6 +google-auth-httplib2==0.1.0 +google-cloud-core==2.3.0 +google-cloud-firestore==2.4.0 +google-cloud-storage==2.3.0 +google-crc32c==1.3.0 +google-resumable-media==2.3.2 +googleapis-common-protos==1.56.0 \ No newline at end of file diff --git a/src/bot.py b/src/bot.py index 1eaee11..d596123 100644 --- a/src/bot.py +++ b/src/bot.py @@ -26,7 +26,7 @@ def start_command(update: Update, context: CallbackContext) -> None: update.message.reply_text(messages.NOT_REGISTERED) return # Registers chat id for message sending. - players[playerName].chat_id = update.message.chat.id + players[playerName].setChatId(update.message.chat.id) logger.info(f'{playerName} started the bot with chat_id {players[playerName].chat_id}.') update.message.reply_text( f'Hey {"Angel" if players[playerName].isAngel else "Mortal"} {playerName}!\n\n{messages.WELCOME_TEXT}{messages.HELP_TEXT}') diff --git a/src/creds.json b/src/creds.json new file mode 100644 index 0000000..fb668f9 --- /dev/null +++ b/src/creds.json @@ -0,0 +1,12 @@ + { + "type": "service_account", + "project_id": "capt-361017", + "private_key_id": "23e20f983975228ac8d813d311e29d1b8d03afde", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwgg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gJhHYJUSQZcc8\ncwPE0/LfyQKBgQCX7Avyyc/gDrOKB0S52/fcf7WSlCz9uDjalXd/dotZkB9nYOr0\nnY+fmtQI3UKj0InD5BTSN9B2SKCXkoRC9wO+6La1x0282qoeCKim6WPw0yL10pdO\nMFfs1n6saIyx6vSASxLzL7Qk6VDa8ws2ayGxv4+nm0W/4LkSVIZYn+119QKBgEnS\n7Z0OFd9tAyk5mu3ctwXKrMxIcmwiqzlUrhIaQ6DHDYCrlMB+I2df3iDvpP1KoRdz\nCrPZEcvoGan8BHFb5n+HRCRMHwCDxPswr4GtcxmquMI1XFzfoVUQi7zFDHREP3ip\nk2j4C+TflJ3CKlxIpmxdZsN7MQ6fCHGqDq1R/0+RAoGBAK8SF3eu83rYt0sPw2jA\nsroMg336l4FozGU0KKPYmhj7Zd4DrYTn+x+R0DFHJmrZ+VQ5u3Fxg/yb7MUH0tFR\npUVRmXgVua0CB6dx88c7W8h/tTL1PBx0wJ2S5vElfOeiUJUgP/tO7Lr2yAfGlMxc\nMYYA1MzrBg8j5hqhsrxsF/ks\n-----END PRIVATE KEY-----\n", + "client_email": "captbot@capt-361017.iam.gserviceaccount.com", + "client_id": "100672919073175058691", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/captbot%40capt-361017.iam.gserviceaccount.com" +} diff --git a/src/player.py b/src/player.py index 13577b6..78a069c 100644 --- a/src/player.py +++ b/src/player.py @@ -1,8 +1,15 @@ import csv import logging -logger = logging.getLogger(__name__) +import firebase_admin +from firebase_admin import credentials +from firebase_admin import firestore +logger = logging.getLogger(__name__) +cred = credentials.Certificate('creds.json')- +app = firebase_admin.initialize_app(cred) +db = firestore.client() +dbName = u'players' class Player(): def __init__(self): @@ -11,6 +18,17 @@ def __init__(self): self.chat_id = None self.isAngel = False + def setChatId(self,id): + self.chat_id = id + docs = db.collection(dbName).where(u'username',u'==',self.username).stream() + result = None + indent = None + for doc in docs: + indent = db.collection(dbName).document(doc.id) + indent.update({ + u'chatId' : id + }) + # Initialise dict of players from players file def loadPlayers(players: dict) -> str: @@ -28,12 +46,18 @@ def loadPlayers(players: dict) -> str: playerName = row[0].strip().lower() partnerName = row[1].strip().lower() + for doc in db.collection(dbName).where(u'username',u'==',playerName).stream(): player = doc.to_dict() + players[playerName].username = playerName players[playerName].partner = players[partnerName] + players[playerName].chat_id = player["chatId"] players[playerName].isAngel = True + for doc in db.collection(dbName).where(u'username',u'==',partnerName).stream(): partner = doc.to_dict() + players[partnerName].username = partnerName players[partnerName].partner = players[playerName] + players[partnerName].chat_id = partner["chatId"] players[partnerName].isAngel = False logger.info(f'Angel {playerName} has Mortal {partnerName}.') From 9795586532dec1c9602baece4fdd15ef72bac76f Mon Sep 17 00:00:00 2001 From: fm528 Date: Wed, 31 Aug 2022 02:55:24 +0800 Subject: [PATCH 16/16] no changes --- .gitignore | 2 ++ src/uploader.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/uploader.py diff --git a/.gitignore b/.gitignore index 40e3e77..8e12c49 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ # pycache src/__pycache__ +src/creds.json + diff --git a/src/uploader.py b/src/uploader.py new file mode 100644 index 0000000..f3e87b0 --- /dev/null +++ b/src/uploader.py @@ -0,0 +1,28 @@ +import csv +import logging + +import firebase_admin +from firebase_admin import credentials +from firebase_admin import firestore +logger = logging.getLogger(__name__) +cred = credentials.Certificate('creds.json') +app = firebase_admin.initialize_app(cred) +db = firestore.client() +dbName = u'players2' + +with open('C:/Users/fmcmu/Documents/GitHub/capt-buddy-bot/csv/pairings.csv') as csv_file: + csv_reader = csv.reader(csv_file, delimiter=',') + line_count = 0 + results = "" + for row in csv_reader: + if line_count == 0: + logger.info(f'Column names are {", ".join(row)}.') + results += f'Column names are {", ".join(row)}.\n' + line_count += 1 + else: + playerName = {"username":row[0].strip().lower(),"chatId" :None} + partnerName = {"username":row[1].strip().lower(),"chatId" :None} + db.collection(dbName).add(playerName) + db.collection(dbName).add(partnerName) + +