A modular telegram Python bot running on python3 with an sqlalchemy database.

Overview

TG_Bot

A modular telegram Python bot running on python3 with an sqlalchemy 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.

IMPORTANT NOTICE:

This project is no longer under active maintenance. Occasional bug fixes may be released, but no new features are scheduled to be added. Users of Marie are encouraged to migrate to Rose, which is the improved version of this project, written in golang, with scalability in mind.

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:[email protected]: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:[email protected]: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.

Owner
Movindu Bandara
Movindu Bandara
Simple Telegram AI Chat bot made using OpenAI and Luna API

Yui Yui, is a simple telegram chat bot made using OpenAI and Luna Chat bot Deployment 👀 Deploying is easy 🤫 ! You can deploy this bot in Heroku or i

I'm Not A Bot #Left_TG 21 Dec 29, 2022
A multi purpose discord bot for python

Sypher The best multi purpose discord bot. Add Sypher right now Invite Me | Join

Johan Naizu 1 Dec 15, 2022
Another Autoscaler is a Kubernetes controller that automatically starts, stops, or restarts pods from a deployment at a specified time using a cron annotation.

Another Autoscaler Another Autoscaler is a Kubernetes controller that automatically starts, stops, or restarts pods from a deployment at a specified t

Diego Najar 66 Nov 19, 2022
A quick-and-dirty script to scrape the daily menu of Leipzig University Mensa and send it to a telegram channel.

Feed me Mensa UL A quick-and-dirty script to scrape the daily menu of Leipzig University Mensa and send it to a telegram channel. For food and cat lov

3 Apr 08, 2022
trackbranch is a tool for developers that can be used to store collections of branches in the form of profiles.

trackbranch trackbranch is a tool for developers that can be used to store collections of branches in the form of profiles. This can be useful for sit

Kevin Morris 1 Oct 21, 2021
Some random bot for Discord which was created just for fun (Made with Discord.py library)

Ghosty Previously known as 'secondthunder-py-bot' This is repository of some random bot for Discord which was created just for fun and for some educat

Владислав 8 Oct 02, 2022
Spotify playlist anonymizer.

Spotify heavily personalizes auto-generated playlists like Song Radio based on the music you've listened to in the past. But sometimes you want to listen to Song Radio precisely to hear some fresh so

Jakob de Maeyer 9 Nov 27, 2022
Yet another random discord bot.

YARDB (r!) Yet another fully functional and random discord bot. I might add more features if I'm bored also don't criticize on my code. Commands: 4 Di

kayle 1 Oct 21, 2021
Trust-minimized Bitcoin wallet

coldcore Trust-minimized, airgapped Bitcoin management This is experimental software. Wait for a formal release before use with real funds. A trust-mi

James O'Beirne 121 Jan 01, 2023
Simple Reddit bot that replies to comments containing a certain word.

reddit-replier-bot Small comment reply bot based on PRAW. This script will scan the comments of a subreddit as they come in and look for a trigger wor

Kefendy 0 Jun 04, 2022
TeamDltvideo Bot you can add in your Telegram Group Thanks

TeamDltvideo TeamDltvideo Bot you can add in your Telegram Group Thanks Video Stream is a telegram bot project that's allow you to play video on teleg

TeamDlt 1 Nov 18, 2021
A tool for transferring server variable values from one intersect gamedata.db to another

Server Variable Transfer Tool Purpose This tool exists for use with the Intersect Engine (Ascension Game Dev GitHub). Its purpose is to UPDATE one sql

AVild 2 Oct 27, 2021
Python library for generating sequences with uniform stimulus history

Sampling Euler tours for uniform stimulus history Table of Contents About Examples Experiment 1 Experiment 2 Experiment 3 Experiment 4 Experiment 5 Co

5 Nov 11, 2021
Discord Token Nuker With Python

Discord token nuker a.k.a A$$Fvcker Setup For installing the requirements do this: pip install -r requirements.txt To start the Token nuker run this

PR3C14D0 8 Sep 22, 2022
Properly-formatted dynamic timestamps for Discord messages

discord-timestamps discord-timestamps generates properly-formatted dynamic timestamps for Discord messages, with support for Arrow objects. format

Ben Soyka 2 Mar 10, 2022
My attempt to reverse the Discord nitro token generation function.

discord-theory-I PART: I My attempt to reverse the Discord nitro token generation function. The Nitro generation tools thing is common in Discord now,

Jakom 29 Aug 14, 2022
The Most advanced and User-Friendly Google Collab NoteBook to download Torrent directly to Google Drive with File or Magnet Link support and with added protection of Timeout Preventer.

Torrent To Google Drive (UI Added! 😊 ) A Simple and User-Friendly Google Collab Notebook with UI to download Torrent to Google Drive using (.Torrent)

Dr.Caduceus 33 Aug 16, 2022
HASOKI DDOS TOOL- powerful DDoS toolkit for penetration tests

DDoS Attack Panel includes CloudFlare Bypass (UAM, CAPTCHA, GS ,VS ,BFM, etc..) This is open source code. I am not responsible if you use it for malic

Rebyc 1 Dec 02, 2022
Instant messaging client in tkinter

Concord_client_tk Instant messaging client in tkinter Contributors : Ilade-s [https://github.com/Ilade-s] Doku [https://github.com/D0kuhebi] Descripti

Raphaël Merlet 2 Jun 15, 2022
Discovery is an open-source Discord Bot with the main features Tickets, Moderation, Giveaways and Reaction roles.

Discovery is an open-source Discord Bot with the main features Tickets, Moderation, Giveaways and Reaction roles.

1 Dec 29, 2021