[R]Internet/Weblink im Chat, anklickbar. Python 2.7

07/13/2016 05:08 Noa_#16
Quote:
Originally Posted by .Raicon View Post
Bau das ganze System noch aus und denk an einen sinnvollen "Filter", dann ist das ganze vil. doch ganz praktikabel.
Bringt mir nicht das weiter auszubauen, da wir es für unseren Server eh nicht benutzen.
Ich hab mit den oberen nur getextet damit die anderen/User das verbessern, und es in einer bessere Richtung editieren können.
07/13/2016 13:35 Lordechen#17
Hallo Leute,

mal ne kleine Erweiterung.

* Nutzt das Ingame Webfenster
* Alle Links gehen https, http und www
* Funktioniert mit allen Python Versionen
* Weblinks per PM, Chat, Rufchat, Gildenchat,... versendbar
* Daten aus den Anhang des Erstellers werden nicht benötigt

uichat.py unter def __SendChatPacket(self, text, type):
wisper.py unter def SendWhisper(self):

folgendes ergänzen:
Code:
color = "FF1CC2"
text = re.sub("(^| )(http[s]?://.+?)( |$)", "\\1|cff%s|Hweblink:\\2|h\\2|h|r\\3" % (color,), text)
text = re.sub("(^| )(www\\..+?)( |$)", "\\1|cff%s|Hweblink:\\2|h\\2|h|r\\3" % (color,), text)
text = text.replace("https://", "")	
text = text.replace("http://", "")
und in der interfacemodule

Code:
	def MakeHyperlinkTooltip(self, hyperlink):
		tokens = hyperlink.split(":")
		if tokens and len(tokens):
			type = tokens[0]
			if "item" == type:
				self.hyperlinkItemTooltip.SetHyperlinkItem(tokens)
ersetzen durch

Code:
	def MakeHyperlinkTooltip(self, hyperlink):
		tokens = hyperlink.split(":")
		if tokens and len(tokens):
			type = tokens[0]
			if "item" == type:
				self.hyperlinkItemTooltip.SetHyperlinkItem(tokens)
			elif "Link" == type:
				self.OpenWebWindow(str(tokens[1]))
Viel Spass damit.
MFG Lordechen.
07/13/2016 14:57 #Metho#18
Quote:
Originally Posted by Lordechen View Post
Hallo Leute,

mal ne kleine Erweiterung.

* Nutzt das Ingame Webfenster
* Alle Links gehen https, http und www
* Funktioniert mit allen Python Versionen
* Weblinks per PM, Chat, Rufchat, Gildenchat,... versendbar
* Daten aus den Anhang des Erstellers werden nicht benötigt

uichat.py unter def __SendChatPacket(self, text, type):
wisper.py unter def SendWhisper(self):

folgendes ergänzen:
Code:
color = "FF1CC2"
text = re.sub("(^| )([url]https://.+?)([/url] |$)", "\\1|cff%s|HLink:\\2|h\\2|h|r\\3" % (color,), text)
text = re.sub("(^| )([url]http://.+?)([/url] |$)", "\\1|cff%s|HLink:\\2|h\\2|h|r\\3" % (color,), text)
text = re.sub("(^| )(www\\..+?)( |$)", "\\1|cff%s|HLink:\\2|h\\2|h|r\\3" % (color,), text)
text = text.replace("https://", "")	
text = text.replace("http://", "")
und in der interfacemodule

Code:
	def MakeHyperlinkTooltip(self, hyperlink):
		tokens = hyperlink.split(":")
		if tokens and len(tokens):
			type = tokens[0]
			if "item" == type:
				self.hyperlinkItemTooltip.SetHyperlinkItem(tokens)
ersetzen durch

Code:
	def MakeHyperlinkTooltip(self, hyperlink):
		tokens = hyperlink.split(":")
		if tokens and len(tokens):
			type = tokens[0]
			if "item" == type:
				self.hyperlinkItemTooltip.SetHyperlinkItem(tokens)
			elif "Link" == type:
				self.OpenWebWindow(str(tokens[1]))
Viel Spass damit.
MFG Lordechen.
Warum teilst du das ganze in drei re.sub-Prozesse ein?

Das Vorhaben

Code:
[EckigeKlammer]url[EckigeKlammer]
besagt, dass du entweder den Buchstaben u, r oder l erwartest.

Das Vorhaben

Code:
[EckigeKlammer]/url[EckigeKlammer]
besagt, dass du entweder das Zeichen / oder einen Buchstaben wie u, r, l erwartest. Wenn du wirklich tags machen willst, gibt's dazu flags:

PHP Code:
re.sub(flags=re.IGNORECASE)
re.sub(flags=re.I) 

Das Vorhaben

Code:
.+?
Erwartet 1 x-beliebiges Zeichen oder mehr oder garnichts. Also das gleiche wie:

Code:
.*
Das

Code:
https://
und das

Code:
http://
ist einfach nur

Code:
https?://
Wieso entfernst du danach die beiden Protokolle, dies ist wichtig und essenziell, bei einem Link
Code:
text = text.replace("https://", "")	
text = text.replace("http://", "")
Was ergibt das für einen Sinn?

PHP Code:
if tokens and len(tokens): 
Oder das?

PHP Code:
str(tokens[1]) 
Wieso typisiert man was, was bereits eine Zeichenkette ist?
07/13/2016 15:19 Lordechen#19
Bedank dich bei epvp das [url] stammt nicht von mir hat sich irgend wie rein gemogelt und wenn du meinst die Protokolle seien wichtig dann probiers aus dann wirst auch merken wiso sie gelöscht werden.
Im übrichen war das ne 2 Minuten arbeit mehr zeit opfer ich für epvp nicht wirklich und es funktioniert.
07/13/2016 21:56 new Account("Undercover")#20
Quote:
Originally Posted by #Metho View Post
Code:
.+?
Erwartet 1 x-beliebiges Zeichen oder mehr oder garnichts. Also das gleiche wie:

Code:
.*
nicht ganz richtig.

Das ? steht in diesem Fall einfach für "non-greedy", das bedeutet, dass die Bedigung ".+" solange gematcht wird, bis die nachfolgende Bedingung zutrifft. Mit optional hat das an dieser Stelle nichts zu tun.

Beispiel:
Code:
import re

text = "Hello World! Irgendein weiterer Text!"
pattern = "(.+)\\!"

print(re.match(pattern, text).group(0))

--> Hello World! Irgendein weiterer Text!
Code:
import re

text = "Hello World! Irgendein weiterer Text!"
pattern = "(.+?)\\!"

print(re.match(pattern, text).group(0))

--> Hello World!
Beim 2. (mit non-greedy operator (?)) wird alles gematcht, bis die nächste Bedingung (das einzelne Zeichen "!") zutrifft.

Beim 1. wird solange gematcht, bis die die letzte Möglichkeit der nächsten Bedingung erreicht ist.
07/14/2016 07:24 »DeneX«#21
Danke für dein Release
07/25/2016 10:46 mehmettro2#22
syserr

Code:
0725 11:44:33147 :: Traceback (most recent call last):

0725 11:44:33147 ::   File "uiChat.py", line 403, in OnIMEReturn

0725 11:44:33147 ::   File "uiChat.py", line 305, in __SendTalkingChatPacket

0725 11:44:33147 ::   File "uiChat.py", line 227, in __SendChatPacket

0725 11:44:33147 :: TypeError
0725 11:44:33147 :: : 
0725 11:44:33147 :: 'in <string>' requires character as left operand
0725 11:44:33147 ::
07/25/2016 13:51 Lordechen#23
Wann lernt ihr es mal?
Ohne die datei zu sehen kann euch keiner helfen.
Also bite uichat.py anhängen
07/29/2016 07:22 .Liron#24
Habe ich gesucht danke. :)
10/22/2016 10:22 xP3NG3Rx#25
Much sexier! :cool:
(ew. need to add an exception into insultcheck for the urls :p)
[Only registered and activated users can see links. Click Here To Register...]

Can handle ([Only registered and activated users can see links. Click Here To Register...] | ftp.* | [Only registered and activated users can see links. Click Here To Register...] | [Only registered and activated users can see links. Click Here To Register...] | file://*) [Only registered and activated users can see links. Click Here To Register...]

uiChat.py
Code:
	def GetLinks(self, string, ret):
		import re
		links = re.findall("(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])", string, re.I)
		if not (hasattr(ret, "clear") and hasattr(ret, "update")):
			return False

		ret.clear()
		map(lambda link: (ret.update({link:"|cFF00C0FC|Hweb:%s|h[%s]|h|r"%(re.sub("://", "w<?", link), link)})) if link else None, links)
		return len(links) > 0
Code:
	def __SendChatPacket(self, text, type):
#		if text[0] == '/':
#			if ENABLE_CHAT_COMMAND or constInfo.CONSOLE_ENABLE:
#				pass
#			else:
#				return

		if net.IsChatInsultIn(text):
			chat.AppendChat(chat.CHAT_TYPE_INFO, locale.CHAT_INSULT_STRING)
		else:
			links={}
			if self.GetLinks(text, links):
				for k,v in links.iteritems():
					text = text.replace(k, v)
			net.SendChatPacket(text, type)
interfaceModule.py
Code:
	def MakeHyperlinkTooltip(self, hyperlink):
		tokens = hyperlink.split(":")
		if tokens and len(tokens):
			type = tokens[0]
			if "item" == type:
				self.hyperlinkItemTooltip.SetHyperlinkItem(tokens)
			elif "web" == type:
				app.ExecuteShell(tokens[1].replace("w<?", "://"))
PythonApplicationModule.cpp
Code:
#include <Shellapi.h>
///////
PyObject* appExecuteShell(PyObject* poSelf, PyObject* poArgs)
{
	char* szPageLink;
	if (!PyTuple_GetString(poArgs, 0, &szPageLink))
		return Py_BuildException();
	int iExit;
	if (!PyTuple_GetInteger(poArgs, 1, &iExit))
		iExit=0;

	ShellExecute(0, "open", szPageLink, 0, 0, SW_SHOWNORMAL);
	if (iExit)
		PostQuitMessage(0);

	return Py_BuildNone();
}
///////
		{ "ExecuteShell",				appExecuteShell,				METH_VARARGS },
09/04/2017 00:34 Aioriax#26
This gives me syntax error:

Code:
	def GetLinks(self, string, ret):
		import re
		links = re.findall("(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])", string, re.I)
		if not (hasattr(ret, "clear") and hasattr(ret, "update")):
			return False

		ret.clear()
		map(lambda link: (ret.update({link:"|cFF00C0FC|Hweb:%s|h[%s]|h|r"%(re.sub("://", "w<?", link), link)})) if link else None, links)
		return len(links) > 0
This line in red exactly

Code:
map(lambda link: (ret.update({link:"|cFF00C0FC|Hweb:%s|h[%s]|h|r"%(re.sub("://", "w<?", link), link)})) if link else None, links)
TABS are ok
12/13/2017 23:45 Martasovi2#27
Quote:
Originally Posted by xP3NG3Rx View Post
Much sexier! :cool:
(ew. need to add an exception into insultcheck for the urls :p)
[Only registered and activated users can see links. Click Here To Register...]

Can handle ([Only registered and activated users can see links. Click Here To Register...] | ftp.* | [Only registered and activated users can see links. Click Here To Register...] | [Only registered and activated users can see links. Click Here To Register...] | file://*) [Only registered and activated users can see links. Click Here To Register...]

uiChat.py
Code:
	def GetLinks(self, string, ret):
		import re
		links = re.findall("(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])", string, re.I)
		if not (hasattr(ret, "clear") and hasattr(ret, "update")):
			return False

		ret.clear()
		map(lambda link: (ret.update({link:"|cFF00C0FC|Hweb:%s|h[%s]|h|r"%(re.sub("://", "w<?", link), link)})) if link else None, links)
		return len(links) > 0
Code:
	def __SendChatPacket(self, text, type):
#		if text[0] == '/':
#			if ENABLE_CHAT_COMMAND or constInfo.CONSOLE_ENABLE:
#				pass
#			else:
#				return

		if net.IsChatInsultIn(text):
			chat.AppendChat(chat.CHAT_TYPE_INFO, locale.CHAT_INSULT_STRING)
		else:
			links={}
			if self.GetLinks(text, links):
				for k,v in links.iteritems():
					text = text.replace(k, v)
			net.SendChatPacket(text, type)
interfaceModule.py
Code:
	def MakeHyperlinkTooltip(self, hyperlink):
		tokens = hyperlink.split(":")
		if tokens and len(tokens):
			type = tokens[0]
			if "item" == type:
				self.hyperlinkItemTooltip.SetHyperlinkItem(tokens)
			elif "web" == type:
				app.ExecuteShell(tokens[1].replace("w<?", "://"))
PythonApplicationModule.cpp
Code:
#include <Shellapi.h>
///////
PyObject* appExecuteShell(PyObject* poSelf, PyObject* poArgs)
{
	char* szPageLink;
	if (!PyTuple_GetString(poArgs, 0, &szPageLink))
		return Py_BuildException();
	int iExit;
	if (!PyTuple_GetInteger(poArgs, 1, &iExit))
		iExit=0;

	ShellExecute(0, "open", szPageLink, 0, 0, SW_SHOWNORMAL);
	if (iExit)
		PostQuitMessage(0);

	return Py_BuildNone();
}
///////
		{ "ExecuteShell",				appExecuteShell,				METH_VARARGS },
The map don't work for me :(
Code:
map(lambda link: (ret.update({link:"|cFF00C0FC|Hweb:%s|h[%s]|h|r"%(re.sub("://", "w<?", link), link)})) if link else None, links)
Code:
networkModule.py(line:208) SetSelectCharacterPhase
system.py(line:130) __pack_import
system.py(line:110) _process_result
introSelect.py(line:30) ?
system.py(line:130) __pack_import
system.py(line:110) _process_result
interfaceModule.py(line:14) ?
system.py(line:130) __pack_import

networkModule.SetSelectCharacterPhase - exceptions.SyntaxError:invalid syntax (line 1186)

1213 23:39:13195 :: ============================================================================================================
1213 23:39:13195 :: Abort!!!!
12/14/2017 14:38 DasSchwarzeT#28
Quote:
Originally Posted by Martasovi2 View Post
The map don't work for me :(
Code:
map(lambda link: (ret.update({link:"|cFF00C0FC|Hweb:%s|h[%s]|h|r"%(re.sub("://", "w<?", link), link)})) if link else None, links)
Code:
networkModule.py(line:208) SetSelectCharacterPhase
system.py(line:130) __pack_import
system.py(line:110) _process_result
introSelect.py(line:30) ?
system.py(line:130) __pack_import
system.py(line:110) _process_result
interfaceModule.py(line:14) ?
system.py(line:130) __pack_import

networkModule.SetSelectCharacterPhase - exceptions.SyntaxError:invalid syntax (line 1186)

1213 23:39:13195 :: ============================================================================================================
1213 23:39:13195 :: Abort!!!!
map() comes with Python 2.7
12/15/2017 00:47 xP3NG3Rx#29
Nope the map is available in python2.2 too, maybe the problem is the pure one-line if statement, that is not compatible w/ it. Anyway it's syntax error and not attribute or nameerror so, show a picture with whitespaces. Here it is my mine with a little modification about allowing pages but that one is commented out 'coz I'm not using it.

[Only registered and activated users can see links. Click Here To Register...]
12/18/2017 19:39 .Alpha.#30
Well actually you could use [Only registered and activated users can see links. Click Here To Register...] for the url parsing that way it should be way easier to also do whitelisting/blacklisting