Gozerbot

From AleikoumWiki

Revision as of 15:57, 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

###############################################################
# 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')
Personal tools