GithubHelp home page GithubHelp logo

telegrambot's Introduction

Hi 👋, I'm Andrian | a.k.a andr1an0lv

CyberSecurity student and CTF player

gif

redl1k


🌐 Socials:


👨‍💻 CTFtime Profile

🌱 Instagram

📫 Telegram

YouTube

📃 HackMD

telegrambot's People

Stargazers

 avatar

Watchers

 avatar

telegrambot's Issues

InlineKeyboardMarkup

#Используемая библиотека
import telebot
from telebot import types

@bot.message_handler(commands=['start', 'старт'])
def get_user_start(message):
markup_inline = types.InlineKeyboardMarkup()
item_yes = types.InlineKeyboardButton(text='Да!', callback_data='yes')#кнопка с текстом Да!, к которой мы привязали команду #yes
item_no = types.InlineKeyboardButton(text='No', callback_data='no')#кнопка с текстом No, к которой мы привязали команду #no
markup_inline.add(item_yes, item_no)#Добавляем кнопки в место, где у нас клавиатура
bot.send_message(message.from_user.id, 'Ты готов?', #Текст отправляемый ботом
reply_markup=markup_inline
)

Connect to DB

#Libraries
import sqlite3
import telebot

#Работа с бд
connect = sqlite3.connect('users.db')#Users.db это файл, в которой будут сохранятся все следующие регистрации в боте
cursor = connect.cursor()#Подсоединение к бд
cursor.execute("""CREATE TABLE IF NOT EXISTS login_id( #Создание таблицы в бд
id INTEGER
)""")
connect.commit()

#Проверка на существование в бд этого айди
people_id = message.chat.id
cursor.execute(f"SELECT id FROM login_id WHERE id = {people_id}")
data = cursor.fetchone()
if data is None:

#Добавление значения в поля
bot.send_message(message.from_user.id, 'Давай познакомимся!\nКак тебя зовут?')
bot.register_next_step_handler(message, reg_name)
user_id = [message.chat.id]
cursor.execute("INSERT INTO login_id VALUES(?);", user_id)
connect.commit()

#Если найден пользователь, вывести следующие:
else:
bot.send_message(message.chat.id, 'Такой пользователь уже существует')

Multi-level button in the keyboard

import telebot
from telebot import types

bot=telebot.TeleBot("token")

@bot.message_handler(content_types=['text'])
def inline_key(a):
if a.text == "Inline_menu":
mainmenu = types.InlineKeyboardMarkup()
key1 = types.InlineKeyboardButton(text='Кнопка 1', callback_data='key1')
key2 = types.InlineKeyboardButton(text='Кнопка 2', callback_data='key2')
mainmenu.add(key1, key2)
bot.send_message(a.chat.id, 'Это главное меню!', reply_markup=mainmenu)

@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
if call.data == "mainmenu":
mainmenu = types.InlineKeyboardMarkup()
key1 = types.InlineKeyboardButton(text='Кнопка 1', callback_data='key1')
key2 = types.InlineKeyboardButton(text='Кнопка 2', callback_data='key2')
mainmenu.add(key1, key2)
bot.edit_message_reply_markup(call.message.chat.id, call.message.message_id, reply_markup=mainmenu)
elif call.data == "key1":
next_menu = types.InlineKeyboardMarkup()
key3 = types.InlineKeyboardButton(text='Кнопка 3', callback_data='key3')
back = types.InlineKeyboardButton(text='Назад', callback_data='mainmenu')
next_menu.add(key3, back)
bot.edit_message_text('Это меню уровня 2, для кнопки1!', call.message.chat.id, call.message.message_id,
reply_markup=next_menu)
elif call.data == "key2":
next_menu2 = types.InlineKeyboardMarkup()
key4 = types.InlineKeyboardButton(text='Кнопка 4', callback_data='key4')
back = types.InlineKeyboardButton(text='Назад', callback_data='mainmenu')
next_menu2.add(key4, back)
bot.edit_message_text('Это меню уровня 2, для кнопки2!', call.message.chat.id, call.message.message_id,
reply_markup=next_menu2)

bot.polling()

Markup

#import Libraries
import telebot
from telebot import types

bot = telebot.TeleBot('UR_Token')

@bot.message_handler(commands=['Function'])
def dnevnik(message):
if message.text == '/Function':
markup_inline = types.InlineKeyboardMarkup()
item_profile = types.InlineKeyboardButton(text='Profile', callback_data='Function')
markup_inline.add(item_Function)
bot.reply_to(message, "Нажми на кнопку\n"
"И выбери что тебя интересует)",
reply_markup=markup_inline)

bot.polling()

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.