Compare commits
114 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb2966a867 | |||
| 5915bde104 | |||
| 1ac50de2d1 | |||
| 693d865b95 | |||
| fff65ba25d | |||
| 40bf30b19f | |||
| 3e4f8937f3 | |||
| a9eb223616 | |||
| b515fb0f81 | |||
| 9a280d3814 | |||
| 031758c2cd | |||
| 9fb61e2b98 | |||
| aafa3c33a9 | |||
|
|
01792e12da | ||
| 6801d9a0fd | |||
| f314a50e3f | |||
| c22b71353f | |||
|
|
899527436f | ||
|
|
95ac0caf30 | ||
|
|
27f4cd6122 | ||
| 39ec9b9bf7 | |||
| 1aaa489f55 | |||
| bb3fda4778 | |||
| c108d7d32c | |||
| 9bb86699f7 | |||
| c9f6407149 | |||
| 335c661a34 | |||
| bc304827f5 | |||
| 9a143ba84a | |||
|
|
9fc0c4c071 | ||
|
|
1852f4ebe2 | ||
|
|
37eef98e20 | ||
|
|
62a8921e10 | ||
|
|
14dd773d5c | ||
|
|
c8d2f7c344 | ||
|
|
720cff55c1 | ||
|
|
4a539becca | ||
|
|
734427d16f | ||
|
|
fa08480a34 | ||
|
|
581d9d4c84 | ||
|
|
bbb597f5f6 | ||
|
|
109f61c146 | ||
|
|
f9ce4c9d2d | ||
|
|
2725b7a499 | ||
|
|
721b33d963 | ||
|
|
b3e8502804 | ||
|
|
9652cac405 | ||
|
|
cd182db4ba | ||
|
|
fde794e7aa | ||
|
|
efb5fd0531 | ||
|
|
641ab7c3fb | ||
|
|
0e7a32f36a | ||
|
|
7faad7df23 | ||
|
|
43457b7fc1 | ||
|
|
5ee3403c3f | ||
|
|
5f8cf83d35 | ||
|
|
e3cdb3812a | ||
|
|
50ccbca4be | ||
|
|
f19bcabe61 | ||
|
|
f33ec2fc20 | ||
|
|
877348711e | ||
|
|
52c1d2717e | ||
|
|
7adfe234fb | ||
|
|
e867dd23c1 | ||
|
|
99ded107f1 | ||
|
|
fc492d1ba8 | ||
|
|
f98c77faf9 | ||
|
|
da9755e948 | ||
|
|
98e71f66e9 | ||
|
|
ca1837318d | ||
|
|
76d1625346 | ||
|
|
fff1a5c0c7 | ||
|
|
e1fc05dea2 | ||
|
|
d352541a86 | ||
|
|
1a6c0c1f49 | ||
|
|
361a39420a | ||
|
|
765acd0d42 | ||
|
|
ee277e44c8 | ||
|
|
eaaffd2056 | ||
|
|
4598294bd1 | ||
|
|
4c5a5718fc | ||
|
|
29246e7b97 | ||
|
|
3048bf1f51 | ||
|
|
d93654043a | ||
|
|
93198bf82b | ||
|
|
e60793315b | ||
|
|
d1e62a3941 | ||
|
|
758d775a5b | ||
|
|
d22c3ca6b6 | ||
|
|
4e535f6580 | ||
|
|
cb72e48f09 | ||
|
|
786c580b47 | ||
|
|
46de864da3 | ||
|
|
a4e672597c | ||
|
|
9fa7624be7 | ||
|
|
073be5e629 | ||
|
|
16ea4ede05 | ||
|
|
b6539a31fc | ||
|
|
6a07ef45f2 | ||
|
|
814f88756c | ||
|
|
49122706a7 | ||
|
|
39da2d53fc | ||
|
|
7d32b69809 | ||
|
|
8fba876e93 | ||
|
|
a28cd1e421 | ||
|
|
ca25888325 | ||
|
|
2ec3efbdeb | ||
|
|
e31039eb8b | ||
|
|
6fe0df2fb7 | ||
|
|
308272803d | ||
|
|
a9d50dc478 | ||
|
|
958c70ef4d | ||
|
|
fca483e4e6 | ||
|
|
736621c516 |
11
.dockerignore
Normal file
11
.dockerignore
Normal file
@@ -0,0 +1,11 @@
|
||||
/tmp/
|
||||
audio/*/
|
||||
/.idea
|
||||
user.db
|
||||
*.pyc
|
||||
/.run/
|
||||
.env
|
||||
*.exe
|
||||
/venv/
|
||||
config.json
|
||||
.editorconfig
|
||||
9
.gitignore
vendored
9
.gitignore
vendored
@@ -1,12 +1,11 @@
|
||||
/tmp/
|
||||
/audio/*/
|
||||
audio/*/
|
||||
/.idea
|
||||
/user.db
|
||||
user.db
|
||||
*.pyc
|
||||
/.run/
|
||||
/.env
|
||||
.env
|
||||
*.exe
|
||||
/venv/
|
||||
/fun_and_admin_bot.egg-info/
|
||||
/.YMcache/
|
||||
config.json
|
||||
.editorconfig
|
||||
158
.gitlab-ci.yml
158
.gitlab-ci.yml
@@ -1,67 +1,111 @@
|
||||
# You can override the included template(s) by including variable overrides
|
||||
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
|
||||
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
|
||||
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
|
||||
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
|
||||
# Note that environment variables can be set in several places
|
||||
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
|
||||
|
||||
stages:
|
||||
- 'test'
|
||||
- 'code_quality'
|
||||
- 'deploy'
|
||||
- 'build'
|
||||
- 'push'
|
||||
|
||||
sast:
|
||||
pytest:
|
||||
stage: 'test'
|
||||
include:
|
||||
- template: Security/SAST.gitlab-ci.yml
|
||||
- template: Security/Dependency-Scanning.gitlab-ci.yml
|
||||
- template: Security/SAST-IaC.gitlab-ci.yml
|
||||
|
||||
qodana:
|
||||
stage: 'code_quality'
|
||||
needs: ['gemnasium-python-dependency_scanning', 'semgrep-sast', 'kics-iac-sast']
|
||||
image: python
|
||||
only:
|
||||
- master
|
||||
- merge_requests
|
||||
image:
|
||||
name: jetbrains/qodana-python-community
|
||||
entrypoint:
|
||||
- ''
|
||||
- test
|
||||
- tags
|
||||
cache:
|
||||
- key: qodana-2023.3-$CI_DEFAULT_BRANCH-$CI_COMMIT_REF_SLUG
|
||||
fallback_keys:
|
||||
- qodana-2023.3-$CI_DEFAULT_BRANCH-
|
||||
- qodana-2023.3-
|
||||
paths:
|
||||
- ".qodana/cache"
|
||||
variables:
|
||||
QODANA_TOKEN: "$qodana_token"
|
||||
script:
|
||||
- qodana --save-report --results-dir=$CI_PROJECT_DIR/.qodana/results --cache-dir=$CI_PROJECT_DIR/.qodana/cache
|
||||
artifacts:
|
||||
expose_as: qodana_report
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- ".qodana/results/"
|
||||
|
||||
|
||||
push:
|
||||
stage: 'deploy'
|
||||
image: 'alpine'
|
||||
needs: ['qodana']
|
||||
only:
|
||||
- master
|
||||
- $CI_PROJECT_DIR/venv/
|
||||
before_script:
|
||||
- apk add openssh-client > /dev/null
|
||||
- eval $(ssh-agent -s)
|
||||
- chmod 400 $SSH_PRIVATE_KEY
|
||||
|
||||
- mkdir -p ~/.ssh
|
||||
- chmod 700 ~/.ssh
|
||||
|
||||
- cp $SSH_PRIVATE_KEY ~/.ssh/id_rsa
|
||||
|
||||
- ssh-add ~/.ssh/id_rsa
|
||||
- cd $CI_PROJECT_DIR
|
||||
- python -m venv venv
|
||||
- chmod u+x venv/bin/activate
|
||||
- source venv/bin/activate
|
||||
- pip install --upgrade --quiet pip
|
||||
- pip install --quiet -U -r requirements.txt
|
||||
- pip install --quiet -U -r tests/requirements.txt
|
||||
script:
|
||||
- ssh $BOT_HOST -oStrictHostKeyChecking=accept-new 'cd /opt/discord/tarkov && git pull'
|
||||
- pytest -v
|
||||
|
||||
|
||||
variables:
|
||||
# DOCKER_HOST: tcp://docker:2375
|
||||
# fill those if you have a proxy in your environment
|
||||
DOCKER_DRIVER: overlay2
|
||||
# See https://github.com/docker-library/docker/pull/166
|
||||
DOCKER_TLS_CERTDIR: "/certs"
|
||||
|
||||
make_image:
|
||||
stage: build
|
||||
needs:
|
||||
- pytest
|
||||
image: docker:26.1.3
|
||||
services:
|
||||
- docker:26.1.3-dind
|
||||
|
||||
before_script:
|
||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||
|
||||
script:
|
||||
# fetches the latest image (not failing if image is not found)
|
||||
- docker pull $CI_REGISTRY_IMAGE:latest || true
|
||||
# builds the project, passing proxy variables, using OCI labels
|
||||
# notice the cache-from, which is going to use the image we just pulled locally
|
||||
# the built image is tagged locally with the commit SHA, and then pushed to
|
||||
# the GitLab registry
|
||||
- >
|
||||
DOCKER_BUILDKIT=1 docker build
|
||||
--pull
|
||||
--cache-from $CI_REGISTRY_IMAGE:latest
|
||||
--label "org.opencontainers.image.title=$CI_PROJECT_TITLE"
|
||||
--label "org.opencontainers.image.url=$CI_PROJECT_URL"
|
||||
--label "org.opencontainers.image.created=$CI_JOB_STARTED_AT"
|
||||
--label "org.opencontainers.image.revision=$CI_COMMIT_SHA"
|
||||
--label "org.opencontainers.image.version=$CI_COMMIT_REF_NAME"
|
||||
--tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
|
||||
.
|
||||
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
|
||||
|
||||
# Here, the goal is to tag the "master" branch as "latest"
|
||||
Push latest:
|
||||
variables:
|
||||
# We are just playing with Docker here.
|
||||
# We do not need GitLab to clone the source code.
|
||||
GIT_STRATEGY: none
|
||||
stage: push
|
||||
before_script:
|
||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||
script:
|
||||
# Because we have no guarantee that this job will be picked up by the same runner
|
||||
# that built the image in the previous step, we pull it again locally
|
||||
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
|
||||
# Then we tag it "latest"
|
||||
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:latest
|
||||
# Annnd we push it.
|
||||
- docker push $CI_REGISTRY_IMAGE:latest
|
||||
|
||||
# Finally, the goal here is to Docker tag any Git tag
|
||||
# GitLab will start a new pipeline everytime a Git tag is created, which is pretty awesome
|
||||
Push commit:
|
||||
variables:
|
||||
# Again, we do not need the source code here. Just playing with Docker.
|
||||
GIT_STRATEGY: none
|
||||
stage: push
|
||||
before_script:
|
||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||
script:
|
||||
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
|
||||
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
|
||||
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
|
||||
|
||||
Push tag:
|
||||
variables:
|
||||
# Again, we do not need the source code here. Just playing with Docker.
|
||||
GIT_STRATEGY: none
|
||||
stage: push
|
||||
only:
|
||||
# We want this job to be run on tags only.
|
||||
- tags
|
||||
before_script:
|
||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||
script:
|
||||
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
|
||||
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
||||
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
||||
22
Dockerfile
Normal file
22
Dockerfile
Normal file
@@ -0,0 +1,22 @@
|
||||
FROM python:3.12.2-slim-bookworm as builder
|
||||
LABEL authors="bacon"
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt /app
|
||||
RUN pip wheel install \
|
||||
--no-cache-dir -q \
|
||||
--no-deps --wheel-dir /app/wheels \
|
||||
-r requirements.txt
|
||||
|
||||
FROM python:3.12.2-slim-bookworm as runner
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=builder /app/wheels /wheels
|
||||
RUN apt-get update -qq && \
|
||||
apt-get install -qq --no-install-recommends ffmpeg -y && \
|
||||
apt-get clean -qq autoclean && \
|
||||
pip install --no-cache -q /wheels/*
|
||||
COPY src/ /app
|
||||
|
||||
ENTRYPOINT ["python", "bot.py"]
|
||||
#ENTRYPOINT ["ffmpeg"]
|
||||
0
docker-compose.yml
Normal file
0
docker-compose.yml
Normal file
@@ -1,45 +0,0 @@
|
||||
"""
|
||||
lib.CogsPrepare
|
||||
~~~~~~~~~~~~~
|
||||
Loads, unloads Cogs files
|
||||
cog_list: return list of cog filenames
|
||||
work_with_cogs: loads, reloads and unloads cogs files
|
||||
|
||||
"""
|
||||
from os import listdir, rename
|
||||
from typing import List
|
||||
|
||||
from disnake.ext import commands
|
||||
|
||||
from .Logger import logger
|
||||
|
||||
|
||||
async def cog_list(fold: str = './cogs') -> List[str]:
|
||||
cogs_list = []
|
||||
for _filename in listdir(fold):
|
||||
if _filename.endswith('.py'):
|
||||
cogs_list.append(_filename[:-3])
|
||||
return cogs_list
|
||||
|
||||
|
||||
async def work_with_cogs(what_do, bot: commands.Bot, cog):
|
||||
if isinstance(cog, str):
|
||||
cog = cog.split()
|
||||
for _filename in cog:
|
||||
if what_do == "load":
|
||||
bot.load_extension(f'cogs.{_filename}')
|
||||
logger.info(f'Loaded cog {_filename}')
|
||||
elif what_do == 'unload':
|
||||
bot.unload_extension(f'cogs.{_filename}')
|
||||
logger.info(f'Cog {_filename} unloaded')
|
||||
elif what_do == 'reload':
|
||||
bot.reload_extension(f'cogs.{_filename}')
|
||||
logger.info(f'Cog {_filename} reloaded')
|
||||
elif what_do == 'disable':
|
||||
bot.unload_extension(f'cogs.{_filename}')
|
||||
rename(f'cogs/{_filename}.py', f'cogs/disabled/{_filename}.py')
|
||||
logger.info(f'Cog {_filename} stopped and disabled')
|
||||
elif what_do == 'enable':
|
||||
rename(f'cogs/disabled/{_filename}.py', f'cogs/{_filename}.py')
|
||||
bot.load_extension(f'cogs.{_filename}')
|
||||
logger.info(f'Cog {_filename} started and enabled')
|
||||
@@ -1,5 +0,0 @@
|
||||
"""
|
||||
lib
|
||||
~~~~~~~~~~~~~
|
||||
Some libs for the bot which help him
|
||||
"""
|
||||
@@ -1,6 +0,0 @@
|
||||
version: "1.0"
|
||||
bootstrap: |
|
||||
rm -rf .idea
|
||||
pip install -U -r requirements.txt
|
||||
profile:
|
||||
name: qodana.recommended
|
||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
__version__ = '0.0.7'
|
||||
__title__ = "Pisya_bot"
|
||||
__title__ = "src"
|
||||
__author__ = "baconborn"
|
||||
|
||||
from typing import NamedTuple, Literal
|
||||
15
bot.py → src/bot.py
Executable file → Normal file
15
bot.py → src/bot.py
Executable file → Normal file
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
from os import getenv
|
||||
from os.path import isfile
|
||||
|
||||
@@ -7,10 +6,9 @@ from disnake import OptionType, Option, Localized, ApplicationCommandInteraction
|
||||
from disnake.ext.commands import Bot, is_owner
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from __init__ import __version__ as ver
|
||||
from lib.CogsPrep import work_with_cogs, cog_list
|
||||
from lib.Comands import determine_prefix
|
||||
from lib.Logger import logger
|
||||
from integral_lib.CogsPrep import work_with_cogs, cog_list
|
||||
from integral_lib.Comands import determine_prefix
|
||||
from integral_lib.Logger import logger
|
||||
|
||||
load_dotenv()
|
||||
if not isfile('.env') or not getenv('CONF_FILE'):
|
||||
@@ -37,7 +35,7 @@ bot = Bot(command_prefix=determine_prefix,
|
||||
|
||||
bot.i18n.load("locale/")
|
||||
|
||||
asyncio.run(work_with_cogs('load', bot, asyncio.run(cog_list())))
|
||||
work_with_cogs('load', bot, cog_list())
|
||||
|
||||
|
||||
@bot.event
|
||||
@@ -45,7 +43,6 @@ async def on_ready():
|
||||
logger.info('Bot started')
|
||||
logger.info(f'Disnake version {__version__}')
|
||||
logger.info(f'We have logged in as {bot.user}')
|
||||
logger.info(f'Version of bot is - v{ver}')
|
||||
|
||||
|
||||
@bot.slash_command(
|
||||
@@ -141,14 +138,14 @@ async def reload(inter: ApplicationCommandInteraction, cog: str):
|
||||
@reload.autocomplete('cog')
|
||||
async def _cog_opt(inter: ApplicationCommandInteraction, current: str):
|
||||
current = current.lower()
|
||||
_list = await cog_list(fold='./cogs/')
|
||||
_list = cog_list(fold='./cogs/')
|
||||
return [choice for choice in _list if current in choice.lower()]
|
||||
|
||||
|
||||
@enable.autocomplete('cog')
|
||||
async def _cog_opt(inter: ApplicationCommandInteraction, current: str):
|
||||
current = current.lower()
|
||||
_list = await cog_list(fold='./cogs/disabled/')
|
||||
_list = cog_list(fold='./cogs/disabled/')
|
||||
return [choice for choice in _list if current in choice.lower()]
|
||||
|
||||
|
||||
@@ -2,16 +2,16 @@ from asyncio import sleep
|
||||
|
||||
import disnake
|
||||
from disnake import Option, OptionType, Localized
|
||||
from disnake.ext import commands, tasks
|
||||
from disnake.ext import tasks
|
||||
|
||||
from lib.Comands import read_json, write_json
|
||||
from lib.DB_Worker import fill_bd, prepare_db, work_with_db
|
||||
from lib.Logger import logger
|
||||
from integral_lib.Comands import *
|
||||
from integral_lib.DB_Worker import fill_bd, prepare_db, work_with_db
|
||||
from integral_lib.Logger import logger
|
||||
|
||||
|
||||
class Admin(commands.Cog, name='Admin'):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot # a defining bot as global var in class
|
||||
self.bot = bot # a defining src as global var in class
|
||||
|
||||
@commands.Cog.listener() # this is a decorator for events/listeners
|
||||
async def on_ready(self):
|
||||
@@ -54,7 +54,7 @@ class Admin(commands.Cog, name='Admin'):
|
||||
async def on_member_join(self, member):
|
||||
await fill_bd(member.name, member.id, member.bot, member.nick, member.guild.id)
|
||||
|
||||
bot_role = read_json(member.guild.id, 'bot_role') # Get bot role
|
||||
bot_role = read_json(member.guild.id, 'bot_role') # Get src role
|
||||
guest_role = read_json(member.guild.id, 'guest_role') # Get guest role
|
||||
|
||||
if bot_role or guest_role:
|
||||
@@ -67,7 +67,7 @@ class Admin(commands.Cog, name='Admin'):
|
||||
|
||||
@commands.slash_command(
|
||||
name="set_default_role",
|
||||
description=Localized("Set Default bot role", key="DEF_ROLE"),
|
||||
description=Localized("Set Default src role", key="DEF_ROLE"),
|
||||
options=[
|
||||
Option("role",
|
||||
"Specify role",
|
||||
@@ -78,7 +78,7 @@ class Admin(commands.Cog, name='Admin'):
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def set_guest_role(self, inter: disnake.ApplicationCommandInteraction, role):
|
||||
await write_json(inter.guild.id, "guest_role", role.id)
|
||||
await inter.response.send_message(f"Set up bot role to: `{role.name}`", ephemeral=True)
|
||||
await inter.response.send_message(f"Set up src role to: `{role.name}`", ephemeral=True)
|
||||
|
||||
@commands.command(name="set_prefix")
|
||||
@commands.has_permissions(administrator=True)
|
||||
@@ -89,7 +89,7 @@ class Admin(commands.Cog, name='Admin'):
|
||||
@commands.guild_only()
|
||||
@commands.slash_command(
|
||||
name="set_prefix",
|
||||
description="Setting up bot prefix",
|
||||
description="Setting up src prefix",
|
||||
options=[
|
||||
Option("prefix",
|
||||
"Specify prefix",
|
||||
@@ -106,7 +106,7 @@ class Admin(commands.Cog, name='Admin'):
|
||||
@commands.has_permissions(administrator=True)
|
||||
@commands.slash_command(
|
||||
name="set_trigger_role",
|
||||
description=Localized("Setting up role to trigger bot", key="KEY_ROLE"),
|
||||
description=Localized("Setting up role to trigger src", key="KEY_ROLE"),
|
||||
options=[
|
||||
Option("role",
|
||||
Localized("Specify role", key="SETUP_ROLE"),
|
||||
@@ -120,7 +120,7 @@ class Admin(commands.Cog, name='Admin'):
|
||||
|
||||
@commands.slash_command(
|
||||
name="set_bot_role",
|
||||
description=Localized("Set bot role", key="BOT_ROLE"),
|
||||
description=Localized("Set src role", key="BOT_ROLE"),
|
||||
options=[
|
||||
Option("role",
|
||||
Localized("Specify role", key="SETUP_ROLE"),
|
||||
@@ -134,7 +134,7 @@ class Admin(commands.Cog, name='Admin'):
|
||||
await write_json(ctx.guild.id,
|
||||
"bot_role",
|
||||
role.id)
|
||||
await ctx.send(f"Set up bot role to: `{role.name}`", ephemeral=True)
|
||||
await ctx.send(f"Set up src role to: `{role.name}`", ephemeral=True)
|
||||
|
||||
@set_bot_role.error
|
||||
@set_trigger_role.error
|
||||
@@ -1,12 +1,12 @@
|
||||
import random
|
||||
|
||||
import disnake
|
||||
from disnake import OptionChoice, Option, OptionType, Member, VoiceState
|
||||
from disnake import OptionChoice, Option, OptionType, Member, VoiceState, ApplicationCommandInteraction
|
||||
from disnake.ext import commands
|
||||
|
||||
from lib.Logger import logger
|
||||
from lib.Player import play_audio
|
||||
from lib.ListGenerator import ListGenerator
|
||||
from integral_lib.ListGenerator import ListGenerator
|
||||
from integral_lib.Logger import logger
|
||||
from integral_lib.Player import play_audio
|
||||
|
||||
|
||||
class Audio(commands.Cog, name='Audio'):
|
||||
@@ -27,7 +27,7 @@ class Audio(commands.Cog, name='Audio'):
|
||||
logger.info('Skip playing by Game')
|
||||
else:
|
||||
# Prepare list of audio
|
||||
from lib.Comands import read_json
|
||||
from integral_lib.Comands import read_json
|
||||
_role = await read_json(member.guild.id, 'tigger_role')
|
||||
audio: list = []
|
||||
for _a in ListGenerator('audio'):
|
||||
@@ -59,7 +59,17 @@ class Audio(commands.Cog, name='Audio'):
|
||||
await inter.response.send_message('You`re not in voice', ephemeral=True)
|
||||
|
||||
@playaudio.autocomplete('audio')
|
||||
async def list_to_play(self, inter: disnake.ApplicationCommandInteraction, current: str):
|
||||
async def list_to_play(self, inter: ApplicationCommandInteraction, current: str):
|
||||
"""
|
||||
Asynchronously generates a list of OptionChoices for the given audio files based on the user input.
|
||||
Parameters:
|
||||
- inter: disnake.ApplicationCommandInteraction - The interaction context for the command.
|
||||
- current: str - The current user input to filter the audio file choices.
|
||||
Returns:
|
||||
- list[OptionChoice] - A list of OptionChoice objects representing the available audio file choices.
|
||||
:param current:
|
||||
:param inter: ApplicationCommandInteraction
|
||||
"""
|
||||
current = current.lower()
|
||||
_dict: dict = {}
|
||||
for f in ListGenerator('audio'):
|
||||
@@ -4,13 +4,13 @@ import disnake
|
||||
from disnake import OptionChoice
|
||||
from disnake.ext import commands
|
||||
|
||||
from lib.Comands import write_json
|
||||
from lib.Logger import logger
|
||||
from integral_lib.Comands import write_json
|
||||
from integral_lib.Logger import logger
|
||||
|
||||
|
||||
class Fun(commands.Cog, name='Fun'):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot # defining bot as global var in class
|
||||
self.bot = bot # defining src as global var in class
|
||||
|
||||
@commands.Cog.listener() # this is a decorator for events/listeners
|
||||
async def on_ready(self):
|
||||
@@ -19,7 +19,7 @@ class Fun(commands.Cog, name='Fun'):
|
||||
@commands.has_permissions(administrator=True)
|
||||
@commands.slash_command(
|
||||
name="set_bot_channel",
|
||||
description="Set channel which iterate with bot",
|
||||
description="Set channel which iterate with src",
|
||||
|
||||
)
|
||||
async def set_bot_channel(self, inter: disnake.ApplicationCommandInteraction, channel: str):
|
||||
@@ -2,13 +2,13 @@ import disnake
|
||||
from disnake import Option
|
||||
from disnake.ext import commands
|
||||
|
||||
from lib import YandexPlayer
|
||||
from lib.Logger import logger
|
||||
from integral_lib import YandexPlayer
|
||||
from integral_lib.Logger import logger
|
||||
|
||||
|
||||
class Testing(commands.Cog, name='Testing'):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot # defining bot as global var in class
|
||||
self.bot = bot # defining src as global var in class
|
||||
|
||||
@commands.Cog.listener() # this is a decorator for events/listeners
|
||||
async def on_ready(self):
|
||||
@@ -2,12 +2,12 @@ import disnake
|
||||
from disnake import Option, OptionType, Colour
|
||||
from disnake.ext import commands
|
||||
|
||||
from lib.Logger import logger
|
||||
from integral_lib.Logger import logger
|
||||
|
||||
|
||||
class General(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot # defining bot as global var in class
|
||||
self.bot = bot # defining src as global var in class
|
||||
|
||||
@commands.Cog.listener() # this is a decorator for events/listeners
|
||||
async def on_ready(self):
|
||||
@@ -1,29 +1,31 @@
|
||||
import os
|
||||
|
||||
import disnake
|
||||
import psutil
|
||||
|
||||
from disnake import ApplicationCommandInteraction
|
||||
from disnake.ext import commands
|
||||
|
||||
from __init__ import version_info as ver
|
||||
from lib.Comands import determine_prefix
|
||||
from lib.Logger import logger
|
||||
from integral_lib.Comands import determine_prefix
|
||||
from integral_lib.Logger import logger
|
||||
|
||||
|
||||
class BotInfo(commands.Cog, name='Bot Info'):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot # defining bot as global var in class
|
||||
self.bot = bot # defining src as global var in class
|
||||
|
||||
@commands.Cog.listener() # this is a decorator for events/listeners
|
||||
async def on_ready(self):
|
||||
logger.info(f'Cog {__name__.split(".")[1]} is ready!.')
|
||||
|
||||
@commands.slash_command(name="info_bot",
|
||||
description='Shows general info about bot') # this is for making a command
|
||||
async def info_bot(self, inter: disnake.ApplicationCommandInteraction):
|
||||
description='Shows general info about src') # this is for making a command
|
||||
async def info_bot(self, inter: ApplicationCommandInteraction):
|
||||
_pid = os.getpid()
|
||||
_process = psutil.Process(_pid)
|
||||
emb = disnake.Embed(
|
||||
title="General information",
|
||||
description="General information on about bot",
|
||||
description="General information on about src",
|
||||
)
|
||||
emb.set_thumbnail(self.bot.user.avatar.url)
|
||||
emb.add_field(name="System info:", value=f"Memory Usage: {round(_process.memory_info().rss / 2 ** 20, 2)} Mb\n"
|
||||
78
src/integral_lib/CogsPrep.py
Normal file
78
src/integral_lib/CogsPrep.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""
|
||||
integral_lib.CogsPrepare
|
||||
~~~~~~~~~~~~~
|
||||
Loads, unloads Cogs files
|
||||
cog_list: return list of cog filenames
|
||||
work_with_cogs: loads, reloads and unloads cogs files
|
||||
|
||||
"""
|
||||
from os import listdir, rename
|
||||
from typing import List
|
||||
|
||||
from disnake.ext.commands.interaction_bot_base import InteractionBotBase
|
||||
|
||||
from .Logger import logger
|
||||
|
||||
|
||||
def cog_list(fold: str = './cogs') -> List[str]:
|
||||
"""
|
||||
A function that generates a list of cog names based on the files present in a specified folder.
|
||||
|
||||
Parameters:
|
||||
- fold (str): The directory path where the cog files are located. Defaults to './cogs'.
|
||||
|
||||
Returns:
|
||||
- List[str]: A list of cog names without the '.py' extension.
|
||||
"""
|
||||
cogs_list = []
|
||||
for _filename in listdir(fold):
|
||||
if _filename.endswith('.py'):
|
||||
cogs_list.append(_filename[:-3])
|
||||
return cogs_list
|
||||
|
||||
|
||||
def work_with_cogs(what_do: str,
|
||||
bot: InteractionBotBase,
|
||||
cog: str | list):
|
||||
"""
|
||||
Perform the specified action on the given cog or list of cogs.
|
||||
Args:
|
||||
what_do (str): The action to perform (load, unload, reload, disable, enable).
|
||||
src (InteractionBotBase): The src instance to work with.
|
||||
cog (str | list): The name of the cog or a list of cogs to work with.
|
||||
Raises:
|
||||
ValueError: If the action is not recognized.
|
||||
Returns:
|
||||
None
|
||||
--------
|
||||
:param cog: str | list
|
||||
:param bot: InteractionBotBase
|
||||
:param what_do: str = ['load', 'unload', 'reload', 'disable', 'enable']
|
||||
"""
|
||||
|
||||
if isinstance(cog, str):
|
||||
cog = cog.split()
|
||||
for _filename in cog:
|
||||
if _filename.endswith('.py'):
|
||||
_filename = _filename.split('.')[0]
|
||||
if what_do == "load":
|
||||
bot.load_extension(f'cogs.{_filename}')
|
||||
logger.info(f'Cog {_filename} loaded')
|
||||
elif what_do == 'unload':
|
||||
bot.unload_extension(f'cogs.{_filename}')
|
||||
logger.info(f'Cog {_filename} unloaded')
|
||||
elif what_do == 'reload':
|
||||
bot.reload_extension(f'cogs.{_filename}')
|
||||
logger.info(f'Cog {_filename} reloaded')
|
||||
elif what_do == 'disable':
|
||||
bot.unload_extension(f'cogs.{_filename}')
|
||||
rename(f'cogs/{_filename}.py',
|
||||
f'cogs/disabled/{_filename}.py')
|
||||
logger.info(f'Cog {_filename} stopped and disabled')
|
||||
elif what_do == 'enable':
|
||||
rename(f'cogs/disabled/{_filename}.py',
|
||||
f'cogs/{_filename}.py')
|
||||
bot.load_extension(f'cogs.{_filename}')
|
||||
logger.info(f'Cog {_filename} started and enabled')
|
||||
else:
|
||||
raise ValueError(f"Unrecognized action: {what_do}")
|
||||
@@ -1,7 +1,9 @@
|
||||
"""
|
||||
lib.Commands
|
||||
integral_lib.Commands
|
||||
~~~~~~~~~~~~~~
|
||||
Some prepare for commands
|
||||
|
||||
|
||||
"""
|
||||
from json import load, decoder, dump, JSONDecodeError
|
||||
from os import getenv
|
||||
@@ -35,6 +37,18 @@ async def read_json(guild: int, _param: str):
|
||||
|
||||
|
||||
async def write_json(guild: int, param_name: str, param: str or int):
|
||||
"""
|
||||
A function to write JSON data to a file after updating or adding a parameter value.
|
||||
|
||||
Parameters:
|
||||
|
||||
- guild: an integer representing the guild ID
|
||||
- param_name: a string representing the parameter name
|
||||
- param: a string or integer representing the parameter value
|
||||
|
||||
Returns:
|
||||
This function does not return anything.
|
||||
"""
|
||||
with open(getenv('CONF_FILE'), encoding='utf-8') as f:
|
||||
try:
|
||||
_json = load(f)
|
||||
@@ -52,7 +66,8 @@ async def write_json(guild: int, param_name: str, param: str or int):
|
||||
|
||||
def determine_prefix(bot: commands.Bot, msg):
|
||||
"""
|
||||
Determite per-server bot prefix
|
||||
Determine the per-server src prefix based on the given message object.
|
||||
|
||||
:param bot: Disnake Bot object
|
||||
:param msg: Disnake msg object
|
||||
:return: prefix for server, default is $
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlite3 import connect, Error
|
||||
|
||||
from lib.Logger import logger
|
||||
from .Logger import logger
|
||||
|
||||
|
||||
class DBReader:
|
||||
@@ -18,8 +18,7 @@ class DBReader:
|
||||
try:
|
||||
sql_con = connect("user.db")
|
||||
cursor = sql_con.cursor()
|
||||
cursor.execute("""SELECT * FROM "(guildid)" """,
|
||||
{'guildid': guildid})
|
||||
cursor.execute(f"""SELECT * FROM "{guildid}" """)
|
||||
record = cursor.fetchall()
|
||||
return record
|
||||
except Error as _e:
|
||||
@@ -86,9 +85,9 @@ async def prepare_db(guild: int):
|
||||
try:
|
||||
_connect = connect('user.db')
|
||||
cursor = _connect.cursor()
|
||||
cursor.execute(f'''CREATE TABLE IF NOT EXISTS "{guild}"
|
||||
([userid] INTEGER PRIMARY KEY, [username] TEXT,
|
||||
[nick] TEXT, [isbot] BOOL, [defaulttracks] TEXT, [usertracks] TEXT)''')
|
||||
cursor.execute(f'CREATE TABLE IF NOT EXISTS "{guild}"\n'
|
||||
f' ([userid] INTEGER PRIMARY KEY, [username] TEXT,\n'
|
||||
f' [nick] TEXT, [isbot] BOOL, [defaulttracks] TEXT, [usertracks] TEXT)')
|
||||
cursor.close()
|
||||
except Error as _error:
|
||||
logger.info(_error)
|
||||
@@ -111,7 +110,7 @@ async def work_with_db(db_func: str, data_turple: tuple):
|
||||
|
||||
|
||||
async def fill_bd(name: str, userid: int, isbot: bool, nick: str, guild: int):
|
||||
sqlite_insert_with_param = (f"""INSERT OR IGNORE INTO "{guild}"
|
||||
sqlite_insert_with_param = (f"""INSERT OR IGNORE INTO '{guild}'
|
||||
(username, userid, nick, isbot)
|
||||
VALUES (?, ?, ?, ?)""")
|
||||
data_tuple: tuple[str, int, str, bool] = (name, userid, nick, isbot)
|
||||
@@ -1,6 +1,6 @@
|
||||
from asyncio import sleep
|
||||
|
||||
from disnake import FFmpegOpusAudio
|
||||
from disnake import FFmpegPCMAudio
|
||||
|
||||
from .Logger import logger
|
||||
|
||||
@@ -10,7 +10,7 @@ async def play_audio(audio, bot, vc):
|
||||
logger.error(f'Playing: {audio}')
|
||||
vp = await vc.connect()
|
||||
if not vp.is_playing():
|
||||
vp.play(FFmpegOpusAudio(f'{audio}', ))
|
||||
vp.play(FFmpegPCMAudio(f'{audio}', ))
|
||||
while vp.is_playing():
|
||||
await sleep(0.5)
|
||||
await sleep(1)
|
||||
5
src/integral_lib/__init__.py
Normal file
5
src/integral_lib/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
"""
|
||||
integral_lib
|
||||
~~~~~~~~~~~~~
|
||||
Some libs for the src which help him
|
||||
"""
|
||||
BIN
tests/requirements.txt
Normal file
BIN
tests/requirements.txt
Normal file
Binary file not shown.
41
tests/test_bot.py
Normal file
41
tests/test_bot.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from disnake import Intents
|
||||
from disnake.ext import commands
|
||||
|
||||
intents = Intents(messages=True,
|
||||
message_content=True,
|
||||
)
|
||||
|
||||
|
||||
class Cog(commands.Cog):
|
||||
@commands.command()
|
||||
async def my_cmd(self, ctx):
|
||||
pass
|
||||
|
||||
|
||||
class CogTwo(commands.Cog):
|
||||
async def bot_check(self, ctx) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
class CogThree(commands.Cog):
|
||||
async def bot_check_once(self, ctx) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
class CogFour(commands.Cog):
|
||||
async def bot_slash_command_check(self, ctx) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
class CogFive(commands.Cog):
|
||||
async def can_run(self, ctx) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
def test_bot():
|
||||
bot = commands.Bot(command_prefix='$', intents=intents)
|
||||
bot.add_cog(Cog())
|
||||
bot.add_cog(CogTwo())
|
||||
bot.add_cog(CogThree())
|
||||
bot.add_cog(CogFour())
|
||||
bot.add_cog(CogFive())
|
||||
31
tests/test_lib_Cog.py
Normal file
31
tests/test_lib_Cog.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from disnake.ext.commands.common_bot_base import CommonBotBase
|
||||
from mock import mock
|
||||
|
||||
sys.path.append('src')
|
||||
from integral_lib import CogsPrep
|
||||
|
||||
|
||||
def test_cog_list():
|
||||
with mock.patch('integral_lib.CogsPrep.listdir') as MockClass:
|
||||
MockClass.return_value = ['cog1.py', 'cog2.py']
|
||||
result = CogsPrep.cog_list()
|
||||
assert result == ['cog1', 'cog2']
|
||||
|
||||
|
||||
@pytest.mark.parametrize("cog", ["cog1.py", "cog2"])
|
||||
@pytest.mark.parametrize("what_do", ['load', 'unload', 'reload', 'disable', 'enable'])
|
||||
def test_work_with_cogs(what_do, cog):
|
||||
with mock.patch('integral_lib.CogsPrep.rename') as mock_rename:
|
||||
mock_rename.return_value = None
|
||||
mock_bot = mock.MagicMock(spec=CommonBotBase)
|
||||
result = CogsPrep.work_with_cogs(what_do, mock_bot, cog)
|
||||
if what_do in ['load', 'enable']:
|
||||
assert mock_bot.load_extension.called
|
||||
elif what_do in ['unload', 'disable']:
|
||||
assert mock_bot.unload_extension.called
|
||||
elif what_do == 'reload':
|
||||
assert mock_bot.reload_extension.called
|
||||
|
||||
Reference in New Issue
Block a user