A Python library to interact with a chat API
Project description
Seiketsu-API
Installation
Install the library using pip
:
pip install seiketsu-api
Usage
First, import the ApiSeiketsu
class from the library:
from api_seiketsu import ApiSeiketsu, ApiSeiketsuImage
Initialize the ApiSeiketsu object
In the token field, insert your token, or the public one: 3rnPH1ooGMjui9fwf8y4Ueta9ivDJfbae0lTNtMRGoRddzMAhKDr=dgq7yyfJR8v
Create an instance of the ApiSeiketsu
class:
token = 'your_token'
seiketsu = ApiSeiketsu(token)
Read message
To get the latest message, call the read_message
method:
sender, message_text = seiketsu.read_message()
sender
contains the sender's nickname, message_text
contains the text of the message.
If you want read_message
to run all the time you can loop:
while True:
sender, message_text = seiketsu.read_message()
print(f'{sender}: {message_text}')
Write message
To write a new chat message, call the write_message
method, passing alias
and message_text
as arguments:
seiketsu.write_message(alias="John", message_text="Hello, world!")
Upload image
To upload an image, call the upload_image
method, passing the image file as an argument.
seiketsuImage = ApiSeiketsuImage()
image_file = open('C:\\folder\\image.png', 'rb') # Use the correct file path to your image
image_url = seiketsuImage.upload_image(image_file) # Call the upload_image function to upload the image
To display an image in chat, use the write_message
method.
Example
Here is a simple example demonstrating the use of the Seiketsu-API. Reads the last message, checks if the bot wrote it himself, if not, repeats it.
from api_seiketsu import ApiSeiketsu
token = '3rnPH1ooGMjui9fwf8y4Ueta9ivDJfbae0lTNtMRGoRddzMAhKDr=dgq7yyfJR8v'
seiketsu = ApiSeiketsu(token) # Initialize seiketsu API
aliasBot = "TestBot" # Name for Bot
while True:
# Waiting for a new message
sender, message = seiketsu.read_message()
# Checking that this is not a message from a bot
if sender != aliasBot + '#BOT':
# Sending a reply message
seiketsu.write_message(alias=aliasBot, message_text=message)
# Message output to console
print(f'Repeated message: {aliasBot}: {message}')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for seiketsu_api-1.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b39aae13488941a24e0e3b226ab66759de505cf1f927a6bc97f46915232d3e07 |
|
MD5 | d3c916f8df67d1eef648a1765c7a5d39 |
|
BLAKE2b-256 | dace02b9ed84005dc1a1c41e1e329955f940075dfe24308a0ae37d5b248ba1fc |