bafser tg api
Project description
bafser tgapi
usage
init project: bafser init_project
set webhook: bafser configure_webhook set
delete webhook: bafser configure_webhook delete
main.py
import sys
from bafser import AppConfig, create_app
import bafser_tgapi as tgapi
from bot.bot import Bot
from scripts.init_db import init_db
app, run = create_app(__name__, AppConfig(DEV_MODE="dev" in sys.argv))
tgapi.setup(
config_path="config_dev.txt" if __name__ == "__main__" else "config.txt",
botCls=Bot,
import_folder="bot",
app=app,
)
run(False, init_db)
if __name__ == "__main__":
tgapi.run_long_polling()
else:
tgapi.set_webhook()
init_db.py
from bafser import AppConfig
from sqlalchemy.orm import Session
from data.user import Roles, User
def init_db(db_sess: Session, config: AppConfig):
u = User.new(db_sess, 12345, False, "Admin", "", "username", "en")
u.add_role(u, Roles.admin)
db_sess.commit()
data.user.py
from bafser_tgapi import TgUserBase
from data._roles import Roles
class User(TgUserBase):
_default_role = Roles.user
data.msg.py
from bafser_tgapi import MsgBase
from data._tables import Tables
class Msg(MsgBase):
__tablename__ = Tables.Msg
bot.py
from typing import override
from bafser import Log
import bafser_tgapi as tgapi
from sqlalchemy.orm import Session
from data.user import User
class Bot(tgapi.BotWithDB[User]):
@override
def get_user(self, db_sess: Session, sender: tgapi.User) -> User:
user = User.get_by_id_tg(db_sess, sender.id)
if user is None:
user = User.new_from_data(db_sess, sender)
if user.username != sender.username:
old_username = user.username
user.username = sender.username
Log.updated(user, user, [("username", old_username, user.username)])
return user
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bafser_tgapi-1.0.0.tar.gz.
File metadata
- Download URL: bafser_tgapi-1.0.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef05861e16d0a9d3d73dbc264f43e6300f1b2a63707be0ae04b990a4b06be532
|
|
| MD5 |
3e74872c8f3845ce9fd8cc29d63171ba
|
|
| BLAKE2b-256 |
d36fdc818330f3a02060b63dcf9429892b80a10342799eb9fa006600d45ad6cc
|
Provenance
The following attestation bundles were made for bafser_tgapi-1.0.0.tar.gz:
Publisher:
main.yml on MixelTe/bafser_tgapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bafser_tgapi-1.0.0.tar.gz -
Subject digest:
ef05861e16d0a9d3d73dbc264f43e6300f1b2a63707be0ae04b990a4b06be532 - Sigstore transparency entry: 563893787
- Sigstore integration time:
-
Permalink:
MixelTe/bafser_tgapi@aaa9e76a519af5b9116b12fc9ffcd31e1bdf8ad2 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/MixelTe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@aaa9e76a519af5b9116b12fc9ffcd31e1bdf8ad2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bafser_tgapi-1.0.0-py3-none-any.whl.
File metadata
- Download URL: bafser_tgapi-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15c8ce3a7d24becfbc99cd6bcb8370a5e10ca78c24e577a38931c22f5bac6688
|
|
| MD5 |
7ebe6ed14e590c7923f95fcb11b712f6
|
|
| BLAKE2b-256 |
c9502319ab583e0981bc44b7da317df2535b8ce20bba12e42d9dd6e82a21f8ab
|
Provenance
The following attestation bundles were made for bafser_tgapi-1.0.0-py3-none-any.whl:
Publisher:
main.yml on MixelTe/bafser_tgapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bafser_tgapi-1.0.0-py3-none-any.whl -
Subject digest:
15c8ce3a7d24becfbc99cd6bcb8370a5e10ca78c24e577a38931c22f5bac6688 - Sigstore transparency entry: 563893807
- Sigstore integration time:
-
Permalink:
MixelTe/bafser_tgapi@aaa9e76a519af5b9116b12fc9ffcd31e1bdf8ad2 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/MixelTe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@aaa9e76a519af5b9116b12fc9ffcd31e1bdf8ad2 -
Trigger Event:
push
-
Statement type: