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

WIP rate-limiting as middleware per user #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

NikitosnikN
Copy link
Owner

No description provided.

@@ -14,9 +14,9 @@ jobs:
uses: actions/checkout@v3

- name: AI Code Reviewer
uses: your-username/ai-code-reviewer@main
uses: freeedcom/ai-codereviewer@v2.7.0

Choose a reason for hiding this comment

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

Consider using a more descriptive name for your repository. The name ai-codereviewer could be more specific to reflect the functionality of the repository.

OPENAI_API_MODEL: "gpt-4"

Choose a reason for hiding this comment

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

The model gpt-4 does not exist. Please use a valid model name.

func RateLimit(requestsPerSecond int) telebot.MiddlewareFunc {
return func(next telebot.HandlerFunc) telebot.HandlerFunc {
return func(c telebot.Context) error {
u := c.Get(string(user.UserInfoContextKey)).(*user.User)

Choose a reason for hiding this comment

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

There is a potential for a panic here if the type assertion .(*user.User) fails. It would be safer to use the comma ok idiom to check if the type assertion was successful.

return func(c telebot.Context) error {
u := c.Get(string(user.UserInfoContextKey)).(*user.User)

if u == nil {

Choose a reason for hiding this comment

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

This check for u == nil is redundant as it will never be nil if the type assertion at line 12 fails. It would be better to remove this check.

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.

None yet

1 participant