Added support for Bot tokens (#138)

Added support for Bot tokens
This commit is contained in:
Kowlin 2016-04-15 23:23:14 +02:00 committed by Twentysix
parent a0da25aab2
commit 4994c40bd3
2 changed files with 53 additions and 15 deletions

View File

@ -8,11 +8,18 @@ class Settings:
def __init__(self,path=default_path): def __init__(self,path=default_path):
self.path = path self.path = path
self.check_folders() self.check_folders()
self.default_settings = {"EMAIL" : "EmailHere", "PASSWORD" : "PasswordHere", "OWNER" : "id_here", "PREFIXES" : [], "default":{"ADMIN_ROLE" : "Transistor", "MOD_ROLE" : "Process"}} self.default_settings = {"EMAIL" : "EmailHere", "PASSWORD" : "", "OWNER" : "id_here", "PREFIXES" : [], "default":{"ADMIN_ROLE" : "Transistor", "MOD_ROLE" : "Process"}, "LOGIN_TYPE" : "email"}
if not fileIO(self.path,"check"): if not fileIO(self.path,"check"):
self.bot_settings = self.default_settings self.bot_settings = self.default_settings
self.save_settings() self.save_settings()
else: else:
current = fileIO(self.path, "load")
if current.keys() != self.default_settings.keys():
for key in self.default_settings.keys():
if key not in current.keys():
current[key] = self.default_settings[key]
print("Adding " + str(key) + " field to red settings.json")
fileIO(self.path, "save", current)
self.bot_settings = fileIO(self.path,"load") self.bot_settings = fileIO(self.path,"load")
if "default" not in self.bot_settings: if "default" not in self.bot_settings:
self.update_old_settings() self.update_old_settings()
@ -106,6 +113,15 @@ class Settings:
ret.update({server:self.bot_settings[server]}) ret.update({server:self.bot_settings[server]})
return ret return ret
@property
def login_type(self):
return self.bot_settings["LOGIN_TYPE"]
@login_type.setter
def login_type(self,value):
self.bot_settings["LOGIN_TYPE"] = value
self.save_settings()
def get_server(self,server): def get_server(self,server):
if server is None: if server is None:
return self.bot_settings["default"].copy() return self.bot_settings["default"].copy()

36
red.py
View File

@ -345,17 +345,36 @@ def check_folders():
def check_configs(): def check_configs():
if settings.bot_settings == settings.default_settings: if settings.bot_settings == settings.default_settings:
print("Red - First run configuration") print("Welcome to Red. A modular Discord bot!")
print("Please choose on how you want to log in, you can either choose a normal or bot account.")
print("For more information on bot accounts visit: https://discordapp.com/developers/docs/topics/oauth2#bot-vs-user-accounts")
print("If you don't know that you NEED a bot-tagged account, don't use one. There are more than just cosmetic differences. If still in doubt, select email")
print("Please choose if you want to use a Email or Token.")
settings.login_type = input("\n'email' or 'token'> ").lower()
# Deny empty logintype!
if not settings.login_type:
input("You have to choose either 'email' or 'token'")
exit(1)
# Check if input is either email or token, if email to on to email & password. else go to token input.
if settings.login_type == "email":
print("If you don't have one, create a NEW ACCOUNT for Red. Do *not* use yours. (https://discordapp.com)") print("If you don't have one, create a NEW ACCOUNT for Red. Do *not* use yours. (https://discordapp.com)")
settings.email = input("\nEmail> ") settings.email = input("\nEmail> ")
settings.password = input("\nPassword> ") settings.password = input("\nPassword> ")
if not settings.email:
if not settings.email or not settings.password: input("Email cannot be empty. Restart Red and repeat the configuration process.")
input("Email and password cannot be empty. Restart Red and repeat the configuration process.")
exit(1) exit(1)
if not settings.password:
if "@" not in settings.email: input("Password cannot be empty. Restart Red and repeat the configuration process.")
input("You didn't enter a valid email. Restart Red and repeat the configuration process.") exit(1)
elif settings.login_type == "token":
print("Get your bot token from: https://discordapp.com/developers/applications/me")
print("If you don't have a application or a bot token, make one and a bot account then copy the token.")
settings.email = input("\nToken> ")
if not settings.email:
input("Token cannot be empty. Restart Red and repeat the configuration process.")
exit(1)
else:
input("Please enter 'email' or 'token'. Restart Red and repeat the configuration process.")
exit(1) exit(1)
print("\nChoose a prefix (or multiple ones, one at once) for the commands. Type exit when you're done. Example prefix: !") print("\nChoose a prefix (or multiple ones, one at once) for the commands. Type exit when you're done. Example prefix: !")
@ -489,6 +508,9 @@ def main():
print("Owner has not been set yet. Do '{}set owner' in chat to set yourself as owner.".format(bot.command_prefix[0])) print("Owner has not been set yet. Do '{}set owner' in chat to set yourself as owner.".format(bot.command_prefix[0]))
else: else:
owner.hidden = True # Hides the set owner command from help owner.hidden = True # Hides the set owner command from help
if settings.login_type == "token":
yield from bot.login(settings.email)
else:
yield from bot.login(settings.email, settings.password) yield from bot.login(settings.email, settings.password)
yield from bot.connect() yield from bot.connect()