Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reload command to update database from slack #80

Merged
merged 3 commits into from
Dec 19, 2017
Merged

Add reload command to update database from slack #80

merged 3 commits into from
Dec 19, 2017

Conversation

Kileak
Copy link
Collaborator

@Kileak Kileak commented Dec 17, 2017

Moved the database initialization into a static function, so we can trigger it from a challenge command. Calling !reload will reinitialize the pickle database with the information from slack (likely the same as restarting the bot).

Fixes #78

def execute(self, slack_wrapper, args, channel_id, user_id):
"""Execute the Reload command."""

slack_wrapper.post_message(channel_id, "Start updating CTF challenge handler...")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we start using more user-friendly messages such as :

Updating CTFs and challenges...
Update finished.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I ask is because most people don't know/care about the concept of "handlers" :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. That's why "localization" should be done by someone other than a developer :)

Will update this later. Maybe we should refactor all the texts out of the code in something like a resource file, separating code and texts.

Initialize the challenge handler.
This might be refactored. Not sure, if the handler itself should do the channel handling,
or if it should be used to a common class, so it can be reused.
Reloads the ctf and challenge information from slack.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imperative: "Reload" not "Reloads"

pickle.dump(database, open(ChallengeHandler.DB, "wb+"))

def init(self, slack_wrapper):
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Put into one line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also probably don't need doc strings for things as obvious as this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a remnant from the previous code.

"archivectf": CommandDesc(ArchiveCTFCommand, "Archive the challenges of a ctf", None, None)
}

def init(self, slack_wrapper):
def update_database_from_slack(slack_wrapper):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs self or @classmethod or @staticmethod decorator.

pickle.dump(database, open(ChallengeHandler.DB, "wb+"))

def init(self, slack_wrapper):
ChallengeHandler.update_database_from_slack(slack_wrapper)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init is a proper method. So this could use self.update_database_from_slack.

We should change the registration of handlers so that we do NOT instantiate the handler class, in which case we'd change all of these to class or static methods.

I'll file a separate ticket.

pickle.dump(database, open(ChallengeHandler.DB, "wb+"))

def init(self, slack_wrapper):
ChallengeHandler.update_database_from_slack(slack_wrapper)

# Register this handler
HandlerFactory.register("ctf", ChallengeHandler())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See that the challenge handler is instantiated here. We probably don't need to if we are keeping all state in the class object itself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just made this "static", so we can call it from the ReloadCommand, which has no reference to the challenge handler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I filed #86 to figure out how we want to do this. This is fine for now.

@Corb3nik Corb3nik merged commit dff6ce5 into OpenToAllCTF:development Dec 19, 2017
@Grazfather Grazfather deleted the reload branch December 19, 2017 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants