Gozerbot

From AleikoumWiki

Revision as of 16:01, 4 December 2008 by Erwan (Talk | contribs)
Jump to: navigation, search

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 os, re, popen2, random
from gozerbot.commands import cmnds
from gozerbot.generic import rlog
from gozerbot.plughelp import plughelp
from gozerbot.examples import examples
###############################################################

re_ok = re.compile('[^-_\.a-zA-Z0-9]')



###############################################################
# 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
        choices = ['pierre', 'ciseaux', 'feuille']

        if user_choice not in choices:
                machaine = "variables possible : 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')

Leirn version

# test plugin

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