diff --git a/.gitignore b/.gitignore index 3788098..9675f60 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ *.json *.pyc /.run/ +!/.env diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..f36472a --- /dev/null +++ b/__init__.py @@ -0,0 +1,3 @@ +__version__ = '1.0.0' +__title__ = "Pisya bot" +__author__ = "beaconborn" diff --git a/cogs/audio.py b/cogs/audio.py index f9704cd..b20f279 100644 --- a/cogs/audio.py +++ b/cogs/audio.py @@ -25,6 +25,7 @@ class Audio(commands.Cog): if any('Escape from Tarkov' in str(user.activity) for user in after.channel.members): logging.info('Skip playing by Game') else: + # Prepare list of audio from lib.Comands import read_json _role = await read_json(member.guild.id, 'tigger_role') # Read audio from DB @@ -46,12 +47,12 @@ class Audio(commands.Cog): full_audio = def_audio_db + audio_db await play_audio(random.choice(full_audio), self.bot, after.channel) elif len(member.roles) == 1 or _role is None: - logging.info(f'Skip playing') + logging.info(f'Skip playing by role') elif any(str(role.id) in _role for role in member.roles): logging.info(f'Play audio from list by role') await play_audio(random.choice(def_audio_ls), self.bot, after.channel) else: - logging.info(f'Skip playing') + logging.info(f'Skip playing by any else') @commands.command(name="upload_audio") async def upload_audio(self, ctx, user=None): diff --git a/lib/CogsPrepare.py b/lib/CogsPrepare.py index 3ace086..076b376 100644 --- a/lib/CogsPrepare.py +++ b/lib/CogsPrepare.py @@ -1,13 +1,16 @@ +""" +lib.CogsPrepare +~~~~~~~~~~~~~ +Loads, unloads Cogs files +cog_list: return list of cog filenames +work_with_cogs: loads, reloads and unloads cogs files + +""" import logging from os import listdir from disnake.ext import commands -""" -Loads, unloads Cogs files -cog_list: return list of cog filenames - -""" def cog_list(): diff --git a/lib/Comands.py b/lib/Comands.py index 19211c1..42376d2 100644 --- a/lib/Comands.py +++ b/lib/Comands.py @@ -1,14 +1,21 @@ import json -from os import walk +import os + """ Some prepare for commands """ +def check_conf(): + if not os.path.isfile(os.getenv('conf_file')): + with open(os.getenv('conf_file'), 'w+', encoding='utf-8') as f: + f.write("") + + async def list_files(fold: str = 'audio'): fl = [] - for filenames in walk(fold): + for filenames in os.walk(fold): fl.extend(filenames) break files = {} @@ -24,11 +31,11 @@ async def read_json(guild: int, _param: str): :param _param: Parameter in json file :return: value of parameter. """ - with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON - parameter = None + parameter = None + with open(os.getenv('conf_file'), 'r', encoding='utf-8') as f: # Open the JSON try: - _json = json.load(fp) # Load the custom prefixes - except TypeError: + _json = json.load(f) # Load the custom prefixes + except json.decoder.JSONDecodeError: _json = {} if guild: # If the guild exists try: @@ -43,7 +50,7 @@ async def read_json(guild: int, _param: str): async def write_json(guild: int, param_name: str, param: str or int): - with open('prefix.json', 'r', encoding='utf-8') as f: + with open(os.getenv('conf_file'), 'r', encoding='utf-8') as f: try: _json = json.load(f) except json.decoder.JSONDecodeError: @@ -54,7 +61,7 @@ async def write_json(guild: int, param_name: str, param: str or int): _json.update({f'{guild}': {}}) _guild = _json[f'{guild}'] _guild.update({f'{param_name}': f'{param}'}) - with open('prefix.json', 'w', encoding='utf-8') as f: + with open(os.getenv('conf_file'), 'w', encoding='utf-8') as f: json.dump(_json, f, indent=4) @@ -66,9 +73,9 @@ def determine_prefix(bot, msg): :return: prefix for server, default is $ """ parameter = '$' - with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON + with open(os.getenv('conf_file'), 'r', encoding='utf-8') as f: # Open the JSON try: - _json = json.load(fp) # Load the custom prefixes + _json = json.load(f) # Load the custom prefixes except: _json = {} try: @@ -86,9 +93,9 @@ def determine_time(msg): :return: prefix for server, default is $ """ parameter = 15 - with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON + with open(os.getenv('conf_file'), 'r', encoding='utf-8') as f: # Open the JSON try: - _json = json.load(fp) # Load the custom prefixes + _json = json.load(f) # Load the custom prefixes except: _json = {} try: diff --git a/lib/__init__.py b/lib/__init__.py index e69de29..4d64265 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -0,0 +1,10 @@ +""" +lib +~~~~~~~~~~~~~ +Some libs for the bot whitch help him +""" + +from .DB import * +from .Player import * +from .Comands import * +from .CogsPrepare import * diff --git a/requirements.txt b/requirements.txt index e73597a..0e0a8df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ disnake[audio]~=2.5.2 setuptools==65.3.0 psutil~=5.9.1 pymediainfo~=5.1.0 -pyNaCl~=1.5.0 \ No newline at end of file +pyNaCl~=1.5.0 +python-dotenv~=0.20.0 diff --git a/setup.py b/setup.py index d2c73e0..40a2a05 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,15 @@ from setuptools import setup +import test setup( name='fun and admin bot', - version='1.0.0', + version=test.__version__, packages=['lib'], url='', + platforms='POSIX', license='', author='riksl', author_email='', - description='' + description='', + requires=[] ) diff --git a/test.py b/test.py index bffb6e4..237a478 100644 --- a/test.py +++ b/test.py @@ -1,18 +1,18 @@ import asyncio import logging +import os import sys -from os import path - +import pisya_bot import disnake from disnake import OptionChoice, OptionType, Option from disnake.ext import commands +from dotenv import load_dotenv from lib.CogsPrepare import work_with_cogs -from lib.Comands import determine_prefix +from lib.Comands import determine_prefix, check_conf -if not path.isfile('prefix.json'): - with open('prefix.json', 'w+', encoding='utf-8') as f: - f.write("") +load_dotenv() +check_conf() intents = disnake.Intents(messages=True, guilds=True, @@ -37,6 +37,7 @@ asyncio.run(work_with_cogs('load', bot)) async def on_ready(): logging.info(f'Bot started') logging.info('We have logged in as {0.user}'.format(bot)) + logging.info(f'{pisya_bot.__version__}') @bot.slash_command( @@ -65,4 +66,4 @@ async def slash_cogs(inter, what_do): await inter.response.send_message('You`re not bot owner', ephemeral=True) -bot.run('OTQ2ODE5MDA0MzE0NTcwODUy.YhkP6Q.dhFqi2MJMrxzHt5FtjK5Cl-5BI8') +bot.run(os.getenv('TOKEN'))