added .env

This commit is contained in:
2022-08-28 20:36:58 +03:00
parent 78a477f21a
commit caa8d6b20e
9 changed files with 59 additions and 29 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@
*.json *.json
*.pyc *.pyc
/.run/ /.run/
!/.env

3
__init__.py Normal file
View File

@@ -0,0 +1,3 @@
__version__ = '1.0.0'
__title__ = "Pisya bot"
__author__ = "beaconborn"

View File

@@ -25,6 +25,7 @@ class Audio(commands.Cog):
if any('Escape from Tarkov' in str(user.activity) for user in after.channel.members): if any('Escape from Tarkov' in str(user.activity) for user in after.channel.members):
logging.info('Skip playing by Game') logging.info('Skip playing by Game')
else: else:
# Prepare list of audio
from lib.Comands import read_json from lib.Comands import read_json
_role = await read_json(member.guild.id, 'tigger_role') _role = await read_json(member.guild.id, 'tigger_role')
# Read audio from DB # Read audio from DB
@@ -46,12 +47,12 @@ class Audio(commands.Cog):
full_audio = def_audio_db + audio_db full_audio = def_audio_db + audio_db
await play_audio(random.choice(full_audio), self.bot, after.channel) await play_audio(random.choice(full_audio), self.bot, after.channel)
elif len(member.roles) == 1 or _role is None: 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): elif any(str(role.id) in _role for role in member.roles):
logging.info(f'Play audio from list by role') logging.info(f'Play audio from list by role')
await play_audio(random.choice(def_audio_ls), self.bot, after.channel) await play_audio(random.choice(def_audio_ls), self.bot, after.channel)
else: else:
logging.info(f'Skip playing') logging.info(f'Skip playing by any else')
@commands.command(name="upload_audio") @commands.command(name="upload_audio")
async def upload_audio(self, ctx, user=None): async def upload_audio(self, ctx, user=None):

View File

@@ -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 import logging
from os import listdir from os import listdir
from disnake.ext import commands from disnake.ext import commands
"""
Loads, unloads Cogs files
cog_list: return list of cog filenames
"""
def cog_list(): def cog_list():

View File

@@ -1,14 +1,21 @@
import json import json
from os import walk import os
""" """
Some prepare for commands 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'): async def list_files(fold: str = 'audio'):
fl = [] fl = []
for filenames in walk(fold): for filenames in os.walk(fold):
fl.extend(filenames) fl.extend(filenames)
break break
files = {} files = {}
@@ -24,11 +31,11 @@ async def read_json(guild: int, _param: str):
:param _param: Parameter in json file :param _param: Parameter in json file
:return: value of parameter. :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: try:
_json = json.load(fp) # Load the custom prefixes _json = json.load(f) # Load the custom prefixes
except TypeError: except json.decoder.JSONDecodeError:
_json = {} _json = {}
if guild: # If the guild exists if guild: # If the guild exists
try: 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): 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: try:
_json = json.load(f) _json = json.load(f)
except json.decoder.JSONDecodeError: 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}': {}}) _json.update({f'{guild}': {}})
_guild = _json[f'{guild}'] _guild = _json[f'{guild}']
_guild.update({f'{param_name}': f'{param}'}) _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) json.dump(_json, f, indent=4)
@@ -66,9 +73,9 @@ def determine_prefix(bot, msg):
:return: prefix for server, default is $ :return: prefix for server, default is $
""" """
parameter = '$' 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: try:
_json = json.load(fp) # Load the custom prefixes _json = json.load(f) # Load the custom prefixes
except: except:
_json = {} _json = {}
try: try:
@@ -86,9 +93,9 @@ def determine_time(msg):
:return: prefix for server, default is $ :return: prefix for server, default is $
""" """
parameter = 15 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: try:
_json = json.load(fp) # Load the custom prefixes _json = json.load(f) # Load the custom prefixes
except: except:
_json = {} _json = {}
try: try:

View File

@@ -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 *

View File

@@ -3,3 +3,4 @@ setuptools==65.3.0
psutil~=5.9.1 psutil~=5.9.1
pymediainfo~=5.1.0 pymediainfo~=5.1.0
pyNaCl~=1.5.0 pyNaCl~=1.5.0
python-dotenv~=0.20.0

View File

@@ -1,12 +1,15 @@
from setuptools import setup from setuptools import setup
import test
setup( setup(
name='fun and admin bot', name='fun and admin bot',
version='1.0.0', version=test.__version__,
packages=['lib'], packages=['lib'],
url='', url='',
platforms='POSIX',
license='', license='',
author='riksl', author='riksl',
author_email='', author_email='',
description='' description='',
requires=[]
) )

15
test.py
View File

@@ -1,18 +1,18 @@
import asyncio import asyncio
import logging import logging
import os
import sys import sys
from os import path import pisya_bot
import disnake import disnake
from disnake import OptionChoice, OptionType, Option from disnake import OptionChoice, OptionType, Option
from disnake.ext import commands from disnake.ext import commands
from dotenv import load_dotenv
from lib.CogsPrepare import work_with_cogs 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'): load_dotenv()
with open('prefix.json', 'w+', encoding='utf-8') as f: check_conf()
f.write("")
intents = disnake.Intents(messages=True, intents = disnake.Intents(messages=True,
guilds=True, guilds=True,
@@ -37,6 +37,7 @@ asyncio.run(work_with_cogs('load', bot))
async def on_ready(): async def on_ready():
logging.info(f'Bot started') logging.info(f'Bot started')
logging.info('We have logged in as {0.user}'.format(bot)) logging.info('We have logged in as {0.user}'.format(bot))
logging.info(f'{pisya_bot.__version__}')
@bot.slash_command( @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) await inter.response.send_message('You`re not bot owner', ephemeral=True)
bot.run('OTQ2ODE5MDA0MzE0NTcwODUy.YhkP6Q.dhFqi2MJMrxzHt5FtjK5Cl-5BI8') bot.run(os.getenv('TOKEN'))