Skip to content

Commit

Permalink
pep 8 updates and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andcool-Systems committed Mar 6, 2024
1 parent 3502585 commit 118bf05
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/out
/Telegram_provider/dataBase.db
/Telegram_provider/.env
/FileUploaderBot/.env
/FileUploaderBot/.env
/.ruff_cache
22 changes: 11 additions & 11 deletions Telegram_provider/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ async def send_login_message(message: types.Message):
builder = InlineKeyboardBuilder()
builder.add(types.InlineKeyboardButton(
text="Log in",
callback_data=f"log_login")
callback_data="log_login")
)
builder.add(types.InlineKeyboardButton(
text="Register",
callback_data=f"log_register")
callback_data="log_register")
)

await message.answer(f"_To access your files from any device, sign in. " + \
"The files will be linked to your account and you will have full access to them._",
await message.answer("_To access your files from any device, sign in. " + \
"The files will be linked to your account and you will have full access to them._",
reply_markup=builder.as_markup(),
parse_mode="Markdown")

Expand All @@ -56,7 +56,7 @@ async def start(message: types.Message, state: FSMContext):
await message.answer("*Attention! This bot is in open beta testing, so there may be significant bugs and errors in operation.\n*" + \
f"Current version: {version}", parse_mode="Markdown")
await message.answer(f"Hello, {message.from_user.full_name}!\n" + \
f"I am the Telegram provider of the fu.andcool.ru service. To get started, send me the file that needs to be uploaded.")
"I am the Telegram provider of the fu.andcool.ru service. To get started, send me the file that needs to be uploaded.")


@dp.message(Command('account'))
Expand All @@ -72,7 +72,7 @@ async def account(message: types.Message, state: FSMContext):
builder = InlineKeyboardBuilder()
builder.add(types.InlineKeyboardButton(
text="Log out",
callback_data=f"logout")
callback_data="logout")
)

await message.answer(f"Logged in as **{user_obj.username}**\n",
Expand All @@ -87,7 +87,7 @@ async def account(message: types.Message, state: FSMContext):
@dp.callback_query(F.data.startswith("log_"))
async def log(callback: types.CallbackQuery, state: FSMContext):
await callback.message.delete()
message = await callback.message.answer(f"OK, now send me the data from your account in the format:\n```\nMy cool username\nMy cool password```",
message = await callback.message.answer("OK, now send me the data from your account in the format:\n```\nMy cool username\nMy cool password```",
parse_mode="Markdown")
await state.set_state(States.wait_to_data)
await state.update_data(login_register=callback.data.replace("log_", ""))
Expand Down Expand Up @@ -126,7 +126,7 @@ async def log_reg(message: types.Message, state: FSMContext):


@dp.callback_query(F.data == "logout")
async def log(callback: types.CallbackQuery, state: FSMContext):
async def logout(callback: types.CallbackQuery, state: FSMContext):
user_db = await db.user.find_first(where={"user_id": callback.from_user.id})
if not user_db:
await callback.message.answer("You are not logged in")
Expand Down Expand Up @@ -204,7 +204,7 @@ async def send_file(message: types.Message, state: FSMContext):
file = await bot.get_file(file_id)

bio = io.BytesIO()
filename = f"voice.mp3"
filename = "voice.mp3"
file_bytes = await bot.download(file_id, destination=bio)
bio.seek(0)

Expand Down Expand Up @@ -246,7 +246,7 @@ async def delete_file(callback: types.CallbackQuery, state: FSMContext):
except Exception as e:
await callback.message.edit_text("❌Delete error: " + str(e))

async def start():
async def start_bot():
"""Асинхронная функция для запуска диспатчера"""

await db.connect() # Connecting to database
Expand All @@ -264,4 +264,4 @@ async def start():


if __name__ == '__main__':
asyncio.run(start())
asyncio.run(start_bot())
1 change: 0 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

"aac": "audio/aac",
"mp3": "audio/mpeg",
"mpeg": "audio/mpeg",
"ogg": "audio/ogg",

"gif": "image/gif",
Expand Down
24 changes: 0 additions & 24 deletions imports.py

This file was deleted.

39 changes: 30 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,28 @@
created by AndcoolSystems, 2023-2024
"""

from imports import *
from fastapi import FastAPI, UploadFile, Request, Header
from fastapi.responses import JSONResponse, FileResponse, Response
from typing import Annotated, Union
import uvicorn
from config import filetypes, default, accessLifeTime, accessLifeTimeBot
import aiohttp
import utils
from slowapi.errors import RateLimitExceeded
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.util import get_remote_address
from fastapi.middleware.cors import CORSMiddleware
import time
import aiofiles
from prisma import Prisma
import uuid
import os
from datetime import datetime
from dotenv import load_dotenv
import jwt
import bcrypt
import random
import json


def custom_key_func(request: Request):
Expand All @@ -28,7 +49,7 @@ def dynamic_limit_provider_upload(key: str):
db = Prisma()
load_dotenv()
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, rate_limit_exceeded_handler)
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)

app.add_middleware( # Disable CORS
CORSMiddleware,
Expand Down Expand Up @@ -483,7 +504,7 @@ async def login_token(request: Request,

@app.post("/api/login/discord/{code}") # login handler
@limiter.limit(dynamic_limit_provider)
async def login(code: str,
async def login_discord(code: str,
request: Request,
user_agent: Union[str, None] = Header(default=None)):

Expand All @@ -500,7 +521,7 @@ async def login(code: str,

response_json = {}
async with aiohttp.ClientSession() as session:
async with session.post(f'https://discord.com/api/v10/oauth2/token', data=data, headers=headers, auth=auth) as response:
async with session.post('https://discord.com/api/v10/oauth2/token', data=data, headers=headers, auth=auth) as response:
response_json = await response.json()
if response.status != 200:
return JSONResponse({"status": "error", "message": "Internal error, please, log in again"}, status_code=401)
Expand Down Expand Up @@ -732,7 +753,7 @@ async def transfer(

try:
body = await request.json()
except:
except Exception:
return JSONResponse(
content={"status": "error", "message": "Couldn't parse request body"},
status_code=400,
Expand All @@ -755,7 +776,7 @@ async def transfer(
await db.file.update(
where={"id": file.id}, data={"user_id": token_db.user_id}
)
except:
except Exception:
non_success.append(requested_file)

return {"status": "success", "message": "transfered", "unsuccess": non_success}
Expand Down Expand Up @@ -903,7 +924,7 @@ async def generate_invite(

@app.post("/api/join/{invite_link}") # join handler
@limiter.limit(dynamic_limit_provider)
async def delete_group(
async def join_group(
invite_link: str,
request: Request,
Authorization: Annotated[Union[str, None], Header(convert_underscores=False)] = None,
Expand Down Expand Up @@ -959,7 +980,7 @@ async def delete_group(

@app.get("/api/invite_info/{invite_link}") # invite info handler
@limiter.limit(dynamic_limit_provider)
async def delete_group(
async def invite_link(
invite_link: str,
request: Request,
Authorization: Annotated[Union[str, None], Header(convert_underscores=False)] = None,
Expand Down Expand Up @@ -995,7 +1016,7 @@ async def delete_group(

@app.post("/api/leave/{group_id}") # leave handler
@limiter.limit(dynamic_limit_provider)
async def delete_group(
async def leave_group(
group_id: int,
request: Request,
Authorization: Annotated[Union[str, None], Header(convert_underscores=False)] = None,
Expand Down
4 changes: 2 additions & 2 deletions web/uploaders/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ <h1>File uploader</h1>
<hr>
<p style="margin-top: 0%;font-size: 80%;">by AndcoolSystems</p>
<h2 style="font-weight: 600;">Bots</h2>
<p id="sharex" style="cursor: pointer; margin-bottom: 3px;"><a href="https://discord.com/users/1201599088534225008" target="_blank">Discord</a></p>
<p id="sharex" style="cursor: pointer;"><a href="https://t.me/fu_andcool_bot" target="_blank">Telegram</a></p>
<p id="sharex" style="margin-bottom: 3px;"><a href="https://discord.com/users/1201599088534225008" target="_blank" style="cursor: pointer">Discord bot</a> by kwixie_</p>
<p id="sharex"><a href="https://t.me/fu_andcool_bot" target="_blank" style="cursor: pointer;">Telegram bot</a></p>

<h2 style="font-weight: 600;">ShareX</h2>
<p id="sharex"><a href="/uploaders/File uploader.sxcu" download="File uploader.sxcu">Click here</a> to download the ShareX config</p>
Expand Down

0 comments on commit 118bf05

Please sign in to comment.