├── LICENSE.md ├── README.md ├── config.py ├── connection.py ├── content ├── other.py └── text.py ├── main.py └── plugins ├── ban.py ├── everyone_message.py ├── start.py └── unban.py /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | Copyright (C) 2021 >_run 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LivegramBot 2 | This bot is made for talking with your subscribers - they send a message to bot, and bot will forward message to your PM/group! 3 | Bot supports python 3.6+. It wasn't tested on versions lower. 4 | To use this library, install [PytelegramBotAPI](https://pypi.org/project/pyTelegramBotAPI/) 5 | 6 | ## About 7 | This is LivegramBot - bot for talking with users! 8 | 9 | ## Setup 10 | To begin setup, just edit config.py file. There is whole config to be edited. Here are written some variables that should be edited: 11 | 12 | blocked = "bot was blocked by the user" #Bot got blocked by the user 13 | 14 | start = "Hello! This is your start message!" #start message 15 | 16 | ban = "you were banned by the admin!" #You got banned 17 | 18 | unban = "you were unbanned by the admin." #You were unbanned 19 | 20 | text_message = "Message that would be send if somebody writes any text" #When user writes a message, this message is shown by default 21 | 22 | banned = "you are blocked" #ban 23 | 24 | main_id = 1111 #id, your id or group id 25 | 26 | TOKEN = "####:##############" #token 27 | 28 | notallowed = "Forwarding is not allowed!" #Forwarding messages to bot is not allowed 29 | 30 | ## Bugs and PRs 31 | For any bug, create issue. Your issue will be reviewed. 32 | If you want to make pull request, you are welcome 33 | 34 | [Maintainer](https://t.me/coder2020) 35 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | #Hi. this is config file. YOU NEED TO EDIT ONLY THIS FILE. 2 | #Read instructions here: https://github.com/coder2020official/pyLivegramBot 3 | #Written by @coder2020 - telegram account. 4 | 5 | blocked = "bot was blocked by the user" 6 | start = "Hello! This is your start message!" 7 | ban = "you were banned by the admin!" 8 | unban = "you were unbanned by the admin." 9 | text_message = "Message that would be send if somebody writes any text" 10 | banned = "you are blocked" 11 | main_id = -1111 #id without quotes #can be group id REMEMBER!: SUPERGROUP ID BEGINS WITH MINUS 12 | TOKEN = "######:############" 13 | notallowed = "Do not forward me a message." -------------------------------------------------------------------------------- /connection.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | 3 | def create_db_new(): 4 | db = sqlite3.connect('users.db', check_same_thread=False) 5 | sql = db.cursor() 6 | sql.execute('''CREATE TABLE IF NOT EXISTS USERS( 7 | user_id INTEGER, 8 | first_name VARCHAR, 9 | messageid INT, 10 | message VARCHAR)''') 11 | sql.execute('''CREATE TABLE IF NOT EXISTS blocked( 12 | user_id INT)''') 13 | sql.execute('''CREATE TABLE IF NOT EXISTS user( 14 | user_id INT)''') 15 | sql.close() 16 | db.close() 17 | 18 | 19 | def database_query(query: str,spec_args): 20 | """Performs database commands. 21 | :params: 22 | query: str - this should be your command to be executed""" 23 | db = sqlite3.connect('users.db', check_same_thread=False) 24 | with db: 25 | sql = db.cursor() 26 | sql.execute(query,spec_args) 27 | result = sql.fetchall() 28 | if db: 29 | db.commit() 30 | sql.close() 31 | 32 | return result 33 | def database_query_spec(query: str): 34 | """Performs database commands. 35 | :params: 36 | query: str - this should be your command to be executed""" 37 | db = sqlite3.connect('users.db', check_same_thread=False) 38 | with db: 39 | sql = db.cursor() 40 | sql.execute(query) 41 | result = sql.fetchall() 42 | if db: 43 | db.commit() 44 | sql.close() 45 | 46 | return result 47 | -------------------------------------------------------------------------------- /content/other.py: -------------------------------------------------------------------------------- 1 | from connection import database_query 2 | import telebot 3 | import sqlite3 4 | import config 5 | bot = telebot.TeleBot(config.TOKEN) 6 | def other(message): 7 | try: 8 | if message.chat.id != config.main_id: 9 | if message.forward_from == None: 10 | get = database_query("SELECT user_id FROM blocked WHERE user_id = ?",(message.from_user.id,)) 11 | if get != []: 12 | bot.send_message(message.chat.id, config.banned) 13 | else: 14 | q = bot.forward_message(config.main_id, message.chat.id, message.message_id) 15 | database_query("INSERT OR IGNORE INTO USERS VALUES(?,?,?,?)",(message.from_user.id,message.from_user.first_name, q.message_id, message.text)) 16 | bot.send_message(message.chat.id, config.text_message) 17 | print(message.message_id) 18 | else: 19 | bot.send_message(message.chat.id, config.notallowed) 20 | elif message.chat.id == config.main_id: 21 | if message.reply_to_message is None: 22 | bot.forward_message(config.main_id, message.chat.id, message.message_id) 23 | database_query("INSERT OR IGNORE INTO USERS VALUES(?,?,?,?)",(message.from_user.id,message.from_user.first_name, message.message_id, message.text)) 24 | bot.send_message(message.chat.id, config.text_message) 25 | elif message.reply_to_message is not None: 26 | print(message.reply_to_message.message_id) 27 | get = database_query("SELECT user_id FROM USERS WHERE messageid = ?",(message.reply_to_message.message_id,)) 28 | for i in get: 29 | bot.copy_message(i[0],message.chat.id, message.message_id) 30 | except telebot.apihelper.ApiException: 31 | bot.send_message(message.chat.id, config.blocked) -------------------------------------------------------------------------------- /content/text.py: -------------------------------------------------------------------------------- 1 | from connection import database_query, database_query_spec 2 | import telebot 3 | import config 4 | bot = telebot.TeleBot(config.TOKEN) 5 | def text(message): 6 | try: 7 | get = database_query("SELECT user_id FROM blocked WHERE user_id = ?",(message.from_user.id,)) 8 | print(get) 9 | if get != []: 10 | bot.send_message(message.chat.id, config.banned) 11 | else: 12 | if message.chat.id != config.main_id: 13 | if message.forward_from == None: 14 | q = bot.forward_message(config.main_id, message.chat.id, message.message_id) 15 | database_query("INSERT OR IGNORE INTO USERS VALUES(?,?,?,?)",(message.from_user.id,message.from_user.first_name, q.message_id, message.text)) 16 | bot.send_message(message.chat.id, config.text_message) 17 | print(message.message_id) 18 | else: 19 | bot.send_message(message.chat.id, config.notallowed) 20 | elif message.chat.id == config.main_id: 21 | if message.reply_to_message is None: 22 | bot.forward_message(config.main_id, message.chat.id, message.message_id) 23 | database_query("INSERT INTO USERS VALUES(?,?,?,?)",(message.from_user.id,message.from_user.first_name, message.message_id, message.text)) 24 | bot.send_message(message.chat.id, config.text_message) 25 | elif message.reply_to_message is not None: 26 | print(message.reply_to_message.message_id) 27 | users = database_query("SELECT user_id FROM USERS WHERE messageid = ?",(message.reply_to_message.message_id,)) 28 | for i in users: 29 | print(i[0]) 30 | bot.send_message(i[0], message.text) 31 | except Exception as e: 32 | print(str(e)) 33 | bot.send_message(message.chat.id, config.blocked) -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import telebot #module for bots 2 | 3 | 4 | #some plugins that will be connected 5 | from plugins.ban import blocked 6 | from plugins.unban import unblocked 7 | from content.text import text 8 | from content.other import other 9 | from plugins.start import start 10 | from plugins.everyone_message import message_everyone 11 | 12 | 13 | #database connection and creation 14 | from connection import * 15 | create_db_new() 16 | 17 | 18 | #main file that registers all commands 19 | 20 | #config file 21 | import config 22 | 23 | 24 | #we use pytelegrambotapi library. 25 | bot = telebot.TeleBot(config.TOKEN) 26 | 27 | @bot.message_handler(commands=['start']) 28 | def start2(message): 29 | start(message) 30 | @bot.message_handler(commands=["ban"]) 31 | def bloc(message): 32 | blocked(message) 33 | @bot.message_handler(commands=["unban"]) 34 | def some(message): 35 | unblocked(message) 36 | @bot.message_handler(commands=["admin_message"]) 37 | def reklama(message): 38 | if message.chat.id == config.main_id: 39 | bot.send_message(message.chat.id, "your message to be sent: ") 40 | bot.register_next_step_handler(message, textrek) 41 | else: 42 | pass 43 | def textrek(message): 44 | message_everyone(message) 45 | @bot.message_handler(content_types=['text']) 46 | def tex(message): 47 | text(message) 48 | #photo #stikeri #video 49 | @bot.message_handler(content_types=['photo','sticker','video','audio','voice','location','animation','contact','document','dice','poll']) 50 | def other2(message): 51 | other(message) 52 | bot.polling(none_stop=True) -------------------------------------------------------------------------------- /plugins/ban.py: -------------------------------------------------------------------------------- 1 | from connection import database_query 2 | import config 3 | import sqlite3 4 | import telebot 5 | bot = telebot.TeleBot(config.TOKEN) 6 | def blocked(message): 7 | try: 8 | if message.chat.id == config.main_id: 9 | #fromm = str(message.from_user.id) 10 | #name = message.from_user.first_name 11 | get = database_query("SELECT user_id FROM USERS WHERE messageid = ?",(message.reply_to_message.message_id,)) 12 | for i in get: 13 | print(i[0]) 14 | get2 = database_query("SELECT user_id FROM blocked WHERE user_id = ?",(i[0],)) 15 | if get2 == []: 16 | bot.send_message(i[0],config.ban) 17 | bot.send_message(message.chat.id, "you blocked " + str(i[0])) 18 | database_query("INSERT INTO blocked VALUES (?)",(i[0],)) 19 | else: 20 | bot.send_message(message.chat.id, "you are not admin!") 21 | except Exception as ee: 22 | print("error in block" + str(ee)) -------------------------------------------------------------------------------- /plugins/everyone_message.py: -------------------------------------------------------------------------------- 1 | from connection import database_query, database_query_spec 2 | import telebot 3 | import config 4 | 5 | bot = telebot.TeleBot(config.TOKEN) 6 | def message_everyone(message): 7 | usrs = database_query_spec("SELECT user_id FROM user") 8 | for i in usrs: 9 | try: 10 | bot.copy_message(i[0],message.chat.id, message.message_id) 11 | except: 12 | print("error!!") -------------------------------------------------------------------------------- /plugins/start.py: -------------------------------------------------------------------------------- 1 | from connection import database_query 2 | import telebot 3 | import config 4 | import sqlite3 5 | bot = telebot.TeleBot(config.TOKEN) 6 | def start(message): 7 | try: 8 | bot.send_message(message.chat.id, config.start) 9 | info = database_query("SELECT user_id FROM user WHERE user_id = ?",(message.from_user.id,)) 10 | if info == []: 11 | database_query("INSERT INTO user VALUES(?)",(message.from_user.id,)) 12 | except Exception as e: 13 | print(str(e)) -------------------------------------------------------------------------------- /plugins/unban.py: -------------------------------------------------------------------------------- 1 | from connection import database_query 2 | import telebot 3 | import sqlite3 4 | import config 5 | bot = telebot.TeleBot(config.TOKEN) 6 | def unblocked(message): 7 | try: 8 | if message.chat.id == config.main_id: 9 | Lusers = database_query("SELECT user_id FROM USERS WHERE messageid = ?",(message.reply_to_message.message_id,)) 10 | for i in Lusers: 11 | print(str(i[0]) + " mine") 12 | get_blocked = database_query("SELECT user_id FROM blocked WHERE user_id = ?",(i[0],)) 13 | database_query("DELETE FROM blocked WHERE user_id = ?",(i[0],)) 14 | bot.send_message(i[0],"you were unblocked") 15 | bot.send_message(message.chat.id, "you unblocked " + str(i[0])) 16 | else: 17 | bot.send_message(message.chat.id, "you are not admin!") 18 | except Exception as ee: 19 | print("error in block" + str(ee)) --------------------------------------------------------------------------------