diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml new file mode 100644 index 0000000..3470336 --- /dev/null +++ b/.github/workflows/black.yml @@ -0,0 +1,34 @@ +name: black + +on: + push: + +jobs: + formatter: + name: formatter + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.8.14] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install Poetry + run: | + curl -sSL https://install.python-poetry.org/ | python + - name: Add path for Poetry + run: echo "$HOME/.poetry/bin" >> $GITHUB_PATH + - name: Install Dependencies + run: poetry install --no-interaction + - name: black + run: poetry run black . + - name: autoflake + run: poetry run autoflake -r . + - uses: stefanzweifel/git-auto-commit-action@v3.0.0 + with: + commit_message: Apply Code Formatter Change + ref: ${{ github.head_ref }} \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 789452f..21cc655 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,7 +26,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 pipenv + pip install flake8 - name: Lint with flake8 run: | flake8 . --count --ignore=E501,E722,C901 --select=E9,F63,F7,F82 --show-source --statistics diff --git a/cogs/bot_info.py b/cogs/bot_info.py new file mode 100644 index 0000000..faa6b78 --- /dev/null +++ b/cogs/bot_info.py @@ -0,0 +1,26 @@ +import discord +from discord.ext import commands +from discord import app_commands +from replit import db + +def bot_command_count_get(data): + return db[f"bot_command_{data}_count_db"] + +def bot_command_all_count_db_get(): + return db[f"bot_command_all_count_db"] + + +class bot_info(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @app_commands.command( + name="bot_info", + description="Botの情報を表示します。" + ) + async def botinfo( + self, i: discord.Interaction + ): + await i.response.send_message(embed=discord.Embed(title='Botの情報').add_field(name='全コマンドの合計実行数', value=str(bot_command_all_count_db_get())), ephemeral=True) +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(bot_info(bot)) diff --git a/cogs/bot_process.py b/cogs/bot_process.py new file mode 100644 index 0000000..e2fb2bd --- /dev/null +++ b/cogs/bot_process.py @@ -0,0 +1,33 @@ +import discord +from discord.ext import commands +from discord import app_commands +from replit import db + +def bot_command_count_get(data): + return db[f"bot_command_{data}_count_db"] + +def bot_command_count(data): + db[f"bot_command_{data}_count_db"] = int(bot_command_count_get()) + 1 + +def bot_command_all_count_db_get(): + return db[f"bot_command_all_count_db"] + +def bot_command_count_p1(): + db[f"bot_command_all_count_db"] = int(bot_command_all_count_db_get()) + 1 + + +class bot_process(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @commands.Cog.listener(name='on_interaction') + async def interaction(self, i: discord.Interaction): + if i.type == discord.InteractionType.application_command: + bot_command_count_p1() + if self.bot.tree.get_command(i.command.name): + bot_command_count(i.command.name) + else: + return + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(bot_process(bot)) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c35ce06 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "EightBot" +version = "2.0.0" +description = "" +authors = ["EightBotDev "] + +[tool.poetry.dependencies] +python = ">=3.8.0,<3.9" +numpy = "^1.22.2" +Flask = "^2.2.0" +urllib3 = "^1.26.12" +discord = "^2.0.0" +requests = "^2.28.1" +black = "^22.10.0" +autoflake = "^1.7.7"