| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
BeneSim is a very simple and thus pretty easy to use python twitch bot. The code is quite ugly, but it does what it's supposed to do. The main purpose of the bot is to respond to trigger phrases. For example say you want a bot that posts a link to your discord server everytime a user uses the keyword discord in his message. This can be accomplished with the following code
def discordCommand(bot, nickname, channel, args, message):
bot.sendMessage(channel, "Join my discord server at http://foo.bar")
bot.addCommand(discordCommand, "discord", starts_with=False, case_sensitive=False)Actually no installation required, it's just a simple python module, just use it right away or import it into your own module. I may add a setup.py in the future though.
Let's start with the initialization first. You can use it inside your module
from benebot import Botor simply use the module itself
if __name__ == "__main__":
bot = Bot(username="botusername", password="oauth:botpassword", channels=(("#foo", 20), ("#bar", 20)))Alright, username and password should be self-explanatory. channels must be an iterable, e.g. a list or tuple, in this case I used a tuple. Each entry of the tuple contains the channelname and the message limit and must be a iterable, too. In this case I want to joint the channel #foo with a message limit of 20 and the channel #bar with a message limit of 20. The message limit is the total number of messages that can be send to the specific channel within a time frame of 30 seconds. You may get an 8h IP ban if you send more messages than you are allowed to.
Now let's define a command. All commands need a function that gets called once the command gets triggered.
def exampleCommand(bot, nickname, channel, args):
bot.sendMessage(channel, "Command called by {} in channel {} with arguments {}".format(nickname, channel, args))The signature of the command functions must always be as shown above. The individual parameters will be supplied by the bot once the command triggers:
Now that we have the desired functionality inside the command function lets add it to the bot.
bot.addCommand(function=exampleCommand, trigger="example", nicknames=None, channels=None, case_sensitive=False, starts_with=True, cooldown=None)OK, lets go over all those parameters:
The bot will now call the function exampleCommand everytime a user writes example or ExAmple, etc. at the beginning of a message.
Finnaly we need to start the bot.
bot.connect()
bot.run()A minimal working example should look like this
from benebot import Bot
def exampleCommand(bot, nickname, channel, args, message):
bot.sendMessage(channel, "Command called by {} in channel {} with arguments {}".format(nickname, channel, args))
if __name__ == "__main__":
bot = Bot(username="botusername", password="oauth:botpassword", channels=(("#foo", 20), ("#bar", 20)))
bot.addCommand(function=exampleCommand, trigger="example", nicknames=None, channels=None, case_sensitive=False, starts_with=True, cooldown=None)
bot.connect()
bot.run()Important: BeneBot uses blocking sockets! A bot using asyncio for asynchronous networking may follow.
I hope this tutorial will help get you started. Have a look at the module itself, atleast the user-code part contains some documentation.
| Back | FazBrowse Home | New Git URL |