IPB

Bienvenue invité ( Connexion | Inscription )

[ En ligne ] · Standard · Linéaire+

> Pfouuu, java me fait chier, là ...

momo
post 09/08/2002 21:50
Message #1


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



.. alors je vais essayer Python ... ça à l'air marrant à premiere vu ...

Ceci est un communiqué sans interet aucun d'un momo qui se desespere de programmer bcp mieux en Basic que dans n'importe quel autre langage


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
 
Reply to this topicStart new topicStart Poll
Réponse(s)
Gfx
post 12/08/2002 0:13
Message #2


Goule
****

Groupe : Membres
Messages : 980
Inscrit le : 01/08/2002 23:00
Lieu : Lyon
Membre no. 106



Oui mais c beau techniquement smile.gif))

J'ai aussi ça :
CODE

#!/usr/bin/env python

# NYCTALOPE - 07/30/2002 - 02:33:02
#
# Lorsque quelqu'un parle, le bot prend un nombre aléatoirement entre 0 et 1
# Il prend le code ASCII correspondant aux 2 premières décimales de ce nombre
# Si ce code apparaît dans le nick en majuscules de l'intervenant, une ligne
# des scripts du donjon est envoyée.
#
# Tout le monde peut dire en public ou en privé :
# nyctalope, parle
# pour recevoir une citation.
#
# Le fichier nyctalope.conf permet de configurer le bot.
#
# GNU-GPL v2, (C)2002 Romain GUY, romain.guy@jext.org

import os.path
from random import *
import re
from socket import *
import sys

################################################################################
##########
# CONSTANTES - Définies dans le fichier nyctalope.conf
# Ce sont les valeurs par défaut si le fichier nyctalope.conf est introuvable.
################################################################################
##########

BOT_CHANS = '#pcteam,#progworld' # canaux (séparés par des virgules)
BOT_HOST = 'ircnet.kaptech.fr' # serveur
BOT_PORT = 6667 # port sur le serveur IRC
BOT_IDENT = 'nyctalope' # nick ET ident du bot
OP = '.?gfx@.*\.ppp\.tiscali\.fr' # masque de l'administrateur (c'est une regex)
IDENT_PORT = 113 # port ident (local)

################################################################################
##########
# CODE SOURCE
################################################################################
##########

DEBUG = 0 # mode debug
sourceFiles = []

# EMISSION D'UNE CITATION
def quote(source):
randomizer = Random()
file = sourceFiles[randomizer.randrange(1, len(sourceFiles))]

if file[-1] == '\n':
file = file[:-1]

quotes = open(file)
lines = quotes.readlines()
line = ''
quotes.close()

while len(line) == 0:
line = lines[randomizer.randrange(1, len(lines))].strip()
if DEBUG:
print line

bot.send('NOTICE ' + source + ' :' + line + '\r\n')

# CONFIGURATION
print "Reading configuration..."
if os.path.exists('nyctalope.conf'):
conf = open('nyctalope.conf')
lines = conf.readlines()
conf.close()

for line in lines:
match = re.search('^([^=]*)=(.*)$', line)
if match is not None:
key, value = match.groups(2)
if key == 'BOT_CHANS': BOT_CHANS = value
elif key == 'BOT_HOST' : BOT_HOST = value
elif key == 'BOT_PORT' : BOT_PORT = int(value)
elif key == 'BOT_IDENT': BOT_IDENT = value
elif key == 'OP' : OP = '(\+.)?' + value.replace('.', '\.').replace('*', '.*')

# CREATION DE LA LISTE DES FICHIERS
print "Gathering data..."
naheulbeuk = re.compile('\?|/?Pen of Chaos_Le Donjon de Naheulbeuk \d\d.*.txt$')
for file in os.listdir('.'):
if naheulbeuk.search(file):
sourceFiles.append(file)

# SOCKETS
print "Creating sockets..."
ident, bot = socket(AF_INET, SOCK_STREAM), socket(AF_INET, SOCK_STREAM)

# SERVEUR IDENT
print "Running ident server on port", IDENT_PORT, "..."
try:
ident.bind(('', IDENT_PORT))
ident.listen(1)
bot.connect((BOT_HOST, BOT_PORT))
irc, irchost = ident.accept()
print "Got ident request, answering..."
irc.send(re.search('(\d+)', irc.recv(1024)).group(1) + ", " + str(BOT_PORT) + ' : USERID : UNIX : ' + BOT_IDENT)
irc.close()
ident.close()
except:
print "Ident server already running on port", IDENT_PORT, "..."

# CONNEXION DU BOT
print "Connecting bot..."
try:
bot.send('NICK ' + BOT_IDENT + '\r\n')
bot.send('USER ' + BOT_IDENT + ' ' + gethostname() + ' ' + BOT_HOST + ' :' + BOT_IDENT + '\r\n')
while (bot.recv(1024).find('376 ' + BOT_IDENT) == -1):
pass
bot.send('JOIN ' + BOT_CHANS + '\r\n')
except:
print "Could not connect, try changing bot nick..."
sys.exit(1)

# BOUCLE PRINCIPALE
while 1:

# RECEPTION D'UNE LIGNE DU SERVEUR
match = re.search('(?m)^PING.+|:([^!]+)!([^\s]+)\s+(\w+)\s+(#?\w+)?\s*([^:]+)?:?([^\r]*)', bot.recv(1024))
if match is not None:
nick, id, command, source, arg, text = match.groups(5)

# PING PONG
if match.group(0).find('PING') == 0:
bot.send('PONG ' + BOT_IDENT + '\r\n')

else:
# COMMANDES PUBLIQUES
if command == 'PRIVMSG':

# COMMANDES DE L'OP
if re.search(OP, id) is not None:
match = re.search('^' + BOT_IDENT + ', (.*)$', text)
if match is not None:
command = match.group(1)
if command == 'quit':
bot.send("QUIT :Je le savais bien que t'étais une salope !!\r\n")
bot.close()
break

# COMMANDES TIERS
match = re.search('^' + BOT_IDENT + ', (parle)\s?(.*)$', text)

if match is not None:
command, arguments = match.groups(2)

# ORDRE DE PARLER
if command == 'parle':
quote(('#' in source and source or nick))
print "I've been forced to talk by", nick, "..."

# CITATION ALEATOIRE
elif chr(int(re.search('0\.(\d\d)', str(Random().random())).group(1))) in nick.upper():
quote(('#' in source and source or nick))
print "I've randomly quoted on", nick, "talk..."

# REJOINDRE LES CHANS
elif command == 'PART':

if text == BOT_IDENT and nick == BOT_IDENT:
bot.send('JOIN ' + source + '\r\n')
print "Rejoining chan", source, "..."

# REJOINDRE APRES UN KICK
elif command == 'KICK':

if arg.strip() == BOT_IDENT:
bot.send('JOIN ' + source + '\r\n')
print "Kicked, rejoining chan", source, "..."

# end of nyctalope.py


--------------------
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Posts in this topic
momo   Pfouuu, java me fait chier, là ...   09/08/2002 21:50
Darhf   alors un petit article pour toi qui date une peu v...   09/08/2002 22:06
momo   je le relis +/- regulierement ... :)   09/08/2002 22:15
Poischack   arf moi j'ai fait l'inverse python -> java......   09/08/2002 23:30
momo   from Tkinter import * def Clear_button(...   10/08/2002 17:44
Gfx   Rah Python rulez !!!!   10/08/2002 17:44
momo   ben ça :)   10/08/2002 17:45
momo   m'enfin quand on voit ce que supporte ce langage, ...   10/08/2002 17:52
Poischack   tu peux toujours utilisé py2exe, il te fait des e...   10/08/2002 17:57
momo   dwd en cours .. done on verra ça à tête repos...   10/08/2002 18:03
Poischack   c vrai que elif plus que plus cool que else if ....   10/08/2002 18:20
momo   sans compter qu'il est sacrement rapide : je vou...   11/08/2002 8:53
momo   from Tkinter import * def Clear_bton(...   11/08/2002 15:13
momo   tiens, j'y pense, y a pas moyen de mettre une colo...   11/08/2002 15:15
Poischack   nan et c'est bete, sinon ton prog marche, c'est ...   11/08/2002 15:33
momo   Posté le: Dim Août 11, 2002 3:13 pm : "bon, i...   11/08/2002 20:01
Poischack   oula va peut etre falloir que je change de lunette...   11/08/2002 20:03
momo   m'enfin en attendant, "impr. Ecran" et paint font ...   11/08/2002 20:11
Gfx   Y'a des trucs mortels en Python momo, lit mes arti...   11/08/2002 23:36
Poischack   heu .... moi je prefere mes prog qui tiennent su...   11/08/2002 23:38
Gfx   Oui mais c beau techniquement :))) J'ai aussi Ã...   12/08/2002 0:13
Gfx   Au fait, jette un oeil aux générateurs. Et plutÃ...   12/08/2002 0:20
Gfx   Au fait momo, tu peux compiler le Python sous form...   12/08/2002 1:13
momo   ben le tinker, je l'utilise uniquement parceque tk...   12/08/2002 9:52
momo   téléchargement de pyQT : Done téléchargement...   12/08/2002 12:53
Gfx   momo, tu as juste besoin de la DLL de QT, qui ne f...   12/08/2002 13:39
momo   bon, de toutes façon, j'ai presque terminé le te...   12/08/2002 13:44
momo   bon voilà, done ....   12/08/2002 14:02
momo   localisation spatio-temporelle: Terre, 14/08/2002 ...   14/08/2002 20:59
Poischack   Microsoft, relation publique: pschht pschhtt momo...   14/08/2002 21:15
Gfx   Installe l'extension PIL. Ca rulez pour traiter le...   14/08/2002 21:43
momo   ce serait trop facile du coup ...   14/08/2002 21:46
Poischack   :) pff pourquoi faire facil quan don peut faire co...   14/08/2002 21:51
momo   et pourquoi ne pas develloper sa propre librairie ...   15/08/2002 10:53
momo   from Tkinter import * def Dwords(files...   16/08/2002 10:24


Reply to this topicTopic OptionsStart new topic
2 utilisateur(s) sur ce sujet (2 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :
 

Version bas débit Nous sommes le : : 04/07/2025 15:08