Snippets Collections
const [touchStart, setTouchStart] = useState(null)
const [touchEnd, setTouchEnd] = useState(null)

// the required distance between touchStart and touchEnd to be detected as a swipe
const minSwipeDistance = 50 

const onTouchStart = (e) => {
  setTouchEnd(null) // otherwise the swipe is fired even with usual touch events
  setTouchStart(e.targetTouches[0].clientX)
}

const onTouchMove = (e) => setTouchEnd(e.targetTouches[0].clientX)

const onTouchEnd = () => {
  if (!touchStart || !touchEnd) return
  const distance = touchStart - touchEnd
  const isLeftSwipe = distance > minSwipeDistance
  const isRightSwipe = distance < -minSwipeDistance
  if (isLeftSwipe || isRightSwipe) console.log('swipe', isLeftSwipe ? 'left' : 'right')
  // add your conditional logic here
}
import json

user_info_file_path = 'userinfo.json'

def save_user_info(chat_id, user_id, first_name, last_name, username):
    # Load existing user information from the file
    user_info = load_user_info()

    # Add or update user information
    user_info[user_id] = {
	"user_id": user_id,
	"username": username,
    "chat_id": chat_id,
    "first_name": first_name,
    "last_name": last_name
    }

    # Save the updated user information back to the file
    with open(user_info_file_path, 'w') as file:
        json.dump(user_info, file)

def load_user_info():
    try:
        # Load user information from the file
        with open(user_info_file_path, 'r') as file:
            return json.load(file)
    except FileNotFoundError:
        # If the file doesn't exist yet, return an empty dictionary
        return {}
import json
from telegram import Update
from telegram.ext import CallbackContext

def append_user_info_to_json(update: Update, context: CallbackContext, file_path='users.json'):
    user_info = {
        'chat_id': update.effective_chat.id,
        'first_name': update.effective_chat.first_name,
        'last_name': update.effective_chat.last_name,
        'username': update.effective_chat.username
    }

    try:
        # Load existing data
        with open(file_path, 'r') as file:
            data = json.load(file)
    except FileNotFoundError:
        # If the file doesn't exist, start a new list
        data = []

    # Append new data
    data.append(user_info)

    # Write updated data back to file
    with open(file_path, 'w') as file:
        json.dump(data, file, indent=4)


def start(update: Update, context: CallbackContext) -> None:
    # Append user info to JSON
    append_user_info_to_json(update, context)
import os
import telebot
import main
from dotenv import load_dotenv
load_dotenv()

API_KEY = os.environ.get('TELEGRAM_API_KEY')
bot = telebot.TeleBot(
    API_KEY, parse_mode=None)


@bot.message_handler(commands=['start', 'help'])
def greet(message):
    bot.reply_to(message, "Hey My G")


@bot.message_handler(commands=['btc', 'BTC', 'bitcoin', 'BITCOIN'])
def prices(message):
    bot.reply_to(message, main.get_cmc_data('BTC'))


@bot.message_handler(commands=['eth', 'ETH', 'ethereum', 'ETHEREUM'])
def prices(message):
    bot.reply_to(message, main.get_cmc_data('ETH'))


@bot.message_handler(commands=['wagmi', 'WAGMI'])
def prices(message):
    bot.reply_to(message, main.get_cmc_data('WAGMI'))


bot.polling()
print("bot running...")
star

Sun Mar 24 2024 16:58:51 GMT+0000 (Coordinated Universal Time)

#telegram #bot #user #info #collect #store #json
star

Thu Nov 16 2023 23:25:54 GMT+0000 (Coordinated Universal Time)

#telegram #bot #user #info #collect #store #json
star

Thu Nov 16 2023 23:23:40 GMT+0000 (Coordinated Universal Time)

#telegram #bot #user #info #collect #store #json
star

Mon Mar 28 2022 18:27:30 GMT+0000 (Coordinated Universal Time) https://www.youtube.com/watch?v=NwBWW8cNCP4

#python #telegram #bot

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension