Package: aptbot
aptbotA chatbot for twitch.tvDependenciesPython (any >=3.7 version should work)python-dotenvurllib3InstallIt is highly recommended you install and run aptbot in a virtual environment.Clone this repositorygit clone https://github.com/atheridis/aptbot.git,
change to the directorycd aptbot, then install the packagepip install ..First StepsAdding an accountAfter installing, you can add an account usingaptbot --add-account "account_name".
A directory will be created in~/.config/aptbot/on Linux
or%APPDATA%\aptbot\accounts\on Windows with the twitch name of that account.Each account directory should contain amain.pyfile
with the most minimal code being:fromaptbotimportBot,Message,Commands# Runs at the beginning, when the account connects.# Can be used for an infinite loop within the account,# so the bot can send messages, even when chat isn't moving.defstart(bot:Bot,message:Message,stop_event):pass# Gets ran every time the IRC channel sends a message.# This can either be a message from a user# a raid, when a mod deletes a message, etc.defmain(bot:Bot,message:Message):passWhen you add an account usingaptbot --add-account "account_name"oraptbot -a "account_name",
the following python file calledmain.pywill be created:importtimefromthreadingimportEventfromaptbotimportBot,Commands,Message# Starts when the bot is enabled# Sends the message "Hello, world!" every 2 minutes to the channel# stop_event is set to True, when you disable the account with aptbot -d "account_name"defstart(bot:Bot,message:Message,stop_event:Event):whilenotstop_event.is_set():bot.send_message(message.channel,"Hello, world!")time.sleep(120)defmain(bot:Bot,message:Message):# Check whether the message sent is a message by a user in chat# and not some notification.ifmessage.command==Commands.PRIVMSG:# Check the content of the message and if the first word is '!hello'# send a reply by creating a new thread.# You can also use `message.nick` instead of `message.tags['display-name']`# but then the message sent back# will contain the name of the user in all lowercaseifmessage.value.split()[0]=="!hello":bot.send_message(message.channel,f"hello{message.tags['display-name']}",reply=message.tags["id"],)Activating your botOnce you have an account set up you can enable the bot by usingaptbot --enable.
To stop the bot from running useaptbot --disableon another terminal.After testing you would want to runaptbot --enableas a daemon, the easiest way
to do that on Linux is to usenohup aptbot --enable &. This will leave anohup.outfile in the directory you're in, which may not be ideal. If you wish to have no output
other than the logs provided in~/.cache/aptbot/logs/aptbot.logyou may usenohup aptbot --enable </dev/null >/dev/null 2>&1 &. You are now free to control
aptbot through any terminal. Typeaptbot --helpto see all available commands.More than one fileYou can import modules from the same directory that themain.pyfiles are in,
but if you wantaptbot --updateto work on them you will need to reload the modules
due to how python handles module imports. Some examples will be coming soon.BUGSEditing any of the directory names in~/.config/aptbot/or%APPDATA%\aptbot\accounts\while the bot is running, may cause weird behaviour.