{"id":13486651,"url":"https://github.com/PaulSonOfLars/tgbot","last_synced_at":"2025-03-27T21:30:43.715Z","repository":{"id":41829356,"uuid":"98918956","full_name":"PaulSonOfLars/tgbot","owner":"PaulSonOfLars","description":"Modular telegram group management bot","archived":true,"fork":false,"pushed_at":"2022-09-30T11:09:56.000Z","size":759,"stargazers_count":723,"open_issues_count":10,"forks_count":919,"subscribers_count":58,"default_branch":"master","last_synced_at":"2024-10-30T21:37:53.719Z","etag":null,"topics":["bot","database","postgres","python-bot","python3","sqlalchemy-database","telegram","tgbot"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PaulSonOfLars.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-31T18:44:57.000Z","updated_at":"2024-10-28T03:26:46.000Z","dependencies_parsed_at":"2023-01-18T11:16:52.421Z","dependency_job_id":null,"html_url":"https://github.com/PaulSonOfLars/tgbot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulSonOfLars%2Ftgbot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulSonOfLars%2Ftgbot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulSonOfLars%2Ftgbot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaulSonOfLars%2Ftgbot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PaulSonOfLars","download_url":"https://codeload.github.com/PaulSonOfLars/tgbot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245927119,"owners_count":20695171,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","database","postgres","python-bot","python3","sqlalchemy-database","telegram","tgbot"],"created_at":"2024-07-31T18:00:49.503Z","updated_at":"2025-03-27T21:30:43.704Z","avatar_url":"https://github.com/PaulSonOfLars.png","language":"Python","funding_links":[],"categories":["Python","Bots","一般机器人（bots）"],"sub_categories":["Bot Libs","机器人类库"],"readme":"## IMPORTANT NOTICE:\n\nThis project is no longer maintained, and should be considered deprecated. Use at your own risk.\n\nTelegram have made many breaking changes since this bot was last updated, and as such, there are no expectations that\nthis will work. Notably, user IDs have gone from 32 bit to 64, which will cause issues with the database that I do not\nbelieve are worth fixing.\n\nIf you choose to take inspiration from this codebase, I would like to ask that you \"pass it forward\", and make your\ncode open source. This will help people learn from you, as you are learning from this repo.\n\nIf you are simply looking for a group management bot to use in your chat, I would like to encourage giving\n[Rose](https://t.me/MissRose_bot) a try; it was built as [Marie](https://t.me/BanhammerMarie_bot)'s successor, and has\nmany of the same features (but is much faster!)\n\n# tgbot\n\nA modular telegram Python bot running on python3 with a postgres database.\n\nOriginally a simple group management bot with multiple admin features, it has evolved into becoming a basis for modular\nbots aiming to provide simple plugin expansion via a simple drag and drop.\n\nCan be found on telegram as [Marie](https://t.me/BanhammerMarie_bot).\n\nFor questions regarding creating your own bot, please head to [this chat](https://t.me/MarieOT) where you'll find a\ngroup of volunteers to help. We'll also help when a database schema changes, and some table column needs to be\nmodified/added (this info can also be found in the commit messages)\n\nJoin the [news channel](https://t.me/MarieNews) if you just want to stay in the loop about new features or\nannouncements.\n\nMarie and I can also be found moderating the [marie support group](https://t.me/MarieSupport) aimed at providing help\nsetting up Marie in your chats (*not* for bot clones).\nFeel free to join to report bugs, and stay in the loop on the status of the bot development.\n\nNote to maintainers that all schema changes will be found in the commit messages, and its their responsibility to read\nany new commits.\n\n## Starting the bot.\n\nOnce you've setup your database and your configuration (see below) is complete, simply run:\n\n`python3 -m tg_bot`\n\n## Setting up the bot (Read this before trying to use!):\n\nPlease make sure to use python3.6, as I cannot guarantee everything will work as expected on older python versions!\nThis is because markdown parsing is done by iterating through a dict, which are ordered by default in 3.6.\n\n### Configuration\n\nThere are two possible ways of configuring your bot: a config.py file, or ENV variables.\n\nThe prefered version is to use a `config.py` file, as it makes it easier to see all your settings grouped together.\nThis file should be placed in your `tg_bot` folder, alongside the `__main__.py` file .\nThis is where your bot token will be loaded from, as well as your database URI (if you're using a database), and most of\nyour other settings.\n\nIt is recommended to import sample_config and extend the Config class, as this will ensure your config contains all\ndefaults set in the sample_config, hence making it easier to upgrade.\n\nAn example `config.py` file could be:\n\n```\nfrom tg_bot.sample_config import Config\n\n\nclass Development(Config):\n    OWNER_ID = 254318997  # my telegram ID\n    OWNER_USERNAME = \"SonOfLars\"  # my telegram username\n    API_KEY = \"your bot api key\"  # my api key, as provided by the botfather\n    SQLALCHEMY_DATABASE_URI = 'postgresql://username:password@localhost:5432/database'  # sample db credentials\n    MESSAGE_DUMP = '-1234567890' # some group chat that your bot is a member of\n    USE_MESSAGE_DUMP = True\n    SUDO_USERS = [18673980, 83489514]  # List of id's for users which have sudo access to the bot.\n    LOAD = []\n    NO_LOAD = ['translation']\n```\n\nIf you can't have a config.py file (EG on heroku), it is also possible to use environment variables.\nThe following env variables are supported:\n\n- `ENV`: Setting this to ANYTHING will enable env variables\n\n- `TOKEN`: Your bot token, as a string.\n- `OWNER_ID`: An integer of consisting of your owner ID\n- `OWNER_USERNAME`: Your username\n\n- `DATABASE_URL`: Your database URL\n- `MESSAGE_DUMP`: optional: a chat where your replied saved messages are stored, to stop people deleting their old\n- `LOAD`: Space separated list of modules you would like to load\n- `NO_LOAD`: Space separated list of modules you would like NOT to load\n- `WEBHOOK`: Setting this to ANYTHING will enable webhooks when in env mode\n  messages\n- `URL`: The URL your webhook should connect to (only needed for webhook mode)\n\n- `SUDO_USERS`: A space separated list of user_ids which should be considered sudo users\n- `SUPPORT_USERS`: A space separated list of user_ids which should be considered support users (can gban/ungban,\n  nothing else)\n- `WHITELIST_USERS`: A space separated list of user_ids which should be considered whitelisted - they can't be banned.\n- `DONATION_LINK`: Optional: link where you would like to receive donations.\n- `CERT_PATH`: Path to your webhook certificate\n- `PORT`: Port to use for your webhooks\n- `DEL_CMDS`: Whether to delete commands from users which don't have rights to use that command\n- `STRICT_GBAN`: Enforce gbans across new groups as well as old groups. When a gbanned user talks, he will be banned.\n- `WORKERS`: Number of threads to use. 8 is the recommended (and default) amount, but your experience may vary.\n  __Note__ that going crazy with more threads wont necessarily speed up your bot, given the large amount of sql data\n  accesses, and the way python asynchronous calls work.\n- `BAN_STICKER`: Which sticker to use when banning people.\n- `ALLOW_EXCL`: Whether to allow using exclamation marks ! for commands as well as /.\n\n### Python dependencies\n\nInstall the necessary python dependencies by moving to the project directory and running:\n\n`pip3 install -r requirements.txt`.\n\nThis will install all necessary python packages.\n\n### Database\n\nIf you wish to use a database-dependent module (eg: locks, notes, userinfo, users, filters, welcomes),\nyou'll need to have a database installed on your system. I use postgres, so I recommend using it for optimal\ncompatibility.\n\nIn the case of postgres, this is how you would set up a the database on a debian/ubuntu system. Other distributions may\nvary.\n\n- install postgresql:\n\n`sudo apt-get update \u0026\u0026 sudo apt-get install postgresql`\n\n- change to the postgres user:\n\n`sudo su - postgres`\n\n- create a new database user (change YOUR_USER appropriately):\n\n`createuser -P -s -e YOUR_USER`\n\nThis will be followed by you needing to input your password.\n\n- create a new database table:\n\n`createdb -O YOUR_USER YOUR_DB_NAME`\n\nChange YOUR_USER and YOUR_DB_NAME appropriately.\n\n- finally:\n\n`psql YOUR_DB_NAME -h YOUR_HOST YOUR_USER`\n\nThis will allow you to connect to your database via your terminal.\nBy default, YOUR_HOST should be 0.0.0.0:5432.\n\nYou should now be able to build your database URI. This will be:\n\n`sqldbtype://username:pw@hostname:port/db_name`\n\nReplace sqldbtype with whichever db youre using (eg postgres, mysql, sqllite, etc)\nrepeat for your username, password, hostname (localhost?), port (5432?), and db name.\n\n## Modules\n\n### Setting load order.\n\nThe module load order can be changed via the `LOAD` and `NO_LOAD` configuration settings.\nThese should both represent lists.\n\nIf `LOAD` is an empty list, all modules in `modules/` will be selected for loading by default.\n\nIf `NO_LOAD` is not present, or is an empty list, all modules selected for loading will be loaded.\n\nIf a module is in both `LOAD` and `NO_LOAD`, the module will not be loaded - `NO_LOAD` takes priority.\n\n### Creating your own modules.\n\nCreating a module has been simplified as much as possible - but do not hesitate to suggest further simplification.\n\nAll that is needed is that your .py file be in the modules folder.\n\nTo add commands, make sure to import the dispatcher via\n\n`from tg_bot import dispatcher`.\n\nYou can then add commands using the usual\n\n`dispatcher.add_handler()`.\n\nAssigning the `__help__` variable to a string describing this modules' available\ncommands will allow the bot to load it and add the documentation for\nyour module to the `/help` command. Setting the `__mod_name__` variable will also allow you to use a nicer, user\nfriendly name for a module.\n\nThe `__migrate__()` function is used for migrating chats - when a chat is upgraded to a supergroup, the ID changes, so\nit is necessary to migrate it in the db.\n\nThe `__stats__()` function is for retrieving module statistics, eg number of users, number of chats. This is accessed\nthrough the `/stats` command, which is only available to the bot owner.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPaulSonOfLars%2Ftgbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPaulSonOfLars%2Ftgbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPaulSonOfLars%2Ftgbot/lists"}