TeamspeakBot
|
Public Member Functions | |
def | __init__ (self, ip, port=10011, user=None, password=None, virtual_server_id=None, minimal=False) |
Constructs a TeamspeakBot instance. More... | |
def | send_command (self, message, callback=None, data=None, err_callback=None) |
Sends a raw message to the teamspeak servers. More... | |
def | add_chat_command (self, command, description, access_level, callback, args=None, is_channel_command=False) |
Adds a chat command. More... | |
def | get_all_commands (self) |
Returns an dictionary with an instance of all commands. More... | |
def | set_value (self, key, value) |
Sets a persistent value which is saved in the database and can be retrieved later. More... | |
def | get_value (self, key, default_value=None) |
Retrieves a persistent value identified by key which was set earlier. More... | |
def | get_clients (self) |
Returns an array of currently connected client ids. More... | |
def | get_clients_cldbid (self) |
Returns an array of currently connected client database ids. More... | |
def | get_client_value (self, clid, key, default_value=None) |
Retrieves a client value. More... | |
def | set_client_value (self, clid, key, value, persistent=False) |
Sets a client value. More... | |
def | register_value_changed_callback (self, key, callback) |
Registers a callback which will be called everytime the value with the given key changes. More... | |
def | start_timer (self, callback, interval, is_single_shot=False, args) |
A timer will be started and the callback will be called after interval seconds with the given args. More... | |
def | stop_timer (self, timer_id) |
Deletes the set timer with the given id. More... | |
def | is_clid_online (self, clid) |
Returns true when the given clid is currently online. More... | |
def | is_cldbid_online (self, cldbid) |
Returns true when the given cldbid is currently online. More... | |
def | get_client_cldbid_by_clid (self, clid) |
Returns the client database id which belongs to the given client id. More... | |
def | get_client_clid_by_cldbid (self, cldbid) |
Returns the client id which belongs to the given client database id. More... | |
def | get_client_accesslevel (self, clid) |
Returns the client accesslevel for the given client id. More... | |
def | get_mysql_instance (self) |
Returns a handle to the mysql instance to perform raw queries. More... | |
def | execute_query (self, query, args) |
Executes a raw query on the mysql database. More... | |
def | send_server_notify_register (self, event, idd=None) |
Wraps servernotifyregister. More... | |
def | switch_to_channel (self, cid) |
Switches the bot instance to the given channel id. More... | |
def | switch_client_to_channel (self, clid, cid) |
Switches a client to the given channel id. More... | |
def | servergroupaddclient (self, sgid, cldbid, callback=None, data=None, err_callback=None) |
Adds the given client ot the given servergroup. More... | |
def | servergroupdelclient (self, sgid, cldbid, callback=None, data=None, err_callback=None) |
Removes the given client from the given servergroup. More... | |
def | send_text_to_client (self, clid, message, callback=None, data=None, err_callback=None) |
Sends a message to a client. More... | |
def | send_text_to_channel (self, cid, message) |
Sends a text message in a channel. More... | |
def | login_use (self, register_for_events=True) |
Logins with the provided credentials and choses a server. More... | |
def | register_for_all_events (self) |
Registers for the following events: server, textprivate, channel. More... | |
Static Public Member Functions | |
def | get_user_setting (key_path) |
Returns the value of an user setting. More... | |
Public Attributes | |
bot_name | |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.__init__ | ( | self, | |
ip, | |||
port = 10011 , |
|||
user = None , |
|||
password = None , |
|||
virtual_server_id = None , |
|||
minimal = False |
|||
) |
Constructs a TeamspeakBot instance.
ip | Ip of the server you want to connect to |
port | Port of the server yoú want to connect to |
user | Serverquery username |
password | Serverquery password |
virtual_server_id | The virtual id of the serverr you want the bot to manage |
minimal | Initializes a minimal bot version. The following will not be initialized: mysql, timer, plugins |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.add_chat_command | ( | self, | |
command, | |||
description, | |||
access_level, | |||
callback, | |||
args = None , |
|||
is_channel_command = False |
|||
) |
Adds a chat command.
Adds a chat command to the bot. When is_channel_command is false, a user needs to private message the bot in order to trigger the command. Otherwise, the user needs to post that command in a channel. The command needs to be prefixed with the needed prefix provided in the config file.
Your callback can return predefined values to indicate its result or state, e.g when the user did not provide all needed arguments you can return self.bot_instance.CommandResults.INVALID_USE to trigger a message to the sender indicating the right command structure. All possible values are defined in CommandResults
command | The command the user needs to type ( without prefix ) |
description | A description of that command. Usefull in for help commands and similiar |
access_level | The minimum accesslevel required for the command. |
callback | A callback to call when a user triggers a command |
args | An array of strings of args you expect. You have to parse them yourself, this is only to help the user about expected arguments. |
is_channel_command | Whether the command should trigger in channels or in private messages |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.execute_query | ( | self, | |
query, | |||
args | |||
) |
Executes a raw query on the mysql database.
We are using pymysql with a dict cursor in the backend. Refer to the pymysql documentation for more information: http://pymysql.readthedocs.io/en/latest/modules/cursors.html This function wraps "execute" and the args will be passed on.
query | |
args | A |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_all_commands | ( | self | ) |
Returns an dictionary with an instance of all commands.
An instance holds the following members:
command - The command, converted to lowercase original_command - The original command, as it was provided by the plugin author ( no case conversion ) description - A description of that command, as provided by the plugin author accesslevel - The required accesslevel for that command is_channel_command - Whether is is a channel command or noth callback - The callback to call when the command was executed by a user args - The args of that command, an array of ( one-word ) strings used to describe possible args of that command
def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_client_accesslevel | ( | self, | |
clid | |||
) |
Returns the client accesslevel for the given client id.
clid | Clientid to return the accesslevel for |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_client_cldbid_by_clid | ( | self, | |
clid | |||
) |
Returns the client database id which belongs to the given client id.
clid | The client id |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_client_clid_by_cldbid | ( | self, | |
cldbid | |||
) |
Returns the client id which belongs to the given client database id.
cldbid | The client database id |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_client_value | ( | self, | |
clid, | |||
key, | |||
default_value = None |
|||
) |
Retrieves a client value.
First, the teamspeak data namespace will be searched. If nothing is found, the custom data namespace will be searched. This means that custom keys cannot have the same name as a already existing teamspeak key otherwise it will be shadowed by the teamspeak key.
Returns None when a key is not found in both namespaces.
clid | The client id whose value you want to retrieve |
key | The key whose value you want to retrieve |
default_value | The value to return when the clid does not exist or the key could not be found |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_clients | ( | self | ) |
Returns an array of currently connected client ids.
This excludes server query clients.
def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_clients_cldbid | ( | self | ) |
Returns an array of currently connected client database ids.
This excludes server query clients.
def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_mysql_instance | ( | self | ) |
Returns a handle to the mysql instance to perform raw queries.
|
static |
Returns the value of an user setting.
This function returns the value of an user setting. These are values the user can define inside their config.json. The key can be a path to a value ( separated with . ) which will correspond to a key nested inside the json document.
E.g:
key_path = MyPlugin.youtube.api_key
would correspond to the following structure inside config.json:
The config namespace and the plugins key be prepended automatically.
key_path | The path to the value |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_value | ( | self, | |
key, | |||
default_value = None |
|||
) |
Retrieves a persistent value identified by key which was set earlier.
key | |
default_value | The default value to return when the key was not found |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.is_cldbid_online | ( | self, | |
cldbid | |||
) |
Returns true when the given cldbid is currently online.
cldbid | The client database id to check |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.is_clid_online | ( | self, | |
clid | |||
) |
Returns true when the given clid is currently online.
clid | The client id to check |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.login_use | ( | self, | |
register_for_events = True |
|||
) |
Logins with the provided credentials and choses a server.
Calls login with the provided server query credentials during bot construction. After, it will call use with the provided virtual server id, register for all events and initialize the bot data.
register_for_events | Whether the bot instance should register for events server|textprivate|channelk |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.register_for_all_events | ( | self | ) |
Registers for the following events: server, textprivate, channel.
def General.TeamspeakBot.Bot.Main.TeamspeakBot.register_value_changed_callback | ( | self, | |
key, | |||
callback | |||
) |
Registers a callback which will be called everytime the value with the given key changes.
key | The key you want to watch |
callback | The callback to call when the given key changes |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.send_command | ( | self, | |
message, | |||
callback = None , |
|||
data = None , |
|||
err_callback = None |
|||
) |
Sends a raw message to the teamspeak servers.
Will send a raw command to the teamspeak server. You need to take care about escaping the sent message yourself. Refer to the teamspeak3 server query doc for more information.
message | The message to send |
callback | The callback which will be called when the answer for the query arrives |
data | Additional data which will be passed to the callback as event.data |
err_callback | A callback which will be called when the query failed |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.send_server_notify_register | ( | self, | |
event, | |||
idd = None |
|||
) |
Wraps servernotifyregister.
See teamspeak query doc for more.
event | server|channel|textserver|textchannel|textprivate |
idd | channelID |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.send_text_to_channel | ( | self, | |
cid, | |||
message | |||
) |
Sends a text message in a channel.
cid | Channel id |
msg | Message to send |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.send_text_to_client | ( | self, | |
clid, | |||
message, | |||
callback = None , |
|||
data = None , |
|||
err_callback = None |
|||
) |
Sends a message to a client.
clid | The client id which will receive the message |
message | The message to send to the client |
callback | Will be called when the query result are received |
data | Additional data to pass to the callback |
err_callback | Will be called when the query results in a error |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.servergroupaddclient | ( | self, | |
sgid, | |||
cldbid, | |||
callback = None , |
|||
data = None , |
|||
err_callback = None |
|||
) |
Adds the given client ot the given servergroup.
sgid | The id of the servergroup which the client will receive |
cldbid | The database id of the client which will receive the servergroup |
callback | Will be called when the query result are received |
data | Additional data to pass to the callback |
err_callback | Will be called when the query results in a error |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.servergroupdelclient | ( | self, | |
sgid, | |||
cldbid, | |||
callback = None , |
|||
data = None , |
|||
err_callback = None |
|||
) |
Removes the given client from the given servergroup.
sgid | The id of the servergroup from which the client will be removed |
cldbid | The database id of the client which will be removed from the given servergroup |
callback | Will be called when the query result are received |
data | Additional data to pass to the callback |
err_callback | Will be called when the query results in a error |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.set_client_value | ( | self, | |
clid, | |||
key, | |||
value, | |||
persistent = False |
|||
) |
Sets a client value.
If persistent is true, the value will be saved in the database.
clid | The client id to save the value for |
key | The key for you value |
value | Your value |
persistent | Whether the value should be persistent. If true, it will be saved to the DB and will be retrieved the next time the client connects |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.set_value | ( | self, | |
key, | |||
value | |||
) |
Sets a persistent value which is saved in the database and can be retrieved later.
key | Identifier for you value |
value | Value to set |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.start_timer | ( | self, | |
callback, | |||
interval, | |||
is_single_shot = False , |
|||
args | |||
) |
A timer will be started and the callback will be called after interval seconds with the given args.
A timer will be started an the callback will be called after interval seconds. When is_single_shot was set to true, the timer will be automatically removed after it was fired. All additional args are passed onto the given callback.
callback | The callback to call after the interval |
interval | The time between successive calls |
is_single_shot | Whether the timer will be deleted after it fired the first time |
args | Additional args to pass onto the callback |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.stop_timer | ( | self, | |
timer_id | |||
) |
Deletes the set timer with the given id.
Returns true when a timer with that id was deleted.
timer_id | The id returned by start_timer for the started timer. |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.switch_client_to_channel | ( | self, | |
clid, | |||
cid | |||
) |
Switches a client to the given channel id.
clid | The client id to switch |
cid | The channel id the client should be switched to |
def General.TeamspeakBot.Bot.Main.TeamspeakBot.switch_to_channel | ( | self, | |
cid | |||
) |
Switches the bot instance to the given channel id.
cid | The channel id the bot should switch into |