Trsro XFgwDropChecker WhiteList

Could you please review the codes and add them to the whitelist? @Ryan

from phBot import *
import QtBind
import re
import os
import json
from threading import *
import threading
import time

pName = 'xFgwDropChecker'
pVersion = '1.0.5'

# ______________________________ ' Initializing ' ______________________________ #

# Graphic user interface 
gui = QtBind.init(__name__,pName)
lblCard = QtBind.createLabel(gui,'Talisman Drop List ',10,5)
lblPetBuff = QtBind.createLabel(gui,'Pet Buff Drop List ',160,5)
lblShield = QtBind.createLabel(gui,'Power Shield Drop List ',310,5)
lblAlert = QtBind.createLabel(gui,'If in Alert List ',462,145)
btnAddItem = QtBind.createButton(gui,'btnAddItem_clicked',"      Add     ",610,185)
btnRemItem = QtBind.createButton(gui,'btnRemItem_clicked',"       Remove       ",610,215)
tbxItems = QtBind.createLineEdit(gui,"",610,160,110,20)
cbxEventLoop = QtBind.createCheckBox(gui, 'EventLoop_checked','Item Drop Checker',610,20)


def EventLoop_checked(checked):
	saveConfigs()
def gcdrop_clicked(checked):
	saveConfigs()

def saveConfigs():
	# Save if data has been loaded
	if isJoined():
		# Save all data
		data = {}

		data['Items'] = checklist2
		data['Items2'] = checklist
		data['Item Drop Alert'] = QtBind.isChecked(gui,cbxSoxDrop)
		data['Item Drop Checker'] = QtBind.isChecked(gui,cbxEventLoop)

		# Overrides
		with open(getConfig(),"w") as f:
			f.write(json.dumps(data, indent=4, sort_keys=True))

cbxSoxDrop = QtBind.createCheckBox(gui,'gcdrop_clicked','Item Drop Alert',610,40) 
FIXSOUNDPATH = 'c:\\Windows\\Media\\chimes.wav'


list1 = QtBind.createList(gui,10,20,140,280)
list2 = QtBind.createList(gui,160,20,140,280)
list3 = QtBind.createList(gui,310,20,140,280)
list4 = QtBind.createList(gui,460,160,140,140)
checklist = []
checklist2 = []
uids = set()


# Return xInjectLeader folder path
def getPath():
	return get_config_dir()+pName+"\\"

# Return character configs path (JSON)
def getConfig():
	return getPath()+inGame['server'] + "_" + inGame['name'] + ".json"

# Check if character is ingame
def isJoined():
	global inGame
	inGame = get_character_data()
	if not (inGame and "name" in inGame and inGame["name"]):
		inGame = None
	return inGame

# Load default configs
def loadDefaultConfig():
	# Clear data
	QtBind.clear(gui,list4)
	QtBind.setChecked(gui,cbxEventLoop,False)
	QtBind.setChecked(gui,cbxSoxDrop,False)

# Loads all config previously saved
def loadConfigs():
	loadDefaultConfig()
	if isJoined():
		# Check config exists to load
		if os.path.exists(getConfig()):
			data = {}
			with open(getConfig(),"r") as f:
				data = json.load(f)
			if "Items" in data:
				for nickname in data["Items"]:
					QtBind.append(gui,list4,nickname)
					checklist2.append(nickname)
			if 'Item Drop Checker' in data and data['Item Drop Checker']:
				QtBind.setChecked(gui,cbxEventLoop,True)
			if 'Item Drop Alert' in data and data['Item Drop Alert']:
				QtBind.setChecked(gui,cbxSoxDrop,True)


def btnAddItem_clicked(): # Sereness's tears
	if inGame:
		player = QtBind.text(gui,tbxItems)
		# Player nickname it's not empty
		if player and not lstItems_exist(player):
			# Init dictionary
			data = {}
			# Load config if exist
			if os.path.exists(getConfig()):
				with open(getConfig(), 'r') as f:
					data = json.load(f)
			# Add new leader
			if not "Items" in data:
				data['Items'] = []
			data['Items'].append(player)
			if not "Item Drop Checker" in data:
				data['Item Drop Checker'] = []
			data['Item Drop Checker'] = QtBind.isChecked(gui,cbxEventLoop)
			# Replace configs
			with open(getConfig(),"w") as f:
				f.write(json.dumps(data, indent=4, sort_keys=True))
			checklist2.append(player)
			QtBind.append(gui,list4,player)
			QtBind.setText(gui, tbxItems,"")
			log('Plugin: Item added ['+player+']')

def btnRemItem_clicked():
	if inGame:
		selectedItem = QtBind.text(gui,list4)
		if selectedItem:
			if os.path.exists(getConfig()):
				data = {"Items":[]}
				with open(getConfig(), 'r') as f:
					data = json.load(f)
				try:
					# remove leader nickname from file if exists
					data["Items"].remove(selectedItem)
					with open(getConfig(),"w") as f:
						f.write(json.dumps(data, indent=4, sort_keys=True))
				except:
					pass # just ignore file if doesn't exist
			checklist2.remove(selectedItem)
			QtBind.remove(gui,list4,selectedItem)
			log('Plugin: Item removed ['+selectedItem+']')

def lstItems_exist(nickname):
	nickname = nickname.lower()
	players = QtBind.getItems(gui,list4)
	for i in range(len(players)):
		if players[i].lower() == nickname:
			return True
	return False

# Called when the bot successfully connects to the game server
def connected():
	global inGame
	inGame = None

# Called when the character enters the game world
def joined_game():
	loadConfigs()

def event_loop():
	drops = get_drops()
	pattern = "TALISMAN"
	pattern2 = "PET2_ENC"
	pattern3 = "PET2_ASS"
	pattern4 = "PET2_PRO"
	pattern5 = "ITEM_EU_SHIELD_11_SET_A_RARE"
	pattern6 = "ITEM_CH_SHIELD_11_SET_A_RARE"
	servername = ''
	if QtBind.isChecked(gui,cbxEventLoop) :
		for drop in drops:
			currentUid = drop
			name = drops[drop]['name']
			servername = drops[drop]['servername']
			itemdata = "%s" % (name)
			itemdata2 = "%s" % (name)
			itemdata3 = "%s" % (name)
			result = re.search(pattern, servername)
			result2 = re.search(pattern2, servername) or re.search(pattern3, servername) or re.search(pattern4, servername)
			result3 = re.search(pattern5, servername) or re.search(pattern6, servername)
			if result and currentUid not in uids:
				QtBind.append(gui,list1,itemdata)
				checklist.append(itemdata)
			if result2 and currentUid not in uids:
				QtBind.append(gui,list2,itemdata2)
				checklist.append(itemdata2)
			if result3 and currentUid not in uids:
				QtBind.append(gui,list3,itemdata3)
				checklist.append(itemdata3)
			if result or result2 or result3 and currentUid not in uids :
				for name in checklist :
					if name in checklist2:
						soxdroptrigger()
						checklist.clear()
			uids.add(currentUid)

def soxdroptrigger():
	if QtBind.isChecked(gui,cbxSoxDrop):
		x = threading.Thread(target=soxdropalert)
		x.start()

def soxdropalert():
	for x in range(1,11):
		play_wav(FIXSOUNDPATH)
		time.sleep(1.0)
		if x == 10 :
			QtBind.setChecked(gui,cbxSoxDrop,True)

def teleported():
	uids.clear()





QtBind.createButton(gui,'clearlistgui',"  Clear List (Talisman) ",460,20)
QtBind.createButton(gui,'clearlistgui2',"  Clear List (Pet Buff) ",460,50)
QtBind.createButton(gui,'clearlistgui3',"  Clear List (Power Shield) ",460,80)
QtBind.createButton(gui,'clearlistgui4',"  Clear List (ALL) ",460,110)

def clearlistgui() : 
	QtBind.clear(gui,list1)
def clearlistgui2() : 
	QtBind.clear(gui,list2)
def clearlistgui3() : 
	QtBind.clear(gui,list3)
def clearlistgui4() : 
	QtBind.clear(gui,list1)
	QtBind.clear(gui,list2)
	QtBind.clear(gui,list3)

# Plugin loaded
log('Plugin: '+pName+' v'+pVersion+' succesfully loaded')

if os.path.exists(getPath()):
	# Adding RELOAD plugin support
	loadConfigs()
else:
	# Creating configs folder
	os.makedirs(getPath())
	log('Plugin: '+pName+' folder has been created, ** Again Reload Plugin TAB **')

@Ryan Can you whitelist this plugin for trsro?