All pastes #635358 Raw Edit

Talk.py

public python v1 · immutable
#635358 ·published 2007-07-27 00:39 UTC
rendered paste body
# Talk.py# An X-Chat Python Script by Maulsel# What it does: Colors names for roleplay.# Tested on: X-Chat Aqua 0.16.0# You may modify this code as long as you keep the copyright info.# Copyright: Script is Public Domain. Originally Created by Maulsel.# Changelog# 0.1 - Basic code# 0.2 - Revamped code, added saving of data# 0.3 - Changed save format slightly, added autosave and preferencesimport xchat, pickle, os.path__module_name__ = "Talk"__module_version__ = "0.3"__module_description__ = "Colors names for roleplay."xchat.prnt("Loading Talk script...")	# let's define some stuffconfigFile = 'Talk.conf'#configDir = '~/.xchat2/' # linux#configDir = '' # windows / anything elseconfigDir = '/Applications/X-Chat Aqua/Plugins/' # OS Xnull = ''data = []null2 = '(lp0\n.'defprefs = {'autosave': 1}config = configDir + configFile# let's get the stored data out of the fileif (os.path.isfile(config)):	xchat.prnt("Trying to open config file...")	f = open(config, 'r')	xchat.prnt("Loading contents...")	cont = f.read()	if (cont != null):		if (cont != null2):			temp = pickle.loads(cont)			data = temp[1]			prefs = temp[0]			xchat.prnt("Loaded.")	else:		xchat.prnt("No content saved to load.")	f.close()else:	xchat.prnt("Creating config file...")	f = open(config, 'w')	f.close()	xchat.prnt("Created.")	xchat.prnt("Setting basic settings...")	startprefs()	xchat.prnt("Done.")if prefs == {}:			# bugfix	prefs = defprefs	# bugfix		def dotalk(word, word_eol, userdata):	lookfor = word[1].capitalize()	for i in data:		for x in i:			if x == lookfor:				name = i[0]				color = i[1]				bgcolor = i[2]				break	xchat.command("SAY " + color + "," + bgcolor + "(" + name + ") " + word_eol[2])	return xchat.EAT_ALL	def setcolor(word, word_eol, userdata):	gotit = 0	lookfor = word[1].capitalize()	for i in data:		for x in i:				if x == lookfor:					i[1] = word[2]					i[2] = word[3]					gotit = 1					break	if gotit == 0:		data.append([word[1].capitalize(), word[2], word[3]])	xchat.command("ECHO Set colors for " + word[1].capitalize() + ". Preview: " + word[2] + "," + word[3] + "(" + word[1].capitalize() + ")")	if prefs['autosave'] == 1:			savedata()	return xchat.EAT_ALL	#def preferences_cb(word, word_eol, userdata):#	if word[1] == 'help':#		xchat.prnt("Preferences:")#		xchat.prnt("'autosave': if on, then whenever you /setcolors, it will automatically save the conf file.")#		if prefs['autosave'] == 1:#			xchat.prnt("'autosave': Enabled")#		else:#			xchat.prnt("'autosave': Disabled")#	else:#		if prefs.is_key(word[1]):#			# working on it!#	return xchat.EAT_ALL	def getsave():	# whole thing is for a bugfix	temp = [prefs, data]	tempo = pickle.dumps(temp)	return tempo		def savedata():	xchat.prnt("Saving data...")	tempo = getsave()			#bugfix	f = open(config, 'w')	f.write(tempo)	f.close()	xchat.prnt("Saved.")	return xchat.EAT_ALLdef savedata_cb(word, word_eol, userdata):	savedata()	return xchat.EAT_ALLdef unload_cb(userdata):	savedata()	xchat.prnt("Unloaded Talk.")	xchat.hook_unload(unload_cb)xchat.hook_command("setcolors", setcolor, help="/setcolors name color bgcolor")xchat.hook_command("talk", dotalk, help="/talk name What to say")xchat.hook_command("savetalk", savedata_cb, help="/savetalk")#xchat.hook_command("tprefs", preferences_cb, help="/tprefs help")xchat.prnt("Loaded Talk script.")