fixed env var
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
#Copyright 2020 Sleepingpirate.
|
|
||||||
import os
|
import os
|
||||||
from os import environ
|
from os import environ, path
|
||||||
import logging
|
import logging
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
@@ -8,33 +7,14 @@ import asyncio
|
|||||||
from plexapi.myplex import MyPlexAccount
|
from plexapi.myplex import MyPlexAccount
|
||||||
from discord import Webhook, AsyncWebhookAdapter
|
from discord import Webhook, AsyncWebhookAdapter
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from dotenv import load_dotenv
|
|
||||||
import configparser
|
|
||||||
import texttable
|
import texttable
|
||||||
import sys
|
import sys
|
||||||
|
from app.header.configparser import roleid, PLEXUSER, PLEXPASS, PLEX_SERVER_NAME, Plex_LIBS, chan, ownerid, auto_remove_user
|
||||||
|
|
||||||
sys.stdout = sys.stderr
|
sys.stdout = sys.stderr
|
||||||
CONFIG_PATH = 'app/config/config.ini'
|
|
||||||
BOT_SECTION = 'bot_envs'
|
|
||||||
|
|
||||||
try:
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config.read(CONFIG_PATH)
|
|
||||||
except:
|
|
||||||
print("Cannot find config")
|
|
||||||
|
|
||||||
# settings
|
|
||||||
Discord_bot_token = config.get(BOT_SECTION, 'discord_bot_token')
|
|
||||||
roleid = config.get(BOT_SECTION, 'role_id')
|
|
||||||
PLEXUSER = config.get(BOT_SECTION, 'plex_user')
|
|
||||||
PLEXPASS = config.get(BOT_SECTION, 'plex_pass')
|
|
||||||
PLEX_SERVER_NAME = config.get(BOT_SECTION, 'plex_server_name')
|
|
||||||
Plex_LIBS = config.get(BOT_SECTION, 'plex_libs')
|
|
||||||
chan = int(config.get(BOT_SECTION, 'channel_id'))
|
|
||||||
ownerid = int(config.get(BOT_SECTION, 'owner_id'))
|
|
||||||
auto_remove_user = config.get(BOT_SECTION, 'auto_remove_user') if config.get(BOT_SECTION, 'auto_remove_user') else False
|
|
||||||
|
|
||||||
Plex_LIBS = list(Plex_LIBS.split(','))
|
Plex_LIBS = list(Plex_LIBS.split(','))
|
||||||
roleid = list(roleid.split(','))
|
roleid = list(roleid.split(','))
|
||||||
|
|
||||||
print(roleid)
|
print(roleid)
|
||||||
if auto_remove_user:
|
if auto_remove_user:
|
||||||
print("auto remove user = True")
|
print("auto remove user = True")
|
||||||
|
|||||||
69
app/helper/confighelper.py
Normal file
69
app/helper/confighelper.py
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import configparser
|
||||||
|
from os import environ, path
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
|
||||||
|
CONFIG_PATH = 'app/config/config.ini'
|
||||||
|
BOT_SECTION = 'bot_envs'
|
||||||
|
CONFIG_KEYS = ['username', 'password', 'discord_bot_token', 'plex_user', 'plex_pass',
|
||||||
|
'role_id', 'plex_server_name', 'plex_libs', 'owner_id', 'channel_id',
|
||||||
|
'auto_remove_user']
|
||||||
|
|
||||||
|
def get_config():
|
||||||
|
"""
|
||||||
|
Function to return current config
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
config.read(CONFIG_PATH)
|
||||||
|
return config
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
print('error in reading config')
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG_PATH = 'app/config/config.ini'
|
||||||
|
BOT_SECTION = 'bot_envs'
|
||||||
|
|
||||||
|
# settings
|
||||||
|
Discord_bot_token = ""
|
||||||
|
roleid = 0
|
||||||
|
PLEXUSER = ""
|
||||||
|
PLEXPASS = ""
|
||||||
|
PLEX_SERVER_NAME = ""
|
||||||
|
Plex_LIBS = ""
|
||||||
|
chan = 0
|
||||||
|
ownerid = 0
|
||||||
|
auto_remove_user = ""
|
||||||
|
|
||||||
|
switch = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
if(path.exists(CONFIG_PATH)):
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read(CONFIG_PATH)
|
||||||
|
Discord_bot_token = config.get(BOT_SECTION, 'discord_bot_token')
|
||||||
|
roleid = config.get(BOT_SECTION, 'role_id')
|
||||||
|
PLEXUSER = config.get(BOT_SECTION, 'plex_user')
|
||||||
|
PLEXPASS = config.get(BOT_SECTION, 'plex_pass')
|
||||||
|
PLEX_SERVER_NAME = config.get(BOT_SECTION, 'plex_server_name')
|
||||||
|
Plex_LIBS = config.get(BOT_SECTION, 'plex_libs')
|
||||||
|
chan = int(config.get(BOT_SECTION, 'channel_id'))
|
||||||
|
ownerid = int(config.get(BOT_SECTION, 'owner_id'))
|
||||||
|
auto_remove_user = config.get(BOT_SECTION, 'auto_remove_user') if config.get(BOT_SECTION, 'auto_remove_user') else False
|
||||||
|
switch = 1
|
||||||
|
else:
|
||||||
|
load_dotenv(dotenv_path='bot.env')
|
||||||
|
Discord_bot_token = environ.get('discord_bot_token')
|
||||||
|
roleid = int(environ.get('role_id'))
|
||||||
|
PLEXUSER = environ.get('PLEXUSER')
|
||||||
|
PLEXPASS = config.get(BOT_SECTION, 'plex_pass')
|
||||||
|
PLEX_SERVER_NAME = config.get(BOT_SECTION, 'plex_server_name')
|
||||||
|
Plex_LIBS = config.get(BOT_SECTION, 'plex_libs')
|
||||||
|
chan = int(config.get(BOT_SECTION, 'channel_id'))
|
||||||
|
ownerid = int(config.get(BOT_SECTION, 'owner_id'))
|
||||||
|
auto_remove_user = config.get(BOT_SECTION, 'auto_remove_user') if config.get(BOT_SECTION, 'auto_remove_user') else False
|
||||||
|
switch = 1
|
||||||
|
except:
|
||||||
|
print("Cannot find config/Incomplete config")
|
||||||
|
|
||||||
9
bot.env
Normal file
9
bot.env
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
discord_bot_token=
|
||||||
|
plex_username=
|
||||||
|
plex_password=
|
||||||
|
role_id=
|
||||||
|
plex_server_name=
|
||||||
|
plex_libs=
|
||||||
|
owner_id=
|
||||||
|
channel_id=
|
||||||
|
auto_remove_user=True
|
||||||
11
run.py
11
run.py
@@ -3,18 +3,13 @@ import os
|
|||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
from discord.utils import get
|
from discord.utils import get
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
|
||||||
import Cogs.Json.jshelper as jshelper
|
|
||||||
import sys
|
import sys
|
||||||
|
from app.header.configparser import switch, Discord_bot_token
|
||||||
|
|
||||||
jshelper.prestart()
|
if switch == 0:
|
||||||
data = jshelper.openf("/app/config/app.db")
|
|
||||||
if data["token"] == "":
|
|
||||||
print("Missing Config.")
|
print("Missing Config.")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
data = jshelper.openf("/config/app.db")
|
|
||||||
TOKEN = data["token"]
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.members = True
|
intents.members = True
|
||||||
bot = commands.Bot(command_prefix=".", intents = intents)
|
bot = commands.Bot(command_prefix=".", intents = intents)
|
||||||
@@ -72,4 +67,4 @@ for filename in os.listdir("Cogs"):
|
|||||||
if filename.endswith('.py'):
|
if filename.endswith('.py'):
|
||||||
bot.load_extension(f'Cogs.{filename[:-3]}')
|
bot.load_extension(f'Cogs.{filename[:-3]}')
|
||||||
|
|
||||||
bot.run(TOKEN)
|
bot.run(Discord_bot_token)
|
||||||
Reference in New Issue
Block a user