Coder Social home page Coder Social logo

paulsonoflars / tgbot Goto Github PK

View Code? Open in Web Editor NEW
669.0 54.0 906.0 759 KB

Modular telegram group management bot

License: GNU General Public License v3.0

Python 99.99% Procfile 0.01%
bot python-bot tgbot telegram sqlalchemy-database python3 database postgres

tgbot's Introduction

IMPORTANT NOTICE:

This project is no longer maintained, and should be considered deprecated. Use at your own risk.

Telegram have made many breaking changes since this bot was last updated, and as such, there are no expectations that this will work. Notably, user IDs have gone from 32 bit to 64, which will cause issues with the database that I do not believe are worth fixing.

If you choose to take inspiration from this codebase, I would like to ask that you "pass it forward", and make your code open source. This will help people learn from you, as you are learning from this repo.

If you are simply looking for a group management bot to use in your chat, I would like to encourage giving Rose a try; it was built as Marie's successor, and has many of the same features (but is much faster!)

tgbot

A modular telegram Python bot running on python3 with a postgres database.

Originally a simple group management bot with multiple admin features, it has evolved into becoming a basis for modular bots aiming to provide simple plugin expansion via a simple drag and drop.

Can be found on telegram as Marie.

For questions regarding creating your own bot, please head to this chat where you'll find a group of volunteers to help. We'll also help when a database schema changes, and some table column needs to be modified/added (this info can also be found in the commit messages)

Join the news channel if you just want to stay in the loop about new features or announcements.

Marie and I can also be found moderating the marie support group aimed at providing help setting up Marie in your chats (not for bot clones). Feel free to join to report bugs, and stay in the loop on the status of the bot development.

Note to maintainers that all schema changes will be found in the commit messages, and its their responsibility to read any new commits.

Starting the bot.

Once you've setup your database and your configuration (see below) is complete, simply run:

python3 -m tg_bot

Setting up the bot (Read this before trying to use!):

Please make sure to use python3.6, as I cannot guarantee everything will work as expected on older python versions! This is because markdown parsing is done by iterating through a dict, which are ordered by default in 3.6.

Configuration

There are two possible ways of configuring your bot: a config.py file, or ENV variables.

The prefered version is to use a config.py file, as it makes it easier to see all your settings grouped together. This file should be placed in your tg_bot folder, alongside the __main__.py file . This is where your bot token will be loaded from, as well as your database URI (if you're using a database), and most of your other settings.

It is recommended to import sample_config and extend the Config class, as this will ensure your config contains all defaults set in the sample_config, hence making it easier to upgrade.

An example config.py file could be:

from tg_bot.sample_config import Config


class Development(Config):
    OWNER_ID = 254318997  # my telegram ID
    OWNER_USERNAME = "SonOfLars"  # my telegram username
    API_KEY = "your bot api key"  # my api key, as provided by the botfather
    SQLALCHEMY_DATABASE_URI = 'postgresql://username:password@localhost:5432/database'  # sample db credentials
    MESSAGE_DUMP = '-1234567890' # some group chat that your bot is a member of
    USE_MESSAGE_DUMP = True
    SUDO_USERS = [18673980, 83489514]  # List of id's for users which have sudo access to the bot.
    LOAD = []
    NO_LOAD = ['translation']

If you can't have a config.py file (EG on heroku), it is also possible to use environment variables. The following env variables are supported:

  • ENV: Setting this to ANYTHING will enable env variables

  • TOKEN: Your bot token, as a string.

  • OWNER_ID: An integer of consisting of your owner ID

  • OWNER_USERNAME: Your username

  • DATABASE_URL: Your database URL

  • MESSAGE_DUMP: optional: a chat where your replied saved messages are stored, to stop people deleting their old

  • LOAD: Space separated list of modules you would like to load

  • NO_LOAD: Space separated list of modules you would like NOT to load

  • WEBHOOK: Setting this to ANYTHING will enable webhooks when in env mode messages

  • URL: The URL your webhook should connect to (only needed for webhook mode)

  • SUDO_USERS: A space separated list of user_ids which should be considered sudo users

  • SUPPORT_USERS: A space separated list of user_ids which should be considered support users (can gban/ungban, nothing else)

  • WHITELIST_USERS: A space separated list of user_ids which should be considered whitelisted - they can't be banned.

  • DONATION_LINK: Optional: link where you would like to receive donations.

  • CERT_PATH: Path to your webhook certificate

  • PORT: Port to use for your webhooks

  • DEL_CMDS: Whether to delete commands from users which don't have rights to use that command

  • STRICT_GBAN: Enforce gbans across new groups as well as old groups. When a gbanned user talks, he will be banned.

  • WORKERS: Number of threads to use. 8 is the recommended (and default) amount, but your experience may vary. Note that going crazy with more threads wont necessarily speed up your bot, given the large amount of sql data accesses, and the way python asynchronous calls work.

  • BAN_STICKER: Which sticker to use when banning people.

  • ALLOW_EXCL: Whether to allow using exclamation marks ! for commands as well as /.

Python dependencies

Install the necessary python dependencies by moving to the project directory and running:

pip3 install -r requirements.txt.

This will install all necessary python packages.

Database

If you wish to use a database-dependent module (eg: locks, notes, userinfo, users, filters, welcomes), you'll need to have a database installed on your system. I use postgres, so I recommend using it for optimal compatibility.

In the case of postgres, this is how you would set up a the database on a debian/ubuntu system. Other distributions may vary.

  • install postgresql:

sudo apt-get update && sudo apt-get install postgresql

  • change to the postgres user:

sudo su - postgres

  • create a new database user (change YOUR_USER appropriately):

createuser -P -s -e YOUR_USER

This will be followed by you needing to input your password.

  • create a new database table:

createdb -O YOUR_USER YOUR_DB_NAME

Change YOUR_USER and YOUR_DB_NAME appropriately.

  • finally:

psql YOUR_DB_NAME -h YOUR_HOST YOUR_USER

This will allow you to connect to your database via your terminal. By default, YOUR_HOST should be 0.0.0.0:5432.

You should now be able to build your database URI. This will be:

sqldbtype://username:pw@hostname:port/db_name

Replace sqldbtype with whichever db youre using (eg postgres, mysql, sqllite, etc) repeat for your username, password, hostname (localhost?), port (5432?), and db name.

Modules

Setting load order.

The module load order can be changed via the LOAD and NO_LOAD configuration settings. These should both represent lists.

If LOAD is an empty list, all modules in modules/ will be selected for loading by default.

If NO_LOAD is not present, or is an empty list, all modules selected for loading will be loaded.

If a module is in both LOAD and NO_LOAD, the module will not be loaded - NO_LOAD takes priority.

Creating your own modules.

Creating a module has been simplified as much as possible - but do not hesitate to suggest further simplification.

All that is needed is that your .py file be in the modules folder.

To add commands, make sure to import the dispatcher via

from tg_bot import dispatcher.

You can then add commands using the usual

dispatcher.add_handler().

Assigning the __help__ variable to a string describing this modules' available commands will allow the bot to load it and add the documentation for your module to the /help command. Setting the __mod_name__ variable will also allow you to use a nicer, user friendly name for a module.

The __migrate__() function is used for migrating chats - when a chat is upgraded to a supergroup, the ID changes, so it is necessary to migrate it in the db.

The __stats__() function is for retrieving module statistics, eg number of users, number of chats. This is accessed through the /stats command, which is only available to the bot owner.

tgbot's People

Contributors

1maverick1 avatar anirudhgupta109 avatar gotenksin avatar herobuxx avatar jvlianodorneles avatar msfjarvis avatar paulsonoflars avatar rohk25 avatar skittles9823 avatar spechide avatar sphericalkat avatar termozour avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tgbot's Issues

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:sqldbtype Error

my config.py is here

    OWNER_ID = 9829c10057  # my telegram ID
    OWNER_USERNAME = "charindith"  # my telegram username
    API_KEY = "11846d7265:AAGpXcl1ssssuKNW7rgB8dwh4dddddv9Dg"  # my api key, as provided by the botfather
    SQLALCHEMY_DATABASE_URI = 'sqldbtype://charin:charin@localhost:5432/charin'  # sample db credentials
    MESSAGE_DUMP = '-1012430833035' # some group chat that your bot is a member of
    USE_MESSAGE_DUMP = True
    SUDO_USERS = []  # List of id's for users which have sudo access to the bot.
    LOAD = []
    NO_LOAD = ['translation']

I done all the instructions correctly but then this happen

root@ip-172-31-44-112:/home/ubuntu/tgbot# python3 -m tg_bot
2020-09-10 19:46:03,627 - tg_bot - INFO - Not loading: ['translation']
2020-09-10 19:46:03,628 - tg_bot - INFO - Modules to load: ['admin', 'afk', 'antiflood', 'backups', 'bans', 'blacklist', 'cust_filters', 'disable', 'global_bans', 'locks', 'log_channel', 'misc', 'msg_deleting', 'muting', 'notes', 'reporting', 'rss', 'rules', 'sed', 'userinfo', 'users', 'warns', 'welcome']
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/ubuntu/tgbot/tg_bot/__main__.py", line 74, in <module>
    imported_module = importlib.import_module("tg_bot.modules." + module_name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gc
```d_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ubuntu/tgbot/tg_bot/modules/admin.py", line 12, in <module>
    from tg_bot.modules.disable import DisableAbleCommandHandler
  File "/home/ubuntu/tgbot/tg_bot/modules/disable.py", line 19, in <module>
    from tg_bot.modules.sql import disable_sql as sql
  File "/home/ubuntu/tgbot/tg_bot/modules/sql/__init__.py", line 16, in <module>
    SESSION = start()
  File "/home/ubuntu/tgbot/tg_bot/modules/sql/__init__.py", line 9, in start
    engine = create_engine(DB_URI, client_encoding="utf8")
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/__init__.py", line 500, in create_engine
    return strategy.create(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/strategies.py", line 61, in create
    entrypoint = u._get_entrypoint()
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/url.py", line 172, in _get_entrypoint
    cls = registry.load(name)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/util/langhelpers.py", line 268, in load
    "Can't load plugin: %s:%s" % (self.group, name)
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:sqldbtype

fban -> unban - Rose still kicks the user

I unfortunately fbanned the wrong id (it was a forwarded message, so the original couldn't be determined). Then I unbanned the user (positive response from Rose) and removed him/her from the list of banned users. When the user wanted to join again, s*he was kickbanned again by Rose. Only adding the user by me (admin) solved the problem. I can add the user id here, if you want to check the logs.

SQL Error

Check here

File "/app/tg_bot/modules/sql/init.py", line 16, in
2021-11-07T12:04:16.887722+00:00 app[web.1]: SESSION = start()
2021-11-07T12:04:16.887736+00:00 app[web.1]: File "/app/tg_bot/modules/sql/init.py", line 9, in start
2021-11-07T12:04:16.887833+00:00 app[web.1]: engine = create_engine(DB_URI, client_encoding="utf8")
2021-11-07T12:04:16.887847+00:00 app[web.1]: File "", line 2, in create_engine
2021-11-07T12:04:16.887932+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py", line 298, in warned
2021-11-07T12:04:16.888130+00:00 app[web.1]: return fn(*args, **kwargs)
2021-11-07T12:04:16.888145+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/sqlalchemy/engine/create.py", line 534, in create_engine
2021-11-07T12:04:16.888406+00:00 app[web.1]: entrypoint = u._get_entrypoint()
2021-11-07T12:04:16.888420+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/sqlalchemy/engine/url.py", line 645, in _get_entrypoint
2021-11-07T12:04:16.888721+00:00 app[web.1]: cls = registry.load(name)
2021-11-07T12:04:16.888735+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 343, in load
2021-11-07T12:04:16.888947+00:00 app[web.1]: raise exc.NoSuchModuleError(
2021-11-07T12:04:16.889032+00:00 app[web.1]: sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres

user_id integer out of range

sqlalchemy.exc.DataError: (psycopg2.errors.NumericValueOutOfRange) integer out of range

[SQL: INSERT INTO users (user_id, username) VALUES (%(user_id)s, %(username)s)]
[parameters: {'user_id': 53****, 'username': 'test_testmm_bot'}]
(Background on this error at: https://sqlalche.me/e/14/9h9h)

ๅฏไปฅๅœจๆฌข่ฟŽ่ฏญ้‡ŒๆทปๅŠ ๅ›พ็‰‡ๅ—๏ผŸ

้ฆ–ๅ…ˆๆ„Ÿ่ฐขๅˆถไฝœ็ป„ใ€‚
ๅฆ‚้ข˜๏ผŒMarkdown้‡Œ่พนๅฏไปฅๆทปๅŠ ๅ‘้€ๅ›พ็‰‡ๅŠŸ่ƒฝๅ—๏ผŸ

๏น‰๏น‰๏น‰๏น‰๏น‰๏น‰๏น‰Google translate:
title๏ผšCan you add pictures to the welcome message?

content๏ผšFirst of all thanks to the production team.
Like the title, can you add the function of sending pictures in Markdown?
โค๏ธ๐Ÿ˜˜

Ban my number or my area code?!

Hi there, I'm confused!

There are a lot of group in telegram that use Rose bot to manage but I can't send message because of banning my number on it. I think you blocked all +98 codes. but what your logic to did it?!

my number is +98-91********
Why did you block? are u in censorship team or something like that?

I am getting error.

Hi!

2021-05-07 12:23:10,513 - tg_bot - INFO - Not loading: ['translation', 'rss', 'sed']
2021-05-07 12:23:10,513 - tg_bot - INFO - Modules to load: ['admin', 'afk', 'antiflood', 'backups', 'bans', 'blacklist', 'cust_filters', 'disable', 'global_bans', 'locks', 'log_channel', 'misc', 'msg_deleting', 'muting', 'notes', 'reporting', 'rules', 'userinfo', 'users', 'warns', 'welcome']
/usr/lib/python3/dist-packages/requests/init.py:91: RequestsDependencyWarning: urllib3 (1.25.11) or chardet (3.0.4) doesn't match a supported version!
RequestsDependencyWarning)
2021-05-07 12:23:12,674 - tg_bot - INFO - Successfully loaded modules: ['admin', 'afk', 'antiflood', 'backups', 'bans', 'blacklist', 'cust_filters', 'disable', 'global_bans', 'locks', 'log_channel', 'misc', 'msg_deleting', 'muting', 'notes', 'reporting', 'rules', 'userinfo', 'users', 'warns', 'welcome']
2021-05-07 12:23:12,675 - tg_bot - INFO - Using long polling.
2021-05-07 12:29:47,945 - telegram.ext.updater - ERROR - unhandled exception in dispatcher
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/telegram/ext/updater.py", line 156, in _thread_wrapper
target(*args, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/telegram/ext/dispatcher.py", line 228, in start
self.process_update(update)
File "/home/pi/tgbot/tg_bot/main.py", line 478, in process_update
cnt = CHATS_CNT.get(update.effective_chat.id, 0)
AttributeError: 'NoneType' object has no attribute 'id'

How I can solve?

Database error for user IDs with 10 digits

Seeing the following error for accounts with new 10 digit user ID system. Accounts that have 9 or less digit user IDs are working fine. probably related to https://core.telegram.org/bots/api#march-9-2021, where it says

user identifiers can now have up to 52 significant bits and require a 64-bit integer or double-precision float type to be stored safely.

Could you please suggest a solution?

Example error details-

sqlalchemy.exc.DataError: (psycopg2.errors.NumericValueOutOfRange) integer out of range

[SQL: INSERT INTO afk_users (user_id, is_afk, reason) VALUES (%(user_id)s, %(is_afk)s, %(reason)s)]
[parameters: {'user_id': 1234567890, 'is_afk': True, 'reason': 'test'}]
(Background on this error at: https://sqlalche.me/e/14/9h9h)

complaint mode

Hi, can contributors add complaint mode to Rose.

So someone in group write bad things. Then X number of users(can be adjust by admin) complain this user to admin. then this user who wrote bad things add silent mode or bun or kick. Then admin control the process.

Thanks to contributors.

Problems with mysql

Hello,

First of all, I know Marie is down, but I am hoping for help anyway.
I am actually trying to host this project on my own, but I can't get the bot starting.
I am using Mysql as database backend, with this line in config.py:

SQLALCHEMY_DATABASE_URI = 'mysql://root:9wTEfjyg9EmNGtRt@localhost:3306/nemesis'

But I am getting an error as followed:

2020-01-02 11:35:51,109 - tg_bot - INFO - Not loading: ['translation', 'rss', 'sed']
2020-01-02 11:35:51,110 - tg_bot - INFO - Modules to load: ['admin', 'afk', 'antiflood', 'backups', 'bans', 'blacklist', 'cust_filters', 'disable', 'global_bans', 'locks', 'log_channel', 'misc', 'msg_deleting', 'muting', 'notes', 'reporting', 'rules', 'userinfo', 'users', 'warns', 'welcome']
Traceback (most recent call last):
  File "/usr/lib64/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/jens/tgbot/tg_bot/__main__.py", line 74, in <module>
    imported_module = importlib.import_module("tg_bot.modules." + module_name)
  File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/jens/tgbot/tg_bot/modules/admin.py", line 12, in <module>
    from tg_bot.modules.disable import DisableAbleCommandHandler
  File "/home/jens/tgbot/tg_bot/modules/disable.py", line 19, in <module>
    from tg_bot.modules.sql import disable_sql as sql
  File "/home/jens/tgbot/tg_bot/modules/sql/__init__.py", line 16, in <module>
    SESSION = start()
  File "/home/jens/tgbot/tg_bot/modules/sql/__init__.py", line 9, in start
    engine = create_engine(DB_URI, client_encoding="utf8")
  File "/usr/lib/python3.7/site-packages/sqlalchemy/engine/__init__.py", line 479, in create_engine
    return strategy.create(*args, **kwargs)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 173, in create
    engineclass.__name__,
TypeError: Invalid argument(s) 'client_encoding' sent to create_engine(), using configuration MySQLDialect_mysqldb/QueuePool/Engine.  Please check that the keyword arguments are appropriate for this combination of components.

What am I doing wrong?
Thanks for your help.

EDIT: Fix Typo

[Intentional, closed] Send rules to group chat instead of PM

When I add a rule to a group chat, the rule gets saved and a message is shown. However, if I want to view the rules that I've set, it replies to tell me to go to the bot's PM to see the group chat rules. This can be troublesome especially when I have to click/tap on the "Start" button to actually see the group chat rules.

Having the bot to message the rules in the same chat will be better as it is less troublesome and so that people who join the group can see the rules of the group. However, this can also cause spam issues if the group is very popular.

So, is this intentional behaviour?

Feature: Leave from Chat if Added by anyone other than owner

I am new to Python, as well as telegram bot creation. It will be great if you can guide me to add a piece of code to exit the group if the bot is added to any group, by anyone other than owner of bot.

I am not able to understand, where should I write that code to exit/leave from group.

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres

HI

I installed postgres and all dependencies but get an error with "postgres" for SQLALCHEMY_DATABASE_URI.

root@rpi4-cloud:~/telegram/tgbot# python3 -m tg_bot
2022-02-19 19:38:00,629 - tg_bot - INFO - Not loading: ['translation', 'rss', 'sed']
2022-02-19 19:38:00,629 - tg_bot - INFO - Modules to load: ['admin', 'afk', 'antiflood', 'backups', 'bans', 'blacklist', 'cust_filters', 'disable', 'global_bans', 'locks', 'log_channel', 'misc', 'msg_deleting', 'muting', 'notes', 'reporting', 'rules', 'userinfo', 'users', 'warns', 'welcome']
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/root/telegram/tgbot/tg_bot/__main__.py", line 74, in <module>
    imported_module = importlib.import_module("tg_bot.modules." + module_name)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/root/telegram/tgbot/tg_bot/modules/admin.py", line 12, in <module>
    from tg_bot.modules.disable import DisableAbleCommandHandler
  File "/root/telegram/tgbot/tg_bot/modules/disable.py", line 19, in <module>
    from tg_bot.modules.sql import disable_sql as sql
  File "/root/telegram/tgbot/tg_bot/modules/sql/__init__.py", line 16, in <module>
    SESSION = start()
  File "/root/telegram/tgbot/tg_bot/modules/sql/__init__.py", line 9, in start
    engine = create_engine(DB_URI, client_encoding="utf8")
  File "<string>", line 2, in create_engine
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/deprecations.py", line 309, in warned
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/create.py", line 534, in create_engine
    entrypoint = u._get_entrypoint()
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/url.py", line 661, in _get_entrypoint
    cls = registry.load(name)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/langhelpers.py", line 344, in load
    "Can't load plugin: %s:%s" % (self.group, name)
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres
root@rpi4-cloud:~/telegram/tgbot#

if i replaced by "postgresql", i got another error:

root@rpi4-cloud:~/telegram/tgbot# python3 -m tg_bot
2022-02-19 19:39:32,557 - tg_bot - INFO - Not loading: ['translation', 'rss', 'sed']
2022-02-19 19:39:32,558 - tg_bot - INFO - Modules to load: ['admin', 'afk', 'antiflood', 'backups', 'bans', 'blacklist', 'cust_filters', 'disable', 'global_bans', 'locks', 'log_channel', 'misc', 'msg_deleting', 'muting', 'notes', 'reporting', 'rules', 'userinfo', 'users', 'warns', 'welcome']
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1803, in _execute_context
    cursor, statement, parameters, context
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.NumericValueOutOfRange: integer out of range


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/root/telegram/tgbot/tg_bot/__main__.py", line 74, in <module>
    imported_module = importlib.import_module("tg_bot.modules." + module_name)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/root/telegram/tgbot/tg_bot/modules/admin.py", line 14, in <module>
    from tg_bot.modules.helper_funcs.extraction import extract_user
  File "/root/telegram/tgbot/tg_bot/modules/helper_funcs/extraction.py", line 7, in <module>
    from tg_bot.modules.users import get_user_id
  File "/root/telegram/tgbot/tg_bot/modules/users.py", line 11, in <module>
    import tg_bot.modules.sql.users_sql as sql
  File "/root/telegram/tgbot/tg_bot/modules/sql/users_sql.py", line 172, in <module>
    ensure_bot_in_db()
  File "/root/telegram/tgbot/tg_bot/modules/sql/users_sql.py", line 71, in ensure_bot_in_db
    SESSION.commit()
  File "<string>", line 2, in commit
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/session.py", line 1431, in commit
    self._transaction.commit(_to_root=self.future)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/session.py", line 829, in commit
    self._prepare_impl()
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/session.py", line 808, in _prepare_impl
    self.session.flush()
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/session.py", line 3363, in flush
    self._flush(objects)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/session.py", line 3503, in _flush
    transaction.rollback(_capture_exception=True)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/langhelpers.py", line 72, in __exit__
    with_traceback=exc_tb,
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/session.py", line 3463, in _flush
    flush_context.execute()
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
    rec.execute(self)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/unitofwork.py", line 633, in execute
    uow,
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/persistence.py", line 249, in save_obj
    insert,
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/persistence.py", line 1097, in _emit_insert_statements
    statement, multiparams, execution_options=execution_options
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1614, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/sql/elements.py", line 326, in _execute_on_connection
    self, multiparams, params, execution_options
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1491, in _execute_clauseelement
    cache_hit=cache_hit,
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
    e, statement, parameters, cursor, context
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 2027, in _handle_dbapi_exception
    sqlalchemy_exception, with_traceback=exc_info[2], from_=e
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1803, in _execute_context
    cursor, statement, parameters, context
  File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.DataError: (psycopg2.errors.NumericValueOutOfRange) integer out of range

[SQL: INSERT INTO users (user_id, username) VALUES (%(user_id)s, %(username)s)]
[parameters: {'user_id': xxxxxxx, 'username': 'xxxxxxxx'}]
(Background on this error at: https://sqlalche.me/e/14/9h9h)

Any clue is welcome.

Thanks

tg_bot

there is no module found tg_bot

saying goodbye and welcome to other bots when bots are lock

hello
thanks for your good bot
I think it's better not to say goodbye and welcome to bots when bots are lock. because it's like this.
1- say hello to bot
2- remove the bot
3- say only admins can add a bot
4- say goodbye

if admin doesn't like a robot the the robot is not welcome, and when Marie remove some user or but she shouldn't say goodbye.

Error while starting bot

Hello,
I am currently having troubles with setting up Marie.
When trying to start here I get the following Error:

2020-01-02 12:39:54,994 - tg_bot - INFO - Not loading: ['translation']
2020-01-02 12:39:54,994 - tg_bot - INFO - Modules to load: ['admin', 'afk', 'antiflood', 'backups', 'bans', 'blacklist', 'cust_filters', 'disable', 'global_bans', 'locks', 'log_channel', 'misc', 'msg_deleting', 'muting', 'notes', 'reporting', 'rss', 'rules', 'sed', 'userinfo', 'users', 'warns', 'welcome']
Traceback (most recent call last):
  File "/usr/lib64/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/jens/tgbot/tg_bot/__main__.py", line 74, in <module>
    imported_module = importlib.import_module("tg_bot.modules." + module_name)
  File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/jens/tgbot/tg_bot/modules/backups.py", line 10, in <module>
    from tg_bot.__main__ import DATA_IMPORT
  File "/home/jens/tgbot/tg_bot/__main__.py", line 74, in <module>
    imported_module = importlib.import_module("tg_bot.modules." + module_name)
  File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/jens/tgbot/tg_bot/modules/locks.py", line 23, in <module>
    'document': Filters.document & ~Filters.animation,
AttributeError: type object 'Filters' has no attribute 'animation'

I saw #59, but I think this isn't my problem.
What is the problem?
Thanks for your help.

Send Message to all chats

Hello,

At the time Marie was shutted down, A message was sent to all chats in wich the bot was a member in. How did the admins do that?

Thanks for your help.

error when trying to run bot

2019-02-14 08:18:28,165 - tg_bot - INFO - Not loading: ['translation', 'rss', 'sed']
2019-02-14 08:18:28,165 - tg_bot - INFO - Modules to load: ['admin', 'afk', 'antiflood', 'backups', 'bans', 'blacklist', 'cust_filters', 'disable', 'global_bans', 'locks', 'log_channel', 'misc', 'msg_deleting', 'muting', 'notes', 'reporting', 'rules', 'userinfo', 'users', 'warns', 'welcome']
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/ubuntu/tgbot/tg_bot/main.py", line 74, in
imported_module = importlib.import_module("tg_bot.modules." + module_name)
File "/usr/lib/python3.6/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "/home/ubuntu/tgbot/tg_bot/modules/admin.py", line 12, in
from tg_bot.modules.disable import DisableAbleCommandHandler
File "/home/ubuntu/tgbot/tg_bot/modules/disable.py", line 19, in
from tg_bot.modules.sql import disable_sql as sql
File "/home/ubuntu/tgbot/tg_bot/modules/sql/init.py", line 16, in
SESSION = start()
File "/home/ubuntu/tgbot/tg_bot/modules/sql/init.py", line 9, in start
engine = create_engine(DB_URI, client_encoding="utf8")
File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/init.py", line 431, in create_engine
return strategy.create(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/strategies.py", line 56, in create
plugins = u._instantiate_plugins(kwargs)
AttributeError: 'NoneType' object has no attribute '_instantiate_plugins'

Tgbot

No module found : tg_bot

TypeError: Can't instantiate abstract class _Supporters with abstract methods __call__

Hi! This is my first issue.

I am getting error.

E:\erenay1\tgbot-master>python -m tg_bot
2021-05-07 09:36:27,491 - tg_bot - INFO - Not loading: ['translation', 'rss', 'sed']
2021-05-07 09:36:27,491 - tg_bot - INFO - Modules to load: ['admin', 'afk', 'antiflood', 'backups', 'bans', 'blacklist', 'cust_filters', 'disable', 'global_bans', 'locks', 'log_channel', 'misc', 'msg_deleting', 'muting', 'notes', 'reporting', 'rules', 'userinfo', 'users', 'warns', 'welcome']
Traceback (most recent call last):
File "C:\Users\Erenay\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 194, in _run_module_as_main
return run_code(code, main_globals, None,
File "C:\Users\Erenay\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "E:\erenay1\tgbot-master\tg_bot_main
.py", line 74, in
imported_module = importlib.import_module("tg_bot.modules." + module_name)
File "C:\Users\Erenay\AppData\Local\Programs\Python\Python38\lib\importlib_init
.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "E:\erenay1\tgbot-master\tg_bot\modules\admin.py", line 14, in
from tg_bot.modules.helper_funcs.extraction import extract_user
File "E:\erenay1\tgbot-master\tg_bot\modules\helper_funcs\extraction.py", line 7, in
from tg_bot.modules.users import get_user_id
File "E:\erenay1\tgbot-master\tg_bot\modules\users.py", line 13, in
from tg_bot.modules.helper_funcs.filters import CustomFilters
File "E:\erenay1\tgbot-master\tg_bot\modules\helper_funcs\filters.py", line 7, in
class CustomFilters(object):
File "E:\erenay1\tgbot-master\tg_bot\modules\helper_funcs\filters.py", line 12, in CustomFilters
support_filter = _Supporters()
TypeError: Can't instantiate abstract class _Supporters with abstract methods call

Can anyone help me?

PSQL

psql: could not translate host name "0.0.0.0:5432" to address: Name or service not known

help what to do

Getting this error

ap4r1ch17@4P4R1CH17 ~/tgbot (master)> python3 -m tg_bot
2020-07-30 13:18:10,386 - tg_bot - INFO - Not loading: ['translation']
2020-07-30 13:18:10,386 - tg_bot - INFO - Modules to load: ['admin', 'afk', 'antiflood', 'backups', 'bans', 'blacklist', 'cust_filters', 'disable', 'global_bans', 'locks', 'log_channel', 'misc', 'msg_deleting', 'muting', 'notes', 'reporting', 'rss', 'rules', 'sed', 'userinfo', 'users', 'warns', 'welcome']
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/ap4r1ch17/tgbot/tg_bot/__main__.py", line 74, in <module>
    imported_module = importlib.import_module("tg_bot.modules." + module_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ap4r1ch17/tgbot/tg_bot/modules/admin.py", line 12, in <module>
    from tg_bot.modules.disable import DisableAbleCommandHandler
  File "/home/ap4r1ch17/tgbot/tg_bot/modules/disable.py", line 19, in <module>
    from tg_bot.modules.sql import disable_sql as sql
  File "/home/ap4r1ch17/tgbot/tg_bot/modules/sql/__init__.py", line 16, in <module>
    SESSION = start()
  File "/home/ap4r1ch17/tgbot/tg_bot/modules/sql/__init__.py", line 9, in start
    engine = create_engine(DB_URI, client_encoding="utf8")
  File "/home/ap4r1ch17/.local/lib/python3.8/site-packages/sqlalchemy/engine/__init__.py", line 500, in create_engine
    return strategy.create(*args, **kwargs)
  File "/home/ap4r1ch17/.local/lib/python3.8/site-packages/sqlalchemy/engine/strategies.py", line 54, in create
    u = url.make_url(name_or_url)
  File "/home/ap4r1ch17/.local/lib/python3.8/site-packages/sqlalchemy/engine/url.py", line 229, in make_url
    return _parse_rfc1738_args(name_or_url)
  File "/home/ap4r1ch17/.local/lib/python3.8/site-packages/sqlalchemy/engine/url.py", line 290, in _parse_rfc1738_args
    raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string ''

Feature request: bot localization

I'd like to see this bot has an option to set its language which used inside the group.
I think many people are ready to contribute to translate it.

Database error when adding this line

Hello, i've clone your bot with some edited script (just edit language). I want to update the bot base on your script, all script is work, but this script look like has error. when i write this script, and then build the bot. Bot will error when save welcome message or load welcome message, it say :

[SQL: 'SELECT welcome_pref.chat_id AS welcome_pref_chat_id, welcome_pref.should_welcome AS welcome_pref_should_welcome, welcome_pref.should_goodbye AS welcome_pref_should_goodbye, welcome_pref.custom_welcome AS welcome_pref_custom_welcome, welcome_pref.welcome_type AS welcome_pref_welcome_type, welcome_pref.custom_leave AS welcome_pref_custom_leave, welcome_pref.leave_type AS welcome_pref_leave_type, welcome_pref.clean_welcome AS welcome_pref_clean_welcome \nFROM welcome_pref \nWHERE welcome_pref.chat_id = %(param_1)s'] [parameters: {'param_1': '-10011xxxxxxxx'}] (Background on this error at: http://sqlalche.me/e/f405)

I don't know what error, but i think database error at read or write it, when i delete that line, and build, my bot has work fine.
And make new clean database fixed it, but some my group data is on old database.
And same error at locks_sql.py on tgbot/tg_bot/modules/sql.
Btw thanks to make perfect and open source bot ๐Ÿ‘

clean_welcome = Column(BigInteger)

add chat_lock feature

add chat_lock feature.
what will this feature do?
messages will be deleted when the command is used.admin messages will not be deleted
as an example, you can look at the bot over there. for example

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.