Giter Club home page Giter Club logo

telegram-mebot's Introduction

Telegram MeBot

Многопоточный, простой Телеграм бот на Python 3.

Данный бот как личный помощник, который может выполнять различные рутиные задачи. Получать команды ввида /command и реагировать на них выполняя полезную работу.

Бот принимает только команды ввида /command или /command text text. Название команды привязанно к методу класса.

Очень легко создавать методы которые будут реагировать на полученные команды. Имя метода необходимо начинать со знака _.

Установка

pip install mebot

Импортировать необходимые объекты

from mebot.telegram import main as mebot, BaseCoordinator

Сюда вставить ваш телеграм токен TOKEN = os.getenv("TOKEN", "This YOU TOKEN")

Остановить работу Бота необходимо нажать сочетание клавиш Ctrl + C.

Полный ответ от телеграмма находится в атрибуте класса self.tg_object.

Пример 1

from mebot.telegram import main as mebot, BaseCoordinator
import os

TOKEN = os.getenv("TOKEN", "")

class Command( BaseCoordinator ):
    """ 
    Атрибуты класса:
    'tg_object' --  данные от телеграма
    'chat_id' -- чат id
    'api_url' -- урл с токеном
    'command' -- команда которая была вызвана
    'storage' -- словарь для хранения различных данных для каждого клиента
    
    Доступ осуществляется через self.tg_object, self.chat_id и т.д.
    """

    def _start(self):
        """
        command /start
        """
        return "Привет!! Это твой Телеграм Бот. Готов тебе служить!"

    def _echo(self):
        """
        command /echo
        """
        return f"{self.command}"


if __name__ == '__main__':

    mebot( token=TOKEN, coordinator = Command )

Пример 2

from mebot.telegram import main as mebot, BaseCoordinator
import time, os

TOKEN = os.getenv("TOKEN", "")

class Command( BaseCoordinator ):
    """ 
    Атрибуты класса:
    'tg_object' --  данные от телеграма
    'chat_id' -- чат id
    'api_url' -- урл с токеном
    'command' -- команда которая была вызвана
    'storage' -- словарь для хранения различных данных для каждого клиента
    
    Доступ осуществляется через self.tg_object, self.chat_id и т.д.
    """

    def _play(self):
        '''запустить спам сообщений'''
        self.storage["play"] = True
        i = 0
        while True:
            i+=1
            if not self.storage["play"]:
                break
            self.send_message( "{}. play **I 😲 Spamer**".format(i) )
            time.sleep(2)

        return "play stop"


    def _stop(self):
        '''остановить спам собщений'''
        self.storage["play"] = False


if __name__ == '__main__':

    mebot( token=TOKEN, coordinator = Command )

telegram-mebot's People

Contributors

repen avatar

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.