2016-08-31 07:28:58 +12:00
|
|
|
import ruamel.yaml as yaml
|
2016-07-09 13:27:19 +12:00
|
|
|
import asyncio
|
2016-08-31 07:21:17 +12:00
|
|
|
import rethinkdb as r
|
2016-09-01 15:24:21 +12:00
|
|
|
import pendulum
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
loop = asyncio.get_event_loop()
|
2016-09-29 12:39:34 +13:00
|
|
|
global_config = {}
|
2016-07-09 13:27:19 +12:00
|
|
|
|
2016-08-19 13:56:41 +12:00
|
|
|
# Ensure that the required config.yml file actually exists
|
2016-08-12 14:14:30 +12:00
|
|
|
try:
|
|
|
|
with open("config.yml", "r") as f:
|
2017-03-08 12:18:18 +13:00
|
|
|
global_config = yaml.safe_load(f)
|
2017-05-12 15:06:27 +12:00
|
|
|
global_config = {k: v for k, v in global_config.items() if v}
|
2016-08-12 14:14:30 +12:00
|
|
|
except FileNotFoundError:
|
|
|
|
print("You have no config file setup! Please use config.yml.sample to setup a valid config file")
|
|
|
|
quit()
|
2016-07-11 09:57:52 +12:00
|
|
|
|
2016-08-31 07:51:04 +12:00
|
|
|
try:
|
|
|
|
bot_token = global_config["bot_token"]
|
|
|
|
except KeyError:
|
|
|
|
print("You have no bot_token saved, this is a requirement for running a bot.")
|
|
|
|
print("Please use config.yml.sample to setup a valid config file")
|
|
|
|
quit()
|
|
|
|
|
2016-09-01 07:09:11 +12:00
|
|
|
|
2016-08-19 13:56:41 +12:00
|
|
|
# Default bot's description
|
2016-08-31 10:33:37 +12:00
|
|
|
bot_description = global_config.get("description")
|
2016-08-19 13:56:41 +12:00
|
|
|
# Bot's default prefix for commands
|
2016-09-01 07:09:11 +12:00
|
|
|
default_prefix = global_config.get("command_prefix", "!")
|
2016-08-19 13:56:41 +12:00
|
|
|
# The key for bots.discord.pw and carbonitex
|
2016-08-12 14:14:30 +12:00
|
|
|
discord_bots_key = global_config.get('discord_bots_key', "")
|
2016-08-19 13:56:41 +12:00
|
|
|
carbon_key = global_config.get('carbon_key', "")
|
2016-09-21 10:22:02 +12:00
|
|
|
# The client ID for twitch requsets
|
|
|
|
twitch_key = global_config.get('twitch_key', "")
|
2016-10-08 15:45:00 +13:00
|
|
|
# The key for youtube API calls
|
|
|
|
youtube_key = global_config.get("youtube_key", "")
|
2016-10-29 16:16:01 +13:00
|
|
|
# The key for Osu API calls
|
|
|
|
osu_key = global_config.get('osu_key', '')
|
2017-02-18 17:11:47 +13:00
|
|
|
# The key for League of Legends API calls
|
|
|
|
lol_key = global_config.get('lol_key', '')
|
2016-10-08 15:45:00 +13:00
|
|
|
# The keys needed for deviant art calls
|
2016-08-19 13:56:41 +12:00
|
|
|
# The invite link for the server made for the bot
|
2016-08-16 15:30:52 +12:00
|
|
|
dev_server = global_config.get("dev_server", "")
|
2016-10-29 13:33:55 +13:00
|
|
|
# The User-Agent that we'll use for most requests
|
2017-05-12 15:06:27 +12:00
|
|
|
user_agent = global_config.get('user_agent', None)
|
|
|
|
# The URL to proxy youtube_dl's requests through
|
|
|
|
ytdl_proxy = global_config.get('youtube_dl_proxy', None)
|
2016-10-31 16:14:30 +13:00
|
|
|
# The extensions to load
|
2017-05-15 13:08:13 +12:00
|
|
|
extensions = [
|
|
|
|
'cogs.interaction',
|
|
|
|
'cogs.misc',
|
|
|
|
'cogs.mod',
|
|
|
|
'cogs.admin',
|
|
|
|
'cogs.images',
|
|
|
|
'cogs.owner',
|
|
|
|
'cogs.stats',
|
|
|
|
'cogs.picarto',
|
|
|
|
'cogs.overwatch',
|
|
|
|
'cogs.links',
|
|
|
|
'cogs.roles',
|
|
|
|
'cogs.tictactoe',
|
|
|
|
'cogs.hangman', 'cogs.events', 'cogs.raffle',
|
|
|
|
'cogs.twitch',
|
|
|
|
'cogs.blackjack',
|
|
|
|
'cogs.osu',
|
|
|
|
'cogs.tags',
|
|
|
|
'cogs.roulette',
|
|
|
|
'cogs.music',
|
2017-06-07 20:30:19 +12:00
|
|
|
'cogs.polls',
|
|
|
|
'cogs.playlist',
|
|
|
|
'cogs.dj'
|
2017-05-15 13:08:13 +12:00
|
|
|
]
|
2017-05-12 12:50:57 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
|
2016-08-19 13:56:41 +12:00
|
|
|
# The default status the bot will use
|
2017-01-06 07:13:22 +13:00
|
|
|
default_status = global_config.get("default_status", None)
|
2016-08-31 07:21:17 +12:00
|
|
|
# The rethinkdb hostname
|
2016-08-31 07:51:04 +12:00
|
|
|
db_host = global_config.get('db_host', 'localhost')
|
2016-08-31 07:21:17 +12:00
|
|
|
# The rethinkdb database name
|
2016-08-31 07:51:04 +12:00
|
|
|
db_name = global_config.get('db_name', 'Discord_Bot')
|
2016-08-31 07:21:17 +12:00
|
|
|
# The rethinkdb certification
|
2016-08-31 07:51:04 +12:00
|
|
|
db_cert = global_config.get('db_cert', '')
|
2016-08-31 07:21:17 +12:00
|
|
|
# The rethinkdb port
|
|
|
|
db_port = global_config.get('db_port', 28015)
|
2016-09-01 08:21:52 +12:00
|
|
|
# The user and password assigned
|
|
|
|
db_user = global_config.get('db_user', 'admin')
|
|
|
|
db_pass = global_config.get('db_pass', '')
|
2016-08-31 13:48:30 +12:00
|
|
|
# We've set all the options we need to be able to connect
|
|
|
|
# so create a dictionary that we can use to unload to connect
|
2016-09-01 08:21:52 +12:00
|
|
|
# db_opts = {'host': db_host, 'db': db_name, 'port': db_port, 'ssl':
|
|
|
|
# {'ca_certs': db_cert}, 'user': db_user, 'password': db_pass}
|
|
|
|
db_opts = {'host': db_host, 'db': db_name, 'port': db_port, 'user': db_user, 'password': db_pass}
|
2016-09-01 07:09:11 +12:00
|
|
|
|
|
|
|
|
|
|
|
def command_prefix(bot, message):
|
2017-06-07 20:30:19 +12:00
|
|
|
if not message.guild:
|
2016-09-01 10:53:33 +12:00
|
|
|
return default_prefix
|
2017-06-07 20:30:19 +12:00
|
|
|
return bot.db.load('server_settings', key=message.guild.id, pluck='prefix') or default_prefix
|