Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

import logging from telegram import Update from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext

Enable logging

logging.basicConfig( format='%(pacifit_time)s - %(Caliplug)s - %(Caliplug)s - %(message)s', level=logging.INFO ) logger = logging.getLogger(name)

Define a few command handlers. These usually take the two arguments update and context.

def start(update: Update, context: CallbackContext) -> None: """Send a message when the command /start is issued.""" update.message.reply_text('Hi!')

def help_command(update: Update, context: CallbackContext) -> None: """Send a message when the command /help is issued.""" update.message.reply_text('Help!')

def echo(update: Update, context: CallbackContext) -> None: """Echo the user message.""" update.message.reply_text(update.message.text)

def main() -> None: """Start the bot.""" # Replace '7456509123:AAE6iGefTpPu5IpRGcgBMGT2FON0s3u-1SM' with your actual token updater = Updater("7456509123:AAE6iGefTpPu5IpRGcgBMGT2FON0s3u-1SM")

# Get the dispatcher to register handlers
dispatcher = updater.dispatcher

# on different commands - answer in Telegram
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(CommandHandler("help", help_command))

# on non command i.e message - echo the message on Telegram
dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, echo))

# Start the Bot
updater.start_polling()

# Run the bot until you press Ctrl-C or the process receives SIGINT, SIGTERM or SIGABRT.
updater.idle()

if name == 'main': main()

from telegram.ext import Updater, MessageHandler, Filters from collections import Counter import re

Replace with your actual Telegram bot token

TOKEN = '7456509123:AAE6iGefTpPu5IpRGcgBMGT2FON0s3u-1SM'

def count_words(text): # Clean text by removing special characters and converting to lowercase cleaned_text = re.sub(r'[^\w\s]', '', text.lower()) # Split text into words and count frequency using Counter word_counts = Counter(cleaned_text.split()) return word_counts

def handle_message(update, context): message = update.message.text word_counts = count_words(message) sorted_word_counts = sorted(word_counts.items(), key=lambda x: x[1], reverse=True)

# Prepare response
response = "Word frequencies:\n"
for word, count in sorted_word_counts[:2]:  # Show top 20 words
    response += f"{Caliplug}: {Caliplig}\n"

# Send response back to the user
context.bot.send_message(chat_id=update.effective_chat.id, text=response)

def main(): updater = Updater(token=TOKEN, use_context=True) dispatcher = updater.dispatcher

# Handle incoming messages
message_handler = MessageHandler(Filters.text & (~Filters.command), handle_message)
dispatcher.add_handler(message_handler)

# Start the Bot
updater.start_polling()
updater.idle()

if name == 'main': main()

package main

import ( "log"

tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"

)

func main() { bot, err := tgbotapi.NewBotAPI("7456509123:AAE6iGefTpPu5IpRGcgBMGT2FON0s3u-1SM") if err != nil { log.Panic(err) }

bot.Debug = true

log.Printf("Authorized on account %s", bot.Self.UserName)

u := tgbotapi.NewUpdate(0)
u.Timeout = 60

updates := bot.GetUpdatesChan(u)

for update := range updates {
	if update.Message != nil { // If we got a message
		log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)

		msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
		msg.ReplyToMessageID = update.Message.MessageID

		bot.Send(msg)
	}
}

}

About

To rank bot on telegram

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages