I was trying to merge xAutoReply with this one to bring UI interface then set a msg easily.
Does anyone can help me to figure out what can I do to fix it?
from phBot import *
import QtBind
import struct
import json
import os
import phBotChat
pName = 'xWelcomeParty'
pVersion = '1.0'
playerData = None
textEncoding = None
enable = False
enmsgstall = False
enmsgbuy = False
folderSave = os.path.dirname(os.path.realpath(__file__))+"\\WelcomeParty"
gui = QtBind.init(__name__,pName)
btnEnable = QtBind.createButton(gui, 'enable_clicked', ' Enable WelcomeParty ', 10, 10)
lblPM = QtBind.createLabel(gui,'Welcome Messages to PM',11,35)
lblSave = QtBind.createLabel(gui,"Remember to save the configurations by clicking the 'Save' button, otherwise bad things happen.",11,240)
lblLoad = QtBind.createLabel(gui,"The 'Load' button can be used to manually reload all configs after using the Reload plugins button.",11,260)
listMsg = QtBind.createList(gui,10,50,300,150)
leMsg = QtBind.createLineEdit(gui,"",10,205,250,19)
btnAddMsg = QtBind.createButton(gui, 'addmsg_clicked', ' A ', 264, 207)
btnRemMsg = QtBind.createButton(gui, 'remmsg_clicked', ' R ', 289, 207)
btnRefresh = QtBind.createButton(gui,'btnLoad_clicked'," Load ",140,10)
btnSave = QtBind.createButton(gui,'btnSave_clicked'," Save ",185,10)
if not os.path.exists(folderSave):
os.makedirs(folderSave)
def btnSave_clicked():
global playerData
global enable
countmsg = 0
if playerData:
data = {}
if os.path.exists(get_autoreply_path()):
with open(get_autoreply_path(), 'r') as f:
data = json.load(f)
if not "Enabled" in data:
data['Enabled'] = False
if not "MsgList" in data:
data['MsgList'] = []
data['Enabled'] = enable
data['MsgList'] = []
countmsg = len(QtBind.getItems(gui,listMsg))
if countmsg > 0:
for msg in QtBind.getItems(gui,listMsg):
data['MsgList'].append(msg)
with open(get_autoreply_path(),"w") as f:
f.write(json.dumps(data, indent=4, sort_keys=True))
log("AutoReply: saved configs")
def enable_clicked():
global enable
if enable == False:
enable = True
QtBind.setText(gui,btnEnable,' Disable WelcomeParty ')
log("WelcomeParty: enabled")
else:
enable = False
QtBind.setText(gui,btnEnable,' Enable WelcomeParty ')
log("WelcomeParty: disabled")
def btnLoad_clicked():
global playerData
playerData = get_character_data()
if playerData:
configs_load()
def addmsg_clicked():
msg = QtBind.text(gui,leMsg)
if len(msg) > 0 and len(msg) <= 100:
QtBind.append(gui,listMsg,msg)
log("WelcomeParty: added message to the list")
QtBind.clear(gui,leMsg)
elif len(msg) == 0:
log("WelcomeParty: the message has to be longer than 0 characters")
elif len(msg) > 100:
log("WelcomeParty: the message can only be up to 100 characters long; your message has "+str(len(msg))+" characters")
def remmsg_clicked():
selectedItem = QtBind.text(gui,listMsg)
if selectedItem:
QtBind.remove(gui,listMsg,selectedItem)
log("WelcomeParty: removed message from the list")
def teleported():
global playerData
global textEncoding
textEncoding = get_encoding()
playerData = get_character_data()
configs_load()
def get_autoreply_path():
return folderSave+"\\"+ playerData['server'] + "_" + playerData['name'] + ".json"
def configs_load():
global enable
global enmsgstall
global enmsgbuy
if os.path.exists(get_autoreply_path()):
data = {}
with open(get_autoreply_path(),"r") as f:
data = json.load(f)
if "Enabled" in data:
if data['Enabled'] == True:
QtBind.setText(gui,btnEnable,' Disable WelcomeParty ')
enable = True
elif data['Enabled'] == False:
QtBind.setText(gui,btnEnable,' Enable WelcomeParty ')
enable = False
if "MsgList" in data:
QtBind.clear(gui,listMsg)
for msg in data["MsgList"]:
QtBind.append(gui,listMsg,msg)
log("WelcomeParty: loaded configs")
# else:
# log("WelcomeParty: didn't find any configuration file, please configure and save your messages")
def handle_joymax(opcode, data):
global playerData
global textEncoding
global enable
if opcode == 0x3E6E:
msglist = QtBind.getItems(gui,listMsg)
index = 6
indexstall = 0
myname = playerData['name']
index += 2
if data[index] == 0x02 and enable == True:
Character = ""
index += 1
CharacterLength = struct.unpack_from('<H', data, index)[0]
index += 2
Character = struct.unpack_from('<' + str(CharacterLength) + 's', data, index)[0].decode('cp1252')
if msglist != []:
for msg in msglist:
phBotChat.Private(Character,str(msg))
if QtBind.isChecked(gui,btnEnable):
phBotChat.Party('Welcome my party' %CharName)
log('Plugin: [%s] Joined Your Party.. Sending a lovely welcome message' %CharName)
return True
log("Plugin: "+pName+" v"+pVersion+" successfully loaded")