| | import os |
| |
|
| |
|
| | TELEGRAM_TEMPLATE = """""" |
| | import os |
| | import logging |
| | from telegram import Update |
| | from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes |
| |
|
| | TOKEN = os.getenv("TELEGRAM_TOKEN") |
| |
|
| | async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): |
| | await update.message.reply_text("Hello! I'm your assistant bot.") |
| |
|
| | async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE): |
| | await update.message.reply_text(update.message.text) |
| |
|
| | def main(): |
| | if not TOKEN: |
| | raise RuntimeError("Set TELEGRAM_TOKEN env var") |
| | app = Application.builder().token(TOKEN).build() |
| | app.add_handler(CommandHandler("start", start)) |
| | app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo)) |
| | app.run_polling() |
| |
|
| | if __name__ == "__main__": |
| | main() |
| | """""" |
| |
|
| |
|
| | DISCORD_TEMPLATE = """""" |
| | import os |
| | import discord |
| |
|
| | TOKEN = os.getenv("DISCORD_TOKEN") |
| | intents = discord.Intents.default() |
| | intents.message_content = True |
| | client = discord.Client(intents=intents) |
| |
|
| | @client.event |
| | async def on_ready(): |
| | print(f"Logged in as {client.user}") |
| |
|
| | @client.event |
| | async def on_message(message: discord.Message): |
| | if message.author == client.user: |
| | return |
| | if message.content.startswith("!ping"): |
| | await message.channel.send("pong") |
| |
|
| | def main(): |
| | if not TOKEN: |
| | raise RuntimeError("Set DISCORD_TOKEN env var") |
| | client.run(TOKEN) |
| |
|
| | if __name__ == "__main__": |
| | main() |
| | """""" |
| |
|
| |
|
| | def create_bot(bot_type: str, output_dir: str = "bots") -> str: |
| | os.makedirs(output_dir, exist_ok=True) |
| | if bot_type == "telegram": |
| | path = os.path.join(output_dir, "telegram_bot.py") |
| | with open(path, "w", encoding="utf-8") as f: |
| | f.write(TELEGRAM_TEMPLATE) |
| | return path |
| | elif bot_type == "discord": |
| | path = os.path.join(output_dir, "discord_bot.py") |
| | with open(path, "w", encoding="utf-8") as f: |
| | f.write(DISCORD_TEMPLATE) |
| | return path |
| | else: |
| | raise ValueError("Unsupported bot_type. Use 'telegram' or 'discord'.") |