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

Move invite URL generation to on_ready event #166

Closed
CarrotManMatt opened this issue Mar 28, 2024 · 6 comments · Fixed by #175
Closed

Move invite URL generation to on_ready event #166

CarrotManMatt opened this issue Mar 28, 2024 · 6 comments · Fixed by #175
Assignees
Labels
good first issue Good for newcomers refactor Improvements to the codebase that do not directly affect users

Comments

@CarrotManMatt
Copy link
Member

Rather than generating the invite URL from a util CLI command, it should just be output when the bot is run.

If the selected guild (from the given ID) is not available to the bot, the bot should shut down. An error message should be alerted that the bot needs to be invited using the outputted invite URL link.

Completion of this issue should also include removing the whole of the CLI util command framework.

@CarrotManMatt CarrotManMatt added good first issue Good for newcomers refactor Improvements to the codebase that do not directly affect users labels Mar 28, 2024
@edwinchan129
Copy link
Contributor

I'd like to take this issue on. Is there any helpful files/lines of code I should start looking at for this issue?

@CarrotManMatt
Copy link
Member Author

CarrotManMatt commented Mar 30, 2024

Hi @edwinchan129! We really appreciate you looking to contribute to TeX-Bot. The main changes for this issue would be to:

I have added links to all the necessary code lines/documentation but feel free to look around any of the existing code to see how we have used the invite URL generation code so far. And keep asking questions if you ever get stuck or need any additional help!

@edwinchan129
Copy link
Contributor

edwinchan129 commented Mar 31, 2024

@CarrotManMatt Do you mean that the bot should output a link when this command "poetry run python -m main" is run instead and generate an invite link based on variables set on the .env file? I'm also unsure on how to get Tex-Bot to run properly in my test server as I'm unsure what to put into the required variables: MEMBERS_LIST_URL, MEMBERS_LIST_URL_SESSION_COOKIE, and MODERATION_DOCUMENT_URL.

@CarrotManMatt
Copy link
Member Author

Do you mean that the bot should output a link when this command "poetry run python -m main" is run instead

In a sense. If you call the logger.info() function from within the on_ready() function within cogs/startup.py it will output the generated link when the bot starts up (either automatically or by running the command you mentioned.

generate an invite link based on variables set on the .env file?

Retrieving the main guild is already done within the on_ready() function. So it technically uses the values from the .env file, however you won't need to worry about that. I'd recommend taking a look at the existing code within the on_ready() function to see how the main_guild object is used.

I'm unsure what to put into the required variables: MEMBERS_LIST_URL, MEMBERS_LIST_URL_SESSION_COOKIE, and MODERATION_DOCUMENT_URL

Apologies about this. The current state of the project makes these variables required, however they should be optional when running locally. They are used only for the /makemember function so if you're not testing that they should be optional (unfortunately they're not).

  • For MEMBERS_LIST_URL you can just put any valid URL that you like
  • For MEMBERS_LIST_URL_SESSION_COOKIE you can put any sequence of 128 letters (just has to match this regex: \A[A-Fa-f\d]{128,256}\Z)
  • For MODERATION_DOCUMENT_URL you can just put any valid URL that you like

See the .env.example file for descriptions on all these environment variables & the docs here

@edwinchan129
Copy link
Contributor

Alright I got the basics of it down and it seems to be working at generating an invite url. I just want to ask some more clarifying questions before I test it further and the submit a pull request.

If the selected guild (from the given ID) is not available to the bot, the bot should shut down. An error message should be alerted that the bot needs to be invited using the outputted invite URL link.

Does this mean that the the invite url should be generated each time the bot is run, but the bot should exit out if the user doesn't invite the bot to the guild specified in the .env file? I see in the startup.py that there is a check for whether the bot has a main_guild set, but this itself doesn't verify whether the bot is already in the server before proceeding. It does, however, shut down if the main_guild isn't set. Should this be modified to the case I mentioned or is simply generating a valid invite url at the moment all that matters?

@CarrotManMatt
Copy link
Member Author

Good thoughts!

I would suggest that if the bot is already in the selected guild, then the invite URL should only be outputted if the log level is set to DEBUG, otherwise it continues running but does not output the invite URL.

If the bot is not yet in the selected guild (hence main_guild does not get set because the guild is not within the list of guild that the bot is within) it should always output the invite URL and then shut down.

edwinchan129 added a commit to edwinchan129/TeX-Bot-Py-V2 that referenced this issue Apr 14, 2024
Moved invite URL generation to global function within utils/generate_invite_url.py.
Deleted utils/__main__.py and utils/base_utility_function.py.
Removed main() from utils/init.py.
Moved call to generate_invite_url() to startup.py.
    - If main guild not set, invite URL will be outputted and bot will be shutdown.
    - If main guild is set, invite URL will only be outputted if CONSOLE_LOG_LEVEL in environment variable set to DEBUG.
I had to modify tests for generate_invite_url() in test/tests_util.py reflect new behavior as it no longer takes in command line arguments.
    - You may need to modify it accordingly to remove irrelevant test cases and adjust to new behavior.
@codemicro codemicro linked a pull request Apr 14, 2024 that will close this issue
CarrotManMatt pushed a commit that referenced this issue Apr 21, 2024
* Fix Issue #166

* Fixed Pull Request #175 Ruff Issues

* Trailing Whitespace in cogs/startup.py removed

* Update test_utility functions and Remove unnecessary checks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers refactor Improvements to the codebase that do not directly affect users
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants