[Python] Vérification de code

Fermé
Tomas - 27 mai 2007 à 15:15
sebsauvage Messages postés 32893 Date d'inscription mercredi 29 août 2001 Statut Modérateur Dernière intervention 21 octobre 2019 - 28 mai 2007 à 14:14
Vérification de code Python

salut, je voulais savoir si qqun pouvais me corriger ou vérifier que ce code était correct.

import os, xchat

__module_name__ = "fserve"
__module_version__ = "1.0"
__module_description__ = "Share Rocks^^."

# Description of Operation:
# !share opens a DCC connection. On connect presents help message.
# !help also presents help message.
# !list prints contents of folder
# !get gets the file
#
# Written by YouMotherFucker

###### EDIT THESE LINES FOR YOUR CONFIGURATION ########
max = 1
directory = "C:\Program Files\mIRC\download\Finish"
#######################################################

def priv_mesg(word, word_eol, userdata):
if word[1].find("!list") != -1:
contents = os.listdir(directory)
count = 1
for file in contents:
size = os.stat(directory + file).st_size / 1048576
saystring = "say " + repr(count) + ". " + file + " " + str(size) + " MB"
xchat.command(saystring)
count = count + 1
if word[1].find("!help") != -1:
xchat.command("say To get a list of available files, use !list.")
xchat.command("say To download a file, use !get [number], where")
xchat.command("say [number] is the number as given by !list.")
xchat.command("say Downloads are limited to a total of " + str(max) + " to all users.")
xchat.command("say To open a DCC Chat, type !share")
if word[1].find("!share") != -1:
commandStr = "dcc chat " + word[0]
dccList = xchat.get_list("dcc")
if dccList != []:
for i in dccList:
if (i.type == 3 or i.type == 2) and i.nick == word[0] and (i.status == 0 or i.status == 1):
xchat.command("say Error: A connection is already open or being offered to you.")
return xchat.EAT_NONE
xchat.command(commandStr)
if word[1].find("!get") != -1:
transferring = 0
dccList = xchat.get_list("dcc")
if dccList != []:
for i in dccList:
if i.type == 0 and (i.status == 1 or i.status == 0 or i.status == 4):
transferring = transferring + 1
if transferring >= max:
xchat.command("say Too many transfers are taking place.")
return xchat.EAT_NONE
length = len(word[1])
if length > 5:
strNumber = word[1][4:]
Number = int(strNumber)
contents = os.listdir(directory)
count = 1
for file in contents:
if count == Number:
commandStr = "dcc send " + word[0] + " \"" + directory + file + "\""
xchat.command(commandStr)
count = count + 1
return xchat.EAT_NONE

def conn_mesg(word, word_eol, userdata):
if word[1].find("!share") != -1:
commandStr = "dcc chat " + word[0]
dccList=xchat.get_list("dcc")
if dccList != []:
for i in dccList:
if (i.type == 3 or i.type == 2) and i.nick == word[0] and (i.status == 0 or i.status == 1):
xchat.command("notice " + word[0] + " Error: A connection is already open or being offered to you.")
return xchat.EAT_NONE
xchat.command(commandStr)
return xchat.EAT_NONE

def dcc_mesg(word, word_eol, userdata):
xchat.command("notice " + word[0] + " To get a list of available files, use !list.")
xchat.command("notice " + word[0] + " To download a file, use !get [number], where")
xchat.command("notice " + word[0] + " [number] is the number as given by !list.")
xchat.command("notice " + word[0] + " Downloads are limited to a total of " + str(max)+ " to all users.")
xchat.command("notice " + word[0] + " To open a DCC Chat, type !share. To get this help again use !help.")
return xchat.EAT_NONE

xchat.hook_print("Private Message to Dialog", priv_mesg)
xchat.hook_print("Channel Message", conn_mesg)
xchat.hook_print("DCC CHAT Connect", dcc_mesg)
print("FServe Started!")
A voir également:

1 réponse

sebsauvage Messages postés 32893 Date d'inscription mercredi 29 août 2001 Statut Modérateur Dernière intervention 21 octobre 2019 15 655
28 mai 2007 à 14:14
impossible de vérifier ton code.

Met ton code entre balises < code> sinon il est inutilisable.
1