def floodOver(self): cur = self.timers.pop(0) for timer in self.timers: if timer[0] == cur[0]: return ts3lib.printMessage( cur[0], "{} [color=green][b]expired!".format(self.name), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def onServerErrorEvent(self, schid, errorMessage, error, returnCode, extraMessage): if not returnCode in self.retcodes: return False reason = "finished" self.perms["processed"] += 1 if error == ERROR_ok: self.perms["success"] += 1 elif error == ERROR_client_is_flooding: self.perms["fail"] += 1 self.perms["stop"] = True reason = "failed because of flooding" elif error in [ ERROR_permissions_client_insufficient, ERROR_permissions_insufficient_group_power, ERROR_permissions_insufficient_permission_power ]: self.perms["fail"] += 1 # if self.perms["stop"]: self.retcodes = {} # else: del self.retcodes[returnCode] if not len(self.retcodes): ts3lib.printMessage( schid, "{} {} {}".format(self.name, reason, self.perms), PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) if self.perms["stop"]: self.flood = True QTimer.singleShot(5000, self.disableFlood) elif self.perms["success"] > 0: self.getFullPerms(schid) return True
def sendCommand(name, cmd, schid=0, silent=True, reverse=False, mode=1): """ Sends a command through TS3Hook. :param mode: See enum: HookMode :param reverse: :param name: :param cmd: :param schid: :param silent: """ if schid == 0: schid = ts3lib.getCurrentServerConnectionHandlerID() if PluginHost.cfg.getboolean("general", "verbose") or not silent: ts3lib.printMessage( schid, '{timestamp} [color=orange]{name}[/color]:[color=white] {prefix}{message}' .format(timestamp=timestamp(), name=name, prefix="-" if reverse else "~", message=cmd), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) print("mode:", mode) if mode == HookMode.TS3HOOK: cmd = "{}cmd{}".format("-" if reverse else "~", cmd.replace(" ", "~s")) elif mode == HookMode.TSPATCH: cmd = "{}{}".format("-" if reverse else "~", cmd) else: raise SyntaxError("No HookMode specified!") (err, clid) = ts3lib.getClientID(schid) retcode = "" # "TS3Hook:Command:{}".format(ts3lib.createReturnCode(256)) err = ts3lib.requestSendPrivateTextMsg(schid, cmd, clid, retcode) if err != ts3defines.ERROR_ok: ts3lib.requestSendChannelTextMsg(schid, cmd, 0, retcode) if err != ts3defines.ERROR_ok: ts3lib.requestSendServerTextMsg(schid, cmd, retcode)
def printHidden(self): counts = self.getClientCounts(self.schid) if counts["hidden"]["total"] > 0: ts3lib.printMessage( self.schid, "[color=orange][b]{}[/b] users are hidden on this server!". format(counts["hidden"]["total"]), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def onPluginCommandEvent(self, schid, clid, pluginCommand): ts3lib.printMessageToCurrentTab("onPluginCommandEvent") ts3lib.printMessage( schid, "{0} PluginMessage from {1}: {2}".format(timestamp(), clientURL(clid), pluginCommand), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def sendCommand(self, cmd): ts3lib.printMessage( ts3lib.getCurrentServerConnectionHandlerID(), '{timestamp} [color=orange]{name}[/color]:[color=white] {message}'. format(timestamp=self.timestamp(), name=self.name, message=cmd), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) cmd = cmd.replace(" ", "~s") schid = ts3lib.getCurrentServerConnectionHandlerID() ts3lib.requestSendServerTextMsg(schid, "~cmd{}".format(cmd))
def log(self, logLevel, message, schid=0): ts3lib.logMessage(message, logLevel, self.name, schid) if logLevel in [LogLevel.LogLevel_DEBUG, LogLevel.LogLevel_DEVEL ] and self.debug: ts3lib.printMessage( schid if schid else ts3lib.getCurrentServerConnectionHandlerID(), '{timestamp} [color=orange]{name}[/color]: {message}'.format( timestamp=timestamp(), name=self.name, message=message), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def sendCommand(name, cmd, schid=0): if PluginHost.cfg.getboolean("general", "verbose"): ts3lib.printMessage( ts3lib.getCurrentServerConnectionHandlerID(), '{timestamp} [color=orange]{name}[/color]:[color=white] {message}'. format(timestamp=timestamp(), name=name, message=cmd), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) cmd = cmd.replace(" ", "~s") if schid == 0: schid = ts3lib.getCurrentServerConnectionHandlerID() ts3lib.requestSendServerTextMsg(schid, "~cmd{}".format(cmd))
def onClientMoveEvent(self, schid, clientID, oldChannelID, newChannelID, visibility, moveMessage): if oldChannelID != 0: return (err, mdata) = ts3lib.getClientVariable( schid, clientID, ts3defines.ClientProperties.CLIENT_META_DATA) if not mdata or mdata.strip() == "": return ts3lib.printMessage( schid, "{} {}'s Metadata: {}".format(timestamp(), clientURL(schid, clientID), mdata), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def onServerPermissionErrorEvent(self, schid, errorMessage, error, returnCode, failedPermissionID): if returnCode != self.perm[2]: return perm = self.perm ts3lib.printMessage( schid, "{}: Error setting permission [{}] #{} ({}): {} ({})".format( self.name, failedPermissionID, perm[0], perm[1], error, errorMessage), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) self.perm = (0, "", "")
def checkQueries(self): (err, clist) = ts3lib.getClientList(self.schid) for c in clist: if c in self.queries: continue else: (err, ctype) = ts3lib.getClientVariable(self.schid, c, ts3defines.ClientPropertiesRare.CLIENT_TYPE) if ctype != ts3defines.ClientType.ClientType_SERVERQUERY: continue self.queries.append(c) (err, cid) = ts3lib.getChannelOfClient(self.schid, c) # (err, channelname) = ts3lib.getChannelVariable(self.schid, cid, ts3defines.ChannelProperties.CHANNEL_NAME) ts3lib.printMessage(self.schid, "<{0}> Found Query {1} in channel {2}".format(Time(), clientURL(self.schid, c), channelURL(self.schid, cid)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def onServerErrorEvent(self, schid, errorMessage, error, returnCode, extraMessage): if error == ts3defines.ERROR_client_is_flooding: # print(self.name,"onServerErrorEvent", schid, errorMessage, error, returnCode, extraMessage) wait = int(self.regex.match(extraMessage).group(1)) timer = QTimer self.timers.append((schid, wait, timer)) timer.singleShot(wait, self.floodOver) d = timedelta(milliseconds=wait) ts3lib.printMessage( schid, "{} [color=red]Remaining Time: [b]{}[/b]".format( self.name, str(d)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def onClientIDsFinishedEvent(self, schid): if not self.waitingFor in self.query_uids: return if len(self.hqueries) > 0: # qstring = ", ".join("[url=client://{0}/{1}]{2}[/url]".format(tup) for tup in self.queries) qlist = ["[url=client://{}/{}]{}[/url]".format(*tup) for tup in self.hqueries] qstring = ", ".join(qlist) ts3lib.printMessage(schid, "<{0}> Found {1} hidden Queries with UID \"{2}\": {3}".format(Time(), len(self.hqueries), self.waitingFor, qstring), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) self.hqueries = [] if self.waitingFor == self.query_uids[0]: self.waitingFor = self.query_uids[-1] ts3lib.requestClientIDs(schid, self.query_uids[-1], self.retcode) if self.waitingFor == self.query_uids[-1]: self.waitingFor = False
def log(plugin, logLevel, message, schid=0, target=TextMessageTargetMode.TextMessageTarget_SERVER): err = ts3lib.logMessage(message, logLevel, plugin.name, schid) # type: int if err != ERROR_ok or ( logLevel in [LogLevel.LogLevel_DEBUG, LogLevel.LogLevel_DEVEL] and PluginHost.cfg.getboolean("general", "verbose")): ts3lib.printMessage( schid if schid else ts3lib.getCurrentServerConnectionHandlerID(), '{timestamp} [color=orange]{name}[/color]: {message}'.format( timestamp=timestamp(), name=plugin.name, message=message), target)
def onClientMoveEvent(self, schid, clientID, oldChannelID, newChannelID, visibility, moveMessage): pass # if oldChannelID != 0: return (err, clienttype) = ts3lib.getClientVariable( schid, clientID, ts3defines.ClientPropertiesRare.CLIENT_TYPE) if clienttype != ts3defines.ClientType.ClientType_SERVERQUERY: return # (err, channelname) = ts3lib.getChannelVariable(schid, newChannelID, ts3defines.ChannelProperties.CHANNEL_NAME) ts3lib.printMessage( schid, "<{0}> {1} switched from channel {2} to {3}".format( time(), clientURL(schid, clientID), channelURL(schid, oldChannelID), channelURL(schid, newChannelID)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def printQueries(self): (err, schids) = ts3lib.getServerConnectionHandlerList() for schid in schids: (err, cids) = ts3lib.getChannelList(schid) for cid in cids: (err, clids) = ts3lib.getChannelClientList(schid, cid) msg = [] for clid in clids: (err, ctype) = ts3lib.getClientVariable(schid, clid, ts3defines.ClientPropertiesRare.CLIENT_TYPE) if ctype != ts3defines.ClientType.ClientType_SERVERQUERY: continue msg.append(clientURL(schid, clid)) if len(msg) < 1: continue ts3lib.printMessage(schid, "<{0}> {1} has [b]{2}[/b] Query Clients: {3}".format(time(), channelURL(schid, cid), len(msg), ", ".join(msg)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def onTextMessageEvent(self, schid, targetMode, toID, fromID, fromName, fromUniqueIdentifier, message, ffIgnored): try: mClientID = ts3.getClientID(schid)[1] if (mClientID == fromID): return messageL = message.lower() start = messageL.find("/watch?v=") # youtube.com/watch?v=ID count = 9 if (start == -1): start = messageL.find("youtu.be/") # youtu.be/ID count = 9 if (start == -1): # anyother (ex: http://yt.vu/ID) start = messageL.find(".") #look for the first point start = messageL.find("/", start) #then look for the slash count = 1 #+1 for the id? if (start == -1): return end1 = message.find("[", start) end2 = message.find("]", start) if (end1 < end2): end = end1 else: end = end2 end1 = message.find("?", start + count) if (end1 < end and end1 != -1): end = end1 id = message[start + count:end] url = "https://www.googleapis.com/youtube/v3/videos?id=" + id + "&key=" + self.apiKey + "&part=snippet,status" result = urllib.request.urlopen(url) result = result.read().decode('utf-8') start = result.find('"title": "') if (start == -1): return end = result.find('"', start + 10) msg = result[start + 10:end] if (targetMode == 2): ts3.printMessage(schid, "[color=red]" + msg + "[/color]", 1) else: ts3.printMessageToCurrentTab("[color=red]" + msg + "[/color]") except: from traceback import format_exc ts3.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "PyTSon", 0)
def onNewChannelCreatedEvent(self, schid, cid, channelParentID, invokerID, invokerName, invokerUniqueIdentifier): if schid != self.schid: print(cid, "schid != self.schid") return (err, ownID) = ts3lib.getClientID(schid) if invokerID == ownID: print(cid, "invokerID == ownID") return if isPermanent(schid, cid) or isSemiPermanent(schid, cid): print("isPermanent(schid, cid) or isSemiPermanent(schid, cid)") return (error, maxclients) = ts3lib.getChannelVariable( schid, cid, ts3defines.ChannelProperties.CHANNEL_MAXCLIENTS) # (error, maxfamilyclients) = ts3lib.getChannelVariable(schid, cid, ts3defines.ChannelProperties.CHANNEL_MAXFAMILYCLIENTS) if maxclients != -1: clients = channelClientCount(schid, cid) if clients >= maxclients: print(cid, "clients >= maxclients") return (err, needed_tp) = ts3lib.getChannelVariable( schid, cid, ts3defines.ChannelPropertiesRare.CHANNEL_NEEDED_TALK_POWER) if needed_tp >= 0: (err, ownTP) = ts3lib.getClientSelfVariable( schid, ts3defines.ClientPropertiesRare.CLIENT_TALK_POWER) if int(ownTP) < needed_tp: self.request_tp = True (err, pw) = ts3lib.getChannelVariable( schid, cid, ts3defines.ChannelProperties.CHANNEL_FLAG_PASSWORD) if err == ts3defines.ERROR_ok and pw: pw = getChannelPassword(schid, cid, False, False, True) # ts3lib.verifyChannelPassword(schid, cid, pw, "passwordCracker:manual") if not pw: print(cid, "not pw") return status = getContactStatus(invokerUniqueIdentifier) if status == ContactStatus.BLOCKED: print(cid, invokerUniqueIdentifier, "blocked") return ts3lib.printMessage( schid, "{} > Joining into {}".format(self.name, channelURL(schid, cid)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) ts3lib.requestClientMove(schid, ownID, cid, pw if pw else "123")
def onClientMoveEvent(self, schid, clientID, oldChannelID, newChannelID, visibility, moveMessage): # if oldChannelID != 0: return (err, clienttype) = ts3lib.getClientVariable(schid, clientID, ts3defines.ClientPropertiesRare.CLIENT_TYPE) if clienttype != ts3defines.ClientType.ClientType_SERVERQUERY: return # (err, channelname) = ts3lib.getChannelVariable(schid, newChannelID, ts3defines.ChannelProperties.CHANNEL_NAME) if visibility == ts3defines.Visibility.ENTER_VISIBILITY: ts3lib.printMessage(schid, "<{0}> {1} enters view to channel {2}".format(Time(), clientURL(schid, clientID), channelURL(schid, newChannelID)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) elif visibility == ts3defines.Visibility.LEAVE_VISIBILITY: ts3lib.printMessage(schid, "<{0}> {1} leaves from channel {2}{3}".format(Time(), clientURL(schid, clientID), channelURL(schid, oldChannelID), " ({})".format(moveMessage) if moveMessage else ""), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) else: ts3lib.printMessage(schid, "<{0}> {1} switched from channel {2} to {3}".format(Time(), clientURL(schid, clientID), channelURL(schid, oldChannelID), channelURL(schid, newChannelID)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def onClientMoveEvent(self, schid, clientID, oldChannelID, newChannelID, visibility, moveMessage): if not self.enabled: return if self.schid != schid: return if not self.mychan: return (err, suid) = ts3lib.getServerVariable( schid, ts3defines.VirtualServerProperties.VIRTUALSERVER_UNIQUE_IDENTIFIER) if suid != self.suid: return (err, ownID) = ts3lib.getClientID(schid) if clientID == ownID: return if clientID in self.waiting and (newChannelID == 0 or newChannelID == self.mychan): # if newChannelID == self.mychan: # (err, dbid) = ts3lib.getClientVariable(schid, clientID, ts3defines.ClientPropertiesRare.CLIENT_DATABASE_ID) ts3lib.printMessage( schid, "{}: [color=orange]Removing channel mod from {}".format( self.name, self.waiting[clientID] if newChannelID == 0 else clientURL(schid, clientID)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) ts3lib.requestSetClientChannelGroup(schid, [self.sgid_guest], [self.mychan], [self.waiting[clientID]]) del self.waiting[clientID] return if newChannelID == 0 or oldChannelID != 0: return (err, sgids) = ts3lib.getClientVariableAsString( schid, clientID, ts3defines.ClientPropertiesRare.CLIENT_SERVERGROUPS) if not self.sgid_guest in intList(sgids): return # TODO Any way to get the cgid in another channel? (err, uid) = ts3lib.getClientVariable( schid, clientID, ts3defines.ClientProperties.CLIENT_UNIQUE_IDENTIFIER) if getContactStatus(uid) == ContactStatus.BLOCKED: ts3lib.printMessage( schid, "{}: [color=red]Not allowing blocked user {} in your channel.". format(self.name, clientURL(schid, clientID)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) return (err, dbid) = ts3lib.getClientVariable( schid, clientID, ts3defines.ClientPropertiesRare.CLIENT_DATABASE_ID) self.waiting[clientID] = dbid ts3lib.printMessage( schid, "{}: [color=green]Found new guest {} giving him channel mod until he's here ;)" .format(self.name, clientURL(schid, clientID)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) ts3lib.requestSetClientChannelGroup(schid, [self.cgid_mod], [self.mychan], [dbid])
def onClientKickFromChannelEvent(self, schid, clientID, oldChannelID, newChannelID, visibility, kickerID, kickerName, kickerUniqueIdentifier, kickMessage): # Own client ID and own channel (error, myid) = ts3.getClientID(schid) (error, mych) = ts3.getChannelOfClient(schid, myid) if oldChannelID == mych and not myid == kickerID: (error, cuid) = ts3.getClientVariableAsString(schid, clientID, ts3defines.ClientProperties.CLIENT_UNIQUE_IDENTIFIER) (error, cname) = ts3.getClientVariableAsString(schid, clientID, ts3defines.ClientProperties.CLIENT_NICKNAME) status = self.contactStatus(kickerUniqueIdentifier) kickerName_show = "[color=black]"+kickerName+"[/color]" if status == 0: friend = kickerName_show = "[color=#02D110]"+kickerName+"[/color]" ts3.printMessage(schid, "[color=black]‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾[/color]", ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) ts3.printMessage(schid, "[URL=client://"+str(clientID)+"/"+str(cuid)+"~"+cname+"][color=black]"+cname+"[/color][/URL] [color=black]was kicked by[/color] [URL=client://"+str(kickerID)+"/"+str(kickerUniqueIdentifier)+"~"+kickerName+"]"+kickerName_show+"[/URL]", ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) ts3.printMessage(schid, "[color=black]_____________________________________[/color]", ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def onClientMoveEvent(self, schid, clid, oldChannelID, newChannelID, visibility, moveMessage): client = self.ts3host.getUser(schid, clid) # if client.server.me.channel.cid == client.cid if not client.server.me.getChannelGroupId() in [ self.tabs[schid]["channelModGroup"], client.server.defaultChannelAdminGroup ]: return if clid in self.waiting and (newChannelID == 0 or newChannelID == self.mychan): # if newChannelID == self.mychan: # (err, dbid) = ts3lib.getClientVariable(schid, clientID, ts3defines.ClientPropertiesRare.CLIENT_DATABASE_ID) ts3lib.printMessage( schid, "{}: [color=orange]Removing channel mod from {}".format( self.name, self.waiting[clid] if newChannelID == 0 else clientURL(schid, clid)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) ts3lib.requestSetClientChannelGroup(schid, [self.sgid_guest], [self.mychan], [self.waiting[clid]]) del self.waiting[clid] return if newChannelID == 0 or oldChannelID != 0: return (err, sgids) = ts3lib.getClientVariableAsString( schid, clid, ts3defines.ClientPropertiesRare.CLIENT_SERVERGROUPS) if not self.sgid_guest in intList(sgids): return # TODO Any way to get the cgid in another channel? (err, uid) = ts3lib.getClientVariable( schid, clid, ts3defines.ClientProperties.CLIENT_UNIQUE_IDENTIFIER) if getContactStatus(uid) == ContactStatus.BLOCKED: ts3lib.printMessage( schid, "{}: [color=red]Not allowing blocked user {} in your channel.". format(self.name, clientURL(schid, clid)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) return (err, dbid) = ts3lib.getClientVariable( schid, clid, ts3defines.ClientPropertiesRare.CLIENT_DATABASE_ID) self.waiting[clid] = dbid ts3lib.printMessage( schid, "{}: [color=green]Found new guest {} giving him channel mod until he's here ;)" .format(self.name, clientURL(schid, clid)), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER) ts3lib.requestSetClientChannelGroup(schid, [self.cgid_mod], [self.mychan], [dbid])
def onClientServerQueryLoginPasswordEvent(self, schid, loginPassword): self.lastpass[schid] = loginPassword ts3lib.printMessage( schid, "Created new query login password: {}".format(loginPassword), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def clearQueries(self): self.queries = [] ts3lib.printMessage(self.schid, "<{0}> Cleared Query List".format(Time()), ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER)
def printMsg(self, msg, color='#0655d3', tserv=False): target = ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_CHANNEL if tserv: target = ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_SERVER if color: msg = BBCode.color(msg, color) ts3lib.printMessage(self.schid, msg, target)
def printMsg(self, msg, color='#0655d3'): if color: msg = BBCode.color(msg, color) ts3lib.printMessage( self.schid, msg, ts3defines.PluginMessageTarget.PLUGIN_MESSAGE_TARGET_CHANNEL)