TeamspeakBot
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
General.TeamspeakBot.Bot.Main.TeamspeakBot Class Reference

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
 

Constructor & Destructor Documentation

◆ __init__()

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.

Parameters
ipIp of the server you want to connect to
portPort of the server yoú want to connect to
userServerquery username
passwordServerquery password
virtual_server_idThe virtual id of the serverr you want the bot to manage
minimalInitializes a minimal bot version. The following will not be initialized: mysql, timer, plugins

Member Function Documentation

◆ add_chat_command()

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

Parameters
commandThe command the user needs to type ( without prefix )
descriptionA description of that command. Usefull in for help commands and similiar
access_levelThe minimum accesslevel required for the command.
callbackA callback to call when a user triggers a command
argsAn 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_commandWhether the command should trigger in channels or in private messages
Returns
None

◆ execute_query()

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.

Parameters
query
argsA
Returns
The cursor object

◆ get_all_commands()

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

Returns
An dictionary of commands, where the command is the key and the instance is the value

◆ get_client_accesslevel()

def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_client_accesslevel (   self,
  clid 
)

Returns the client accesslevel for the given client id.

Parameters
clidClientid to return the accesslevel for
Returns
Accesslevel of default accesslevel

◆ get_client_cldbid_by_clid()

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.

Parameters
clidThe client id
Returns
The client database id or none

◆ get_client_clid_by_cldbid()

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.

Parameters
cldbidThe client database id
Returns
The client id or none

◆ get_client_value()

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.

Parameters
clidThe client id whose value you want to retrieve
keyThe key whose value you want to retrieve
default_valueThe value to return when the clid does not exist or the key could not be found
Returns
The value or the default_value of no entry was found

◆ get_clients()

def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_clients (   self)

Returns an array of currently connected client ids.

This excludes server query clients.

Returns
Array of integers

◆ get_clients_cldbid()

def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_clients_cldbid (   self)

Returns an array of currently connected client database ids.

This excludes server query clients.

Returns
Array of integers

◆ get_mysql_instance()

def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_mysql_instance (   self)

Returns a handle to the mysql instance to perform raw queries.

Returns
MysqlClass

◆ get_user_setting()

def General.TeamspeakBot.Bot.Main.TeamspeakBot.get_user_setting (   key_path)
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:

{
"chosen_config_namespace": {
"plugins": {
"MyPlugin": {
"youtube": {
"api_key": "000000000000000"
}
}
}
}
}

The config namespace and the plugins key be prepended automatically.

Parameters
key_pathThe path to the value
Returns
The value at the given path

◆ get_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.

Parameters
key
default_valueThe default value to return when the key was not found
Returns
Value

◆ is_cldbid_online()

def General.TeamspeakBot.Bot.Main.TeamspeakBot.is_cldbid_online (   self,
  cldbid 
)

Returns true when the given cldbid is currently online.

Parameters
cldbidThe client database id to check
Returns
True when the cldbid is online, false otherwise

◆ is_clid_online()

def General.TeamspeakBot.Bot.Main.TeamspeakBot.is_clid_online (   self,
  clid 
)

Returns true when the given clid is currently online.

Parameters
clidThe client id to check
Returns
True when the clid is online, false otherwise

◆ login_use()

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.

Parameters
register_for_eventsWhether the bot instance should register for events server|textprivate|channelk
Returns
None

◆ register_for_all_events()

def General.TeamspeakBot.Bot.Main.TeamspeakBot.register_for_all_events (   self)

Registers for the following events: server, textprivate, channel.

Returns
None

◆ register_value_changed_callback()

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.

Parameters
keyThe key you want to watch
callbackThe callback to call when the given key changes
Returns
None

◆ send_command()

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.

Parameters
messageThe message to send
callbackThe callback which will be called when the answer for the query arrives
dataAdditional data which will be passed to the callback as event.data
err_callbackA callback which will be called when the query failed
Returns
Boolean. True if the message was sent, false otherwise.

◆ send_server_notify_register()

def General.TeamspeakBot.Bot.Main.TeamspeakBot.send_server_notify_register (   self,
  event,
  idd = None 
)

Wraps servernotifyregister.

See teamspeak query doc for more.

Parameters
eventserver|channel|textserver|textchannel|textprivate
iddchannelID
Returns
None

◆ send_text_to_channel()

def General.TeamspeakBot.Bot.Main.TeamspeakBot.send_text_to_channel (   self,
  cid,
  message 
)

Sends a text message in a channel.

Parameters
cidChannel id
msgMessage to send
Returns
None

◆ send_text_to_client()

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.

Parameters
clidThe client id which will receive the message
messageThe message to send to the client
callbackWill be called when the query result are received
dataAdditional data to pass to the callback
err_callbackWill be called when the query results in a error
Returns
None

◆ servergroupaddclient()

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.

Parameters
sgidThe id of the servergroup which the client will receive
cldbidThe database id of the client which will receive the servergroup
callbackWill be called when the query result are received
dataAdditional data to pass to the callback
err_callbackWill be called when the query results in a error
Returns
None

◆ servergroupdelclient()

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.

Parameters
sgidThe id of the servergroup from which the client will be removed
cldbidThe database id of the client which will be removed from the given servergroup
callbackWill be called when the query result are received
dataAdditional data to pass to the callback
err_callbackWill be called when the query results in a error
Returns
None

◆ set_client_value()

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.

Parameters
clidThe client id to save the value for
keyThe key for you value
valueYour value
persistentWhether the value should be persistent. If true, it will be saved to the DB and will be retrieved the next time the client connects
Returns
Boolean

◆ set_value()

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.

Parameters
keyIdentifier for you value
valueValue to set
Returns
None

◆ start_timer()

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.

Parameters
callbackThe callback to call after the interval
intervalThe time between successive calls
is_single_shotWhether the timer will be deleted after it fired the first time
argsAdditional args to pass onto the callback
Returns
Integer A identifier for the timer used to delete it

◆ stop_timer()

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.

Parameters
timer_idThe id returned by start_timer for the started timer.
Returns
True when the timer was found and deleted, false otherwise.

◆ switch_client_to_channel()

def General.TeamspeakBot.Bot.Main.TeamspeakBot.switch_client_to_channel (   self,
  clid,
  cid 
)

Switches a client to the given channel id.

Parameters
clidThe client id to switch
cidThe channel id the client should be switched to
Returns
None

◆ switch_to_channel()

def General.TeamspeakBot.Bot.Main.TeamspeakBot.switch_to_channel (   self,
  cid 
)

Switches the bot instance to the given channel id.

Parameters
cidThe channel id the bot should switch into
Returns
None

The documentation for this class was generated from the following file: