-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
219 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🤖</text></svg>"> | ||
|
||
<title>Telegram Bot Generator</title> | ||
<link rel="stylesheet" href="../styles.css"> | ||
|
||
</head> | ||
<body> | ||
|
||
<div class="container"> | ||
<h2>Telegram Bot Generator by @oopshnik</h2> | ||
<h3>Repo: <a href="https://github.com/oopshnik/bot_template">github.com/oopshnik/bot_template</a><br> | ||
Console version avaible at <a href="https://github.com/oopshnik/bot_template">Github</a><br> | ||
Template also avaible at <a href="https://github.com/oopshnik/bot_template">Github</a>. | ||
</h3> | ||
|
||
<input type="text" id="apiToken" placeholder="Enter your API Token" required> | ||
<input type="text" id="botName" placeholder="Enter Bot Name" value="MyBot"> | ||
<section class="intro"> | ||
<h1>How to Setup a bot</h1> | ||
<h3> | ||
<br> Go to <a href="https://t.me/BotFather">@BotFather</a> | ||
<br> Then type /newbot command | ||
<br> Choice Bot`s Displayname and Username | ||
<br> Then copy API-TOKEN to API_TOKEN Variable | ||
<br> Replace code with that you need | ||
<br> Run your code | ||
<br> That`s all | ||
</h3> | ||
</section> | ||
<textarea id="commands" placeholder="Enter custom commands (Format: command:description)" rows="5"></textarea> | ||
|
||
<label for="enableLogging">Enable Logging?</label> | ||
<select id="enableLogging"> | ||
<option value="yes">Yes</option> | ||
<option value="no">No</option> | ||
</select> | ||
|
||
<label for="loggingLevel">Logging Level</label> | ||
<select id="loggingLevel"> | ||
<option value="INFO">INFO</option> | ||
<option value="DEBUG">DEBUG</option> | ||
<option value="WARNING">WARNING</option> | ||
<option value="ERROR">ERROR</option> | ||
</select> | ||
|
||
<button onclick="generateBot()">Generate Bot</button> | ||
</div> | ||
|
||
<script> | ||
function generateBot() { | ||
const apiToken = document.getElementById('apiToken').value; | ||
const botName = document.getElementById('botName').value; | ||
const commandsText = document.getElementById('commands').value; | ||
const enableLogging = document.getElementById('enableLogging').value === 'yes'; | ||
const loggingLevel = document.getElementById('loggingLevel').value; | ||
|
||
const customCommands = commandsText | ||
.split('\n') | ||
.map(line => line.split(':')) | ||
.filter(parts => parts.length === 2) | ||
.map(parts => [parts[0].trim(), parts[1].trim()]); | ||
|
||
const code = generateBotCode(apiToken, botName, customCommands, enableLogging, loggingLevel); | ||
|
||
const blob = new Blob([code], { type: 'text/x-python' }); | ||
const link = document.createElement('a'); | ||
link.href = URL.createObjectURL(blob); | ||
link.download = `${botName.toLowerCase().replace(/ /g, '_')}.py`; | ||
link.click(); | ||
} | ||
|
||
function generateBotCode(apiToken, botName, customCommands, enableLogging, loggingLevel) { | ||
const loggingSetup = enableLogging ? ` | ||
# Logging configuration | ||
logging.basicConfig( | ||
level=logging.${loggingLevel.toUpperCase()}, | ||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | ||
filename='${botName.toLowerCase()}_bot.log', | ||
filemode='a' | ||
) | ||
logger = logging.getLogger(__name__) | ||
` : "logger = None"; | ||
|
||
const commandsCode = customCommands.map(([command, desc]) => ` | ||
@bot.message_handler(commands=['${command}']) | ||
def ${command}(message): | ||
${enableLogging ? `logger.info(f"User {message.from_user.id} requested ${command}")` : ''} | ||
bot.reply_to(message, "${desc}") | ||
`).join('\n'); | ||
|
||
return ` | ||
import os | ||
import telebot | ||
import logging | ||
${loggingSetup} | ||
API_TOKEN = '${apiToken}' | ||
bot = telebot.TeleBot(API_TOKEN) | ||
@bot.message_handler(commands=['start']) | ||
def welcome(message): | ||
${enableLogging ? `logger.info(f"User {message.from_user.id} started the bot")` : ''} | ||
bot.reply_to(message, f"Welcome {message.from_user.first_name}! Use /help to see available commands.") | ||
@bot.message_handler(commands=['help']) | ||
def help(message): | ||
${enableLogging ? `logger.info(f"User {message.from_user.id} requested help")` : ''} | ||
help_message = "Available commands:\\n" + "\\n".join([ | ||
"/{0} - {1}".format(cmd, desc) for cmd, desc in ${JSON.stringify(customCommands)} | ||
]) | ||
bot.reply_to(message, help_message) | ||
${commandsCode} | ||
@bot.message_handler(func=lambda message: True) | ||
def echo_all(message): | ||
${enableLogging ? `logger.info(f"Received message: {message.text}")` : ''} | ||
bot.reply_to(message, "I don't understand that command. Use /help.") | ||
if __name__ == '__main__': | ||
${enableLogging ? `logger.info("${botName} bot started")` : ''} | ||
try: | ||
bot.polling(none_stop=True) | ||
except Exception as e: | ||
${enableLogging ? `logger.error(f"Error: {e}")` : ''} | ||
finally: | ||
${enableLogging ? `logger.info("${botName} bot stopped")` : ''} | ||
`; | ||
} | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters