Par défaut, le daemon écoute sur le port 7776 (par opposition à 6667 pour IRC ) et reconnaît deux commandes:
- §login username : crée un nouvel utilisateur sur le serveur IRC ou récupère le contrôle d'un utilisateur déjà connecté.
- §msg message pour le chan : envoie un message sur le chan IRC par défaut (#botempe pour l'instant).
Ces commandes vont très probablement changer, mais l'équipe doit encore discuter des modalités de la communication PHP-Python-IRC, et des différences qui peuvent exister entre l'implémentation pour le client IRC AJAX que développe Coolboy d'une part, et le système de notifications prévu pour MP.
__________________________
Aidez les autres membres en publiant sur le forum le code que nous vous avons aidé à créer ! Où sont les membres de MP ?
Pour un accès plus facile au code en développement, voici une copie de la version 0.01 :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
--------------------------------------------------------------------------------
Botempe is a IRC client daemon for the MoteurProg community ( http://www.moteurprog.com ).
--------------------------------------------------------------------------------
Authors:
- Hugo Herter <mail AT hugoh DOT org>
Objectives:
- Allow PHP scripts to send notifications
to the chan or to the connected users.
(new private message, new topic in a forum some connected users follow, ...)
Later objectives:
- Save the discutions from the main channel(s) on the website for later access.
Requirements:
- Python ( development uses version 2.5.1)
This distribution may include a copy of Python IRCLib
http://sourceforge.net/projects/python-irclib
Thanks to Peyton McCullough for his article "IRC on a Higher Level"
http://www.devshed.com/c/a/Python/IRC-on-a-Higher-Level/
Copyright (C) 2008 Hugo Herter
This file is part of Botempe.
Botempe is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Botempe is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Botempe. If not, see <http://www.gnu.org/licenses/>.
"""
__version__ = '0.01'
import threading, socket
import irclib
# Connection information
network = 'localhost' #'irc.moteurprog.com'
port = 6667
channel = '#botempe'
nick = 'Botempe'
name = 'Botempe %s' % __version__
# Connect
irc = irclib.IRC()
# Users
users = {}
# IRC virtual user
class VirtualUser:
def __init__(self, nick):
self.nick = nick
self.server = irc.server()
self.server.connect(network, port, nick, ircname=name)
self.server.join(channel)
# Client Listener
class ClientListener(threading.Thread):
def __init__(self, client, addr):
threading.Thread.__init__(self)
self.client = client
self.addr = addr
def run(self):
cache = ""
new = True
while (new):
try:
new = self.client.recv(2**14)
cache += new
# !!! TODO: Specify exception name
except Exception:
break
while 'n' in cache:
instruction, cache = cache.split('n',1)
self.execute(instruction)
def execute(self, instruction):
# !!! This is a draft for demo-only !
if ' ' in instruction:
action, argument = instruction.split(' ', 1)
else:
action, argument = instruction, None
if action == '§login':
if not users.has_key(argument):
users[argument] = VirtualUser(argument)
self.user = users[argument]
self.client.send('§login donen')
elif action == '§msg':
self.user.server.privmsg ( channel, argument )
# Local Listener
class LocalListener(threading.Thread):
"""Class that handles local connexions"""
clients = []
def __init__(self):
"Binds the local port."
threading.Thread.__init__(self)
self.socket = socket.socket()
self.socket.bind(('localhost', 7776))
self.socket.listen(32)
def run(self):
"Listens to new connections."
while (True):
client, addr = self.socket.accept()
print "Connexion:", client, addr
listener = ClientListener(client, addr)
self.clients.append(listener)
listener.start()
# Start local listnener in a new thread
listener = LocalListener()
listener.start()
# Loop
irc.process_forever()
__________________________
Aidez les autres membres en publiant sur le forum le code que nous vous avons aidé à créer ! Où sont les membres de MP ?