[C++/Python]Weblink în Chat
P.S: Întotdeauna când umblați într-un fișier .py este recomandată deschiderea cu Notepad++ și configurarea programului astfel:
- Afișare->Arată simboluri->Afișare spații libere și Tab-uri
- Codificare->Set de caractere->Central European->Windows
- În Python va trebui să fiți mereu atent la tab-uri sa nu aveți eventuale erori
Deschideți uiChat.py din root și căutați
Cod: Selectaţi tot
elif chat.CHAT_TYPE_SHOUT == self.GetChatMode():
self.SetChatMode(chat.CHAT_TYPE_TALKING)
self.SetText("")
self.__CheckChatMark()
Cod: Selectaţi tot
if app.LINK_IN_CHAT:
def GetLink(self, text):
link = ""
start = text.find("http://")
if start == -1:
start = text.find("https://")
if start == -1:
return ""
return text[start:len(text)].split(" ")[0]
Cod: Selectaţi tot
def __SendChatPacket(self, text, type):
Cod: Selectaţi tot
def __SendChatPacket(self, text, type):
if net.IsChatInsultIn(text):
chat.AppendChat(chat.CHAT_TYPE_INFO, locale.CHAT_INSULT_STRING)
else:
if app.LINK_IN_CHAT:
link = self.GetLink(text)
if link != "":
import chr
if not chr.IsGameMaster():
text = text.replace(link, "|cFF00C0FC|h|Hweb:" + link.replace("://", "XxX") + "|h" + link + "|h|r")
else:
text = text.replace(link, "|cFF00C0FC|h|Hsysweb:" + link.replace("://", "XxX") + "|h" + link + "|h|r")
Cod: Selectaţi tot
def SendWhisper(self):
Cod: Selectaţi tot
def SendWhisper(self):
import time
text = self.chatLine.GetText()
textLength = len(text)
if textLength > 0:
if app.LINK_IN_CHAT:
link = self.GetLink(text)
if link != "":
import chr
if not chr.IsGameMaster():
text = text.replace(link, "|cFF00C0FC|h|Hweb:" + link.replace("://", "XxX") + "|h" + link + "|h|r")
else:
text = text.replace(link, "|cFF00C0FC|h|Hsysweb:" + link.replace("://", "XxX") + "|h" + link + "|h|r")
if net.IsInsultIn(text):
chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.CHAT_INSULT_STRING)
return
Saat = time.strftime("%H:%M:%S")
net.SendWhisperPacket(self.targetName, ": |cFFFFA500|h(Lv. " + str(player.GetStatus(player.LEVEL)) + ") " "(Ora " + Saat + "):|cff00ff00|h " + text)
self.chatLine.SetText("")
chat.AppendWhisper(chat.WHISPER_TYPE_CHAT, self.targetName, player.GetName() + ": |cFFFFA500|h(Lv. " + str(player.GetStatus(player.LEVEL)) + ") " "(Ora " + Saat + "): " + text)
Cod: Selectaţi tot
if app.LINK_IN_CHAT:
def GetLink(self, text):
link = ""
start = text.find("http://")
if start == -1:
start = text.find("https://")
if start == -1:
return ""
return text[start:len(text)].split(" ")[0]
Cod: Selectaţi tot
if app.LINK_IN_CHAT:
def GetLink(self, text):
link = ""
start = text.find("http://")
if start == -1:
start = text.find("https://")
if start == -1:
return ""
return text[start:len(text)].split(" ")[0]
Deschideți interfacemodule.py din root și căutați
Cod: Selectaţi tot
import localeInfo
Cod: Selectaţi tot
if app.LINK_IN_CHAT:
import os
Cod: Selectaţi tot
self.wndGuildBuilding = None
Cod: Selectaţi tot
if app.LINK_IN_CHAT:
self.OpenLinkQuestionDialog = None
Cod: Selectaţi tot
self.DRAGON_SOUL_IS_QUALIFIED
Cod: Selectaţi tot
if app.LINK_IN_CHAT:
def AnswerOpenLink(self, answer):
if not self.OpenLinkQuestionDialog:
return
self.OpenLinkQuestionDialog.Close()
self.OpenLinkQuestionDialog = None
if not answer:
return
link = constInfo.link
os.system(link)
Cod: Selectaţi tot
def MakeHyperlinkTooltip(self, hyperlink):
Cod: Selectaţi tot
def MakeHyperlinkTooltip(self, hyperlink):
tokens = hyperlink.split(":")
if tokens and len(tokens):
type = tokens[0]
if "item" == type:
self.hyperlinkItemTooltip.SetHyperlinkItem(tokens)
elif "msg" == type and str(tokens[1]) != player.GetMainCharacterName():
self.OpenWhisperDialog(str(tokens[1]))
elif app.LINK_IN_CHAT and "web" == type and tokens[1].startswith("httpXxX") or "web" == type and tokens[1].startswith("httpsXxX"):
OpenLinkQuestionDialog = uiCommon.QuestionDialog2()
OpenLinkQuestionDialog.SetText1(localeInfo.CHAT_OPEN_LINK_DANGER)
OpenLinkQuestionDialog.SetText2(localeInfo.CHAT_OPEN_LINK)
OpenLinkQuestionDialog.SetAcceptEvent(lambda arg=TRUE: self.AnswerOpenLink(arg))
OpenLinkQuestionDialog.SetCancelEvent(lambda arg=FALSE: self.AnswerOpenLink(arg))
constInfo.link = "start " + tokens[1].replace("XxX", "://").replace("&","^&")
OpenLinkQuestionDialog.Open()
self.OpenLinkQuestionDialog = OpenLinkQuestionDialog
elif app.LINK_IN_CHAT and "sysweb" == type:
os.system("start " + tokens[1].replace("XxX", "://"))
Cod: Selectaţi tot
CHAT_OPEN_LINK_DANGER Atentie: Acest link poate contine un virus!
CHAT_OPEN_LINK Doresti sa deschizi acest link ?
Cod: Selectaţi tot
#define LINK_IN_CHAT
Cod: Selectaţi tot
#ifdef LINK_IN_CHAT
PyModule_AddIntConstant(poModule, "LINK_IN_CHAT", 1);
#else
PyModule_AddIntConstant(poModule, "LINK_IN_CHAT", 0);
#endif
Căutați
Cod: Selectaţi tot
PyObject * chatGetLinkFromHyperlink(PyObject * poSelf, PyObject * poArgs)
{
char * szHyperlink;
if (!PyTuple_GetString(poArgs, 0, &szHyperlink))
return Py_BuildException();
std::string stHyperlink(szHyperlink);
std::vector<std::string> results;
split_string(stHyperlink, ":", results, false);
if (0 == results[0].compare("item"))
{
if (results.size() < 6)
return Py_BuildValue("s", "");
CItemData * pItemData = NULL;
if (CItemManager::Instance().GetItemDataPointer(htoi(results[1].c_str()), &pItemData))
{
char buf[1024] = { 0 };
char itemlink[256];
int len;
bool isAttr = false;
len = snprintf(itemlink, sizeof(itemlink), "item:%x:%x:%x:%x:%x",
htoi(results[1].c_str()),
htoi(results[2].c_str()),
htoi(results[3].c_str()),
htoi(results[4].c_str()),
htoi(results[5].c_str()));
if (results.size() >= 8)
{
for (int i = 6; i < results.size(); i += 2)
{
len += snprintf(itemlink + len, sizeof(itemlink) - len, ":%x:%d",
htoi(results[i].c_str()),
atoi(results[i+1].c_str()));
isAttr = true;
}
}
if (isAttr)
snprintf(buf, sizeof(buf), "|cffffc700|H%s|h[%s]|h|r", itemlink, pItemData->GetName());
else
snprintf(buf, sizeof(buf), "|cfff1e6c0|H%s|h[%s]|h|r", itemlink, pItemData->GetName());
return Py_BuildValue("s", buf);
}
}
return Py_BuildValue("s", "");
}
Cod: Selectaţi tot
PyObject * chatGetLinkFromHyperlink(PyObject * poSelf, PyObject * poArgs)
{
char * szHyperlink;
if (!PyTuple_GetString(poArgs, 0, &szHyperlink))
return Py_BuildException();
std::string stHyperlink(szHyperlink);
std::vector<std::string> results;
split_string(stHyperlink, ":", results, false);
if (0 == results[0].compare("item"))
{
if (results.size() < 6)
return Py_BuildValue("s", "");
CItemData * pItemData = NULL;
if (CItemManager::Instance().GetItemDataPointer(htoi(results[1].c_str()), &pItemData))
{
char buf[1024] = { 0 };
char itemlink[256];
int len;
bool isAttr = false;
len = snprintf(itemlink, sizeof(itemlink), "item:%x:%x:%x:%x:%x",
htoi(results[1].c_str()),
htoi(results[2].c_str()),
htoi(results[3].c_str()),
htoi(results[4].c_str()),
htoi(results[5].c_str()));
if (results.size() >= 8)
{
for (int i = 6; i < results.size(); i += 2)
{
len += snprintf(itemlink + len, sizeof(itemlink) - len, ":%x:%d",
htoi(results[i].c_str()),
atoi(results[i+1].c_str()));
isAttr = true;
}
}
if (isAttr)
snprintf(buf, sizeof(buf), "|cffffc700|H%s|h[%s]|h|r", itemlink, pItemData->GetName());
else
snprintf(buf, sizeof(buf), "|cfff1e6c0|H%s|h[%s]|h|r", itemlink, pItemData->GetName());
return Py_BuildValue("s", buf);
}
}
#ifdef LINK_IN_CHAT
else if (0 == results[0].compare("link"))
{
char buf[1024] = { 0 };
snprintf(buf, sizeof(buf), "|cffc9c0f1|H|h%s|h|r", results[1].c_str());
return Py_BuildValue("s", buf);
}
#endif
return Py_BuildValue("s", "");
}
Credite: ZeNu