-
Notifications
You must be signed in to change notification settings - Fork 0
Documentation
Just skip to the part where you want to get started.
Topic | Description |
---|---|
Client | Represents a LINE Official Acc... |
linelib.ext | Extensions for building your bot. |
class Client(
self,
channel_secret: str,
channel_access_token: str,
*args, **options: Any
)
Represents a LINE Official Account (Client).
parameter | type | default | description |
---|---|---|---|
channel_secret | str |
required | Channel secret. |
channel_access_token | str |
required | Channel access token. |
*args, **options | Any |
() , {}
|
No usage provided. |
from linelib import Client
client = Client('channel secret', 'channel access token')
-
CS :
str
- Channel secret. -
CAT :
str
- Channel access token. -
app :
Flask
- (Running) Flask application. Note that it has been usedCORS(app)
-
headers :
dict
- Headers for requests. -
loop :
Loop
- Asyncio event loop. -
_EVENTS* :
dict
- Saved event handlers. -
_VALID_EVENTS* :
list
- Current valid events.
📢 Notice! |
---|
* - These attributes should not be overwritten or deleted by the user. |
def createEvents(
self,
name: str,
obj: type
) -> None
Save the provided content to Client._EVENTS
.
parameter | type | default | description |
---|---|---|---|
name | str |
required | Event name. |
obj | type |
required | An event object. |
from linelib import Client
client = Client(...)
class ControlledEventObject:
def __init__(self, json: dict):
self.type = json['type'] # event type, REQUIRED
self.options = json['options'] # additional options, REQUIRED
async def emit(self, ctx):
await ctx.reply('Hello, World!')
obj = ControlledEventObject({
'type': 'text', # text message event
'options': () # Empty
})
client.createEvents('text', obj) # registers the event handler
def emitEvents(
self,
name: str,
*args: Any,
**kwargs: Any
) -> None
Runs the events inside Client._EVENTS
.
parameter | type | default | description |
---|---|---|---|
name | str |
required | The event name. |
*args, **kwargs | Any |
() , {}
|
Any arguments to add for the event handlers. |
from linelib import Client
client = Client(...)
@client.event('ready')
async def execute_me():
print("I just got executed!")
client.emitEvents('ready') # no arguments required
@event(
self,
listener: str,
*options
) -> EventObject
Registers an event handler. See Client._VALID_EVENTS
to see a list of valid events.
Decorator Parameters
parameter | type | default | description |
---|---|---|---|
listener | Union[str, Callable] |
FUNCTION_NAME_OR_LISTENER |
Listener name or leave blank. |
📖 Reference |
---|
FUNCTION_NAME_OR_LISTENER - You can pass in a valid function (Client._VALID_EVENTS ), or you can leave this blank and let linelib detect your function name. (Prefix: on_ + Event name) |
Handler Parameters
Handlers must be async (coroutine) functions.
parameter | type | description |
---|---|---|
ctx? None? |
Depends |
The specification depends on the event type. |
Depends: ctx? None?
event name | argument(s) | type | description |
---|---|---|---|
ready |
❌ | ❌ | No arguments should be passed. |
text |
ctx | TextMessageEvent |
The text message context. |
postback |
ctx | PostbackEvent |
The postback context. |
sticker |
ctx | StickerMessageEvent |
The sticker message context. |
unsend |
ctx | UnsendEvent |
Message unsent. (Cannot reply) |
follow |
ctx | FollowEvent |
A user added your bot as friend or unblocked your bot. |
unfollow |
ctx | UnfollowEvent |
A user blocked your bot. |
join |
ctx | JoinEvent |
Occurs when your bot joins a group chat. |
leave |
ctx | LeaveEvent |
Occurs when your bot leaves a group chat. |
memberJoined |
ctx | MemberJoinEvent |
Occurs when a member joins the group chat. |
memberLeft |
ctx | MemberLeaveEvent |
Occurs when a member leaves the group chat. |
videoPlayComplete |
ctx | VideoViewingCompleteEvent |
The user finishes viewing a video for at least once. |
beacon |
ctx | BeaconEvent |
LINE beacon event (enter , stay , banner ) |
accountLink |
ctx | AccountLinkEvent |
The user has linked their LINE account with a provider's service account. |
image |
ctx | ImageMessageEvent |
The image message context. You can download them. |
video |
ctx | VideoMessageEvent |
The video message context. You can download them. |
audio |
ctx | AudioMessageEvent |
The audio message context. You can download them. |
file |
ctx | FileMessageEvent |
The file message context. You can download them. |
location |
ctx | LocationMessageEvent |
The location event context. |
from linelib import Client
client = Client(...)
# method 1
@client.event('ready')
async def ready(): # any name you want
print("WOW!")
# method 2
@client.event()
async def on_ready(): # on_{EVENT_NAME}
print("Wow, again -- wow!!")
@client.event('text')
async def on_text(ctx):
await ctx.reply('Good morning!')
client.run(...)
def load_cog(
self,
cog: type
)
Loads a Cog (extension).
parameter | type | default | description |
---|---|---|---|
cog | type |
required | The cog to load. |
def run(
self,
*args,
**options: Any
)
Runs the LINE bot.
parameter | type | default | description |
---|---|---|---|
**options | Any |
{} |
Configure run options. See Client Options → |
option | type | description | example |
---|---|---|---|
log_level | level |
Sets the logger level of Flask. | log_level=logging.ERROR |
show_logs | bool |
Show linelib logs? | show_logs=False |
* | Any |
Unnamed for linelib, only for app.run options. |
threaded=True |
from linelib import Client
client = Client(...)
client.run(log_level=logging.ERROR, show_logs=False, threaded=True)
import linelib.ext
Extensions for building your bot.
class SocialPlugins
The LINE Social Plugins. (extension)
@staticmethod
def share(
url: str
) -> str
Returns a LINE Share Link. This is useful when you want a custom button.
from linelib.ext import SocialPlugins
print(SocialPlugins.share("https://example.com"))
constructed <_depends>: Depends
Represents something depends on the specification.
__bool__
def __bool__(self) -> bool
Returns False
.
__repr__
def __repr__(self) -> str
Returns "It Depends."
__hash__
def __hash__(self) -> int
Returns 0
.
__getitem__
def __getitem__(self, k) -> Any
Returns k
.
from linelib.ext import Depends
def my_function(arg: Depends[str] = None):
pass
from linelib.ext import commands
commands
module.
VALID_TYPES: list[type]
An array of valid typings for cog command arguments.
class Cog(self)
Represents a command cog.
The above represents an __init__
method, which is not recommended using until you've constructed with __init_subclass__
.
def __init_subclass__(cls) -> None
Subclass initialization (highly recommended). This gathers valid linelib cog commands and store them into _ll_COMMANDS
→ for further usage.
Example
from linelib.ext import commands
class MyCog(commands.Cog):
...
async def emit(self, ctx: type) -> Depends[str]
Emits the commands inside the cog. (DO NOT TOUCH)
Returns "all-nf"
(str) if every command name cannot satisfy the condition (command not found).
async def not_found(self, ctx, command: str) -> Any
Emits when a command is not found. This coroutine function is overwritable.
Example
from linelib.ext import commands
class MyCog(commands.Cog):
async def not_found(self, ctx, command):
await ctx.reply(f"Command '{command}' not found.")
properties | default | description |
---|---|---|
name | "UnnamedCog" | The name of the cog. |
show_not_found_log | False | Whether to show command not found log or not. |
_ll_CONSTRUCTED* | False | Identification to check if this cog is constructed when using Client.load_cog . |
_ll_COMMANDS* | [] | Temporary list to store commands detected inside a cog class. |
📢 Notice |
---|
* : Do not touch |
class CogCommandWrapper(
self,
cmd_name: str,
func,
rule: CommandRule | _dfr = DEFAULT_RULE
)
Represents a cog command.
parameters | type | default | description |
---|---|---|---|
cmd_name | str |
required | Command name. |
func | Callable |
required | Handler function. |
rule |
CommandRule | _dfr
|
DEFAULT_RULE |
Command rules. |
async def emit(self, o: Cog, ctx: type) -> Depends[str]
Event emitting for the handler. Returns "no"
(str) if this command does not equal to the context. (ctx.content
)
DO NOT TOUCH
parameters | type | default | description |
---|---|---|---|
o | Cog |
required | The Cog itself. |
ctx | type |
required | The context. |
@on_error(
self,
function: Callable
)
Event decorator when an error occurs.
The handler must be an async (coroutine) function.
type | parameters | description |
---|---|---|
@decorator | * | You do not need to add anything. |
handler | self, ctx, error |
error : The error message. |
Example
from linelib.ext import commands
class MyCog(commands.Cog):
@commands.cog_command() # returns CogCommandWrapper
async def my_command(self, ctx):
...
@my_command.on_error
async def my_error_handler(self, ctx, error):
print(error)
@rule_reject(
self,
function: Callable
) -> Callable
Event decorator once the rule function returned False
, which represents no pass.
The handler must be an async (coroutine) function.
type | parameters | description |
---|---|---|
@decorator | * | You do not need to add anything. |
handler | self, ctx | The context. |
Example
from linelib.ext import commands, rule
clas MyCog(commands.Cog):
@commands.cog_command(
name="hello",
rule=rule.CommandRule(
rule="cooldown",
seconds=10
)
) # returns CogCommandWrapper
async def hello(self, ctx):
...
@hello.rule_reject
async def rejected(self, ctx):
await ctx.reply("Rejected!")
@cog_command(
*,
name: String@CogCommandWrapper,
rule: CommandRule = DEFAULT_RULE
) -> CogCommandWrapper
Represents a command for cogs.
@decorator parameters
parameter | type | default | description | example |
---|---|---|---|---|
* | -- | -- | -- | You need to use named keywords. |
name | String@CogCommandWrapper | required | The command name. | name="hello" |
rule | CommandRule | required | Command rule. | See CommandRule |
Handler parameters
constructed <_str>: String
Represents any string.
def __matmul__(self, other) -> Any
Returns other
.
from typing import Any
from linelib.ext import commands
commands.String@Any
Thanks for taking your time to read my awful documentation and guides.
Note that if you're interested, please also check out the Official LINE Documentation!
Hello! I am a cute sidebar that makes you to read this whole text with no doubt.
I was born in 1969 and collaborated with Gustavo Fring for my entire life, and my motto is: "Life is a career."
Actually, I have a more important announcement to make besides my profile.
My name is Sustavo Fring, but you can call me Sus.
I am the secondary owner of Los Pollos Hermanos that almost nobody knows.
Gustavo and I created an empire.
I AM THE DANGER.
My name is Walter Hartwell White. I live at-