Skip to content

Commit adbb81d

Browse files
committed
Bugfix imports
1 parent b251a54 commit adbb81d

File tree

3 files changed

+36
-72
lines changed

3 files changed

+36
-72
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,11 @@ yarn-error.log*
217217
*.tsbuildinfo
218218
next-env.d.ts
219219
/.cursorindexingignore
220+
221+
# AI instruction files (generated)
222+
CLAUDE.md
223+
GEMINI.md
224+
.cursorrules
225+
.claude
226+
AGENTS.md
227+
WARP.md

.pre-commit-config.yaml

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,12 @@
11
repos:
2-
# - repo: local
3-
# hooks:
4-
# - id: jupyter-nb-clear-output
5-
# name: jupyter-nb-clear-output
6-
# language: system
7-
# entry: jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace
82
- repo: https://github.com/kynan/nbstripout
93
rev: 0.5.0
104
hooks:
115
- id: nbstripout
126
files: \.ipynb$
137
stages: [ pre-commit ]
148

15-
- repo: https://github.com/jendrikseipp/vulture
16-
rev: 'v2.10'
17-
hooks:
18-
- id: vulture
19-
args: [
20-
"--min-confidence", "80",
21-
"src" # project_name - path to scan
22-
]
23-
files: ^.*\.py$
24-
exclude: ^(.git|.venv|venv|build|dist)/.*$
25-
26-
- repo: local
27-
hooks:
28-
- id: pytest-check
29-
name: pytest-check
30-
entry: pytest
31-
language: system
32-
pass_filenames: false
33-
always_run: true
34-
args: [
35-
"--cov=src", # project_name - path to scan
36-
"--cov-report=xml",
37-
"--cov-fail-under=50",
38-
]
39-
409
- repo: https://github.com/asottile/pyupgrade
4110
rev: v3.19.0
4211
hooks:
4312
- id: pyupgrade
44-
45-
- repo: https://github.com/RobertCraigie/pyright-python
46-
rev: v1.1.399
47-
hooks:
48-
- id: pyright
49-
additional_dependencies: ["pyright==1.1.399"]
50-
51-
- repo: https://github.com/astral-sh/ruff-pre-commit
52-
# Ruff version.
53-
rev: v0.7.4
54-
hooks:
55-
# Run the linter.
56-
- id: ruff
57-
types_or: [ python, pyi ]
58-
args: [ --fix ]
59-
# Run the formatter.
60-
- id: ruff-format
61-
types_or: [ python, pyi ]

src/router.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
from pydantic import BaseModel
1+
from textwrap import dedent
2+
23
from aiogram import F, Router
3-
from aiogram.filters import CommandStart, Command
4+
from aiogram.filters import Command, CommandStart
45
from aiogram.fsm.context import FSMContext
56
from aiogram.types import Message
67
from botspot import answer_safe, commands_menu, get_message_text, reply_safe
78
from botspot.components.new.llm_provider import aquery_llm_structured
8-
from botspot.user_interactions import ask_user_choice, ask_user
9-
from botspot.utils import send_safe, markdown_to_html
9+
from botspot.components.qol.bot_commands_menu import Visibility
10+
from botspot.user_interactions import ask_user, ask_user_choice
11+
from botspot.utils import markdown_to_html, send_safe
1012
from botspot.utils.admin_filter import AdminFilter
11-
from botspot.types import Visibility
1213
from loguru import logger
13-
from textwrap import dedent
14+
from pydantic import BaseModel
1415

1516
from src.app import App
1617

@@ -65,62 +66,66 @@ async def help_handler(message: Message, app: App):
6566
await send_safe(message.chat.id, help_message)
6667

6768

68-
@commands_menu.botspot_command("stats", "Show usage statistics (admin only)", visibility=Visibility.ADMIN_ONLY)
69+
@commands_menu.botspot_command(
70+
"stats", "Show usage statistics (admin only)", visibility=Visibility.ADMIN_ONLY
71+
)
6972
@router.message(AdminFilter())
7073
@router.message(Command("stats"))
7174
async def stats_handler(message: Message, app: App):
7275
"""Stats command handler - shows usage statistics for all users"""
7376
assert message.from_user is not None
74-
77+
7578
# Get user statistics
7679
try:
7780
stats = await app.get_user_statistics()
78-
81+
7982
# Format the statistics nicely
8083
response = "<b>📊 Bot Usage Statistics</b>\n\n"
81-
84+
8285
# Summary section
8386
summary = stats["summary"]
84-
response += f"<b>📈 Summary:</b>\n"
87+
response += "<b>📈 Summary:</b>\n"
8588
response += f"• Total Users: {summary['total_users']}\n"
8689
response += f"• Total Requests: {summary['total_requests']}\n"
8790
response += f"• Total Audio Minutes: {summary['total_minutes']:.1f}\n"
8891
response += f"• Total Cost: ${summary['total_cost']:.4f}\n\n"
89-
92+
9093
# Per-user statistics
9194
response += "<b>👥 Per-User Statistics:</b>\n"
92-
95+
9396
user_stats = stats["user_stats"]
9497
# Sort users by total cost (descending)
95-
sorted_users = sorted(user_stats.items(), key=lambda x: x[1]["total_cost"], reverse=True)
96-
98+
sorted_users = sorted(
99+
user_stats.items(), key=lambda x: x[1]["total_cost"], reverse=True
100+
)
101+
97102
for username, user_data in sorted_users[:20]: # Show top 20 users
98103
response += f"\n<b>@{username}</b>\n"
99104
response += f" • Requests: {user_data['total_requests']}\n"
100105
response += f" • Audio Minutes: {user_data['total_minutes']:.1f}\n"
101106
response += f" • Total Cost: ${user_data['total_cost']:.4f}\n"
102-
107+
103108
# Show breakdown of operations if available
104109
if user_data["operations"]:
105-
response += f" • Operations: "
110+
response += " • Operations: "
106111
op_details = []
107112
for op, op_data in user_data["operations"].items():
108113
op_details.append(f"{op}({op_data['count']})")
109114
response += ", ".join(op_details) + "\n"
110-
115+
111116
# Show activity timeframe
112117
if user_data["first_activity"] and user_data["last_activity"]:
113118
first = user_data["first_activity"]
114119
last = user_data["last_activity"]
115120
response += f" • Active: {first.strftime('%Y-%m-%d')} to {last.strftime('%Y-%m-%d')}\n"
116-
121+
117122
if len(user_stats) > 20:
118123
response += f"\n<i>... and {len(user_stats) - 20} more users</i>"
119-
124+
120125
except Exception as e:
121126
logger.error(f"Error getting statistics: {e}")
122127
response = f"❌ Error retrieving statistics: {str(e)}"
123-
128+
124129
await send_safe(message.chat.id, response)
125130

126131

@@ -274,15 +279,15 @@ async def ask_user_speedup(message: Message, app: App, state: FSMContext):
274279
"none": "No speedup (original speed)",
275280
"2": "2x speed (default)",
276281
"3": "3x speed",
277-
"4": "4x speed",
282+
"4": "4x speed",
278283
"5": "5x speed",
279284
},
280285
state=state,
281286
default_choice="2",
282287
timeout=10,
283288
cleanup=app.config.cleanup_messages,
284289
)
285-
290+
286291
if speedup == "none":
287292
return None
288293
else:

0 commit comments

Comments
 (0)