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 an Auto Config system and have a default config file. #73

Closed
wants to merge 4 commits into from
Closed

Add an Auto Config system and have a default config file. #73

wants to merge 4 commits into from

Conversation

Inheritanc-e
Copy link

@Inheritanc-e Inheritanc-e commented Jan 14, 2021

Fixes #50

Created an auto-config system, added a config folder which contains the config list and the default config files for the bot, modified constants.py to use the config files to store channel and role ids. Used collections.namedtuple for channel and role constants. Modified return statements in __init__.py. Synced the project to use modified constants.py

…he config list and the default config files for the bot, modified constants.py to use the config files to store channel and role ids. Used collections.namedtuple for channel and role constants. Modified return statments in __init__.py. Synced the project to use modified constants.py

Polls:
optional: False

Copy link
Contributor

Choose a reason for hiding this comment

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

Add the un-optional channels here too, and when the bot goes over them, it asks the user whether they want to create the un-optional channels or not.
Same for the roles.

Copy link
Author

Choose a reason for hiding this comment

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

It is pretty obvious that the channels and roles that have not been marked as optional are mandatory.

Copy link
Contributor

Choose a reason for hiding this comment

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

But, to test the github category we need the dev categories, so hence we need them.

Copy link
Author

Choose a reason for hiding this comment

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

We need them hence it's set to false.

Copy link
Author

Choose a reason for hiding this comment

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

And if we require them to be mandatory then we could just completely remove them from the config-list.yaml

Copy link
Contributor

Choose a reason for hiding this comment

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

We need them hence it's set to false.

the dev-gurkbot, etc. are required for github category and I don't see them here.

Copy link
Author

Choose a reason for hiding this comment

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

Well they aren't needed for the bot as of now. So....

class Channels(NamedTuple):
devalerts = int(os.getenv("CHANNEL_DEVALERTS", 796695123177766982))
devlog = int(os.getenv("CHANNEL_DEVLOG", 789431367167377448))
class Gurkbot:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
class Gurkbot:
class Client:

Copy link
Author

Choose a reason for hiding this comment

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

Having the class as the bot's name would make more sense IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if the name of the bot changes in future?

Copy link
Author

Choose a reason for hiding this comment

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

Then we change the name of the class.

Copy link
Member

Choose a reason for hiding this comment

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

Do we really need this class? Is it related to how auto-config works?
Gurkbot doesn't feel like an apt name.

Copy link
Author

Choose a reason for hiding this comment

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

I mean would it not make sense to have the tokens and prefix of the bot in a single class?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it would keep the client constants together

Copy link
Author

Choose a reason for hiding this comment

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

Client can mean many things.

ERROR_REPLIES = bot_replies["ERROR_REPLIES"]
POSITIVE_REPLIES = bot_replies["POSITIVE_REPLIES"]
NEGATIVE_REPLIES = bot_replies["NEGATIVE_REPLIES"]
ERROR_REPLIES = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did u shift the error replies to constants.py from the yaml file?
See fisher's comments on Error Handler Pr

Copy link
Author

Choose a reason for hiding this comment

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

Gotcha.

token = os.getenv('TOKEN')


Channels = namedtuple(
Copy link
Contributor

Choose a reason for hiding this comment

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

Using a class for this looks better and more readable and easier to understand.

Copy link
Author

Choose a reason for hiding this comment

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

If we use a class then we would have to insert them again. But we shouldn't have to do that because it already exists in the config, file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using namedtuple, why not pick them like we did for the environment variables?

Copy link
Author

Choose a reason for hiding this comment

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

What do you mean?
Namedtuple is perfect for storing constants.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure about this one, chief.
We should discuss this on the server. Readability is lost.
Btw, you can use typing.NamedTuple to create a named tuple and I feel that'd produce more readable code.

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 agree with @codephile1221, the readability is lost, @gustavwilliam whats your say on this?

Copy link
Member

Choose a reason for hiding this comment

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

TBH, readability doesn't matter much since you can look at the original config file.

Copy link
Author

Choose a reason for hiding this comment

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

How is readability lost?
This is very much understandable, the first parameter of named tuples are keys and the default keyword takes a tuple which are the values for those keys going from left to right.

Copy link
Contributor

Choose a reason for hiding this comment

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

Which is easier to understand, the former way or the yours?

Copy link
Author

Choose a reason for hiding this comment

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

Mine is very much understandable, if you wish to see the ids then the config file exists for that, and you would not understand mine only if you don't know how namedtuple works.

Comment on lines +28 to +30
""" Check's if the guild exists or not, if not then raises NotFound."""

if not self.bot.get_guild(int(os.getenv('Guild_ID'))):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
""" Check's if the guild exists or not, if not then raises NotFound."""
if not self.bot.get_guild(int(os.getenv('Guild_ID'))):
"""Check's if the guild exists or not, if not then raises NotFound."""
if not self.bot.get_guild(int(os.getenv('Guild_ID'))):

There shouldn't be a empty space in def functions.

return

else:
logger.info('Successfully created all the roles and roles')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.info('Successfully created all the roles and roles')
logger.info('Successfully created all the roles')

Comment on lines +112 to +113
for c in self.required()['Channels']:
await guild.create_text_channel(name=c)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for c in self.required()['Channels']:
await guild.create_text_channel(name=c)
for channel in self.required()['Channels']:
await guild.create_text_channel(name=channel)

return

else:
logger.info('Successfully created all the roles and channels!')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.info('Successfully created all the roles and channels!')
logger.info('Successfully created all the roles.')

Isn't this only making the channels?

Copy link
Author

Choose a reason for hiding this comment

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

If the code reached up the else statement then it means that the server doesn't have the channels configured nor does it have the roles configured.

Comment on lines +125 to +129
for c in self.required()['Channels']:
await guild.create_text_channel(name=c)

for r in self.check()['Roles']:
await guild.create_role(name=r)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for c in self.required()['Channels']:
await guild.create_text_channel(name=c)
for r in self.check()['Roles']:
await guild.create_role(name=r)
for channel in self.required()['Channels']:
await guild.create_text_channel(name=channel)
for role in self.check()['Roles']:
await guild.create_role(name=role)

'The bot does not have the required permissions to create the roles and the channels!')

else:
logger.info('Successfully created all the roles and channels and roles!')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.info('Successfully created all the roles and channels and roles!')
logger.info('Successfully created all the roles and channels!')

@Shivansh-007
Copy link
Contributor

@Inheritanc-e Can you fix the conflicts in here?

@RohanJnr
Copy link
Member

is this PR still WIP?

@gustavwilliam
Copy link
Member

is this PR still WIP?

@RohanJnr definitely doesn't seem so

@gustavwilliam
Copy link
Member

@Inheritanc-e Thanks for all the work you did with this. Sadly it doesn't seem like it'll be finished, so I'm closing the PR.

The code is pretty outdated compared to the rest of the bot today, but if you would like to resume something like this in the future, feel free to ping me.

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.

Have a default config file.
5 participants