Skip to content

Commit

Permalink
style: isort & flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilhem Saurel committed Mar 20, 2016
1 parent c07596e commit bf00ec2
Show file tree
Hide file tree
Showing 105 changed files with 844 additions and 791 deletions.
9 changes: 5 additions & 4 deletions bashfr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
""" A module to parse quote extracted from http://danstonchat.com/ """

import random

import pipobot.lib.utils
from BeautifulSoup import BeautifulSoup
from pipobot.lib.abstract_modules import FortuneModule
Expand Down Expand Up @@ -48,9 +49,9 @@ def extract_data(self, html_content):
class BashfrTest(ModuleTest):
def test_bashfr_5(self):
bot_rep = self.bot_answer("!bashfr 5")
expected=(u"bashfr #5 :\n"
u"(swatchtim) mac ? ca existe encore ca ?\n"
u" * kick: (swatchtim) was kicked by (Cafmac) (Ouais. Les cons aussi.)")
expected = (u"bashfr #5 :\n"
u"(swatchtim) mac ? ca existe encore ca ?\n"
u" * kick: (swatchtim) was kicked by (Cafmac) (Ouais. Les cons aussi.)")
self.assertEqual(bot_rep, expected)

def test_bashfr_random(self):
Expand Down
8 changes: 4 additions & 4 deletions bashorg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
""" A module to parse quotes from http://bash.org """

from pipobot.lib.utils import xhtml2text
from BeautifulSoup import BeautifulSoup
from pipobot.lib.abstract_modules import FortuneModule
from pipobot.lib.module_test import ModuleTest
from pipobot.lib.utils import xhtml2text


class CmdBashorg(FortuneModule):
Expand Down Expand Up @@ -44,8 +44,8 @@ def extract_data(self, html_content):
class BashfOrgTest(ModuleTest):
def test_bashorg_ok(self):
bot_rep = self.bot_answer("!bashorg 1729")
expected=(u"bashorg #1729 :\n"
u"<blinkchik> can i become a bot and how??")
expected = (u"bashorg #1729 :\n"
u"<blinkchik> can i become a bot and how??")
self.assertEqual(bot_rep, expected)

def test_bashorg_random(self):
Expand Down
77 changes: 39 additions & 38 deletions belotebot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,107 +1,108 @@
#! /usr/bin/env python
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-

import game
import logging
from pipobot.lib.modules import defaultcmd, answercmd
from pipobot.lib.modules import SyncModule, IQModule
import os

from pipobot.lib.modules import IQModule, SyncModule, answercmd, defaultcmd

import game
from cards import Deck


class CmdBelote(SyncModule) :
class CmdBelote(SyncModule):
""" Module Belote for bot """

def __init__(self, bot) :
def __init__(self, bot):
desc = "Jeu de belote. Si vous voulez être renseigné, \
allez au bureau des renseignements, ils vous renseigneront…"
SyncModule.__init__(self, bot, desc=desc, name='b')
self.game = None

# Notify function for the belote game
@staticmethod
def html(card) :
def html(card):
""" HTMl output with img, not supported in all clients """
return '<img src="http://www.bde.enseeiht.fr/~chataia/cards/png/%s%s.png" alt="%s" />' \
% (card.val, card.suit.name, card.output())
ret = '<img src="http://www.bde.enseeiht.fr/~chataia/cards/png/%s%s.png" alt="%s" />'
return ret % (card.val, card.suit.name, card.output())

@staticmethod
def bob(card) :
def bob(card):
"""" Output using BoB (Bits of binary, XEP-0231), supported in pidgin """
return '<img src="cid:%[email protected]" alt="%s" />' % (card.output(utf8=False), card.output())

def notify(self, msg, cards_obj=None, private=None) :
def notify(self, msg, cards_obj=None, private=None):
""" Implementation of a Belote() notify function:
msg: Message with @ for cards
cards_obj: object to replace with @
private: if not None, name of the player to send
"""
if cards_obj is not None :
txtmsg = msg.replace('@','%s') % tuple(cards_obj)
htmlmsg = msg.replace('@','%s %s') % \
tuple((e for f in [(CmdBelote.html(c), CmdBelote.bob(c)) for c in cards_obj] for e in f))
if cards_obj is not None:
txtmsg = msg.replace('@', '%s') % tuple(cards_obj)
htmlmsg = msg.replace('@', '%s %s') % \
tuple((e for f in [(CmdBelote.html(c), CmdBelote.bob(c)) for c in cards_obj] for e in f))
self.bot.say({'text': txtmsg, 'xhtml': htmlmsg}, priv=private)
else :
else:
self.bot.say(msg, priv=private)

def notify_cards(self) :
def notify_cards(self):
""" Default notify_cards """

for player in self.game.players :
self.notify('@ '*len(player.cards), sorted(player.cards), private=player)
for player in self.game.players:
self.notify('@ ' * len(player.cards), sorted(player.cards), private=player)

def notify_tapis(self) :
def notify_tapis(self):
""" Show the table """
pass

@answercmd("cartes")
def show_cards(self, sender) :
def show_cards(self, sender):
""" A player ask to show his cards """
player = self.game.find_player(sender)
self.notify('@ '*len(player.cards), sorted(player.cards), private=player)
self.notify('@ ' * len(player.cards), sorted(player.cards), private=player)

@answercmd("tapis")
def show_tapis(self, sender) :
def show_tapis(self, sender):
self.notify_tapis()

@answercmd("init")
def init_game(self, sender) :
def init_game(self, sender):
""" Init new game """

self.game = game.Belote(self.notify, self.notify_cards, self.notify_tapis)

@defaultcmd
def answer(self, sender, message) :
def answer(self, sender, message):
""" Default answer if not an answercmd """

if self.game.state == 'wait_player' and 'moi' in message :
if self.game.state == 'wait_player' and 'moi' in message:
self.game.join(sender)
elif self.game.state in ['wait_choice', 'sec_choice'] :
elif self.game.state in ['wait_choice', 'sec_choice']:
suit = self.game.deck.find_suit(message.decode('utf8'))
take = suit is not None or message == 'y'
self.game.choice(sender, take=take, suit=suit)
elif self.game.state == 'wait_play' :
elif self.game.state == 'wait_play':
card = self.game.deck.find(message.decode('utf8'))
if card is None :
if card is None:
self.notify("Cette carte n'existe pas")
return
self.game.play(sender, card)

import os
from cards import Deck

class IqBobBelote(IQModule) :
class IqBobBelote(IQModule):

def __init__(self, bot) :
def __init__(self, bot):
IQModule.__init__(self, bot, name='BoBCard', desc='BoB for belote cards')
bot.registerPlugin("xep_0231")

# Generate cache
deck = Deck()
for card in deck.cards :
for card in deck.cards:
path = os.path.join(os.path.dirname(__file__), "png/%s.png" % card.output(utf8=False))
cid = card.output(utf8=False)+"@bob.xmpp.org"
cid = card.output(utf8=False) + "@bob.xmpp.org"

fdimg = open(path)
raw_img = fdimg.read()
fdimg.close()

bot.plugin['xep_0231'].set_bob(data=raw_img, mtype='image/png', cid=cid)
Loading

0 comments on commit bf00ec2

Please sign in to comment.