Skip to content

Modular telegram group management bot written on python ๐Ÿ

License

Notifications You must be signed in to change notification settings

Ghost-IU/Miss-Evie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Miss_Evie

forthebadge made-with-python ForTheBadge built-with-love

License: GPL v3 PRs Welcome

logo

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, becoming extremely modular and simple to use. Note that this project uses well-known Telegram-bot of it's time @BanhammerMarie_bot from Paul Larson as it's base.

Can be found on telegram as miss_evie.

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

Clone the repo

git clone -j$(nproc --all) https://github.com/DevOps117/Miss-Evie.git

Credits

Starry69 for many stuffs.

Skittbot for Stickers module and memes in extras module.

AyraHikari for weather modules and some other stuffs.

MrYacha for connections module

ATechnoHazard for many stuffs

corsicanu and nunopenim for android modules

Any other missing Credits can be seen in commits!

Starting the bot

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

  • sudo python3 -m miss_evie

For podman users

  • sudo podman pod start miss_evie

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

Please make sure to use atleast 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.

Podman

Update the package database

  • sudo pacman -Sy

Install podman

  • sudo pacman -S podman

Build the bot image(cd into the bot directory first)

  • sudo podman build --no-cache -t miss_evie:1.0 .

Create a pod and the containers(change YOUR_PASS appropriately)

  • sudo podman pod create --name miss_evie
  • sudo podman create --name evie --pod miss_evie localhost/miss_evie:1.0
  • sudo podman create -e POSTGRES_PASSWORD=YOUR_PASS --name db_container --pod miss_evie postgres:alpine

Configure the database container

  • sudo podman start db_container
  • sudo podman exec -it db_container /bin/sh

Then continue from step 2 of #database

After exiting from the container

Configure the bot

Make the config.py, check out #configuration

After making one

  • sudo podman cp <location of the config.py> evie:miss_evie/config.py

Starting the bot(pod)

  • sudo podman pod start miss_evie

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 miss_evie 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 miss_evie.sample_config import Config


class Development(Config):
    OWNER_ID =  823033347 # my telegram ID
    OWNER_USERNAME = "devops117"  # 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 = []  # List of id's for users which have sudo access to the bot.
    LOAD = []
    NO_LOAD = []
    TELETHON_HASH = None # for purge stuffs
    TELETHON_ID = None

Bot deps(for arch based)

Update the package database

  • sudo pacman -Sy

Install deps

  • sudo pacman -S libffi gcc git python libjpeg-turbo zlib postgresql libwebp libxml2 libxslt

Ensure pip

  • sudo python3 -m ensurepip

Python dependencies

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

  • sudo pip3 install -U --no-cache pip wheel
  • sudo pip3 install -U --no-cache -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 arch system. Other distributions may vary.

chsh to some sh for postgres user In my case bash

  • sudo chsh -s /bin/bash postgres

Change to the postgres user

  • sudo su - postgres

Create a new db cluster with initdb

  • cd && mkdir data && chmod 0700 data && initdb -D data

Change UNIX Socket dir value(Optional) Appending this one time much better than doing sudo mkdir /run/postgresql && sudo chown postgres:postgres /run/postgresql on each reboot.

  • echo "unix_socket_directories = '/tmp'" >> data/postgresql.conf

Start the db server with pg_ctl

  • pg_ctl start -D data

Create a new database user (change YOUR_USER appropriately)

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

  • createuser -Pse YOUR_USER

Create a new database(Change YOUR_USER and YOUR_DB_NAME appropriately.)

  • createdb -O YOUR_USER YOUR_DB_NAME

Testing

  • 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 localhost:5432.

You should now be able to build your database URI.

Sample database URI

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

Replace sqldbtype with whichever db youre using (eg postgresql, 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 miss_evie 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.

About

Modular telegram group management bot written on python ๐Ÿ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages