Gozerbot

From AleikoumWiki

(Difference between revisions)
Jump to: navigation, search
m (Leirn version)
Current revision (16:16, 4 December 2008) (edit) (undo)
m (la version de Laby)
 
Line 62: Line 62:
###############################################################
###############################################################
# Libs et modules
# Libs et modules
-
import os, re, popen2, random
+
import random
from gozerbot.commands import cmnds
from gozerbot.commands import cmnds
from gozerbot.generic import rlog
from gozerbot.generic import rlog
Line 68: Line 68:
from gozerbot.examples import examples
from gozerbot.examples import examples
###############################################################
###############################################################
- 
-
re_ok = re.compile('[^-_\.a-zA-Z0-9]')
 
- 
Line 94: Line 91:
except IndexError:
except IndexError:
ievent.missing('<feuille|pierre|ciseaux>')
ievent.missing('<feuille|pierre|ciseaux>')
-
return
+
return 1
choices = ['pierre', 'ciseaux', 'feuille']
choices = ['pierre', 'ciseaux', 'feuille']
if user_choice not in choices:
if user_choice not in choices:
-
machaine = "variables possible : ciseaux|feuille|pierre"
+
machaine = "variables possibles : ciseaux|feuille|pierre"
ievent.reply(machaine)
ievent.reply(machaine)
return 1
return 1

Current revision

Contents

Presentation

Gozerbot est un bot jabber (http://gozerbot.org/newsite/)

gozerbot is the Python IRC bot and Jabber bot in one

Requirements

    * a shell
    * python 2.4 or higher
    * if you want to remotely install plugins: the gnupg module
    * if you want mysql support: the py-MySQLdb module
    * if you want jabber support: the xmpppy module

Why gozerbot?

    * provide both IRC and Jabber support
    * user management by userhost .. bot will not respond if it doesn't know you (see /docs/handbook/USER/)
    * fleet .. use more than one bot in a program (list of bots) (see /docs/plugins/FLEET/)
    * use the bot through dcc chat
    * fetch rss feeds (see /docs/plugins/RSS/)
    * remember items
    * relaying between bots (see /docs/plugins/RELAY/)
    * program your own plugins (see /docs/handbook/PROGRAMPLUGIN/)
    * run the builtin webserver (see /docs/plugins/WEBSERVER/)
    * query other bots webserver via irc (see /docs/plugins/COLLECTIVE/)
    * serve as a udp <-> irc or jabber notification bot (see /docs/plugins/UDP)
    * mysql and sqlite support

Installation / Configuration

Plugins

shifumi.py

avec mon pote Leirn on souhaite que nos bots se battent au shifumi ! du coup chacun de nous a developpe son plugin shifumi

la version de Laby

###############################################################
# Premier Test de Plugins pour erwanbot : shifumi !!!
# author : Erwan Labynocle Aleikoum Ben Souiden
# date : 2008-12-04
# current version : 0.2
# changelog :
#       0.2 : gestion des erreurs / help / exemple
#       0.1 : creation
# fixme :
#       aucun
###############################################################
# ___  ___       ______ _          _    ______       _
# |  \/  |       |  ___(_)        | |   | ___ \     | |
# | .  . |_   _  | |_   _ _ __ ___| |_  | |_/ / ___ | |_
# | |\/| | | | | |  _| | | '__/ __| __| | ___ \/ _ \| __|
# | |  | | |_| | | |   | | |  \__ \ |_  | |_/ / (_) | |_
# \_|  |_/\__, | \_|   |_|_|  |___/\__| \____/ \___/ \__|
#          __/ |
#         |___/ shifumi edition !

###############################################################
# Libs et modules
import random
from gozerbot.commands import cmnds
from gozerbot.generic import rlog
from gozerbot.plughelp import plughelp
from gozerbot.examples import examples
###############################################################


###############################################################
# Fonction 1 : analyse des shifumi choices
###############################################################
def shifumi_analyse(parameter_1,parameter_2):
        if parameter_1 == "ciseaux" and parameter_2 == "feuille":
                return "ciseaux"
        elif parameter_1 == "pierre" and parameter_2 == "ciseaux":
                return "pierre"
        elif parameter_1 == "feuille" and parameter_2 == "pierre":
                return "feuille"
        else:
                return parameter_2

###############################################################
# Fonction 2 : un shifumi totalement random
###############################################################
def handle_shifumi_random(bot, ievent):
        try:
                user_choice = ievent.args[0]
        except IndexError:
                ievent.missing('<feuille|pierre|ciseaux>')
                return 1
        choices = ['pierre', 'ciseaux', 'feuille']

        if user_choice not in choices:
                machaine = "variables possibles : ciseaux|feuille|pierre"
                ievent.reply(machaine)
                return 1

        bot_choice = str(random.choice(choices))

        rlog(10, 'handle_shifumi_random', 'choix bot :  %s et choix player : %s' % (bot_choice, user_choice))

        machaine = "le robot a choisi : " + bot_choice + " et vous " + user_choice
        ievent.reply(machaine)

        result = shifumi_analyse(bot_choice,user_choice)
        rlog(10, 'handle_shifumi_random', 'result :  %s' % (result))

        if result == bot_choice and result == user_choice:
                machaine = "egalite !"
        elif result == bot_choice:
                machaine = "bot gagnant !"
        else:
                machaine = "bravo"
        ievent.reply(machaine)
        return 0



###############################################################
# Liste des commandes
###############################################################
plughelp.add('shifumi', '!shifumi <ciseaux|feuille|pierre>')
examples.add('shifumi', '!shifumi ciseaux', 'shifumi')
cmnds.add('shifumi', handle_shifumi_random, 'USER')

La version de Leirn

# shifumi plugin
# author : Laurent Vromman <laurent@vromman.org>
# date : 2008-12-04

"""
This file is provided under the MIT Licence

The MIT License

Copyright (c) 2008 Laurent Vromman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""


import random
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.generic import rlog

def handle_shifumi(bot, ievent):
    """
        Play shifumi
        pierre : 0
        feuille : 1
        ciseaux : 2
    """
    rlog(10, 'shifumi', 'entering handle_shifumi')
    try:
        option = ievent.args[0]
    except IndexError:
        ievent.missing('<feuille|pierre|ciseaux>')
        return

    options = ["pierre", "feuille", "ciseaux"]

    if option not in options:
        ievent.missing('<feuille|pierre|ciseaux>')
        return

    botplay = random.randint(0, 2)

    if option == "pierre":
        gamerplay = 0
    elif option == "feuille":
        gamerplay = 1
    elif option == "ciseaux":
        gamerplay = 2
    result = (gamerplay - botplay) % 3
    rlog(5, 'shifumi', 'result is %s' % (str(result)))
    if result == 0:
        ievent.reply('egalite')
    elif result == 1:
        ievent.reply('gamer : %s, bot : %s, gagnant : gamer' % (option, options[botplay]))
    elif result == 2:
        ievent.reply('gamer : %s, bot : %s, gagnant : bot' % (option, options[botplay]))



cmnds.add('shifumi', handle_shifumi, 'USER')
examples.add('shifumi', 'play shifumi against the bot', 'shifumi <feuille|pierre|ciseaux>')
Personal tools