Esempio n. 1
0
 def addUserToDB(self, client_unique_id, account_name, api_key,
                 created_date, last_audit_date):
     client_id = self.getActiveTsUserID(client_unique_id)
     client_exists = self.db_cursor.execute(
         "SELECT * FROM users WHERE ts_db_id=?",
         (client_unique_id, )).fetchall()
     if len(client_exists) > 1:
         TS3Auth.log(
             'Function [addUserToDB] WARN: Found multipe database entries for single unique teamspeakid %s.'
             % client_unique_id,
             silent=True)
     if len(client_exists
            ) != 0:  # If client TS database id is in BOT's database.
         self.db_cursor.execute(
             """UPDATE users SET ts_db_id=?, account_name=?, api_key=?, created_date=?, last_audit_date=? WHERE ts_db_id=?""",
             (client_unique_id, account_name, api_key, created_date,
              last_audit_date, client_unique_id))
         TS3Auth.log(
             "Teamspeak ID %s already in Database updating with new Account Name '%s'. (likely permissions changed by a Teamspeak Admin)"
             % (client_unique_id, account_name))
     else:
         self.db_cursor.execute(
             "INSERT INTO users ( ts_db_id, account_name, api_key, created_date, last_audit_date) VALUES(?,?,?,?,?)",
             (client_unique_id, account_name, api_key, created_date,
              last_audit_date))
     self.db_conn.commit()
Esempio n. 2
0
    def getUserDatabase(self):
        if os.path.isfile(self.db_name):
            self.db_conn = sqlite3.connect(
                self.db_name,
                check_same_thread=False,
                detect_types=sqlite3.PARSE_DECLTYPES)
            self.db_cursor = self.db_conn.cursor()
            TS3Auth.log("Loaded User Database...")

        else:
            self.db_conn = sqlite3.connect(
                self.db_name,
                check_same_thread=False,
                detect_types=sqlite3.PARSE_DECLTYPES)
            self.db_cursor = self.db_conn.cursor()
            TS3Auth.log("No User Database found...created new database!")
            self.db_cursor.execute('''CREATE TABLE users
                                (ts_db_id text primary key, account_name text, api_key text, created_date date, last_audit_date date)'''
                                   )
            self.db_cursor.execute('''CREATE TABLE bot_info
                                (version text, last_succesful_audit date)''')
            self.db_conn.commit()
            self.db_cursor.execute(
                'INSERT INTO bot_info (version, last_succesful_audit) VALUES (?,?)',
                (
                    current_version,
                    datetime.date.today(),
                ))
            self.db_conn.commit()
Esempio n. 3
0
 def addUserToDB(self,client_unique_id,account_name,api_key,created_date,last_audit_date):
     client_id=self.getActiveTsUserID(client_unique_id)
     client_exists=self.db_cursor.execute("SELECT * FROM users WHERE ts_db_id=?",  (client_unique_id,)).fetchall()
     if len(client_exists) > 1:
         TS3Auth.log('Function [addUserToDB] WARN: Found multipe database entries for single unique teamspeakid %s.' %client_unique_id, silent=True)
     if len(client_exists) != 0: # If client TS database id is in BOT's database.
         self.db_cursor.execute("""UPDATE users SET ts_db_id=?, account_name=?, api_key=?, created_date=?, last_audit_date=? WHERE ts_db_id=?""", (client_unique_id, account_name, api_key, created_date, last_audit_date,client_unique_id))
         TS3Auth.log("Teamspeak ID %s already in Database updating with new Account Name '%s'. (likely permissions changed by a Teamspeak Admin)" %(client_unique_id,account_name))
     else:
         self.db_cursor.execute("INSERT INTO users ( ts_db_id, account_name, api_key, created_date, last_audit_date) VALUES(?,?,?,?,?)",(client_unique_id, account_name, api_key, created_date, last_audit_date))
     self.db_conn.commit()
Esempio n. 4
0
 def addUserToDB(self, client_db_id, account_name, api_key, created_date, last_audit_date):
     client_exists = self.db_cursor.execute(
         "SELECT EXISTS(SELECT * FROM users WHERE ts_db_id=?)",  (client_db_id,)).fetchone()
     if client_exists[0] != 0:  # If client Ts id is not already in DB
         self.db_cursor.execute("""UPDATE users SET ts_db_id=?, account_name=?, api_key=?, created_date=?, last_audit_date=? WHERE ts_db_id=?""", (
             client_db_id, account_name, api_key, created_date, last_audit_date, client_db_id))
         TS3Auth.log("Teamspeak ID %s already in Database updating with new Account Name '%s'. (likely permissions changed by a Teamspeak Admin)" % (
             client_db_id, account_name))
     else:
         self.db_cursor.execute("INSERT INTO users ( ts_db_id, account_name, api_key, created_date, last_audit_date) VALUES(?,?,?,?,?)", (
             client_db_id, account_name, api_key, created_date, last_audit_date))
     self.db_conn.commit()
Esempio n. 5
0
 def setPermissions(self, client_id):
     client_db_id = ts3conn.clientinfo(clid=client_id)[
         0].get('client_database_id')
     if DEBUG:
         TS3Auth.log("Adding Permissions:  SGID: %s   CLDBID: %s" %
                     (self.vgrp_id, client_db_id))
     try:
         # Add user to group
         ts3conn.servergroupaddclient(
             sgid=self.vgrp_id, cldbid=client_db_id)
     except:
         TS3Auth.log(
             "Unable to add client to '%s' group. Does the group exist?" % verified_group)
Esempio n. 6
0
        def getUserDatabase(self):
                if os.path.isfile(self.db_name):
                        self.db_conn = sqlite3.connect(self.db_name,check_same_thread=False,detect_types=sqlite3.PARSE_DECLTYPES)
                        self.db_cursor = self.db_conn.cursor()
                        TS3Auth.log ("Loaded User Database...")

                else:
                        self.db_conn = sqlite3.connect(self.db_name,check_same_thread=False,detect_types=sqlite3.PARSE_DECLTYPES)
                        self.db_cursor = self.db_conn.cursor()
                        TS3Auth.log("No User Database found...created new database!")
                        self.db_cursor.execute('''CREATE TABLE users
                                (ts_db_id text primary key, account_name text, api_key text, created_date date, last_audit_date date)''')
                        self.db_cursor.execute('''CREATE TABLE bot_info
                                (version text, last_succesful_audit date)''')
                        self.db_conn.commit()
                        self.db_cursor.execute('INSERT INTO bot_info (version, last_succesful_audit) VALUES (?,?)', (current_version, datetime.date.today(), ))
                        self.db_conn.commit()
Esempio n. 7
0
        def auditUsers(self):
            self.c_audit_date=datetime.date.today() #Update current date everytime run
            self.db_audit_list=self.db_cursor.execute('SELECT * FROM users').fetchall()
            for audit_user in self.db_audit_list:

                #Convert to single variables
                audit_ts_id = audit_user[0]
                audit_account_name = audit_user[1]
                audit_api_key = audit_user[2]
                audit_created_date = audit_user[3]
                audit_last_audit_date = audit_user[4]

                if DEBUG:
                        print("Audit: User ",audit_account_name)
                        print("TODAY |%s|  NEXT AUDIT |%s|" %(self.c_audit_date,audit_last_audit_date + datetime.timedelta(days=audit_period)))

                #compare audit date

                if self.c_audit_date >= audit_last_audit_date + datetime.timedelta(days=audit_period):
                    TS3Auth.log ("User %s is due for audting!" %audit_account_name)
                    auth=TS3Auth.auth_request(audit_api_key,audit_account_name)
                    if auth.success:
                            TS3Auth.log("User %s is still on %s. Succesful audit!" %(audit_account_name,auth.world.get('name')))
                            self.db_cursor.execute("UPDATE users SET last_audit_date = ? WHERE ts_db_id= ?", (self.c_audit_date,audit_ts_id,))
                            self.db_conn.commit()
                    else:
                            TS3Auth.log("User %s is no longer on our server. Removing access...." %(audit_account_name))
                            self.removePermissions(audit_ts_id)
                            self.removeUserFromDB(audit_ts_id)

            self.db_cursor.execute('INSERT INTO bot_info (last_succesful_audit) VALUES (?)', (self.c_audit_date,))
            self.db_conn.commit()
 def get(self, key, args=()):
     '''
 key: the string to identify the locale-string with
 args: an optional tuple of arguments to pass to the old style formatter. If the number of arguments don't match the number of template spots in the string, no argument will be inserted at all
 returns: either the looked-up locale-string, the loooked-up locale from the fallback Locale (if any) or the key as fallback-fallback
 '''
     tpl = ""
     if key in self._values:
         tpl = self._values[key]
     elif self._fallback is not None:
         tpl = self._fallback.get(key)
     else:
         tpl = key
     try:
         tpl = tpl % args
     except TypeError:
         TS3Auth.log(
             "Could not insert all %d arguments into the string with key '%s' of locale %d. I will not insert any arguments at all."
             % (len(args), key, self.__class__.__name__))
     return tpl
Esempio n. 9
0
 def setPermissions(self,unique_client_id):
         try:
                 client_db_id = self.getTsDatabaseID(unique_client_id)
                 if DEBUG:
                         TS3Auth.log("Adding Permissions: CLUID [%s] SGID: %s   CLDBID: %s" %(unique_client_id, self.vgrp_id, client_db_id))
                 try:
                         #Add user to group
                         self.ts_connection.servergroupaddclient(sgid=self.vgrp_id, cldbid=client_db_id)
                 except:
                         TS3Auth.log("Unable to add client to '%s' group. Does the group exist?" %verified_group)
         except ts3.query.TS3QueryError as err:
                 TS3Auth.log("BOT [setPermissions]: Failed; %s" %err) #likely due to bad client id
Esempio n. 10
0
    def auditUsers(self):
        self.c_audit_date = datetime.date.today(
        )  #Update current date everytime run
        self.db_audit_list = self.db_cursor.execute(
            'SELECT * FROM users').fetchall()
        for audit_user in self.db_audit_list:

            #Convert to single variables
            audit_ts_id = audit_user[0]
            audit_account_name = audit_user[1]
            audit_api_key = audit_user[2]
            audit_created_date = audit_user[3]
            audit_last_audit_date = audit_user[4]

            if DEBUG:
                print("Audit: User ", audit_account_name)
                print("TODAY |%s|  NEXT AUDIT |%s|" %
                      (self.c_audit_date, audit_last_audit_date +
                       datetime.timedelta(days=audit_period)))

            #compare audit date

            if self.c_audit_date >= audit_last_audit_date + datetime.timedelta(
                    days=audit_period):
                TS3Auth.log("User %s is due for audting!" % audit_account_name)
                auth = TS3Auth.auth_request(audit_api_key, audit_account_name)
                if auth.success:
                    TS3Auth.log("User %s is still on %s. Succesful audit!" %
                                (audit_account_name, auth.world.get('name')))
                    self.db_cursor.execute(
                        "UPDATE users SET last_audit_date = ? WHERE ts_db_id= ?",
                        (
                            self.c_audit_date,
                            audit_ts_id,
                        ))
                    self.db_conn.commit()
                else:
                    TS3Auth.log(
                        "User %s is no longer on our server. Removing access...."
                        % (audit_account_name))
                    self.removePermissions(audit_ts_id)
                    self.removeUserFromDB(audit_ts_id)

        self.db_cursor.execute(
            'INSERT INTO bot_info (last_succesful_audit) VALUES (?)',
            (self.c_audit_date, ))
        self.db_conn.commit()
Esempio n. 11
0
        def removePermissions(self,unique_client_id):
                try:
                        client_db_id = self.getTsDatabaseID(unique_client_id)
                        if DEBUG:
                                TS3Auth.log("Removing Permissions: CLUID [%s] SGID: %s   CLDBID: %s" %(unique_client_id, self.vgrp_id, client_db_id))

                        #Remove user from group
                        try:
                                self.ts_connection.servergroupdelclient(sgid=self.vgrp_id, cldbid=client_db_id)
                        except:
                                TS3Auth.log("Unable to remove client from '%s' group. Does the group exist?" %verified_group)
                except ts3.query.TS3QueryError as err:
                        TS3Auth.log("BOT [removePermissions]: Failed; %s" %err) #likely due to bad client id
Esempio n. 12
0
 def setPermissions(self, unique_client_id):
     try:
         client_db_id = self.getTsDatabaseID(unique_client_id)
         if DEBUG:
             TS3Auth.log(
                 "Adding Permissions: CLUID [%s] SGID: %s   CLDBID: %s" %
                 (unique_client_id, self.vgrp_id, client_db_id))
         try:
             #Add user to group
             self.ts_connection.servergroupaddclient(sgid=self.vgrp_id,
                                                     cldbid=client_db_id)
         except:
             TS3Auth.log(
                 "Unable to add client to '%s' group. Does the group exist?"
                 % verified_group)
     except ts3.query.TS3QueryError as err:
         TS3Auth.log("BOT [setPermissions]: Failed; %s" %
                     err)  #likely due to bad client id
Esempio n. 13
0
    def removePermissions(self, unique_client_id):
        try:
            client_db_id = self.getTsDatabaseID(unique_client_id)
            if DEBUG:
                TS3Auth.log(
                    "Removing Permissions: CLUID [%s] SGID: %s   CLDBID: %s" %
                    (unique_client_id, self.vgrp_id, client_db_id))

            #Remove user from group
            try:
                self.ts_connection.servergroupdelclient(sgid=self.vgrp_id,
                                                        cldbid=client_db_id)
            except:
                TS3Auth.log(
                    "Unable to remove client from '%s' group. Does the group exist?"
                    % verified_group)
        except ts3.query.TS3QueryError as err:
            TS3Auth.log("BOT [removePermissions]: Failed; %s" %
                        err)  #likely due to bad client id
Esempio n. 14
0
        TS3Auth.log(
            'BOT Event: Something went wrong during message received from teamspeak server. Likely bad user command/message.'
        )
        TS3Auth.log(e)

    return None


#######################################

#######################################
# Begins the connect to Teamspeak
#######################################

bot_loop_forever = True
TS3Auth.log("Initializing script....")
while bot_loop_forever:
    try:
        TS3Auth.log("Connecting to Teamspeak server...")
        with ts3.query.TS3Connection(host, port) as ts3conn:

            try:
                ts3conn.login(client_login_name=user,
                              client_login_password=passwd)

            except ts3.query.TS3QueryError as err:
                TS3Auth.log("Login Failed Reason: %s" % err.resp.error["msg"])
                exit(1)
            #Force connection to stay up by sending an alive message every 250 seconds
            ts3conn.keepalive(interval=250)
Esempio n. 15
0
def my_event_handler(sender, event):
        """
        *sender* is the TS3Connection instance, that received the event.

        *event* is a ts3.response.TS3Event instance, that contains the name
        of the event and the data.
        """
        if DEBUG:
                print("\nEvent:")
                #print("  sender:", sender)
                print("  event.event:", event.event)
                print("  event.parsed:", event.parsed)
                print("\n\n")


        raw_cmd=event.parsed[0].get('msg')
        rec_from_name=event.parsed[0].get('invokername').encode('utf-8') #fix any encoding issues introdcued by Teamspeak
        rec_from_uid=event.parsed[0].get('invokeruid')
        rec_from_id=event.parsed[0].get('invokerid')
        rec_type=event.parsed[0].get('targetmode')

        if rec_from_uid == 'serveradmin':
                return #ignore any serveradmin messages, aka seeing our own messages.
        try:
                # Type 2 means it was channel text
                if rec_type == '2':
                        cmd=commandCheck(raw_cmd) #sanitize the commands but also restricts commands to a list of known allowed commands

                        #
                        if cmd == 'verifyme':
                                if BOT.clientNeedsVerify(rec_from_uid):
                                        TS3Auth.log("Verify Request Recieved from user '%s'. Sending PM now...\n        ...waiting for user response." %rec_from_name)
                                        sender.sendtextmessage( targetmode=1, target=rec_from_id, msg=bot_msg_verify)
                                else:
                                        TS3Auth.log("Verify Request Recieved from user '%s'. Already verified, notified user." %rec_from_name)
                                        sender.sendtextmessage( targetmode=1, target=rec_from_id, msg=bot_msg_alrdy_verified)


                # Type 1 means it was a private message
                elif rec_type == '1':
                    #reg_api_auth='\s*(\S+\s*\S+\.\d+)\s+(.*?-.*?-.*?-.*?-.*)\s*$'
                    reg_api_auth='\s*(.+?\.\d+)\s+(.*?-.*?-.*?-.*?-.*)\s*$'


                    #Command for verifying authentication
                    if re.match(reg_api_auth,raw_cmd):
                            pair=re.search(reg_api_auth,raw_cmd)
                            uname=pair.group(1)
                            uapi=pair.group(2)
                            limit_hit=BOT.TsClientLimitReached(uname)
                            if DEBUG:
                                print("Limit hit check: %s" %limit_hit)
                            if not limit_hit:
                                if BOT.clientNeedsVerify(rec_from_uid):
                                    TS3Auth.log("Received verify response from %s" %rec_from_name)
                                    auth=TS3Auth.auth_request(uapi,uname)
                                    if DEBUG:
                                            TS3Auth.log('Name: |%s| API: |%s|' %(uname,uapi))
                                    if auth.success:
                                            TS3Auth.log("Setting permissions for %s as verified." %rec_from_name)

                                            #set permissions
                                            BOT.setPermissions(rec_from_uid)

                                            #get todays date
                                            today_date=datetime.date.today()

                                            #Add user to database so we can query their API key over time to ensure they are still on our server
                                            BOT.addUserToDB(rec_from_uid,uname,uapi,today_date,today_date)
                                            print ("Added user to DB with ID %s" %rec_from_uid)

                                            #notify user they are verified
                                            sender.sendtextmessage( targetmode=1, target=rec_from_id, msg=bot_msg_success)
                                    else:
                                            #Auth Failed
                                            sender.sendtextmessage( targetmode=1, target=rec_from_id, msg=bot_msg_fail)
                                else:
                                        TS3Auth.log("Received API Auth from %s, but %s is already verified. Notified user as such." %(rec_from_name,rec_from_name))
                                        sender.sendtextmessage( targetmode=1, target=rec_from_id, msg=bot_msg_alrdy_verified)
                            else:
                                # client limit is set and hit
                                sender.sendtextmessage( targetmode=1, target=rec_from_id, msg=bot_msg_limit_Hit)
                                TS3Auth.log("Received API Auth from %s, but %s has reached the client limit." %(rec_from_name,rec_from_name))

                    else: 
                        sender.sendtextmessage( targetmode=1, target=rec_from_id, msg=bot_msg_rcv_default)
                        TS3Auth.log("Received bad response from %s [msg= %s]" %(rec_from_name,raw_cmd.encode('utf-8')))
        except:
                TS3Auth.log('BOT Event: Something went wrong during message received from teamspeak server. Likely bad user command/message.')

                
        return None
Esempio n. 16
0
def my_event_handler(sender, event):
    """
        *sender* is the TS3Connection instance, that received the event.

        *event* is a ts3.response.TS3Event instance, that contains the name
        of the event and the data.
        """
    if DEBUG:
        print("\nEvent:")
        #print("  sender:", sender)
        print("  event.event:", event.event)
        print("  event.parsed:", event.parsed)
        print("\n\n")

    raw_cmd = event.parsed[0].get('msg')
    rec_from_name = event.parsed[0].get('invokername').encode(
        'utf-8')  #fix any encoding issues introdcued by Teamspeak
    rec_from_uid = event.parsed[0].get('invokeruid')
    rec_from_id = event.parsed[0].get('invokerid')
    rec_type = event.parsed[0].get('targetmode')

    if rec_from_uid == 'serveradmin':
        return  #ignore any serveradmin messages, aka seeing our own messages.
    try:
        # Type 2 means it was channel text
        if rec_type == '2':
            cmd = commandCheck(
                raw_cmd
            )  #sanitize the commands but also restricts commands to a list of known allowed commands

            #
            if cmd == 'verifyme':
                if BOT.clientNeedsVerify(rec_from_uid):
                    TS3Auth.log(
                        "Verify Request Recieved from user '%s'. Sending PM now...\n        ...waiting for user response."
                        % rec_from_name)
                    sender.sendtextmessage(targetmode=1,
                                           target=rec_from_id,
                                           msg=locale.get("bot_msg_verify"))
                else:
                    TS3Auth.log(
                        "Verify Request Recieved from user '%s'. Already verified, notified user."
                        % rec_from_name)
                    sender.sendtextmessage(
                        targetmode=1,
                        target=rec_from_id,
                        msg=locale.get("bot_msg_alrdy_verified"))

        # Type 1 means it was a private message
        elif rec_type == '1':
            #reg_api_auth='\s*(\S+\s*\S+\.\d+)\s+(.*?-.*?-.*?-.*?-.*)\s*$'
            reg_api_auth = '\s*(.*?-.*?-.*?-.*?-.*)\s*$'

            #Command for verifying authentication
            if re.match(reg_api_auth, raw_cmd):
                pair = re.search(reg_api_auth, raw_cmd)
                uapi = pair.group(1)

                if BOT.clientNeedsVerify(rec_from_uid):

                    TS3Auth.log("Received verify response from %s" %
                                rec_from_name)
                    auth = TS3Auth.auth_request(uapi)

                    if DEBUG:
                        TS3Auth.log('Name: |%s| API: |%s|' % (auth.name, uapi))

                    if auth.success:

                        limit_hit = BOT.TsClientLimitReached(auth.name)
                        if DEBUG:
                            print("Limit hit check: %s" % limit_hit)

                        if not limit_hit:
                            TS3Auth.log(
                                "Setting permissions for %s as verified." %
                                rec_from_name)

                            #set permissions
                            BOT.setPermissions(rec_from_uid)

                            #get todays date
                            today_date = datetime.date.today()

                            #Add user to database so we can query their API key over time to ensure they are still on our server
                            BOT.addUserToDB(rec_from_uid, auth.name, uapi,
                                            today_date, today_date)
                            print("Added user to DB with ID %s" % rec_from_uid)

                            #notify user they are verified
                            sender.sendtextmessage(
                                targetmode=1,
                                target=rec_from_id,
                                msg=locale.get("bot_msg_success"))
                        else:
                            # client limit is set and hit
                            sender.sendtextmessage(
                                targetmode=1,
                                target=rec_from_id,
                                msg=locale.get("bot_msg_limit_Hit"))
                            TS3Auth.log(
                                "Received API Auth from %s, but %s has reached the client limit."
                                % (rec_from_name, rec_from_name))

                    else:
                        #Auth Failed
                        sender.sendtextmessage(targetmode=1,
                                               target=rec_from_id,
                                               msg=locale.get("bot_msg_fail"))
                else:
                    TS3Auth.log(
                        "Received API Auth from %s, but %s is already verified. Notified user as such."
                        % (rec_from_name, rec_from_name))
                    sender.sendtextmessage(
                        targetmode=1,
                        target=rec_from_id,
                        msg=locale.get("bot_msg_alrdy_verified"))

            else:
                sender.sendtextmessage(targetmode=1,
                                       target=rec_from_id,
                                       msg=locale.get("bot_msg_rcv_default"))
                TS3Auth.log("Received bad response from %s [msg= %s]" %
                            (rec_from_name, raw_cmd.encode('utf-8')))
    except Exception as e:
        TS3Auth.log(
            'BOT Event: Something went wrong during message received from teamspeak server. Likely bad user command/message.'
        )
        TS3Auth.log(e)

    return None
Esempio n. 17
0
                        TS3Auth.log("Received bad response from %s [msg= %s]" %(rec_from_name,raw_cmd.encode('utf-8')))
        except:
                TS3Auth.log('BOT Event: Something went wrong during message received from teamspeak server. Likely bad user command/message.')

                
        return None

#######################################


#######################################
# Begins the connect to Teamspeak
#######################################

bot_loop_forever=True
TS3Auth.log("Initializing script....")
while bot_loop_forever:
        try:
                TS3Auth.log("Connecting to Teamspeak server...")
                with ts3.query.TS3Connection(host,port) as ts3conn:

                    try:
                        ts3conn.login(client_login_name=user,client_login_password=passwd)

                    except ts3.query.TS3QueryError as err:
                        TS3Auth.log("Login Failed Reason: %s" %err.resp.error["msg"])
                        exit(1)
                    #Force connection to stay up by sending an alive message every 250 seconds
                    ts3conn.keepalive(interval=250)

                    #Choose which server instance we want to join (unless multiple exist the default of 1 should be fine)
Esempio n. 18
0
def my_event_handler(sender, event):
    """
    *sender* is the TS3Connection instance, that received the event.

    *event* is a ts3.response.TS3Event instance, that contains the name
    of the event and the data.
    """
    if DEBUG:
        print("\nEvent:")
        print("  sender:", sender)
        print("  event.event:", event.event)
        print("  event.parsed:", event.parsed)
        print("\n\n")

    raw_cmd = event.parsed[0].get('msg')
    rec_from_name = event.parsed[0].get('invokername')
    rec_from_name=rec_from_name.encode('utf-8')
    rec_from_id = event.parsed[0].get('invokerid')
    rec_type = event.parsed[0].get('targetmode')

    # Type 2 means it was channel text
    if rec_type == '2':
        # sanitize the commands but also restricts commands to a list of known
        # allowed commands
        cmd = commandCheck(raw_cmd)

        #
        if cmd == 'verifyme':
            if BOT.clientNeedsVerify(rec_from_id):
                TS3Auth.log(
                    "Verify Request Recieved from user '%s'. Sending PM now...\n        ...waiting for user response." % rec_from_name)
                sender.sendtextmessage(
                    targetmode=1, target=rec_from_id, msg=bot_msg_verify)
            else:
                TS3Auth.log(
                    "Verify Request Recieved from user '%s'. Already verified, notified user." % rec_from_name)
                sender.sendtextmessage(
                    targetmode=1, target=rec_from_id, msg=bot_msg_alrdy_verified)

        elif cmd == 'setguild':
            if BOT.clientNeedsVerify(rec_from_id):
                TS3Auth.log(
                    "Received Guild Set request from '%s' but user is not verified. Sending PM requesting to verify first." % rec_from_name)
                sender.sendtextmessage(
                    targetmode=1, target=rec_from_id, msg=bot_msg_sguild_nv)
            else:
                TS3Auth.log(
                    "Received Guild Set request from user '%s'. Sending PM to begin changing tags." % rec_from_name)
                sender.sendtextmessage(
                    targetmode=1, target=rec_from_id, msg=bot_msg_sguild)

    # Type 1 means it was a private message
    elif rec_type == '1':
        reg_api_auth = '\s*(.+?\.\d+)\s+(.*?-.*?-.*?-.*?-.*)\s*$'
        reg_guild_auth = '\s*(.*?-.*?-.*?-.*?-.*)\s*$'

        # Command for verifying authentication
        if re.match(reg_api_auth, raw_cmd):
            pair = re.search(reg_api_auth, raw_cmd)
            uname = pair.group(1)
            uapi = pair.group(2)

            limit_hit = BOT.TsClientLimitReached(uname)
            if DEBUG:
                print("Limit hit check: %s" % limit_hit)
            if not limit_hit:
                if BOT.clientNeedsVerify(rec_from_id):
                    TS3Auth.log("Received verify response from %s" %
                                rec_from_name)
                    auth = TS3Auth.auth_request(uapi, uname)
                    if DEBUG:
                        TS3Auth.log('Name: |%s| API: |%s|' % (uname, uapi))
                    if auth.success:
                        TS3Auth.log(
                            "Setting permissions for %s as verified." % rec_from_name)

                        # set permissions
                        BOT.setPermissions(rec_from_id)

                        # get todays date
                        today_date = datetime.date.today()

                        # Add user to database so we can query their API key
                        # over time to ensure they are still on our server
                        BOT.addUserToDB(rec_from_id, uname,
                                        uapi, today_date, today_date)

                        # notify user they are verified
                        sender.sendtextmessage(
                            targetmode=1, target=rec_from_id, msg=bot_msg_success)
                    else:
                        # Auth Failed
                        sender.sendtextmessage(
                            targetmode=1, target=rec_from_id, msg=bot_msg_fail)
                else:
                    TS3Auth.log("Received API Auth from %s, but %s is already verified. Notified user as such." % (
                        rec_from_name, rec_from_name))
                    sender.sendtextmessage(
                        targetmode=1, target=rec_from_id, msg=bot_msg_alrdy_verified)
            else:
                # client limit is set and hit
                sender.sendtextmessage(
                    targetmode=1, target=rec_from_id, msg=bot_msg_limit_Hit)
                TS3Auth.log("Received API Auth from %s, but %s has reached the client limit." % (
                    rec_from_name, rec_from_name))

        # Command for setguild tags
        elif re.match(reg_guild_auth, raw_cmd):
            if BOT.clientNeedsVerify(rec_from_id):
                TS3Auth.log("Received Guild Auth from %s, but %s isn't verified. Notified user as such." % (
                    rec_from_name, rec_from_name))
                sender.sendtextmessage(
                    targetmode=1, target=rec_from_id, msg=bot_msg_gld_needs_auth)
            else:
                TS3Auth.log("Received Guild Auth from %s. Sending contents to user for selection." % (
                    rec_from_name))
                auth = TS3Auth.auth_request(
                    re.search(reg_guild_auth, raw_cmd).group(1).strip(),)
                self.user_sessions.append()
                sender.sendtextmessage(targetmode=1, target=rec_from_id, msg='%s\n%s\n\n' % (
                    bot_msg_gld_list, auth.guild_tags))

        #Had to encode bot nickname to match the encoded rec_from_name for a
        # proper one to one match, otherwise the bot messages itself to oblivion.. reading it's own message
        elif rec_from_name != BOT.nickname.encode('utf-8'):
            sender.sendtextmessage(
                targetmode=1, target=rec_from_id, msg=bot_msg_rcv_default)
            TS3Auth.log("Received bad response from %s [msg= %s]" % (
                rec_from_name, raw_cmd))

    return None