# if you have any questions concerning the bot, you can contact me in my discord server: https://discord.gg/PXrKVHp OR [r/pythontwitchbot](https://www.reddit.com/r/pythontwitchbot/) on reddit
if you would like to send a few dollars my way you can do so
here: [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9ZVUE7CR24738)
this bot is also on PYPI: https://pypi.org/project/PythonTwitchBotFramework/
install from pip: `pip install PythonTwitchBotFramework`
# PythonTwitchBotFramework
fully async twitchbot framework/library compatible with python 3.6+
### how to stop the bot
to stop the bot running, do any of these commands:
`!shutdown` `!stop` or `!s` in the twitch chat of the channel its in, this command tries to properly shutdown all the
tasks the bot is currently running and gives time to stop/cancel
these commands requires the caller have permission to execute them
# Quick Links
* [Quick Start](#quick-start)
* [Overriding Events](#overriding-events)
* [Overriding Events On Mods](#overriding-events-on-mods)
* [Adding Commands](#adding-commands)
* [SubCommands](#subcommands)
* [DummyCommands](#dummycommands)
* [Permissions](#permissions)
* [Using Chat Commands](#managing-permissions-using-chat-commands)
* [Editing The Config](#managing-permission-by-editing-the-configs)
* [Reloading Permissions](#reloading-permissions)
* [Command Server](#command-server)
* [Command Console](#command-console)
* [Mysql Support](#mysql-support)
* [Command Whitelist](#command-whitelist)
* [Twitch PubSub Client](#twitch-pubsub-client)
# basic info
This is a fully async twitch bot framework complete with:
* builtin command system using decorators
* overridable events (message received, whisper received, ect)
* full permission system that is individual for each channel
* message timers
* quotes
* custom commands
* builtin economy
there is also mod system builtin to the bot, there is a collection of pre-made mods
here: [MODS](https://github.com/sharkbound/twitch_bot_mods)
# Quick Start
for a reference for builtin command look at the
wiki [HERE](https://github.com/sharkbound/PythonTwitchBotFramework/wiki/Builtin_Command_Reference)
the minimum code to get the bot running is this:
```python
from twitchbot.bots import BaseBot
if __name__ == '__main__':
BaseBot().run()
```
this will start the bot.
if you have a folder with your own custom commands you can load the .py files in it with:
```python
from twitchbot import BaseBot, load_commands_from_directory
if __name__ == '__main__':
load_commands_from_directory('PATH/TO/DIRECTORY')
BaseBot().run()
```
# Overriding Events
the bots events are overridable via the following 2 ways:
## using decorators:
```python
from twitchbot import event_handler, Event, Message
@event_handler(Event.on_privmsg_received)
async def on_privmsg_received(msg: Message):
print(f'{msg.author} sent message {msg.content} to channel {msg.channel_name}')
```
## subclassing BaseBot
```python
from twitchbot import BaseBot, Message
class MyCustomTwitchBot(BaseBot):
async def on_privmsg_received(self, msg: Message):
print(f'{msg.author} sent message {msg.content} to channel {msg.channel_name}')
```
then you would use MyCustomTwitchBot instead of BaseBot:
```python
MyCustomTwitchBot().run()
```
## Overriding Events On Mods
Visit [***the mods wiki page***](https://github.com/sharkbound/PythonTwitchBotFramework/wiki/Mods#index)
on this repo's wiki to view how to do it via Mods
* all overridable events are:
#### when using the decorator event override way, `self` is not included, ex: `(self, msg: Message)` becomes: `(msg: Message)`
```python
from twitchbot import Event
Event.on_connected: (self)
Event.on_permission_check: (self, msg
: Message, cmd: Command) -> bool # return False to deny permission to execute the cmd
Event.on_after_command_execute: (self, msg: Message, cmd: Command)
Event.on_before_command_execute: (self, msg: Message, cmd: Command) -> bool # return False to cancel command
Event.on_bits_donated: (self, msg: Message, bits: int)
Event.on_channel_raided: (self, channel: Channel, raider: str, viewer_count: int)
Event.on_channel_joined: (self, channel: Channel)
Event.on_channel_subscription: (self, subscriber: str, channel: Channel, msg: Message)
Event.on_privmsg_received: (self, msg: Message)
Event.on_privmsg_sent: (self, msg: str, channel: str, sender: str)
Event.on_whisper_received: (self, msg: Message)
Event.on_whisper_sent: (self, msg: str, receiver: str, sender: str)
Event.on_raw_message: (self, msg: Message)
Event.on_user_join: (self, user: str, channel: Channel)
Event.on_user_part: (self, user: str, channel: Channel)
Event.on_mod_reloaded: (self, mod: Mod)
Event.on_channel_points_redemption: (self, msg: Message, reward: str)
Event.on_bot_timed_out_from_channel: (self, msg: Message, channel: Channel, seconds: int)
Event.on_bot_banned_from_channel: (self, msg: Message, channel: Channel)
Event.on_poll_started: (self, channel: Channel, poll: PollData)
Event.on_poll_ended: (self, channel: Channel, poll: PollData)
Event.on_pubsub_received: (self, raw: 'PubSubData')
Event.on_pubsub_custom_channel_point_reward: (self, raw: 'PubSubData', data: 'PubSubPointRedemption')
Event.on_pubsub_bits: (self, raw: 'PubSubData', data: 'PubSubBits')
Event.on_pubsub_moderation_action: (self, raw: 'PubSubData', data: 'PubSubModerationAction')
Event.on_pubsub_subscription: (self, raw: 'PubSubData', data: 'PubSubSubscription')
Event.on_bot_shutdown: (self)
```
if this is the first time running the bot it will generate a folder named `configs`.
inside is `config.json` which you put the authentication into
as the bot is used it will also generate channel permission files in the `configs` folder
# Adding Commands
to register your own commands use the Command decorator:
* using decorators
```python
from twitchbot import Command
@Command('COMMAND_NAME')
async def cmd_function(msg, *args):
await msg.reply('i was called!')
```
* you can also limit the commands to be whisper or channel chat only
(default is channel chat only)
```python
from twitchbot import Command, CommandContext
# other options are CommandContext.BOTH and CommandContext.WHISPER
@Command('COMMAND_NAME', context=CommandContext.CHANNEL) # this is the default command context
async def cmd_function(msg, *args):
await msg.reply('i was called!')
```
* you can also specify if a permission is required to be able to call the command (if no permission is specified anyone
can call the command):
```python
from twitchbot import Command
@Command('COMMAND_NAME', permission='PERMISSION_NAME')
async def cmd_function(msg, *args):
await msg.reply('i was called!')
```
* you can also specify a help/syntax for the command for the help chat command to give into on it:
```python
from twitchbot import Command, Message
@Command('COMMAND_NAME', help='this command does a very important thing!', syntax='<name>')
async def cmd_function(msg: Message, *args):
await msg.reply('i was called!')
```
so when you do `!help COMMAND_NAME`
it will this in chat:
```
help for "!command_name",
syntax: "<name>",
help: "this command does a very important thing!"
```
* you can add aliases for a command (other command names that refer to the same command):
```python
from twitchbot import Command, Message
@Command('COMMAND_NAME',
help='this command does a very important thing!',
syntax='<name>',
aliases=['COMMAND_NAME_2', 'COMMAND_NAME_3'])
async def cmd_function(msg: Message, *args):
await msg.reply('i was called!')
```
`COMMAND_NAME_2` and `COMMAND_NAME_2` both re
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
PyPI 官网下载 | PythonTwitchBotFramework-1.17.0.tar.gz (103个子文件)
setup.cfg 42B
MANIFEST.in 15B
README.md 24KB
PKG-INFO 29KB
PKG-INFO 29KB
basebot.py 16KB
currency_commands.py 15KB
modloader.py 13KB
message.py 13KB
command.py 12KB
client.py 9KB
config.py 8KB
irc.py 8KB
permission.py 7KB
timer_commands.py 6KB
twitch_api_util.py 5KB
polldata.py 5KB
models.py 5KB
message_timer.py 5KB
replywaiter.py 5KB
poll_commands.py 4KB
permission_commands.py 4KB
tags.py 4KB
custom_commands.py 4KB
point_redemption_model.py 4KB
cmd_management_commands.py 4KB
channel.py 3KB
mod_management_commands.py 3KB
duel.py 3KB
currency.py 3KB
event_util.py 3KB
models.py 3KB
chatters.py 3KB
quote_commands.py 3KB
quotes.py 2KB
command_util.py 2KB
command_server.py 2KB
arena.py 2KB
cached_property.py 2KB
subscription_model.py 2KB
disabled_mods.py 2KB
misc_commands.py 2KB
ratelimit.py 2KB
bits_model.py 2KB
enums.py 2KB
streaminfoapi.py 2KB
fun_commands.py 2KB
commands.py 2KB
task_util.py 2KB
regex.py 1KB
reply_waiter_mod.py 1KB
__init__.py 1KB
command_whitelist.py 1KB
events.py 1KB
userinfoapi.py 1KB
misc_util.py 1KB
disabled_commands.py 1KB
pubsub_moderation_action.py 1KB
getpassgui.py 1KB
whisper_model.py 1KB
debug_commands.py 1004B
session.py 997B
message_util.py 979B
loyalty_ticker.py 976B
baseapi.py 872B
command_console.py 870B
dict_util.py 836B
user_followers.py 825B
exceptions.py 807B
setup.py 768B
shared.py 753B
register_util.py 728B
emote.py 551B
poll_announcer_mod.py 535B
timer_auto_start_mod.py 492B
ratelimit.py 418B
topics.py 417B
admin_commands.py 415B
colors.py 350B
test_has_events.py 338B
__init__.py 336B
permissions_mod.py 332B
logging_config.py 298B
userinfo.py 283B
__init__.py 198B
follower.py 161B
__init__.py 148B
__init__.py 141B
__init__.py 82B
mock_irc.py 62B
__init__.py 29B
__init__.py 27B
__init__.py 25B
__init__.py 22B
__init__.py 0B
__init__.py 0B
__init__.py 0B
__init__.py 0B
SOURCES.txt 3KB
requires.txt 69B
共 103 条
- 1
- 2
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功