def channelcreate(self, name, propertiesdict=[]): # parse all properties properties = '' for item in propertiesdict: properties = properties + ' ' + item + '=' + ts3tools.escape_text( str(propertiesdict[item])) return ts3tools.parse_raw_data( base.send_receive('channelcreate channel_name=' + ts3tools.escape_text(name) + properties))
def send_sm(self, base, msg, socket=False): """ Sends a server message (all users can see it in the server tab). """ if socket is False: return base.send_receive('sendtextmessage targetmode=3 msg=' + ts3tools.escape_text(msg)) else: return base.get_event_socket().send( 'sendtextmessage targetmode=3 msg=' + ts3tools.escape_text(msg))
def send_pm(self, base, clid, msg, socket=False): """ Sends a private message to given user. """ if socket is False: return base.send_receive('sendtextmessage targetmode=1 msg=' + ts3tools.escape_text(msg) + ' target=' + clid) else: return base.get_event_socket().send( 'sendtextmessage targetmode=1 msg=' + ts3tools.escape_text(msg) + ' target=' + clid)
def event_clientjoined(user): # send welcome message, if enabled if config['Welcome']['enabled'] == 'true': if config['Welcome']['force_user'] != 'false': ts3tools.set_nickname(base, config['Welcome']['force_user'], True) chathelper.send_pm(base, user["clid"], ts3tools.escape_text(config['Welcome']['message']), True)
def channeledit(self, cid, propertiesdict=[]): # parse all properties properties = '' for item in propertiesdict: properties = properties + ' ' + item + '=' + ts3tools.escape_text( str(propertiesdict[item])) return ts3tools.parse_raw_data( base.send_receive('channeledit cid=' + str(cid) + ' ' + properties))
def event_clientjoined(values): # sends a text message (especially a question) to every connecting user ## simplify some values id = values['clid'] ## set the nickname to Pony to make it easier for the user ts3tools.set_nickname(base, 'Pony', True) ## send a message, in this case a question chathelper.send_pm(base, id, ts3tools.escape_text("What's my name?"), True)
def event_chat(values): # if the user answers right (in this case with a text message contains "Pony"), answer him that he is correct # if not, slap him with words! ## simplify some values id = values['invokerid'] msg = values['msg'] ## set the nickname to Pony ts3tools.set_nickname(base, 'Pony', True) ## answer to the user ## note: you have to use SOCKET_EVENT if you want to let someone chat with the bot because only SOCKET_EVENT is waiting for chat commands! if msg == "Pony": chathelper.send_pm( base, id, ts3tools.escape_text("Yes, that's right! You are the best!"), True) else: chathelper.send_pm( base, id, ts3tools.escape_text( "I think you don't know me yet. Why I asked you..."), True)
def event_start(values): # let the bot write "This is a test message!" every 5 seconds, # you can see that in console! ## sleep 5 seconds ## (yes, you can sleep without problems because of threading!) time.sleep(5) ## send a text message to server (send_sm means "send server message") ## note: this is sent through command socket chathelper.send_sm(base, ts3tools.escape_text('This is a test message!')) ## make it loop endless ## (yes, you can do that, too! the Thread is still alive!) event_start({})
def test(values): global base base.send_receive('sendtextmessage targetmode=2 target=1 msg=' + ts3tools.escape_text('nope')) base.execute_callback(name + '.test', {})
def event_clientjoined(user): # send welcome message, if enabled if config['Welcome']['enabled'] == 'true': chathelper.send_pm(base, user["clid"], ts3tools.escape_text(config['Welcome']['message']), True)
def test(values): global app2 time.sleep(5) base.send_receive('sendtextmessage targetmode=2 target=1 msg=' + ts3tools.escape_text('This is a test message!')) base.execute_callback(name + '.test', {})