Register for your free account! | Forgot your password?

Go Back   elitepvpers > Popular Games > Metin2 > Metin2 Private Server > Metin2 PServer Guides & Strategies
You last visited: Today at 10:31

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



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

Discussion on [R]Internet/Weblink im Chat, anklickbar. Python 2.7 within the Metin2 PServer Guides & Strategies forum part of the Metin2 Private Server category.

Reply
 
Old 07/13/2016, 05:08   #16
 
Noa_'s Avatar
 
elite*gold: 0
Join Date: May 2013
Posts: 605
Received Thanks: 580
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.
Noa_ is offline  
Old 07/13/2016, 13:35   #17
 
elite*gold: 15
Join Date: Mar 2009
Posts: 295
Received Thanks: 150
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.
Lordechen is offline  
Thanks
1 User
Old 07/13/2016, 14:57   #18
 
elite*gold: 0
Join Date: Apr 2015
Posts: 428
Received Thanks: 361
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?
#Metho is offline  
Old 07/13/2016, 15:19   #19
 
elite*gold: 15
Join Date: Mar 2009
Posts: 295
Received Thanks: 150
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.
Lordechen is offline  
Old 07/13/2016, 21:56   #20
 
elite*gold: 0
Join Date: Jun 2016
Posts: 7
Received Thanks: 4
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.
new Account("Undercover") is offline  
Thanks
1 User
Old 07/14/2016, 07:24   #21
 
»DeneX«'s Avatar
 
elite*gold: 0
Join Date: Jul 2015
Posts: 1,311
Received Thanks: 524
Danke für dein Release
»DeneX« is offline  
Old 07/25/2016, 10:46   #22
 
elite*gold: 0
Join Date: Aug 2013
Posts: 4
Received Thanks: 0
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 ::
mehmettro2 is offline  
Old 07/25/2016, 13:51   #23
 
elite*gold: 15
Join Date: Mar 2009
Posts: 295
Received Thanks: 150
Wann lernt ihr es mal?
Ohne die datei zu sehen kann euch keiner helfen.
Also bite uichat.py anhängen
Lordechen is offline  
Old 07/29/2016, 07:22   #24
 
.Liron's Avatar
 
elite*gold: 0
Join Date: May 2014
Posts: 292
Received Thanks: 520
Habe ich gesucht danke.
.Liron is offline  
Old 10/22/2016, 10:22   #25
 
xP3NG3Rx's Avatar
 
elite*gold: 50
Join Date: May 2011
Posts: 269
Received Thanks: 990
Much sexier!
(ew. need to add an exception into insultcheck for the urls )


Can handle ( | ftp.* | | | file://*)

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 },
xP3NG3Rx is offline  
Thanks
7 Users
Old 09/04/2017, 00:34   #26
 
Aioriax's Avatar
 
elite*gold: 0
Join Date: Jun 2011
Posts: 63
Received Thanks: 5
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
Aioriax is offline  
Old 12/13/2017, 23:45   #27
 
Martasovi2's Avatar
 
elite*gold: 0
Join Date: May 2012
Posts: 18
Received Thanks: 3
Unhappy

Quote:
Originally Posted by xP3NG3Rx View Post
Much sexier!
(ew. need to add an exception into insultcheck for the urls )


Can handle ( | ftp.* | | | file://*)

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!!!!
Martasovi2 is offline  
Old 12/14/2017, 14:38   #28
 
DasSchwarzeT's Avatar
 
elite*gold: 399
Join Date: Sep 2011
Posts: 5,323
Received Thanks: 3,938
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
DasSchwarzeT is offline  
Old 12/15/2017, 00:47   #29
 
xP3NG3Rx's Avatar
 
elite*gold: 50
Join Date: May 2011
Posts: 269
Received Thanks: 990
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.

xP3NG3Rx is offline  
Old 12/18/2017, 19:39   #30

 
elite*gold: 0
Join Date: Jul 2009
Posts: 2,471
Received Thanks: 5,622
Well actually you could use for the url parsing that way it should be way easier to also do whitelisting/blacklisting
.Alpha. is offline  
Reply


Similar Threads Similar Threads
[PYTHON] Minimal twitch chat client
01/29/2016 - Coding Snippets - 0 Replies
Just a very minimalistic twitch irc client in python (great to gather statistics about the chat) https://gist.github.com/0Skynet/833dd97620d44c345 520 Everything is explained with comments. Feel free to suggest improvements. import socket # twitch irc host
[Python] Chat oder Zustand auslesen?
10/13/2014 - Metin2 Private Server - 6 Replies
Hey... ich bin gerade einwenig mit Python und Metin2 am ausprobieren. Nun bin ich an einem Punkt angekommen, wo ich nicht weiterkommen :( Ich möchte gerne überprüfen, ob mein Char mit einer Aktion fertig ist z.B. angeln. Gibt es eine Funktion den Chat auszulesen oder eine Funktion um zu überprüfen, ob der Char nur rumsteht ohne (in dem Fall jetzt) zu angeln? Mfg
AVM FritzBox - Passwort durch WEBLINK rausfinden
07/03/2013 - Technical Support - 4 Replies
Hallo Ich habe mein Passwort für meine FritzBox 3131 vergessen, nun wollte ich fragen ob man es durch einen weblink (fritz.box/...../) anzeigen lassen kann? Mfg. Ich
Python - Chat Help
02/01/2013 - Metin2 Private Server - 0 Replies
Hey leute und zwar sofort zur frage ich habe einen clienten mit einem Chat Bug...Der anderen erhält die nachricht nicht also der net.SendChatPacket funktioniert irgendwie nicht kp was da falsch ist bin neu in python...naja wie kriege ich das hin das der andere meine nachricht erhält? Das Steht in der uiwhisper.py import ui import net import chat import player import app import locale import ime
Spoiler nicht anklickbar! - Grafik einfügen etc. nicht anklickbar!
12/08/2009 - Main - 3 Replies
Hallo! Ich kann leider keine Spoiler mehr anklicken,oder kann auch während ich schreibe das "dicke B" , "Schräge I , "Unterstrichene U" etc. nicht anklicken! Ich kann auch garnichts mehr anklicken während ich schreibe. Das einzigste was ich benutze,ist ein Proxy,da ich von EPVP gebannt wurde,und es mit einem Head-Admin regeln muss. Kann ich solange dagegen was machen? Oder muss ich warten,bis ich vielleicht wieder unentbannt werde? Gruß, Tigerrace - aka. TerrorPanda ___



All times are GMT +1. The time now is 10:31.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.