From ee4261755d3c8a16f78e8a9a646ccbee5dbc1661 Mon Sep 17 00:00:00 2001 From: JKuijperM Date: Thu, 5 Jan 2023 15:04:40 +0100 Subject: [PATCH] Initial commit adding the test code --- .gitignore | 1 + Pipfile | 13 +++++++++++++ bot.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 Pipfile create mode 100644 bot.py diff --git a/.gitignore b/.gitignore index b6e4761..3c7d1ac 100644 --- a/.gitignore +++ b/.gitignore @@ -109,6 +109,7 @@ venv/ ENV/ env.bak/ venv.bak/ +.idea # Spyder project settings .spyderproject diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..edba2a8 --- /dev/null +++ b/Pipfile @@ -0,0 +1,13 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +twitchio = "*" + +[dev-packages] + +[requires] +python_version = "3.10" +python_full_version = "3.10.8" diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..89676ec --- /dev/null +++ b/bot.py @@ -0,0 +1,42 @@ +import os +from twitchio.ext import commands + + +class Bot(commands.Bot): + + def __init__(self): + super().__init__(token=os.environ['TMI_TOKEN'], + # client_id=os.environ['CLIENT_ID'], + nick=os.environ['BOT_NICK'], + prefix=os.environ['BOT_PREFIX'], + initial_channels=[os.environ['CHANNEL']]) + + async def event_ready(self): + # We are logged in and ready to chat and use commands... + print(f'Logged in as | {self.nick}') + print(f'User id is | {self.user_id}') + await bot.connected_channels[0].send('/me El brujero ha llegado!') + + async def event_message(self, message): + # Messages with echo set to True are messages sent by the bot... + # For now we just want to ignore them... + if message.echo: + return + + # Print the contents of our message to console... + print(message.content) + + # Since we have commands and are overriding the default `event_message` + # We must let the bot know we want to handle and invoke our commands... + await self.handle_commands(message) + + @commands.command() + async def hello(self, ctx: commands.Context): + # Send a hello back! + await ctx.send('Hello world') + + +if __name__ == "__main__": + bot = Bot() + bot.run() +