import asyncio
import argparse
from urllib.parse import urlparse
from twitchio.ext import commands

class TwitchBot(commands.Bot):
    def __init__(self, token, client_id, nick, prefix, initial_channels):
        super().__init__(token=token, client_id=client_id, nick=nick, prefix=prefix, initial_channels=initial_channels)
        self.message_to_send = None

    async def event_ready(self):
        print(f"Connecté en tant que {self.nick}")
        if self.message_to_send:
            channel = self.get_channel(self.initial_channels[0])
            if channel:
                await channel.send(self.message_to_send)
                print("Message envoyé avec succès.")
            await self.close()

async def send_message_with_twitchio(token, client_id, nick, channel, message):
    bot = TwitchBot(
        token=token,
        client_id=client_id,
        nick=nick,
        prefix="!",
        initial_channels=[channel]
    )
    bot.message_to_send = message
    await bot.run()

async def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-pseudo', type=str, required=True, help='Pseudo name account')
    parser.add_argument('-token', type=str, required=True, help='Token oauth')
    parser.add_argument('-message', type=str, required=True, help='Message to send')
    parser.add_argument('-twitchname', type=str, required=True, help='Twitch channel name')
    args = parser.parse_args()

    # Vous devrez obtenir un client_id depuis https://dev.twitch.tv/console
    client_id = "your_client_id_here"  # Remplacez par votre client_id
    
    await send_message_with_twitchio(
        token=args.token,
        client_id=client_id,
        nick=args.pseudo,
        channel=args.twitchname,
        message=args.message
    )

if __name__ == "__main__":
    asyncio.run(main()) 