From 779c7c20ce2339067f70f2505145114caa108a98 Mon Sep 17 00:00:00 2001 From: Rami Mouro Date: Mon, 4 Mar 2019 18:08:59 -0700 Subject: [PATCH 1/2] Added Daily Programmer on message command, Implemented saving it to a text file, and pinging General, Still in progress: Figuring out the link so that it links it in General. --- pybot/endpoints/slack/messages.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/pybot/endpoints/slack/messages.py b/pybot/endpoints/slack/messages.py index b5414de7..d9131d86 100644 --- a/pybot/endpoints/slack/messages.py +++ b/pybot/endpoints/slack/messages.py @@ -18,6 +18,7 @@ def create_endpoints(plugin): plugin.on_message(".*@here", here_bad) plugin.on_message(".*@channel", here_bad) plugin.on_message(".*\!pybot", advertise_pybot) + plugin.on_message("=== .* Daily Programmer ===.*", daily_challenge) def not_bot_message(event: Message): @@ -32,7 +33,7 @@ async def advertise_pybot(event: Message, app: SirBot): BOT_URL = 'https://github.com/OperationCode/operationcode-pybot' response = {'channel': event['channel'], 'text': f'OC-Community-Bot is a community led project' - f'\n <{BOT_URL}|source> '} + f'\n <{BOT_URL}|source> '} await app.plugins["slack"].api.query(methods.CHAT_POST_MESSAGE, data=response) @@ -81,3 +82,27 @@ async def message_deleted(event: Message, app: SirBot): except Exception as E: logger.exception(E) logger.debug(event) + + +async def daily_challenge(event: Message, app: SirBot): + """ + Pings general with the new Daily Challenge as well as saves it to a text file. + """ + new_message = event["text"] + f = open("DailyChallenges.txt", "w+") + f.write(new_message + "\n") + f.close() + link = permlink(event["ts"], event["channel"]) + response = {'channel': 'general', + 'text': 'New Daily Challenge', + 'attachments': [ + { + "fallback": "Check out today's Daily Challenge!", + "color": "#36a64f", + "title": "Daily Challenge", + "title_link": link, + "text": new_message, + } + ] + } + await app.plugins["slack"].api.query(methods.CHAT_POST_MESSAGE, data=response) From de86c7c5cbd95c8803cfb8cea984622d6b2d3e8c Mon Sep 17 00:00:00 2001 From: Rami Mouro Date: Tue, 5 Mar 2019 13:59:25 -0700 Subject: [PATCH 2/2] fixed it up and made it look pretty for PR purposes. --- pybot/endpoints/slack/messages.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/pybot/endpoints/slack/messages.py b/pybot/endpoints/slack/messages.py index d9131d86..0d9cbee7 100644 --- a/pybot/endpoints/slack/messages.py +++ b/pybot/endpoints/slack/messages.py @@ -87,22 +87,14 @@ async def message_deleted(event: Message, app: SirBot): async def daily_challenge(event: Message, app: SirBot): """ Pings general with the new Daily Challenge as well as saves it to a text file. + Planning on adding a link to the new challenge but this will come later. """ new_message = event["text"] f = open("DailyChallenges.txt", "w+") f.write(new_message + "\n") f.close() - link = permlink(event["ts"], event["channel"]) - response = {'channel': 'general', - 'text': 'New Daily Challenge', - 'attachments': [ - { - "fallback": "Check out today's Daily Challenge!", - "color": "#36a64f", - "title": "Daily Challenge", - "title_link": link, - "text": new_message, - } - ] - } + response = { + 'channel': 'general', + 'text': 'New Daily Programmer challenge check out #Daily-programmer' + } await app.plugins["slack"].api.query(methods.CHAT_POST_MESSAGE, data=response)