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

feat: Allow multiple telegram IDs #52

Merged
merged 13 commits into from
Dec 11, 2022
Merged

feat: Allow multiple telegram IDs #52

merged 13 commits into from
Dec 11, 2022

Conversation

dhilman
Copy link
Contributor

@dhilman dhilman commented Dec 9, 2022

Moved to loading all of env file variables with viper. This provides the nice benefit of type support.

Updated existing config.Init to have a more explicit name and use an instance of viper rather than the global.

#41

Copy link
Owner

@m1guelpf m1guelpf left a comment

Choose a reason for hiding this comment

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

LGTM! Since you're adding tests, could you add an Actions workflow that runs them? 😄

@m1guelpf
Copy link
Owner

Also, it is not super clear to me if this still allows leaving the ID field empty & specifying a single ID, could we get tests for those as well? :D

@dhilman
Copy link
Contributor Author

dhilman commented Dec 10, 2022

Hey @m1guelpf, yeah good shout on both, moved to table tests as there are a few now. Action added 😉

Left the test action to run on ubuntu-latest only, think that is sufficient considering we build on other OSs. Lmk if you would rather have it run on all as well

Copy link
Owner

@m1guelpf m1guelpf left a comment

Choose a reason for hiding this comment

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

LGTM! Just some final comments before we get this in 😄

Comment on lines 29 to 31
if !fileExists(path) {
return nil, fmt.Errorf("config file '%s' does not exist", path)
}
Copy link
Owner

Choose a reason for hiding this comment

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

Following #46, we want to proceed when the .env file isn't found (but print a warning just in case)

Copy link
Contributor Author

@dhilman dhilman Dec 10, 2022

Choose a reason for hiding this comment

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

there is a slight issue with this (a quirk of viper). it requires reading a config into viper to register the keys, only these keys will then be loaded from env.

imo we should rename env.example to .env and keep the failure.

One other alternative would be to register the keys by encoding an empty instance of the EnvConfig we have, before reading from env, wdyt @m1guelpf ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@m1guelpf updated with a somewhat of a middle ground, introduced an emptyConfig string for the purpose of registering the keys.

Test added for when no file is provided

want: &EnvConfig{
TelegramID: []int64{},
TelegramToken: "",
EditWaitSeconds: 0,
Copy link
Owner

Choose a reason for hiding this comment

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

This should default to 1 right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

defaults to 1 in the Validate method

@m1guelpf m1guelpf linked an issue Dec 10, 2022 that may be closed by this pull request
@m1guelpf m1guelpf mentioned this pull request Dec 10, 2022
@m1guelpf m1guelpf closed this Dec 11, 2022
@m1guelpf m1guelpf reopened this Dec 11, 2022
@m1guelpf m1guelpf merged commit 9d23a22 into m1guelpf:main Dec 11, 2022
@kairin
Copy link

kairin commented Dec 13, 2022

Last login: Tue Dec 13 19:01:55 on ttys000
mini@Macs-Mac-mini ~ % /Users/mini/Applications/ChatGPT/chatgpt-telegram-Darwin-arm64/chatgpt-telegram ; exit;
2022/12/13 19:03:42 Started ChatGPT
2022/12/13 19:03:42 config file .env does not exist, using env variables
2022/12/13 19:03:42 Invalid .env config: TELEGRAM_TOKEN is not set

Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

i received the following error running on Mac Mini M1.

i am unsure how to troubleshoot it or what went wrong.

i have edited the env.example to env.env according to the instructions.
also updated the .json file according to instructions.

@xros
Copy link

xros commented Dec 17, 2022

Last login: Tue Dec 13 19:01:55 on ttys000
mini@Macs-Mac-mini ~ % /Users/mini/Applications/ChatGPT/chatgpt-telegram-Darwin-arm64/chatgpt-telegram ; exit;
2022/12/13 19:03:42 Started ChatGPT
2022/12/13 19:03:42 config file .env does not exist, using env variables
2022/12/13 19:03:42 Invalid .env config: TELEGRAM_TOKEN is not set
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]

i received the following error running on Mac Mini M1.

i am unsure how to troubleshoot it or what went wrong.

i have edited the env.example to env.env according to the instructions. also updated the .json file according to instructions.

copy env.example to .env in the same folder.

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.

Allowing for multiple Telegram IDs
4 participants