added .env
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@
|
||||
*.json
|
||||
*.pyc
|
||||
/.run/
|
||||
!/.env
|
||||
|
||||
3
__init__.py
Normal file
3
__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
__version__ = '1.0.0'
|
||||
__title__ = "Pisya bot"
|
||||
__author__ = "beaconborn"
|
||||
@@ -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):
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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
|
||||
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:
|
||||
|
||||
@@ -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 *
|
||||
|
||||
@@ -3,3 +3,4 @@ setuptools==65.3.0
|
||||
psutil~=5.9.1
|
||||
pymediainfo~=5.1.0
|
||||
pyNaCl~=1.5.0
|
||||
python-dotenv~=0.20.0
|
||||
|
||||
7
setup.py
7
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=[]
|
||||
)
|
||||
|
||||
15
test.py
15
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'))
|
||||
|
||||
Reference in New Issue
Block a user