Browse Source

Change config stuff and how they're handled

master
l4p1n 9 months ago
parent
commit
d74dc89177
Signed by untrusted user: l4p1n <l4p1n@l4p1n.ch> GPG Key ID: 8A2C2F68B58DC35C
7 changed files with 16 additions and 21 deletions
  1. +1
    -0
      .gitignore
  2. +2
    -2
      app.py
  3. +1
    -1
      cmds/server_events.py
  4. +2
    -2
      lib/BotClass.py
  5. +9
    -0
      lib/config.example.py
  6. +0
    -15
      lib/config.py
  7. +1
    -1
      lib/database.py

+ 1
- 0
.gitignore View File

@@ -9,3 +9,4 @@ webapp/dl
l4p1n-env
yoyo.ini
logs/
lib/config.py

+ 2
- 2
app.py View File

@@ -25,7 +25,7 @@ extensions = [
'cmds.scheduled_messages'
]
if __name__ == '__main__':
bot = BotClass([config.command_prefix,])
bot = BotClass([config.BOT_COMMAND_PREFIX])
bot.remove_command('help')

# Setup le logging
@@ -64,4 +64,4 @@ if __name__ == '__main__':
application.error(tr)

application.info('Exécution du bot')
bot.run(config.discord_api_token)
bot.run(config.BOT_TOKEN)

+ 1
- 1
cmds/server_events.py View File

@@ -95,7 +95,7 @@ class ServerEvents(commands.Cog):
self.logging.info('Attempt to post server count to discordbots.org')
data = {"server_count": bot_count}
headers = {
"Authorization": config.dbl_token,
"Authorization": config.DISCORD_BOT_LIST_TOKEN,
"User-Agent": 'l4p1n-bot <contact@l4p1n.ch>',
'Content-Type': 'application/json'
}


+ 2
- 2
lib/BotClass.py View File

@@ -37,8 +37,8 @@ class BotClass(commands.Bot):
if not self.has_been_init:
assert self.has_been_init is False
self.matrix = matrix_helpers.MatrixHelper()
self.matrix.set_default_room(config.matrix['room_id'])
await self.matrix.connect(config.matrix['homeserver'], config.matrix['username'], config.matrix['password'])
self.matrix.set_default_room(config.MATRIX_ROOM_ID)
await self.matrix.connect(config.MATRIX_HOMESERVER, config.MATRIX_USERNAME, config.MATRIX_PASSWORD)
await self.cogs['SocketServerCog'].start_server()

self.has_been_init = True


+ 9
- 0
lib/config.example.py View File

@@ -0,0 +1,9 @@
DISCORD_BOT_LIST_TOKEN = None
DISCORD_WONDERBOT_TOKEN = None # Previously named Discord Bot List FR
BOT_COMMAND_PREFIX = '!'
BOT_TOKEN = None
DATABASE_URL = None
MATRIX_HOMESERVER = None
MATRIX_USERNAME = None
MATRIX_PASSWORD = None
MATRIX_ROOM_ID = None

+ 0
- 15
lib/config.py View File

@@ -1,15 +0,0 @@
import json

with open('config.json') as f:
__config = json.load(f)


def __getattr__(name):
if name not in __config:
raise AttributeError(f'No key named {name} in config')

return __config.get(name)


def get(key, default=None):
__config.get(key, default)

+ 1
- 1
lib/database.py View File

@@ -17,7 +17,7 @@ async def init_database():
return

logger.info('Connexion effective à la base de données')
database = await asyncpg.create_pool(config.database, min_size=5, max_size=15)
database = await asyncpg.create_pool(config.DATABASE_URL, min_size=5, max_size=15)
event.set()

return database


Loading…
Cancel
Save