# PYVKBOT
![Python](https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=Python&logoColor=black)
[![tests&build](https://img.shields.io/github/workflow/status/zeph1rrinc/pyvkbot/tests/master?label=test%26build&logo=github&logoColor=white)](https://github.com/zeph1rrinc/pyvkbot/actions)
[![LICENCE](https://img.shields.io/badge/License-MIT-yellow.svg?logo=ReadtheDocs&logoColor=white)](/LICENSE.md)
[![Version](https://img.shields.io/pypi/v/pyvkbot?logo=pypi&logoColor=white)](https://pypi.org/project/PyVkBot/)
## Installation
```
pip install pyvkbot
```
## Bot
### Methods
### init
Creating instance for future working
Params:
- token: str - access token of your group
- main_chat: int - [OPTIONAL] main chat for bot
- group_id: int - [OPTIONAL] id of your group
- logging: bool - [OPTIONAL. DEFAULT: True] if True - logging in stdout by loguru.logger
Example:
```python
import os
from PyVkBot import Bot
token = os.getenv("TOKEN")
bot = Bot(token=token, main_chat=123, group_id=123123123, logging=False)
```
### delete_message
Deleting message from group chat, if author is not admin
Params:
- peer_id: int - id of chat where you want to delete messages
- cmidis: list - list of conversations ids of message, which you want to delete
Example:
```python
from PyVkBot import Bot
def delete_some_message(bot: Bot, message: dict):
bot.delete_message(peer_id=message['peer_id'], cmids=[message['conversation_message_id']])
```
### on
Creating handler for events in longpoll listen
Params:
- event: str - Event type. You can take in from Types
- callback: Callable - function, which is executed, when event triggers
- trigger: str - trigger for event. Command for message or type of event for other (you can get it from Types)
Example:
```python
from PyVkBot import Types
def test_handler(bot, message):
print(bot, message)
# triggers when user left or kicked from chat
bot.on(Types.EventTypes.ACTION, test_handler, Types.ActionTypes.CHAT_KICK_USER)
# triggers when user sent audio message
bot.on(Types.EventTypes.ATTACHMENT, test_handler, Types.AttachmentTypes.AUDIO_MESSAGE)
# triggers when user sent "hello"
bot.on(Types.EventTypes.MESSAGE, test_handler, "hello")
# triggers when user sent any test message
bot.on(Types.EventTypes.MESSAGE, test_handler)
```
### send_api_method
Sending some vk api method
Params:
- method: str - vk_api method. See [Docs](https://dev.vk.com/method?ref=tjournal.ru) for learn more
- payload: dict - dict of data to send in method
Example
```python
bot.send_api_method("messages.send", {"peer_id": 123, "text": "hi", "random_id":0})
```
### send_message
Sending message in chat
Params:
- peer_id: int - id of chat, where you want to send message
- text: str - text of message you wanted to send
- keyboard: Union[str, Keyboard] - [OPTIONAL] Keyboard for user, if needed. Takes Keyboard class or json string
Example:
```python
from PyVkBot.Keyboard import Keyboard
# Sends hi message to chat
bot.send_message(peer_id=123, text='hi')
# Send hello message to chat with keyboard
keyboard = Keyboard(inline=False)
keyboard.add_button(label="123")
bot.send_message(peer_id=123, text="hello", keyboard=keyboard)
# or
bot.send_message(peer_id=123, text="hello", keyboard=keyboard.get_keyboard())
# Send hello message to chat with removing keyboard
keyboard=Keyboard(inline=False).get_empty_keyboard()
bot.send_message(peer_id=123, text="hello", keyboard=keyboard)
```
### start
Creating handler for "start" button in private messages
Params:
- callback: Callable - function, which is executed, when button is pushed
Example:
```python
from PyVkBot import Bot
def start_command(bot: Bot, message: dict):
bot.send_message(peer_id=message['peer_id'], text="Hello there!")
bot.start(start_command)
```
### start_polling
Starting polling messages from users
Params:
- callback: Callable - [OPTIONAL] Function, which would be executed, when bot is started
Example
```python
bot.start_polling()
bot.start_polling(lambda *_: print("BOT STARTED!"))
```
## Keyboard
Creating a vk keyboard
Params:
- one_time: bool - [OPTIONAL. DEFAULT: False] If true, keyboard closes when user pushes the buttons
- inline: bool - [OPTIONAL. DEFAULT: False] if ture, keyboard will be inline
Example:
```python
from PyVkBot.Keyboard import Keyboard
# Simple vk keyboard
simple_keyboard = Keyboard()
# Simple one time vk keyboard
one_time_keyboard = Keyboard(one_time=True)
# Inline vk keyboard
inline_keyboard = Keyboard(inline=True)
```
All keyboard methods you can see in [doc](https://vk-api.readthedocs.io/en/latest/keyboard.html). Callback methods are not implemented.
Raw data
{
"_id": null,
"home_page": "https://github.com/zeph1rrinc/pyvkbot",
"name": "PyVkBot",
"maintainer": "",
"docs_url": null,
"requires_python": ">3.10",
"maintainer_email": "",
"keywords": "",
"author": "zeph1rr",
"author_email": "grianton535@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/1e/0f/d256fb4a56220c238e24eb4164261e923cb12658628edce022103c742a80/PyVkBot-1.0.5.tar.gz",
"platform": null,
"description": "\ufeff# PYVKBOT\n\n![Python](https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=Python&logoColor=black)\n\n[![tests&build](https://img.shields.io/github/workflow/status/zeph1rrinc/pyvkbot/tests/master?label=test%26build&logo=github&logoColor=white)](https://github.com/zeph1rrinc/pyvkbot/actions)\n[![LICENCE](https://img.shields.io/badge/License-MIT-yellow.svg?logo=ReadtheDocs&logoColor=white)](/LICENSE.md)\n[![Version](https://img.shields.io/pypi/v/pyvkbot?logo=pypi&logoColor=white)](https://pypi.org/project/PyVkBot/)\n\n## Installation\n\n```\npip install pyvkbot\n```\n\n## Bot\n### Methods\n### init\nCreating instance for future working\n\nParams:\n- token: str - access token of your group\n- main_chat: int - [OPTIONAL] main chat for bot\n- group_id: int - [OPTIONAL] id of your group\n- logging: bool - [OPTIONAL. DEFAULT: True] if True - logging in stdout by loguru.logger\n\nExample:\n\n```python\nimport os\nfrom PyVkBot import Bot\n\ntoken = os.getenv(\"TOKEN\")\n\nbot = Bot(token=token, main_chat=123, group_id=123123123, logging=False)\n```\n\n### delete_message\nDeleting message from group chat, if author is not admin\n\nParams:\n- peer_id: int - id of chat where you want to delete messages\n- cmidis: list - list of conversations ids of message, which you want to delete\n\nExample:\n```python\nfrom PyVkBot import Bot\n\ndef delete_some_message(bot: Bot, message: dict):\n bot.delete_message(peer_id=message['peer_id'], cmids=[message['conversation_message_id']])\n```\n\n### on\nCreating handler for events in longpoll listen\n\nParams:\n- event: str - Event type. You can take in from Types\n- callback: Callable - function, which is executed, when event triggers\n- trigger: str - trigger for event. Command for message or type of event for other (you can get it from Types)\n\nExample:\n\n```python\nfrom PyVkBot import Types\n\ndef test_handler(bot, message):\n print(bot, message)\n\n# triggers when user left or kicked from chat\nbot.on(Types.EventTypes.ACTION, test_handler, Types.ActionTypes.CHAT_KICK_USER)\n# triggers when user sent audio message\nbot.on(Types.EventTypes.ATTACHMENT, test_handler, Types.AttachmentTypes.AUDIO_MESSAGE)\n# triggers when user sent \"hello\"\nbot.on(Types.EventTypes.MESSAGE, test_handler, \"hello\")\n# triggers when user sent any test message\nbot.on(Types.EventTypes.MESSAGE, test_handler)\n```\n\n### send_api_method\nSending some vk api method\n\nParams:\n- method: str - vk_api method. See [Docs](https://dev.vk.com/method?ref=tjournal.ru) for learn more\n- payload: dict - dict of data to send in method\n\nExample\n```python\nbot.send_api_method(\"messages.send\", {\"peer_id\": 123, \"text\": \"hi\", \"random_id\":0})\n```\n\n### send_message\nSending message in chat\n\nParams:\n- peer_id: int - id of chat, where you want to send message\n- text: str - text of message you wanted to send\n- keyboard: Union[str, Keyboard] - [OPTIONAL] Keyboard for user, if needed. Takes Keyboard class or json string\n\nExample:\n```python\nfrom PyVkBot.Keyboard import Keyboard\n\n# Sends hi message to chat\nbot.send_message(peer_id=123, text='hi')\n\n# Send hello message to chat with keyboard\nkeyboard = Keyboard(inline=False)\nkeyboard.add_button(label=\"123\")\nbot.send_message(peer_id=123, text=\"hello\", keyboard=keyboard)\n# or\nbot.send_message(peer_id=123, text=\"hello\", keyboard=keyboard.get_keyboard())\n\n# Send hello message to chat with removing keyboard\nkeyboard=Keyboard(inline=False).get_empty_keyboard()\nbot.send_message(peer_id=123, text=\"hello\", keyboard=keyboard)\n```\n\n### start\nCreating handler for \"start\" button in private messages\n\nParams:\n- callback: Callable - function, which is executed, when button is pushed\n\nExample:\n```python\nfrom PyVkBot import Bot\n\ndef start_command(bot: Bot, message: dict):\n bot.send_message(peer_id=message['peer_id'], text=\"Hello there!\")\n\nbot.start(start_command)\n```\n\n### start_polling\nStarting polling messages from users\n\nParams:\n- callback: Callable - [OPTIONAL] Function, which would be executed, when bot is started\n\nExample\n```python\nbot.start_polling()\nbot.start_polling(lambda *_: print(\"BOT STARTED!\"))\n```\n\n## Keyboard\nCreating a vk keyboard\n\nParams:\n- one_time: bool - [OPTIONAL. DEFAULT: False] If true, keyboard closes when user pushes the buttons\n- inline: bool - [OPTIONAL. DEFAULT: False] if ture, keyboard will be inline\n\nExample:\n```python\nfrom PyVkBot.Keyboard import Keyboard\n\n# Simple vk keyboard\nsimple_keyboard = Keyboard()\n\n# Simple one time vk keyboard\none_time_keyboard = Keyboard(one_time=True)\n\n# Inline vk keyboard\ninline_keyboard = Keyboard(inline=True)\n```\n\nAll keyboard methods you can see in [doc](https://vk-api.readthedocs.io/en/latest/keyboard.html). Callback methods are not implemented.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Chat bot for vk.com",
"version": "1.0.5",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "61aecadfffa29283bee66c43b9c5a9d5",
"sha256": "f98c32183217331b32a8e77359596d47da8542bc5b0cf4896cd82ab99e1d62a2"
},
"downloads": -1,
"filename": "PyVkBot-1.0.5.tar.gz",
"has_sig": false,
"md5_digest": "61aecadfffa29283bee66c43b9c5a9d5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">3.10",
"size": 5401,
"upload_time": "2022-12-05T22:46:13",
"upload_time_iso_8601": "2022-12-05T22:46:13.846657Z",
"url": "https://files.pythonhosted.org/packages/1e/0f/d256fb4a56220c238e24eb4164261e923cb12658628edce022103c742a80/PyVkBot-1.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-05 22:46:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "zeph1rrinc",
"github_project": "pyvkbot",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "pyvkbot"
}