Gozerbot
From AleikoumWiki
(Difference between revisions)
Erwan (Talk | contribs)
(New page: = Presentation = = Installation / Configuration = = Plugins = == shifumi.py == <pre> ############################################################### # Premier Test de Plugins pour erwa...)
Next diff →
Revision as of 15:55, 4 December 2008
Contents |
Presentation
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')